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 license information. 5# Code generated by Microsoft (R) AutoRest Code Generator. 6# Changes may cause incorrect behavior and will be lost if the code is regenerated. 7# -------------------------------------------------------------------------- 8from typing import Any, AsyncIterable, Callable, Dict, Generic, Optional, TypeVar, Union 9import warnings 10 11from azure.core.async_paging import AsyncItemPaged, AsyncList 12from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error 13from azure.core.pipeline import PipelineResponse 14from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest 15from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod 16from azure.mgmt.core.exceptions import ARMErrorFormat 17from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling 18 19from ... import models as _models 20 21T = TypeVar('T') 22ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] 23 24class VirtualMachinesOperations: 25 """VirtualMachinesOperations async operations. 26 27 You should not instantiate this class directly. Instead, you should create a Client instance that 28 instantiates it for you and attaches it as an attribute. 29 30 :ivar models: Alias to model classes used in this operation group. 31 :type models: ~azure.mgmt.compute.v2018_06_01.models 32 :param client: Client for service requests. 33 :param config: Configuration of service client. 34 :param serializer: An object model serializer. 35 :param deserializer: An object model deserializer. 36 """ 37 38 models = _models 39 40 def __init__(self, client, config, serializer, deserializer) -> None: 41 self._client = client 42 self._serialize = serializer 43 self._deserialize = deserializer 44 self._config = config 45 46 def list_by_location( 47 self, 48 location: str, 49 **kwargs: Any 50 ) -> AsyncIterable["_models.VirtualMachineListResult"]: 51 """Gets all the virtual machines under the specified subscription for the specified location. 52 53 :param location: The location for which virtual machines under the subscription are queried. 54 :type location: str 55 :keyword callable cls: A custom type or function that will be passed the direct response 56 :return: An iterator like instance of either VirtualMachineListResult or the result of cls(response) 57 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.compute.v2018_06_01.models.VirtualMachineListResult] 58 :raises: ~azure.core.exceptions.HttpResponseError 59 """ 60 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachineListResult"] 61 error_map = { 62 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 63 } 64 error_map.update(kwargs.pop('error_map', {})) 65 api_version = "2018-06-01" 66 accept = "application/json" 67 68 def prepare_request(next_link=None): 69 # Construct headers 70 header_parameters = {} # type: Dict[str, Any] 71 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 72 73 if not next_link: 74 # Construct URL 75 url = self.list_by_location.metadata['url'] # type: ignore 76 path_format_arguments = { 77 'location': self._serialize.url("location", location, 'str', pattern=r'^[-\w\._]+$'), 78 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 79 } 80 url = self._client.format_url(url, **path_format_arguments) 81 # Construct parameters 82 query_parameters = {} # type: Dict[str, Any] 83 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 84 85 request = self._client.get(url, query_parameters, header_parameters) 86 else: 87 url = next_link 88 query_parameters = {} # type: Dict[str, Any] 89 request = self._client.get(url, query_parameters, header_parameters) 90 return request 91 92 async def extract_data(pipeline_response): 93 deserialized = self._deserialize('VirtualMachineListResult', pipeline_response) 94 list_of_elem = deserialized.value 95 if cls: 96 list_of_elem = cls(list_of_elem) 97 return deserialized.next_link or None, AsyncList(list_of_elem) 98 99 async def get_next(next_link=None): 100 request = prepare_request(next_link) 101 102 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 103 response = pipeline_response.http_response 104 105 if response.status_code not in [200]: 106 map_error(status_code=response.status_code, response=response, error_map=error_map) 107 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 108 109 return pipeline_response 110 111 return AsyncItemPaged( 112 get_next, extract_data 113 ) 114 list_by_location.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/virtualMachines'} # type: ignore 115 116 async def _capture_initial( 117 self, 118 resource_group_name: str, 119 vm_name: str, 120 parameters: "_models.VirtualMachineCaptureParameters", 121 **kwargs: Any 122 ) -> Optional["_models.VirtualMachineCaptureResult"]: 123 cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.VirtualMachineCaptureResult"]] 124 error_map = { 125 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 126 } 127 error_map.update(kwargs.pop('error_map', {})) 128 api_version = "2018-06-01" 129 content_type = kwargs.pop("content_type", "application/json") 130 accept = "application/json" 131 132 # Construct URL 133 url = self._capture_initial.metadata['url'] # type: ignore 134 path_format_arguments = { 135 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 136 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 137 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 138 } 139 url = self._client.format_url(url, **path_format_arguments) 140 141 # Construct parameters 142 query_parameters = {} # type: Dict[str, Any] 143 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 144 145 # Construct headers 146 header_parameters = {} # type: Dict[str, Any] 147 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 148 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 149 150 body_content_kwargs = {} # type: Dict[str, Any] 151 body_content = self._serialize.body(parameters, 'VirtualMachineCaptureParameters') 152 body_content_kwargs['content'] = body_content 153 request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) 154 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 155 response = pipeline_response.http_response 156 157 if response.status_code not in [200, 202]: 158 map_error(status_code=response.status_code, response=response, error_map=error_map) 159 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 160 161 deserialized = None 162 if response.status_code == 200: 163 deserialized = self._deserialize('VirtualMachineCaptureResult', pipeline_response) 164 165 if cls: 166 return cls(pipeline_response, deserialized, {}) 167 168 return deserialized 169 _capture_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/capture'} # type: ignore 170 171 async def begin_capture( 172 self, 173 resource_group_name: str, 174 vm_name: str, 175 parameters: "_models.VirtualMachineCaptureParameters", 176 **kwargs: Any 177 ) -> AsyncLROPoller["_models.VirtualMachineCaptureResult"]: 178 """Captures the VM by copying virtual hard disks of the VM and outputs a template that can be used 179 to create similar VMs. 180 181 :param resource_group_name: The name of the resource group. 182 :type resource_group_name: str 183 :param vm_name: The name of the virtual machine. 184 :type vm_name: str 185 :param parameters: Parameters supplied to the Capture Virtual Machine operation. 186 :type parameters: ~azure.mgmt.compute.v2018_06_01.models.VirtualMachineCaptureParameters 187 :keyword callable cls: A custom type or function that will be passed the direct response 188 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 189 :keyword polling: By default, your polling method will be AsyncARMPolling. 190 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 191 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 192 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 193 :return: An instance of AsyncLROPoller that returns either VirtualMachineCaptureResult or the result of cls(response) 194 :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.compute.v2018_06_01.models.VirtualMachineCaptureResult] 195 :raises ~azure.core.exceptions.HttpResponseError: 196 """ 197 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 198 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachineCaptureResult"] 199 lro_delay = kwargs.pop( 200 'polling_interval', 201 self._config.polling_interval 202 ) 203 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 204 if cont_token is None: 205 raw_result = await self._capture_initial( 206 resource_group_name=resource_group_name, 207 vm_name=vm_name, 208 parameters=parameters, 209 cls=lambda x,y,z: x, 210 **kwargs 211 ) 212 213 kwargs.pop('error_map', None) 214 kwargs.pop('content_type', None) 215 216 def get_long_running_output(pipeline_response): 217 deserialized = self._deserialize('VirtualMachineCaptureResult', pipeline_response) 218 219 if cls: 220 return cls(pipeline_response, deserialized, {}) 221 return deserialized 222 223 path_format_arguments = { 224 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 225 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 226 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 227 } 228 229 if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, path_format_arguments=path_format_arguments, **kwargs) 230 elif polling is False: polling_method = AsyncNoPolling() 231 else: polling_method = polling 232 if cont_token: 233 return AsyncLROPoller.from_continuation_token( 234 polling_method=polling_method, 235 continuation_token=cont_token, 236 client=self._client, 237 deserialization_callback=get_long_running_output 238 ) 239 else: 240 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 241 begin_capture.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/capture'} # type: ignore 242 243 async def _create_or_update_initial( 244 self, 245 resource_group_name: str, 246 vm_name: str, 247 parameters: "_models.VirtualMachine", 248 **kwargs: Any 249 ) -> "_models.VirtualMachine": 250 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachine"] 251 error_map = { 252 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 253 } 254 error_map.update(kwargs.pop('error_map', {})) 255 api_version = "2018-06-01" 256 content_type = kwargs.pop("content_type", "application/json") 257 accept = "application/json" 258 259 # Construct URL 260 url = self._create_or_update_initial.metadata['url'] # type: ignore 261 path_format_arguments = { 262 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 263 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 264 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 265 } 266 url = self._client.format_url(url, **path_format_arguments) 267 268 # Construct parameters 269 query_parameters = {} # type: Dict[str, Any] 270 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 271 272 # Construct headers 273 header_parameters = {} # type: Dict[str, Any] 274 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 275 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 276 277 body_content_kwargs = {} # type: Dict[str, Any] 278 body_content = self._serialize.body(parameters, 'VirtualMachine') 279 body_content_kwargs['content'] = body_content 280 request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) 281 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 282 response = pipeline_response.http_response 283 284 if response.status_code not in [200, 201]: 285 map_error(status_code=response.status_code, response=response, error_map=error_map) 286 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 287 288 if response.status_code == 200: 289 deserialized = self._deserialize('VirtualMachine', pipeline_response) 290 291 if response.status_code == 201: 292 deserialized = self._deserialize('VirtualMachine', pipeline_response) 293 294 if cls: 295 return cls(pipeline_response, deserialized, {}) 296 297 return deserialized 298 _create_or_update_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}'} # type: ignore 299 300 async def begin_create_or_update( 301 self, 302 resource_group_name: str, 303 vm_name: str, 304 parameters: "_models.VirtualMachine", 305 **kwargs: Any 306 ) -> AsyncLROPoller["_models.VirtualMachine"]: 307 """The operation to create or update a virtual machine. 308 309 :param resource_group_name: The name of the resource group. 310 :type resource_group_name: str 311 :param vm_name: The name of the virtual machine. 312 :type vm_name: str 313 :param parameters: Parameters supplied to the Create Virtual Machine operation. 314 :type parameters: ~azure.mgmt.compute.v2018_06_01.models.VirtualMachine 315 :keyword callable cls: A custom type or function that will be passed the direct response 316 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 317 :keyword polling: By default, your polling method will be AsyncARMPolling. 318 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 319 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 320 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 321 :return: An instance of AsyncLROPoller that returns either VirtualMachine or the result of cls(response) 322 :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.compute.v2018_06_01.models.VirtualMachine] 323 :raises ~azure.core.exceptions.HttpResponseError: 324 """ 325 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 326 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachine"] 327 lro_delay = kwargs.pop( 328 'polling_interval', 329 self._config.polling_interval 330 ) 331 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 332 if cont_token is None: 333 raw_result = await self._create_or_update_initial( 334 resource_group_name=resource_group_name, 335 vm_name=vm_name, 336 parameters=parameters, 337 cls=lambda x,y,z: x, 338 **kwargs 339 ) 340 341 kwargs.pop('error_map', None) 342 kwargs.pop('content_type', None) 343 344 def get_long_running_output(pipeline_response): 345 deserialized = self._deserialize('VirtualMachine', pipeline_response) 346 347 if cls: 348 return cls(pipeline_response, deserialized, {}) 349 return deserialized 350 351 path_format_arguments = { 352 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 353 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 354 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 355 } 356 357 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 358 elif polling is False: polling_method = AsyncNoPolling() 359 else: polling_method = polling 360 if cont_token: 361 return AsyncLROPoller.from_continuation_token( 362 polling_method=polling_method, 363 continuation_token=cont_token, 364 client=self._client, 365 deserialization_callback=get_long_running_output 366 ) 367 else: 368 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 369 begin_create_or_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}'} # type: ignore 370 371 async def _update_initial( 372 self, 373 resource_group_name: str, 374 vm_name: str, 375 parameters: "_models.VirtualMachineUpdate", 376 **kwargs: Any 377 ) -> "_models.VirtualMachine": 378 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachine"] 379 error_map = { 380 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 381 } 382 error_map.update(kwargs.pop('error_map', {})) 383 api_version = "2018-06-01" 384 content_type = kwargs.pop("content_type", "application/json") 385 accept = "application/json" 386 387 # Construct URL 388 url = self._update_initial.metadata['url'] # type: ignore 389 path_format_arguments = { 390 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 391 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 392 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 393 } 394 url = self._client.format_url(url, **path_format_arguments) 395 396 # Construct parameters 397 query_parameters = {} # type: Dict[str, Any] 398 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 399 400 # Construct headers 401 header_parameters = {} # type: Dict[str, Any] 402 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 403 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 404 405 body_content_kwargs = {} # type: Dict[str, Any] 406 body_content = self._serialize.body(parameters, 'VirtualMachineUpdate') 407 body_content_kwargs['content'] = body_content 408 request = self._client.patch(url, query_parameters, header_parameters, **body_content_kwargs) 409 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 410 response = pipeline_response.http_response 411 412 if response.status_code not in [200, 201]: 413 map_error(status_code=response.status_code, response=response, error_map=error_map) 414 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 415 416 if response.status_code == 200: 417 deserialized = self._deserialize('VirtualMachine', pipeline_response) 418 419 if response.status_code == 201: 420 deserialized = self._deserialize('VirtualMachine', pipeline_response) 421 422 if cls: 423 return cls(pipeline_response, deserialized, {}) 424 425 return deserialized 426 _update_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}'} # type: ignore 427 428 async def begin_update( 429 self, 430 resource_group_name: str, 431 vm_name: str, 432 parameters: "_models.VirtualMachineUpdate", 433 **kwargs: Any 434 ) -> AsyncLROPoller["_models.VirtualMachine"]: 435 """The operation to update a virtual machine. 436 437 :param resource_group_name: The name of the resource group. 438 :type resource_group_name: str 439 :param vm_name: The name of the virtual machine. 440 :type vm_name: str 441 :param parameters: Parameters supplied to the Update Virtual Machine operation. 442 :type parameters: ~azure.mgmt.compute.v2018_06_01.models.VirtualMachineUpdate 443 :keyword callable cls: A custom type or function that will be passed the direct response 444 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 445 :keyword polling: By default, your polling method will be AsyncARMPolling. 446 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 447 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 448 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 449 :return: An instance of AsyncLROPoller that returns either VirtualMachine or the result of cls(response) 450 :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.compute.v2018_06_01.models.VirtualMachine] 451 :raises ~azure.core.exceptions.HttpResponseError: 452 """ 453 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 454 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachine"] 455 lro_delay = kwargs.pop( 456 'polling_interval', 457 self._config.polling_interval 458 ) 459 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 460 if cont_token is None: 461 raw_result = await self._update_initial( 462 resource_group_name=resource_group_name, 463 vm_name=vm_name, 464 parameters=parameters, 465 cls=lambda x,y,z: x, 466 **kwargs 467 ) 468 469 kwargs.pop('error_map', None) 470 kwargs.pop('content_type', None) 471 472 def get_long_running_output(pipeline_response): 473 deserialized = self._deserialize('VirtualMachine', pipeline_response) 474 475 if cls: 476 return cls(pipeline_response, deserialized, {}) 477 return deserialized 478 479 path_format_arguments = { 480 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 481 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 482 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 483 } 484 485 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 486 elif polling is False: polling_method = AsyncNoPolling() 487 else: polling_method = polling 488 if cont_token: 489 return AsyncLROPoller.from_continuation_token( 490 polling_method=polling_method, 491 continuation_token=cont_token, 492 client=self._client, 493 deserialization_callback=get_long_running_output 494 ) 495 else: 496 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 497 begin_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}'} # type: ignore 498 499 async def _delete_initial( 500 self, 501 resource_group_name: str, 502 vm_name: str, 503 **kwargs: Any 504 ) -> None: 505 cls = kwargs.pop('cls', None) # type: ClsType[None] 506 error_map = { 507 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 508 } 509 error_map.update(kwargs.pop('error_map', {})) 510 api_version = "2018-06-01" 511 512 # Construct URL 513 url = self._delete_initial.metadata['url'] # type: ignore 514 path_format_arguments = { 515 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 516 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 517 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 518 } 519 url = self._client.format_url(url, **path_format_arguments) 520 521 # Construct parameters 522 query_parameters = {} # type: Dict[str, Any] 523 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 524 525 # Construct headers 526 header_parameters = {} # type: Dict[str, Any] 527 528 request = self._client.delete(url, query_parameters, header_parameters) 529 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 530 response = pipeline_response.http_response 531 532 if response.status_code not in [200, 202, 204]: 533 map_error(status_code=response.status_code, response=response, error_map=error_map) 534 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 535 536 if cls: 537 return cls(pipeline_response, None, {}) 538 539 _delete_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}'} # type: ignore 540 541 async def begin_delete( 542 self, 543 resource_group_name: str, 544 vm_name: str, 545 **kwargs: Any 546 ) -> AsyncLROPoller[None]: 547 """The operation to delete a virtual machine. 548 549 :param resource_group_name: The name of the resource group. 550 :type resource_group_name: str 551 :param vm_name: The name of the virtual machine. 552 :type vm_name: str 553 :keyword callable cls: A custom type or function that will be passed the direct response 554 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 555 :keyword polling: By default, your polling method will be AsyncARMPolling. 556 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 557 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 558 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 559 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 560 :rtype: ~azure.core.polling.AsyncLROPoller[None] 561 :raises ~azure.core.exceptions.HttpResponseError: 562 """ 563 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 564 cls = kwargs.pop('cls', None) # type: ClsType[None] 565 lro_delay = kwargs.pop( 566 'polling_interval', 567 self._config.polling_interval 568 ) 569 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 570 if cont_token is None: 571 raw_result = await self._delete_initial( 572 resource_group_name=resource_group_name, 573 vm_name=vm_name, 574 cls=lambda x,y,z: x, 575 **kwargs 576 ) 577 578 kwargs.pop('error_map', None) 579 kwargs.pop('content_type', None) 580 581 def get_long_running_output(pipeline_response): 582 if cls: 583 return cls(pipeline_response, None, {}) 584 585 path_format_arguments = { 586 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 587 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 588 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 589 } 590 591 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 592 elif polling is False: polling_method = AsyncNoPolling() 593 else: polling_method = polling 594 if cont_token: 595 return AsyncLROPoller.from_continuation_token( 596 polling_method=polling_method, 597 continuation_token=cont_token, 598 client=self._client, 599 deserialization_callback=get_long_running_output 600 ) 601 else: 602 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 603 begin_delete.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}'} # type: ignore 604 605 async def get( 606 self, 607 resource_group_name: str, 608 vm_name: str, 609 expand: Optional[str] = "instanceView", 610 **kwargs: Any 611 ) -> "_models.VirtualMachine": 612 """Retrieves information about the model view or the instance view of a virtual machine. 613 614 :param resource_group_name: The name of the resource group. 615 :type resource_group_name: str 616 :param vm_name: The name of the virtual machine. 617 :type vm_name: str 618 :param expand: The expand expression to apply on the operation. 619 :type expand: str 620 :keyword callable cls: A custom type or function that will be passed the direct response 621 :return: VirtualMachine, or the result of cls(response) 622 :rtype: ~azure.mgmt.compute.v2018_06_01.models.VirtualMachine 623 :raises: ~azure.core.exceptions.HttpResponseError 624 """ 625 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachine"] 626 error_map = { 627 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 628 } 629 error_map.update(kwargs.pop('error_map', {})) 630 api_version = "2018-06-01" 631 accept = "application/json" 632 633 # Construct URL 634 url = self.get.metadata['url'] # type: ignore 635 path_format_arguments = { 636 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 637 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 638 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 639 } 640 url = self._client.format_url(url, **path_format_arguments) 641 642 # Construct parameters 643 query_parameters = {} # type: Dict[str, Any] 644 if expand is not None: 645 query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') 646 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 647 648 # Construct headers 649 header_parameters = {} # type: Dict[str, Any] 650 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 651 652 request = self._client.get(url, query_parameters, header_parameters) 653 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 654 response = pipeline_response.http_response 655 656 if response.status_code not in [200]: 657 map_error(status_code=response.status_code, response=response, error_map=error_map) 658 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 659 660 deserialized = self._deserialize('VirtualMachine', pipeline_response) 661 662 if cls: 663 return cls(pipeline_response, deserialized, {}) 664 665 return deserialized 666 get.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}'} # type: ignore 667 668 async def instance_view( 669 self, 670 resource_group_name: str, 671 vm_name: str, 672 **kwargs: Any 673 ) -> "_models.VirtualMachineInstanceView": 674 """Retrieves information about the run-time state of a virtual machine. 675 676 :param resource_group_name: The name of the resource group. 677 :type resource_group_name: str 678 :param vm_name: The name of the virtual machine. 679 :type vm_name: str 680 :keyword callable cls: A custom type or function that will be passed the direct response 681 :return: VirtualMachineInstanceView, or the result of cls(response) 682 :rtype: ~azure.mgmt.compute.v2018_06_01.models.VirtualMachineInstanceView 683 :raises: ~azure.core.exceptions.HttpResponseError 684 """ 685 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachineInstanceView"] 686 error_map = { 687 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 688 } 689 error_map.update(kwargs.pop('error_map', {})) 690 api_version = "2018-06-01" 691 accept = "application/json" 692 693 # Construct URL 694 url = self.instance_view.metadata['url'] # type: ignore 695 path_format_arguments = { 696 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 697 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 698 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 699 } 700 url = self._client.format_url(url, **path_format_arguments) 701 702 # Construct parameters 703 query_parameters = {} # type: Dict[str, Any] 704 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 705 706 # Construct headers 707 header_parameters = {} # type: Dict[str, Any] 708 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 709 710 request = self._client.get(url, query_parameters, header_parameters) 711 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 712 response = pipeline_response.http_response 713 714 if response.status_code not in [200]: 715 map_error(status_code=response.status_code, response=response, error_map=error_map) 716 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 717 718 deserialized = self._deserialize('VirtualMachineInstanceView', pipeline_response) 719 720 if cls: 721 return cls(pipeline_response, deserialized, {}) 722 723 return deserialized 724 instance_view.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/instanceView'} # type: ignore 725 726 async def _convert_to_managed_disks_initial( 727 self, 728 resource_group_name: str, 729 vm_name: str, 730 **kwargs: Any 731 ) -> None: 732 cls = kwargs.pop('cls', None) # type: ClsType[None] 733 error_map = { 734 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 735 } 736 error_map.update(kwargs.pop('error_map', {})) 737 api_version = "2018-06-01" 738 739 # Construct URL 740 url = self._convert_to_managed_disks_initial.metadata['url'] # type: ignore 741 path_format_arguments = { 742 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 743 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 744 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 745 } 746 url = self._client.format_url(url, **path_format_arguments) 747 748 # Construct parameters 749 query_parameters = {} # type: Dict[str, Any] 750 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 751 752 # Construct headers 753 header_parameters = {} # type: Dict[str, Any] 754 755 request = self._client.post(url, query_parameters, header_parameters) 756 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 757 response = pipeline_response.http_response 758 759 if response.status_code not in [200, 202]: 760 map_error(status_code=response.status_code, response=response, error_map=error_map) 761 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 762 763 if cls: 764 return cls(pipeline_response, None, {}) 765 766 _convert_to_managed_disks_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/convertToManagedDisks'} # type: ignore 767 768 async def begin_convert_to_managed_disks( 769 self, 770 resource_group_name: str, 771 vm_name: str, 772 **kwargs: Any 773 ) -> AsyncLROPoller[None]: 774 """Converts virtual machine disks from blob-based to managed disks. Virtual machine must be 775 stop-deallocated before invoking this operation. 776 777 :param resource_group_name: The name of the resource group. 778 :type resource_group_name: str 779 :param vm_name: The name of the virtual machine. 780 :type vm_name: str 781 :keyword callable cls: A custom type or function that will be passed the direct response 782 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 783 :keyword polling: By default, your polling method will be AsyncARMPolling. 784 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 785 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 786 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 787 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 788 :rtype: ~azure.core.polling.AsyncLROPoller[None] 789 :raises ~azure.core.exceptions.HttpResponseError: 790 """ 791 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 792 cls = kwargs.pop('cls', None) # type: ClsType[None] 793 lro_delay = kwargs.pop( 794 'polling_interval', 795 self._config.polling_interval 796 ) 797 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 798 if cont_token is None: 799 raw_result = await self._convert_to_managed_disks_initial( 800 resource_group_name=resource_group_name, 801 vm_name=vm_name, 802 cls=lambda x,y,z: x, 803 **kwargs 804 ) 805 806 kwargs.pop('error_map', None) 807 kwargs.pop('content_type', None) 808 809 def get_long_running_output(pipeline_response): 810 if cls: 811 return cls(pipeline_response, None, {}) 812 813 path_format_arguments = { 814 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 815 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 816 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 817 } 818 819 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 820 elif polling is False: polling_method = AsyncNoPolling() 821 else: polling_method = polling 822 if cont_token: 823 return AsyncLROPoller.from_continuation_token( 824 polling_method=polling_method, 825 continuation_token=cont_token, 826 client=self._client, 827 deserialization_callback=get_long_running_output 828 ) 829 else: 830 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 831 begin_convert_to_managed_disks.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/convertToManagedDisks'} # type: ignore 832 833 async def _deallocate_initial( 834 self, 835 resource_group_name: str, 836 vm_name: str, 837 **kwargs: Any 838 ) -> None: 839 cls = kwargs.pop('cls', None) # type: ClsType[None] 840 error_map = { 841 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 842 } 843 error_map.update(kwargs.pop('error_map', {})) 844 api_version = "2018-06-01" 845 846 # Construct URL 847 url = self._deallocate_initial.metadata['url'] # type: ignore 848 path_format_arguments = { 849 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 850 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 851 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 852 } 853 url = self._client.format_url(url, **path_format_arguments) 854 855 # Construct parameters 856 query_parameters = {} # type: Dict[str, Any] 857 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 858 859 # Construct headers 860 header_parameters = {} # type: Dict[str, Any] 861 862 request = self._client.post(url, query_parameters, header_parameters) 863 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 864 response = pipeline_response.http_response 865 866 if response.status_code not in [200, 202]: 867 map_error(status_code=response.status_code, response=response, error_map=error_map) 868 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 869 870 if cls: 871 return cls(pipeline_response, None, {}) 872 873 _deallocate_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/deallocate'} # type: ignore 874 875 async def begin_deallocate( 876 self, 877 resource_group_name: str, 878 vm_name: str, 879 **kwargs: Any 880 ) -> AsyncLROPoller[None]: 881 """Shuts down the virtual machine and releases the compute resources. You are not billed for the 882 compute resources that this virtual machine uses. 883 884 :param resource_group_name: The name of the resource group. 885 :type resource_group_name: str 886 :param vm_name: The name of the virtual machine. 887 :type vm_name: str 888 :keyword callable cls: A custom type or function that will be passed the direct response 889 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 890 :keyword polling: By default, your polling method will be AsyncARMPolling. 891 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 892 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 893 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 894 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 895 :rtype: ~azure.core.polling.AsyncLROPoller[None] 896 :raises ~azure.core.exceptions.HttpResponseError: 897 """ 898 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 899 cls = kwargs.pop('cls', None) # type: ClsType[None] 900 lro_delay = kwargs.pop( 901 'polling_interval', 902 self._config.polling_interval 903 ) 904 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 905 if cont_token is None: 906 raw_result = await self._deallocate_initial( 907 resource_group_name=resource_group_name, 908 vm_name=vm_name, 909 cls=lambda x,y,z: x, 910 **kwargs 911 ) 912 913 kwargs.pop('error_map', None) 914 kwargs.pop('content_type', None) 915 916 def get_long_running_output(pipeline_response): 917 if cls: 918 return cls(pipeline_response, None, {}) 919 920 path_format_arguments = { 921 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 922 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 923 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 924 } 925 926 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 927 elif polling is False: polling_method = AsyncNoPolling() 928 else: polling_method = polling 929 if cont_token: 930 return AsyncLROPoller.from_continuation_token( 931 polling_method=polling_method, 932 continuation_token=cont_token, 933 client=self._client, 934 deserialization_callback=get_long_running_output 935 ) 936 else: 937 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 938 begin_deallocate.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/deallocate'} # type: ignore 939 940 async def generalize( 941 self, 942 resource_group_name: str, 943 vm_name: str, 944 **kwargs: Any 945 ) -> None: 946 """Sets the state of the virtual machine to generalized. 947 948 :param resource_group_name: The name of the resource group. 949 :type resource_group_name: str 950 :param vm_name: The name of the virtual machine. 951 :type vm_name: str 952 :keyword callable cls: A custom type or function that will be passed the direct response 953 :return: None, or the result of cls(response) 954 :rtype: None 955 :raises: ~azure.core.exceptions.HttpResponseError 956 """ 957 cls = kwargs.pop('cls', None) # type: ClsType[None] 958 error_map = { 959 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 960 } 961 error_map.update(kwargs.pop('error_map', {})) 962 api_version = "2018-06-01" 963 964 # Construct URL 965 url = self.generalize.metadata['url'] # type: ignore 966 path_format_arguments = { 967 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 968 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 969 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 970 } 971 url = self._client.format_url(url, **path_format_arguments) 972 973 # Construct parameters 974 query_parameters = {} # type: Dict[str, Any] 975 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 976 977 # Construct headers 978 header_parameters = {} # type: Dict[str, Any] 979 980 request = self._client.post(url, query_parameters, header_parameters) 981 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 982 response = pipeline_response.http_response 983 984 if response.status_code not in [200]: 985 map_error(status_code=response.status_code, response=response, error_map=error_map) 986 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 987 988 if cls: 989 return cls(pipeline_response, None, {}) 990 991 generalize.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/generalize'} # type: ignore 992 993 def list( 994 self, 995 resource_group_name: str, 996 **kwargs: Any 997 ) -> AsyncIterable["_models.VirtualMachineListResult"]: 998 """Lists all of the virtual machines in the specified resource group. Use the nextLink property in 999 the response to get the next page of virtual machines. 1000 1001 :param resource_group_name: The name of the resource group. 1002 :type resource_group_name: str 1003 :keyword callable cls: A custom type or function that will be passed the direct response 1004 :return: An iterator like instance of either VirtualMachineListResult or the result of cls(response) 1005 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.compute.v2018_06_01.models.VirtualMachineListResult] 1006 :raises: ~azure.core.exceptions.HttpResponseError 1007 """ 1008 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachineListResult"] 1009 error_map = { 1010 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 1011 } 1012 error_map.update(kwargs.pop('error_map', {})) 1013 api_version = "2018-06-01" 1014 accept = "application/json" 1015 1016 def prepare_request(next_link=None): 1017 # Construct headers 1018 header_parameters = {} # type: Dict[str, Any] 1019 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 1020 1021 if not next_link: 1022 # Construct URL 1023 url = self.list.metadata['url'] # type: ignore 1024 path_format_arguments = { 1025 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1026 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1027 } 1028 url = self._client.format_url(url, **path_format_arguments) 1029 # Construct parameters 1030 query_parameters = {} # type: Dict[str, Any] 1031 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 1032 1033 request = self._client.get(url, query_parameters, header_parameters) 1034 else: 1035 url = next_link 1036 query_parameters = {} # type: Dict[str, Any] 1037 request = self._client.get(url, query_parameters, header_parameters) 1038 return request 1039 1040 async def extract_data(pipeline_response): 1041 deserialized = self._deserialize('VirtualMachineListResult', pipeline_response) 1042 list_of_elem = deserialized.value 1043 if cls: 1044 list_of_elem = cls(list_of_elem) 1045 return deserialized.next_link or None, AsyncList(list_of_elem) 1046 1047 async def get_next(next_link=None): 1048 request = prepare_request(next_link) 1049 1050 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1051 response = pipeline_response.http_response 1052 1053 if response.status_code not in [200]: 1054 map_error(status_code=response.status_code, response=response, error_map=error_map) 1055 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1056 1057 return pipeline_response 1058 1059 return AsyncItemPaged( 1060 get_next, extract_data 1061 ) 1062 list.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines'} # type: ignore 1063 1064 def list_all( 1065 self, 1066 **kwargs: Any 1067 ) -> AsyncIterable["_models.VirtualMachineListResult"]: 1068 """Lists all of the virtual machines in the specified subscription. Use the nextLink property in 1069 the response to get the next page of virtual machines. 1070 1071 :keyword callable cls: A custom type or function that will be passed the direct response 1072 :return: An iterator like instance of either VirtualMachineListResult or the result of cls(response) 1073 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.compute.v2018_06_01.models.VirtualMachineListResult] 1074 :raises: ~azure.core.exceptions.HttpResponseError 1075 """ 1076 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachineListResult"] 1077 error_map = { 1078 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 1079 } 1080 error_map.update(kwargs.pop('error_map', {})) 1081 api_version = "2018-06-01" 1082 accept = "application/json" 1083 1084 def prepare_request(next_link=None): 1085 # Construct headers 1086 header_parameters = {} # type: Dict[str, Any] 1087 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 1088 1089 if not next_link: 1090 # Construct URL 1091 url = self.list_all.metadata['url'] # type: ignore 1092 path_format_arguments = { 1093 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1094 } 1095 url = self._client.format_url(url, **path_format_arguments) 1096 # Construct parameters 1097 query_parameters = {} # type: Dict[str, Any] 1098 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 1099 1100 request = self._client.get(url, query_parameters, header_parameters) 1101 else: 1102 url = next_link 1103 query_parameters = {} # type: Dict[str, Any] 1104 request = self._client.get(url, query_parameters, header_parameters) 1105 return request 1106 1107 async def extract_data(pipeline_response): 1108 deserialized = self._deserialize('VirtualMachineListResult', pipeline_response) 1109 list_of_elem = deserialized.value 1110 if cls: 1111 list_of_elem = cls(list_of_elem) 1112 return deserialized.next_link or None, AsyncList(list_of_elem) 1113 1114 async def get_next(next_link=None): 1115 request = prepare_request(next_link) 1116 1117 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1118 response = pipeline_response.http_response 1119 1120 if response.status_code not in [200]: 1121 map_error(status_code=response.status_code, response=response, error_map=error_map) 1122 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1123 1124 return pipeline_response 1125 1126 return AsyncItemPaged( 1127 get_next, extract_data 1128 ) 1129 list_all.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Compute/virtualMachines'} # type: ignore 1130 1131 def list_available_sizes( 1132 self, 1133 resource_group_name: str, 1134 vm_name: str, 1135 **kwargs: Any 1136 ) -> AsyncIterable["_models.VirtualMachineSizeListResult"]: 1137 """Lists all available virtual machine sizes to which the specified virtual machine can be 1138 resized. 1139 1140 :param resource_group_name: The name of the resource group. 1141 :type resource_group_name: str 1142 :param vm_name: The name of the virtual machine. 1143 :type vm_name: str 1144 :keyword callable cls: A custom type or function that will be passed the direct response 1145 :return: An iterator like instance of either VirtualMachineSizeListResult or the result of cls(response) 1146 :rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.compute.v2018_06_01.models.VirtualMachineSizeListResult] 1147 :raises: ~azure.core.exceptions.HttpResponseError 1148 """ 1149 cls = kwargs.pop('cls', None) # type: ClsType["_models.VirtualMachineSizeListResult"] 1150 error_map = { 1151 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 1152 } 1153 error_map.update(kwargs.pop('error_map', {})) 1154 api_version = "2018-06-01" 1155 accept = "application/json" 1156 1157 def prepare_request(next_link=None): 1158 # Construct headers 1159 header_parameters = {} # type: Dict[str, Any] 1160 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 1161 1162 if not next_link: 1163 # Construct URL 1164 url = self.list_available_sizes.metadata['url'] # type: ignore 1165 path_format_arguments = { 1166 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1167 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1168 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1169 } 1170 url = self._client.format_url(url, **path_format_arguments) 1171 # Construct parameters 1172 query_parameters = {} # type: Dict[str, Any] 1173 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 1174 1175 request = self._client.get(url, query_parameters, header_parameters) 1176 else: 1177 url = next_link 1178 query_parameters = {} # type: Dict[str, Any] 1179 request = self._client.get(url, query_parameters, header_parameters) 1180 return request 1181 1182 async def extract_data(pipeline_response): 1183 deserialized = self._deserialize('VirtualMachineSizeListResult', pipeline_response) 1184 list_of_elem = deserialized.value 1185 if cls: 1186 list_of_elem = cls(list_of_elem) 1187 return None, AsyncList(list_of_elem) 1188 1189 async def get_next(next_link=None): 1190 request = prepare_request(next_link) 1191 1192 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1193 response = pipeline_response.http_response 1194 1195 if response.status_code not in [200]: 1196 map_error(status_code=response.status_code, response=response, error_map=error_map) 1197 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1198 1199 return pipeline_response 1200 1201 return AsyncItemPaged( 1202 get_next, extract_data 1203 ) 1204 list_available_sizes.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/vmSizes'} # type: ignore 1205 1206 async def _power_off_initial( 1207 self, 1208 resource_group_name: str, 1209 vm_name: str, 1210 **kwargs: Any 1211 ) -> None: 1212 cls = kwargs.pop('cls', None) # type: ClsType[None] 1213 error_map = { 1214 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 1215 } 1216 error_map.update(kwargs.pop('error_map', {})) 1217 api_version = "2018-06-01" 1218 1219 # Construct URL 1220 url = self._power_off_initial.metadata['url'] # type: ignore 1221 path_format_arguments = { 1222 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1223 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1224 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1225 } 1226 url = self._client.format_url(url, **path_format_arguments) 1227 1228 # Construct parameters 1229 query_parameters = {} # type: Dict[str, Any] 1230 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 1231 1232 # Construct headers 1233 header_parameters = {} # type: Dict[str, Any] 1234 1235 request = self._client.post(url, query_parameters, header_parameters) 1236 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1237 response = pipeline_response.http_response 1238 1239 if response.status_code not in [200, 202]: 1240 map_error(status_code=response.status_code, response=response, error_map=error_map) 1241 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1242 1243 if cls: 1244 return cls(pipeline_response, None, {}) 1245 1246 _power_off_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/powerOff'} # type: ignore 1247 1248 async def begin_power_off( 1249 self, 1250 resource_group_name: str, 1251 vm_name: str, 1252 **kwargs: Any 1253 ) -> AsyncLROPoller[None]: 1254 """The operation to power off (stop) a virtual machine. The virtual machine can be restarted with 1255 the same provisioned resources. You are still charged for this virtual machine. 1256 1257 :param resource_group_name: The name of the resource group. 1258 :type resource_group_name: str 1259 :param vm_name: The name of the virtual machine. 1260 :type vm_name: str 1261 :keyword callable cls: A custom type or function that will be passed the direct response 1262 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 1263 :keyword polling: By default, your polling method will be AsyncARMPolling. 1264 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 1265 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 1266 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 1267 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 1268 :rtype: ~azure.core.polling.AsyncLROPoller[None] 1269 :raises ~azure.core.exceptions.HttpResponseError: 1270 """ 1271 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 1272 cls = kwargs.pop('cls', None) # type: ClsType[None] 1273 lro_delay = kwargs.pop( 1274 'polling_interval', 1275 self._config.polling_interval 1276 ) 1277 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 1278 if cont_token is None: 1279 raw_result = await self._power_off_initial( 1280 resource_group_name=resource_group_name, 1281 vm_name=vm_name, 1282 cls=lambda x,y,z: x, 1283 **kwargs 1284 ) 1285 1286 kwargs.pop('error_map', None) 1287 kwargs.pop('content_type', None) 1288 1289 def get_long_running_output(pipeline_response): 1290 if cls: 1291 return cls(pipeline_response, None, {}) 1292 1293 path_format_arguments = { 1294 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1295 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1296 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1297 } 1298 1299 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 1300 elif polling is False: polling_method = AsyncNoPolling() 1301 else: polling_method = polling 1302 if cont_token: 1303 return AsyncLROPoller.from_continuation_token( 1304 polling_method=polling_method, 1305 continuation_token=cont_token, 1306 client=self._client, 1307 deserialization_callback=get_long_running_output 1308 ) 1309 else: 1310 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 1311 begin_power_off.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/powerOff'} # type: ignore 1312 1313 async def _restart_initial( 1314 self, 1315 resource_group_name: str, 1316 vm_name: str, 1317 **kwargs: Any 1318 ) -> None: 1319 cls = kwargs.pop('cls', None) # type: ClsType[None] 1320 error_map = { 1321 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 1322 } 1323 error_map.update(kwargs.pop('error_map', {})) 1324 api_version = "2018-06-01" 1325 1326 # Construct URL 1327 url = self._restart_initial.metadata['url'] # type: ignore 1328 path_format_arguments = { 1329 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1330 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1331 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1332 } 1333 url = self._client.format_url(url, **path_format_arguments) 1334 1335 # Construct parameters 1336 query_parameters = {} # type: Dict[str, Any] 1337 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 1338 1339 # Construct headers 1340 header_parameters = {} # type: Dict[str, Any] 1341 1342 request = self._client.post(url, query_parameters, header_parameters) 1343 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1344 response = pipeline_response.http_response 1345 1346 if response.status_code not in [200, 202]: 1347 map_error(status_code=response.status_code, response=response, error_map=error_map) 1348 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1349 1350 if cls: 1351 return cls(pipeline_response, None, {}) 1352 1353 _restart_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/restart'} # type: ignore 1354 1355 async def begin_restart( 1356 self, 1357 resource_group_name: str, 1358 vm_name: str, 1359 **kwargs: Any 1360 ) -> AsyncLROPoller[None]: 1361 """The operation to restart a virtual machine. 1362 1363 :param resource_group_name: The name of the resource group. 1364 :type resource_group_name: str 1365 :param vm_name: The name of the virtual machine. 1366 :type vm_name: str 1367 :keyword callable cls: A custom type or function that will be passed the direct response 1368 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 1369 :keyword polling: By default, your polling method will be AsyncARMPolling. 1370 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 1371 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 1372 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 1373 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 1374 :rtype: ~azure.core.polling.AsyncLROPoller[None] 1375 :raises ~azure.core.exceptions.HttpResponseError: 1376 """ 1377 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 1378 cls = kwargs.pop('cls', None) # type: ClsType[None] 1379 lro_delay = kwargs.pop( 1380 'polling_interval', 1381 self._config.polling_interval 1382 ) 1383 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 1384 if cont_token is None: 1385 raw_result = await self._restart_initial( 1386 resource_group_name=resource_group_name, 1387 vm_name=vm_name, 1388 cls=lambda x,y,z: x, 1389 **kwargs 1390 ) 1391 1392 kwargs.pop('error_map', None) 1393 kwargs.pop('content_type', None) 1394 1395 def get_long_running_output(pipeline_response): 1396 if cls: 1397 return cls(pipeline_response, None, {}) 1398 1399 path_format_arguments = { 1400 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1401 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1402 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1403 } 1404 1405 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 1406 elif polling is False: polling_method = AsyncNoPolling() 1407 else: polling_method = polling 1408 if cont_token: 1409 return AsyncLROPoller.from_continuation_token( 1410 polling_method=polling_method, 1411 continuation_token=cont_token, 1412 client=self._client, 1413 deserialization_callback=get_long_running_output 1414 ) 1415 else: 1416 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 1417 begin_restart.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/restart'} # type: ignore 1418 1419 async def _start_initial( 1420 self, 1421 resource_group_name: str, 1422 vm_name: str, 1423 **kwargs: Any 1424 ) -> None: 1425 cls = kwargs.pop('cls', None) # type: ClsType[None] 1426 error_map = { 1427 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 1428 } 1429 error_map.update(kwargs.pop('error_map', {})) 1430 api_version = "2018-06-01" 1431 1432 # Construct URL 1433 url = self._start_initial.metadata['url'] # type: ignore 1434 path_format_arguments = { 1435 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1436 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1437 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1438 } 1439 url = self._client.format_url(url, **path_format_arguments) 1440 1441 # Construct parameters 1442 query_parameters = {} # type: Dict[str, Any] 1443 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 1444 1445 # Construct headers 1446 header_parameters = {} # type: Dict[str, Any] 1447 1448 request = self._client.post(url, query_parameters, header_parameters) 1449 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1450 response = pipeline_response.http_response 1451 1452 if response.status_code not in [200, 202]: 1453 map_error(status_code=response.status_code, response=response, error_map=error_map) 1454 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1455 1456 if cls: 1457 return cls(pipeline_response, None, {}) 1458 1459 _start_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start'} # type: ignore 1460 1461 async def begin_start( 1462 self, 1463 resource_group_name: str, 1464 vm_name: str, 1465 **kwargs: Any 1466 ) -> AsyncLROPoller[None]: 1467 """The operation to start a virtual machine. 1468 1469 :param resource_group_name: The name of the resource group. 1470 :type resource_group_name: str 1471 :param vm_name: The name of the virtual machine. 1472 :type vm_name: str 1473 :keyword callable cls: A custom type or function that will be passed the direct response 1474 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 1475 :keyword polling: By default, your polling method will be AsyncARMPolling. 1476 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 1477 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 1478 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 1479 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 1480 :rtype: ~azure.core.polling.AsyncLROPoller[None] 1481 :raises ~azure.core.exceptions.HttpResponseError: 1482 """ 1483 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 1484 cls = kwargs.pop('cls', None) # type: ClsType[None] 1485 lro_delay = kwargs.pop( 1486 'polling_interval', 1487 self._config.polling_interval 1488 ) 1489 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 1490 if cont_token is None: 1491 raw_result = await self._start_initial( 1492 resource_group_name=resource_group_name, 1493 vm_name=vm_name, 1494 cls=lambda x,y,z: x, 1495 **kwargs 1496 ) 1497 1498 kwargs.pop('error_map', None) 1499 kwargs.pop('content_type', None) 1500 1501 def get_long_running_output(pipeline_response): 1502 if cls: 1503 return cls(pipeline_response, None, {}) 1504 1505 path_format_arguments = { 1506 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1507 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1508 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1509 } 1510 1511 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 1512 elif polling is False: polling_method = AsyncNoPolling() 1513 else: polling_method = polling 1514 if cont_token: 1515 return AsyncLROPoller.from_continuation_token( 1516 polling_method=polling_method, 1517 continuation_token=cont_token, 1518 client=self._client, 1519 deserialization_callback=get_long_running_output 1520 ) 1521 else: 1522 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 1523 begin_start.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start'} # type: ignore 1524 1525 async def _redeploy_initial( 1526 self, 1527 resource_group_name: str, 1528 vm_name: str, 1529 **kwargs: Any 1530 ) -> None: 1531 cls = kwargs.pop('cls', None) # type: ClsType[None] 1532 error_map = { 1533 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 1534 } 1535 error_map.update(kwargs.pop('error_map', {})) 1536 api_version = "2018-06-01" 1537 1538 # Construct URL 1539 url = self._redeploy_initial.metadata['url'] # type: ignore 1540 path_format_arguments = { 1541 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1542 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1543 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1544 } 1545 url = self._client.format_url(url, **path_format_arguments) 1546 1547 # Construct parameters 1548 query_parameters = {} # type: Dict[str, Any] 1549 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 1550 1551 # Construct headers 1552 header_parameters = {} # type: Dict[str, Any] 1553 1554 request = self._client.post(url, query_parameters, header_parameters) 1555 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1556 response = pipeline_response.http_response 1557 1558 if response.status_code not in [200, 202]: 1559 map_error(status_code=response.status_code, response=response, error_map=error_map) 1560 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1561 1562 if cls: 1563 return cls(pipeline_response, None, {}) 1564 1565 _redeploy_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/redeploy'} # type: ignore 1566 1567 async def begin_redeploy( 1568 self, 1569 resource_group_name: str, 1570 vm_name: str, 1571 **kwargs: Any 1572 ) -> AsyncLROPoller[None]: 1573 """Shuts down the virtual machine, moves it to a new node, and powers it back on. 1574 1575 :param resource_group_name: The name of the resource group. 1576 :type resource_group_name: str 1577 :param vm_name: The name of the virtual machine. 1578 :type vm_name: str 1579 :keyword callable cls: A custom type or function that will be passed the direct response 1580 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 1581 :keyword polling: By default, your polling method will be AsyncARMPolling. 1582 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 1583 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 1584 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 1585 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 1586 :rtype: ~azure.core.polling.AsyncLROPoller[None] 1587 :raises ~azure.core.exceptions.HttpResponseError: 1588 """ 1589 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 1590 cls = kwargs.pop('cls', None) # type: ClsType[None] 1591 lro_delay = kwargs.pop( 1592 'polling_interval', 1593 self._config.polling_interval 1594 ) 1595 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 1596 if cont_token is None: 1597 raw_result = await self._redeploy_initial( 1598 resource_group_name=resource_group_name, 1599 vm_name=vm_name, 1600 cls=lambda x,y,z: x, 1601 **kwargs 1602 ) 1603 1604 kwargs.pop('error_map', None) 1605 kwargs.pop('content_type', None) 1606 1607 def get_long_running_output(pipeline_response): 1608 if cls: 1609 return cls(pipeline_response, None, {}) 1610 1611 path_format_arguments = { 1612 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1613 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1614 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1615 } 1616 1617 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 1618 elif polling is False: polling_method = AsyncNoPolling() 1619 else: polling_method = polling 1620 if cont_token: 1621 return AsyncLROPoller.from_continuation_token( 1622 polling_method=polling_method, 1623 continuation_token=cont_token, 1624 client=self._client, 1625 deserialization_callback=get_long_running_output 1626 ) 1627 else: 1628 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 1629 begin_redeploy.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/redeploy'} # type: ignore 1630 1631 async def _reimage_initial( 1632 self, 1633 resource_group_name: str, 1634 vm_name: str, 1635 parameters: Optional["_models.VirtualMachineReimageParameters"] = None, 1636 **kwargs: Any 1637 ) -> None: 1638 cls = kwargs.pop('cls', None) # type: ClsType[None] 1639 error_map = { 1640 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 1641 } 1642 error_map.update(kwargs.pop('error_map', {})) 1643 api_version = "2018-06-01" 1644 content_type = kwargs.pop("content_type", "application/json") 1645 1646 # Construct URL 1647 url = self._reimage_initial.metadata['url'] # type: ignore 1648 path_format_arguments = { 1649 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1650 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1651 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1652 } 1653 url = self._client.format_url(url, **path_format_arguments) 1654 1655 # Construct parameters 1656 query_parameters = {} # type: Dict[str, Any] 1657 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 1658 1659 # Construct headers 1660 header_parameters = {} # type: Dict[str, Any] 1661 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 1662 1663 body_content_kwargs = {} # type: Dict[str, Any] 1664 if parameters is not None: 1665 body_content = self._serialize.body(parameters, 'VirtualMachineReimageParameters') 1666 else: 1667 body_content = None 1668 body_content_kwargs['content'] = body_content 1669 request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) 1670 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1671 response = pipeline_response.http_response 1672 1673 if response.status_code not in [200, 202]: 1674 map_error(status_code=response.status_code, response=response, error_map=error_map) 1675 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1676 1677 if cls: 1678 return cls(pipeline_response, None, {}) 1679 1680 _reimage_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/reimage'} # type: ignore 1681 1682 async def begin_reimage( 1683 self, 1684 resource_group_name: str, 1685 vm_name: str, 1686 parameters: Optional["_models.VirtualMachineReimageParameters"] = None, 1687 **kwargs: Any 1688 ) -> AsyncLROPoller[None]: 1689 """Reimages the virtual machine which has an ephemeral OS disk back to its initial state. 1690 1691 :param resource_group_name: The name of the resource group. 1692 :type resource_group_name: str 1693 :param vm_name: The name of the virtual machine. 1694 :type vm_name: str 1695 :param parameters: Parameters supplied to the Reimage Virtual Machine operation. 1696 :type parameters: ~azure.mgmt.compute.v2018_06_01.models.VirtualMachineReimageParameters 1697 :keyword callable cls: A custom type or function that will be passed the direct response 1698 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 1699 :keyword polling: By default, your polling method will be AsyncARMPolling. 1700 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 1701 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 1702 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 1703 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 1704 :rtype: ~azure.core.polling.AsyncLROPoller[None] 1705 :raises ~azure.core.exceptions.HttpResponseError: 1706 """ 1707 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 1708 cls = kwargs.pop('cls', None) # type: ClsType[None] 1709 lro_delay = kwargs.pop( 1710 'polling_interval', 1711 self._config.polling_interval 1712 ) 1713 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 1714 if cont_token is None: 1715 raw_result = await self._reimage_initial( 1716 resource_group_name=resource_group_name, 1717 vm_name=vm_name, 1718 parameters=parameters, 1719 cls=lambda x,y,z: x, 1720 **kwargs 1721 ) 1722 1723 kwargs.pop('error_map', None) 1724 kwargs.pop('content_type', None) 1725 1726 def get_long_running_output(pipeline_response): 1727 if cls: 1728 return cls(pipeline_response, None, {}) 1729 1730 path_format_arguments = { 1731 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1732 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1733 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1734 } 1735 1736 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 1737 elif polling is False: polling_method = AsyncNoPolling() 1738 else: polling_method = polling 1739 if cont_token: 1740 return AsyncLROPoller.from_continuation_token( 1741 polling_method=polling_method, 1742 continuation_token=cont_token, 1743 client=self._client, 1744 deserialization_callback=get_long_running_output 1745 ) 1746 else: 1747 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 1748 begin_reimage.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/reimage'} # type: ignore 1749 1750 async def _perform_maintenance_initial( 1751 self, 1752 resource_group_name: str, 1753 vm_name: str, 1754 **kwargs: Any 1755 ) -> None: 1756 cls = kwargs.pop('cls', None) # type: ClsType[None] 1757 error_map = { 1758 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 1759 } 1760 error_map.update(kwargs.pop('error_map', {})) 1761 api_version = "2018-06-01" 1762 1763 # Construct URL 1764 url = self._perform_maintenance_initial.metadata['url'] # type: ignore 1765 path_format_arguments = { 1766 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1767 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1768 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1769 } 1770 url = self._client.format_url(url, **path_format_arguments) 1771 1772 # Construct parameters 1773 query_parameters = {} # type: Dict[str, Any] 1774 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 1775 1776 # Construct headers 1777 header_parameters = {} # type: Dict[str, Any] 1778 1779 request = self._client.post(url, query_parameters, header_parameters) 1780 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1781 response = pipeline_response.http_response 1782 1783 if response.status_code not in [200, 202]: 1784 map_error(status_code=response.status_code, response=response, error_map=error_map) 1785 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1786 1787 if cls: 1788 return cls(pipeline_response, None, {}) 1789 1790 _perform_maintenance_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/performMaintenance'} # type: ignore 1791 1792 async def begin_perform_maintenance( 1793 self, 1794 resource_group_name: str, 1795 vm_name: str, 1796 **kwargs: Any 1797 ) -> AsyncLROPoller[None]: 1798 """The operation to perform maintenance on a virtual machine. 1799 1800 :param resource_group_name: The name of the resource group. 1801 :type resource_group_name: str 1802 :param vm_name: The name of the virtual machine. 1803 :type vm_name: str 1804 :keyword callable cls: A custom type or function that will be passed the direct response 1805 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 1806 :keyword polling: By default, your polling method will be AsyncARMPolling. 1807 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 1808 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 1809 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 1810 :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) 1811 :rtype: ~azure.core.polling.AsyncLROPoller[None] 1812 :raises ~azure.core.exceptions.HttpResponseError: 1813 """ 1814 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 1815 cls = kwargs.pop('cls', None) # type: ClsType[None] 1816 lro_delay = kwargs.pop( 1817 'polling_interval', 1818 self._config.polling_interval 1819 ) 1820 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 1821 if cont_token is None: 1822 raw_result = await self._perform_maintenance_initial( 1823 resource_group_name=resource_group_name, 1824 vm_name=vm_name, 1825 cls=lambda x,y,z: x, 1826 **kwargs 1827 ) 1828 1829 kwargs.pop('error_map', None) 1830 kwargs.pop('content_type', None) 1831 1832 def get_long_running_output(pipeline_response): 1833 if cls: 1834 return cls(pipeline_response, None, {}) 1835 1836 path_format_arguments = { 1837 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1838 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1839 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1840 } 1841 1842 if polling is True: polling_method = AsyncARMPolling(lro_delay, path_format_arguments=path_format_arguments, **kwargs) 1843 elif polling is False: polling_method = AsyncNoPolling() 1844 else: polling_method = polling 1845 if cont_token: 1846 return AsyncLROPoller.from_continuation_token( 1847 polling_method=polling_method, 1848 continuation_token=cont_token, 1849 client=self._client, 1850 deserialization_callback=get_long_running_output 1851 ) 1852 else: 1853 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 1854 begin_perform_maintenance.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/performMaintenance'} # type: ignore 1855 1856 async def _run_command_initial( 1857 self, 1858 resource_group_name: str, 1859 vm_name: str, 1860 parameters: "_models.RunCommandInput", 1861 **kwargs: Any 1862 ) -> Optional["_models.RunCommandResult"]: 1863 cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.RunCommandResult"]] 1864 error_map = { 1865 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError 1866 } 1867 error_map.update(kwargs.pop('error_map', {})) 1868 api_version = "2018-06-01" 1869 content_type = kwargs.pop("content_type", "application/json") 1870 accept = "application/json, text/json" 1871 1872 # Construct URL 1873 url = self._run_command_initial.metadata['url'] # type: ignore 1874 path_format_arguments = { 1875 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1876 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1877 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1878 } 1879 url = self._client.format_url(url, **path_format_arguments) 1880 1881 # Construct parameters 1882 query_parameters = {} # type: Dict[str, Any] 1883 query_parameters['api-version'] = self._serialize.query("api_version", api_version, 'str') 1884 1885 # Construct headers 1886 header_parameters = {} # type: Dict[str, Any] 1887 header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') 1888 header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') 1889 1890 body_content_kwargs = {} # type: Dict[str, Any] 1891 body_content = self._serialize.body(parameters, 'RunCommandInput') 1892 body_content_kwargs['content'] = body_content 1893 request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) 1894 pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) 1895 response = pipeline_response.http_response 1896 1897 if response.status_code not in [200, 202]: 1898 map_error(status_code=response.status_code, response=response, error_map=error_map) 1899 raise HttpResponseError(response=response, error_format=ARMErrorFormat) 1900 1901 deserialized = None 1902 if response.status_code == 200: 1903 deserialized = self._deserialize('RunCommandResult', pipeline_response) 1904 1905 if cls: 1906 return cls(pipeline_response, deserialized, {}) 1907 1908 return deserialized 1909 _run_command_initial.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand'} # type: ignore 1910 1911 async def begin_run_command( 1912 self, 1913 resource_group_name: str, 1914 vm_name: str, 1915 parameters: "_models.RunCommandInput", 1916 **kwargs: Any 1917 ) -> AsyncLROPoller["_models.RunCommandResult"]: 1918 """Run command on the VM. 1919 1920 :param resource_group_name: The name of the resource group. 1921 :type resource_group_name: str 1922 :param vm_name: The name of the virtual machine. 1923 :type vm_name: str 1924 :param parameters: Parameters supplied to the Run command operation. 1925 :type parameters: ~azure.mgmt.compute.v2018_06_01.models.RunCommandInput 1926 :keyword callable cls: A custom type or function that will be passed the direct response 1927 :keyword str continuation_token: A continuation token to restart a poller from a saved state. 1928 :keyword polling: By default, your polling method will be AsyncARMPolling. 1929 Pass in False for this operation to not poll, or pass in your own initialized polling object for a personal polling strategy. 1930 :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod 1931 :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. 1932 :return: An instance of AsyncLROPoller that returns either RunCommandResult or the result of cls(response) 1933 :rtype: ~azure.core.polling.AsyncLROPoller[~azure.mgmt.compute.v2018_06_01.models.RunCommandResult] 1934 :raises ~azure.core.exceptions.HttpResponseError: 1935 """ 1936 polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] 1937 cls = kwargs.pop('cls', None) # type: ClsType["_models.RunCommandResult"] 1938 lro_delay = kwargs.pop( 1939 'polling_interval', 1940 self._config.polling_interval 1941 ) 1942 cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] 1943 if cont_token is None: 1944 raw_result = await self._run_command_initial( 1945 resource_group_name=resource_group_name, 1946 vm_name=vm_name, 1947 parameters=parameters, 1948 cls=lambda x,y,z: x, 1949 **kwargs 1950 ) 1951 1952 kwargs.pop('error_map', None) 1953 kwargs.pop('content_type', None) 1954 1955 def get_long_running_output(pipeline_response): 1956 deserialized = self._deserialize('RunCommandResult', pipeline_response) 1957 1958 if cls: 1959 return cls(pipeline_response, deserialized, {}) 1960 return deserialized 1961 1962 path_format_arguments = { 1963 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 1964 'vmName': self._serialize.url("vm_name", vm_name, 'str'), 1965 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), 1966 } 1967 1968 if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, path_format_arguments=path_format_arguments, **kwargs) 1969 elif polling is False: polling_method = AsyncNoPolling() 1970 else: polling_method = polling 1971 if cont_token: 1972 return AsyncLROPoller.from_continuation_token( 1973 polling_method=polling_method, 1974 continuation_token=cont_token, 1975 client=self._client, 1976 deserialization_callback=get_long_running_output 1977 ) 1978 else: 1979 return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) 1980 begin_run_command.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand'} # type: ignore 1981