async def _sync(params, session): _in_query_parameters = PAYLOAD_FORMAT["sync"]["query"].keys() payload = prepare_payload(params, PAYLOAD_FORMAT["sync"]) subdevice_type = get_subdevice_type( "/api/content/subscribed-library/{library_id}?action=sync" ) if subdevice_type and not params[subdevice_type]: _json = await exists(params, session, build_url(params)) if _json: params[subdevice_type] = _json["id"] _url = ( "https://{vcenter_hostname}" # aa "/api/content/subscribed-library/{library_id}?action=sync" ).format(**params) + gen_args(params, _in_query_parameters) async with session.post(_url, json=payload, **session_timeout(params)) as resp: try: if resp.headers["Content-Type"] == "application/json": _json = await resp.json() except KeyError: _json = {} if "value" not in _json: # 7.0.2 _json = {"value": _json} return await update_changed_flag(_json, resp.status, "sync")
async def _set(params, session): _in_query_parameters = PAYLOAD_FORMAT["set"]["query"].keys() payload = prepare_payload(params, PAYLOAD_FORMAT["set"]) subdevice_type = get_subdevice_type("/api/appliance/access/ssh") if subdevice_type and not params[subdevice_type]: _json = await exists(params, session, build_url(params)) if _json: params[subdevice_type] = _json["id"] _url = ("https://{vcenter_hostname}" "/api/appliance/access/ssh").format( **params ) + gen_args(params, _in_query_parameters) async with session.get(_url, json=payload, **session_timeout(params)) as resp: before = await resp.json() async with session.put(_url, json=payload, **session_timeout(params)) as resp: try: if resp.headers["Content-Type"] == "application/json": _json = await resp.json() except KeyError: _json = {} if "value" not in _json: # 7.0.2 _json = {"value": _json} # The PUT answer does not let us know if the resource has actually been # modified if resp.status < 300: async with session.get( _url, json=payload, **session_timeout(params) ) as resp_get: after = await resp_get.json() if before == after: return await update_changed_flag(after, resp_get.status, "get") return await update_changed_flag(_json, resp.status, "set")
async def _set(params, session): _in_query_parameters = PAYLOAD_FORMAT["set"]["query"].keys() payload = prepare_payload(params, PAYLOAD_FORMAT["set"]) subdevice_type = get_subdevice_type( "/api/appliance/networking/dns/servers") if subdevice_type and not params[subdevice_type]: _json = await exists(params, session, build_url(params)) if _json: params[subdevice_type] = _json["id"] _url = ("https://{vcenter_hostname}" "/api/appliance/networking/dns/servers").format( **params) + gen_args(params, _in_query_parameters) async with session.get(_url, json=payload, **session_timeout(params)) as resp: before = await resp.json() async with session.put(_url, json=payload, **session_timeout(params)) as resp: try: if resp.headers["Content-Type"] == "application/json": _json = await resp.json() except KeyError: _json = {} if "value" not in _json: # 7.0.2 _json = {"value": _json} if (resp.status == 500 and "messages" in _json["value"] and _json["value"]["messages"] and "id" in _json["value"]["messages"][0] and _json["value"]["messages"][0]["id"] == "com.vmware.applmgmt.err_operation_failed" and "args" in _json["value"]["messages"][0] and "changing state RUNNING → CLOSED" in _json["value"]["messages"][0]["args"][0]): # vSphere 7.0.2, a network configuration changes of the appliance raise a systemd error, # but the change is applied. The problem can be resolved by a yum update. async with session.get(_url, json=payload, **session_timeout(params)) as resp: _json = {"value": await resp.json()} # The PUT answer does not let us know if the resource has actually been # modified if resp.status < 300: async with session.get(_url, json=payload, **session_timeout(params)) as resp_get: after = await resp_get.json() if before == after: return await update_changed_flag(after, resp_get.status, "get") return await update_changed_flag(_json, resp.status, "set")
async def _delete(params, session): _in_query_parameters = PAYLOAD_FORMAT["delete"]["query"].keys() payload = prepare_payload(params, PAYLOAD_FORMAT["delete"]) subdevice_type = get_subdevice_type("/api/vcenter/datacenter/{datacenter}") if subdevice_type and not params[subdevice_type]: _json = await exists(params, session, build_url(params)) if _json: params[subdevice_type] = _json["id"] _url = ("https://{vcenter_hostname}" "/api/vcenter/datacenter/{datacenter}").format( **params) + gen_args(params, _in_query_parameters) async with session.delete(_url, json=payload, **session_timeout(params)) as resp: try: if resp.headers["Content-Type"] == "application/json": _json = await resp.json() except KeyError: _json = {} return await update_changed_flag(_json, resp.status, "delete")