Skip to content
403 changes: 267 additions & 136 deletions scripts/multiapi_init_gen.py

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions scripts/templates/_multiapi_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# 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 azure.profiles import KnownProfiles, ProfileDefinition
from azure.profiles.multiapiclient import MultiApiClientMixin
from .version import VERSION
from ._configuration import {{ client_name }}Configuration
{% if mixin_operations %}from ._operations_mixin import {{ client_name }}OperationsMixin{% endif %}


class {{ client_name }}({% if mixin_operations %}{{ client_name }}OperationsMixin, {% endif %}MultiApiClientMixin, SDKClient):
"""{{ client_doc }}

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: {{ client_name }}Configuration

: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 = '{{ last_api_version }}'
_PROFILE_TAG = "{{ module_name }}.{{ client_name }}"
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
{%- for rt_name, api_version in last_rt_list|dictsort %}
'{{ rt_name }}': '{{ api_version }}',
{%- endfor %}
None: DEFAULT_API_VERSION
}},
_PROFILE_TAG + " latest"
)

def __init__(self, credentials, subscription_id, api_version=None, base_url=None, profile=KnownProfiles.default):
self.config = {{ client_name }}Configuration(credentials, subscription_id, base_url)
super({{ client_name }}, self).__init__(
credentials,
self.config,
api_version=api_version,
profile=profile
)

@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:
{% for mod_api_version, api_version in mod_to_api_version|dictsort %}
* {{ api_version }}: :mod:`{{ mod_api_version }}.models<{{ module_name }}.{{ mod_api_version }}.models>`
{%- endfor %}
"""
{%- for mod_api_version, api_version in mod_to_api_version|dictsort %}
{% if not loop.first %}el{% endif %}if api_version == '{{ api_version }}':
from .{{ mod_api_version }} import models
return models
{%- endfor %}
raise NotImplementedError("APIVersion {} is not available".format(api_version))
{% for operation_name, available_apis in operations|dictsort %}
@property
def {{ operation_name }}(self):
"""Instance depends on the API version:
{% for api in available_apis %}
* {{ mod_to_api_version[api[0]] }}: :class:`{{ api[1] }}<{{ module_name }}.{{ api[0] }}.operations.{{ api[1] }}>`
{%- endfor %}
"""
api_version = self._get_api_version('{{ operation_name }}')
{%- for api in available_apis %}
{% if not loop.first %}el{% endif %}if api_version == '{{ mod_to_api_version[api[0]] }}':
from .{{ api[0] }}.operations import {{ api[1] }} as OperationClass
{%- endfor %}
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)))
{% endfor %}
33 changes: 33 additions & 0 deletions scripts/templates/_operations_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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 import Serializer, Deserializer


class {{ client_name }}OperationsMixin(object):

{% for operation_name, metadata in mixin_operations|dictsort %}
def {{ operation_name }}{{ metadata['signature'] }}:
"""{{ metadata['doc'] }}
"""
api_version = self._get_api_version('{{ operation_name }}')
{%- for api in metadata['available_apis'] %}
{% if not loop.first %}el{% endif %}if api_version == '{{ mod_to_api_version[api] }}':
from .{{ api }}.operations import {{ client_name }}OperationsMixin as OperationClass
{%- endfor %}
else:
raise NotImplementedError("APIVersion {} is not available".format(api_version))
mixin_instance = OperationClass()
mixin_instance._client = self._client
mixin_instance.config = self.config
mixin_instance._serialize = Serializer(self._models_dict(api_version))
mixin_instance._deserialize = Deserializer(self._models_dict(api_version))
return mixin_instance.{{ operation_name }}({{ metadata['call'] }}, **operation_config)
{% endfor %}
9 changes: 9 additions & 0 deletions scripts/templates/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 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.
# --------------------------------------------------------------------------
{%- for mod_api_version, _ in mod_to_api_version|dictsort %}
from .{{ mod_api_version }}.models import *
{%- endfor %}
10 changes: 6 additions & 4 deletions sdk/network/azure-mgmt-network/azure/mgmt/network/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# coding=utf-8
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
Expand All @@ -9,9 +9,11 @@
# regenerated.
# --------------------------------------------------------------------------

from .network_management_client import NetworkManagementClient
from .version import VERSION
from ._configuration import NetworkManagementClientConfiguration
from ._network_management_client import NetworkManagementClient
__all__ = ['NetworkManagementClient', 'NetworkManagementClientConfiguration']

__all__ = ['NetworkManagementClient']
from .version import VERSION

__version__ = VERSION

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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 msrestazure import AzureConfiguration

from .version import VERSION


class NetworkManagementClientConfiguration(AzureConfiguration):
"""Configuration for NetworkManagementClient
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: The subscription credentials which uniquely
identify the 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(NetworkManagementClientConfiguration, self).__init__(base_url)

# Starting Autorest.Python 4.0.64, make connection pool activated by default
self.keep_alive = True

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

self.credentials = credentials
self.subscription_id = subscription_id
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,15 @@

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
from ._configuration import NetworkManagementClientConfiguration
from ._operations_mixin import NetworkManagementClientOperationsMixin


class NetworkManagementClientConfiguration(AzureConfiguration):
"""Configuration for NetworkManagementClient
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: The subscription credentials which uniquely
identify the 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(NetworkManagementClientConfiguration, self).__init__(base_url)

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

self.credentials = credentials
self.subscription_id = subscription_id


class NetworkManagementClient(MultiApiClientMixin, SDKClient):
class NetworkManagementClient(NetworkManagementClientOperationsMixin, MultiApiClientMixin, SDKClient):
"""Network Client

This ready contains multiple API versions, to help you deal with all Azure clouds
Expand Down Expand Up @@ -83,6 +51,8 @@ class NetworkManagementClient(MultiApiClientMixin, SDKClient):
_PROFILE_TAG = "azure.mgmt.network.NetworkManagementClient"
LATEST_PROFILE = ProfileDefinition({
_PROFILE_TAG: {
'interface_endpoints': '2019-02-01',
'virtual_wa_ns': '2018-07-01',
None: DEFAULT_API_VERSION
}},
_PROFILE_TAG + " latest"
Expand All @@ -97,83 +67,6 @@ def __init__(self, credentials, subscription_id, api_version=None, base_url=None
profile=profile
)

def check_dns_name_availability(
self, location, domain_name_label, custom_headers=None, raw=False, **operation_config):
"""Checks whether a domain name in the cloudapp.azure.com zone is
available for use.

:param location: The location of the domain name.
:type location: str
:param domain_name_label: The domain name to be verified. It must
conform to the following regular expression:
^[a-z][a-z0-9-]{1,61}[a-z0-9]$.
:type domain_name_label: 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: :class:`DnsNameAvailabilityResult
<azure.mgmt.network.v2018_08_01.models.DnsNameAvailabilityResult>` or
:class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>` if
raw=true
:rtype: :class:`DnsNameAvailabilityResult
<azure.mgmt.network.v2018_08_01.models.DnsNameAvailabilityResult>` or
:class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
:raises: :class:`CloudError<msrestazure.azure_exceptions.CloudError>`
"""
api_version = self._get_api_version('check_dns_name_availability')
if api_version == '2019-04-01':
from .v2019_04_01 import NetworkManagementClient as ClientClass
elif api_version == '2019-02-01':
from .v2019_02_01 import NetworkManagementClient as ClientClass
elif api_version == '2018-12-01':
from .v2018_12_01 import NetworkManagementClient as ClientClass
elif api_version == '2018-11-01':
from .v2018_11_01 import NetworkManagementClient as ClientClass
elif api_version == '2018-10-01':
from .v2018_10_01 import NetworkManagementClient as ClientClass
elif api_version == '2018-08-01':
from .v2018_08_01 import NetworkManagementClient as ClientClass
elif api_version == '2018-07-01':
from .v2018_07_01 import NetworkManagementClient as ClientClass
elif api_version == '2018-06-01':
from .v2018_06_01 import NetworkManagementClient as ClientClass
elif api_version == '2018-04-01':
from .v2018_04_01 import NetworkManagementClient as ClientClass
elif api_version == '2018-02-01':
from .v2018_02_01 import NetworkManagementClient as ClientClass
elif api_version == '2018-01-01':
from .v2018_01_01 import NetworkManagementClient as ClientClass
elif api_version == '2017-11-01':
from .v2017_11_01 import NetworkManagementClient as ClientClass
elif api_version == '2017-10-01':
from .v2017_10_01 import NetworkManagementClient as ClientClass
elif api_version == '2017-09-01':
from .v2017_09_01 import NetworkManagementClient as ClientClass
elif api_version == '2017-08-01':
from .v2017_08_01 import NetworkManagementClient as ClientClass
elif api_version == '2017-06-01':
from .v2017_06_01 import NetworkManagementClient as ClientClass
elif api_version == '2017-03-01':
from .v2017_03_01 import NetworkManagementClient as ClientClass
elif api_version == '2016-12-01':
from .v2016_12_01 import NetworkManagementClient as ClientClass
elif api_version == '2016-09-01':
from .v2016_09_01 import NetworkManagementClient as ClientClass
elif api_version == '2015-06-15':
from .v2015_06_15 import NetworkManagementClient as ClientClass
localclient = ClientClass(self.config.credentials,
self.config.subscription_id,
self.config.base_url)
return localclient.check_dns_name_availability(location,
domain_name_label,
custom_headers,
raw,
**operation_config)

############ 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)}
Expand Down
Loading