Skip to content

Commit

Permalink
replace network sdk for spring (#5971)
Browse files Browse the repository at this point in the history
* replace network sdk for spring
  • Loading branch information
AllyW committed Mar 14, 2023
1 parent 4b5cd12 commit 6dbe8e0
Show file tree
Hide file tree
Showing 13 changed files with 2,593 additions and 41 deletions.
4 changes: 4 additions & 0 deletions src/spring/HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Release History
===============
1.7.1
---
* Remove dependency to NETWORK SDK

1.7.0
---
* Print application logs when create/update deployment
Expand Down
11 changes: 11 additions & 0 deletions src/spring/azext_spring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ def __init__(self, cli_ctx=None):
super(springCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=spring_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

Expand Down
58 changes: 34 additions & 24 deletions src/spring/azext_spring/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,51 +358,61 @@ 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 Apps 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 @@ -567,11 +577,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/azext_spring/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/azext_spring/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
# --------------------------------------------------------------------------------------------
20 changes: 20 additions & 0 deletions src/spring/azext_spring/aaz/latest/network/__cmd_group.py
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/azext_spring/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 *
22 changes: 22 additions & 0 deletions src/spring/azext_spring/aaz/latest/network/vnet/__cmd_group.py
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"]
12 changes: 12 additions & 0 deletions src/spring/azext_spring/aaz/latest/network/vnet/__init__.py
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

0 comments on commit 6dbe8e0

Please sign in to comment.