Exemplo n.º 1
0
def register(registration_endpoint, worker_group_name, machine_id, cert_path,
             key_path, is_azure_vm, vm_id, azure_resource_id, test_mode):
    """Registers the worker through the automation linked account with the Agent Service.

    Returns:
        The deserialized response from the Agent Service.
    """
    http_client_factory = httpclientfactory.HttpClientFactory(
        cert_path, key_path, test_mode)
    http_client = http_client_factory.create_http_client(sys.version_info)

    no_proxy_http_client_factory = httpclientfactory.HttpClientFactory(
        cert_path, key_path, test_mode, force_no_proxy=True)
    no_proxy_http_client = no_proxy_http_client_factory.create_http_client(
        sys.version_info)

    headers, payload = get_headers_and_payload(worker_group_name, is_azure_vm,
                                               vm_id, azure_resource_id,
                                               cert_path, no_proxy_http_client)
    url = registration_endpoint + "/HybridV2(MachineId='" + machine_id + "')"

    response = http_client.put(url, headers=headers, data=payload)

    if response.status_code != 200:
        raise Exception("Unable to register [status_code=" +
                        str(response.status_code) + "]")

    return json.loads(response.raw_data), payload
def get_metadata_from_imds(http_client):
    """
    Tries to get azurevm metadata from IMDS
    :return: a dictionary of the following format
    {
        "compute": {
            "location": "some-location",
            "name": "some-computer",
            "offer": "some-offer",
            "osType": "Linux",
            "placementGroupId": "",
            "platformFaultDomain": "0",
            "platformUpdateDomain": "0",
            "publisher": "some-publisher",
            "resourceGroupName": "rome-resourceGroup",
            "sku": "some-sku",
            "subscriptionId": "aaaa0000-aa00-aa00-aa00-aaaaaa000000",
            "tags": "",
            "version": "1.1.10",
            "vmId": "bbbb0000-bb00-bb00-bb00-bbbbbb000000",
            "vmSize": "Standard_D1"
        },
        "network": {
            "interface": [
                {
                    "ipv4": {
                        "ipAddress": [
                            {
                                "privateIpAddress": "0.0.0.0",
                                "publicIpAddress": "0.0.0.0"
                            }
                        ],
                        "subnet": [
                            {
                                "address": "10.0.0.0",
                                "prefix": "24"
                            }
                        ]
                    },
                    "ipv6": {
                        "ipAddress": []
                    },
                    "macAddress": "000AAABBB11"
                }
            ]
        }
    }
    """
    try:
        mdUrl = "http://169.254.169.254/metadata/instance?api-version=2017-08-01"
        header = {'Metadata': 'True'}
        response = http_client.get(mdUrl, headers=header)
        jsonObj = json.loads(response.raw_data)
        return jsonObj

    except:
        return None
Exemplo n.º 3
0
def get_metadata_from_imds(http_client):
    """
    Tries to get azurevm metadata from IMDS
    :return: a dictionary of the following format
    {
        "compute": {
            "location": "some-location",
            "name": "some-computer",
            "offer": "some-offer",
            "osType": "Linux",
            "placementGroupId": "",
            "platformFaultDomain": "0",
            "platformUpdateDomain": "0",
            "publisher": "some-publisher",
            "resourceGroupName": "rome-resourceGroup",
            "sku": "some-sku",
            "subscriptionId": "aaaa0000-aa00-aa00-aa00-aaaaaa000000",
            "tags": "",
            "version": "1.1.10",
            "vmId": "bbbb0000-bb00-bb00-bb00-bbbbbb000000",
            "vmSize": "Standard_D1"
        },
        "network": {
            "interface": [
                {
                    "ipv4": {
                        "ipAddress": [
                            {
                                "privateIpAddress": "0.0.0.0",
                                "publicIpAddress": "0.0.0.0"
                            }
                        ],
                        "subnet": [
                            {
                                "address": "10.0.0.0",
                                "prefix": "24"
                            }
                        ]
                    },
                    "ipv6": {
                        "ipAddress": []
                    },
                    "macAddress": "000AAABBB11"
                }
            ]
        }
    }
    """
    try:
        mdUrl = "http://169.254.169.254/metadata/instance?api-version=2017-08-01"
        header = {'Metadata': 'True'}
        response = http_client.get(mdUrl, headers=header)
        jsonObj = json.loads(response.raw_data)
        return jsonObj

    except:
        return None
def register(registration_endpoint, worker_group_name, machine_id, cert_path, key_path, test_mode):
    """Registers the worker through the automation linked account with the Agent Service.

    Returns:
        The deserialized response from the Agent Service.
    """
    headers, payload = get_headers_and_payload(worker_group_name, cert_path)
    url = registration_endpoint + "/HybridV2(MachineId='" + machine_id + "')"

    http_client = CurlHttpClient(cert_path, key_path, test_mode)
    response = http_client.put(url, headers=headers, data=payload)

    if response.status_code != 200:
        raise Exception("Unable to register [reason=" + response.raw_data + "]")

    return json.loads(response.raw_data)
Exemplo n.º 5
0
def register(registration_endpoint, worker_group_name, machine_id, cert_path,
             key_path, test_mode):
    """Registers the worker through the automation linked account with the Agent Service.

    Returns:
        The deserialized response from the Agent Service.
    """
    headers, payload = get_headers_and_payload(worker_group_name, cert_path)
    url = registration_endpoint + "/HybridV2(MachineId='" + machine_id + "')"

    http_client = CurlHttpClient(cert_path, key_path, test_mode)
    response = http_client.put(url, headers=headers, data=payload)

    if response.status_code != 200:
        raise Exception("Unable to register [reason=" + response.raw_data +
                        "]")

    return json.loads(response.raw_data)
def register(registration_endpoint, worker_group_name, machine_id, cert_path, key_path, is_azure_vm, vm_id,
             azure_resource_id, test_mode):
    """Registers the worker through the automation linked account with the Agent Service.

    Returns:
        The deserialized response from the Agent Service.
    """
    http_client_factory = httpclientfactory.HttpClientFactory(cert_path, key_path, test_mode)
    http_client = http_client_factory.create_http_client(sys.version_info)

    no_proxy_http_client_factory = httpclientfactory.HttpClientFactory(cert_path, key_path, test_mode, force_no_proxy=True)
    no_proxy_http_client = no_proxy_http_client_factory.create_http_client(sys.version_info)

    headers, payload = get_headers_and_payload(worker_group_name, is_azure_vm, vm_id, azure_resource_id, cert_path,
                                               no_proxy_http_client)
    url = registration_endpoint + "/HybridV2(MachineId='" + machine_id + "')"

    response = http_client.put(url, headers=headers, data=payload)

    if response.status_code != 200:
        raise Exception("Unable to register [status_code=" + str(response.status_code) + "]")

    return json.loads(response.raw_data), payload