|
| 1 | +# coding=utf-8 |
| 2 | +# -------------------------------------------------------------------------- |
| 3 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +# Licensed under the MIT License. See License.txt in the project root for |
| 5 | +# license information. |
| 6 | +# |
| 7 | +# Code generated by Microsoft (R) AutoRest Code Generator. |
| 8 | +# Changes may cause incorrect behavior and will be lost if the code is |
| 9 | +# regenerated. |
| 10 | +# -------------------------------------------------------------------------- |
| 11 | + |
| 12 | +import uuid |
| 13 | +from msrest.pipeline import ClientRawResponse |
| 14 | +from msrest.polling import LROPoller, NoPolling |
| 15 | +from msrestazure.polling.arm_polling import ARMPolling |
| 16 | + |
| 17 | +from .. import models |
| 18 | + |
| 19 | + |
| 20 | +class VirtualMachinesOperations(object): |
| 21 | + """VirtualMachinesOperations operations. |
| 22 | +
|
| 23 | + You should not instantiate directly this class, but create a Client instance that will create it for you and attach it as attribute. |
| 24 | +
|
| 25 | + :param client: Client for service requests. |
| 26 | + :param config: Configuration of service client. |
| 27 | + :param serializer: An object model serializer. |
| 28 | + :param deserializer: An object model deserializer. |
| 29 | + :ivar api_version: The HDInsight client API Version. Constant value: "2018-06-01-preview". |
| 30 | + """ |
| 31 | + |
| 32 | + models = models |
| 33 | + |
| 34 | + def __init__(self, client, config, serializer, deserializer): |
| 35 | + |
| 36 | + self._client = client |
| 37 | + self._serialize = serializer |
| 38 | + self._deserialize = deserializer |
| 39 | + self.api_version = "2018-06-01-preview" |
| 40 | + |
| 41 | + self.config = config |
| 42 | + |
| 43 | + def list_hosts( |
| 44 | + self, resource_group_name, cluster_name, custom_headers=None, raw=False, **operation_config): |
| 45 | + """Lists the HDInsight clusters hosts. |
| 46 | +
|
| 47 | + :param resource_group_name: The name of the resource group. |
| 48 | + :type resource_group_name: str |
| 49 | + :param cluster_name: The name of the cluster. |
| 50 | + :type cluster_name: str |
| 51 | + :param dict custom_headers: headers that will be added to the request |
| 52 | + :param bool raw: returns the direct response alongside the |
| 53 | + deserialized response |
| 54 | + :param operation_config: :ref:`Operation configuration |
| 55 | + overrides<msrest:optionsforoperations>`. |
| 56 | + :return: HostInfoListResult or ClientRawResponse if raw=true |
| 57 | + :rtype: ~azure.mgmt.hdinsight.models.HostInfoListResult or |
| 58 | + ~msrest.pipeline.ClientRawResponse |
| 59 | + :raises: |
| 60 | + :class:`ErrorResponseException<azure.mgmt.hdinsight.models.ErrorResponseException>` |
| 61 | + """ |
| 62 | + # Construct URL |
| 63 | + url = self.list_hosts.metadata['url'] |
| 64 | + path_format_arguments = { |
| 65 | + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), |
| 66 | + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), |
| 67 | + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str') |
| 68 | + } |
| 69 | + url = self._client.format_url(url, **path_format_arguments) |
| 70 | + |
| 71 | + # Construct parameters |
| 72 | + query_parameters = {} |
| 73 | + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') |
| 74 | + |
| 75 | + # Construct headers |
| 76 | + header_parameters = {} |
| 77 | + header_parameters['Accept'] = 'application/json' |
| 78 | + if self.config.generate_client_request_id: |
| 79 | + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) |
| 80 | + if custom_headers: |
| 81 | + header_parameters.update(custom_headers) |
| 82 | + if self.config.accept_language is not None: |
| 83 | + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') |
| 84 | + |
| 85 | + # Construct and send request |
| 86 | + request = self._client.post(url, query_parameters, header_parameters) |
| 87 | + response = self._client.send(request, stream=False, **operation_config) |
| 88 | + |
| 89 | + if response.status_code not in [200]: |
| 90 | + raise models.ErrorResponseException(self._deserialize, response) |
| 91 | + |
| 92 | + deserialized = None |
| 93 | + if response.status_code == 200: |
| 94 | + deserialized = self._deserialize('HostInfoListResult', response) |
| 95 | + |
| 96 | + if raw: |
| 97 | + client_raw_response = ClientRawResponse(deserialized, response) |
| 98 | + return client_raw_response |
| 99 | + |
| 100 | + return deserialized |
| 101 | + list_hosts.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/listHosts'} |
| 102 | + |
| 103 | + |
| 104 | + def _restart_hosts_initial( |
| 105 | + self, resource_group_name, cluster_name, hosts, custom_headers=None, raw=False, **operation_config): |
| 106 | + # Construct URL |
| 107 | + url = self.restart_hosts.metadata['url'] |
| 108 | + path_format_arguments = { |
| 109 | + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), |
| 110 | + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), |
| 111 | + 'clusterName': self._serialize.url("cluster_name", cluster_name, 'str') |
| 112 | + } |
| 113 | + url = self._client.format_url(url, **path_format_arguments) |
| 114 | + |
| 115 | + # Construct parameters |
| 116 | + query_parameters = {} |
| 117 | + query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') |
| 118 | + |
| 119 | + # Construct headers |
| 120 | + header_parameters = {} |
| 121 | + header_parameters['Content-Type'] = 'application/json; charset=utf-8' |
| 122 | + if self.config.generate_client_request_id: |
| 123 | + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) |
| 124 | + if custom_headers: |
| 125 | + header_parameters.update(custom_headers) |
| 126 | + if self.config.accept_language is not None: |
| 127 | + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') |
| 128 | + |
| 129 | + # Construct body |
| 130 | + body_content = self._serialize.body(hosts, '[str]') |
| 131 | + |
| 132 | + # Construct and send request |
| 133 | + request = self._client.post(url, query_parameters, header_parameters, body_content) |
| 134 | + response = self._client.send(request, stream=False, **operation_config) |
| 135 | + |
| 136 | + if response.status_code not in [200, 202]: |
| 137 | + raise models.ErrorResponseException(self._deserialize, response) |
| 138 | + |
| 139 | + if raw: |
| 140 | + client_raw_response = ClientRawResponse(None, response) |
| 141 | + return client_raw_response |
| 142 | + |
| 143 | + def restart_hosts( |
| 144 | + self, resource_group_name, cluster_name, hosts, custom_headers=None, raw=False, polling=True, **operation_config): |
| 145 | + """Restarts the specified HDInsight cluster hosts. |
| 146 | +
|
| 147 | + :param resource_group_name: The name of the resource group. |
| 148 | + :type resource_group_name: str |
| 149 | + :param cluster_name: The name of the cluster. |
| 150 | + :type cluster_name: str |
| 151 | + :param hosts: The list of hosts to restart |
| 152 | + :type hosts: list[str] |
| 153 | + :param dict custom_headers: headers that will be added to the request |
| 154 | + :param bool raw: The poller return type is ClientRawResponse, the |
| 155 | + direct response alongside the deserialized response |
| 156 | + :param polling: True for ARMPolling, False for no polling, or a |
| 157 | + polling object for personal polling strategy |
| 158 | + :return: An instance of LROPoller that returns None or |
| 159 | + ClientRawResponse<None> if raw==True |
| 160 | + :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or |
| 161 | + ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[None]] |
| 162 | + :raises: |
| 163 | + :class:`ErrorResponseException<azure.mgmt.hdinsight.models.ErrorResponseException>` |
| 164 | + """ |
| 165 | + raw_result = self._restart_hosts_initial( |
| 166 | + resource_group_name=resource_group_name, |
| 167 | + cluster_name=cluster_name, |
| 168 | + hosts=hosts, |
| 169 | + custom_headers=custom_headers, |
| 170 | + raw=True, |
| 171 | + **operation_config |
| 172 | + ) |
| 173 | + |
| 174 | + def get_long_running_output(response): |
| 175 | + if raw: |
| 176 | + client_raw_response = ClientRawResponse(None, response) |
| 177 | + return client_raw_response |
| 178 | + |
| 179 | + lro_delay = operation_config.get( |
| 180 | + 'long_running_operation_timeout', |
| 181 | + self.config.long_running_operation_timeout) |
| 182 | + if polling is True: polling_method = ARMPolling(lro_delay, **operation_config) |
| 183 | + elif polling is False: polling_method = NoPolling() |
| 184 | + else: polling_method = polling |
| 185 | + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) |
| 186 | + restart_hosts.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HDInsight/clusters/{clusterName}/restartHosts'} |
0 commit comments