Skip to content

Commit

Permalink
{aaz} Rename aaz profile package name by adding profile_ prefix f…
Browse files Browse the repository at this point in the history
…or azure stack profiles. (#27073)

* Rename aaz profile package name by adding 'profile_' prefix for azure stack profiles

* add comments

* fix network and vm profile module load

* fix compact script
  • Loading branch information
kairu-ms authored Aug 3, 2023
1 parent b5ad5d3 commit 3a0c926
Show file tree
Hide file tree
Showing 983 changed files with 39 additions and 26 deletions.
4 changes: 3 additions & 1 deletion scripts/compact_aaz.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ def compact(self):
_LOGGER.info("Compacting {} folder:".format(self._get_aaz_folder()))
self._create_compact_aaz_folder()
from azure.cli.core.profiles import AZURE_API_PROFILES
from azure.cli.core.aaz.utils import get_aaz_profile_module_name
for profile in AZURE_API_PROFILES:
_LOGGER.info("Compacting profile {}".format(profile))
profile_mod_name = profile.lower().replace('-', '_')

profile_mod_name = get_aaz_profile_module_name(profile)
profile_path = self._get_aaz_rg_path(profile_mod_name)
if not os.path.exists(profile_path):
continue
Expand Down
3 changes: 2 additions & 1 deletion src/azure-cli-core/azure/cli/core/aaz/_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from ._poller import AAZLROPoller
from ._command_ctx import AAZCommandCtx
from .exceptions import AAZUnknownFieldError, AAZUnregisteredArg
from .utils import get_aaz_profile_module_name


logger = get_logger(__name__)
Expand Down Expand Up @@ -408,7 +409,7 @@ def load_aaz_command_table(loader, aaz_pkg_name, args):
def _get_profile_pkg(aaz_module_name, cloud):
""" load the profile package of aaz module according to the cloud profile.
"""
profile_module_name = cloud.profile.lower().replace('-', '_')
profile_module_name = get_aaz_profile_module_name(cloud.profile)
try:
return importlib.import_module(f'{aaz_module_name}.{profile_module_name}')
except ModuleNotFoundError:
Expand Down
8 changes: 8 additions & 0 deletions src/azure-cli-core/azure/cli/core/aaz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,11 @@ def assign_aaz_dict_arg(target: AAZDict, source: AAZDict, element_transformer=No
target[key] = element

return target


def get_aaz_profile_module_name(profile_name):
profile_module_name = profile_name.lower().replace('-', '_')
if profile_module_name != "latest":
# the rest profiles for azure-stack use start with digit number, it's not a valid python package name.
profile_module_name = "profile_" + profile_module_name
return profile_module_name
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _ensure_subnet_service_endpoint(cli_ctx, subnet_id):
' Use --ignore-missing-endpoint or -i to'
' skip validation and manually verify service endpoint.')
# ad-hoc api version 2019-02-01
Subnet = import_module("azure.cli.command_modules.appservice.aaz.2019_03_01_hybrid.network.vnet.subnet")
Subnet = import_module("azure.cli.command_modules.appservice.aaz.profile_2019_03_01_hybrid.network.vnet.subnet")
subnet_obj = Subnet.Show(cli_ctx=cli_ctx)(command_args={
"name": subnet_name,
"vnet_name": subnet_vnet_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
VERSION_2019_10_01 = "2019-10-01"
# ad-hoc api version 2020-04-01
appservice = "azure.cli.command_modules.appservice"
NSG = import_module(".aaz.2020_09_01_hybrid.network.nsg", package=appservice)
NSGRule = import_module(".aaz.2020_09_01_hybrid.network.nsg.rule", package=appservice)
RouteTable = import_module(".aaz.2020_09_01_hybrid.network.route_table", package=appservice)
RouteTableRoute = import_module(".aaz.2020_09_01_hybrid.network.route_table.route", package=appservice)
Subnet = import_module(".aaz.2020_09_01_hybrid.network.vnet.subnet", package=appservice)
NSG = import_module(".aaz.profile_2020_09_01_hybrid.network.nsg", package=appservice)
NSGRule = import_module(".aaz.profile_2020_09_01_hybrid.network.nsg.rule", package=appservice)
RouteTable = import_module(".aaz.profile_2020_09_01_hybrid.network.route_table", package=appservice)
RouteTableRoute = import_module(".aaz.profile_2020_09_01_hybrid.network.route_table.route", package=appservice)
Subnet = import_module(".aaz.profile_2020_09_01_hybrid.network.vnet.subnet", package=appservice)

logger = get_logger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion src/azure-cli/azure/cli/command_modules/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def load_arguments(self, command):
profile.load_arguments(self, command)

def get_module_name_by_profile(self, module_name):
profile_module_name = self.cli_ctx.cloud.profile.lower().replace('-', '_')
from azure.cli.core.aaz.utils import get_aaz_profile_module_name
profile_module_name = get_aaz_profile_module_name(profile_name=self.cli_ctx.cloud.profile)
if module_name:
return f'azure.cli.command_modules.network.azure_stack.{profile_module_name}.{module_name}'
return f'azure.cli.command_modules.network.azure_stack.{profile_module_name}'
Expand Down
Loading

0 comments on commit 3a0c926

Please sign in to comment.