async def _probe(params, session):
    _in_query_parameters = PAYLOAD_FORMAT["probe"]["query"].keys()
    payload = prepare_payload(params, PAYLOAD_FORMAT["probe"])
    subdevice_type = get_subdevice_type("/api/content/subscribed-library?action=probe")
    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?action=probe"
    ).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, "probe")
Beispiel #2
0
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/local-accounts/global-policy")
    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/local-accounts/global-policy").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")