Ejemplo n.º 1
0
def build_url(params):
    if params.get("service"):
        _in_query_parameters = PAYLOAD_FORMAT["get"]["query"].keys()
        return (("https://{vcenter_hostname}"
                 "/api/appliance/services/").format(**params) +
                params["service"] + gen_args(params, _in_query_parameters))
    _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
    return ("https://{vcenter_hostname}"
            "/api/appliance/services").format(**params) + gen_args(
                params, _in_query_parameters)
def build_url(params):
    if params.get("datacenter"):
        _in_query_parameters = PAYLOAD_FORMAT["get"]["query"].keys()
        return (("https://{vcenter_hostname}"
                 "/api/vcenter/datacenter/").format(**params) +
                params["datacenter"] + gen_args(params, _in_query_parameters))
    _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
    return ("https://{vcenter_hostname}"
            "/api/vcenter/datacenter").format(**params) + gen_args(
                params, _in_query_parameters)
def build_url(params):
    if params.get("floppy"):
        _in_query_parameters = PAYLOAD_FORMAT["get"]["query"].keys()
        return (("https://{vcenter_hostname}"
                 "/api/vcenter/vm/{vm}/hardware/floppy/").format(**params) +
                params["floppy"] + gen_args(params, _in_query_parameters))
    _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
    return ("https://{vcenter_hostname}"
            "/api/vcenter/vm/{vm}/hardware/floppy").format(
                **params) + gen_args(params, _in_query_parameters)
def build_url(params):
    if params.get("protocol"):
        _in_query_parameters = PAYLOAD_FORMAT["get"]["query"].keys()
        return (("https://{vcenter_hostname}"
                 "/api/appliance/networking/proxy/").format(**params) +
                params["protocol"] + gen_args(params, _in_query_parameters))
    _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
    return ("https://{vcenter_hostname}"
            "/api/appliance/networking/proxy").format(**params) + gen_args(
                params, _in_query_parameters)
Ejemplo n.º 5
0
def build_url(params):
    if params.get("library_item_id"):
        _in_query_parameters = PAYLOAD_FORMAT["get"]["query"].keys()
        return (("https://{vcenter_hostname}"
                 "/api/content/library/item/").format(**params) +
                params["library_item_id"] +
                gen_args(params, _in_query_parameters))
    _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
    return ("https://{vcenter_hostname}"
            "/api/content/library/item").format(**params) + gen_args(
                params, _in_query_parameters)
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")
Ejemplo n.º 7
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/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")
Ejemplo n.º 9
0
async def _info(params, session):
    payload_format = list(PAYLOAD_FORMAT.values())[0]
    _in_query_parameters = payload_format["query"].keys()
    _url = ("https://{vcenter_hostname}"
            "/api/appliance/health/mem").format(**params) + gen_args(
                params, _in_query_parameters)
    async with session.get(_url, **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, "get")
    def build_url(self, object_type, params):
        try:
            _in_query_parameters = INVENTORY[object_type]["list"][
                "query"].keys()
            if object_type == "resource_pool":
                object_type = object_type.replace("_", "-")
        except KeyError:
            raise AnsibleLookupError("object_type must be one of [%s]." %
                                     ", ".join(list(INVENTORY.keys())))

        return (
            f"https://{self._options['vcenter_hostname']}/api/vcenter/{object_type}"
        ) + gen_args(params, _in_query_parameters)
Ejemplo n.º 11
0
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")
def build_url(params):
    _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
    return ("https://{vcenter_hostname}"
            "/api/appliance/networking/dns/domains").format(
                **params) + gen_args(params, _in_query_parameters)
Ejemplo n.º 13
0
def build_url(params):
    _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
    return ("https://{vcenter_hostname}"
            "/api/appliance/system/storage").format(**params) + gen_args(
                params, _in_query_parameters)
def build_url(params):
    _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
    return ("https://{vcenter_hostname}" "/api/vcenter/folder").format(
        **params
    ) + gen_args(params, _in_query_parameters)
def build_url(params):
    _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
    return ("https://{vcenter_hostname}" "/api/appliance/infraprofile/configs").format(
        **params
    ) + gen_args(params, _in_query_parameters)
def build_url(params):
    _in_query_parameters = PAYLOAD_FORMAT["list"]["query"].keys()
    return ("https://{vcenter_hostname}"
            "/api/vcenter/vm/{vm}/guest/networking/routes").format(
                **params) + gen_args(params, _in_query_parameters)