From 3792f3a5be0e463c13412c5f3f5be419fb9a19b7 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Wed, 29 Apr 2020 10:52:45 -0600 Subject: [PATCH 1/3] don't copy files for sdk gen --- README.md | 7 +++---- autorest.sh | 9 +++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7e07b76..9293c24 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,8 @@ python setup.py bdist_wheel ## AutoRest client code generation The code in the `azext_vmware/vendored_sdks` subdirectory was generated using the [AutoRest CLI](http://azure.github.io/autorest/user/command-line-interface.html). It is a Node app that bootstraps a dotnet app. It generates code from the a Swagger 2 spec. Here is how the current code was generated: -``` ps -cp ../azure-rest-api-specs/specification/vmwarevirtustream/resource-manager/Microsoft.VMwareVirtustream/preview/2019-08-09-preview/vmwarevirtustream.json . -cp ../azure-rest-api-specs/specification/vmwarevirtustream/resource-manager/Microsoft.VMwareVirtustream/preview/2019-08-09-preview/examples/*.json examples/ -docker run --rm -it -v ${PWD}:/src -w /src node:lts bash +``` sh +docker run --rm -it -v ${PWD}:/src -v ${PWD}/../azure-rest-api-specs:/azure-rest-api-specs -w /src node:lts bash ``` ``` sh @@ -51,5 +49,6 @@ npm install -g autorest npm install -g oav --unsafe-perm=true --allow-root apt-get update apt-get install libunwind-dev -y +rm -rf azext_vmware/vendored_sdks/ ./autorest.sh ``` \ No newline at end of file diff --git a/autorest.sh b/autorest.sh index bedf4ca..f0cd6d2 100755 --- a/autorest.sh +++ b/autorest.sh @@ -1,7 +1,8 @@ #!/bin/sh -e # swagger validation # https://github.com/Azure/azure-rest-api-specs/blob/master/documentation/swagger-checklist.md#validation-tools-for-swagger-checklist -autorest --input-file=vmwarevirtustream.json --azure-validator --openapi-type=arm -oav validate-spec vmwarevirtustream.json -p -oav validate-example vmwarevirtustream.json -p -autorest --input-file=vmwarevirtustream.json --python --output-folder=azext_vmware --namespace=vendored_sdks --azure-arm=true --override-client-name=VirtustreamClient --use=@microsoft.azure/autorest.python@~3.0.56 \ No newline at end of file +spec=/azure-rest-api-specs/specification/vmwarevirtustream/resource-manager/Microsoft.VMwareVirtustream/preview/2019-08-09-preview/vmwarevirtustream.json +autorest --input-file=$spec --azure-validator --openapi-type=arm +oav validate-spec $spec -p +oav validate-example $spec -p +autorest --input-file=$spec --python --output-folder=azext_vmware --namespace=vendored_sdks --azure-arm=true --override-client-name=VirtustreamClient --use=@microsoft.azure/autorest.python@~3.0.56 \ No newline at end of file From f4b8612c4bebd49766d7f81e8c13b4c5f6a9937f Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Wed, 29 Apr 2020 15:57:02 -0600 Subject: [PATCH 2/3] include latest quota api changes from https://github.com/Azure/azure-rest-api-specs/pull/9269 + Sku patch --- README.md | 8 +-- azext_vmware/vendored_sdks/models/__init__.py | 5 ++ azext_vmware/vendored_sdks/models/quota.py | 36 +++++++++++ .../vendored_sdks/models/quota_py3.py | 36 +++++++++++ .../models/virtustream_client_enums.py | 6 ++ .../vendored_sdks/virtustream_client.py | 62 +++++++++++++++++++ install-autorest.sh | 5 ++ autorest.sh => run-autorest.sh | 1 + 8 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 azext_vmware/vendored_sdks/models/quota.py create mode 100644 azext_vmware/vendored_sdks/models/quota_py3.py create mode 100644 install-autorest.sh rename autorest.sh => run-autorest.sh (94%) diff --git a/README.md b/README.md index 9293c24..ed6c3a5 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,6 @@ docker run --rm -it -v ${PWD}:/src -v ${PWD}/../azure-rest-api-specs:/azure-rest ``` ``` sh -npm install -g autorest -npm install -g oav --unsafe-perm=true --allow-root -apt-get update -apt-get install libunwind-dev -y -rm -rf azext_vmware/vendored_sdks/ -./autorest.sh +./install-autorest.sh +./run-autorest.sh ``` \ No newline at end of file diff --git a/azext_vmware/vendored_sdks/models/__init__.py b/azext_vmware/vendored_sdks/models/__init__.py index b9ceef6..b5f673a 100644 --- a/azext_vmware/vendored_sdks/models/__init__.py +++ b/azext_vmware/vendored_sdks/models/__init__.py @@ -6,6 +6,7 @@ # -------------------------------------------------------------------------- try: + from .quota_py3 import Quota from .resource_py3 import Resource from .tracked_resource_py3 import TrackedResource from .api_error_base_py3 import ApiErrorBase @@ -24,6 +25,7 @@ from .cluster_py3 import Cluster from .admin_credentials_py3 import AdminCredentials except (SyntaxError, ImportError): + from .quota import Quota from .resource import Resource from .tracked_resource import TrackedResource from .api_error_base import ApiErrorBase @@ -45,6 +47,7 @@ from .private_cloud_paged import PrivateCloudPaged from .cluster_paged import ClusterPaged from .virtustream_client_enums import ( + QuotaEnabled, SslEnum, PrivateCloudProvisioningState, InternetEnum, @@ -52,6 +55,7 @@ ) __all__ = [ + 'Quota', 'Resource', 'TrackedResource', 'ApiErrorBase', @@ -72,6 +76,7 @@ 'OperationPaged', 'PrivateCloudPaged', 'ClusterPaged', + 'QuotaEnabled', 'SslEnum', 'PrivateCloudProvisioningState', 'InternetEnum', diff --git a/azext_vmware/vendored_sdks/models/quota.py b/azext_vmware/vendored_sdks/models/quota.py new file mode 100644 index 0000000..cb301ff --- /dev/null +++ b/azext_vmware/vendored_sdks/models/quota.py @@ -0,0 +1,36 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class Quota(Model): + """Subscription quotas. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar hosts_remaining: Remaining hosts quota by sku type + :vartype hosts_remaining: dict[str, int] + :param quota_enabled: Host quota is active for current subscription. + Possible values include: 'Enabled', 'Disabled' + :type quota_enabled: str or ~vendored_sdks.models.QuotaEnabled + """ + + _validation = { + 'hosts_remaining': {'readonly': True}, + } + + _attribute_map = { + 'hosts_remaining': {'key': 'hostsRemaining', 'type': '{int}'}, + 'quota_enabled': {'key': 'quotaEnabled', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(Quota, self).__init__(**kwargs) + self.hosts_remaining = None + self.quota_enabled = kwargs.get('quota_enabled', None) diff --git a/azext_vmware/vendored_sdks/models/quota_py3.py b/azext_vmware/vendored_sdks/models/quota_py3.py new file mode 100644 index 0000000..89196b1 --- /dev/null +++ b/azext_vmware/vendored_sdks/models/quota_py3.py @@ -0,0 +1,36 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class Quota(Model): + """Subscription quotas. + + Variables are only populated by the server, and will be ignored when + sending a request. + + :ivar hosts_remaining: Remaining hosts quota by sku type + :vartype hosts_remaining: dict[str, int] + :param quota_enabled: Host quota is active for current subscription. + Possible values include: 'Enabled', 'Disabled' + :type quota_enabled: str or ~vendored_sdks.models.QuotaEnabled + """ + + _validation = { + 'hosts_remaining': {'readonly': True}, + } + + _attribute_map = { + 'hosts_remaining': {'key': 'hostsRemaining', 'type': '{int}'}, + 'quota_enabled': {'key': 'quotaEnabled', 'type': 'str'}, + } + + def __init__(self, *, quota_enabled=None, **kwargs) -> None: + super(Quota, self).__init__(**kwargs) + self.hosts_remaining = None + self.quota_enabled = quota_enabled diff --git a/azext_vmware/vendored_sdks/models/virtustream_client_enums.py b/azext_vmware/vendored_sdks/models/virtustream_client_enums.py index 301d1a2..7ddae0b 100644 --- a/azext_vmware/vendored_sdks/models/virtustream_client_enums.py +++ b/azext_vmware/vendored_sdks/models/virtustream_client_enums.py @@ -8,6 +8,12 @@ from enum import Enum +class QuotaEnabled(str, Enum): + + enabled = "Enabled" + disabled = "Disabled" + + class SslEnum(str, Enum): enabled = "Enabled" diff --git a/azext_vmware/vendored_sdks/virtustream_client.py b/azext_vmware/vendored_sdks/virtustream_client.py index ccb7da2..3a72602 100644 --- a/azext_vmware/vendored_sdks/virtustream_client.py +++ b/azext_vmware/vendored_sdks/virtustream_client.py @@ -9,6 +9,10 @@ from msrest import Serializer, Deserializer from msrestazure import AzureConfiguration from .version import VERSION +from msrest.pipeline import ClientRawResponse +from msrest.polling import LROPoller, NoPolling +from msrestazure.polling.arm_polling import ARMPolling +import uuid from .operations.operations import Operations from .operations.private_clouds_operations import PrivateCloudsOperations from .operations.clusters_operations import ClustersOperations @@ -85,3 +89,61 @@ def __init__( self._client, self.config, self._serialize, self._deserialize) self.clusters = ClustersOperations( self._client, self.config, self._serialize, self._deserialize) + + def check_quota_availability( + self, location, custom_headers=None, raw=False, **operation_config): + """Return quota for subscription by region. + + :param location: Azure region + :type location: 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`. + :return: Quota or ClientRawResponse if raw=true + :rtype: ~vendored_sdks.models.Quota or + ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ApiErrorException` + """ + # Construct URL + url = self.check_quota_availability.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str'), + 'location': self._serialize.url("location", location, '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['Accept'] = 'application/json' + 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, header_parameters) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.ApiErrorException(self._deserialize, response) + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('Quota', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + check_quota_availability.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.VMwareVirtustream/locations/{location}/checkQuotaAvailability'} diff --git a/install-autorest.sh b/install-autorest.sh new file mode 100644 index 0000000..a09ebd5 --- /dev/null +++ b/install-autorest.sh @@ -0,0 +1,5 @@ +#!/bin/sh -e +npm install -g autorest +npm install -g oav --unsafe-perm=true --allow-root +apt-get update +apt-get install libunwind-dev -y \ No newline at end of file diff --git a/autorest.sh b/run-autorest.sh similarity index 94% rename from autorest.sh rename to run-autorest.sh index f0cd6d2..0130dcf 100755 --- a/autorest.sh +++ b/run-autorest.sh @@ -5,4 +5,5 @@ spec=/azure-rest-api-specs/specification/vmwarevirtustream/resource-manager/Micr autorest --input-file=$spec --azure-validator --openapi-type=arm oav validate-spec $spec -p oav validate-example $spec -p +rm -rf azext_vmware/vendored_sdks/ autorest --input-file=$spec --python --output-folder=azext_vmware --namespace=vendored_sdks --azure-arm=true --override-client-name=VirtustreamClient --use=@microsoft.azure/autorest.python@~3.0.56 \ No newline at end of file From b5f819127820cdaa64d2cccf8f9efbca70866ce9 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Wed, 29 Apr 2020 16:11:24 -0600 Subject: [PATCH 3/3] add vmware checkquotaavailability --- azext_vmware/_help.py | 5 +++++ azext_vmware/commands.py | 5 ++++- azext_vmware/custom.py | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/azext_vmware/_help.py b/azext_vmware/_help.py index 34257e2..06a1ddb 100644 --- a/azext_vmware/_help.py +++ b/azext_vmware/_help.py @@ -96,4 +96,9 @@ helps['vmware private-cloud update'] = """ type: command short-summary: Update a private cloud. +""" + +helps['vmware checkquotaavailability'] = """ + type: command + short-summary: Return quota for subscription by region. """ \ No newline at end of file diff --git a/azext_vmware/commands.py b/azext_vmware/commands.py index ad36118..d125b63 100644 --- a/azext_vmware/commands.py +++ b/azext_vmware/commands.py @@ -31,4 +31,7 @@ def load_command_table(self, _): g.custom_command('update', 'cluster_update') g.custom_command('list', 'cluster_list') g.custom_command('delete', 'cluster_delete') - g.custom_command('show', 'cluster_show') \ No newline at end of file + g.custom_command('show', 'cluster_show') + + with self.command_group('vmware', vmware_sdk, client_factory=cf_vmware) as g: + g.custom_command('checkquotaavailability', 'check_quota_availability') \ No newline at end of file diff --git a/azext_vmware/custom.py b/azext_vmware/custom.py index 6de6462..a106368 100644 --- a/azext_vmware/custom.py +++ b/azext_vmware/custom.py @@ -104,4 +104,7 @@ def cluster_show(cmd, client: VirtustreamClient, resource_group_name, private_cl return client.clusters.get(resource_group_name=resource_group_name, private_cloud_name=private_cloud, cluster_name=name) def cluster_delete(cmd, client: VirtustreamClient, resource_group_name, private_cloud, name): - return client.clusters.delete(resource_group_name=resource_group_name, private_cloud_name=private_cloud, cluster_name=name) \ No newline at end of file + return client.clusters.delete(resource_group_name=resource_group_name, private_cloud_name=private_cloud, cluster_name=name) + +def check_quota_availability(cmd, client: VirtustreamClient, location): + return client.check_quota_availability(location) \ No newline at end of file