Пример #1
0
def get_vcenter(connection, vcenter_id):
    """
    Get a single vCenter based on its id.
    This will produce a dict representation
    of a vCenter:
    {
        'username': '******',
        'instanceUuid': '137E2125-73EB-4E1B-BF03-2B6CD396E6AC',
        'monitor': 'false',
        'hostname': '172.16.214.129',
        'meter': 'true',
        'version': '5.5.0',
        'active': 'true',
        'fullname': 'VMware vCenter Server 5.5.0 build-1945287 (Sim)',
        'id': '1'
    }

    :raises VCenterException:
    :param connection:
    :param vcenter_id:
    :return:
    """
    connection.command_path = "vcenter/{0}".format(vcenter_id)
    extra_headers = {connection.header_key: connection.token}
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    res = requests.get(url=url, headers=extra_headers, verify=verify_ssl)
    if res.status_code > 210:
        raise VCenterException("Unable to retrieve vCenter: {0} => {1}".format(
            res.status_code, res.content
        ))
    body = res.content
    return vcenter.parse_vcenter(body)
Пример #2
0
def get_vcenter(connection, vcenter_id):
    """
    Get a single vCenter based on its id.
    This will produce a dict representation
    of a vCenter:
    {
        'username': '******',
        'instanceUuid': '137E2125-73EB-4E1B-BF03-2B6CD396E6AC',
        'monitor': 'false',
        'hostname': '172.16.214.129',
        'meter': 'true',
        'version': '5.5.0',
        'active': 'true',
        'fullname': 'VMware vCenter Server 5.5.0 build-1945287 (Sim)',
        'id': '1'
    }

    :raises VCenterException:
    :param connection:
    :param vcenter_id:
    :return:
    """
    connection.command_path = "vcenter/{0}".format(vcenter_id)
    extra_headers = {connection.header_key: connection.token}
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    res = requests.get(url=url, headers=extra_headers, verify=verify_ssl)
    if res.status_code > 210:
        raise VCenterException("Unable to retrieve vCenter: {0} => {1}".format(
            res.status_code, res.content))
    body = res.content
    return vcenter.parse_vcenter(body)
Пример #3
0
def create_vcenter(connection, vcenter_obj):
    """
    vcenter should be a dict that looks like:

    {
        'hostname': '10.2.3.4',
        'username': '******',
        'password': '******',
        'monitor': 'true'
    }

    :raises VCenterException:
    :param connection:
    :return dict:
    """
    connection.command_path = "vcenter"
    extra_headers = {
        connection.header_key: connection.token,
        'Content-Type': 'text/xml'
    }
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    vcenter_data = _build_vcenter(vcenter_obj)
    res = requests.post(url, headers=extra_headers,
                        data=vcenter_data,
                        verify=verify_ssl)
    if res.status_code > 210:
        raise VCenterException("Unable to create a vCenter: {0} => {1}".format(
            res.status_code, res.content
        ))
    return vcenter.parse_vcenter(res.content)
Пример #4
0
def create_vcenter(connection, vcenter_obj):
    """
    vcenter should be a dict that looks like:

    {
        'hostname': '10.2.3.4',
        'username': '******',
        'password': '******',
        'monitor': 'true'
    }

    :raises VCenterException:
    :param connection:
    :return dict:
    """
    connection.command_path = "vcenter"
    extra_headers = {
        connection.header_key: connection.token,
        'Content-Type': 'text/xml'
    }
    url = connection.build_url()
    verify_ssl = connection.verify_ssl
    vcenter_data = _build_vcenter(vcenter_obj)
    res = requests.post(url,
                        headers=extra_headers,
                        data=vcenter_data,
                        verify=verify_ssl)
    if res.status_code > 210:
        raise VCenterException("Unable to create a vCenter: {0} => {1}".format(
            res.status_code, res.content))
    return vcenter.parse_vcenter(res.content)