diff --git a/sdk/iothub/azure-mgmt-iothub/azure/mgmt/iothub/operations/iot_hub_operations.py b/sdk/iothub/azure-mgmt-iothub/azure/mgmt/iothub/operations/iot_hub_operations.py index 273da15a077e..073723a53a72 100644 --- a/sdk/iothub/azure-mgmt-iothub/azure/mgmt/iothub/operations/iot_hub_operations.py +++ b/sdk/iothub/azure-mgmt-iothub/azure/mgmt/iothub/operations/iot_hub_operations.py @@ -11,6 +11,8 @@ import uuid from msrest.pipeline import ClientRawResponse +from msrest.polling import LROPoller, NoPolling +from msrestazure.polling.arm_polling import ARMPolling from .. import models @@ -36,29 +38,9 @@ def __init__(self, client, config, serializer, deserializer): self.config = config - def manual_failover( - self, iot_hub_name, resource_group_name, failover_region, custom_headers=None, raw=False, **operation_config): - """Manual Failover Fail over. - - Perform manual fail over of given hub. - :param iot_hub_name: IotHub to fail over - :type iot_hub_name: str - :param resource_group_name: resource group which Iot Hub belongs to - :type resource_group_name: str - :param failover_region: Region the hub will be failed over to - :type failover_region: str - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: IotHubDescription or ClientRawResponse if raw=true - :rtype: ~azure.mgmt.iothub.models.IotHubDescription or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorDetailsException` - """ + def _manual_failover_initial( + self, iot_hub_name, resource_group_name, failover_region, custom_headers=None, raw=False, **operation_config): failover_input = models.FailoverInput(failover_region=failover_region) # Construct URL @@ -76,7 +58,6 @@ def manual_failover( # Construct headers header_parameters = {} - header_parameters['Accept'] = 'application/json' header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) @@ -92,17 +73,56 @@ def manual_failover( request = self._client.post(url, query_parameters, header_parameters, body_content) response = self._client.send(request, stream=False, **operation_config) - if response.status_code not in [200]: + if response.status_code not in [200, 202]: raise models.ErrorDetailsException(self._deserialize, response) - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('IotHubDescription', response) - if raw: - client_raw_response = ClientRawResponse(deserialized, response) + client_raw_response = ClientRawResponse(None, response) return client_raw_response - return deserialized + def manual_failover( + self, iot_hub_name, resource_group_name, failover_region, custom_headers=None, raw=False, polling=True, **operation_config): + """Manual Failover Fail over. + + Perform manual fail over of given hub. + + :param iot_hub_name: IotHub to fail over + :type iot_hub_name: str + :param resource_group_name: resource group which Iot Hub belongs to + :type resource_group_name: str + :param failover_region: Region the hub will be failed over to + :type failover_region: str + :param dict custom_headers: headers that will be added to the request + :param bool raw: The poller return type is ClientRawResponse, the + direct response alongside the deserialized response + :param polling: True for ARMPolling, False for no polling, or a + polling object for personal polling strategy + :return: An instance of LROPoller that returns None or + ClientRawResponse if raw==True + :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or + ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[None]] + :raises: + :class:`ErrorDetailsException` + """ + raw_result = self._manual_failover_initial( + iot_hub_name=iot_hub_name, + resource_group_name=resource_group_name, + failover_region=failover_region, + custom_headers=custom_headers, + raw=True, + **operation_config + ) + + def get_long_running_output(response): + if raw: + client_raw_response = ClientRawResponse(None, response) + return client_raw_response + + lro_delay = operation_config.get( + 'long_running_operation_timeout', + self.config.long_running_operation_timeout) + if polling is True: polling_method = ARMPolling(lro_delay, **operation_config) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) manual_failover.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{iotHubName}/failover'} diff --git a/sdk/iothub/azure-mgmt-iothub/azure/mgmt/iothub/version.py b/sdk/iothub/azure-mgmt-iothub/azure/mgmt/iothub/version.py index feaaf2faf213..0a72a39badd5 100644 --- a/sdk/iothub/azure-mgmt-iothub/azure/mgmt/iothub/version.py +++ b/sdk/iothub/azure-mgmt-iothub/azure/mgmt/iothub/version.py @@ -9,5 +9,5 @@ # regenerated. # -------------------------------------------------------------------------- -VERSION = "0.8.1" +VERSION = "0.8.2"