11
11
12
12
import uuid
13
13
from msrest .pipeline import ClientRawResponse
14
+ from msrest .polling import LROPoller , NoPolling
15
+ from msrestazure .polling .arm_polling import ARMPolling
14
16
15
17
from .. import models
16
18
@@ -36,29 +38,9 @@ def __init__(self, client, config, serializer, deserializer):
36
38
37
39
self .config = config
38
40
39
- def manual_failover (
40
- self , iot_hub_name , resource_group_name , failover_region , custom_headers = None , raw = False , ** operation_config ):
41
- """Manual Failover Fail over.
42
-
43
- Perform manual fail over of given hub.
44
41
45
- :param iot_hub_name: IotHub to fail over
46
- :type iot_hub_name: str
47
- :param resource_group_name: resource group which Iot Hub belongs to
48
- :type resource_group_name: str
49
- :param failover_region: Region the hub will be failed over to
50
- :type failover_region: 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: IotHubDescription or ClientRawResponse if raw=true
57
- :rtype: ~azure.mgmt.iothub.models.IotHubDescription or
58
- ~msrest.pipeline.ClientRawResponse
59
- :raises:
60
- :class:`ErrorDetailsException<azure.mgmt.iothub.models.ErrorDetailsException>`
61
- """
42
+ def _manual_failover_initial (
43
+ self , iot_hub_name , resource_group_name , failover_region , custom_headers = None , raw = False , ** operation_config ):
62
44
failover_input = models .FailoverInput (failover_region = failover_region )
63
45
64
46
# Construct URL
@@ -76,7 +58,6 @@ def manual_failover(
76
58
77
59
# Construct headers
78
60
header_parameters = {}
79
- header_parameters ['Accept' ] = 'application/json'
80
61
header_parameters ['Content-Type' ] = 'application/json; charset=utf-8'
81
62
if self .config .generate_client_request_id :
82
63
header_parameters ['x-ms-client-request-id' ] = str (uuid .uuid1 ())
@@ -92,17 +73,56 @@ def manual_failover(
92
73
request = self ._client .post (url , query_parameters , header_parameters , body_content )
93
74
response = self ._client .send (request , stream = False , ** operation_config )
94
75
95
- if response .status_code not in [200 ]:
76
+ if response .status_code not in [200 , 202 ]:
96
77
raise models .ErrorDetailsException (self ._deserialize , response )
97
78
98
- deserialized = None
99
-
100
- if response .status_code == 200 :
101
- deserialized = self ._deserialize ('IotHubDescription' , response )
102
-
103
79
if raw :
104
- client_raw_response = ClientRawResponse (deserialized , response )
80
+ client_raw_response = ClientRawResponse (None , response )
105
81
return client_raw_response
106
82
107
- return deserialized
83
+ def manual_failover (
84
+ self , iot_hub_name , resource_group_name , failover_region , custom_headers = None , raw = False , polling = True , ** operation_config ):
85
+ """Manual Failover Fail over.
86
+
87
+ Perform manual fail over of given hub.
88
+
89
+ :param iot_hub_name: IotHub to fail over
90
+ :type iot_hub_name: str
91
+ :param resource_group_name: resource group which Iot Hub belongs to
92
+ :type resource_group_name: str
93
+ :param failover_region: Region the hub will be failed over to
94
+ :type failover_region: str
95
+ :param dict custom_headers: headers that will be added to the request
96
+ :param bool raw: The poller return type is ClientRawResponse, the
97
+ direct response alongside the deserialized response
98
+ :param polling: True for ARMPolling, False for no polling, or a
99
+ polling object for personal polling strategy
100
+ :return: An instance of LROPoller that returns None or
101
+ ClientRawResponse<None> if raw==True
102
+ :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or
103
+ ~msrestazure.azure_operation.AzureOperationPoller[~msrest.pipeline.ClientRawResponse[None]]
104
+ :raises:
105
+ :class:`ErrorDetailsException<azure.mgmt.iothub.models.ErrorDetailsException>`
106
+ """
107
+ raw_result = self ._manual_failover_initial (
108
+ iot_hub_name = iot_hub_name ,
109
+ resource_group_name = resource_group_name ,
110
+ failover_region = failover_region ,
111
+ custom_headers = custom_headers ,
112
+ raw = True ,
113
+ ** operation_config
114
+ )
115
+
116
+ def get_long_running_output (response ):
117
+ if raw :
118
+ client_raw_response = ClientRawResponse (None , response )
119
+ return client_raw_response
120
+
121
+ lro_delay = operation_config .get (
122
+ 'long_running_operation_timeout' ,
123
+ self .config .long_running_operation_timeout )
124
+ if polling is True : polling_method = ARMPolling (lro_delay , ** operation_config )
125
+ elif polling is False : polling_method = NoPolling ()
126
+ else : polling_method = polling
127
+ return LROPoller (self ._client , raw_result , get_long_running_output , polling_method )
108
128
manual_failover .metadata = {'url' : '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{iotHubName}/failover' }
0 commit comments