Skip to content
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
4 changes: 4 additions & 0 deletions src/spring-cloud/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Release History
===============

0.2.5
-----
* enable to specified sku when create or update service instance

0.2.4
-----
* Add command "az spring-cloud app identity" to support Managed Identity feature
Expand Down
8 changes: 8 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
text: az spring-cloud create -n MyService -g MyResourceGroup -l westus
"""

helps['spring-cloud update'] = """
type: command
short-summary: Update pricing tier of an Azure Spring Cloud.
examples:
- name: Update pricing tier.
text: az spring-cloud update -n MyService --sku Standard -g MyResourceGroup
"""

helps['spring-cloud delete'] = """
type: command
short-summary: Delete an Azure Spring Cloud.
Expand Down
20 changes: 10 additions & 10 deletions src/spring-cloud/azext_spring_cloud/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from azure.cli.core.commands.parameters import get_enum_type, get_three_state_flag
from azure.cli.core.commands.parameters import (name_type, get_location_type, resource_group_name_type)
from ._validators import (validate_env, validate_cosmos_type, validate_resource_id, validate_location,
validate_name, validate_app_name, validate_deployment_name, validate_nodes_count,
validate_log_lines, validate_log_limit, validate_log_since)
validate_name, validate_app_name, validate_deployment_name, validate_log_lines,
validate_log_limit, validate_log_since, validate_sku)
from ._utils import ApiType

from .vendored_sdks.appplatform.models import RuntimeVersion, TestKeyType
Expand All @@ -31,8 +31,11 @@ def load_arguments(self, _):
'--name', '-n'], help='Name of Azure Spring Cloud.')

with self.argument_context('spring-cloud create') as c:
c.argument('location', arg_type=get_location_type(
self.cli_ctx), validator=validate_location)
c.argument('location', arg_type=get_location_type(self.cli_ctx), validator=validate_location)
c.argument('sku', type=str, validator=validate_sku, help='Name of SKU, the value is "Basic" or "Standard"')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use get_enum_type for sku?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it able to customize the CLI error in get_enum_type?

raise CLIError("The pricing tier only accept value [Basic, Standard]")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message of get_enum_type cannot be customized and will tell users to see --help for the allowed values.


with self.argument_context('spring-cloud update') as c:
c.argument('sku', type=str, validator=validate_sku, help='Name of SKU, the value is "Basic" or "Standard"')

with self.argument_context('spring-cloud test-endpoint renew-key') as c:
c.argument('type', type=str, arg_type=get_enum_type(
Expand Down Expand Up @@ -103,12 +106,9 @@ def load_arguments(self, _):

for scope in ['spring-cloud app deploy', 'spring-cloud app scale']:
with self.argument_context(scope) as c:
c.argument('cpu', type=int,
help='Number of virtual cpu cores per instance.', validator=validate_nodes_count)
c.argument('memory', type=int,
help='Number of GB of memory per instance.', validator=validate_nodes_count)
c.argument('instance_count', type=int,
help='Number of instance.', validator=validate_nodes_count)
c.argument('cpu', type=int, help='Number of virtual cpu cores per instance.')
c.argument('memory', type=int, help='Number of GB of memory per instance.')
c.argument('instance_count', type=int, help='Number of instance.')

for scope in ['spring-cloud app deploy', 'spring-cloud app deployment create']:
with self.argument_context(scope) as c:
Expand Down
9 changes: 9 additions & 0 deletions src/spring-cloud/azext_spring_cloud/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,12 @@ def _get_rg_location(ctx, resource_group_name, subscription_id=None):
# Just do the get, we don't need the result, it will error out if the group doesn't exist.
rg = groups.get(resource_group_name)
return rg.location


def _get_sku_name(tier): # pylint: disable=too-many-return-statements
tier = tier.upper()
if tier == 'BASIC':
return 'B0'
if tier == 'STANDARD':
return 'S0'
raise CLIError("Invalid sku(pricing tier), please refer to command help for valid values")
19 changes: 6 additions & 13 deletions src/spring-cloud/azext_spring_cloud/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def validate_location(namespace):
for piece in location_slice])


def validate_sku(namespace):
namespace.sku = namespace.sku.upper()
if namespace.sku not in ['BASIC', 'STANDARD']:
raise CLIError("The pricing tier only accept value [Basic, Standard]")


def validate_name(namespace):
namespace.name = namespace.name.lower()
matchObj = match(r'^[a-z][a-z0-9-]{2,30}[a-z0-9]$', namespace.name)
Expand Down Expand Up @@ -86,19 +92,6 @@ def validate_cosmos_type(namespace):
"Cosmosdb with type {} should specify collection name".format(type))


def validate_nodes_count(namespace):
"""Validate that cpu, memory and instance-count is set in a range"""
if namespace.cpu is not None:
if namespace.cpu < 1 or namespace.cpu > 4:
raise CLIError('--cpu must be in the range [1,4]')
if namespace.memory is not None:
if namespace.memory < 1 or namespace.memory > 8:
raise CLIError('--memory must be in the range [1,8]')
if namespace.instance_count is not None:
if namespace.instance_count < 1 or namespace.instance_count > 20:
raise CLIError('--instance-count must be in the range [1,20]')


def validate_log_limit(namespace):
temp_limit = None
try:
Expand Down
13 changes: 5 additions & 8 deletions src/spring-cloud/azext_spring_cloud/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
# pylint: disable=too-many-statements
def load_command_table(self, _):
with self.command_group('spring-cloud', client_factory=cf_app_services) as g:
g.custom_command('create', 'spring_cloud_create',
supports_no_wait=True)
g.custom_command('delete', 'spring_cloud_delete',
supports_no_wait=True)
g.custom_command('list', 'spring_cloud_list',
table_transformer=transform_spring_cloud_table_output)
g.custom_show_command('show', 'spring_cloud_get',
table_transformer=transform_spring_cloud_table_output)
g.custom_command('create', 'spring_cloud_create', supports_no_wait=True)
g.custom_command('update', 'spring_cloud_update', supports_no_wait=True)
g.custom_command('delete', 'spring_cloud_delete', supports_no_wait=True)
Comment on lines +18 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add g.wait_command.

g.custom_command('list', 'spring_cloud_list', table_transformer=transform_spring_cloud_table_output)
g.custom_show_command('show', 'spring_cloud_get', table_transformer=transform_spring_cloud_table_output)

with self.command_group('spring-cloud test-endpoint', client_factory=cf_spring_cloud) as g:
g.custom_command('enable ', 'enable_test_endpoint')
Expand Down
28 changes: 22 additions & 6 deletions src/spring-cloud/azext_spring_cloud/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ast import literal_eval
from azure.cli.core.commands import cached_put
from ._utils import _get_rg_location
from ._utils import _get_sku_name
from six.moves.urllib import parse
from threading import Thread
from threading import Timer
Expand All @@ -38,19 +39,34 @@
LOG_RUNNING_PROMPT = "This command usually takes minutes to run. Add '--verbose' parameter if needed."


def spring_cloud_create(cmd, client, resource_group, name, location=None, no_wait=False):
def spring_cloud_create(cmd, client, resource_group, name, location=None, sku=None, no_wait=False):
rg_location = _get_rg_location(cmd.cli_ctx, resource_group)
if location is None:
location = rg_location
resource = models.ServiceResource(location=location)

return sdk_no_wait(no_wait, client.create_or_update,
resource_group_name=resource_group, service_name=name, resource=resource)
if sku is None:
sku = "Standard"
full_sku = models.Sku(
name=_get_sku_name(sku),
tier=sku
)
resource = models.ServiceResource(location=location, sku=full_sku)

return sdk_no_wait(no_wait, client.create_or_update, resource_group_name=resource_group, service_name=name, resource=resource)


def spring_cloud_update(cmd, client, resource_group, name, sku=None, no_wait=False):
full_sku = models.Sku(
name=_get_sku_name(sku),
tier=sku
)
resource = models.ServiceResource(sku=full_sku)

return sdk_no_wait(no_wait, client.update, resource_group_name=resource_group, service_name=name, resource=resource)


def spring_cloud_delete(cmd, client, resource_group, name, no_wait=False):
return sdk_no_wait(no_wait, client.delete,
resource_group_name=resource_group, service_name=name)
return sdk_no_wait(no_wait, client.delete, resource_group_name=resource_group, service_name=name)


def spring_cloud_list(cmd, client, resource_group=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .operations import CustomDomainsOperations
from .operations import DeploymentsOperations
from .operations import Operations
from .operations import SkuOperations
from . import models


Expand All @@ -43,6 +44,8 @@ class AppPlatformManagementClient(SDKClient):
:vartype deployments: azure.mgmt.appplatform.operations.DeploymentsOperations
:ivar operations: Operations operations
:vartype operations: azure.mgmt.appplatform.operations.Operations
:ivar sku: Sku operations
:vartype sku: azure.mgmt.appplatform.operations.SkuOperations

:param credentials: Credentials needed for the client to connect to Azure.
:type credentials: :mod:`A msrestazure Credentials
Expand Down Expand Up @@ -79,3 +82,5 @@ def __init__(
self._client, self.config, self._serialize, self._deserialize)
self.operations = Operations(
self._client, self.config, self._serialize, self._deserialize)
self.sku = SkuOperations(
self._client, self.config, self._serialize, self._deserialize)
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,17 @@
from ._models_py3 import ProxyResource
from ._models_py3 import RegenerateTestKeyRequestPayload
from ._models_py3 import Resource
from ._models_py3 import ResourceSku
from ._models_py3 import ResourceSkuCapabilities
from ._models_py3 import ResourceSkuLocationInfo
from ._models_py3 import ResourceSkuRestrictionInfo
from ._models_py3 import ResourceSkuRestrictions
from ._models_py3 import ResourceSkuZoneDetails
from ._models_py3 import ResourceUploadDefinition
from ._models_py3 import ServiceResource
from ._models_py3 import ServiceSpecification
from ._models_py3 import Sku
from ._models_py3 import SkuCapacity
from ._models_py3 import TemporaryDisk
from ._models_py3 import TestKeys
from ._models_py3 import TraceProperties
Expand Down Expand Up @@ -87,9 +95,17 @@
from ._models import ProxyResource
from ._models import RegenerateTestKeyRequestPayload
from ._models import Resource
from ._models import ResourceSku
from ._models import ResourceSkuCapabilities
from ._models import ResourceSkuLocationInfo
from ._models import ResourceSkuRestrictionInfo
from ._models import ResourceSkuRestrictions
from ._models import ResourceSkuZoneDetails
from ._models import ResourceUploadDefinition
from ._models import ServiceResource
from ._models import ServiceSpecification
from ._models import Sku
from ._models import SkuCapacity
from ._models import TemporaryDisk
from ._models import TestKeys
from ._models import TraceProperties
Expand All @@ -101,6 +117,7 @@
from ._paged_models import CustomDomainResourcePaged
from ._paged_models import DeploymentResourcePaged
from ._paged_models import OperationDetailPaged
from ._paged_models import ResourceSkuPaged
from ._paged_models import ServiceResourcePaged
from ._app_platform_management_client_enums import (
ProvisioningState,
Expand All @@ -113,6 +130,9 @@
RuntimeVersion,
DeploymentResourceProvisioningState,
DeploymentResourceStatus,
SkuScaleType,
ResourceSkuRestrictionsType,
ResourceSkuRestrictionsReasonCode,
)

__all__ = [
Expand Down Expand Up @@ -150,9 +170,17 @@
'ProxyResource',
'RegenerateTestKeyRequestPayload',
'Resource',
'ResourceSku',
'ResourceSkuCapabilities',
'ResourceSkuLocationInfo',
'ResourceSkuRestrictionInfo',
'ResourceSkuRestrictions',
'ResourceSkuZoneDetails',
'ResourceUploadDefinition',
'ServiceResource',
'ServiceSpecification',
'Sku',
'SkuCapacity',
'TemporaryDisk',
'TestKeys',
'TraceProperties',
Expand All @@ -165,6 +193,7 @@
'CustomDomainResourcePaged',
'DeploymentResourcePaged',
'OperationDetailPaged',
'ResourceSkuPaged',
'ProvisioningState',
'ConfigServerState',
'TraceProxyState',
Expand All @@ -175,4 +204,7 @@
'RuntimeVersion',
'DeploymentResourceProvisioningState',
'DeploymentResourceStatus',
'SkuScaleType',
'ResourceSkuRestrictionsType',
'ResourceSkuRestrictionsReasonCode',
]
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,22 @@ class DeploymentResourceStatus(str, Enum):
allocating = "Allocating"
upgrading = "Upgrading"
compiling = "Compiling"


class SkuScaleType(str, Enum):

none = "None"
manual = "Manual"
automatic = "Automatic"


class ResourceSkuRestrictionsType(str, Enum):

location = "Location"
zone = "Zone"


class ResourceSkuRestrictionsReasonCode(str, Enum):

quota_id = "QuotaId"
not_available_for_subscription = "NotAvailableForSubscription"
Loading