Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

vmware checkquotaavailability #34

Merged
merged 3 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,11 @@ 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
npm install -g autorest
npm install -g oav --unsafe-perm=true --allow-root
apt-get update
apt-get install libunwind-dev -y
./autorest.sh
./install-autorest.sh
./run-autorest.sh
```
7 changes: 0 additions & 7 deletions autorest.sh

This file was deleted.

5 changes: 5 additions & 0 deletions azext_vmware/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
5 changes: 4 additions & 1 deletion azext_vmware/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
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')
5 changes: 4 additions & 1 deletion azext_vmware/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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)
5 changes: 5 additions & 0 deletions azext_vmware/vendored_sdks/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -45,13 +47,15 @@
from .private_cloud_paged import PrivateCloudPaged
from .cluster_paged import ClusterPaged
from .virtustream_client_enums import (
QuotaEnabled,
SslEnum,
PrivateCloudProvisioningState,
InternetEnum,
ClusterProvisioningState,
)

__all__ = [
'Quota',
'Resource',
'TrackedResource',
'ApiErrorBase',
Expand All @@ -72,6 +76,7 @@
'OperationPaged',
'PrivateCloudPaged',
'ClusterPaged',
'QuotaEnabled',
'SslEnum',
'PrivateCloudProvisioningState',
'InternetEnum',
Expand Down
36 changes: 36 additions & 0 deletions azext_vmware/vendored_sdks/models/quota.py
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 36 additions & 0 deletions azext_vmware/vendored_sdks/models/quota_py3.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions azext_vmware/vendored_sdks/models/virtustream_client_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
from enum import Enum


class QuotaEnabled(str, Enum):

enabled = "Enabled"
disabled = "Disabled"


class SslEnum(str, Enum):

enabled = "Enabled"
Expand Down
62 changes: 62 additions & 0 deletions azext_vmware/vendored_sdks/virtustream_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<msrest:optionsforoperations>`.
:return: Quota or ClientRawResponse if raw=true
:rtype: ~vendored_sdks.models.Quota or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`ApiErrorException<vendored_sdks.models.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'}
5 changes: 5 additions & 0 deletions install-autorest.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions run-autorest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh -e
# swagger validation
# https://github.com/Azure/azure-rest-api-specs/blob/master/documentation/swagger-checklist.md#validation-tools-for-swagger-checklist
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
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 [email protected]/autorest.python@~3.0.56