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,5 +1,9 @@
Release History
===============
3.1.7
---
* Remove dependency to NETWORK SDK

3.1.6
---
* The spring-cloud command group has been deprecated and will be removed in Nov. 2022.
Expand Down
73 changes: 42 additions & 31 deletions src/spring-cloud/azext_spring_cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

from azure.cli.core.commands import CliCommandType
from azext_spring_cloud._help import helps # pylint: disable=unused-import
from azext_spring_cloud._client_factory import cf_spring_cloud
from azext_spring_cloud.commands import load_command_table
from azext_spring_cloud._params import load_arguments


class spring_cloudCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
spring_cloud_custom = CliCommandType(
operations_tmpl='azext_spring_cloud.custom#{}',
client_factory=cf_spring_cloud)
super(spring_cloudCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=spring_cloud_custom)

def load_command_table(self, args):
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
load_arguments(self, command)


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

from azure.cli.core import AzCommandsLoader

from azure.cli.core.commands import CliCommandType
from azext_spring_cloud._help import helps # pylint: disable=unused-import
from azext_spring_cloud._client_factory import cf_spring_cloud
from azext_spring_cloud.commands import load_command_table
from azext_spring_cloud._params import load_arguments


class spring_cloudCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
spring_cloud_custom = CliCommandType(
operations_tmpl='azext_spring_cloud.custom#{}',
client_factory=cf_spring_cloud)
super(spring_cloudCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=spring_cloud_custom)

def load_command_table(self, args):
from azure.cli.core.aaz import load_aaz_command_table
try:
from . import aaz
except ImportError:
aaz = None
if aaz:
load_aaz_command_table(
loader=self,
aaz_pkg_name=aaz.__name__,
args=args
)
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
load_arguments(self, command)


COMMAND_LOADER_CLS = spring_cloudCommandsLoader
59 changes: 35 additions & 24 deletions src/spring-cloud/azext_spring_cloud/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,51 +299,62 @@ def validate_vnet(cmd, namespace):
instance_location_slice = instance_location.split(" ")
instance_location = "".join([piece.lower()
for piece in instance_location_slice])
if vnet_obj.location.lower() != instance_location.lower():
if vnet_obj["location"].lower() != instance_location.lower():
raise InvalidArgumentValueError('--vnet and Azure Spring Cloud instance should be in the same location.')
for subnet in vnet_obj.subnets:
for subnet in vnet_obj["subnets"]:
_validate_subnet(namespace, subnet)
_validate_route_table(namespace, vnet_obj)

if namespace.reserved_cidr_range:
_validate_cidr_range(namespace)
else:
namespace.reserved_cidr_range = _set_default_cidr_range(vnet_obj.address_space.address_prefixes) if \
vnet_obj and vnet_obj.address_space and vnet_obj.address_space.address_prefixes \
namespace.reserved_cidr_range = _set_default_cidr_range(vnet_obj["addressSpace"]["addressPrefixes"]) if \
vnet_obj and vnet_obj.get("addressSpace", None) and vnet_obj["addressSpace"].get("addressPrefixes", None) \
else '10.234.0.0/16,10.244.0.0/16,172.17.0.1/16'


def _validate_subnet(namespace, subnet):
name = ''
limit = 32
if subnet.id.lower() == namespace.app_subnet.lower():
if subnet["id"].lower() == namespace.app_subnet.lower():
name = 'app-subnet'
limit = 28
elif subnet.id.lower() == namespace.service_runtime_subnet.lower():
elif subnet["id"].lower() == namespace.service_runtime_subnet.lower():
name = 'service-runtime-subnet'
limit = 28
else:
return
if subnet.ip_configurations:
if subnet.get("ipConfigurations", None):
raise InvalidArgumentValueError('--{} should not have connected device.'.format(name))
address = ip_network(subnet.address_prefix, strict=False)
address = ip_network(subnet["addressPrefix"], strict=False)
if address.prefixlen > limit:
raise InvalidArgumentValueError('--{0} should contain at least /{1} address, got /{2}'.format(name, limit, address.prefixlen))


def _get_vnet(cmd, vnet_id):
vnet = parse_resource_id(vnet_id)
network_client = _get_network_client(cmd.cli_ctx, subscription_id=vnet['subscription'])
return network_client.virtual_networks.get(vnet['resource_group'], vnet['resource_name'])


def _get_network_client(cli_ctx, subscription_id=None):
from azure.cli.core.profiles import ResourceType, get_api_version
from azure.cli.core.commands.client_factory import get_mgmt_service_client
return get_mgmt_service_client(cli_ctx,
ResourceType.MGMT_NETWORK,
subscription_id=subscription_id,
api_version=get_api_version(cli_ctx, ResourceType.MGMT_NETWORK))
from .aaz.latest.network.vnet import Show as _VirtualNetworkShow

class VirtualNetworkShow(_VirtualNetworkShow):
@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
from azure.cli.core.aaz import AAZStrArg
args_schema = super()._build_arguments_schema(*args, **kwargs)
args_schema.subscription_id = AAZStrArg()
return args_schema

def pre_operations(self):
from azure.cli.core.aaz import has_value
args = self.ctx.args
if has_value(args.subscription_id):
self.ctx._subscription_id = args.subscription_id

get_args = {
'name': vnet['resource_name'],
'subscription_id': vnet['subscription'],
'resource_group': vnet['resource_group']
}
return VirtualNetworkShow(cli_ctx=cmd.cli_ctx)(command_args=get_args)


def _get_authorization_client(cli_ctx, subscription_id=None):
Expand Down Expand Up @@ -508,11 +519,11 @@ def _validate_resource_group_name(name, message_name):
def _validate_route_table(namespace, vnet_obj):
app_route_table_id = ""
runtime_route_table_id = ""
for subnet in vnet_obj.subnets:
if subnet.id.lower() == namespace.app_subnet.lower() and subnet.route_table:
app_route_table_id = subnet.route_table.id
if subnet.id.lower() == namespace.service_runtime_subnet.lower() and subnet.route_table:
runtime_route_table_id = subnet.route_table.id
for subnet in vnet_obj["subnets"]:
if subnet["id"].lower() == namespace.app_subnet.lower() and subnet.get("routeTable", None):
app_route_table_id = subnet["routeTable"]["id"]
if subnet["id"].lower() == namespace.service_runtime_subnet.lower() and subnet.get("routeTable", None):
runtime_route_table_id = subnet["routeTable"]["id"]

if app_route_table_id and runtime_route_table_id:
if app_route_table_id == runtime_route_table_id:
Expand Down
6 changes: 6 additions & 0 deletions src/spring-cloud/azext_spring_cloud/aaz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# --------------------------------------------------------------------------------------------
# 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 aaz-dev-tools
# --------------------------------------------------------------------------------------------
6 changes: 6 additions & 0 deletions src/spring-cloud/azext_spring_cloud/aaz/latest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# --------------------------------------------------------------------------------------------
# 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 aaz-dev-tools
# --------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# --------------------------------------------------------------------------------------------
# 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 aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


class __CMDGroup(AAZCommandGroup):
"""Manage Azure Network resources.
"""
pass


__all__ = ["__CMDGroup"]
11 changes: 11 additions & 0 deletions src/spring-cloud/azext_spring_cloud/aaz/latest/network/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# 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 aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# --------------------------------------------------------------------------------------------
# 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 aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


class __CMDGroup(AAZCommandGroup):
"""Check if a private IP address is available for use within a virtual network.

To learn more about Virtual Networks visit https://docs.microsoft.com/azure/virtual-network/virtual-network-manage-network.
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# --------------------------------------------------------------------------------------------
# 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 aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
from ._show import *
Loading