Debian Codegraph @

ansible_collections/vmware/vmware_rest/plugins/modules/vcenter_vm_hardware_ethernet.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright: (c) 2021, Ansible Project
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5 # template: header.j2
6 # This module is autogenerated using the ansible.content_builder.
7 # See: https://github.com/ansible-community/ansible.content_builder
8
9
10 DOCUMENTATION = r"""
11 module: vcenter_vm_hardware_ethernet
12 short_description: Adds a virtual Ethernet adapter to the virtual machine.
13 description: Adds a virtual Ethernet adapter to the virtual machine.
14 deprecated:
15 removed_in: 5.0.0
16 why: This module has been moved to the L(new vmware.vmware collection,https://forum.ansible.com/t/5880)
17 alternative: Use M(vmware.vmware.vm) instead.
18 options:
19 allow_guest_control:
20 description:
21 - Flag indicating whether the guest can connect and disconnect the device.
22 - If unset, the value is unchanged.
23 type: bool
24 backing:
25 description:
26 - Physical resource backing for the virtual Ethernet adapter.
27 - If unset, the system may try to find an appropriate backing. If one is not
28 found, the request will fail. Required with I(state=['present'])
29 - 'Valid attributes are:'
30 - ' - C(type) (str): This option defines the valid backing types for a virtual
31 Ethernet adapter. ([''present''])'
32 - ' This key is required with [''present''].'
33 - ' - Accepted values:'
34 - ' - DISTRIBUTED_PORTGROUP'
35 - ' - HOST_DEVICE'
36 - ' - OPAQUE_NETWORK'
37 - ' - STANDARD_PORTGROUP'
38 - ' - C(network) (str): Identifier of the network that backs the virtual Ethernet
39 adapter.'
40 - This field is optional and it is only relevant when the value of I(type)
41 is one of STANDARD_PORTGROUP, DISTRIBUTED_PORTGROUP, or OPAQUE_NETWORK.
42 - When clients pass a value of this structure as a parameter, the field must
43 be the id of a resource returned by M(vmware.vmware_rest.vcenter_network_info).
44 (['present'])
45 - ' - C(distributed_port) (str): Key of the distributed virtual port that
46 backs the virtual Ethernet adapter. Depending on the type of the Portgroup,
47 the port may be specified using this field. If the portgroup type is early-binding
48 (also known as static), a port is assigned when the Ethernet adapter is
49 configured to use the port. The port may be either automatically or specifically
50 assigned based on the value of this field. If the portgroup type is ephemeral,
51 the port is created and assigned to a virtual machine when it is powered
52 on and the Ethernet adapter is connected. This field cannot be specified
53 as no free ports exist before use.'
54 - May be used to specify a port when the network specified on the I(network)
55 field is a static or early binding distributed portgroup. If unset, the
56 port will be automatically assigned to the Ethernet adapter based on the
57 policy embodied by the portgroup type. (['present'])
58 type: dict
59 label:
60 description:
61 - The name of the item
62 type: str
63 mac_address:
64 description:
65 - 'MAC address. '
66 - ' This field may be modified at any time, and changes will be applied the
67 next time the virtual machine is powered on.'
68 - ''
69 - If unset, the value is unchanged. Must be specified if I(mac_type) is MANUAL.
70 Must be unset if the MAC address type is not MANUAL.
71 type: str
72 mac_type:
73 choices:
74 - ASSIGNED
75 - GENERATED
76 - MANUAL
77 description:
78 - The I(mac_address_type) enumerated type defines the valid MAC address origins
79 for a virtual Ethernet adapter.
80 type: str
81 nic:
82 description:
83 - Virtual Ethernet adapter identifier.
84 - The parameter must be the id of a resource returned by M(vmware.vmware_rest.vcenter_vm_hardware_ethernet).
85 Required with I(state=['absent', 'connect', 'disconnect', 'present'])
86 type: str
87 pci_slot_number:
88 description:
89 - Address of the virtual Ethernet adapter on the PCI bus. If the PCI address
90 is invalid, the server will change when it the VM is started or as the
91 device is hot added.
92 - If unset, the server will choose an available address when the virtual machine
93 is powered on.
94 type: int
95 session_timeout:
96 description:
97 - 'Timeout settings for client session. '
98 - 'The maximal number of seconds for the whole operation including connection
99 establishment, request sending and response. '
100 - The default value is 300s.
101 type: float
102 version_added: 2.1.0
103 start_connected:
104 description:
105 - Flag indicating whether the virtual device should be connected whenever
106 the virtual machine is powered on.
107 - If unset, the value is unchanged.
108 type: bool
109 state:
110 choices:
111 - absent
112 - connect
113 - disconnect
114 - present
115 default: present
116 description: []
117 type: str
118 type:
119 choices:
120 - E1000
121 - E1000E
122 - PCNET32
123 - VMXNET
124 - VMXNET2
125 - VMXNET3
126 description:
127 - The I(emulation_type) enumerated type defines the valid emulation types
128 for a virtual Ethernet adapter.
129 type: str
130 upt_compatibility_enabled:
131 description:
132 - 'Flag indicating whether Universal Pass-Through (UPT) compatibility should
133 be enabled on this virtual Ethernet adapter. '
134 - ' This field may be modified at any time, and changes will be applied the
135 next time the virtual machine is powered on.'
136 - ''
137 - If unset, the value is unchanged. Must be unset if the emulation type of
138 the virtual Ethernet adapter is not VMXNET3.
139 type: bool
140 vcenter_hostname:
141 description:
142 - The hostname or IP address of the vSphere vCenter
143 - If the value is not specified in the task, the value of environment variable
144 C(VMWARE_HOST) will be used instead.
145 required: true
146 type: str
147 vcenter_password:
148 description:
149 - The vSphere vCenter password
150 - If the value is not specified in the task, the value of environment variable
151 C(VMWARE_PASSWORD) will be used instead.
152 required: true
153 type: str
154 vcenter_rest_log_file:
155 description:
156 - 'You can use this optional parameter to set the location of a log file. '
157 - 'This file will be used to record the HTTP REST interaction. '
158 - 'The file will be stored on the host that runs the module. '
159 - 'If the value is not specified in the task, the value of '
160 - environment variable C(VMWARE_REST_LOG_FILE) will be used instead.
161 type: str
162 vcenter_username:
163 description:
164 - The vSphere vCenter username
165 - If the value is not specified in the task, the value of environment variable
166 C(VMWARE_USER) will be used instead.
167 required: true
168 type: str
169 vcenter_validate_certs:
170 default: true
171 description:
172 - Allows connection when SSL certificates are not valid. Set to C(false) when
173 certificates are not trusted.
174 - If the value is not specified in the task, the value of environment variable
175 C(VMWARE_VALIDATE_CERTS) will be used instead.
176 type: bool
177 vm:
178 description:
179 - Virtual machine identifier.
180 - The parameter must be the id of a resource returned by M(vmware.vmware_rest.vcenter_vm_info).
181 This parameter is mandatory.
182 required: true
183 type: str
184 wake_on_lan_enabled:
185 description:
186 - 'Flag indicating whether wake-on-LAN shoud be enabled on this virtual Ethernet
187 adapter. '
188 - ' This field may be modified at any time, and changes will be applied the
189 next time the virtual machine is powered on.'
190 - ''
191 - If unset, the value is unchanged.
192 type: bool
193 author:
194 - Ansible Cloud Team (@ansible-collections)
195 version_added: 0.1.0
196 requirements:
197 - vSphere 7.0.3 or greater
198 - python >= 3.6
199 - aiohttp
200 notes:
201 - Tested on vSphere 7.0.3
202 """
203
204 EXAMPLES = r"""
205 - name: Get the dvswitch called my-portgroup
206 vmware.vmware_rest.vcenter_network_info:
207 filter_types: DISTRIBUTED_PORTGROUP
208 filter_names: my portrgoup
209 register: my_portgroup
210
211 - name: Look up the VM called test_vm1 in the inventory
212 register: search_result
213 vmware.vmware_rest.vcenter_vm_info:
214 filter_names:
215 - test_vm1
216
217 - name: Collect information about a specific VM
218 vmware.vmware_rest.vcenter_vm_info:
219 vm: '{{ search_result.value[0].vm }}'
220 register: test_vm1_info
221
222 - name: Attach a VM to a dvswitch
223 vmware.vmware_rest.vcenter_vm_hardware_ethernet:
224 vm: '{{ test_vm1_info.id }}'
225 pci_slot_number: 4
226 backing:
227 type: DISTRIBUTED_PORTGROUP
228 network: '{{ my_portgroup.value[0].network }}'
229 start_connected: false
230 register: vm_hardware_ethernet_1
231
232 - name: Turn the NIC's start_connected flag on
233 vmware.vmware_rest.vcenter_vm_hardware_ethernet:
234 nic: '{{ vm_hardware_ethernet_1.id }}'
235 start_connected: true
236 vm: '{{ test_vm1_info.id }}'
237
238 - name: Attach the VM to a standard portgroup
239 vmware.vmware_rest.vcenter_vm_hardware_ethernet:
240 vm: '{{ test_vm1_info.id }}'
241 pci_slot_number: 4
242 backing:
243 type: STANDARD_PORTGROUP
244 network: "{{ lookup('vmware.vmware_rest.network_moid', '/my_dc/network/VM Network') }}"
245 register: _result
246
247 - name: Attach the VM to a standard portgroup (again)
248 vmware.vmware_rest.vcenter_vm_hardware_ethernet:
249 vm: '{{ test_vm1_info.id }}'
250 pci_slot_number: 4
251 backing:
252 type: STANDARD_PORTGROUP
253 network: "{{ lookup('vmware.vmware_rest.network_moid', '/my_dc/network/VM Network') }}"
254 register: _result
255
256 - name: Collect a list of the NIC for a given VM
257 vmware.vmware_rest.vcenter_vm_hardware_ethernet_info:
258 vm: '{{ test_vm1_info.id }}'
259 register: vm_nic
260
261 - name: Attach the VM to a standard portgroup (again) using the nic ID
262 vmware.vmware_rest.vcenter_vm_hardware_ethernet:
263 vm: '{{ test_vm1_info.id }}'
264 nic: '{{ vm_nic.value[0].nic }}'
265 backing:
266 type: STANDARD_PORTGROUP
267 network: "{{ lookup('vmware.vmware_rest.network_moid', '/my_dc/network/VM Network') }}"
268 register: _result
269
270 - name: Attach to another standard portgroup
271 vmware.vmware_rest.vcenter_vm_hardware_ethernet:
272 vm: '{{ test_vm1_info.id }}'
273 nic: '{{ vm_nic.value[0].nic }}'
274 backing:
275 type: STANDARD_PORTGROUP
276 network: "{{ lookup('vmware.vmware_rest.network_moid', '/my_dc/network/second_vswitch') }}"
277 register: _result
278 """
279 RETURN = r"""
280 # content generated by the update_return_section callback# task: Attach a VM to a dvswitch
281 id:
282 description: moid of the resource
283 returned: On success
284 sample: '4000'
285 type: str
286 value:
287 description: Attach a VM to a dvswitch
288 returned: On success
289 sample:
290 allow_guest_control: 0
291 backing:
292 connection_cookie: 632732945
293 distributed_port: '2'
294 distributed_switch_uuid: 50 31 d3 c4 2d 09 4f e3-0f d6 7f 30 3d fe d4 a0
295 network: dvportgroup-1022
296 type: DISTRIBUTED_PORTGROUP
297 label: Network adapter 1
298 mac_address: 00:50:56:b1:33:76
299 mac_type: ASSIGNED
300 pci_slot_number: 4
301 start_connected: 0
302 state: NOT_CONNECTED
303 type: VMXNET3
304 upt_compatibility_enabled: 0
305 wake_on_lan_enabled: 0
306 type: dict
307 """
308
309
310 # This structure describes the format of the data expected by the end-points
311 PAYLOAD_FORMAT = {
312 "connect": {"query": {}, "body": {}, "path": {"nic": "nic", "vm": "vm"}},
313 "create": {
314 "query": {},
315 "body": {
316 "allow_guest_control": "allow_guest_control",
317 "backing": "backing",
318 "mac_address": "mac_address",
319 "mac_type": "mac_type",
320 "pci_slot_number": "pci_slot_number",
321 "start_connected": "start_connected",
322 "type": "type",
323 "upt_compatibility_enabled": "upt_compatibility_enabled",
324 "wake_on_lan_enabled": "wake_on_lan_enabled",
325 },
326 "path": {"vm": "vm"},
327 },
328 "delete": {"query": {}, "body": {}, "path": {"nic": "nic", "vm": "vm"}},
329 "disconnect": {"query": {}, "body": {}, "path": {"nic": "nic", "vm": "vm"}},
330 "update": {
331 "query": {},
332 "body": {
333 "allow_guest_control": "allow_guest_control",
334 "backing": "backing",
335 "mac_address": "mac_address",
336 "mac_type": "mac_type",
337 "start_connected": "start_connected",
338 "upt_compatibility_enabled": "upt_compatibility_enabled",
339 "wake_on_lan_enabled": "wake_on_lan_enabled",
340 },
341 "path": {"nic": "nic", "vm": "vm"},
342 },
343 } # pylint: disable=line-too-long
344
345 from ansible.module_utils.basic import env_fallback
346 import os
347
348 if os.getenv("VMWARE_ENABLE_TURBO", False):
349 try:
350 from ansible_collections.cloud.common.plugins.module_utils.turbo.module import (
351 AnsibleTurboModule as AnsibleModule,
352 )
353
354 AnsibleModule.collection_name = "vmware.vmware_rest"
355 except ImportError:
356 from ansible.module_utils.basic import AnsibleModule
357 else:
358 from ansible.module_utils.basic import AnsibleModule
359
360 from ansible_collections.vmware.vmware_rest.plugins.module_utils.vmware_rest import (
361 exists,
362 gen_args,
363 get_device_info,
364 get_subdevice_type,
365 open_session,
366 prepare_payload,
367 session_timeout,
368 update_changed_flag,
369 )
370
371
372 def prepare_argument_spec():
373 argument_spec = {
374 "vcenter_hostname": dict(
375 type="str",
376 required=True,
377 fallback=(env_fallback, ["VMWARE_HOST"]),
378 ),
379 "vcenter_username": dict(
380 type="str",
381 required=True,
382 fallback=(env_fallback, ["VMWARE_USER"]),
383 ),
384 "vcenter_password": dict(
385 type="str",
386 required=True,
387 no_log=True,
388 fallback=(env_fallback, ["VMWARE_PASSWORD"]),
389 ),
390 "vcenter_validate_certs": dict(
391 type="bool",
392 required=False,
393 default=True,
394 fallback=(env_fallback, ["VMWARE_VALIDATE_CERTS"]),
395 ),
396 "vcenter_rest_log_file": dict(
397 type="str",
398 required=False,
399 fallback=(env_fallback, ["VMWARE_REST_LOG_FILE"]),
400 ),
401 "session_timeout": dict(
402 type="float",
403 required=False,
404 fallback=(env_fallback, ["VMWARE_SESSION_TIMEOUT"]),
405 ),
406 }
407
408 argument_spec["allow_guest_control"] = {"type": "bool"}
409 argument_spec["backing"] = {"type": "dict"}
410 argument_spec["label"] = {"type": "str"}
411 argument_spec["mac_address"] = {"type": "str"}
412 argument_spec["mac_type"] = {
413 "type": "str",
414 "choices": ["ASSIGNED", "GENERATED", "MANUAL"],
415 }
416 argument_spec["nic"] = {"type": "str"}
417 argument_spec["pci_slot_number"] = {"type": "int"}
418 argument_spec["start_connected"] = {"type": "bool"}
419 argument_spec["state"] = {
420 "type": "str",
421 "choices": ["absent", "connect", "disconnect", "present"],
422 "default": "present",
423 }
424 argument_spec["type"] = {
425 "type": "str",
426 "choices": ["E1000", "E1000E", "PCNET32", "VMXNET", "VMXNET2", "VMXNET3"],
427 }
428 argument_spec["upt_compatibility_enabled"] = {"type": "bool"}
429 argument_spec["vm"] = {"required": True, "type": "str"}
430 argument_spec["wake_on_lan_enabled"] = {"type": "bool"}
431
432 return argument_spec
433
434
435 async def main():
436 required_if = list([])
437
438 module_args = prepare_argument_spec()
439 module = AnsibleModule(
440 argument_spec=module_args, required_if=required_if, supports_check_mode=False
441 )
442 if not module.params["vcenter_hostname"]:
443 module.fail_json("vcenter_hostname cannot be empty")
444 if not module.params["vcenter_username"]:
445 module.fail_json("vcenter_username cannot be empty")
446 if not module.params["vcenter_password"]:
447 module.fail_json("vcenter_password cannot be empty")
448 try:
449 session = await open_session(
450 vcenter_hostname=module.params["vcenter_hostname"],
451 vcenter_username=module.params["vcenter_username"],
452 vcenter_password=module.params["vcenter_password"],
453 validate_certs=module.params["vcenter_validate_certs"],
454 log_file=module.params["vcenter_rest_log_file"],
455 )
456 except Exception as err:
457 if hasattr(err, "get_message"):
458 module.fail_json(err.get_message())
459 else:
460 module.fail_json(str(err))
461 result = await entry_point(module, session)
462 module.exit_json(**result)
463
464
465 # template: default_module.j2
466 def build_url(params):
467 return (
468 "https://{vcenter_hostname}" "/api/vcenter/vm/{vm}/hardware/ethernet"
469 ).format(**params)
470
471
472 async def entry_point(module, session):
473
474 if module.params["state"] == "present":
475 if "_create" in globals():
476 operation = "create"
477 else:
478 operation = "update"
479 elif module.params["state"] == "absent":
480 operation = "delete"
481 else:
482 operation = module.params["state"]
483
484 func = globals()["_" + operation]
485
486 return await func(module.params, session)
487
488
489 async def _connect(params, session):
490 _in_query_parameters = PAYLOAD_FORMAT["connect"]["query"].keys()
491 payload = prepare_payload(params, PAYLOAD_FORMAT["connect"])
492 subdevice_type = get_subdevice_type(
493 "/api/vcenter/vm/{vm}/hardware/ethernet/{nic}?action=connect"
494 )
495 if subdevice_type and not params[subdevice_type]:
496 _json = await exists(params, session, build_url(params))
497 if _json:
498 params[subdevice_type] = _json["id"]
499 _url = (
500 "https://{vcenter_hostname}"
501 # aa
502 "/api/vcenter/vm/{vm}/hardware/ethernet/{nic}?action=connect"
503 ).format(**params) + gen_args(params, _in_query_parameters)
504 async with session.post(_url, json=payload, **session_timeout(params)) as resp:
505 try:
506 if resp.headers["Content-Type"] == "application/json":
507 _json = await resp.json()
508 except KeyError:
509 _json = {}
510 if "value" not in _json: # 7.0.2
511 _json = {"value": _json}
512
513 return await update_changed_flag(_json, resp.status, "connect")
514
515
516 async def _create(params, session):
517
518 lookup_url = per_id_url = build_url(params)
519 uniquity_keys = ["nic"]
520 comp_func = None
521
522 async def lookup_with_filters(params, session, url):
523 search_filter = ""
524
525 if "name" not in params:
526 return
527 async with session.get(f"{url}?names={params['name']}{search_filter}") as resp:
528 _json = await resp.json()
529 if isinstance(_json, list) and len(_json) == 1:
530 return await get_device_info(session, url, _json[0]["nic"])
531
532 _json = None
533
534 if params["nic"]:
535 _json = await get_device_info(session, build_url(params), params["nic"])
536
537 if not _json and (uniquity_keys or comp_func):
538 _json = await exists(
539 params,
540 session,
541 url=lookup_url,
542 uniquity_keys=uniquity_keys,
543 per_id_url=per_id_url,
544 comp_func=comp_func,
545 )
546
547 if not _json:
548 _json = await lookup_with_filters(params, session, build_url(params))
549
550 if _json:
551 if "value" not in _json: # 7.0.2+
552 _json = {"value": _json}
553 if "_update" in globals():
554 params["nic"] = _json["id"]
555 return await globals()["_update"](params, session)
556
557 return await update_changed_flag(_json, 200, "get")
558
559 payload = prepare_payload(params, PAYLOAD_FORMAT["create"])
560 _url = (
561 "https://{vcenter_hostname}" "/api/vcenter/vm/{vm}/hardware/ethernet"
562 ).format(**params)
563 async with session.post(_url, json=payload, **session_timeout(params)) as resp:
564 if resp.status == 500:
565 text = await resp.text()
566 raise Exception(f"Request has failed: status={resp.status}, {text}")
567 try:
568 if resp.headers["Content-Type"] == "application/json":
569 _json = await resp.json()
570 except KeyError:
571 _json = {}
572
573 if (resp.status in [200, 201]) and "error" not in _json:
574 if isinstance(_json, str): # 7.0.2 and greater
575 _id = _json # TODO: fetch the object
576 elif isinstance(_json, dict) and "value" not in _json:
577 _id = list(_json["value"].values())[0]
578 elif isinstance(_json, dict) and "value" in _json:
579 _id = _json["value"]
580 _json_device_info = await get_device_info(session, _url, _id)
581 if _json_device_info:
582 _json = _json_device_info
583
584 return await update_changed_flag(_json, resp.status, "create")
585
586
587 async def _delete(params, session):
588 _in_query_parameters = PAYLOAD_FORMAT["delete"]["query"].keys()
589 payload = prepare_payload(params, PAYLOAD_FORMAT["delete"])
590 subdevice_type = get_subdevice_type("/api/vcenter/vm/{vm}/hardware/ethernet/{nic}")
591 if subdevice_type and not params[subdevice_type]:
592 _json = await exists(params, session, build_url(params))
593 if _json:
594 params[subdevice_type] = _json["id"]
595 _url = (
596 "https://{vcenter_hostname}" "/api/vcenter/vm/{vm}/hardware/ethernet/{nic}"
597 ).format(**params) + gen_args(params, _in_query_parameters)
598 async with session.delete(_url, json=payload, **session_timeout(params)) as resp:
599 try:
600 if resp.headers["Content-Type"] == "application/json":
601 _json = await resp.json()
602 except KeyError:
603 _json = {}
604 return await update_changed_flag(_json, resp.status, "delete")
605
606
607 async def _disconnect(params, session):
608 _in_query_parameters = PAYLOAD_FORMAT["disconnect"]["query"].keys()
609 payload = prepare_payload(params, PAYLOAD_FORMAT["disconnect"])
610 subdevice_type = get_subdevice_type(
611 "/api/vcenter/vm/{vm}/hardware/ethernet/{nic}?action=disconnect"
612 )
613 if subdevice_type and not params[subdevice_type]:
614 _json = await exists(params, session, build_url(params))
615 if _json:
616 params[subdevice_type] = _json["id"]
617 _url = (
618 "https://{vcenter_hostname}"
619 # aa
620 "/api/vcenter/vm/{vm}/hardware/ethernet/{nic}?action=disconnect"
621 ).format(**params) + gen_args(params, _in_query_parameters)
622 async with session.post(_url, json=payload, **session_timeout(params)) as resp:
623 try:
624 if resp.headers["Content-Type"] == "application/json":
625 _json = await resp.json()
626 except KeyError:
627 _json = {}
628 if "value" not in _json: # 7.0.2
629 _json = {"value": _json}
630
631 return await update_changed_flag(_json, resp.status, "disconnect")
632
633
634 async def _update(params, session):
635 payload = prepare_payload(params, PAYLOAD_FORMAT["update"])
636 _url = (
637 "https://{vcenter_hostname}" "/api/vcenter/vm/{vm}/hardware/ethernet/{nic}"
638 ).format(**params)
639 async with session.get(_url, **session_timeout(params)) as resp:
640 _json = await resp.json()
641 if "value" in _json:
642 value = _json["value"]
643 else: # 7.0.2 and greater
644 value = _json
645 for k, v in value.items():
646 if k in payload:
647 if isinstance(payload[k], dict) and isinstance(v, dict):
648 to_delete = True
649 for _k in list(payload[k].keys()):
650 if payload[k][_k] != v.get(_k):
651 to_delete = False
652 if to_delete:
653 del payload[k]
654 elif payload[k] == v:
655 del payload[k]
656 elif payload[k] == {}:
657 del payload[k]
658
659 if payload == {} or payload == {"spec": {}}:
660 # Nothing has changed
661 if "value" not in _json: # 7.0.2
662 _json = {"value": _json}
663 _json["id"] = params.get("nic")
664 return await update_changed_flag(_json, resp.status, "get")
665 async with session.patch(_url, json=payload, **session_timeout(params)) as resp:
666 try:
667 if resp.headers["Content-Type"] == "application/json":
668 _json = await resp.json()
669 except KeyError:
670 _json = {}
671 if "value" not in _json: # 7.0.2
672 _json = {"value": _json}
673
674 # e.g: content_configuration
675 if not _json and resp.status == 204:
676 async with session.get(_url, **session_timeout(params)) as resp_get:
677 _json_get = await resp_get.json()
678 if _json_get:
679 _json = _json_get
680
681 _json["id"] = params.get("nic")
682 return await update_changed_flag(_json, resp.status, "update")
683
684
685 if __name__ == "__main__":
686 import asyncio
687
688 current_loop = asyncio.new_event_loop()
689 try:
690 asyncio.set_event_loop(current_loop)
691 current_loop.run_until_complete(main())
692 finally:
693 current_loop.close()