# 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.
# --------------------------------------------------------------------------

from msrest.service_client import SDKClient
from msrest import Serializer, Deserializer
from msrestazure import AzureConfiguration

from azure.profiles import KnownProfiles, ProfileDefinition
from azure.profiles.multiapiclient import MultiApiClientMixin
from .version import VERSION

class ComputeManagementClientConfiguration(AzureConfiguration):
    """Configuration for ComputeManagementClient
    Note that all parameters used to create this instance are saved as instance
    attributes.

    :param credentials: Credentials needed for the client to connect to Azure.
    :type credentials: :mod:`A msrestazure Credentials
     object<msrestazure.azure_active_directory>`
    :param subscription_id: Subscription credentials which uniquely identify
     Microsoft Azure subscription. The subscription ID forms part of the URI
     for every service call.
    :type subscription_id: str
    :param str base_url: Service URL
    """

    def __init__(
            self, credentials, subscription_id, base_url=None):

        if credentials is None:
            raise ValueError("Parameter 'credentials' must not be None.")
        if subscription_id is None:
            raise ValueError("Parameter 'subscription_id' must not be None.")
        if not base_url:
            base_url = 'https://management.azure.com'

        super(ComputeManagementClientConfiguration, self).__init__(base_url)

        self.add_user_agent('computemanagementclient/{}'.format(VERSION))
        self.add_user_agent('Azure-SDK-For-Python')

        self.credentials = credentials
        self.subscription_id = subscription_id

class ComputeManagementClient(MultiApiClientMixin, SDKClient):
    """Compute Client.

    This ready contains multiple API versions, to help you deal with all Azure clouds
    (Azure Stack, Azure Government, Azure China, etc.).
    By default, uses latest API version available on public Azure.
    For production, you should stick a particular api-version and/or profile.
    The profile sets a mapping between the operation group and an API version.
    The api-version parameter sets the default API version if the operation
    group is not described in the profile.

    :ivar config: Configuration for client.
    :vartype config: ComputeManagementClientConfiguration

    :param credentials: Credentials needed for the client to connect to Azure.
    :type credentials: :mod:`A msrestazure Credentials
     object<msrestazure.azure_active_directory>`
    :param subscription_id: Subscription credentials which uniquely identify
     Microsoft Azure subscription. The subscription ID forms part of the URI
     for every service call.
    :type subscription_id: str
    :param str api_version: API version to use if no profile is provided, or if
     missing in profile.
    :param str base_url: Service URL
    :param profile: A profile definition, from KnownProfiles to dict.
    :type profile: azure.profiles.KnownProfiles
    """

    DEFAULT_API_VERSION = '2019-03-01'
    _PROFILE_TAG = "azure.mgmt.compute.ComputeManagementClient"
    LATEST_PROFILE = ProfileDefinition({
        _PROFILE_TAG: {
            'resource_skus': '2019-04-01',
            'disks': '2018-09-30',
            'snapshots': '2018-09-30',
            None: DEFAULT_API_VERSION
        }},
        _PROFILE_TAG + " latest"
    )

    def __init__(self, credentials, subscription_id, api_version=None, base_url=None, profile=KnownProfiles.default):
        self.config = ComputeManagementClientConfiguration(credentials, subscription_id, base_url)
        super(ComputeManagementClient, self).__init__(
            credentials,
            self.config,
            api_version=api_version,
            profile=profile
        )

############ Generated from here ############

    @classmethod
    def _models_dict(cls, api_version):
        return {k: v for k, v in cls.models(api_version).__dict__.items() if isinstance(v, type)}

    @classmethod
    def models(cls, api_version=DEFAULT_API_VERSION):
        """Module depends on the API version:

           * 2015-06-15: :mod:`v2015_06_15.models<azure.mgmt.compute.v2015_06_15.models>`
           * 2016-03-30: :mod:`v2016_03_30.models<azure.mgmt.compute.v2016_03_30.models>`
           * 2016-04-30-preview: :mod:`v2016_04_30_preview.models<azure.mgmt.compute.v2016_04_30_preview.models>`
           * 2017-03-30: :mod:`v2017_03_30.models<azure.mgmt.compute.v2017_03_30.models>`
           * 2017-09-01: :mod:`v2017_09_01.models<azure.mgmt.compute.v2017_09_01.models>`
           * 2017-12-01: :mod:`v2017_12_01.models<azure.mgmt.compute.v2017_12_01.models>`
           * 2018-04-01: :mod:`v2018_04_01.models<azure.mgmt.compute.v2018_04_01.models>`
           * 2018-06-01: :mod:`v2018_06_01.models<azure.mgmt.compute.v2018_06_01.models>`
           * 2018-09-30: :mod:`v2018_09_30.models<azure.mgmt.compute.v2018_09_30.models>`
           * 2018-10-01: :mod:`v2018_10_01.models<azure.mgmt.compute.v2018_10_01.models>`
           * 2019-03-01: :mod:`v2019_03_01.models<azure.mgmt.compute.v2019_03_01.models>`
           * 2019-04-01: :mod:`v2019_04_01.models<azure.mgmt.compute.v2019_04_01.models>`
        """
        if api_version == '2015-06-15':
            from .v2015_06_15 import models
            return models
        elif api_version == '2016-03-30':
            from .v2016_03_30 import models
            return models
        elif api_version == '2016-04-30-preview':
            from .v2016_04_30_preview import models
            return models
        elif api_version == '2017-03-30':
            from .v2017_03_30 import models
            return models
        elif api_version == '2017-09-01':
            from .v2017_09_01 import models
            return models
        elif api_version == '2017-12-01':
            from .v2017_12_01 import models
            return models
        elif api_version == '2018-04-01':
            from .v2018_04_01 import models
            return models
        elif api_version == '2018-06-01':
            from .v2018_06_01 import models
            return models
        elif api_version == '2018-09-30':
            from .v2018_09_30 import models
            return models
        elif api_version == '2018-10-01':
            from .v2018_10_01 import models
            return models
        elif api_version == '2019-03-01':
            from .v2019_03_01 import models
            return models
        elif api_version == '2019-04-01':
            from .v2019_04_01 import models
            return models
        raise NotImplementedError("APIVersion {} is not available".format(api_version))

    @property
    def availability_sets(self):
        """Instance depends on the API version:

           * 2015-06-15: :class:`AvailabilitySetsOperations<azure.mgmt.compute.v2015_06_15.operations.AvailabilitySetsOperations>`
           * 2016-03-30: :class:`AvailabilitySetsOperations<azure.mgmt.compute.v2016_03_30.operations.AvailabilitySetsOperations>`
           * 2016-04-30-preview: :class:`AvailabilitySetsOperations<azure.mgmt.compute.v2016_04_30_preview.operations.AvailabilitySetsOperations>`
           * 2017-03-30: :class:`AvailabilitySetsOperations<azure.mgmt.compute.v2017_03_30.operations.AvailabilitySetsOperations>`
           * 2017-12-01: :class:`AvailabilitySetsOperations<azure.mgmt.compute.v2017_12_01.operations.AvailabilitySetsOperations>`
           * 2018-04-01: :class:`AvailabilitySetsOperations<azure.mgmt.compute.v2018_04_01.operations.AvailabilitySetsOperations>`
           * 2018-06-01: :class:`AvailabilitySetsOperations<azure.mgmt.compute.v2018_06_01.operations.AvailabilitySetsOperations>`
           * 2018-10-01: :class:`AvailabilitySetsOperations<azure.mgmt.compute.v2018_10_01.operations.AvailabilitySetsOperations>`
           * 2019-03-01: :class:`AvailabilitySetsOperations<azure.mgmt.compute.v2019_03_01.operations.AvailabilitySetsOperations>`
        """
        api_version = self._get_api_version('availability_sets')
        if api_version == '2015-06-15':
            from .v2015_06_15.operations import AvailabilitySetsOperations as OperationClass
        elif api_version == '2016-03-30':
            from .v2016_03_30.operations import AvailabilitySetsOperations as OperationClass
        elif api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import AvailabilitySetsOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import AvailabilitySetsOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import AvailabilitySetsOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import AvailabilitySetsOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import AvailabilitySetsOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import AvailabilitySetsOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import AvailabilitySetsOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def disks(self):
        """Instance depends on the API version:

           * 2016-04-30-preview: :class:`DisksOperations<azure.mgmt.compute.v2016_04_30_preview.operations.DisksOperations>`
           * 2017-03-30: :class:`DisksOperations<azure.mgmt.compute.v2017_03_30.operations.DisksOperations>`
           * 2018-04-01: :class:`DisksOperations<azure.mgmt.compute.v2018_04_01.operations.DisksOperations>`
           * 2018-06-01: :class:`DisksOperations<azure.mgmt.compute.v2018_06_01.operations.DisksOperations>`
           * 2018-09-30: :class:`DisksOperations<azure.mgmt.compute.v2018_09_30.operations.DisksOperations>`
        """
        api_version = self._get_api_version('disks')
        if api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import DisksOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import DisksOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import DisksOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import DisksOperations as OperationClass
        elif api_version == '2018-09-30':
            from .v2018_09_30.operations import DisksOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def galleries(self):
        """Instance depends on the API version:

           * 2018-06-01: :class:`GalleriesOperations<azure.mgmt.compute.v2018_06_01.operations.GalleriesOperations>`
           * 2019-03-01: :class:`GalleriesOperations<azure.mgmt.compute.v2019_03_01.operations.GalleriesOperations>`
        """
        api_version = self._get_api_version('galleries')
        if api_version == '2018-06-01':
            from .v2018_06_01.operations import GalleriesOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import GalleriesOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def gallery_image_versions(self):
        """Instance depends on the API version:

           * 2018-06-01: :class:`GalleryImageVersionsOperations<azure.mgmt.compute.v2018_06_01.operations.GalleryImageVersionsOperations>`
           * 2019-03-01: :class:`GalleryImageVersionsOperations<azure.mgmt.compute.v2019_03_01.operations.GalleryImageVersionsOperations>`
        """
        api_version = self._get_api_version('gallery_image_versions')
        if api_version == '2018-06-01':
            from .v2018_06_01.operations import GalleryImageVersionsOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import GalleryImageVersionsOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def gallery_images(self):
        """Instance depends on the API version:

           * 2018-06-01: :class:`GalleryImagesOperations<azure.mgmt.compute.v2018_06_01.operations.GalleryImagesOperations>`
           * 2019-03-01: :class:`GalleryImagesOperations<azure.mgmt.compute.v2019_03_01.operations.GalleryImagesOperations>`
        """
        api_version = self._get_api_version('gallery_images')
        if api_version == '2018-06-01':
            from .v2018_06_01.operations import GalleryImagesOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import GalleryImagesOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def images(self):
        """Instance depends on the API version:

           * 2016-04-30-preview: :class:`ImagesOperations<azure.mgmt.compute.v2016_04_30_preview.operations.ImagesOperations>`
           * 2017-03-30: :class:`ImagesOperations<azure.mgmt.compute.v2017_03_30.operations.ImagesOperations>`
           * 2017-12-01: :class:`ImagesOperations<azure.mgmt.compute.v2017_12_01.operations.ImagesOperations>`
           * 2018-04-01: :class:`ImagesOperations<azure.mgmt.compute.v2018_04_01.operations.ImagesOperations>`
           * 2018-06-01: :class:`ImagesOperations<azure.mgmt.compute.v2018_06_01.operations.ImagesOperations>`
           * 2018-10-01: :class:`ImagesOperations<azure.mgmt.compute.v2018_10_01.operations.ImagesOperations>`
           * 2019-03-01: :class:`ImagesOperations<azure.mgmt.compute.v2019_03_01.operations.ImagesOperations>`
        """
        api_version = self._get_api_version('images')
        if api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import ImagesOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import ImagesOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import ImagesOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import ImagesOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import ImagesOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import ImagesOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import ImagesOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def log_analytics(self):
        """Instance depends on the API version:

           * 2017-12-01: :class:`LogAnalyticsOperations<azure.mgmt.compute.v2017_12_01.operations.LogAnalyticsOperations>`
           * 2018-04-01: :class:`LogAnalyticsOperations<azure.mgmt.compute.v2018_04_01.operations.LogAnalyticsOperations>`
           * 2018-06-01: :class:`LogAnalyticsOperations<azure.mgmt.compute.v2018_06_01.operations.LogAnalyticsOperations>`
           * 2018-10-01: :class:`LogAnalyticsOperations<azure.mgmt.compute.v2018_10_01.operations.LogAnalyticsOperations>`
           * 2019-03-01: :class:`LogAnalyticsOperations<azure.mgmt.compute.v2019_03_01.operations.LogAnalyticsOperations>`
        """
        api_version = self._get_api_version('log_analytics')
        if api_version == '2017-12-01':
            from .v2017_12_01.operations import LogAnalyticsOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import LogAnalyticsOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import LogAnalyticsOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import LogAnalyticsOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import LogAnalyticsOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def operations(self):
        """Instance depends on the API version:

           * 2017-12-01: :class:`Operations<azure.mgmt.compute.v2017_12_01.operations.Operations>`
           * 2018-04-01: :class:`Operations<azure.mgmt.compute.v2018_04_01.operations.Operations>`
           * 2018-06-01: :class:`Operations<azure.mgmt.compute.v2018_06_01.operations.Operations>`
           * 2018-10-01: :class:`Operations<azure.mgmt.compute.v2018_10_01.operations.Operations>`
           * 2019-03-01: :class:`Operations<azure.mgmt.compute.v2019_03_01.operations.Operations>`
        """
        api_version = self._get_api_version('operations')
        if api_version == '2017-12-01':
            from .v2017_12_01.operations import Operations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import Operations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import Operations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import Operations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import Operations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def proximity_placement_groups(self):
        """Instance depends on the API version:

           * 2018-04-01: :class:`ProximityPlacementGroupsOperations<azure.mgmt.compute.v2018_04_01.operations.ProximityPlacementGroupsOperations>`
           * 2018-06-01: :class:`ProximityPlacementGroupsOperations<azure.mgmt.compute.v2018_06_01.operations.ProximityPlacementGroupsOperations>`
           * 2018-10-01: :class:`ProximityPlacementGroupsOperations<azure.mgmt.compute.v2018_10_01.operations.ProximityPlacementGroupsOperations>`
           * 2019-03-01: :class:`ProximityPlacementGroupsOperations<azure.mgmt.compute.v2019_03_01.operations.ProximityPlacementGroupsOperations>`
        """
        api_version = self._get_api_version('proximity_placement_groups')
        if api_version == '2018-04-01':
            from .v2018_04_01.operations import ProximityPlacementGroupsOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import ProximityPlacementGroupsOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import ProximityPlacementGroupsOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import ProximityPlacementGroupsOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def resource_skus(self):
        """Instance depends on the API version:

           * 2017-03-30: :class:`ResourceSkusOperations<azure.mgmt.compute.v2017_03_30.operations.ResourceSkusOperations>`
           * 2017-09-01: :class:`ResourceSkusOperations<azure.mgmt.compute.v2017_09_01.operations.ResourceSkusOperations>`
           * 2019-04-01: :class:`ResourceSkusOperations<azure.mgmt.compute.v2019_04_01.operations.ResourceSkusOperations>`
        """
        api_version = self._get_api_version('resource_skus')
        if api_version == '2017-03-30':
            from .v2017_03_30.operations import ResourceSkusOperations as OperationClass
        elif api_version == '2017-09-01':
            from .v2017_09_01.operations import ResourceSkusOperations as OperationClass
        elif api_version == '2019-04-01':
            from .v2019_04_01.operations import ResourceSkusOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def snapshots(self):
        """Instance depends on the API version:

           * 2016-04-30-preview: :class:`SnapshotsOperations<azure.mgmt.compute.v2016_04_30_preview.operations.SnapshotsOperations>`
           * 2017-03-30: :class:`SnapshotsOperations<azure.mgmt.compute.v2017_03_30.operations.SnapshotsOperations>`
           * 2018-04-01: :class:`SnapshotsOperations<azure.mgmt.compute.v2018_04_01.operations.SnapshotsOperations>`
           * 2018-06-01: :class:`SnapshotsOperations<azure.mgmt.compute.v2018_06_01.operations.SnapshotsOperations>`
           * 2018-09-30: :class:`SnapshotsOperations<azure.mgmt.compute.v2018_09_30.operations.SnapshotsOperations>`
        """
        api_version = self._get_api_version('snapshots')
        if api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import SnapshotsOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import SnapshotsOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import SnapshotsOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import SnapshotsOperations as OperationClass
        elif api_version == '2018-09-30':
            from .v2018_09_30.operations import SnapshotsOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def usage(self):
        """Instance depends on the API version:

           * 2015-06-15: :class:`UsageOperations<azure.mgmt.compute.v2015_06_15.operations.UsageOperations>`
           * 2016-03-30: :class:`UsageOperations<azure.mgmt.compute.v2016_03_30.operations.UsageOperations>`
           * 2016-04-30-preview: :class:`UsageOperations<azure.mgmt.compute.v2016_04_30_preview.operations.UsageOperations>`
           * 2017-03-30: :class:`UsageOperations<azure.mgmt.compute.v2017_03_30.operations.UsageOperations>`
           * 2017-12-01: :class:`UsageOperations<azure.mgmt.compute.v2017_12_01.operations.UsageOperations>`
           * 2018-04-01: :class:`UsageOperations<azure.mgmt.compute.v2018_04_01.operations.UsageOperations>`
           * 2018-06-01: :class:`UsageOperations<azure.mgmt.compute.v2018_06_01.operations.UsageOperations>`
           * 2018-10-01: :class:`UsageOperations<azure.mgmt.compute.v2018_10_01.operations.UsageOperations>`
           * 2019-03-01: :class:`UsageOperations<azure.mgmt.compute.v2019_03_01.operations.UsageOperations>`
        """
        api_version = self._get_api_version('usage')
        if api_version == '2015-06-15':
            from .v2015_06_15.operations import UsageOperations as OperationClass
        elif api_version == '2016-03-30':
            from .v2016_03_30.operations import UsageOperations as OperationClass
        elif api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import UsageOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import UsageOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import UsageOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import UsageOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import UsageOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import UsageOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import UsageOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def virtual_machine_extension_images(self):
        """Instance depends on the API version:

           * 2015-06-15: :class:`VirtualMachineExtensionImagesOperations<azure.mgmt.compute.v2015_06_15.operations.VirtualMachineExtensionImagesOperations>`
           * 2016-03-30: :class:`VirtualMachineExtensionImagesOperations<azure.mgmt.compute.v2016_03_30.operations.VirtualMachineExtensionImagesOperations>`
           * 2016-04-30-preview: :class:`VirtualMachineExtensionImagesOperations<azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineExtensionImagesOperations>`
           * 2017-03-30: :class:`VirtualMachineExtensionImagesOperations<azure.mgmt.compute.v2017_03_30.operations.VirtualMachineExtensionImagesOperations>`
           * 2017-12-01: :class:`VirtualMachineExtensionImagesOperations<azure.mgmt.compute.v2017_12_01.operations.VirtualMachineExtensionImagesOperations>`
           * 2018-04-01: :class:`VirtualMachineExtensionImagesOperations<azure.mgmt.compute.v2018_04_01.operations.VirtualMachineExtensionImagesOperations>`
           * 2018-06-01: :class:`VirtualMachineExtensionImagesOperations<azure.mgmt.compute.v2018_06_01.operations.VirtualMachineExtensionImagesOperations>`
           * 2018-10-01: :class:`VirtualMachineExtensionImagesOperations<azure.mgmt.compute.v2018_10_01.operations.VirtualMachineExtensionImagesOperations>`
           * 2019-03-01: :class:`VirtualMachineExtensionImagesOperations<azure.mgmt.compute.v2019_03_01.operations.VirtualMachineExtensionImagesOperations>`
        """
        api_version = self._get_api_version('virtual_machine_extension_images')
        if api_version == '2015-06-15':
            from .v2015_06_15.operations import VirtualMachineExtensionImagesOperations as OperationClass
        elif api_version == '2016-03-30':
            from .v2016_03_30.operations import VirtualMachineExtensionImagesOperations as OperationClass
        elif api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import VirtualMachineExtensionImagesOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import VirtualMachineExtensionImagesOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import VirtualMachineExtensionImagesOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import VirtualMachineExtensionImagesOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import VirtualMachineExtensionImagesOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import VirtualMachineExtensionImagesOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import VirtualMachineExtensionImagesOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def virtual_machine_extensions(self):
        """Instance depends on the API version:

           * 2015-06-15: :class:`VirtualMachineExtensionsOperations<azure.mgmt.compute.v2015_06_15.operations.VirtualMachineExtensionsOperations>`
           * 2016-03-30: :class:`VirtualMachineExtensionsOperations<azure.mgmt.compute.v2016_03_30.operations.VirtualMachineExtensionsOperations>`
           * 2016-04-30-preview: :class:`VirtualMachineExtensionsOperations<azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineExtensionsOperations>`
           * 2017-03-30: :class:`VirtualMachineExtensionsOperations<azure.mgmt.compute.v2017_03_30.operations.VirtualMachineExtensionsOperations>`
           * 2017-12-01: :class:`VirtualMachineExtensionsOperations<azure.mgmt.compute.v2017_12_01.operations.VirtualMachineExtensionsOperations>`
           * 2018-04-01: :class:`VirtualMachineExtensionsOperations<azure.mgmt.compute.v2018_04_01.operations.VirtualMachineExtensionsOperations>`
           * 2018-06-01: :class:`VirtualMachineExtensionsOperations<azure.mgmt.compute.v2018_06_01.operations.VirtualMachineExtensionsOperations>`
           * 2018-10-01: :class:`VirtualMachineExtensionsOperations<azure.mgmt.compute.v2018_10_01.operations.VirtualMachineExtensionsOperations>`
           * 2019-03-01: :class:`VirtualMachineExtensionsOperations<azure.mgmt.compute.v2019_03_01.operations.VirtualMachineExtensionsOperations>`
        """
        api_version = self._get_api_version('virtual_machine_extensions')
        if api_version == '2015-06-15':
            from .v2015_06_15.operations import VirtualMachineExtensionsOperations as OperationClass
        elif api_version == '2016-03-30':
            from .v2016_03_30.operations import VirtualMachineExtensionsOperations as OperationClass
        elif api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import VirtualMachineExtensionsOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import VirtualMachineExtensionsOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import VirtualMachineExtensionsOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import VirtualMachineExtensionsOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import VirtualMachineExtensionsOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import VirtualMachineExtensionsOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import VirtualMachineExtensionsOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def virtual_machine_images(self):
        """Instance depends on the API version:

           * 2015-06-15: :class:`VirtualMachineImagesOperations<azure.mgmt.compute.v2015_06_15.operations.VirtualMachineImagesOperations>`
           * 2016-03-30: :class:`VirtualMachineImagesOperations<azure.mgmt.compute.v2016_03_30.operations.VirtualMachineImagesOperations>`
           * 2016-04-30-preview: :class:`VirtualMachineImagesOperations<azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineImagesOperations>`
           * 2017-03-30: :class:`VirtualMachineImagesOperations<azure.mgmt.compute.v2017_03_30.operations.VirtualMachineImagesOperations>`
           * 2017-12-01: :class:`VirtualMachineImagesOperations<azure.mgmt.compute.v2017_12_01.operations.VirtualMachineImagesOperations>`
           * 2018-04-01: :class:`VirtualMachineImagesOperations<azure.mgmt.compute.v2018_04_01.operations.VirtualMachineImagesOperations>`
           * 2018-06-01: :class:`VirtualMachineImagesOperations<azure.mgmt.compute.v2018_06_01.operations.VirtualMachineImagesOperations>`
           * 2018-10-01: :class:`VirtualMachineImagesOperations<azure.mgmt.compute.v2018_10_01.operations.VirtualMachineImagesOperations>`
           * 2019-03-01: :class:`VirtualMachineImagesOperations<azure.mgmt.compute.v2019_03_01.operations.VirtualMachineImagesOperations>`
        """
        api_version = self._get_api_version('virtual_machine_images')
        if api_version == '2015-06-15':
            from .v2015_06_15.operations import VirtualMachineImagesOperations as OperationClass
        elif api_version == '2016-03-30':
            from .v2016_03_30.operations import VirtualMachineImagesOperations as OperationClass
        elif api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import VirtualMachineImagesOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import VirtualMachineImagesOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import VirtualMachineImagesOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import VirtualMachineImagesOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import VirtualMachineImagesOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import VirtualMachineImagesOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import VirtualMachineImagesOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def virtual_machine_run_commands(self):
        """Instance depends on the API version:

           * 2017-03-30: :class:`VirtualMachineRunCommandsOperations<azure.mgmt.compute.v2017_03_30.operations.VirtualMachineRunCommandsOperations>`
           * 2017-12-01: :class:`VirtualMachineRunCommandsOperations<azure.mgmt.compute.v2017_12_01.operations.VirtualMachineRunCommandsOperations>`
           * 2018-04-01: :class:`VirtualMachineRunCommandsOperations<azure.mgmt.compute.v2018_04_01.operations.VirtualMachineRunCommandsOperations>`
           * 2018-06-01: :class:`VirtualMachineRunCommandsOperations<azure.mgmt.compute.v2018_06_01.operations.VirtualMachineRunCommandsOperations>`
           * 2018-10-01: :class:`VirtualMachineRunCommandsOperations<azure.mgmt.compute.v2018_10_01.operations.VirtualMachineRunCommandsOperations>`
           * 2019-03-01: :class:`VirtualMachineRunCommandsOperations<azure.mgmt.compute.v2019_03_01.operations.VirtualMachineRunCommandsOperations>`
        """
        api_version = self._get_api_version('virtual_machine_run_commands')
        if api_version == '2017-03-30':
            from .v2017_03_30.operations import VirtualMachineRunCommandsOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import VirtualMachineRunCommandsOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import VirtualMachineRunCommandsOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import VirtualMachineRunCommandsOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import VirtualMachineRunCommandsOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import VirtualMachineRunCommandsOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def virtual_machine_scale_set_extensions(self):
        """Instance depends on the API version:

           * 2017-03-30: :class:`VirtualMachineScaleSetExtensionsOperations<azure.mgmt.compute.v2017_03_30.operations.VirtualMachineScaleSetExtensionsOperations>`
           * 2017-12-01: :class:`VirtualMachineScaleSetExtensionsOperations<azure.mgmt.compute.v2017_12_01.operations.VirtualMachineScaleSetExtensionsOperations>`
           * 2018-04-01: :class:`VirtualMachineScaleSetExtensionsOperations<azure.mgmt.compute.v2018_04_01.operations.VirtualMachineScaleSetExtensionsOperations>`
           * 2018-06-01: :class:`VirtualMachineScaleSetExtensionsOperations<azure.mgmt.compute.v2018_06_01.operations.VirtualMachineScaleSetExtensionsOperations>`
           * 2018-10-01: :class:`VirtualMachineScaleSetExtensionsOperations<azure.mgmt.compute.v2018_10_01.operations.VirtualMachineScaleSetExtensionsOperations>`
           * 2019-03-01: :class:`VirtualMachineScaleSetExtensionsOperations<azure.mgmt.compute.v2019_03_01.operations.VirtualMachineScaleSetExtensionsOperations>`
        """
        api_version = self._get_api_version('virtual_machine_scale_set_extensions')
        if api_version == '2017-03-30':
            from .v2017_03_30.operations import VirtualMachineScaleSetExtensionsOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import VirtualMachineScaleSetExtensionsOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import VirtualMachineScaleSetExtensionsOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import VirtualMachineScaleSetExtensionsOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import VirtualMachineScaleSetExtensionsOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import VirtualMachineScaleSetExtensionsOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def virtual_machine_scale_set_rolling_upgrades(self):
        """Instance depends on the API version:

           * 2017-03-30: :class:`VirtualMachineScaleSetRollingUpgradesOperations<azure.mgmt.compute.v2017_03_30.operations.VirtualMachineScaleSetRollingUpgradesOperations>`
           * 2017-12-01: :class:`VirtualMachineScaleSetRollingUpgradesOperations<azure.mgmt.compute.v2017_12_01.operations.VirtualMachineScaleSetRollingUpgradesOperations>`
           * 2018-04-01: :class:`VirtualMachineScaleSetRollingUpgradesOperations<azure.mgmt.compute.v2018_04_01.operations.VirtualMachineScaleSetRollingUpgradesOperations>`
           * 2018-06-01: :class:`VirtualMachineScaleSetRollingUpgradesOperations<azure.mgmt.compute.v2018_06_01.operations.VirtualMachineScaleSetRollingUpgradesOperations>`
           * 2018-10-01: :class:`VirtualMachineScaleSetRollingUpgradesOperations<azure.mgmt.compute.v2018_10_01.operations.VirtualMachineScaleSetRollingUpgradesOperations>`
           * 2019-03-01: :class:`VirtualMachineScaleSetRollingUpgradesOperations<azure.mgmt.compute.v2019_03_01.operations.VirtualMachineScaleSetRollingUpgradesOperations>`
        """
        api_version = self._get_api_version('virtual_machine_scale_set_rolling_upgrades')
        if api_version == '2017-03-30':
            from .v2017_03_30.operations import VirtualMachineScaleSetRollingUpgradesOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import VirtualMachineScaleSetRollingUpgradesOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import VirtualMachineScaleSetRollingUpgradesOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import VirtualMachineScaleSetRollingUpgradesOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import VirtualMachineScaleSetRollingUpgradesOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import VirtualMachineScaleSetRollingUpgradesOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def virtual_machine_scale_set_vms(self):
        """Instance depends on the API version:

           * 2015-06-15: :class:`VirtualMachineScaleSetVMsOperations<azure.mgmt.compute.v2015_06_15.operations.VirtualMachineScaleSetVMsOperations>`
           * 2016-03-30: :class:`VirtualMachineScaleSetVMsOperations<azure.mgmt.compute.v2016_03_30.operations.VirtualMachineScaleSetVMsOperations>`
           * 2016-04-30-preview: :class:`VirtualMachineScaleSetVMsOperations<azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineScaleSetVMsOperations>`
           * 2017-03-30: :class:`VirtualMachineScaleSetVMsOperations<azure.mgmt.compute.v2017_03_30.operations.VirtualMachineScaleSetVMsOperations>`
           * 2017-12-01: :class:`VirtualMachineScaleSetVMsOperations<azure.mgmt.compute.v2017_12_01.operations.VirtualMachineScaleSetVMsOperations>`
           * 2018-04-01: :class:`VirtualMachineScaleSetVMsOperations<azure.mgmt.compute.v2018_04_01.operations.VirtualMachineScaleSetVMsOperations>`
           * 2018-06-01: :class:`VirtualMachineScaleSetVMsOperations<azure.mgmt.compute.v2018_06_01.operations.VirtualMachineScaleSetVMsOperations>`
           * 2018-10-01: :class:`VirtualMachineScaleSetVMsOperations<azure.mgmt.compute.v2018_10_01.operations.VirtualMachineScaleSetVMsOperations>`
           * 2019-03-01: :class:`VirtualMachineScaleSetVMsOperations<azure.mgmt.compute.v2019_03_01.operations.VirtualMachineScaleSetVMsOperations>`
        """
        api_version = self._get_api_version('virtual_machine_scale_set_vms')
        if api_version == '2015-06-15':
            from .v2015_06_15.operations import VirtualMachineScaleSetVMsOperations as OperationClass
        elif api_version == '2016-03-30':
            from .v2016_03_30.operations import VirtualMachineScaleSetVMsOperations as OperationClass
        elif api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import VirtualMachineScaleSetVMsOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import VirtualMachineScaleSetVMsOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import VirtualMachineScaleSetVMsOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import VirtualMachineScaleSetVMsOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import VirtualMachineScaleSetVMsOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import VirtualMachineScaleSetVMsOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import VirtualMachineScaleSetVMsOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def virtual_machine_scale_sets(self):
        """Instance depends on the API version:

           * 2015-06-15: :class:`VirtualMachineScaleSetsOperations<azure.mgmt.compute.v2015_06_15.operations.VirtualMachineScaleSetsOperations>`
           * 2016-03-30: :class:`VirtualMachineScaleSetsOperations<azure.mgmt.compute.v2016_03_30.operations.VirtualMachineScaleSetsOperations>`
           * 2016-04-30-preview: :class:`VirtualMachineScaleSetsOperations<azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineScaleSetsOperations>`
           * 2017-03-30: :class:`VirtualMachineScaleSetsOperations<azure.mgmt.compute.v2017_03_30.operations.VirtualMachineScaleSetsOperations>`
           * 2017-12-01: :class:`VirtualMachineScaleSetsOperations<azure.mgmt.compute.v2017_12_01.operations.VirtualMachineScaleSetsOperations>`
           * 2018-04-01: :class:`VirtualMachineScaleSetsOperations<azure.mgmt.compute.v2018_04_01.operations.VirtualMachineScaleSetsOperations>`
           * 2018-06-01: :class:`VirtualMachineScaleSetsOperations<azure.mgmt.compute.v2018_06_01.operations.VirtualMachineScaleSetsOperations>`
           * 2018-10-01: :class:`VirtualMachineScaleSetsOperations<azure.mgmt.compute.v2018_10_01.operations.VirtualMachineScaleSetsOperations>`
           * 2019-03-01: :class:`VirtualMachineScaleSetsOperations<azure.mgmt.compute.v2019_03_01.operations.VirtualMachineScaleSetsOperations>`
        """
        api_version = self._get_api_version('virtual_machine_scale_sets')
        if api_version == '2015-06-15':
            from .v2015_06_15.operations import VirtualMachineScaleSetsOperations as OperationClass
        elif api_version == '2016-03-30':
            from .v2016_03_30.operations import VirtualMachineScaleSetsOperations as OperationClass
        elif api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import VirtualMachineScaleSetsOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import VirtualMachineScaleSetsOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import VirtualMachineScaleSetsOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import VirtualMachineScaleSetsOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import VirtualMachineScaleSetsOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import VirtualMachineScaleSetsOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import VirtualMachineScaleSetsOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def virtual_machine_sizes(self):
        """Instance depends on the API version:

           * 2015-06-15: :class:`VirtualMachineSizesOperations<azure.mgmt.compute.v2015_06_15.operations.VirtualMachineSizesOperations>`
           * 2016-03-30: :class:`VirtualMachineSizesOperations<azure.mgmt.compute.v2016_03_30.operations.VirtualMachineSizesOperations>`
           * 2016-04-30-preview: :class:`VirtualMachineSizesOperations<azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachineSizesOperations>`
           * 2017-03-30: :class:`VirtualMachineSizesOperations<azure.mgmt.compute.v2017_03_30.operations.VirtualMachineSizesOperations>`
           * 2017-12-01: :class:`VirtualMachineSizesOperations<azure.mgmt.compute.v2017_12_01.operations.VirtualMachineSizesOperations>`
           * 2018-04-01: :class:`VirtualMachineSizesOperations<azure.mgmt.compute.v2018_04_01.operations.VirtualMachineSizesOperations>`
           * 2018-06-01: :class:`VirtualMachineSizesOperations<azure.mgmt.compute.v2018_06_01.operations.VirtualMachineSizesOperations>`
           * 2018-10-01: :class:`VirtualMachineSizesOperations<azure.mgmt.compute.v2018_10_01.operations.VirtualMachineSizesOperations>`
           * 2019-03-01: :class:`VirtualMachineSizesOperations<azure.mgmt.compute.v2019_03_01.operations.VirtualMachineSizesOperations>`
        """
        api_version = self._get_api_version('virtual_machine_sizes')
        if api_version == '2015-06-15':
            from .v2015_06_15.operations import VirtualMachineSizesOperations as OperationClass
        elif api_version == '2016-03-30':
            from .v2016_03_30.operations import VirtualMachineSizesOperations as OperationClass
        elif api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import VirtualMachineSizesOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import VirtualMachineSizesOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import VirtualMachineSizesOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import VirtualMachineSizesOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import VirtualMachineSizesOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import VirtualMachineSizesOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import VirtualMachineSizesOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))

    @property
    def virtual_machines(self):
        """Instance depends on the API version:

           * 2015-06-15: :class:`VirtualMachinesOperations<azure.mgmt.compute.v2015_06_15.operations.VirtualMachinesOperations>`
           * 2016-03-30: :class:`VirtualMachinesOperations<azure.mgmt.compute.v2016_03_30.operations.VirtualMachinesOperations>`
           * 2016-04-30-preview: :class:`VirtualMachinesOperations<azure.mgmt.compute.v2016_04_30_preview.operations.VirtualMachinesOperations>`
           * 2017-03-30: :class:`VirtualMachinesOperations<azure.mgmt.compute.v2017_03_30.operations.VirtualMachinesOperations>`
           * 2017-12-01: :class:`VirtualMachinesOperations<azure.mgmt.compute.v2017_12_01.operations.VirtualMachinesOperations>`
           * 2018-04-01: :class:`VirtualMachinesOperations<azure.mgmt.compute.v2018_04_01.operations.VirtualMachinesOperations>`
           * 2018-06-01: :class:`VirtualMachinesOperations<azure.mgmt.compute.v2018_06_01.operations.VirtualMachinesOperations>`
           * 2018-10-01: :class:`VirtualMachinesOperations<azure.mgmt.compute.v2018_10_01.operations.VirtualMachinesOperations>`
           * 2019-03-01: :class:`VirtualMachinesOperations<azure.mgmt.compute.v2019_03_01.operations.VirtualMachinesOperations>`
        """
        api_version = self._get_api_version('virtual_machines')
        if api_version == '2015-06-15':
            from .v2015_06_15.operations import VirtualMachinesOperations as OperationClass
        elif api_version == '2016-03-30':
            from .v2016_03_30.operations import VirtualMachinesOperations as OperationClass
        elif api_version == '2016-04-30-preview':
            from .v2016_04_30_preview.operations import VirtualMachinesOperations as OperationClass
        elif api_version == '2017-03-30':
            from .v2017_03_30.operations import VirtualMachinesOperations as OperationClass
        elif api_version == '2017-12-01':
            from .v2017_12_01.operations import VirtualMachinesOperations as OperationClass
        elif api_version == '2018-04-01':
            from .v2018_04_01.operations import VirtualMachinesOperations as OperationClass
        elif api_version == '2018-06-01':
            from .v2018_06_01.operations import VirtualMachinesOperations as OperationClass
        elif api_version == '2018-10-01':
            from .v2018_10_01.operations import VirtualMachinesOperations as OperationClass
        elif api_version == '2019-03-01':
            from .v2019_03_01.operations import VirtualMachinesOperations as OperationClass
        else:
            raise NotImplementedError("APIVersion {} is not available".format(api_version))
        return OperationClass(self._client, self.config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))


#!/usr/bin/env python

# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
import json
import logging
import os.path
from pathlib import Path
import sys

import requests
from cookiecutter.main import cookiecutter
from swaggertosdk.SwaggerToSdkNewCLI import generate_code

_LOGGER = logging.getLogger(__name__)

def guess_service_info_from_path(spec_path):
    """Guess Python Autorest options based on the spec path.

    Expected path:
    specification/compute/resource-manager/readme.md
    """
    spec_path = spec_path.lower()
    spec_path = spec_path[spec_path.index("specification"):] # Might raise and it's ok
    split_spec_path = spec_path.split("/")

    rp_name = split_spec_path[1]
    is_arm = split_spec_path[2] == "resource-manager"

    return {
        "rp_name": rp_name,
        "is_arm": is_arm
    }

def get_data(spec_path):
    if spec_path.startswith("http"):
        response = requests.get(spec_path)
        response.raise_for_status()
        return response.text
    else:
        with open(spec_path, "r") as fd:
            return fd.read()

def guess_service_info_from_content(spec_path):
    data = get_data(spec_path)

    lines = data.splitlines()
    while lines:
        line = lines.pop(0)
        if line.startswith("# "):
            pretty_name = line[2:]
            break
    else:
        raise ValueError("Unable to find main title in this README")
    return {
        'pretty_name': pretty_name
    }

def guess_service_info(spec_path):
    result = guess_service_info_from_content(spec_path)
    result.update(guess_service_info_from_path(spec_path))
    return result

def create_swagger_to_sdk_conf(spec_path, service_info, autorest_options):
    type_str = ".mgmt" if service_info["is_arm"] else ".data"
    return {
        "{}{}".format(service_info["rp_name"], type_str): {
            "markdown": spec_path[spec_path.index("specification"):],
            "autorest_options": {
                "namespace": autorest_options["namespace"],
                "package-version": autorest_options["package-version"],
                "package-name": autorest_options["package-name"]
            },
            "output_dir": "{}/{}".format(autorest_options["package-name"], autorest_options["package-name"].replace("-","/")),
            "build_dir": autorest_options["package-name"]
        }
    }

def create_package_service_mapping(spec_path, service_info, autorest_options):
    type_str = "Management" if service_info["is_arm"] else "Client"
    return {
        autorest_options["package-name"]: {
            "service_name": service_info["pretty_name"],
            "category": type_str,
            "namespaces": [
                autorest_options["namespace"]
            ]
        }
    }

def main(spec_path):
    service_info = guess_service_info(spec_path)

    autorest_options = {}
    if service_info["is_arm"]:
        autorest_options["azure-arm"] = True
        namespace = "azure.mgmt." + service_info["rp_name"]
        package_name = "azure-mgmt-" + service_info["rp_name"]
    else:
        autorest_options["add-credentials"] = True
        namespace = "azure." + service_info["rp_name"]
        package_name = "azure-" + service_info["rp_name"]

    # Create output folder
    output_dir = Path(".").resolve() / Path(package_name)
    output_dir.mkdir(exist_ok=True)
    _LOGGER.info("Output folder: %s", output_dir)

    _LOGGER.info("Calling Autorest")
    autorest_options.update({
        "use": "@microsoft.azure/autorest.python@preview",
        "license-header": "MICROSOFT_MIT_NO_VERSION",
        "payload-flattening-threshold": 2,
        "python": "",
        "package-version": "0.1.0",
        "python.output-folder": output_dir
    })

    autorest_options["namespace"] = namespace
    autorest_options["package-name"] = package_name

    generate_code(
        input_file=Path(spec_path) if not spec_path.startswith("http") else spec_path,
        output_dir=output_dir,
        global_conf={"autorest_options": autorest_options},
        local_conf={}
    )

    _LOGGER.info("Rebuilding packaging with Cookiecutter")
    pretty_name = service_info["pretty_name"]
    cookiecutter('gh:Azure/cookiecutter-azuresdk-pypackage',
                 no_input=True,
                 extra_context={
                     'package_name': package_name,
                     'package_pprint_name': pretty_name
                 },
                 overwrite_if_exists=True
    )

    swagger_to_sdk = Path("swagger_to_sdk_config.json")
    if swagger_to_sdk.exists():
        _LOGGER.info("Updating swagger_to_sdk_config.json")
        entry = create_swagger_to_sdk_conf(spec_path, service_info, autorest_options)
        with swagger_to_sdk.open() as fd:
            data_conf = json.load(fd)
            data_conf["projects"].update(entry)
        with swagger_to_sdk.open("w") as fd:
            json.dump(data_conf, fd, indent=2, sort_keys=True)

    package_service_mapping = Path("package_service_mapping.json")
    if package_service_mapping:
        _LOGGER.info("Updating package_service_mapping.json")
        entry = create_package_service_mapping(spec_path, service_info, autorest_options)
        with package_service_mapping.open() as fd:
            data_conf = json.load(fd)
            data_conf.update(entry)
        with package_service_mapping.open("w") as fd:
            json.dump(data_conf, fd, indent=2, sort_keys=True)

    _LOGGER.info("Done! Enjoy your Python SDK!!")

if __name__ == "__main__":
    logging.basicConfig()
    logging.getLogger().setLevel(logging.INFO)

    main(sys.argv[1])


# ------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -------------------------------------------------------------------------

import time
import logging
try:
    from urlparse import urlparse
except ImportError:
    from urllib.parse import urlparse

from uamqp import AMQPClient
from uamqp import authentication
from uamqp import constants, errors
from uamqp.message import Message, MessageProperties

from azure.servicebus.common.utils import create_properties
from azure.servicebus.common.errors import (
    _ServiceBusErrorPolicy,
    InvalidHandlerState,
    ServiceBusError,
    ServiceBusConnectionError,
    ServiceBusAuthorizationError)

_log = logging.getLogger(__name__)

class BaseHandler(object):  # pylint: disable=too-many-instance-attributes

    def __init__(self, endpoint, auth_config, connection=None, encoding='UTF-8', debug=False, **kwargs):
        self.running = False
        self.error = None
        self.endpoint = endpoint
        self.entity = urlparse(endpoint).path.strip('/')
        self.mgmt_target = self.entity + "/$management"
        self.debug = debug
        self.encoding = encoding
        self.auth_config = auth_config
        self.connection = connection
        self.auto_reconnect = kwargs.pop('auto_reconnect', True)
        self.properties = create_properties()
        self.error_policy = kwargs.pop('error_policy', None)
        self.handler_kwargs = kwargs
        if not self.error_policy:
            max_retries = kwargs.pop('max_message_retries', 3)
            is_session = hasattr(self, 'session_id')
            self.error_policy = _ServiceBusErrorPolicy(max_retries=max_retries, is_session=is_session)
        self._handler = None
        self._build_handler()

    def __enter__(self):
        """Open the handler in a context manager."""
        self.open()
        return self

    def __exit__(self, *args):
        """Close the handler when exiting a context manager."""
        self.close()

    def _build_handler(self):
        auth = None if self.connection else authentication.SASTokenAuth.from_shared_access_key(**self.auth_config)
        self._handler = AMQPClient(
            self.endpoint,
            auth=auth,
            debug=self.debug,
            properties=self.properties,
            error_policy=self.error_policy,
            encoding=self.encoding,
            **self.handler_kwargs)

    def _mgmt_request_response(self, operation, message, callback, **kwargs):
        if not self.running:
            raise InvalidHandlerState("Client connection is closed.")

        mgmt_msg = Message(
            body=message,
            properties=MessageProperties(
                reply_to=self.mgmt_target,
                encoding=self.encoding,
                **kwargs))
        try:
            return self._handler.mgmt_request(
                mgmt_msg,
                operation,
                op_type=b"entity-mgmt",
                node=self.mgmt_target.encode(self.encoding),
                timeout=5000,
                callback=callback)
        except Exception as exp:  # pylint: disable=broad-except
            raise ServiceBusError("Management request failed: {}".format(exp), exp)

    def _handle_exception(self, exception):
        if isinstance(exception, (errors.LinkDetach, errors.ConnectionClose)):
            if exception.action and exception.action.retry and self.auto_reconnect:
                _log.info("Handler detached. Attempting reconnect.")
                self.reconnect()
            elif exception.condition == constants.ErrorCodes.UnauthorizedAccess:
                _log.info("Handler detached. Shutting down.")
                error = ServiceBusAuthorizationError(str(exception), exception)
                self.close(exception=error)
                raise error
            else:
                _log.info("Handler detached. Shutting down.")
                error = ServiceBusConnectionError(str(exception), exception)
                self.close(exception=error)
                raise error
        elif isinstance(exception, errors.MessageHandlerError):
            if self.auto_reconnect:
                _log.info("Handler error. Attempting reconnect.")
                self.reconnect()
            else:
                _log.info("Handler error. Shutting down.")
                error = ServiceBusConnectionError(str(exception), exception)
                self.close(exception=error)
                raise error
        elif isinstance(exception, errors.AMQPConnectionError):
            message = "Failed to open handler: {}".format(exception)
            raise ServiceBusConnectionError(message, exception)
        else:
            _log.info("Unexpected error occurred (%r). Shutting down.", exception)
            error = ServiceBusError("Handler failed: {}".format(exception))
            self.close(exception=error)
            raise error

    def reconnect(self):
        """Reconnect the handler.

        If the handler was disconnected from the service with
        a retryable error - attempt to reconnect.
        This method will be called automatically for most retryable errors.
        """
        self._handler.close()
        self._build_handler()
        self.open()

    def open(self):
        """Open handler connection and authenticate session.

        If the handler is already open, this operation will do nothing.
        A handler opened with this method must be explicitly closed.
        It is recommended to open a handler within a context manager as
        opposed to calling the method directly.

        .. note:: This operation is not thread-safe.

        """
        if self.running:
            return
        self.running = True
        try:
            self._handler.open(connection=self.connection)
            while not self._handler.client_ready():
                time.sleep(0.05)
        except Exception as e:  # pylint: disable=broad-except
            try:
                self._handle_exception(e)
            except:
                self.running = False
                raise

    def close(self, exception=None):
        """Close down the handler connection.

        If the handler has already closed, this operation will do nothing. An optional exception can be passed in to
        indicate that the handler was shutdown due to error.
        It is recommended to open a handler within a context manager as
        opposed to calling the method directly.

        .. note:: This operation is not thread-safe.

        :param exception: An optional exception if the handler is closing
         due to an error.
        :type exception: Exception
        """
        self.running = False
        if self.error:
            return
        if isinstance(exception, ServiceBusError):
            self.error = exception
        elif exception:
            self.error = ServiceBusError(str(exception))
        else:
            self.error = ServiceBusError("This message handler is now closed.")
        self._handler.close()