Source code for azure.mgmt.devtestlabs.operations.labs_operations

# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

import uuid
from msrest.pipeline import ClientRawResponse
from msrestazure.azure_exceptions import CloudError
from msrest.exceptions import DeserializationError
from msrestazure.azure_operation import AzureOperationPoller

from .. import models


[docs]class LabsOperations(object): """LabsOperations operations. :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. :param deserializer: An object model deserializer. :ivar api_version: Client API version. Constant value: "2016-05-15". """ models = models def __init__(self, client, config, serializer, deserializer): self._client = client self._serialize = serializer self._deserialize = deserializer self.api_version = "2016-05-15" self.config = config
[docs] def list_by_subscription( self, expand=None, filter=None, top=None, orderby=None, custom_headers=None, raw=False, **operation_config): """List labs in a subscription. :param expand: Specify the $expand query. Example: 'properties($select=defaultStorageAccount)' :type expand: str :param filter: The filter to apply to the operation. :type filter: str :param top: The maximum number of resources to return from the operation. :type top: int :param orderby: The ordering expression for the results, using OData notation. :type orderby: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: An iterator like instance of Lab :rtype: ~azure.mgmt.devtestlabs.models.LabPaged[~azure.mgmt.devtestlabs.models.Lab] :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ def internal_paging(next_link=None, raw=False): if not next_link: # Construct URL url = '/subscriptions/{subscriptionId}/providers/Microsoft.DevTestLab/labs' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if expand is not None: query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') if filter is not None: query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') if top is not None: query_parameters['$top'] = self._serialize.query("top", top, 'int') if orderby is not None: query_parameters['$orderby'] = self._serialize.query("orderby", orderby, 'str') query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') else: url = next_link query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send( request, header_parameters, stream=False, **operation_config) if response.status_code not in [200]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp return response # Deserialize response deserialized = models.LabPaged(internal_paging, self._deserialize.dependencies) if raw: header_dict = {} client_raw_response = models.LabPaged(internal_paging, self._deserialize.dependencies, header_dict) return client_raw_response return deserialized
[docs] def list_by_resource_group( self, resource_group_name, expand=None, filter=None, top=None, orderby=None, custom_headers=None, raw=False, **operation_config): """List labs in a resource group. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param expand: Specify the $expand query. Example: 'properties($select=defaultStorageAccount)' :type expand: str :param filter: The filter to apply to the operation. :type filter: str :param top: The maximum number of resources to return from the operation. :type top: int :param orderby: The ordering expression for the results, using OData notation. :type orderby: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: An iterator like instance of Lab :rtype: ~azure.mgmt.devtestlabs.models.LabPaged[~azure.mgmt.devtestlabs.models.Lab] :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ def internal_paging(next_link=None, raw=False): if not next_link: # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if expand is not None: query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') if filter is not None: query_parameters['$filter'] = self._serialize.query("filter", filter, 'str') if top is not None: query_parameters['$top'] = self._serialize.query("top", top, 'int') if orderby is not None: query_parameters['$orderby'] = self._serialize.query("orderby", orderby, 'str') query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') else: url = next_link query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send( request, header_parameters, stream=False, **operation_config) if response.status_code not in [200]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp return response # Deserialize response deserialized = models.LabPaged(internal_paging, self._deserialize.dependencies) if raw: header_dict = {} client_raw_response = models.LabPaged(internal_paging, self._deserialize.dependencies, header_dict) return client_raw_response return deserialized
[docs] def get( self, resource_group_name, name, expand=None, custom_headers=None, raw=False, **operation_config): """Get lab. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param name: The name of the lab. :type name: str :param expand: Specify the $expand query. Example: 'properties($select=defaultStorageAccount)' :type expand: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: Lab or ClientRawResponse if raw=true :rtype: ~azure.mgmt.devtestlabs.models.Lab or ~msrest.pipeline.ClientRawResponse :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 'name': self._serialize.url("name", name, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} if expand is not None: query_parameters['$expand'] = self._serialize.query("expand", expand, 'str') query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct and send request request = self._client.get(url, query_parameters) response = self._client.send(request, header_parameters, stream=False, **operation_config) if response.status_code not in [200]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp deserialized = None if response.status_code == 200: deserialized = self._deserialize('Lab', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
def _create_or_update_initial( self, resource_group_name, name, lab, custom_headers=None, raw=False, **operation_config): # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 'name': self._serialize.url("name", name, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct body body_content = self._serialize.body(lab, 'Lab') # Construct and send request request = self._client.put(url, query_parameters) response = self._client.send( request, header_parameters, body_content, stream=False, **operation_config) if response.status_code not in [200, 201]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp deserialized = None if response.status_code == 200: deserialized = self._deserialize('Lab', response) if response.status_code == 201: deserialized = self._deserialize('Lab', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
[docs] def create_or_update( self, resource_group_name, name, lab, custom_headers=None, raw=False, **operation_config): """Create or replace an existing lab. This operation can take a while to complete. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param name: The name of the lab. :type name: str :param lab: A lab. :type lab: ~azure.mgmt.devtestlabs.models.Lab :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :return: An instance of AzureOperationPoller that returns Lab or ClientRawResponse if raw=true :rtype: ~msrestazure.azure_operation.AzureOperationPoller[~azure.mgmt.devtestlabs.models.Lab] or ~msrest.pipeline.ClientRawResponse :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ raw_result = self._create_or_update_initial( resource_group_name=resource_group_name, name=name, lab=lab, custom_headers=custom_headers, raw=True, **operation_config ) if raw: return raw_result # Construct and send request def long_running_send(): return raw_result.response def get_long_running_status(status_link, headers=None): request = self._client.get(status_link) if headers: request.headers.update(headers) header_parameters = {} header_parameters['x-ms-client-request-id'] = raw_result.response.request.headers['x-ms-client-request-id'] return self._client.send( request, header_parameters, stream=False, **operation_config) def get_long_running_output(response): if response.status_code not in [200, 201]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp deserialized = self._deserialize('Lab', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized long_running_operation_timeout = operation_config.get( 'long_running_operation_timeout', self.config.long_running_operation_timeout) return AzureOperationPoller( long_running_send, get_long_running_output, get_long_running_status, long_running_operation_timeout)
def _delete_initial( self, resource_group_name, name, custom_headers=None, raw=False, **operation_config): # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 'name': self._serialize.url("name", name, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct and send request request = self._client.delete(url, query_parameters) response = self._client.send(request, header_parameters, stream=False, **operation_config) if response.status_code not in [202, 204]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response
[docs] def delete( self, resource_group_name, name, custom_headers=None, raw=False, **operation_config): """Delete lab. This operation can take a while to complete. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param name: The name of the lab. :type name: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :return: An instance of AzureOperationPoller that returns None or ClientRawResponse if raw=true :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or ~msrest.pipeline.ClientRawResponse :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ raw_result = self._delete_initial( resource_group_name=resource_group_name, name=name, custom_headers=custom_headers, raw=True, **operation_config ) if raw: return raw_result # Construct and send request def long_running_send(): return raw_result.response def get_long_running_status(status_link, headers=None): request = self._client.get(status_link) if headers: request.headers.update(headers) header_parameters = {} header_parameters['x-ms-client-request-id'] = raw_result.response.request.headers['x-ms-client-request-id'] return self._client.send( request, header_parameters, stream=False, **operation_config) def get_long_running_output(response): if response.status_code not in [202, 204]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response long_running_operation_timeout = operation_config.get( 'long_running_operation_timeout', self.config.long_running_operation_timeout) return AzureOperationPoller( long_running_send, get_long_running_output, get_long_running_status, long_running_operation_timeout)
[docs] def update( self, resource_group_name, name, lab, custom_headers=None, raw=False, **operation_config): """Modify properties of labs. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param name: The name of the lab. :type name: str :param lab: A lab. :type lab: ~azure.mgmt.devtestlabs.models.LabFragment :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: Lab or ClientRawResponse if raw=true :rtype: ~azure.mgmt.devtestlabs.models.Lab or ~msrest.pipeline.ClientRawResponse :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 'name': self._serialize.url("name", name, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct body body_content = self._serialize.body(lab, 'LabFragment') # Construct and send request request = self._client.patch(url, query_parameters) response = self._client.send( request, header_parameters, body_content, stream=False, **operation_config) if response.status_code not in [200]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp deserialized = None if response.status_code == 200: deserialized = self._deserialize('Lab', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
def _claim_any_vm_initial( self, resource_group_name, name, custom_headers=None, raw=False, **operation_config): # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/claimAnyVm' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 'name': self._serialize.url("name", name, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send(request, header_parameters, stream=False, **operation_config) if response.status_code not in [200, 202]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response
[docs] def claim_any_vm( self, resource_group_name, name, custom_headers=None, raw=False, **operation_config): """Claim a random claimable virtual machine in the lab. This operation can take a while to complete. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param name: The name of the lab. :type name: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :return: An instance of AzureOperationPoller that returns None or ClientRawResponse if raw=true :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or ~msrest.pipeline.ClientRawResponse :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ raw_result = self._claim_any_vm_initial( resource_group_name=resource_group_name, name=name, custom_headers=custom_headers, raw=True, **operation_config ) if raw: return raw_result # Construct and send request def long_running_send(): return raw_result.response def get_long_running_status(status_link, headers=None): request = self._client.get(status_link) if headers: request.headers.update(headers) header_parameters = {} header_parameters['x-ms-client-request-id'] = raw_result.response.request.headers['x-ms-client-request-id'] return self._client.send( request, header_parameters, stream=False, **operation_config) def get_long_running_output(response): if response.status_code not in [200, 202]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response long_running_operation_timeout = operation_config.get( 'long_running_operation_timeout', self.config.long_running_operation_timeout) return AzureOperationPoller( long_running_send, get_long_running_output, get_long_running_status, long_running_operation_timeout)
def _create_environment_initial( self, resource_group_name, name, lab_virtual_machine_creation_parameter, custom_headers=None, raw=False, **operation_config): # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/createEnvironment' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 'name': self._serialize.url("name", name, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct body body_content = self._serialize.body(lab_virtual_machine_creation_parameter, 'LabVirtualMachineCreationParameter') # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, stream=False, **operation_config) if response.status_code not in [200, 202]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response
[docs] def create_environment( self, resource_group_name, name, lab_virtual_machine_creation_parameter, custom_headers=None, raw=False, **operation_config): """Create virtual machines in a lab. This operation can take a while to complete. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param name: The name of the lab. :type name: str :param lab_virtual_machine_creation_parameter: Properties for creating a virtual machine. :type lab_virtual_machine_creation_parameter: ~azure.mgmt.devtestlabs.models.LabVirtualMachineCreationParameter :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :return: An instance of AzureOperationPoller that returns None or ClientRawResponse if raw=true :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or ~msrest.pipeline.ClientRawResponse :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ raw_result = self._create_environment_initial( resource_group_name=resource_group_name, name=name, lab_virtual_machine_creation_parameter=lab_virtual_machine_creation_parameter, custom_headers=custom_headers, raw=True, **operation_config ) if raw: return raw_result # Construct and send request def long_running_send(): return raw_result.response def get_long_running_status(status_link, headers=None): request = self._client.get(status_link) if headers: request.headers.update(headers) header_parameters = {} header_parameters['x-ms-client-request-id'] = raw_result.response.request.headers['x-ms-client-request-id'] return self._client.send( request, header_parameters, stream=False, **operation_config) def get_long_running_output(response): if response.status_code not in [200, 202]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response long_running_operation_timeout = operation_config.get( 'long_running_operation_timeout', self.config.long_running_operation_timeout) return AzureOperationPoller( long_running_send, get_long_running_output, get_long_running_status, long_running_operation_timeout)
def _export_resource_usage_initial( self, resource_group_name, name, blob_storage_absolute_sas_uri=None, usage_start_date=None, custom_headers=None, raw=False, **operation_config): export_resource_usage_parameters = models.ExportResourceUsageParameters(blob_storage_absolute_sas_uri=blob_storage_absolute_sas_uri, usage_start_date=usage_start_date) # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/exportResourceUsage' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 'name': self._serialize.url("name", name, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct body body_content = self._serialize.body(export_resource_usage_parameters, 'ExportResourceUsageParameters') # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, stream=False, **operation_config) if response.status_code not in [200, 202]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response
[docs] def export_resource_usage( self, resource_group_name, name, blob_storage_absolute_sas_uri=None, usage_start_date=None, custom_headers=None, raw=False, **operation_config): """Exports the lab resource usage into a storage account This operation can take a while to complete. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param name: The name of the lab. :type name: str :param blob_storage_absolute_sas_uri: The blob storage absolute sas uri with write permission to the container which the usage data needs to be uploaded to. :type blob_storage_absolute_sas_uri: str :param usage_start_date: The start time of the usage. If not provided, usage will be reported since the beginning of data collection. :type usage_start_date: datetime :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :return: An instance of AzureOperationPoller that returns None or ClientRawResponse if raw=true :rtype: ~msrestazure.azure_operation.AzureOperationPoller[None] or ~msrest.pipeline.ClientRawResponse :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ raw_result = self._export_resource_usage_initial( resource_group_name=resource_group_name, name=name, blob_storage_absolute_sas_uri=blob_storage_absolute_sas_uri, usage_start_date=usage_start_date, custom_headers=custom_headers, raw=True, **operation_config ) if raw: return raw_result # Construct and send request def long_running_send(): return raw_result.response def get_long_running_status(status_link, headers=None): request = self._client.get(status_link) if headers: request.headers.update(headers) header_parameters = {} header_parameters['x-ms-client-request-id'] = raw_result.response.request.headers['x-ms-client-request-id'] return self._client.send( request, header_parameters, stream=False, **operation_config) def get_long_running_output(response): if response.status_code not in [200, 202]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp if raw: client_raw_response = ClientRawResponse(None, response) return client_raw_response long_running_operation_timeout = operation_config.get( 'long_running_operation_timeout', self.config.long_running_operation_timeout) return AzureOperationPoller( long_running_send, get_long_running_output, get_long_running_status, long_running_operation_timeout)
[docs] def generate_upload_uri( self, resource_group_name, name, blob_name=None, custom_headers=None, raw=False, **operation_config): """Generate a URI for uploading custom disk images to a Lab. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param name: The name of the lab. :type name: str :param blob_name: The blob name of the upload URI. :type blob_name: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: GenerateUploadUriResponse or ClientRawResponse if raw=true :rtype: ~azure.mgmt.devtestlabs.models.GenerateUploadUriResponse or ~msrest.pipeline.ClientRawResponse :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ generate_upload_uri_parameter = models.GenerateUploadUriParameter(blob_name=blob_name) # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/generateUploadUri' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 'name': self._serialize.url("name", name, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct body body_content = self._serialize.body(generate_upload_uri_parameter, 'GenerateUploadUriParameter') # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, body_content, stream=False, **operation_config) if response.status_code not in [200]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp deserialized = None if response.status_code == 200: deserialized = self._deserialize('GenerateUploadUriResponse', response) if raw: client_raw_response = ClientRawResponse(deserialized, response) return client_raw_response return deserialized
[docs] def list_vhds( self, resource_group_name, name, custom_headers=None, raw=False, **operation_config): """List disk images available for custom image creation. :param resource_group_name: The name of the resource group. :type resource_group_name: str :param name: The name of the lab. :type name: str :param dict custom_headers: headers that will be added to the request :param bool raw: returns the direct response alongside the deserialized response :param operation_config: :ref:`Operation configuration overrides<msrest:optionsforoperations>`. :return: An iterator like instance of LabVhd :rtype: ~azure.mgmt.devtestlabs.models.LabVhdPaged[~azure.mgmt.devtestlabs.models.LabVhd] :raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>` """ def internal_paging(next_link=None, raw=False): if not next_link: # Construct URL url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{name}/listVhds' path_format_arguments = { 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), 'name': self._serialize.url("name", name, 'str') } url = self._client.format_url(url, **path_format_arguments) # Construct parameters query_parameters = {} query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') else: url = next_link query_parameters = {} # Construct headers header_parameters = {} header_parameters['Content-Type'] = 'application/json; charset=utf-8' if self.config.generate_client_request_id: header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') # Construct and send request request = self._client.post(url, query_parameters) response = self._client.send( request, header_parameters, stream=False, **operation_config) if response.status_code not in [200]: exp = CloudError(response) exp.request_id = response.headers.get('x-ms-request-id') raise exp return response # Deserialize response deserialized = models.LabVhdPaged(internal_paging, self._deserialize.dependencies) if raw: header_dict = {} client_raw_response = models.LabVhdPaged(internal_paging, self._deserialize.dependencies, header_dict) return client_raw_response return deserialized