From b0119b3875946d28f42eace5065f687dc65683e5 Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Tue, 18 Apr 2023 15:17:16 +0100 Subject: [PATCH 001/145] initial commit of azdev generated files and code --- .github/CODEOWNERS | 2 +- src/aosm/HISTORY.rst | 8 +++ src/aosm/README.rst | 5 ++ src/aosm/azext_aosm/__init__.py | 32 ++++++++++ src/aosm/azext_aosm/_client_factory.py | 12 ++++ src/aosm/azext_aosm/_help.py | 23 ++++++++ src/aosm/azext_aosm/_params.py | 23 ++++++++ src/aosm/azext_aosm/_validators.py | 21 +++++++ src/aosm/azext_aosm/azext_metadata.json | 5 ++ src/aosm/azext_aosm/commands.py | 26 +++++++++ src/aosm/azext_aosm/custom.py | 20 +++++++ src/aosm/azext_aosm/tests/__init__.py | 5 ++ src/aosm/azext_aosm/tests/latest/__init__.py | 5 ++ .../tests/latest/test_aosm_scenario.py | 40 +++++++++++++ src/aosm/setup.cfg | 2 + src/aosm/setup.py | 58 +++++++++++++++++++ 16 files changed, 286 insertions(+), 1 deletion(-) create mode 100644 src/aosm/HISTORY.rst create mode 100644 src/aosm/README.rst create mode 100644 src/aosm/azext_aosm/__init__.py create mode 100644 src/aosm/azext_aosm/_client_factory.py create mode 100644 src/aosm/azext_aosm/_help.py create mode 100644 src/aosm/azext_aosm/_params.py create mode 100644 src/aosm/azext_aosm/_validators.py create mode 100644 src/aosm/azext_aosm/azext_metadata.json create mode 100644 src/aosm/azext_aosm/commands.py create mode 100644 src/aosm/azext_aosm/custom.py create mode 100644 src/aosm/azext_aosm/tests/__init__.py create mode 100644 src/aosm/azext_aosm/tests/latest/__init__.py create mode 100644 src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py create mode 100644 src/aosm/setup.cfg create mode 100644 src/aosm/setup.py diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 90407e25e14..592e442f31c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -284,4 +284,4 @@ /src/traffic-controller/ @jaishals -/src/managedccfs/ @msftsettiy \ No newline at end of file +/src/managedccfs/ @msftsettiy/src/azext_aosm/ @jddarby diff --git a/src/aosm/HISTORY.rst b/src/aosm/HISTORY.rst new file mode 100644 index 00000000000..8c34bccfff8 --- /dev/null +++ b/src/aosm/HISTORY.rst @@ -0,0 +1,8 @@ +.. :changelog: + +Release History +=============== + +0.1.0 +++++++ +* Initial release. \ No newline at end of file diff --git a/src/aosm/README.rst b/src/aosm/README.rst new file mode 100644 index 00000000000..dca4757fd38 --- /dev/null +++ b/src/aosm/README.rst @@ -0,0 +1,5 @@ +Microsoft Azure CLI 'aosm' Extension +========================================== + +This package is for the 'aosm' extension. +i.e. 'az aosm' \ No newline at end of file diff --git a/src/aosm/azext_aosm/__init__.py b/src/aosm/azext_aosm/__init__.py new file mode 100644 index 00000000000..baf34c3bfad --- /dev/null +++ b/src/aosm/azext_aosm/__init__.py @@ -0,0 +1,32 @@ +# -------------------------------------------------------------------------------------------- +# 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 azext_aosm._help import helps # pylint: disable=unused-import + + +class AosmCommandsLoader(AzCommandsLoader): + + def __init__(self, cli_ctx=None): + from azure.cli.core.commands import CliCommandType + from azext_aosm._client_factory import cf_aosm + aosm_custom = CliCommandType( + operations_tmpl='azext_aosm.custom#{}', + client_factory=cf_aosm) + super(AosmCommandsLoader, self).__init__(cli_ctx=cli_ctx, + custom_command_type=aosm_custom) + + def load_command_table(self, args): + from azext_aosm.commands import load_command_table + load_command_table(self, args) + return self.command_table + + def load_arguments(self, command): + from azext_aosm._params import load_arguments + load_arguments(self, command) + + +COMMAND_LOADER_CLS = AosmCommandsLoader diff --git a/src/aosm/azext_aosm/_client_factory.py b/src/aosm/azext_aosm/_client_factory.py new file mode 100644 index 00000000000..8ddc5ea07d0 --- /dev/null +++ b/src/aosm/azext_aosm/_client_factory.py @@ -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. +# -------------------------------------------------------------------------------------------- + +def cf_aosm(cli_ctx, *_): + + from azure.cli.core.commands.client_factory import get_mgmt_service_client + # TODO: Replace CONTOSO with the appropriate label and uncomment + # from azure.mgmt.CONTOSO import CONTOSOManagementClient + # return get_mgmt_service_client(cli_ctx, CONTOSOManagementClient) + return None diff --git a/src/aosm/azext_aosm/_help.py b/src/aosm/azext_aosm/_help.py new file mode 100644 index 00000000000..06451e824c8 --- /dev/null +++ b/src/aosm/azext_aosm/_help.py @@ -0,0 +1,23 @@ +# coding=utf-8 +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from knack.help_files import helps # pylint: disable=unused-import + + +helps['aosm'] = """ + type: group + short-summary: Commands to manage Aosms. +""" + +helps['aosm create'] = """ + type: command + short-summary: Create a Aosm. +""" + +helps['aosm list'] = """ + type: command + short-summary: List Aosms. +""" diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py new file mode 100644 index 00000000000..100dfe242c6 --- /dev/null +++ b/src/aosm/azext_aosm/_params.py @@ -0,0 +1,23 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +# pylint: disable=line-too-long + +from knack.arguments import CLIArgumentType + + +def load_arguments(self, _): + + from azure.cli.core.commands.parameters import tags_type + from azure.cli.core.commands.validators import get_default_location_from_resource_group + + aosm_name_type = CLIArgumentType(options_list='--aosm-name-name', help='Name of the Aosm.', id_part='name') + + with self.argument_context('aosm') as c: + c.argument('tags', tags_type) + c.argument('location', validator=get_default_location_from_resource_group) + c.argument('aosm_name', aosm_name_type, options_list=['--name', '-n']) + + with self.argument_context('aosm list') as c: + c.argument('aosm_name', aosm_name_type, id_part=None) diff --git a/src/aosm/azext_aosm/_validators.py b/src/aosm/azext_aosm/_validators.py new file mode 100644 index 00000000000..bdbc5023a4d --- /dev/null +++ b/src/aosm/azext_aosm/_validators.py @@ -0,0 +1,21 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + + +def example_name_or_id_validator(cmd, namespace): + # Example of a storage account name or ID validator. + # See: + # https://github.com/Azure/azure-cli/blob/dev/doc/authoring_command_modules/authoring_commands.md#supporting-name-or-id-parameters + from azure.cli.core.commands.client_factory import get_subscription_id + from msrestazure.tools import is_valid_resource_id, resource_id + if namespace.storage_account: + if not is_valid_resource_id(namespace.RESOURCE): + namespace.storage_account = resource_id( + subscription=get_subscription_id(cmd.cli_ctx), + resource_group=namespace.resource_group_name, + namespace='Microsoft.Storage', + type='storageAccounts', + name=namespace.storage_account + ) diff --git a/src/aosm/azext_aosm/azext_metadata.json b/src/aosm/azext_aosm/azext_metadata.json new file mode 100644 index 00000000000..da55858aa27 --- /dev/null +++ b/src/aosm/azext_aosm/azext_metadata.json @@ -0,0 +1,5 @@ +{ + "azext.isPreview": true, + "azext.minCliCoreVersion": "2.0.67", + "azext.maxCliCoreVersion": "2.47.0" +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py new file mode 100644 index 00000000000..322841395c5 --- /dev/null +++ b/src/aosm/azext_aosm/commands.py @@ -0,0 +1,26 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=line-too-long +from azure.cli.core.commands import CliCommandType +from azext_aosm._client_factory import cf_aosm + + +def load_command_table(self, _): + + # TODO: Add command type here + # aosm_sdk = CliCommandType( + # operations_tmpl='.operations#None.{}', + # client_factory=cf_aosm) + + with self.command_group('aosm') as g: + g.custom_command('create', 'create_aosm') + # g.command('delete', 'delete') + g.custom_command('list', 'list_aosm') + # g.show_command('show', 'get') + # g.generic_update_command('update', setter_name='update', custom_func_name='update_aosm') + + with self.command_group('aosm', is_preview=True): + pass diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py new file mode 100644 index 00000000000..afd522316d3 --- /dev/null +++ b/src/aosm/azext_aosm/custom.py @@ -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. +# -------------------------------------------------------------------------------------------- + +from knack.util import CLIError + + +def create_aosm(cmd, resource_group_name, aosm_name, location=None, tags=None): + raise CLIError('TODO: Implement `aosm create`') + + +def list_aosm(cmd, resource_group_name=None): + raise CLIError('TODO: Implement `aosm list`') + + +def update_aosm(cmd, instance, tags=None): + with cmd.update_context(instance) as c: + c.set_param('tags', tags) + return instance diff --git a/src/aosm/azext_aosm/tests/__init__.py b/src/aosm/azext_aosm/tests/__init__.py new file mode 100644 index 00000000000..2dcf9bb68b3 --- /dev/null +++ b/src/aosm/azext_aosm/tests/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/__init__.py b/src/aosm/azext_aosm/tests/latest/__init__.py new file mode 100644 index 00000000000..2dcf9bb68b3 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py b/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py new file mode 100644 index 00000000000..a8b6975181d --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py @@ -0,0 +1,40 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import os +import unittest + +# from azure_devtools.scenario_tests import AllowLargeResponse +from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) + + +TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) + + +class AosmScenarioTest(ScenarioTest): + + @ResourceGroupPreparer(name_prefix='cli_test_aosm') + def test_aosm(self, resource_group): + + self.kwargs.update({ + 'name': 'test1' + }) + + self.cmd('aosm create -g {rg} -n {name} --tags foo=doo', checks=[ + self.check('tags.foo', 'doo'), + self.check('name', '{name}') + ]) + self.cmd('aosm update -g {rg} -n {name} --tags foo=boo', checks=[ + self.check('tags.foo', 'boo') + ]) + count = len(self.cmd('aosm list').get_output_in_json()) + self.cmd('aosm show - {rg} -n {name}', checks=[ + self.check('name', '{name}'), + self.check('resourceGroup', '{rg}'), + self.check('tags.foo', 'boo') + ]) + self.cmd('aosm delete -g {rg} -n {name}') + final_count = len(self.cmd('aosm list').get_output_in_json()) + self.assertTrue(final_count, count - 1) diff --git a/src/aosm/setup.cfg b/src/aosm/setup.cfg new file mode 100644 index 00000000000..3c6e79cf31d --- /dev/null +++ b/src/aosm/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal=1 diff --git a/src/aosm/setup.py b/src/aosm/setup.py new file mode 100644 index 00000000000..cec93421831 --- /dev/null +++ b/src/aosm/setup.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + + +from codecs import open +from setuptools import setup, find_packages +try: + from azure_bdist_wheel import cmdclass +except ImportError: + from distutils import log as logger + logger.warn("Wheel is not available, disabling bdist_wheel hook") + +# TODO: Confirm this is the right version number you want and it matches your +# HISTORY.rst entry. +VERSION = '0.1.0' + +# The full list of classifiers is available at +# https://pypi.python.org/pypi?%3Aaction=list_classifiers +CLASSIFIERS = [ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'Intended Audience :: System Administrators', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'License :: OSI Approved :: MIT License', +] + +# TODO: Add any additional SDK dependencies here +DEPENDENCIES = [] + +with open('README.rst', 'r', encoding='utf-8') as f: + README = f.read() +with open('HISTORY.rst', 'r', encoding='utf-8') as f: + HISTORY = f.read() + +setup( + name='aosm', + version=VERSION, + description='Microsoft Azure Command-Line Tools Aosm Extension', + # TODO: Update author and email, if applicable + author='Microsoft Corporation', + author_email='azpycli@microsoft.com', + # TODO: change to your extension source code repo if the code will not be put in azure-cli-extensions repo + url='https://github.com/Azure/azure-cli-extensions/tree/master/src/aosm', + long_description=README + '\n\n' + HISTORY, + license='MIT', + classifiers=CLASSIFIERS, + packages=find_packages(), + install_requires=DEPENDENCIES, + package_data={'azext_aosm': ['azext_metadata.json']}, +) \ No newline at end of file From b3d8ebc086ab470e8794a54ff6bcd2c8d8916155 Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Mon, 24 Apr 2023 19:11:45 +0100 Subject: [PATCH 002/145] add SDK generated with autorest tool --- src/aosm/azext_aosm/__init__.py | 8 +- src/aosm/azext_aosm/_client_factory.py | 10 +- src/aosm/azext_aosm/_help.py | 15 +- src/aosm/azext_aosm/_params.py | 33 +- src/aosm/azext_aosm/azext_metadata.json | 3 +- src/aosm/azext_aosm/commands.py | 14 +- src/aosm/azext_aosm/custom.py | 46 +- src/aosm/azext_aosm/vendored_sdks/__init__.py | 18 + .../vendored_sdks/_configuration.py | 76 + .../_hybrid_network_management_client.py | 173 + src/aosm/azext_aosm/vendored_sdks/_patch.py | 31 + src/aosm/azext_aosm/vendored_sdks/_vendor.py | 27 + src/aosm/azext_aosm/vendored_sdks/_version.py | 9 + .../azext_aosm/vendored_sdks/aio/__init__.py | 15 + .../vendored_sdks/aio/_configuration.py | 72 + .../aio/_hybrid_network_management_client.py | 166 + .../azext_aosm/vendored_sdks/aio/_patch.py | 31 + .../vendored_sdks/aio/operations/__init__.py | 53 + .../_artifact_manifests_operations.py | 738 ++ .../operations/_artifact_stores_operations.py | 508 ++ .../aio/operations/_components_operations.py | 192 + ..._configuration_group_schemas_operations.py | 643 ++ .../_configuration_group_values_operations.py | 559 ++ ...id_network_management_client_operations.py | 170 + ...k_function_definition_groups_operations.py | 515 ++ ...function_definition_versions_operations.py | 692 ++ ..._network_function_ready_k8_s_operations.py | 559 ++ .../_network_functions_operations.py | 673 ++ ...etwork_service_design_groups_operations.py | 511 ++ ...work_service_design_versions_operations.py | 680 ++ .../aio/operations/_operations.py | 115 + .../_preview_subscriptions_operations.py | 540 ++ .../operations/_proxy_artifact_operations.py | 228 + ...k_function_definition_groups_operations.py | 203 + ...function_definition_versions_operations.py | 215 + .../operations/_proxy_publisher_operations.py | 193 + .../aio/operations/_publishers_operations.py | 561 ++ .../_site_network_services_operations.py | 557 ++ .../aio/operations/_sites_operations.py | 552 ++ .../vendored_sdks/models/__init__.py | 484 ++ ..._hybrid_network_management_client_enums.py | 247 + .../vendored_sdks/models/_models.py | 6039 +++++++++++++++ .../vendored_sdks/models/_models_py3.py | 6446 +++++++++++++++++ .../vendored_sdks/operations/__init__.py | 53 + .../_artifact_manifests_operations.py | 1050 +++ .../operations/_artifact_stores_operations.py | 721 ++ .../operations/_components_operations.py | 277 + ..._configuration_group_schemas_operations.py | 900 +++ .../_configuration_group_values_operations.py | 796 ++ ...id_network_management_client_operations.py | 227 + ...k_function_definition_groups_operations.py | 729 ++ ...function_definition_versions_operations.py | 962 +++ ..._network_function_ready_k8_s_operations.py | 796 ++ .../_network_functions_operations.py | 951 +++ ...etwork_service_design_groups_operations.py | 725 ++ ...work_service_design_versions_operations.py | 950 +++ .../vendored_sdks/operations/_operations.py | 152 + .../_preview_subscriptions_operations.py | 763 ++ .../operations/_proxy_artifact_operations.py | 319 + ...k_function_definition_groups_operations.py | 293 + ...function_definition_versions_operations.py | 309 + .../operations/_proxy_publisher_operations.py | 279 + .../operations/_publishers_operations.py | 796 ++ .../_site_network_services_operations.py | 795 ++ .../operations/_sites_operations.py | 790 ++ src/aosm/azext_aosm/vendored_sdks/py.typed | 1 + src/aosm/setup.py | 2 +- 67 files changed, 37211 insertions(+), 45 deletions(-) create mode 100644 src/aosm/azext_aosm/vendored_sdks/__init__.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/_configuration.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/_patch.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/_vendor.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/_version.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/__init__.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/_configuration.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/_patch.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_artifact_manifests_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_artifact_stores_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_components_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_configuration_group_schemas_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_configuration_group_values_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_hybrid_network_management_client_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_definition_groups_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_definition_versions_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_ready_k8_s_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_functions_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_service_design_groups_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_service_design_versions_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_preview_subscriptions_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_artifact_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_network_function_definition_groups_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_network_function_definition_versions_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_publisher_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_publishers_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_site_network_services_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/aio/operations/_sites_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/models/__init__.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/models/_hybrid_network_management_client_enums.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/models/_models.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/models/_models_py3.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/__init__.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_artifact_manifests_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_artifact_stores_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_components_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_configuration_group_schemas_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_configuration_group_values_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_hybrid_network_management_client_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_network_function_definition_groups_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_network_function_definition_versions_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_network_function_ready_k8_s_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_network_functions_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_network_service_design_groups_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_network_service_design_versions_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_preview_subscriptions_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_proxy_artifact_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_proxy_network_function_definition_groups_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_proxy_network_function_definition_versions_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_proxy_publisher_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_publishers_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_site_network_services_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/operations/_sites_operations.py create mode 100644 src/aosm/azext_aosm/vendored_sdks/py.typed diff --git a/src/aosm/azext_aosm/__init__.py b/src/aosm/azext_aosm/__init__.py index baf34c3bfad..a360b6ceca5 100644 --- a/src/aosm/azext_aosm/__init__.py +++ b/src/aosm/azext_aosm/__init__.py @@ -12,12 +12,8 @@ class AosmCommandsLoader(AzCommandsLoader): def __init__(self, cli_ctx=None): from azure.cli.core.commands import CliCommandType - from azext_aosm._client_factory import cf_aosm - aosm_custom = CliCommandType( - operations_tmpl='azext_aosm.custom#{}', - client_factory=cf_aosm) - super(AosmCommandsLoader, self).__init__(cli_ctx=cli_ctx, - custom_command_type=aosm_custom) + aosm_custom = CliCommandType(operations_tmpl='azext_aosm.custom#{}') + super(AosmCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=aosm_custom) def load_command_table(self, args): from azext_aosm.commands import load_command_table diff --git a/src/aosm/azext_aosm/_client_factory.py b/src/aosm/azext_aosm/_client_factory.py index 8ddc5ea07d0..ab281c30153 100644 --- a/src/aosm/azext_aosm/_client_factory.py +++ b/src/aosm/azext_aosm/_client_factory.py @@ -3,10 +3,8 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -def cf_aosm(cli_ctx, *_): +from azure.cli.core.commands.client_factory import get_mgmt_service_client +from .vendored_sdks import HybridNetworkManagementClient - from azure.cli.core.commands.client_factory import get_mgmt_service_client - # TODO: Replace CONTOSO with the appropriate label and uncomment - # from azure.mgmt.CONTOSO import CONTOSOManagementClient - # return get_mgmt_service_client(cli_ctx, CONTOSOManagementClient) - return None +def cf_aosm(cli_ctx, *_) -> HybridNetworkManagementClient: + return get_mgmt_service_client(cli_ctx, HybridNetworkManagementClient) diff --git a/src/aosm/azext_aosm/_help.py b/src/aosm/azext_aosm/_help.py index 06451e824c8..1fb3bb11b3f 100644 --- a/src/aosm/azext_aosm/_help.py +++ b/src/aosm/azext_aosm/_help.py @@ -9,15 +9,20 @@ helps['aosm'] = """ type: group - short-summary: Commands to manage Aosms. + short-summary: Commands to interact with Azure Operator Service Manager (AOSM). """ -helps['aosm create'] = """ +helps['aosm definition'] = """ + type: group + short-summary: Manage AOSM publisher definitions. +""" + +helps['aosm definition build'] = """ type: command - short-summary: Create a Aosm. + short-summary: Build an AOSM publisher definition. """ -helps['aosm list'] = """ +helps['aosm definition generate-config'] = """ type: command - short-summary: List Aosms. + short-summary: Generate configuration file for building an AOSM publisher definition. """ diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index 100dfe242c6..e25ea08b478 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -4,20 +4,33 @@ # -------------------------------------------------------------------------------------------- # pylint: disable=line-too-long +from argcomplete.completers import FilesCompleter +from azure.cli.core import AzCommandsLoader from knack.arguments import CLIArgumentType -def load_arguments(self, _): +def load_arguments(self: AzCommandsLoader, _): - from azure.cli.core.commands.parameters import tags_type - from azure.cli.core.commands.validators import get_default_location_from_resource_group + from azure.cli.core.commands.parameters import file_type, get_enum_type, get_three_state_flag - aosm_name_type = CLIArgumentType(options_list='--aosm-name-name', help='Name of the Aosm.', id_part='name') + definition_type = get_enum_type(["vnf", "cnf", "nsd"]) - with self.argument_context('aosm') as c: - c.argument('tags', tags_type) - c.argument('location', validator=get_default_location_from_resource_group) - c.argument('aosm_name', aosm_name_type, options_list=['--name', '-n']) + # Set the argument context so these options are only available when this specific command + # is called. + with self.argument_context('aosm definition') as c: + c.argument( + 'definition_type', + arg_type=definition_type, + help='Type of AOSM definition to generate.' + ) + c.argument( + 'config_file', + options_list=["--config-file", "-f"], + type=file_type, + completer=FilesCompleter(allowednames="*.json"), + help='The path to the configuration file.' + ) + c.argument('publish', arg_type=get_three_state_flag(), help='Publishes generated AOSM definition.') - with self.argument_context('aosm list') as c: - c.argument('aosm_name', aosm_name_type, id_part=None) + with self.argument_context('aosm generate-config') as c: + c.argument('definition_type', arg_type=definition_type, help='Type of AOSM definition config to generate.') diff --git a/src/aosm/azext_aosm/azext_metadata.json b/src/aosm/azext_aosm/azext_metadata.json index da55858aa27..be5de02d927 100644 --- a/src/aosm/azext_aosm/azext_metadata.json +++ b/src/aosm/azext_aosm/azext_metadata.json @@ -1,5 +1,4 @@ { "azext.isPreview": true, - "azext.minCliCoreVersion": "2.0.67", - "azext.maxCliCoreVersion": "2.47.0" + "azext.minCliCoreVersion": "2.45.0" } \ No newline at end of file diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index 322841395c5..ffa2263d0e4 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -4,23 +4,23 @@ # -------------------------------------------------------------------------------------------- # pylint: disable=line-too-long +from azure.cli.core import AzCommandsLoader from azure.cli.core.commands import CliCommandType from azext_aosm._client_factory import cf_aosm -def load_command_table(self, _): +def load_command_table(self: AzCommandsLoader, _): # TODO: Add command type here # aosm_sdk = CliCommandType( # operations_tmpl='.operations#None.{}', # client_factory=cf_aosm) - with self.command_group('aosm') as g: - g.custom_command('create', 'create_aosm') - # g.command('delete', 'delete') - g.custom_command('list', 'list_aosm') - # g.show_command('show', 'get') - # g.generic_update_command('update', setter_name='update', custom_func_name='update_aosm') + with self.command_group('aosm definition', client_factory=cf_aosm) as g: + # Add each command and bind it to a function in custom.py + g.custom_command('build', 'build_definition') + g.custom_command('generate-config', 'generate_definition_config') + g.custom_command('show', 'show_publisher') with self.command_group('aosm', is_preview=True): pass diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index afd522316d3..2b29643a015 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -3,18 +3,48 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- +import json + +from dataclasses import asdict +from knack.log import get_logger from knack.util import CLIError +from .vendored_sdks import HybridNetworkManagementClient +from .vendored_sdks.models import Publisher +from ._configuration import Configuration, VNFConfiguration + +logger = get_logger(__name__) + +def build_definition(cmd, definition_type, config_file, publish=False): + with open(config_file, "r") as f: + config_dict = json.loads(f) + if definition_type == "vnf": + config = VNFConfiguration(**config_dict) + elif definition_type == "cnf": + config = Configuration(**config_dict) + elif definition_type == "nsd": + config = Configuration(**config_dict) + else: + raise CLIError("Definition type not recognized, options are: vnf, cnf or nsd") -def create_aosm(cmd, resource_group_name, aosm_name, location=None, tags=None): - raise CLIError('TODO: Implement `aosm create`') + if publish: -def list_aosm(cmd, resource_group_name=None): - raise CLIError('TODO: Implement `aosm list`') +def generate_definition_config(cmd, definition_type, output_file="input.json"): + if definition_type == "vnf": + config = VNFConfiguration() + elif definition_type == "cnf": + config = Configuration() + elif definition_type == "nsd": + config = Configuration() + else: + raise CLIError("Definition type not recognized, options are: vnf, cnf or nsd") + with open(output_file, "w", encoding="utf-8") as f: + config_as_dict = json.dumps(asdict(config), indent=4) + f.write(config_as_dict) + logger.info("Empty definition configuration has been written to %s", output_file) -def update_aosm(cmd, instance, tags=None): - with cmd.update_context(instance) as c: - c.set_param('tags', tags) - return instance +def show_publisher(cmd, client: HybridNetworkManagementClient, resource_group_name, publisher_name): + publisher: Publisher = client.publishers.get(resource_group_name, publisher_name) + print(f"Publisher id = {publisher.id}") diff --git a/src/aosm/azext_aosm/vendored_sdks/__init__.py b/src/aosm/azext_aosm/vendored_sdks/__init__.py new file mode 100644 index 00000000000..37494f5f33e --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/__init__.py @@ -0,0 +1,18 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._hybrid_network_management_client import HybridNetworkManagementClient +from ._version import VERSION + +__version__ = VERSION +__all__ = ['HybridNetworkManagementClient'] + +# `._patch.py` is used for handwritten extensions to the generated code +# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +from ._patch import patch_sdk +patch_sdk() diff --git a/src/aosm/azext_aosm/vendored_sdks/_configuration.py b/src/aosm/azext_aosm/vendored_sdks/_configuration.py new file mode 100644 index 00000000000..881c6609513 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/_configuration.py @@ -0,0 +1,76 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import TYPE_CHECKING + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies +from azure.mgmt.core.policies import ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy + +from ._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any + + from azure.core.credentials import TokenCredential + + +class HybridNetworkManagementClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for HybridNetworkManagementClient. + + Note that all parameters used to create this instance are saved as instance + attributes. + + :param credential: Credential needed for the client to connect to Azure. + :type credential: ~azure.core.credentials.TokenCredential + :param subscription_id: The ID of the target subscription. + :type subscription_id: str + :keyword api_version: Api Version. The default value is "2023-04-01-preview". Note that + overriding this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__( + self, + credential, # type: "TokenCredential" + subscription_id, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + super(HybridNetworkManagementClientConfiguration, self).__init__(**kwargs) + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + if credential is None: + raise ValueError("Parameter 'credential' must not be None.") + if subscription_id is None: + raise ValueError("Parameter 'subscription_id' must not be None.") + + self.credential = credential + self.subscription_id = subscription_id + self.api_version = api_version + self.credential_scopes = kwargs.pop('credential_scopes', ['https://management.azure.com/.default']) + kwargs.setdefault('sdk_moniker', 'hybridnetwork/{}'.format(VERSION)) + self._configure(**kwargs) + + def _configure( + self, + **kwargs # type: Any + ): + # type: (...) -> None + self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs) + self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get('http_logging_policy') or ARMHttpLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs) + self.authentication_policy = kwargs.get('authentication_policy') + if self.credential and not self.authentication_policy: + self.authentication_policy = ARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs) diff --git a/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py b/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py new file mode 100644 index 00000000000..fa704c623bc --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py @@ -0,0 +1,173 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from copy import deepcopy +from typing import TYPE_CHECKING + +from msrest import Deserializer, Serializer + +from azure.mgmt.core import ARMPipelineClient + +from . import models +from ._configuration import HybridNetworkManagementClientConfiguration +from .operations import ArtifactManifestsOperations, ArtifactStoresOperations, ComponentsOperations, ConfigurationGroupSchemasOperations, ConfigurationGroupValuesOperations, HybridNetworkManagementClientOperationsMixin, NetworkFunctionDefinitionGroupsOperations, NetworkFunctionDefinitionVersionsOperations, NetworkFunctionReadyK8SOperations, NetworkFunctionsOperations, NetworkServiceDesignGroupsOperations, NetworkServiceDesignVersionsOperations, Operations, PreviewSubscriptionsOperations, ProxyArtifactOperations, ProxyNetworkFunctionDefinitionGroupsOperations, ProxyNetworkFunctionDefinitionVersionsOperations, ProxyPublisherOperations, PublishersOperations, SiteNetworkServicesOperations, SitesOperations + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any + + from azure.core.credentials import TokenCredential + from azure.core.rest import HttpRequest, HttpResponse + +class HybridNetworkManagementClient(HybridNetworkManagementClientOperationsMixin): # pylint: disable=too-many-instance-attributes + """The definitions in this swagger specification will be used to manage the Hybrid Network + resources. + + :ivar configuration_group_schemas: ConfigurationGroupSchemasOperations operations + :vartype configuration_group_schemas: + Microsoft.HybridNetwork.operations.ConfigurationGroupSchemasOperations + :ivar configuration_group_values: ConfigurationGroupValuesOperations operations + :vartype configuration_group_values: + Microsoft.HybridNetwork.operations.ConfigurationGroupValuesOperations + :ivar network_functions: NetworkFunctionsOperations operations + :vartype network_functions: Microsoft.HybridNetwork.operations.NetworkFunctionsOperations + :ivar components: ComponentsOperations operations + :vartype components: Microsoft.HybridNetwork.operations.ComponentsOperations + :ivar network_function_definition_groups: NetworkFunctionDefinitionGroupsOperations operations + :vartype network_function_definition_groups: + Microsoft.HybridNetwork.operations.NetworkFunctionDefinitionGroupsOperations + :ivar preview_subscriptions: PreviewSubscriptionsOperations operations + :vartype preview_subscriptions: + Microsoft.HybridNetwork.operations.PreviewSubscriptionsOperations + :ivar network_function_definition_versions: NetworkFunctionDefinitionVersionsOperations + operations + :vartype network_function_definition_versions: + Microsoft.HybridNetwork.operations.NetworkFunctionDefinitionVersionsOperations + :ivar network_function_ready_k8_s: NetworkFunctionReadyK8SOperations operations + :vartype network_function_ready_k8_s: + Microsoft.HybridNetwork.operations.NetworkFunctionReadyK8SOperations + :ivar network_service_design_groups: NetworkServiceDesignGroupsOperations operations + :vartype network_service_design_groups: + Microsoft.HybridNetwork.operations.NetworkServiceDesignGroupsOperations + :ivar network_service_design_versions: NetworkServiceDesignVersionsOperations operations + :vartype network_service_design_versions: + Microsoft.HybridNetwork.operations.NetworkServiceDesignVersionsOperations + :ivar operations: Operations operations + :vartype operations: Microsoft.HybridNetwork.operations.Operations + :ivar proxy_publisher: ProxyPublisherOperations operations + :vartype proxy_publisher: Microsoft.HybridNetwork.operations.ProxyPublisherOperations + :ivar proxy_network_function_definition_groups: ProxyNetworkFunctionDefinitionGroupsOperations + operations + :vartype proxy_network_function_definition_groups: + Microsoft.HybridNetwork.operations.ProxyNetworkFunctionDefinitionGroupsOperations + :ivar proxy_network_function_definition_versions: + ProxyNetworkFunctionDefinitionVersionsOperations operations + :vartype proxy_network_function_definition_versions: + Microsoft.HybridNetwork.operations.ProxyNetworkFunctionDefinitionVersionsOperations + :ivar publishers: PublishersOperations operations + :vartype publishers: Microsoft.HybridNetwork.operations.PublishersOperations + :ivar artifact_stores: ArtifactStoresOperations operations + :vartype artifact_stores: Microsoft.HybridNetwork.operations.ArtifactStoresOperations + :ivar artifact_manifests: ArtifactManifestsOperations operations + :vartype artifact_manifests: Microsoft.HybridNetwork.operations.ArtifactManifestsOperations + :ivar proxy_artifact: ProxyArtifactOperations operations + :vartype proxy_artifact: Microsoft.HybridNetwork.operations.ProxyArtifactOperations + :ivar sites: SitesOperations operations + :vartype sites: Microsoft.HybridNetwork.operations.SitesOperations + :ivar site_network_services: SiteNetworkServicesOperations operations + :vartype site_network_services: + Microsoft.HybridNetwork.operations.SiteNetworkServicesOperations + :param credential: Credential needed for the client to connect to Azure. + :type credential: ~azure.core.credentials.TokenCredential + :param subscription_id: The ID of the target subscription. + :type subscription_id: str + :param base_url: Service URL. Default value is 'https://management.azure.com'. + :type base_url: str + :keyword api_version: Api Version. The default value is "2023-04-01-preview". Note that + overriding this default value may result in unsupported behavior. + :paramtype api_version: str + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + """ + + def __init__( + self, + credential, # type: "TokenCredential" + subscription_id, # type: str + base_url="https://management.azure.com", # type: str + **kwargs # type: Any + ): + # type: (...) -> None + self._config = HybridNetworkManagementClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) + self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs) + + client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} + self._serialize = Serializer(client_models) + self._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + self.configuration_group_schemas = ConfigurationGroupSchemasOperations(self._client, self._config, self._serialize, self._deserialize) + self.configuration_group_values = ConfigurationGroupValuesOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_functions = NetworkFunctionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.components = ComponentsOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_function_definition_groups = NetworkFunctionDefinitionGroupsOperations(self._client, self._config, self._serialize, self._deserialize) + self.preview_subscriptions = PreviewSubscriptionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_function_definition_versions = NetworkFunctionDefinitionVersionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_function_ready_k8_s = NetworkFunctionReadyK8SOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_service_design_groups = NetworkServiceDesignGroupsOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_service_design_versions = NetworkServiceDesignVersionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) + self.proxy_publisher = ProxyPublisherOperations(self._client, self._config, self._serialize, self._deserialize) + self.proxy_network_function_definition_groups = ProxyNetworkFunctionDefinitionGroupsOperations(self._client, self._config, self._serialize, self._deserialize) + self.proxy_network_function_definition_versions = ProxyNetworkFunctionDefinitionVersionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.publishers = PublishersOperations(self._client, self._config, self._serialize, self._deserialize) + self.artifact_stores = ArtifactStoresOperations(self._client, self._config, self._serialize, self._deserialize) + self.artifact_manifests = ArtifactManifestsOperations(self._client, self._config, self._serialize, self._deserialize) + self.proxy_artifact = ProxyArtifactOperations(self._client, self._config, self._serialize, self._deserialize) + self.sites = SitesOperations(self._client, self._config, self._serialize, self._deserialize) + self.site_network_services = SiteNetworkServicesOperations(self._client, self._config, self._serialize, self._deserialize) + + + def _send_request( + self, + request, # type: HttpRequest + **kwargs # type: Any + ): + # type: (...) -> HttpResponse + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.HttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + def close(self): + # type: () -> None + self._client.close() + + def __enter__(self): + # type: () -> HybridNetworkManagementClient + self._client.__enter__() + return self + + def __exit__(self, *exc_details): + # type: (Any) -> None + self._client.__exit__(*exc_details) diff --git a/src/aosm/azext_aosm/vendored_sdks/_patch.py b/src/aosm/azext_aosm/vendored_sdks/_patch.py new file mode 100644 index 00000000000..74e48ecd07c --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/_patch.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +# This file is used for handwritten extensions to the generated code. Example: +# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +def patch_sdk(): + pass \ No newline at end of file diff --git a/src/aosm/azext_aosm/vendored_sdks/_vendor.py b/src/aosm/azext_aosm/vendored_sdks/_vendor.py new file mode 100644 index 00000000000..138f663c53a --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/_vendor.py @@ -0,0 +1,27 @@ +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.core.pipeline.transport import HttpRequest + +def _convert_request(request, files=None): + data = request.content if not files else None + request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data) + if files: + request.set_formdata_body(files) + return request + +def _format_url_section(template, **kwargs): + components = template.split("/") + while components: + try: + return template.format(**kwargs) + except KeyError as key: + formatted_components = template.split("/") + components = [ + c for c in formatted_components if "{}".format(key.args[0]) not in c + ] + template = "/".join(components) diff --git a/src/aosm/azext_aosm/vendored_sdks/_version.py b/src/aosm/azext_aosm/vendored_sdks/_version.py new file mode 100644 index 00000000000..8d45d4618da --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/_version.py @@ -0,0 +1,9 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +VERSION = "2020-01-01-preview" diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/__init__.py b/src/aosm/azext_aosm/vendored_sdks/aio/__init__.py new file mode 100644 index 00000000000..85453c0838b --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/__init__.py @@ -0,0 +1,15 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._hybrid_network_management_client import HybridNetworkManagementClient +__all__ = ['HybridNetworkManagementClient'] + +# `._patch.py` is used for handwritten extensions to the generated code +# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +from ._patch import patch_sdk +patch_sdk() diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/_configuration.py b/src/aosm/azext_aosm/vendored_sdks/aio/_configuration.py new file mode 100644 index 00000000000..68dc449b003 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/_configuration.py @@ -0,0 +1,72 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any, TYPE_CHECKING + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies +from azure.mgmt.core.policies import ARMHttpLoggingPolicy, AsyncARMChallengeAuthenticationPolicy + +from .._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials_async import AsyncTokenCredential + + +class HybridNetworkManagementClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for HybridNetworkManagementClient. + + Note that all parameters used to create this instance are saved as instance + attributes. + + :param credential: Credential needed for the client to connect to Azure. + :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :param subscription_id: The ID of the target subscription. + :type subscription_id: str + :keyword api_version: Api Version. The default value is "2023-04-01-preview". Note that + overriding this default value may result in unsupported behavior. + :paramtype api_version: str + """ + + def __init__( + self, + credential: "AsyncTokenCredential", + subscription_id: str, + **kwargs: Any + ) -> None: + super(HybridNetworkManagementClientConfiguration, self).__init__(**kwargs) + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + if credential is None: + raise ValueError("Parameter 'credential' must not be None.") + if subscription_id is None: + raise ValueError("Parameter 'subscription_id' must not be None.") + + self.credential = credential + self.subscription_id = subscription_id + self.api_version = api_version + self.credential_scopes = kwargs.pop('credential_scopes', ['https://management.azure.com/.default']) + kwargs.setdefault('sdk_moniker', 'hybridnetwork/{}'.format(VERSION)) + self._configure(**kwargs) + + def _configure( + self, + **kwargs: Any + ) -> None: + self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs) + self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get('http_logging_policy') or ARMHttpLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get('retry_policy') or policies.AsyncRetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get('redirect_policy') or policies.AsyncRedirectPolicy(**kwargs) + self.authentication_policy = kwargs.get('authentication_policy') + if self.credential and not self.authentication_policy: + self.authentication_policy = AsyncARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs) diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py b/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py new file mode 100644 index 00000000000..891ddcb7041 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py @@ -0,0 +1,166 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from copy import deepcopy +from typing import Any, Awaitable, TYPE_CHECKING + +from msrest import Deserializer, Serializer + +from azure.core.rest import AsyncHttpResponse, HttpRequest +from azure.mgmt.core import AsyncARMPipelineClient + +from .. import models +from ._configuration import HybridNetworkManagementClientConfiguration +from .operations import ArtifactManifestsOperations, ArtifactStoresOperations, ComponentsOperations, ConfigurationGroupSchemasOperations, ConfigurationGroupValuesOperations, HybridNetworkManagementClientOperationsMixin, NetworkFunctionDefinitionGroupsOperations, NetworkFunctionDefinitionVersionsOperations, NetworkFunctionReadyK8SOperations, NetworkFunctionsOperations, NetworkServiceDesignGroupsOperations, NetworkServiceDesignVersionsOperations, Operations, PreviewSubscriptionsOperations, ProxyArtifactOperations, ProxyNetworkFunctionDefinitionGroupsOperations, ProxyNetworkFunctionDefinitionVersionsOperations, ProxyPublisherOperations, PublishersOperations, SiteNetworkServicesOperations, SitesOperations + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from azure.core.credentials_async import AsyncTokenCredential + +class HybridNetworkManagementClient(HybridNetworkManagementClientOperationsMixin): # pylint: disable=too-many-instance-attributes + """The definitions in this swagger specification will be used to manage the Hybrid Network + resources. + + :ivar configuration_group_schemas: ConfigurationGroupSchemasOperations operations + :vartype configuration_group_schemas: + Microsoft.HybridNetwork.aio.operations.ConfigurationGroupSchemasOperations + :ivar configuration_group_values: ConfigurationGroupValuesOperations operations + :vartype configuration_group_values: + Microsoft.HybridNetwork.aio.operations.ConfigurationGroupValuesOperations + :ivar network_functions: NetworkFunctionsOperations operations + :vartype network_functions: Microsoft.HybridNetwork.aio.operations.NetworkFunctionsOperations + :ivar components: ComponentsOperations operations + :vartype components: Microsoft.HybridNetwork.aio.operations.ComponentsOperations + :ivar network_function_definition_groups: NetworkFunctionDefinitionGroupsOperations operations + :vartype network_function_definition_groups: + Microsoft.HybridNetwork.aio.operations.NetworkFunctionDefinitionGroupsOperations + :ivar preview_subscriptions: PreviewSubscriptionsOperations operations + :vartype preview_subscriptions: + Microsoft.HybridNetwork.aio.operations.PreviewSubscriptionsOperations + :ivar network_function_definition_versions: NetworkFunctionDefinitionVersionsOperations + operations + :vartype network_function_definition_versions: + Microsoft.HybridNetwork.aio.operations.NetworkFunctionDefinitionVersionsOperations + :ivar network_function_ready_k8_s: NetworkFunctionReadyK8SOperations operations + :vartype network_function_ready_k8_s: + Microsoft.HybridNetwork.aio.operations.NetworkFunctionReadyK8SOperations + :ivar network_service_design_groups: NetworkServiceDesignGroupsOperations operations + :vartype network_service_design_groups: + Microsoft.HybridNetwork.aio.operations.NetworkServiceDesignGroupsOperations + :ivar network_service_design_versions: NetworkServiceDesignVersionsOperations operations + :vartype network_service_design_versions: + Microsoft.HybridNetwork.aio.operations.NetworkServiceDesignVersionsOperations + :ivar operations: Operations operations + :vartype operations: Microsoft.HybridNetwork.aio.operations.Operations + :ivar proxy_publisher: ProxyPublisherOperations operations + :vartype proxy_publisher: Microsoft.HybridNetwork.aio.operations.ProxyPublisherOperations + :ivar proxy_network_function_definition_groups: ProxyNetworkFunctionDefinitionGroupsOperations + operations + :vartype proxy_network_function_definition_groups: + Microsoft.HybridNetwork.aio.operations.ProxyNetworkFunctionDefinitionGroupsOperations + :ivar proxy_network_function_definition_versions: + ProxyNetworkFunctionDefinitionVersionsOperations operations + :vartype proxy_network_function_definition_versions: + Microsoft.HybridNetwork.aio.operations.ProxyNetworkFunctionDefinitionVersionsOperations + :ivar publishers: PublishersOperations operations + :vartype publishers: Microsoft.HybridNetwork.aio.operations.PublishersOperations + :ivar artifact_stores: ArtifactStoresOperations operations + :vartype artifact_stores: Microsoft.HybridNetwork.aio.operations.ArtifactStoresOperations + :ivar artifact_manifests: ArtifactManifestsOperations operations + :vartype artifact_manifests: Microsoft.HybridNetwork.aio.operations.ArtifactManifestsOperations + :ivar proxy_artifact: ProxyArtifactOperations operations + :vartype proxy_artifact: Microsoft.HybridNetwork.aio.operations.ProxyArtifactOperations + :ivar sites: SitesOperations operations + :vartype sites: Microsoft.HybridNetwork.aio.operations.SitesOperations + :ivar site_network_services: SiteNetworkServicesOperations operations + :vartype site_network_services: + Microsoft.HybridNetwork.aio.operations.SiteNetworkServicesOperations + :param credential: Credential needed for the client to connect to Azure. + :type credential: ~azure.core.credentials_async.AsyncTokenCredential + :param subscription_id: The ID of the target subscription. + :type subscription_id: str + :param base_url: Service URL. Default value is 'https://management.azure.com'. + :type base_url: str + :keyword api_version: Api Version. The default value is "2023-04-01-preview". Note that + overriding this default value may result in unsupported behavior. + :paramtype api_version: str + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + """ + + def __init__( + self, + credential: "AsyncTokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + self._config = HybridNetworkManagementClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) + self._client = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs) + + client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} + self._serialize = Serializer(client_models) + self._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + self.configuration_group_schemas = ConfigurationGroupSchemasOperations(self._client, self._config, self._serialize, self._deserialize) + self.configuration_group_values = ConfigurationGroupValuesOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_functions = NetworkFunctionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.components = ComponentsOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_function_definition_groups = NetworkFunctionDefinitionGroupsOperations(self._client, self._config, self._serialize, self._deserialize) + self.preview_subscriptions = PreviewSubscriptionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_function_definition_versions = NetworkFunctionDefinitionVersionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_function_ready_k8_s = NetworkFunctionReadyK8SOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_service_design_groups = NetworkServiceDesignGroupsOperations(self._client, self._config, self._serialize, self._deserialize) + self.network_service_design_versions = NetworkServiceDesignVersionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) + self.proxy_publisher = ProxyPublisherOperations(self._client, self._config, self._serialize, self._deserialize) + self.proxy_network_function_definition_groups = ProxyNetworkFunctionDefinitionGroupsOperations(self._client, self._config, self._serialize, self._deserialize) + self.proxy_network_function_definition_versions = ProxyNetworkFunctionDefinitionVersionsOperations(self._client, self._config, self._serialize, self._deserialize) + self.publishers = PublishersOperations(self._client, self._config, self._serialize, self._deserialize) + self.artifact_stores = ArtifactStoresOperations(self._client, self._config, self._serialize, self._deserialize) + self.artifact_manifests = ArtifactManifestsOperations(self._client, self._config, self._serialize, self._deserialize) + self.proxy_artifact = ProxyArtifactOperations(self._client, self._config, self._serialize, self._deserialize) + self.sites = SitesOperations(self._client, self._config, self._serialize, self._deserialize) + self.site_network_services = SiteNetworkServicesOperations(self._client, self._config, self._serialize, self._deserialize) + + + def _send_request( + self, + request: HttpRequest, + **kwargs: Any + ) -> Awaitable[AsyncHttpResponse]: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = await client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.AsyncHttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + async def close(self) -> None: + await self._client.close() + + async def __aenter__(self) -> "HybridNetworkManagementClient": + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details) -> None: + await self._client.__aexit__(*exc_details) diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/_patch.py b/src/aosm/azext_aosm/vendored_sdks/aio/_patch.py new file mode 100644 index 00000000000..74e48ecd07c --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/_patch.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +# This file is used for handwritten extensions to the generated code. Example: +# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +def patch_sdk(): + pass \ No newline at end of file diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py new file mode 100644 index 00000000000..6c86a395e1f --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py @@ -0,0 +1,53 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._configuration_group_schemas_operations import ConfigurationGroupSchemasOperations +from ._configuration_group_values_operations import ConfigurationGroupValuesOperations +from ._network_functions_operations import NetworkFunctionsOperations +from ._components_operations import ComponentsOperations +from ._network_function_definition_groups_operations import NetworkFunctionDefinitionGroupsOperations +from ._preview_subscriptions_operations import PreviewSubscriptionsOperations +from ._network_function_definition_versions_operations import NetworkFunctionDefinitionVersionsOperations +from ._network_function_ready_k8_s_operations import NetworkFunctionReadyK8SOperations +from ._network_service_design_groups_operations import NetworkServiceDesignGroupsOperations +from ._network_service_design_versions_operations import NetworkServiceDesignVersionsOperations +from ._operations import Operations +from ._proxy_publisher_operations import ProxyPublisherOperations +from ._proxy_network_function_definition_groups_operations import ProxyNetworkFunctionDefinitionGroupsOperations +from ._proxy_network_function_definition_versions_operations import ProxyNetworkFunctionDefinitionVersionsOperations +from ._publishers_operations import PublishersOperations +from ._artifact_stores_operations import ArtifactStoresOperations +from ._artifact_manifests_operations import ArtifactManifestsOperations +from ._proxy_artifact_operations import ProxyArtifactOperations +from ._hybrid_network_management_client_operations import HybridNetworkManagementClientOperationsMixin +from ._sites_operations import SitesOperations +from ._site_network_services_operations import SiteNetworkServicesOperations + +__all__ = [ + 'ConfigurationGroupSchemasOperations', + 'ConfigurationGroupValuesOperations', + 'NetworkFunctionsOperations', + 'ComponentsOperations', + 'NetworkFunctionDefinitionGroupsOperations', + 'PreviewSubscriptionsOperations', + 'NetworkFunctionDefinitionVersionsOperations', + 'NetworkFunctionReadyK8SOperations', + 'NetworkServiceDesignGroupsOperations', + 'NetworkServiceDesignVersionsOperations', + 'Operations', + 'ProxyPublisherOperations', + 'ProxyNetworkFunctionDefinitionGroupsOperations', + 'ProxyNetworkFunctionDefinitionVersionsOperations', + 'PublishersOperations', + 'ArtifactStoresOperations', + 'ArtifactManifestsOperations', + 'ProxyArtifactOperations', + 'HybridNetworkManagementClientOperationsMixin', + 'SitesOperations', + 'SiteNetworkServicesOperations', +] diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_artifact_manifests_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_artifact_manifests_operations.py new file mode 100644 index 00000000000..e95fa73c3cf --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_artifact_manifests_operations.py @@ -0,0 +1,738 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._artifact_manifests_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_artifact_store_request, build_list_credential_request, build_update_request, build_update_state_request_initial +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class ArtifactManifestsOperations: + """ArtifactManifestsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_artifact_store( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.ArtifactManifestListResult"]: + """Gets information about the artifact manifest. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ArtifactManifestListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.ArtifactManifestListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifestListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_artifact_store_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_artifact_store.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_artifact_store_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ArtifactManifestListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_artifact_store.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests"} # type: ignore + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_manifest_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_manifest_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the specified artifact manifest. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + async def _create_or_update_initial( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_manifest_name: str, + parameters: "_models.ArtifactManifest", + **kwargs: Any + ) -> "_models.ArtifactManifest": + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifest"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ArtifactManifest') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('ArtifactManifest', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('ArtifactManifest', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_manifest_name: str, + parameters: "_models.ArtifactManifest", + **kwargs: Any + ) -> AsyncLROPoller["_models.ArtifactManifest"]: + """Creates or updates a artifact manifest. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :param parameters: Parameters supplied to the create or update artifact manifest operation. + :type parameters: ~Microsoft.HybridNetwork.models.ArtifactManifest + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either ArtifactManifest or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.ArtifactManifest] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifest"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ArtifactManifest', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_manifest_name: str, + **kwargs: Any + ) -> "_models.ArtifactManifest": + """Gets information about a artifact manifest resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ArtifactManifest, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ArtifactManifest + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifest"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ArtifactManifest', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_manifest_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.ArtifactManifest": + """Updates a artifact manifest resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :param parameters: Parameters supplied to the create or update artifact manifest operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ArtifactManifest, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ArtifactManifest + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifest"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ArtifactManifest', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + + @distributed_trace_async + async def list_credential( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_manifest_name: str, + **kwargs: Any + ) -> "_models.ArtifactAccessCredential": + """List credential for publishing artifacts defined in artifact manifest. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ArtifactAccessCredential, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ArtifactAccessCredential + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactAccessCredential"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_list_credential_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_credential.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ArtifactAccessCredential', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + list_credential.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}/listCredential"} # type: ignore + + + async def _update_state_initial( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_manifest_name: str, + parameters: "_models.ArtifactManifestUpdateState", + **kwargs: Any + ) -> Optional["_models.ArtifactManifestUpdateState"]: + cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.ArtifactManifestUpdateState"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ArtifactManifestUpdateState') + + request = build_update_state_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._update_state_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('ArtifactManifestUpdateState', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _update_state_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}/updateState"} # type: ignore + + + @distributed_trace_async + async def begin_update_state( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_manifest_name: str, + parameters: "_models.ArtifactManifestUpdateState", + **kwargs: Any + ) -> AsyncLROPoller["_models.ArtifactManifestUpdateState"]: + """Update state for artifact manifest. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :param parameters: Parameters supplied to update the state of artifact manifest. + :type parameters: ~Microsoft.HybridNetwork.models.ArtifactManifestUpdateState + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either ArtifactManifestUpdateState or the + result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.ArtifactManifestUpdateState] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifestUpdateState"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._update_state_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ArtifactManifestUpdateState', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_update_state.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}/updateState"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_artifact_stores_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_artifact_stores_operations.py new file mode 100644 index 00000000000..49ee5c761fe --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_artifact_stores_operations.py @@ -0,0 +1,508 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._artifact_stores_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_publisher_request, build_update_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class ArtifactStoresOperations: + """ArtifactStoresOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_publisher( + self, + resource_group_name: str, + publisher_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.ArtifactStoreListResult"]: + """Gets information of the ArtifactStores under publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ArtifactStoreListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.ArtifactStoreListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactStoreListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_publisher.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ArtifactStoreListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_publisher.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores"} # type: ignore + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the specified artifact store. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + + async def _create_or_update_initial( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + parameters: "_models.ArtifactStore", + **kwargs: Any + ) -> "_models.ArtifactStore": + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactStore"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ArtifactStore') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('ArtifactStore', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('ArtifactStore', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + parameters: "_models.ArtifactStore", + **kwargs: Any + ) -> AsyncLROPoller["_models.ArtifactStore"]: + """Creates or updates a artifact store. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param parameters: Parameters supplied to the create or update application group operation. + :type parameters: ~Microsoft.HybridNetwork.models.ArtifactStore + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either ArtifactStore or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.ArtifactStore] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactStore"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ArtifactStore', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + **kwargs: Any + ) -> "_models.ArtifactStore": + """Gets information about the specified artifact store. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ArtifactStore, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ArtifactStore + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactStore"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ArtifactStore', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.ArtifactStore": + """Update artifact store resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param parameters: Parameters supplied to the create or update application group operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ArtifactStore, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ArtifactStore + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactStore"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ArtifactStore', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_components_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_components_operations.py new file mode 100644 index 00000000000..54d99e5ba17 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_components_operations.py @@ -0,0 +1,192 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._components_operations import build_get_request, build_list_by_network_function_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class ComponentsOperations: + """ComponentsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + network_function_name: str, + component_name: str, + **kwargs: Any + ) -> "_models.Component": + """Gets information about the specified application instance resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: The name of the network function resource. + :type network_function_name: str + :param component_name: The name of the component. + :type component_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Component, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.Component + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.Component"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + component_name=component_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Component', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/components/{componentName}"} # type: ignore + + + @distributed_trace + def list_by_network_function( + self, + resource_group_name: str, + network_function_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.ComponentListResult"]: + """Lists all the component resources in a network function. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: The name of the network function. + :type network_function_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ComponentListResult or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.ComponentListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ComponentListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_network_function_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + network_function_name=network_function_name, + api_version=api_version, + template_url=self.list_by_network_function.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_network_function_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + network_function_name=network_function_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ComponentListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_network_function.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/components"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_configuration_group_schemas_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_configuration_group_schemas_operations.py new file mode 100644 index 00000000000..2d44a98c030 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_configuration_group_schemas_operations.py @@ -0,0 +1,643 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._configuration_group_schemas_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_publisher_request, build_update_request, build_update_state_request_initial +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class ConfigurationGroupSchemasOperations: + """ConfigurationGroupSchemasOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_publisher( + self, + resource_group_name: str, + publisher_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.ConfigurationGroupSchemaListResult"]: + """Gets information of the configuration group schemas under a publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ConfigurationGroupSchemaListResult or the result + of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.ConfigurationGroupSchemaListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchemaListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_publisher.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ConfigurationGroupSchemaListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_publisher.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas"} # type: ignore + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + configuration_group_schema_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + configuration_group_schema_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes a specified configuration group schema. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param configuration_group_schema_name: The name of the configuration group schema. + :type configuration_group_schema_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + async def _create_or_update_initial( + self, + resource_group_name: str, + publisher_name: str, + configuration_group_schema_name: str, + parameters: "_models.ConfigurationGroupSchema", + **kwargs: Any + ) -> "_models.ConfigurationGroupSchema": + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchema"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ConfigurationGroupSchema') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('ConfigurationGroupSchema', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('ConfigurationGroupSchema', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + publisher_name: str, + configuration_group_schema_name: str, + parameters: "_models.ConfigurationGroupSchema", + **kwargs: Any + ) -> AsyncLROPoller["_models.ConfigurationGroupSchema"]: + """Creates or updates a configuration group schema. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param configuration_group_schema_name: The name of the configuration group schema. + :type configuration_group_schema_name: str + :param parameters: Parameters supplied to the create or update configuration group schema + resource. + :type parameters: ~Microsoft.HybridNetwork.models.ConfigurationGroupSchema + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either ConfigurationGroupSchema or the + result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.ConfigurationGroupSchema] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchema"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ConfigurationGroupSchema', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + publisher_name: str, + configuration_group_schema_name: str, + **kwargs: Any + ) -> "_models.ConfigurationGroupSchema": + """Gets information about the specified configuration group schema. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param configuration_group_schema_name: The name of the configuration group schema. + :type configuration_group_schema_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ConfigurationGroupSchema, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ConfigurationGroupSchema + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchema"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ConfigurationGroupSchema', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + publisher_name: str, + configuration_group_schema_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.ConfigurationGroupSchema": + """Updates a configuration group schema resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param configuration_group_schema_name: The name of the configuration group schema. + :type configuration_group_schema_name: str + :param parameters: Parameters supplied to the create or update network service design version + operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ConfigurationGroupSchema, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ConfigurationGroupSchema + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchema"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ConfigurationGroupSchema', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + + async def _update_state_initial( + self, + resource_group_name: str, + publisher_name: str, + configuration_group_schema_name: str, + parameters: "_models.ConfigurationGroupSchemaVersionUpdateState", + **kwargs: Any + ) -> Optional["_models.ConfigurationGroupSchemaVersionUpdateState"]: + cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.ConfigurationGroupSchemaVersionUpdateState"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ConfigurationGroupSchemaVersionUpdateState') + + request = build_update_state_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._update_state_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('ConfigurationGroupSchemaVersionUpdateState', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _update_state_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}/updateState"} # type: ignore + + + @distributed_trace_async + async def begin_update_state( + self, + resource_group_name: str, + publisher_name: str, + configuration_group_schema_name: str, + parameters: "_models.ConfigurationGroupSchemaVersionUpdateState", + **kwargs: Any + ) -> AsyncLROPoller["_models.ConfigurationGroupSchemaVersionUpdateState"]: + """Update configuration group schema state. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param configuration_group_schema_name: The name of the configuration group schema. + :type configuration_group_schema_name: str + :param parameters: Parameters supplied to update the state of configuration group schema. + :type parameters: ~Microsoft.HybridNetwork.models.ConfigurationGroupSchemaVersionUpdateState + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either + ConfigurationGroupSchemaVersionUpdateState or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.ConfigurationGroupSchemaVersionUpdateState] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchemaVersionUpdateState"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._update_state_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ConfigurationGroupSchemaVersionUpdateState', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_update_state.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}/updateState"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_configuration_group_values_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_configuration_group_values_operations.py new file mode 100644 index 00000000000..3eed798cd56 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_configuration_group_values_operations.py @@ -0,0 +1,559 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._configuration_group_values_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_resource_group_request, build_list_by_subscription_request, build_update_tags_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class ConfigurationGroupValuesOperations: + """ConfigurationGroupValuesOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + configuration_group_value_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + configuration_group_value_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the specified hybrid configuration group value. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param configuration_group_value_name: The name of the configuration group value. + :type configuration_group_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + configuration_group_value_name: str, + **kwargs: Any + ) -> "_models.ConfigurationGroupValue": + """Gets information about the specified hybrid configuration group values. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param configuration_group_value_name: The name of the configuration group value. + :type configuration_group_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ConfigurationGroupValue, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ConfigurationGroupValue + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValue"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ConfigurationGroupValue', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + + async def _create_or_update_initial( + self, + resource_group_name: str, + configuration_group_value_name: str, + parameters: "_models.ConfigurationGroupValue", + **kwargs: Any + ) -> "_models.ConfigurationGroupValue": + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValue"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ConfigurationGroupValue') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('ConfigurationGroupValue', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('ConfigurationGroupValue', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + configuration_group_value_name: str, + parameters: "_models.ConfigurationGroupValue", + **kwargs: Any + ) -> AsyncLROPoller["_models.ConfigurationGroupValue"]: + """Creates or updates a hybrid configuration group value. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param configuration_group_value_name: The name of the configuration group value. + :type configuration_group_value_name: str + :param parameters: Parameters supplied to the create or update configuration group value + resource. + :type parameters: ~Microsoft.HybridNetwork.models.ConfigurationGroupValue + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either ConfigurationGroupValue or the + result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.ConfigurationGroupValue] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValue"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ConfigurationGroupValue', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + @distributed_trace_async + async def update_tags( + self, + resource_group_name: str, + configuration_group_value_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.ConfigurationGroupValue": + """Updates a hybrid configuration group tags. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param configuration_group_value_name: The name of the configuration group value. + :type configuration_group_value_name: str + :param parameters: Parameters supplied to update configuration group values tags. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ConfigurationGroupValue, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ConfigurationGroupValue + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValue"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_tags_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update_tags.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ConfigurationGroupValue', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update_tags.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + + @distributed_trace + def list_by_subscription( + self, + **kwargs: Any + ) -> AsyncIterable["_models.ConfigurationGroupValueListResult"]: + """Lists all sites in the configuration group value in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ConfigurationGroupValueListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.ConfigurationGroupValueListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValueListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ConfigurationGroupValueListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/configurationGroupValues"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.ConfigurationGroupValueListResult"]: + """Lists all the hybrid network configurationGroupValues in a resource group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ConfigurationGroupValueListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.ConfigurationGroupValueListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValueListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ConfigurationGroupValueListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_hybrid_network_management_client_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_hybrid_network_management_client_operations.py new file mode 100644 index 00000000000..b58d7765e8f --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_hybrid_network_management_client_operations.py @@ -0,0 +1,170 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, Callable, Dict, Optional, TypeVar, Union + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._hybrid_network_management_client_operations import build_change_artifact_state_request_initial +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class HybridNetworkManagementClientOperationsMixin: + + async def _change_artifact_state_initial( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_name: str, + artifact_version_name: str, + parameters: "_models.ArtifactChangeState", + **kwargs: Any + ) -> Optional["_models.ProxyArtifactVersionsListOverview"]: + cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.ProxyArtifactVersionsListOverview"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ArtifactChangeState') + + request = build_change_artifact_state_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_version_name=artifact_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + artifact_name=artifact_name, + json=_json, + template_url=self._change_artifact_state_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('ProxyArtifactVersionsListOverview', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _change_artifact_state_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactVersions/{artifactVersionName}"} # type: ignore + + + @distributed_trace_async + async def begin_change_artifact_state( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_name: str, + artifact_version_name: str, + parameters: "_models.ArtifactChangeState", + **kwargs: Any + ) -> AsyncLROPoller["_models.ProxyArtifactVersionsListOverview"]: + """Change artifact state defined in artifact store. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_name: The name of the artifact. + :type artifact_name: str + :param artifact_version_name: The name of the artifact version. + :type artifact_version_name: str + :param parameters: Parameters supplied to update the state of artifact manifest. + :type parameters: ~Microsoft.HybridNetwork.models.ArtifactChangeState + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either ProxyArtifactVersionsListOverview or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.ProxyArtifactVersionsListOverview] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ProxyArtifactVersionsListOverview"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._change_artifact_state_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_name=artifact_name, + artifact_version_name=artifact_version_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ProxyArtifactVersionsListOverview', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_change_artifact_state.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactVersions/{artifactVersionName}"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_definition_groups_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_definition_groups_operations.py new file mode 100644 index 00000000000..1676124ba37 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_definition_groups_operations.py @@ -0,0 +1,515 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._network_function_definition_groups_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_publisher_request, build_update_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class NetworkFunctionDefinitionGroupsOperations: + """NetworkFunctionDefinitionGroupsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_publisher( + self, + resource_group_name: str, + publisher_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.NetworkFunctionDefinitionGroupListResult"]: + """Gets information of the network function definition groups under a publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionDefinitionGroupListResult or the + result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroupListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroupListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_publisher.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionDefinitionGroupListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_publisher.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups"} # type: ignore + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes a specified network function definition group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + + async def _create_or_update_initial( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + parameters: "_models.NetworkFunctionDefinitionGroup", + **kwargs: Any + ) -> "_models.NetworkFunctionDefinitionGroup": + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkFunctionDefinitionGroup') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkFunctionDefinitionGroup', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkFunctionDefinitionGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + parameters: "_models.NetworkFunctionDefinitionGroup", + **kwargs: Any + ) -> AsyncLROPoller["_models.NetworkFunctionDefinitionGroup"]: + """Creates or updates a network function definition group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param parameters: Parameters supplied to the create or update publisher network function + definition group operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either NetworkFunctionDefinitionGroup or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroup"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkFunctionDefinitionGroup', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + **kwargs: Any + ) -> "_models.NetworkFunctionDefinitionGroup": + """Gets information about the specified networkFunctionDefinition group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionGroup, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.NetworkFunctionDefinitionGroup": + """Updates a network function definition group resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param parameters: Parameters supplied to the create or update publisher network function + definition group operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionGroup, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_definition_versions_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_definition_versions_operations.py new file mode 100644 index 00000000000..75cb89c1e2a --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_definition_versions_operations.py @@ -0,0 +1,692 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._network_function_definition_versions_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_network_function_definition_group_request, build_update_request, build_update_state_request_initial +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class NetworkFunctionDefinitionVersionsOperations: + """NetworkFunctionDefinitionVersionsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + network_function_definition_version_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + network_function_definition_version_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the specified network function definition version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + async def _create_or_update_initial( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + network_function_definition_version_name: str, + parameters: "_models.NetworkFunctionDefinitionVersion", + **kwargs: Any + ) -> "_models.NetworkFunctionDefinitionVersion": + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkFunctionDefinitionVersion') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkFunctionDefinitionVersion', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkFunctionDefinitionVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + network_function_definition_version_name: str, + parameters: "_models.NetworkFunctionDefinitionVersion", + **kwargs: Any + ) -> AsyncLROPoller["_models.NetworkFunctionDefinitionVersion"]: + """Creates or updates a network function definition version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :param parameters: Parameters supplied to the create or update network function definition + version operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either NetworkFunctionDefinitionVersion or + the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersion"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkFunctionDefinitionVersion', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + network_function_definition_version_name: str, + **kwargs: Any + ) -> "_models.NetworkFunctionDefinitionVersion": + """Gets information about a network function definition version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionVersion, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + network_function_definition_version_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.NetworkFunctionDefinitionVersion": + """Updates a network function definition version resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :param parameters: Parameters supplied to the create or update network function definition + version operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionVersion, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + + @distributed_trace + def list_by_network_function_definition_group( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.NetworkFunctionDefinitionVersionListResult"]: + """Gets information about a list of network function definition versions under a network function + definition group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionDefinitionVersionListResult or the + result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersionListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_network_function_definition_group_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_network_function_definition_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_network_function_definition_group_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionDefinitionVersionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_network_function_definition_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions"} # type: ignore + + async def _update_state_initial( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + network_function_definition_version_name: str, + parameters: "_models.NetworkFunctionDefinitionVersionUpdateState", + **kwargs: Any + ) -> Optional["_models.NetworkFunctionDefinitionVersionUpdateState"]: + cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.NetworkFunctionDefinitionVersionUpdateState"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkFunctionDefinitionVersionUpdateState') + + request = build_update_state_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._update_state_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('NetworkFunctionDefinitionVersionUpdateState', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _update_state_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}/updateState"} # type: ignore + + + @distributed_trace_async + async def begin_update_state( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + network_function_definition_version_name: str, + parameters: "_models.NetworkFunctionDefinitionVersionUpdateState", + **kwargs: Any + ) -> AsyncLROPoller["_models.NetworkFunctionDefinitionVersionUpdateState"]: + """Update network function definition version state. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :param parameters: Parameters supplied to update the state of network function definition + version. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionUpdateState + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either + NetworkFunctionDefinitionVersionUpdateState or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionUpdateState] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersionUpdateState"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._update_state_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkFunctionDefinitionVersionUpdateState', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_update_state.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}/updateState"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_ready_k8_s_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_ready_k8_s_operations.py new file mode 100644 index 00000000000..29c43a13148 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_function_ready_k8_s_operations.py @@ -0,0 +1,559 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._network_function_ready_k8_s_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_resource_group_request, build_list_by_subscription_request, build_update_tags_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class NetworkFunctionReadyK8SOperations: + """NetworkFunctionReadyK8SOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + network_function_ready_k8_s_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + network_function_ready_k8_s_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the specified network function ready K8s. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_ready_k8_s_name: The name of the network function ready K8s. + :type network_function_ready_k8_s_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + network_function_ready_k8_s_name: str, + **kwargs: Any + ) -> "_models.NetworkFunctionReadyK8S": + """Gets information about the specified network function ready K8s. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_ready_k8_s_name: The name of the network function ready K8s. + :type network_function_ready_k8_s_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionReadyK8S, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8S"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionReadyK8S', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + + async def _create_or_update_initial( + self, + resource_group_name: str, + network_function_ready_k8_s_name: str, + parameters: "_models.NetworkFunctionReadyK8S", + **kwargs: Any + ) -> "_models.NetworkFunctionReadyK8S": + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8S"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkFunctionReadyK8S') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkFunctionReadyK8S', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkFunctionReadyK8S', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + network_function_ready_k8_s_name: str, + parameters: "_models.NetworkFunctionReadyK8S", + **kwargs: Any + ) -> AsyncLROPoller["_models.NetworkFunctionReadyK8S"]: + """Creates or updates a network function ready K8s. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_ready_k8_s_name: The name of the network function ready K8s. + :type network_function_ready_k8_s_name: str + :param parameters: Parameters supplied to the create or update network function ready K8s + operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either NetworkFunctionReadyK8S or the + result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8S"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkFunctionReadyK8S', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + @distributed_trace_async + async def update_tags( + self, + resource_group_name: str, + network_function_ready_k8_s_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.NetworkFunctionReadyK8S": + """Updates a network function ready K8s update tags. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_ready_k8_s_name: The name of the network function ready K8s. + :type network_function_ready_k8_s_name: str + :param parameters: Parameters supplied to update network function ready K8s tags. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionReadyK8S, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8S"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_tags_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update_tags.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionReadyK8S', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update_tags.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + + @distributed_trace + def list_by_subscription( + self, + **kwargs: Any + ) -> AsyncIterable["_models.NetworkFunctionReadyK8SListResult"]: + """Lists all network function ready K8s in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionReadyK8SListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8SListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8SListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionReadyK8SListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.NetworkFunctionReadyK8SListResult"]: + """Lists all network function ready K8s in the resource group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionReadyK8SListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8SListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8SListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionReadyK8SListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_functions_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_functions_operations.py new file mode 100644 index 00000000000..720906c97c9 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_functions_operations.py @@ -0,0 +1,673 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._network_functions_operations import build_create_or_update_request_initial, build_delete_request_initial, build_execute_request_request_initial, build_get_request, build_list_by_resource_group_request, build_list_by_subscription_request, build_update_tags_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class NetworkFunctionsOperations: + """NetworkFunctionsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + network_function_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + network_function_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the specified network function resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: The name of the network function. + :type network_function_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + network_function_name: str, + **kwargs: Any + ) -> "_models.NetworkFunction": + """Gets information about the specified network function resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: The name of the network function resource. + :type network_function_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunction, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunction + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunction"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunction', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + + async def _create_or_update_initial( + self, + resource_group_name: str, + network_function_name: str, + parameters: "_models.NetworkFunction", + **kwargs: Any + ) -> "_models.NetworkFunction": + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunction"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkFunction') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkFunction', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkFunction', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + network_function_name: str, + parameters: "_models.NetworkFunction", + **kwargs: Any + ) -> AsyncLROPoller["_models.NetworkFunction"]: + """Creates or updates a network function resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: Resource name for the network function resource. + :type network_function_name: str + :param parameters: Parameters supplied in the body to the create or update network function + operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkFunction + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either NetworkFunction or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.NetworkFunction] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunction"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkFunction', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + @distributed_trace_async + async def update_tags( + self, + resource_group_name: str, + network_function_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.NetworkFunction": + """Updates the tags for the network function resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: Resource name for the network function resource. + :type network_function_name: str + :param parameters: Parameters supplied to the update network function tags operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunction, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunction + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunction"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_tags_request( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update_tags.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunction', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update_tags.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + + @distributed_trace + def list_by_subscription( + self, + **kwargs: Any + ) -> AsyncIterable["_models.NetworkFunctionListResult"]: + """Lists all the network functions in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/networkFunctions"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.NetworkFunctionListResult"]: + """Lists all the network function resources in a resource group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions"} # type: ignore + + async def _execute_request_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + network_function_name: str, + parameters: "_models.ExecuteRequestParameters", + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ExecuteRequestParameters') + + request = build_execute_request_request_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._execute_request_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _execute_request_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/executeRequest"} # type: ignore + + + @distributed_trace_async + async def begin_execute_request( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + network_function_name: str, + parameters: "_models.ExecuteRequestParameters", + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Execute a request to services on a network function. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: The name of the network function. + :type network_function_name: str + :param parameters: Payload for execute request post call. + :type parameters: ~Microsoft.HybridNetwork.models.ExecuteRequestParameters + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._execute_request_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_execute_request.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/executeRequest"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_service_design_groups_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_service_design_groups_operations.py new file mode 100644 index 00000000000..9a422fbe03e --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_service_design_groups_operations.py @@ -0,0 +1,511 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._network_service_design_groups_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_publisher_request, build_update_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class NetworkServiceDesignGroupsOperations: + """NetworkServiceDesignGroupsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_publisher( + self, + resource_group_name: str, + publisher_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.NetworkServiceDesignGroupListResult"]: + """Gets information of the network service design groups under a publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkServiceDesignGroupListResult or the result + of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.NetworkServiceDesignGroupListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignGroupListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_publisher_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + api_version=api_version, + template_url=self.list_by_publisher.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_publisher_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkServiceDesignGroupListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_publisher.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups"} # type: ignore + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes a specified network service design group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + + async def _create_or_update_initial( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + parameters: "_models.NetworkServiceDesignGroup", + **kwargs: Any + ) -> "_models.NetworkServiceDesignGroup": + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkServiceDesignGroup') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkServiceDesignGroup', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkServiceDesignGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + parameters: "_models.NetworkServiceDesignGroup", + **kwargs: Any + ) -> AsyncLROPoller["_models.NetworkServiceDesignGroup"]: + """Creates or updates a network service design group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param parameters: Parameters supplied to the create or update publisher network service design + group operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either NetworkServiceDesignGroup or the + result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignGroup"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkServiceDesignGroup', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + **kwargs: Any + ) -> "_models.NetworkServiceDesignGroup": + """Gets information about the specified networkServiceDesign group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkServiceDesignGroup, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkServiceDesignGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.NetworkServiceDesignGroup": + """Updates a network service design groups resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param parameters: Parameters supplied to the create or update publisher network service design + group operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkServiceDesignGroup, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkServiceDesignGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_service_design_versions_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_service_design_versions_operations.py new file mode 100644 index 00000000000..e5cd4c64c09 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_network_service_design_versions_operations.py @@ -0,0 +1,680 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._network_service_design_versions_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_network_service_design_group_request, build_update_request, build_update_state_request_initial +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class NetworkServiceDesignVersionsOperations: + """NetworkServiceDesignVersionsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + network_service_design_version_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + network_service_design_version_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the specified network service design version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version_name: The name of the network service design version. The + name should conform to the SemVer 2.0.0 specification: https://semver.org/spec/v2.0.0.html. + :type network_service_design_version_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + async def _create_or_update_initial( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + network_service_design_version_name: str, + parameters: "_models.NetworkServiceDesignVersion", + **kwargs: Any + ) -> "_models.NetworkServiceDesignVersion": + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkServiceDesignVersion') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkServiceDesignVersion', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkServiceDesignVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + network_service_design_version_name: str, + parameters: "_models.NetworkServiceDesignVersion", + **kwargs: Any + ) -> AsyncLROPoller["_models.NetworkServiceDesignVersion"]: + """Creates or updates a network service design version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version_name: The name of the network service design version. The + name should conform to the SemVer 2.0.0 specification: https://semver.org/spec/v2.0.0.html. + :type network_service_design_version_name: str + :param parameters: Parameters supplied to the create or update network service design version + operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either NetworkServiceDesignVersion or the + result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersion"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkServiceDesignVersion', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + network_service_design_version_name: str, + **kwargs: Any + ) -> "_models.NetworkServiceDesignVersion": + """Gets information about a network service design version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version_name: The name of the network service design version. The + name should conform to the SemVer 2.0.0 specification: https://semver.org/spec/v2.0.0.html. + :type network_service_design_version_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkServiceDesignVersion, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkServiceDesignVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + network_service_design_version_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.NetworkServiceDesignVersion": + """Updates a network service design version resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version_name: The name of the network service design version. The + name should conform to the SemVer 2.0.0 specification: https://semver.org/spec/v2.0.0.html. + :type network_service_design_version_name: str + :param parameters: Parameters supplied to the create or update network service design version + operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkServiceDesignVersion, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkServiceDesignVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + + @distributed_trace + def list_by_network_service_design_group( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.NetworkServiceDesignVersionListResult"]: + """Gets information about a list of network service design versions under a network service design + group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkServiceDesignVersionListResult or the + result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.NetworkServiceDesignVersionListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersionListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_network_service_design_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + template_url=self.list_by_network_service_design_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_network_service_design_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkServiceDesignVersionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_network_service_design_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions"} # type: ignore + + async def _update_state_initial( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + network_service_design_version_name: str, + parameters: "_models.NetworkServiceDesignVersionUpdateState", + **kwargs: Any + ) -> Optional["_models.NetworkServiceDesignVersionUpdateState"]: + cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.NetworkServiceDesignVersionUpdateState"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkServiceDesignVersionUpdateState') + + request = build_update_state_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._update_state_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('NetworkServiceDesignVersionUpdateState', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _update_state_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}/updateState"} # type: ignore + + + @distributed_trace_async + async def begin_update_state( + self, + resource_group_name: str, + publisher_name: str, + network_service_design_group_name: str, + network_service_design_version_name: str, + parameters: "_models.NetworkServiceDesignVersionUpdateState", + **kwargs: Any + ) -> AsyncLROPoller["_models.NetworkServiceDesignVersionUpdateState"]: + """Update network service design version state. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version_name: The name of the network service design version. The + name should conform to the SemVer 2.0.0 specification: https://semver.org/spec/v2.0.0.html. + :type network_service_design_version_name: str + :param parameters: Parameters supplied to update the state of network service design version. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkServiceDesignVersionUpdateState + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either + NetworkServiceDesignVersionUpdateState or the result of cls(response) + :rtype: + ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.NetworkServiceDesignVersionUpdateState] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersionUpdateState"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._update_state_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkServiceDesignVersionUpdateState', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_update_state.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}/updateState"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_operations.py new file mode 100644 index 00000000000..6a0c29c8809 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_operations.py @@ -0,0 +1,115 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._operations import build_list_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class Operations: + """Operations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list( + self, + **kwargs: Any + ) -> AsyncIterable["_models.OperationList"]: + """Gets a list of the operations. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either OperationList or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.OperationList] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.OperationList"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_request( + api_version=api_version, + template_url=self.list.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_request( + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("OperationList", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list.metadata = {'url': "/providers/Microsoft.HybridNetwork/operations"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_preview_subscriptions_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_preview_subscriptions_operations.py new file mode 100644 index 00000000000..4a34c882a88 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_preview_subscriptions_operations.py @@ -0,0 +1,540 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._preview_subscriptions_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_network_function_definition_group_request, build_update_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class PreviewSubscriptionsOperations: + """PreviewSubscriptionsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_network_function_definition_group( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.PreviewSubscriptionsList"]: + """Lists all the preview subscriptions of a network function definition group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PreviewSubscriptionsList or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.PreviewSubscriptionsList] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.PreviewSubscriptionsList"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_network_function_definition_group_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_network_function_definition_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_network_function_definition_group_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PreviewSubscriptionsList", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_network_function_definition_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions"} # type: ignore + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + preview_subscription: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + preview_subscription: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes a preview subscription resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param preview_subscription: Preview subscription ID. + :type preview_subscription: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + + async def _create_or_update_initial( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + preview_subscription: str, + parameters: "_models.PreviewSubscription", + **kwargs: Any + ) -> "_models.PreviewSubscription": + cls = kwargs.pop('cls', None) # type: ClsType["_models.PreviewSubscription"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'PreviewSubscription') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('PreviewSubscription', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('PreviewSubscription', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + preview_subscription: str, + parameters: "_models.PreviewSubscription", + **kwargs: Any + ) -> AsyncLROPoller["_models.PreviewSubscription"]: + """Creates or updates preview subscription resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param preview_subscription: Preview subscription ID. + :type preview_subscription: str + :param parameters: Parameters supplied to the create or update publisher preview subscription + operation. + :type parameters: ~Microsoft.HybridNetwork.models.PreviewSubscription + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either PreviewSubscription or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.PreviewSubscription] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.PreviewSubscription"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('PreviewSubscription', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + preview_subscription: str, + **kwargs: Any + ) -> "_models.PreviewSubscription": + """Gets the preview subscription resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param preview_subscription: Preview subscription ID. + :type preview_subscription: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PreviewSubscription, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.PreviewSubscription + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.PreviewSubscription"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('PreviewSubscription', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + publisher_name: str, + network_function_definition_group_name: str, + preview_subscription: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.PreviewSubscription": + """Update a preview subscription resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param preview_subscription: Preview subscription ID. + :type preview_subscription: str + :param parameters: Parameters supplied to the create or update publisher preview subscription + operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PreviewSubscription, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.PreviewSubscription + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.PreviewSubscription"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('PreviewSubscription', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_artifact_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_artifact_operations.py new file mode 100644 index 00000000000..0f25526d888 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_artifact_operations.py @@ -0,0 +1,228 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._proxy_artifact_operations import build_get_request, build_list_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class ProxyArtifactOperations: + """ProxyArtifactOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.ProxyArtifactOverviewListResult"]: + """Lists all the available artifacts in the parent Artifact Store. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ProxyArtifactOverviewListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.ProxyArtifactOverviewListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ProxyArtifactOverviewListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ProxyArtifactOverviewListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifacts"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.ProxyArtifactVersionsOverviewListResult"]: + """Get a Artifact overview information. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_name: The name of the artifact. + :type artifact_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ProxyArtifactVersionsOverviewListResult or the + result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.ProxyArtifactVersionsOverviewListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ProxyArtifactVersionsOverviewListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + artifact_name=artifact_name, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + artifact_name=artifact_name, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ProxyArtifactVersionsOverviewListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactVersions"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_network_function_definition_groups_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_network_function_definition_groups_operations.py new file mode 100644 index 00000000000..2f4332009a3 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_network_function_definition_groups_operations.py @@ -0,0 +1,203 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._proxy_network_function_definition_groups_operations import build_get_request, build_list_by_publisher_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class ProxyNetworkFunctionDefinitionGroupsOperations: + """ProxyNetworkFunctionDefinitionGroupsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_publisher( + self, + publisher_scope_name: str, + publisher_location_name: str, + proxy_publisher_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.NetworkFunctionDefinitionGroupOverviewListResult"]: + """Lists all available network function definition group under a publisher. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :param proxy_publisher_name: The name of the proxy publisher. + :type proxy_publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionDefinitionGroupOverviewListResult + or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroupOverviewListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroupOverviewListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_publisher_request( + proxy_publisher_name=proxy_publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.list_by_publisher.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_publisher_request( + proxy_publisher_name=proxy_publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionDefinitionGroupOverviewListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_publisher.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups"} # type: ignore + + @distributed_trace_async + async def get( + self, + publisher_scope_name: str, + publisher_location_name: str, + proxy_publisher_name: str, + network_function_definition_group_name: str, + **kwargs: Any + ) -> "_models.NetworkFunctionDefinitionGroupOverview": + """Get information about network function definition overview. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :param proxy_publisher_name: The name of the proxy publisher. + :type proxy_publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionGroupOverview, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroupOverview + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroupOverview"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + proxy_publisher_name=proxy_publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionGroupOverview', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_network_function_definition_versions_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_network_function_definition_versions_operations.py new file mode 100644 index 00000000000..2faea08c44b --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_network_function_definition_versions_operations.py @@ -0,0 +1,215 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._proxy_network_function_definition_versions_operations import build_get_request, build_list_by_network_function_definition_group_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class ProxyNetworkFunctionDefinitionVersionsOperations: + """ProxyNetworkFunctionDefinitionVersionsOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_network_function_definition_group( + self, + publisher_scope_name: str, + publisher_location_name: str, + proxy_publisher_name: str, + network_function_definition_group_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.NetworkFunctionDefinitionVersionOverviewListResult"]: + """Lists available network function versions under a network function definition group. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :param proxy_publisher_name: The name of the proxy publisher. + :type proxy_publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionDefinitionVersionOverviewListResult + or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionOverviewListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersionOverviewListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_network_function_definition_group_request( + proxy_publisher_name=proxy_publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.list_by_network_function_definition_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_network_function_definition_group_request( + proxy_publisher_name=proxy_publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionDefinitionVersionOverviewListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_network_function_definition_group.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions"} # type: ignore + + @distributed_trace_async + async def get( + self, + publisher_scope_name: str, + publisher_location_name: str, + proxy_publisher_name: str, + network_function_definition_group_name: str, + network_function_definition_version_name: str, + **kwargs: Any + ) -> "_models.NetworkFunctionDefinitionVersionOverview": + """Get information about network function definition version overview. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :param proxy_publisher_name: The name of the proxy publisher. + :type proxy_publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionVersionOverview, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionOverview + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersionOverview"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + proxy_publisher_name=proxy_publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionVersionOverview', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_publisher_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_publisher_operations.py new file mode 100644 index 00000000000..48718b9442c --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_proxy_publisher_operations.py @@ -0,0 +1,193 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._proxy_publisher_operations import build_get_request, build_list_by_location_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class ProxyPublisherOperations: + """ProxyPublisherOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_location( + self, + publisher_scope_name: str, + publisher_location_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.ProxyPublisherOverviewListResult"]: + """Lists all the available network function definition and network service design publishers. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ProxyPublisherOverviewListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.ProxyPublisherOverviewListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ProxyPublisherOverviewListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_location_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.list_by_location.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_location_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("ProxyPublisherOverviewListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers"} # type: ignore + + @distributed_trace_async + async def get( + self, + publisher_scope_name: str, + publisher_location_name: str, + proxy_publisher_name: str, + **kwargs: Any + ) -> "_models.ProxyPublisherOverview": + """Get a publisher overview information. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :param proxy_publisher_name: The name of the proxy publisher. + :type proxy_publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ProxyPublisherOverview, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ProxyPublisherOverview + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ProxyPublisherOverview"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + proxy_publisher_name=proxy_publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ProxyPublisherOverview', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_publishers_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_publishers_operations.py new file mode 100644 index 00000000000..f2b322c3b3e --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_publishers_operations.py @@ -0,0 +1,561 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._publishers_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_resource_group_request, build_list_by_subscription_request, build_update_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class PublishersOperations: + """PublishersOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_subscription( + self, + **kwargs: Any + ) -> AsyncIterable["_models.PublisherListResult"]: + """Lists all the publishers in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PublisherListResult or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.PublisherListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.PublisherListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PublisherListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/publishers"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.PublisherListResult"]: + """Lists all the publishers in a resource group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PublisherListResult or the result of cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.PublisherListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.PublisherListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("PublisherListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers"} # type: ignore + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + publisher_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the specified publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + publisher_name: str, + **kwargs: Any + ) -> "_models.Publisher": + """Gets information about the specified publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Publisher, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.Publisher + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.Publisher"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Publisher', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + + + async def _create_or_update_initial( + self, + resource_group_name: str, + publisher_name: str, + parameters: Optional["_models.Publisher"] = None, + **kwargs: Any + ) -> "_models.Publisher": + cls = kwargs.pop('cls', None) # type: ClsType["_models.Publisher"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + if parameters is not None: + _json = self._serialize.body(parameters, 'Publisher') + else: + _json = None + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('Publisher', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('Publisher', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + publisher_name: str, + parameters: Optional["_models.Publisher"] = None, + **kwargs: Any + ) -> AsyncLROPoller["_models.Publisher"]: + """Creates or updates a publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param parameters: Parameters supplied to the create publisher operation. + :type parameters: ~Microsoft.HybridNetwork.models.Publisher + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either Publisher or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.Publisher] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.Publisher"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('Publisher', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + + @distributed_trace_async + async def update( + self, + resource_group_name: str, + publisher_name: str, + parameters: Optional["_models.TagsObject"] = None, + **kwargs: Any + ) -> "_models.Publisher": + """Update a publisher resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param parameters: Parameters supplied to the create publisher operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Publisher, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.Publisher + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.Publisher"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + if parameters is not None: + _json = self._serialize.body(parameters, 'TagsObject') + else: + _json = None + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Publisher', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_site_network_services_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_site_network_services_operations.py new file mode 100644 index 00000000000..c79bce18e9d --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_site_network_services_operations.py @@ -0,0 +1,557 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._site_network_services_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_resource_group_request, build_list_by_subscription_request, build_update_tags_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class SiteNetworkServicesOperations: + """SiteNetworkServicesOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + site_network_service_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + site_network_service_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the specified site network service. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_network_service_name: The name of the site network service. + :type site_network_service_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + site_network_service_name: str, + **kwargs: Any + ) -> "_models.SiteNetworkService": + """Gets information about the specified site network service. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_network_service_name: The name of the site network service. + :type site_network_service_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SiteNetworkService, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.SiteNetworkService + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkService"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SiteNetworkService', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + + async def _create_or_update_initial( + self, + resource_group_name: str, + site_network_service_name: str, + parameters: "_models.SiteNetworkService", + **kwargs: Any + ) -> "_models.SiteNetworkService": + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkService"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'SiteNetworkService') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('SiteNetworkService', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('SiteNetworkService', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + site_network_service_name: str, + parameters: "_models.SiteNetworkService", + **kwargs: Any + ) -> AsyncLROPoller["_models.SiteNetworkService"]: + """Creates or updates a network site. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_network_service_name: The name of the site network service. + :type site_network_service_name: str + :param parameters: Parameters supplied to the create or update site network service operation. + :type parameters: ~Microsoft.HybridNetwork.models.SiteNetworkService + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either SiteNetworkService or the result of + cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.SiteNetworkService] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkService"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('SiteNetworkService', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + @distributed_trace_async + async def update_tags( + self, + resource_group_name: str, + site_network_service_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.SiteNetworkService": + """Updates a site update tags. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_network_service_name: The name of the site network service. + :type site_network_service_name: str + :param parameters: Parameters supplied to update network site tags. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SiteNetworkService, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.SiteNetworkService + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkService"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_tags_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update_tags.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SiteNetworkService', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update_tags.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + + @distributed_trace + def list_by_subscription( + self, + **kwargs: Any + ) -> AsyncIterable["_models.SiteNetworkServiceListResult"]: + """Lists all sites in the network service in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either SiteNetworkServiceListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.SiteNetworkServiceListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkServiceListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("SiteNetworkServiceListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/siteNetworkServices"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.SiteNetworkServiceListResult"]: + """Lists all site network services. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either SiteNetworkServiceListResult or the result of + cls(response) + :rtype: + ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.SiteNetworkServiceListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkServiceListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("SiteNetworkServiceListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/_sites_operations.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_sites_operations.py new file mode 100644 index 00000000000..2bdc955c7dc --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/_sites_operations.py @@ -0,0 +1,552 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union + +from azure.core.async_paging import AsyncItemPaged, AsyncList +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.core.tracing.decorator_async import distributed_trace_async +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._sites_operations import build_create_or_update_request_initial, build_delete_request_initial, build_get_request, build_list_by_resource_group_request, build_list_by_subscription_request, build_update_tags_request +T = TypeVar('T') +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + +class SitesOperations: + """SitesOperations async operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer) -> None: + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + async def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + site_name: str, + **kwargs: Any + ) -> None: + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_name=site_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + + @distributed_trace_async + async def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name: str, + site_name: str, + **kwargs: Any + ) -> AsyncLROPoller[None]: + """Deletes the specified network site. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_name: The name of the network service site. + :type site_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._delete_initial( + resource_group_name=resource_group_name, + site_name=site_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + @distributed_trace_async + async def get( + self, + resource_group_name: str, + site_name: str, + **kwargs: Any + ) -> "_models.Site": + """Gets information about the specified network site. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_name: The name of the network service site. + :type site_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Site, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.Site + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.Site"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_name=site_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Site', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + + async def _create_or_update_initial( + self, + resource_group_name: str, + site_name: str, + parameters: "_models.Site", + **kwargs: Any + ) -> "_models.Site": + cls = kwargs.pop('cls', None) # type: ClsType["_models.Site"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'Site') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_name=site_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('Site', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('Site', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + + @distributed_trace_async + async def begin_create_or_update( + self, + resource_group_name: str, + site_name: str, + parameters: "_models.Site", + **kwargs: Any + ) -> AsyncLROPoller["_models.Site"]: + """Creates or updates a network site. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_name: The name of the network service site. + :type site_name: str + :param parameters: Parameters supplied to the create or update network site operation. + :type parameters: ~Microsoft.HybridNetwork.models.Site + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for + this operation to not poll, or pass in your own initialized polling object for a personal + polling strategy. + :paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of AsyncLROPoller that returns either Site or the result of cls(response) + :rtype: ~azure.core.polling.AsyncLROPoller[~Microsoft.HybridNetwork.models.Site] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, AsyncPollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.Site"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = await self._create_or_update_initial( + resource_group_name=resource_group_name, + site_name=site_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('Site', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = AsyncARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = AsyncNoPolling() + else: polling_method = polling + if cont_token: + return AsyncLROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + @distributed_trace_async + async def update_tags( + self, + resource_group_name: str, + site_name: str, + parameters: "_models.TagsObject", + **kwargs: Any + ) -> "_models.Site": + """Updates a site update tags. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_name: The name of the network service site. + :type site_name: str + :param parameters: Parameters supplied to update network site tags. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Site, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.Site + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.Site"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_tags_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_name=site_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update_tags.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Site', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update_tags.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + + @distributed_trace + def list_by_subscription( + self, + **kwargs: Any + ) -> AsyncIterable["_models.SiteListResult"]: + """Lists all sites in the network service in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either SiteListResult or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.SiteListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("SiteListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/sites"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name: str, + **kwargs: Any + ) -> AsyncIterable["_models.SiteListResult"]: + """Lists all sites in the network service. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either SiteListResult or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~Microsoft.HybridNetwork.models.SiteListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize("SiteListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return AsyncItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/models/__init__.py b/src/aosm/azext_aosm/vendored_sdks/models/__init__.py new file mode 100644 index 00000000000..31d9f39617d --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/models/__init__.py @@ -0,0 +1,484 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +try: + from ._models_py3 import ArcConnectedK8SNetworkFunctionReadyK8S + from ._models_py3 import ArmResourceDefinitionResourceElementTemplate + from ._models_py3 import ArmResourceDefinitionResourceElementTemplateDetails + from ._models_py3 import ArmTemplateApplicationOverview + from ._models_py3 import ArmTemplateArtifactProfile + from ._models_py3 import ArmTemplateMappingRuleProfile + from ._models_py3 import ArtifactAccessCredential + from ._models_py3 import ArtifactChangeState + from ._models_py3 import ArtifactChangeStateProperties + from ._models_py3 import ArtifactManifest + from ._models_py3 import ArtifactManifestListResult + from ._models_py3 import ArtifactManifestUpdateState + from ._models_py3 import ArtifactProfile + from ._models_py3 import ArtifactStore + from ._models_py3 import ArtifactStoreListResult + from ._models_py3 import ArtifactStorePropertiesFormatManagedResourceGroupConfiguration + from ._models_py3 import AzureArcK8SClusterNFVIDetails + from ._models_py3 import AzureArcKubernetesArtifactProfile + from ._models_py3 import AzureArcKubernetesDeployMappingRuleProfile + from ._models_py3 import AzureArcKubernetesHelmApplication + from ._models_py3 import AzureArcKubernetesNetworkFunctionApplication + from ._models_py3 import AzureArcKubernetesNetworkFunctionTemplate + from ._models_py3 import AzureContainerRegistryScopedTokenCredential + from ._models_py3 import AzureCoreArmTemplateArtifactProfile + from ._models_py3 import AzureCoreArmTemplateDeployMappingRuleProfile + from ._models_py3 import AzureCoreDelegatedImageArtifactProfile + from ._models_py3 import AzureCoreDelegatedImageDeployMappingRuleProfile + from ._models_py3 import AzureCoreDelegatedNetworkFunctionApplication + from ._models_py3 import AzureCoreDelegatedNetworkFunctionImageApplication + from ._models_py3 import AzureCoreDelegatedNetworkFunctionTemplate + from ._models_py3 import AzureCoreNFVIDetails + from ._models_py3 import AzureCoreNetworkFunctionApplication + from ._models_py3 import AzureCoreNetworkFunctionArmTemplateApplication + from ._models_py3 import AzureCoreNetworkFunctionTemplate + from ._models_py3 import AzureCoreNetworkFunctionVhdApplication + from ._models_py3 import AzureCoreVhdImageArtifactProfile + from ._models_py3 import AzureCoreVhdImageDeployMappingRuleProfile + from ._models_py3 import AzureKubernetesServiceNetworkFunctionReadyK8S + from ._models_py3 import AzureOperatorNexusArmTemplateArtifactProfile + from ._models_py3 import AzureOperatorNexusArmTemplateDeployMappingRuleProfile + from ._models_py3 import AzureOperatorNexusClusterNFVIDetails + from ._models_py3 import AzureOperatorNexusImageArtifactProfile + from ._models_py3 import AzureOperatorNexusImageDeployMappingRuleProfile + from ._models_py3 import AzureOperatorNexusNetworkFunctionApplication + from ._models_py3 import AzureOperatorNexusNetworkFunctionArmTemplateApplication + from ._models_py3 import AzureOperatorNexusNetworkFunctionImageApplication + from ._models_py3 import AzureOperatorNexusNetworkFunctionTemplate + from ._models_py3 import AzureStorageAccountContainerCredential + from ._models_py3 import AzureStorageAccountCredential + from ._models_py3 import Component + from ._models_py3 import ComponentListResult + from ._models_py3 import ConfigurationDefinitionResourceElementTemplate + from ._models_py3 import ConfigurationDefinitionResourceElementTemplateDetails + from ._models_py3 import ConfigurationGroupSchema + from ._models_py3 import ConfigurationGroupSchemaListResult + from ._models_py3 import ConfigurationGroupSchemaVersionUpdateState + from ._models_py3 import ConfigurationGroupValue + from ._models_py3 import ConfigurationGroupValueListResult + from ._models_py3 import ContainerizedNetworkFunctionDefinitionVersion + from ._models_py3 import ContainerizedNetworkFunctionTemplate + from ._models_py3 import CustomLocationResourceId + from ._models_py3 import DelegatedNetworkFunctionDefinitionVersion + from ._models_py3 import DelegatedNetworkFunctionTemplate + from ._models_py3 import DependsOnProfile + from ._models_py3 import ErrorAdditionalInfo + from ._models_py3 import ErrorDetail + from ._models_py3 import ErrorResponse + from ._models_py3 import ExecuteRequestParameters + from ._models_py3 import HelmArtifactProfile + from ._models_py3 import HelmMappingRuleProfile + from ._models_py3 import HelmPackageApplicationOverview + from ._models_py3 import HybridAKSNetworkFunctionReadyK8S + from ._models_py3 import ImageArtifactProfile + from ._models_py3 import ImageFileApplicationOverview + from ._models_py3 import ImageMappingRuleProfile + from ._models_py3 import ManagedResourceGroupConfiguration + from ._models_py3 import ManagedServiceIdentity + from ._models_py3 import ManifestArtifactFormat + from ._models_py3 import MappingRuleProfile + from ._models_py3 import NFVIs + from ._models_py3 import NSDArtifactProfile + from ._models_py3 import NetworkFunction + from ._models_py3 import NetworkFunctionApplication + from ._models_py3 import NetworkFunctionDefinitionApplicationOverview + from ._models_py3 import NetworkFunctionDefinitionGroup + from ._models_py3 import NetworkFunctionDefinitionGroupListResult + from ._models_py3 import NetworkFunctionDefinitionGroupOverview + from ._models_py3 import NetworkFunctionDefinitionGroupOverviewListResult + from ._models_py3 import NetworkFunctionDefinitionResourceElementTemplateDetails + from ._models_py3 import NetworkFunctionDefinitionVersion + from ._models_py3 import NetworkFunctionDefinitionVersionListResult + from ._models_py3 import NetworkFunctionDefinitionVersionOverview + from ._models_py3 import NetworkFunctionDefinitionVersionOverviewListResult + from ._models_py3 import NetworkFunctionDefinitionVersionPropertiesFormat + from ._models_py3 import NetworkFunctionDefinitionVersionUpdateState + from ._models_py3 import NetworkFunctionListResult + from ._models_py3 import NetworkFunctionReadyK8S + from ._models_py3 import NetworkFunctionReadyK8SListResult + from ._models_py3 import NetworkFunctionReadyK8SPropertiesFormat + from ._models_py3 import NetworkServiceDesignGroup + from ._models_py3 import NetworkServiceDesignGroupListResult + from ._models_py3 import NetworkServiceDesignVersion + from ._models_py3 import NetworkServiceDesignVersionListResult + from ._models_py3 import NetworkServiceDesignVersionUpdateState + from ._models_py3 import NfviDetails + from ._models_py3 import Operation + from ._models_py3 import OperationDisplay + from ._models_py3 import OperationList + from ._models_py3 import PreviewSubscription + from ._models_py3 import PreviewSubscriptionsList + from ._models_py3 import ProxyArtifactListOverview + from ._models_py3 import ProxyArtifactOverview + from ._models_py3 import ProxyArtifactOverviewListResult + from ._models_py3 import ProxyArtifactOverviewPropertiesValue + from ._models_py3 import ProxyArtifactVersionsListOverview + from ._models_py3 import ProxyArtifactVersionsOverviewListResult + from ._models_py3 import ProxyPublisherOverview + from ._models_py3 import ProxyPublisherOverviewListResult + from ._models_py3 import ProxyResource + from ._models_py3 import Publisher + from ._models_py3 import PublisherListResult + from ._models_py3 import ReferencedResource + from ._models_py3 import RequestMetadata + from ._models_py3 import Resource + from ._models_py3 import ResourceElementTemplate + from ._models_py3 import Site + from ._models_py3 import SiteListResult + from ._models_py3 import SiteNetworkService + from ._models_py3 import SiteNetworkServiceListResult + from ._models_py3 import SystemData + from ._models_py3 import TagsObject + from ._models_py3 import TrackedResource + from ._models_py3 import UserAssignedIdentity + from ._models_py3 import VhdImageArtifactProfile + from ._models_py3 import VhdImageFileApplicationOverview + from ._models_py3 import VhdImageMappingRuleProfile + from ._models_py3 import VirtualNetworkFunctionDefinitionVersion + from ._models_py3 import VirtualNetworkFunctionTemplate +except (SyntaxError, ImportError): + from ._models import ArcConnectedK8SNetworkFunctionReadyK8S # type: ignore + from ._models import ArmResourceDefinitionResourceElementTemplate # type: ignore + from ._models import ArmResourceDefinitionResourceElementTemplateDetails # type: ignore + from ._models import ArmTemplateApplicationOverview # type: ignore + from ._models import ArmTemplateArtifactProfile # type: ignore + from ._models import ArmTemplateMappingRuleProfile # type: ignore + from ._models import ArtifactAccessCredential # type: ignore + from ._models import ArtifactChangeState # type: ignore + from ._models import ArtifactChangeStateProperties # type: ignore + from ._models import ArtifactManifest # type: ignore + from ._models import ArtifactManifestListResult # type: ignore + from ._models import ArtifactManifestUpdateState # type: ignore + from ._models import ArtifactProfile # type: ignore + from ._models import ArtifactStore # type: ignore + from ._models import ArtifactStoreListResult # type: ignore + from ._models import ArtifactStorePropertiesFormatManagedResourceGroupConfiguration # type: ignore + from ._models import AzureArcK8SClusterNFVIDetails # type: ignore + from ._models import AzureArcKubernetesArtifactProfile # type: ignore + from ._models import AzureArcKubernetesDeployMappingRuleProfile # type: ignore + from ._models import AzureArcKubernetesHelmApplication # type: ignore + from ._models import AzureArcKubernetesNetworkFunctionApplication # type: ignore + from ._models import AzureArcKubernetesNetworkFunctionTemplate # type: ignore + from ._models import AzureContainerRegistryScopedTokenCredential # type: ignore + from ._models import AzureCoreArmTemplateArtifactProfile # type: ignore + from ._models import AzureCoreArmTemplateDeployMappingRuleProfile # type: ignore + from ._models import AzureCoreDelegatedImageArtifactProfile # type: ignore + from ._models import AzureCoreDelegatedImageDeployMappingRuleProfile # type: ignore + from ._models import AzureCoreDelegatedNetworkFunctionApplication # type: ignore + from ._models import AzureCoreDelegatedNetworkFunctionImageApplication # type: ignore + from ._models import AzureCoreDelegatedNetworkFunctionTemplate # type: ignore + from ._models import AzureCoreNFVIDetails # type: ignore + from ._models import AzureCoreNetworkFunctionApplication # type: ignore + from ._models import AzureCoreNetworkFunctionArmTemplateApplication # type: ignore + from ._models import AzureCoreNetworkFunctionTemplate # type: ignore + from ._models import AzureCoreNetworkFunctionVhdApplication # type: ignore + from ._models import AzureCoreVhdImageArtifactProfile # type: ignore + from ._models import AzureCoreVhdImageDeployMappingRuleProfile # type: ignore + from ._models import AzureKubernetesServiceNetworkFunctionReadyK8S # type: ignore + from ._models import AzureOperatorNexusArmTemplateArtifactProfile # type: ignore + from ._models import AzureOperatorNexusArmTemplateDeployMappingRuleProfile # type: ignore + from ._models import AzureOperatorNexusClusterNFVIDetails # type: ignore + from ._models import AzureOperatorNexusImageArtifactProfile # type: ignore + from ._models import AzureOperatorNexusImageDeployMappingRuleProfile # type: ignore + from ._models import AzureOperatorNexusNetworkFunctionApplication # type: ignore + from ._models import AzureOperatorNexusNetworkFunctionArmTemplateApplication # type: ignore + from ._models import AzureOperatorNexusNetworkFunctionImageApplication # type: ignore + from ._models import AzureOperatorNexusNetworkFunctionTemplate # type: ignore + from ._models import AzureStorageAccountContainerCredential # type: ignore + from ._models import AzureStorageAccountCredential # type: ignore + from ._models import Component # type: ignore + from ._models import ComponentListResult # type: ignore + from ._models import ConfigurationDefinitionResourceElementTemplate # type: ignore + from ._models import ConfigurationDefinitionResourceElementTemplateDetails # type: ignore + from ._models import ConfigurationGroupSchema # type: ignore + from ._models import ConfigurationGroupSchemaListResult # type: ignore + from ._models import ConfigurationGroupSchemaVersionUpdateState # type: ignore + from ._models import ConfigurationGroupValue # type: ignore + from ._models import ConfigurationGroupValueListResult # type: ignore + from ._models import ContainerizedNetworkFunctionDefinitionVersion # type: ignore + from ._models import ContainerizedNetworkFunctionTemplate # type: ignore + from ._models import CustomLocationResourceId # type: ignore + from ._models import DelegatedNetworkFunctionDefinitionVersion # type: ignore + from ._models import DelegatedNetworkFunctionTemplate # type: ignore + from ._models import DependsOnProfile # type: ignore + from ._models import ErrorAdditionalInfo # type: ignore + from ._models import ErrorDetail # type: ignore + from ._models import ErrorResponse # type: ignore + from ._models import ExecuteRequestParameters # type: ignore + from ._models import HelmArtifactProfile # type: ignore + from ._models import HelmMappingRuleProfile # type: ignore + from ._models import HelmPackageApplicationOverview # type: ignore + from ._models import HybridAKSNetworkFunctionReadyK8S # type: ignore + from ._models import ImageArtifactProfile # type: ignore + from ._models import ImageFileApplicationOverview # type: ignore + from ._models import ImageMappingRuleProfile # type: ignore + from ._models import ManagedResourceGroupConfiguration # type: ignore + from ._models import ManagedServiceIdentity # type: ignore + from ._models import ManifestArtifactFormat # type: ignore + from ._models import MappingRuleProfile # type: ignore + from ._models import NFVIs # type: ignore + from ._models import NSDArtifactProfile # type: ignore + from ._models import NetworkFunction # type: ignore + from ._models import NetworkFunctionApplication # type: ignore + from ._models import NetworkFunctionDefinitionApplicationOverview # type: ignore + from ._models import NetworkFunctionDefinitionGroup # type: ignore + from ._models import NetworkFunctionDefinitionGroupListResult # type: ignore + from ._models import NetworkFunctionDefinitionGroupOverview # type: ignore + from ._models import NetworkFunctionDefinitionGroupOverviewListResult # type: ignore + from ._models import NetworkFunctionDefinitionResourceElementTemplateDetails # type: ignore + from ._models import NetworkFunctionDefinitionVersion # type: ignore + from ._models import NetworkFunctionDefinitionVersionListResult # type: ignore + from ._models import NetworkFunctionDefinitionVersionOverview # type: ignore + from ._models import NetworkFunctionDefinitionVersionOverviewListResult # type: ignore + from ._models import NetworkFunctionDefinitionVersionPropertiesFormat # type: ignore + from ._models import NetworkFunctionDefinitionVersionUpdateState # type: ignore + from ._models import NetworkFunctionListResult # type: ignore + from ._models import NetworkFunctionReadyK8S # type: ignore + from ._models import NetworkFunctionReadyK8SListResult # type: ignore + from ._models import NetworkFunctionReadyK8SPropertiesFormat # type: ignore + from ._models import NetworkServiceDesignGroup # type: ignore + from ._models import NetworkServiceDesignGroupListResult # type: ignore + from ._models import NetworkServiceDesignVersion # type: ignore + from ._models import NetworkServiceDesignVersionListResult # type: ignore + from ._models import NetworkServiceDesignVersionUpdateState # type: ignore + from ._models import NfviDetails # type: ignore + from ._models import Operation # type: ignore + from ._models import OperationDisplay # type: ignore + from ._models import OperationList # type: ignore + from ._models import PreviewSubscription # type: ignore + from ._models import PreviewSubscriptionsList # type: ignore + from ._models import ProxyArtifactListOverview # type: ignore + from ._models import ProxyArtifactOverview # type: ignore + from ._models import ProxyArtifactOverviewListResult # type: ignore + from ._models import ProxyArtifactOverviewPropertiesValue # type: ignore + from ._models import ProxyArtifactVersionsListOverview # type: ignore + from ._models import ProxyArtifactVersionsOverviewListResult # type: ignore + from ._models import ProxyPublisherOverview # type: ignore + from ._models import ProxyPublisherOverviewListResult # type: ignore + from ._models import ProxyResource # type: ignore + from ._models import Publisher # type: ignore + from ._models import PublisherListResult # type: ignore + from ._models import ReferencedResource # type: ignore + from ._models import RequestMetadata # type: ignore + from ._models import Resource # type: ignore + from ._models import ResourceElementTemplate # type: ignore + from ._models import Site # type: ignore + from ._models import SiteListResult # type: ignore + from ._models import SiteNetworkService # type: ignore + from ._models import SiteNetworkServiceListResult # type: ignore + from ._models import SystemData # type: ignore + from ._models import TagsObject # type: ignore + from ._models import TrackedResource # type: ignore + from ._models import UserAssignedIdentity # type: ignore + from ._models import VhdImageArtifactProfile # type: ignore + from ._models import VhdImageFileApplicationOverview # type: ignore + from ._models import VhdImageMappingRuleProfile # type: ignore + from ._models import VirtualNetworkFunctionDefinitionVersion # type: ignore + from ._models import VirtualNetworkFunctionTemplate # type: ignore + +from ._hybrid_network_management_client_enums import ( + ApplicationEnablement, + ArtifactManifestState, + ArtifactReplicationStrategy, + ArtifactState, + ArtifactStoreType, + ArtifactType, + AzureArcKubernetesArtifactType, + AzureCoreArtifactType, + AzureCoreDelegatedArtifactType, + AzureOperatorNexusArtifactType, + ClusterType, + ConfigurationGenerationType, + ContainerizedNetworkFunctionNFVIType, + CreatedByType, + CredentialType, + DelegatedNetworkFunctionNFVIType, + HttpMethod, + ManagedServiceIdentityType, + NFVIType, + NetworkFunctionPublisherArtifactType, + NetworkFunctionType, + ProvisioningState, + PublisherScope, + TemplateType, + Type, + VersionState, + VirtualNetworkFunctionNFVIType, +) + +__all__ = [ + 'ArcConnectedK8SNetworkFunctionReadyK8S', + 'ArmResourceDefinitionResourceElementTemplate', + 'ArmResourceDefinitionResourceElementTemplateDetails', + 'ArmTemplateApplicationOverview', + 'ArmTemplateArtifactProfile', + 'ArmTemplateMappingRuleProfile', + 'ArtifactAccessCredential', + 'ArtifactChangeState', + 'ArtifactChangeStateProperties', + 'ArtifactManifest', + 'ArtifactManifestListResult', + 'ArtifactManifestUpdateState', + 'ArtifactProfile', + 'ArtifactStore', + 'ArtifactStoreListResult', + 'ArtifactStorePropertiesFormatManagedResourceGroupConfiguration', + 'AzureArcK8SClusterNFVIDetails', + 'AzureArcKubernetesArtifactProfile', + 'AzureArcKubernetesDeployMappingRuleProfile', + 'AzureArcKubernetesHelmApplication', + 'AzureArcKubernetesNetworkFunctionApplication', + 'AzureArcKubernetesNetworkFunctionTemplate', + 'AzureContainerRegistryScopedTokenCredential', + 'AzureCoreArmTemplateArtifactProfile', + 'AzureCoreArmTemplateDeployMappingRuleProfile', + 'AzureCoreDelegatedImageArtifactProfile', + 'AzureCoreDelegatedImageDeployMappingRuleProfile', + 'AzureCoreDelegatedNetworkFunctionApplication', + 'AzureCoreDelegatedNetworkFunctionImageApplication', + 'AzureCoreDelegatedNetworkFunctionTemplate', + 'AzureCoreNFVIDetails', + 'AzureCoreNetworkFunctionApplication', + 'AzureCoreNetworkFunctionArmTemplateApplication', + 'AzureCoreNetworkFunctionTemplate', + 'AzureCoreNetworkFunctionVhdApplication', + 'AzureCoreVhdImageArtifactProfile', + 'AzureCoreVhdImageDeployMappingRuleProfile', + 'AzureKubernetesServiceNetworkFunctionReadyK8S', + 'AzureOperatorNexusArmTemplateArtifactProfile', + 'AzureOperatorNexusArmTemplateDeployMappingRuleProfile', + 'AzureOperatorNexusClusterNFVIDetails', + 'AzureOperatorNexusImageArtifactProfile', + 'AzureOperatorNexusImageDeployMappingRuleProfile', + 'AzureOperatorNexusNetworkFunctionApplication', + 'AzureOperatorNexusNetworkFunctionArmTemplateApplication', + 'AzureOperatorNexusNetworkFunctionImageApplication', + 'AzureOperatorNexusNetworkFunctionTemplate', + 'AzureStorageAccountContainerCredential', + 'AzureStorageAccountCredential', + 'Component', + 'ComponentListResult', + 'ConfigurationDefinitionResourceElementTemplate', + 'ConfigurationDefinitionResourceElementTemplateDetails', + 'ConfigurationGroupSchema', + 'ConfigurationGroupSchemaListResult', + 'ConfigurationGroupSchemaVersionUpdateState', + 'ConfigurationGroupValue', + 'ConfigurationGroupValueListResult', + 'ContainerizedNetworkFunctionDefinitionVersion', + 'ContainerizedNetworkFunctionTemplate', + 'CustomLocationResourceId', + 'DelegatedNetworkFunctionDefinitionVersion', + 'DelegatedNetworkFunctionTemplate', + 'DependsOnProfile', + 'ErrorAdditionalInfo', + 'ErrorDetail', + 'ErrorResponse', + 'ExecuteRequestParameters', + 'HelmArtifactProfile', + 'HelmMappingRuleProfile', + 'HelmPackageApplicationOverview', + 'HybridAKSNetworkFunctionReadyK8S', + 'ImageArtifactProfile', + 'ImageFileApplicationOverview', + 'ImageMappingRuleProfile', + 'ManagedResourceGroupConfiguration', + 'ManagedServiceIdentity', + 'ManifestArtifactFormat', + 'MappingRuleProfile', + 'NFVIs', + 'NSDArtifactProfile', + 'NetworkFunction', + 'NetworkFunctionApplication', + 'NetworkFunctionDefinitionApplicationOverview', + 'NetworkFunctionDefinitionGroup', + 'NetworkFunctionDefinitionGroupListResult', + 'NetworkFunctionDefinitionGroupOverview', + 'NetworkFunctionDefinitionGroupOverviewListResult', + 'NetworkFunctionDefinitionResourceElementTemplateDetails', + 'NetworkFunctionDefinitionVersion', + 'NetworkFunctionDefinitionVersionListResult', + 'NetworkFunctionDefinitionVersionOverview', + 'NetworkFunctionDefinitionVersionOverviewListResult', + 'NetworkFunctionDefinitionVersionPropertiesFormat', + 'NetworkFunctionDefinitionVersionUpdateState', + 'NetworkFunctionListResult', + 'NetworkFunctionReadyK8S', + 'NetworkFunctionReadyK8SListResult', + 'NetworkFunctionReadyK8SPropertiesFormat', + 'NetworkServiceDesignGroup', + 'NetworkServiceDesignGroupListResult', + 'NetworkServiceDesignVersion', + 'NetworkServiceDesignVersionListResult', + 'NetworkServiceDesignVersionUpdateState', + 'NfviDetails', + 'Operation', + 'OperationDisplay', + 'OperationList', + 'PreviewSubscription', + 'PreviewSubscriptionsList', + 'ProxyArtifactListOverview', + 'ProxyArtifactOverview', + 'ProxyArtifactOverviewListResult', + 'ProxyArtifactOverviewPropertiesValue', + 'ProxyArtifactVersionsListOverview', + 'ProxyArtifactVersionsOverviewListResult', + 'ProxyPublisherOverview', + 'ProxyPublisherOverviewListResult', + 'ProxyResource', + 'Publisher', + 'PublisherListResult', + 'ReferencedResource', + 'RequestMetadata', + 'Resource', + 'ResourceElementTemplate', + 'Site', + 'SiteListResult', + 'SiteNetworkService', + 'SiteNetworkServiceListResult', + 'SystemData', + 'TagsObject', + 'TrackedResource', + 'UserAssignedIdentity', + 'VhdImageArtifactProfile', + 'VhdImageFileApplicationOverview', + 'VhdImageMappingRuleProfile', + 'VirtualNetworkFunctionDefinitionVersion', + 'VirtualNetworkFunctionTemplate', + 'ApplicationEnablement', + 'ArtifactManifestState', + 'ArtifactReplicationStrategy', + 'ArtifactState', + 'ArtifactStoreType', + 'ArtifactType', + 'AzureArcKubernetesArtifactType', + 'AzureCoreArtifactType', + 'AzureCoreDelegatedArtifactType', + 'AzureOperatorNexusArtifactType', + 'ClusterType', + 'ConfigurationGenerationType', + 'ContainerizedNetworkFunctionNFVIType', + 'CreatedByType', + 'CredentialType', + 'DelegatedNetworkFunctionNFVIType', + 'HttpMethod', + 'ManagedServiceIdentityType', + 'NFVIType', + 'NetworkFunctionPublisherArtifactType', + 'NetworkFunctionType', + 'ProvisioningState', + 'PublisherScope', + 'TemplateType', + 'Type', + 'VersionState', + 'VirtualNetworkFunctionNFVIType', +] diff --git a/src/aosm/azext_aosm/vendored_sdks/models/_hybrid_network_management_client_enums.py b/src/aosm/azext_aosm/vendored_sdks/models/_hybrid_network_management_client_enums.py new file mode 100644 index 00000000000..052b924987e --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/models/_hybrid_network_management_client_enums.py @@ -0,0 +1,247 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from enum import Enum +from six import with_metaclass +from azure.core import CaseInsensitiveEnumMeta + + +class ApplicationEnablement(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The application enablement. + """ + + UNKNOWN = "Unknown" + ENABLED = "Enabled" + DISABLED = "Disabled" + +class ArtifactManifestState(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The artifact manifest state. + """ + + UNKNOWN = "Unknown" + UPLOADING = "Uploading" + UPLOADED = "Uploaded" + VALIDATING = "Validating" + VALIDATION_FAILED = "ValidationFailed" + SUCCEEDED = "Succeeded" + +class ArtifactReplicationStrategy(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The replication strategy. + """ + + UNKNOWN = "Unknown" + SINGLE_REPLICATION = "SingleReplication" + GEO_REPLICATION = "GeoReplication" + +class ArtifactState(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The artifact state. + """ + + UNKNOWN = "Unknown" + PREVIEW = "Preview" + ACTIVE = "Active" + DEPRECATED = "Deprecated" + +class ArtifactStoreType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The artifact store type. + """ + + UNKNOWN = "Unknown" + AZURE_CONTAINER_REGISTRY = "AzureContainerRegistry" + AZURE_STORAGE_ACCOUNT = "AzureStorageAccount" + +class ArtifactType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The artifact type. + """ + + UNKNOWN = "Unknown" + OCI_ARTIFACT = "OCIArtifact" + VHD_IMAGE_FILE = "VhdImageFile" + ARM_TEMPLATE = "ArmTemplate" + IMAGE_FILE = "ImageFile" + +class AzureArcKubernetesArtifactType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The artifact type. + """ + + UNKNOWN = "Unknown" + HELM_PACKAGE = "HelmPackage" + +class AzureCoreArtifactType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The artifact type. + """ + + UNKNOWN = "Unknown" + VHD_IMAGE_FILE = "VhdImageFile" + ARM_TEMPLATE = "ArmTemplate" + +class AzureCoreDelegatedArtifactType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The artifact type. + """ + + UNKNOWN = "Unknown" + IMAGE_FILE = "ImageFile" + +class AzureOperatorNexusArtifactType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The artifact type. + """ + + UNKNOWN = "Unknown" + IMAGE_FILE = "ImageFile" + ARM_TEMPLATE = "ArmTemplate" + +class ClusterType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The cluster type. + """ + + AZURE_KUBERNETES_SERVICE = "AzureKubernetesService" + ARC_CONNECTED_K8_S = "ArcConnectedK8s" + HYBRID_AKS = "HybridAKS" + +class ConfigurationGenerationType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The configuration generation type. + """ + + UNKNOWN = "Unknown" + HANDLEBAR_TEMPLATE = "HandlebarTemplate" + +class ContainerizedNetworkFunctionNFVIType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The network function type. + """ + + UNKNOWN = "Unknown" + AZURE_ARC_KUBERNETES = "AzureArcKubernetes" + +class CreatedByType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The type of identity that created the resource. + """ + + USER = "User" + APPLICATION = "Application" + MANAGED_IDENTITY = "ManagedIdentity" + KEY = "Key" + +class CredentialType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The credential type. + """ + + UNKNOWN = "Unknown" + AZURE_CONTAINER_REGISTRY_SCOPED_TOKEN = "AzureContainerRegistryScopedToken" + AZURE_STORAGE_ACCOUNT_TOKEN = "AzureStorageAccountToken" + +class DelegatedNetworkFunctionNFVIType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The network function type. + """ + + UNKNOWN = "Unknown" + AZURE_CORE = "AzureCore" + +class HttpMethod(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The http method of the request. + """ + + UNKNOWN = "Unknown" + POST = "Post" + PUT = "Put" + GET = "Get" + PATCH = "Patch" + DELETE = "Delete" + +class ManagedServiceIdentityType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """Type of managed service identity (where both SystemAssigned and UserAssigned types are + allowed). + """ + + NONE = "None" + SYSTEM_ASSIGNED = "SystemAssigned" + USER_ASSIGNED = "UserAssigned" + SYSTEM_ASSIGNED_USER_ASSIGNED = "SystemAssigned,UserAssigned" + +class NetworkFunctionPublisherArtifactType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """Network Function publisher artifact type. + """ + + UNKNOWN = "Unknown" + HELM_PACKAGE = "HelmPackage" + VHD_IMAGE_FILE = "VhdImageFile" + ARM_TEMPLATE = "ArmTemplate" + IMAGE_FILE = "ImageFile" + +class NetworkFunctionType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The network function type. + """ + + UNKNOWN = "Unknown" + VIRTUAL_NETWORK_FUNCTION = "VirtualNetworkFunction" + CONTAINERIZED_NETWORK_FUNCTION = "ContainerizedNetworkFunction" + DELEGATED_NETWORK_FUNCTION = "DelegatedNetworkFunction" + +class NFVIType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The NFVI type. + """ + + UNKNOWN = "Unknown" + AZURE_ARC_KUBERNETES = "AzureArcKubernetes" + AZURE_CORE = "AzureCore" + AZURE_OPERATOR_NEXUS = "AzureOperatorNexus" + +class ProvisioningState(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The current provisioning state. + """ + + UNKNOWN = "Unknown" + SUCCEEDED = "Succeeded" + ACCEPTED = "Accepted" + DELETING = "Deleting" + FAILED = "Failed" + CANCELED = "Canceled" + DELETED = "Deleted" + CONVERGING = "Converging" + +class PublisherScope(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """Publisher Scope. + """ + + UNKNOWN = "Unknown" + PUBLIC = "Public" + PRIVATE = "Private" + +class TemplateType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The template type. + """ + + UNKNOWN = "Unknown" + ARM_TEMPLATE = "ArmTemplate" + +class Type(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The resource element template type. + """ + + UNKNOWN = "Unknown" + ARM_RESOURCE_DEFINITION = "ArmResourceDefinition" + CONFIGURATION_DEFINITION = "ConfigurationDefinition" + NETWORK_FUNCTION_DEFINITION = "NetworkFunctionDefinition" + +class VersionState(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The configuration group schema state. + """ + + UNKNOWN = "Unknown" + PREVIEW = "Preview" + ACTIVE = "Active" + DEPRECATED = "Deprecated" + VALIDATING = "Validating" + VALIDATION_FAILED = "ValidationFailed" + +class VirtualNetworkFunctionNFVIType(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """The network function type. + """ + + UNKNOWN = "Unknown" + AZURE_CORE = "AzureCore" + AZURE_OPERATOR_NEXUS = "AzureOperatorNexus" diff --git a/src/aosm/azext_aosm/vendored_sdks/models/_models.py b/src/aosm/azext_aosm/vendored_sdks/models/_models.py new file mode 100644 index 00000000000..6f0814e429a --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/models/_models.py @@ -0,0 +1,6039 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.core.exceptions import HttpResponseError +import msrest.serialization + + +class NetworkFunctionReadyK8SPropertiesFormat(msrest.serialization.Model): + """NetworkFunctionReadyK8s properties. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: ArcConnectedK8SNetworkFunctionReadyK8S, AzureKubernetesServiceNetworkFunctionReadyK8S, HybridAKSNetworkFunctionReadyK8S. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the NetworkFunctionReadyK8s resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar cluster_type: Required. The cluster type.Constant filled by server. Possible values + include: "AzureKubernetesService", "ArcConnectedK8s", "HybridAKS". + :vartype cluster_type: str or ~Microsoft.HybridNetwork.models.ClusterType + :ivar cluster_reference: Required. The k8s/Connected cluster ARM id. + :vartype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar custom_location_reference: The read only custom location ARM id. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'cluster_type': {'required': True}, + 'cluster_reference': {'required': True}, + 'custom_location_reference': {'readonly': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'cluster_type': {'key': 'clusterType', 'type': 'str'}, + 'cluster_reference': {'key': 'clusterReference', 'type': 'ReferencedResource'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + } + + _subtype_map = { + 'cluster_type': {'ArcConnectedK8s': 'ArcConnectedK8SNetworkFunctionReadyK8S', 'AzureKubernetesService': 'AzureKubernetesServiceNetworkFunctionReadyK8S', 'HybridAKS': 'HybridAKSNetworkFunctionReadyK8S'} + } + + def __init__( + self, + **kwargs + ): + """ + :keyword cluster_reference: Required. The k8s/Connected cluster ARM id. + :paramtype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(NetworkFunctionReadyK8SPropertiesFormat, self).__init__(**kwargs) + self.provisioning_state = None + self.cluster_type = None # type: Optional[str] + self.cluster_reference = kwargs['cluster_reference'] + self.custom_location_reference = None + + +class ArcConnectedK8SNetworkFunctionReadyK8S(NetworkFunctionReadyK8SPropertiesFormat): + """Arc Connected kubernetes cluster prerequisite properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the NetworkFunctionReadyK8s resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar cluster_type: Required. The cluster type.Constant filled by server. Possible values + include: "AzureKubernetesService", "ArcConnectedK8s", "HybridAKS". + :vartype cluster_type: str or ~Microsoft.HybridNetwork.models.ClusterType + :ivar cluster_reference: Required. The k8s/Connected cluster ARM id. + :vartype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar custom_location_reference: The read only custom location ARM id. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar user_assigned_managed_identity: Required. The User Assigned Managed Identity ARM id + which has access to the connected cluster. + :vartype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'cluster_type': {'required': True}, + 'cluster_reference': {'required': True}, + 'custom_location_reference': {'readonly': True}, + 'user_assigned_managed_identity': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'cluster_type': {'key': 'clusterType', 'type': 'str'}, + 'cluster_reference': {'key': 'clusterReference', 'type': 'ReferencedResource'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + 'user_assigned_managed_identity': {'key': 'userAssignedManagedIdentity', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword cluster_reference: Required. The k8s/Connected cluster ARM id. + :paramtype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword user_assigned_managed_identity: Required. The User Assigned Managed Identity ARM id + which has access to the connected cluster. + :paramtype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(ArcConnectedK8SNetworkFunctionReadyK8S, self).__init__(**kwargs) + self.cluster_type = 'ArcConnectedK8s' # type: str + self.user_assigned_managed_identity = kwargs['user_assigned_managed_identity'] + + +class ArmResourceDefinitionResourceElementTemplate(msrest.serialization.Model): + """The arm template RE. + + :ivar template_type: The template type. Possible values include: "Unknown", "ArmTemplate". + :vartype template_type: str or ~Microsoft.HybridNetwork.models.TemplateType + :ivar parameter_values: Name and value pairs that define the parameter values. It can be a + well formed escaped JSON string. + :vartype parameter_values: str + :ivar artifact_profile: Artifact profile properties. + :vartype artifact_profile: ~Microsoft.HybridNetwork.models.NSDArtifactProfile + """ + + _attribute_map = { + 'template_type': {'key': 'templateType', 'type': 'str'}, + 'parameter_values': {'key': 'parameterValues', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'NSDArtifactProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword template_type: The template type. Possible values include: "Unknown", "ArmTemplate". + :paramtype template_type: str or ~Microsoft.HybridNetwork.models.TemplateType + :keyword parameter_values: Name and value pairs that define the parameter values. It can be a + well formed escaped JSON string. + :paramtype parameter_values: str + :keyword artifact_profile: Artifact profile properties. + :paramtype artifact_profile: ~Microsoft.HybridNetwork.models.NSDArtifactProfile + """ + super(ArmResourceDefinitionResourceElementTemplate, self).__init__(**kwargs) + self.template_type = kwargs.get('template_type', None) + self.parameter_values = kwargs.get('parameter_values', None) + self.artifact_profile = kwargs.get('artifact_profile', None) + + +class ResourceElementTemplate(msrest.serialization.Model): + """The resource element template object. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: ArmResourceDefinitionResourceElementTemplateDetails, ConfigurationDefinitionResourceElementTemplateDetails, NetworkFunctionDefinitionResourceElementTemplateDetails. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the resource element template. + :vartype name: str + :ivar type: Required. The resource element template type.Constant filled by server. Possible + values include: "Unknown", "ArmResourceDefinition", "ConfigurationDefinition", + "NetworkFunctionDefinition". + :vartype type: str or ~Microsoft.HybridNetwork.models.Type + :ivar depends_on_profile: The depends on profile. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + + _validation = { + 'type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + } + + _subtype_map = { + 'type': {'ArmResourceDefinition': 'ArmResourceDefinitionResourceElementTemplateDetails', 'ConfigurationDefinition': 'ConfigurationDefinitionResourceElementTemplateDetails', 'NetworkFunctionDefinition': 'NetworkFunctionDefinitionResourceElementTemplateDetails'} + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: Name of the resource element template. + :paramtype name: str + :keyword depends_on_profile: The depends on profile. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(ResourceElementTemplate, self).__init__(**kwargs) + self.name = kwargs.get('name', None) + self.type = None # type: Optional[str] + self.depends_on_profile = kwargs.get('depends_on_profile', None) + + +class ArmResourceDefinitionResourceElementTemplateDetails(ResourceElementTemplate): + """The arm resource definition resource element template details. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the resource element template. + :vartype name: str + :ivar type: Required. The resource element template type.Constant filled by server. Possible + values include: "Unknown", "ArmResourceDefinition", "ConfigurationDefinition", + "NetworkFunctionDefinition". + :vartype type: str or ~Microsoft.HybridNetwork.models.Type + :ivar depends_on_profile: The depends on profile. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar configuration: The resource element template type. + :vartype configuration: + ~Microsoft.HybridNetwork.models.ArmResourceDefinitionResourceElementTemplate + """ + + _validation = { + 'type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'configuration': {'key': 'configuration', 'type': 'ArmResourceDefinitionResourceElementTemplate'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: Name of the resource element template. + :paramtype name: str + :keyword depends_on_profile: The depends on profile. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword configuration: The resource element template type. + :paramtype configuration: + ~Microsoft.HybridNetwork.models.ArmResourceDefinitionResourceElementTemplate + """ + super(ArmResourceDefinitionResourceElementTemplateDetails, self).__init__(**kwargs) + self.type = 'ArmResourceDefinition' # type: str + self.configuration = kwargs.get('configuration', None) + + +class NetworkFunctionDefinitionApplicationOverview(msrest.serialization.Model): + """The network function definition application overview. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: ArmTemplateApplicationOverview, HelmPackageApplicationOverview, ImageFileApplicationOverview, VhdImageFileApplicationOverview. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the application. + :vartype name: str + :ivar artifact_type: Required. The application overview artifact type.Constant filled by + server. Possible values include: "Unknown", "HelmPackage", "VhdImageFile", "ArmTemplate", + "ImageFile". + :vartype artifact_type: str or + ~Microsoft.HybridNetwork.models.NetworkFunctionPublisherArtifactType + """ + + _validation = { + 'name': {'readonly': True}, + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + } + + _subtype_map = { + 'artifact_type': {'ArmTemplate': 'ArmTemplateApplicationOverview', 'HelmPackage': 'HelmPackageApplicationOverview', 'ImageFile': 'ImageFileApplicationOverview', 'VhdImageFile': 'VhdImageFileApplicationOverview'} + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(NetworkFunctionDefinitionApplicationOverview, self).__init__(**kwargs) + self.name = None + self.artifact_type = None # type: Optional[str] + + +class ArmTemplateApplicationOverview(NetworkFunctionDefinitionApplicationOverview): + """Arm template Application overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the application. + :vartype name: str + :ivar artifact_type: Required. The application overview artifact type.Constant filled by + server. Possible values include: "Unknown", "HelmPackage", "VhdImageFile", "ArmTemplate", + "ImageFile". + :vartype artifact_type: str or + ~Microsoft.HybridNetwork.models.NetworkFunctionPublisherArtifactType + :ivar deploy_parameters_mapping_rule_profile: The deployment parameters mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreArmTemplateDeployMappingRuleProfile + """ + + _validation = { + 'name': {'readonly': True}, + 'artifact_type': {'required': True}, + 'deploy_parameters_mapping_rule_profile': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreArmTemplateDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ArmTemplateApplicationOverview, self).__init__(**kwargs) + self.artifact_type = 'ArmTemplate' # type: str + self.deploy_parameters_mapping_rule_profile = None + + +class ArmTemplateArtifactProfile(msrest.serialization.Model): + """Template artifact profile. + + :ivar template_name: Template name. + :vartype template_name: str + :ivar template_version: Template version. + :vartype template_version: str + """ + + _attribute_map = { + 'template_name': {'key': 'templateName', 'type': 'str'}, + 'template_version': {'key': 'templateVersion', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword template_name: Template name. + :paramtype template_name: str + :keyword template_version: Template version. + :paramtype template_version: str + """ + super(ArmTemplateArtifactProfile, self).__init__(**kwargs) + self.template_name = kwargs.get('template_name', None) + self.template_version = kwargs.get('template_version', None) + + +class ArmTemplateMappingRuleProfile(msrest.serialization.Model): + """Template mapping rule profile. + + :ivar template_parameters: List of template parameters. + :vartype template_parameters: str + """ + + _attribute_map = { + 'template_parameters': {'key': 'templateParameters', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword template_parameters: List of template parameters. + :paramtype template_parameters: str + """ + super(ArmTemplateMappingRuleProfile, self).__init__(**kwargs) + self.template_parameters = kwargs.get('template_parameters', None) + + +class ArtifactAccessCredential(msrest.serialization.Model): + """The artifact manifest credential definition. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureContainerRegistryScopedTokenCredential, AzureStorageAccountCredential. + + All required parameters must be populated in order to send to Azure. + + :ivar credential_type: Required. The credential type.Constant filled by server. Possible values + include: "Unknown", "AzureContainerRegistryScopedToken", "AzureStorageAccountToken". + :vartype credential_type: str or ~Microsoft.HybridNetwork.models.CredentialType + """ + + _validation = { + 'credential_type': {'required': True}, + } + + _attribute_map = { + 'credential_type': {'key': 'credentialType', 'type': 'str'}, + } + + _subtype_map = { + 'credential_type': {'AzureContainerRegistryScopedToken': 'AzureContainerRegistryScopedTokenCredential', 'AzureStorageAccountToken': 'AzureStorageAccountCredential'} + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ArtifactAccessCredential, self).__init__(**kwargs) + self.credential_type = None # type: Optional[str] + + +class ArtifactChangeState(msrest.serialization.Model): + """The artifact updating request payload. + + :ivar properties: Artifact update state properties. + :vartype properties: ~Microsoft.HybridNetwork.models.ArtifactChangeStateProperties + """ + + _attribute_map = { + 'properties': {'key': 'properties', 'type': 'ArtifactChangeStateProperties'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword properties: Artifact update state properties. + :paramtype properties: ~Microsoft.HybridNetwork.models.ArtifactChangeStateProperties + """ + super(ArtifactChangeState, self).__init__(**kwargs) + self.properties = kwargs.get('properties', None) + + +class ArtifactChangeStateProperties(msrest.serialization.Model): + """The artifact update state properties. + + :ivar artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :vartype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + + _attribute_map = { + 'artifact_state': {'key': 'artifactState', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :paramtype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + super(ArtifactChangeStateProperties, self).__init__(**kwargs) + self.artifact_state = kwargs.get('artifact_state', None) + + +class Resource(msrest.serialization.Model): + """Common fields that are returned in the response for all Azure Resource Manager resources. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(Resource, self).__init__(**kwargs) + self.id = None + self.name = None + self.type = None + self.system_data = None + + +class TrackedResource(Resource): + """The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + """ + super(TrackedResource, self).__init__(**kwargs) + self.tags = kwargs.get('tags', None) + self.location = kwargs['location'] + + +class ArtifactManifest(TrackedResource): + """Artifact manifest properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the ArtifactManifest resource. Possible + values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar artifact_manifest_state: The artifact manifest state. Possible values include: "Unknown", + "Uploading", "Uploaded", "Validating", "ValidationFailed", "Succeeded". + :vartype artifact_manifest_state: str or ~Microsoft.HybridNetwork.models.ArtifactManifestState + :ivar artifacts: The artifacts list. + :vartype artifacts: list[~Microsoft.HybridNetwork.models.ManifestArtifactFormat] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'artifact_manifest_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'artifact_manifest_state': {'key': 'properties.artifactManifestState', 'type': 'str'}, + 'artifacts': {'key': 'properties.artifacts', 'type': '[ManifestArtifactFormat]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword artifacts: The artifacts list. + :paramtype artifacts: list[~Microsoft.HybridNetwork.models.ManifestArtifactFormat] + """ + super(ArtifactManifest, self).__init__(**kwargs) + self.provisioning_state = None + self.artifact_manifest_state = None + self.artifacts = kwargs.get('artifacts', None) + + +class ArtifactManifestListResult(msrest.serialization.Model): + """A list of artifact manifests. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of artifact manifests. + :vartype value: list[~Microsoft.HybridNetwork.models.ArtifactManifest] + :ivar next_link: The URI to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ArtifactManifest]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of artifact manifests. + :paramtype value: list[~Microsoft.HybridNetwork.models.ArtifactManifest] + """ + super(ArtifactManifestListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class ArtifactManifestUpdateState(msrest.serialization.Model): + """The artifact manifest updating request payload. Only the 'Uploaded' state is allowed for updates. Other states are used for internal state transitioning. + + :ivar artifact_manifest_state: The artifact manifest state. Possible values include: "Unknown", + "Uploading", "Uploaded", "Validating", "ValidationFailed", "Succeeded". + :vartype artifact_manifest_state: str or ~Microsoft.HybridNetwork.models.ArtifactManifestState + """ + + _attribute_map = { + 'artifact_manifest_state': {'key': 'artifactManifestState', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_manifest_state: The artifact manifest state. Possible values include: + "Unknown", "Uploading", "Uploaded", "Validating", "ValidationFailed", "Succeeded". + :paramtype artifact_manifest_state: str or + ~Microsoft.HybridNetwork.models.ArtifactManifestState + """ + super(ArtifactManifestUpdateState, self).__init__(**kwargs) + self.artifact_manifest_state = kwargs.get('artifact_manifest_state', None) + + +class ArtifactProfile(msrest.serialization.Model): + """Artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(ArtifactProfile, self).__init__(**kwargs) + self.artifact_store = kwargs.get('artifact_store', None) + + +class ArtifactStore(TrackedResource): + """Artifact store properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the application groups resource. Possible + values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar store_type: The artifact store type. Possible values include: "Unknown", + "AzureContainerRegistry", "AzureStorageAccount". + :vartype store_type: str or ~Microsoft.HybridNetwork.models.ArtifactStoreType + :ivar replication_strategy: The replication strategy. Possible values include: "Unknown", + "SingleReplication", "GeoReplication". + :vartype replication_strategy: str or + ~Microsoft.HybridNetwork.models.ArtifactReplicationStrategy + :ivar managed_resource_group_configuration: + :vartype managed_resource_group_configuration: + ~Microsoft.HybridNetwork.models.ArtifactStorePropertiesFormatManagedResourceGroupConfiguration + :ivar storage_resource_id: The created storage resource id. + :vartype storage_resource_id: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'storage_resource_id': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'store_type': {'key': 'properties.storeType', 'type': 'str'}, + 'replication_strategy': {'key': 'properties.replicationStrategy', 'type': 'str'}, + 'managed_resource_group_configuration': {'key': 'properties.managedResourceGroupConfiguration', 'type': 'ArtifactStorePropertiesFormatManagedResourceGroupConfiguration'}, + 'storage_resource_id': {'key': 'properties.storageResourceId', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword store_type: The artifact store type. Possible values include: "Unknown", + "AzureContainerRegistry", "AzureStorageAccount". + :paramtype store_type: str or ~Microsoft.HybridNetwork.models.ArtifactStoreType + :keyword replication_strategy: The replication strategy. Possible values include: "Unknown", + "SingleReplication", "GeoReplication". + :paramtype replication_strategy: str or + ~Microsoft.HybridNetwork.models.ArtifactReplicationStrategy + :keyword managed_resource_group_configuration: + :paramtype managed_resource_group_configuration: + ~Microsoft.HybridNetwork.models.ArtifactStorePropertiesFormatManagedResourceGroupConfiguration + """ + super(ArtifactStore, self).__init__(**kwargs) + self.provisioning_state = None + self.store_type = kwargs.get('store_type', None) + self.replication_strategy = kwargs.get('replication_strategy', None) + self.managed_resource_group_configuration = kwargs.get('managed_resource_group_configuration', None) + self.storage_resource_id = None + + +class ArtifactStoreListResult(msrest.serialization.Model): + """A list of artifact stores. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of artifact stores. + :vartype value: list[~Microsoft.HybridNetwork.models.ArtifactStore] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ArtifactStore]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of artifact stores. + :paramtype value: list[~Microsoft.HybridNetwork.models.ArtifactStore] + """ + super(ArtifactStoreListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class ArtifactStorePropertiesFormatManagedResourceGroupConfiguration(msrest.serialization.Model): + """ArtifactStorePropertiesFormatManagedResourceGroupConfiguration. + + :ivar name: The managed resource group name. + :vartype name: str + :ivar location: The managed resource group location. + :vartype location: str + """ + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'location': {'key': 'location', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The managed resource group name. + :paramtype name: str + :keyword location: The managed resource group location. + :paramtype location: str + """ + super(ArtifactStorePropertiesFormatManagedResourceGroupConfiguration, self).__init__(**kwargs) + self.name = kwargs.get('name', None) + self.location = kwargs.get('location', None) + + +class NFVIs(msrest.serialization.Model): + """The NFVI object. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureArcK8SClusterNFVIDetails, AzureCoreNFVIDetails, AzureOperatorNexusClusterNFVIDetails. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the nfvi. + :vartype name: str + :ivar nfvi_type: Required. The NFVI type.Constant filled by server. Possible values include: + "Unknown", "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + } + + _subtype_map = { + 'nfvi_type': {'AzureArcKubernetes': 'AzureArcK8SClusterNFVIDetails', 'AzureCore': 'AzureCoreNFVIDetails', 'AzureOperatorNexus': 'AzureOperatorNexusClusterNFVIDetails'} + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: Name of the nfvi. + :paramtype name: str + """ + super(NFVIs, self).__init__(**kwargs) + self.name = kwargs.get('name', None) + self.nfvi_type = None # type: Optional[str] + + +class AzureArcK8SClusterNFVIDetails(NFVIs): + """The AzureArcK8sCluster NFVI detail. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the nfvi. + :vartype name: str + :ivar nfvi_type: Required. The NFVI type.Constant filled by server. Possible values include: + "Unknown", "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :ivar custom_location_reference: The reference to the custom location. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: Name of the nfvi. + :paramtype name: str + :keyword custom_location_reference: The reference to the custom location. + :paramtype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(AzureArcK8SClusterNFVIDetails, self).__init__(**kwargs) + self.nfvi_type = 'AzureArcKubernetes' # type: str + self.custom_location_reference = kwargs.get('custom_location_reference', None) + + +class AzureArcKubernetesArtifactProfile(ArtifactProfile): + """Azure arc kubernetes artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar helm_artifact_profile: Helm artifact profile. + :vartype helm_artifact_profile: ~Microsoft.HybridNetwork.models.HelmArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'helm_artifact_profile': {'key': 'helmArtifactProfile', 'type': 'HelmArtifactProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword helm_artifact_profile: Helm artifact profile. + :paramtype helm_artifact_profile: ~Microsoft.HybridNetwork.models.HelmArtifactProfile + """ + super(AzureArcKubernetesArtifactProfile, self).__init__(**kwargs) + self.helm_artifact_profile = kwargs.get('helm_artifact_profile', None) + + +class MappingRuleProfile(msrest.serialization.Model): + """Mapping rule profile properties. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + """ + super(MappingRuleProfile, self).__init__(**kwargs) + self.application_enablement = kwargs.get('application_enablement', None) + + +class AzureArcKubernetesDeployMappingRuleProfile(MappingRuleProfile): + """Azure arc kubernetes deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar helm_mapping_rule_profile: The helm mapping rule profile. + :vartype helm_mapping_rule_profile: ~Microsoft.HybridNetwork.models.HelmMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'helm_mapping_rule_profile': {'key': 'helmMappingRuleProfile', 'type': 'HelmMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword helm_mapping_rule_profile: The helm mapping rule profile. + :paramtype helm_mapping_rule_profile: ~Microsoft.HybridNetwork.models.HelmMappingRuleProfile + """ + super(AzureArcKubernetesDeployMappingRuleProfile, self).__init__(**kwargs) + self.helm_mapping_rule_profile = kwargs.get('helm_mapping_rule_profile', None) + + +class NetworkFunctionApplication(msrest.serialization.Model): + """Network function application definition. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(NetworkFunctionApplication, self).__init__(**kwargs) + self.name = kwargs.get('name', None) + self.depends_on_profile = kwargs.get('depends_on_profile', None) + + +class AzureArcKubernetesNetworkFunctionApplication(NetworkFunctionApplication): + """Azure arc kubernetes network function application definition. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureArcKubernetesHelmApplication. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "HelmPackage". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureArcKubernetesArtifactType + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + } + + _subtype_map = { + 'artifact_type': {'HelmPackage': 'AzureArcKubernetesHelmApplication'} + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(AzureArcKubernetesNetworkFunctionApplication, self).__init__(**kwargs) + self.artifact_type = 'AzureArcKubernetesNetworkFunctionApplication' # type: str + + +class AzureArcKubernetesHelmApplication(AzureArcKubernetesNetworkFunctionApplication): + """Azure arc kubernetes helm application configurations. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "HelmPackage". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureArcKubernetesArtifactType + :ivar artifact_profile: Azure arc kubernetes artifact profile. + :vartype artifact_profile: ~Microsoft.HybridNetwork.models.AzureArcKubernetesArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureArcKubernetesDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureArcKubernetesArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureArcKubernetesDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure arc kubernetes artifact profile. + :paramtype artifact_profile: ~Microsoft.HybridNetwork.models.AzureArcKubernetesArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureArcKubernetesDeployMappingRuleProfile + """ + super(AzureArcKubernetesHelmApplication, self).__init__(**kwargs) + self.artifact_type = 'HelmPackage' # type: str + self.artifact_profile = kwargs.get('artifact_profile', None) + self.deploy_parameters_mapping_rule_profile = kwargs.get('deploy_parameters_mapping_rule_profile', None) + + +class ContainerizedNetworkFunctionTemplate(msrest.serialization.Model): + """Containerized network function template. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureArcKubernetesNetworkFunctionTemplate. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureArcKubernetes". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.ContainerizedNetworkFunctionNFVIType + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + } + + _subtype_map = { + 'nfvi_type': {'AzureArcKubernetes': 'AzureArcKubernetesNetworkFunctionTemplate'} + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ContainerizedNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = None # type: Optional[str] + + +class AzureArcKubernetesNetworkFunctionTemplate(ContainerizedNetworkFunctionTemplate): + """Azure Arc kubernetes network function template. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureArcKubernetes". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.ContainerizedNetworkFunctionNFVIType + :ivar network_function_applications: Network function applications. + :vartype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureArcKubernetesNetworkFunctionApplication] + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'network_function_applications': {'key': 'networkFunctionApplications', 'type': '[AzureArcKubernetesNetworkFunctionApplication]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword network_function_applications: Network function applications. + :paramtype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureArcKubernetesNetworkFunctionApplication] + """ + super(AzureArcKubernetesNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = 'AzureArcKubernetes' # type: str + self.network_function_applications = kwargs.get('network_function_applications', None) + + +class AzureContainerRegistryScopedTokenCredential(ArtifactAccessCredential): + """The azure container registry scoped token credential definition. + + All required parameters must be populated in order to send to Azure. + + :ivar credential_type: Required. The credential type.Constant filled by server. Possible values + include: "Unknown", "AzureContainerRegistryScopedToken", "AzureStorageAccountToken". + :vartype credential_type: str or ~Microsoft.HybridNetwork.models.CredentialType + :ivar username: The username of the credential. + :vartype username: str + :ivar acr_token: The credential value. + :vartype acr_token: str + :ivar acr_server_url: The Acr server url. + :vartype acr_server_url: str + :ivar repositories: The repositories that could be accessed using the current credential. + :vartype repositories: list[str] + :ivar expiry: The UTC time when credential will expire. + :vartype expiry: ~datetime.datetime + """ + + _validation = { + 'credential_type': {'required': True}, + } + + _attribute_map = { + 'credential_type': {'key': 'credentialType', 'type': 'str'}, + 'username': {'key': 'username', 'type': 'str'}, + 'acr_token': {'key': 'acrToken', 'type': 'str'}, + 'acr_server_url': {'key': 'acrServerUrl', 'type': 'str'}, + 'repositories': {'key': 'repositories', 'type': '[str]'}, + 'expiry': {'key': 'expiry', 'type': 'iso-8601'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword username: The username of the credential. + :paramtype username: str + :keyword acr_token: The credential value. + :paramtype acr_token: str + :keyword acr_server_url: The Acr server url. + :paramtype acr_server_url: str + :keyword repositories: The repositories that could be accessed using the current credential. + :paramtype repositories: list[str] + :keyword expiry: The UTC time when credential will expire. + :paramtype expiry: ~datetime.datetime + """ + super(AzureContainerRegistryScopedTokenCredential, self).__init__(**kwargs) + self.credential_type = 'AzureContainerRegistryScopedToken' # type: str + self.username = kwargs.get('username', None) + self.acr_token = kwargs.get('acr_token', None) + self.acr_server_url = kwargs.get('acr_server_url', None) + self.repositories = kwargs.get('repositories', None) + self.expiry = kwargs.get('expiry', None) + + +class AzureCoreArmTemplateArtifactProfile(ArtifactProfile): + """Azure template artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar template_artifact_profile: Template artifact profile. + :vartype template_artifact_profile: ~Microsoft.HybridNetwork.models.ArmTemplateArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'template_artifact_profile': {'key': 'templateArtifactProfile', 'type': 'ArmTemplateArtifactProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword template_artifact_profile: Template artifact profile. + :paramtype template_artifact_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateArtifactProfile + """ + super(AzureCoreArmTemplateArtifactProfile, self).__init__(**kwargs) + self.template_artifact_profile = kwargs.get('template_artifact_profile', None) + + +class AzureCoreArmTemplateDeployMappingRuleProfile(MappingRuleProfile): + """Azure template deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar template_mapping_rule_profile: The template mapping rule profile. + :vartype template_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'template_mapping_rule_profile': {'key': 'templateMappingRuleProfile', 'type': 'ArmTemplateMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword template_mapping_rule_profile: The template mapping rule profile. + :paramtype template_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateMappingRuleProfile + """ + super(AzureCoreArmTemplateDeployMappingRuleProfile, self).__init__(**kwargs) + self.template_mapping_rule_profile = kwargs.get('template_mapping_rule_profile', None) + + +class AzureCoreDelegatedImageArtifactProfile(ArtifactProfile): + """Azure Image artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar image_artifact_profile: Image artifact profile. + :vartype image_artifact_profile: ~Microsoft.HybridNetwork.models.ImageArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'image_artifact_profile': {'key': 'imageArtifactProfile', 'type': 'ImageArtifactProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword image_artifact_profile: Image artifact profile. + :paramtype image_artifact_profile: ~Microsoft.HybridNetwork.models.ImageArtifactProfile + """ + super(AzureCoreDelegatedImageArtifactProfile, self).__init__(**kwargs) + self.image_artifact_profile = kwargs.get('image_artifact_profile', None) + + +class AzureCoreDelegatedImageDeployMappingRuleProfile(MappingRuleProfile): + """Azure Image deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar image_mapping_rule_profile: The Image mapping rule profile. + :vartype image_mapping_rule_profile: ~Microsoft.HybridNetwork.models.ImageMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'image_mapping_rule_profile': {'key': 'imageMappingRuleProfile', 'type': 'ImageMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword image_mapping_rule_profile: The Image mapping rule profile. + :paramtype image_mapping_rule_profile: ~Microsoft.HybridNetwork.models.ImageMappingRuleProfile + """ + super(AzureCoreDelegatedImageDeployMappingRuleProfile, self).__init__(**kwargs) + self.image_mapping_rule_profile = kwargs.get('image_mapping_rule_profile', None) + + +class AzureCoreDelegatedNetworkFunctionApplication(NetworkFunctionApplication): + """Azure delegated network function application definition. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureCoreDelegatedNetworkFunctionImageApplication. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "ImageFile". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureCoreDelegatedArtifactType + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + } + + _subtype_map = { + 'artifact_type': {'ImageFile': 'AzureCoreDelegatedNetworkFunctionImageApplication'} + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(AzureCoreDelegatedNetworkFunctionApplication, self).__init__(**kwargs) + self.artifact_type = 'AzureCoreDelegatedNetworkFunctionApplication' # type: str + + +class AzureCoreDelegatedNetworkFunctionImageApplication(AzureCoreDelegatedNetworkFunctionApplication): + """Azure core network function Image application definition. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "ImageFile". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureCoreDelegatedArtifactType + :ivar artifact_profile: Azure Image artifact profile. + :vartype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureCoreDelegatedImageArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreDelegatedImageDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureCoreDelegatedImageArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreDelegatedImageDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure Image artifact profile. + :paramtype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureCoreDelegatedImageArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreDelegatedImageDeployMappingRuleProfile + """ + super(AzureCoreDelegatedNetworkFunctionImageApplication, self).__init__(**kwargs) + self.artifact_type = 'ImageFile' # type: str + self.artifact_profile = kwargs.get('artifact_profile', None) + self.deploy_parameters_mapping_rule_profile = kwargs.get('deploy_parameters_mapping_rule_profile', None) + + +class DelegatedNetworkFunctionTemplate(msrest.serialization.Model): + """Delegated network function template. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureCoreDelegatedNetworkFunctionTemplate. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureCore". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.DelegatedNetworkFunctionNFVIType + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + } + + _subtype_map = { + 'nfvi_type': {'AzureCore': 'AzureCoreDelegatedNetworkFunctionTemplate'} + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(DelegatedNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = None # type: Optional[str] + + +class AzureCoreDelegatedNetworkFunctionTemplate(DelegatedNetworkFunctionTemplate): + """Azure delegated network function template. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureCore". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.DelegatedNetworkFunctionNFVIType + :ivar network_function_applications: Network function applications. + :vartype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureCoreDelegatedNetworkFunctionApplication] + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'network_function_applications': {'key': 'networkFunctionApplications', 'type': '[AzureCoreDelegatedNetworkFunctionApplication]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword network_function_applications: Network function applications. + :paramtype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureCoreDelegatedNetworkFunctionApplication] + """ + super(AzureCoreDelegatedNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = 'AzureCore' # type: str + self.network_function_applications = kwargs.get('network_function_applications', None) + + +class AzureCoreNetworkFunctionApplication(NetworkFunctionApplication): + """Azure virtual network function application definition. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureCoreNetworkFunctionArmTemplateApplication, AzureCoreNetworkFunctionVhdApplication. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "VhdImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureCoreArtifactType + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + } + + _subtype_map = { + 'artifact_type': {'ArmTemplate': 'AzureCoreNetworkFunctionArmTemplateApplication', 'VhdImageFile': 'AzureCoreNetworkFunctionVhdApplication'} + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(AzureCoreNetworkFunctionApplication, self).__init__(**kwargs) + self.artifact_type = 'AzureCoreNetworkFunctionApplication' # type: str + + +class AzureCoreNetworkFunctionArmTemplateApplication(AzureCoreNetworkFunctionApplication): + """Azure core network function Template application definition. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "VhdImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureCoreArtifactType + :ivar artifact_profile: Azure template artifact profile. + :vartype artifact_profile: ~Microsoft.HybridNetwork.models.AzureCoreArmTemplateArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreArmTemplateDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureCoreArmTemplateArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreArmTemplateDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure template artifact profile. + :paramtype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureCoreArmTemplateArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreArmTemplateDeployMappingRuleProfile + """ + super(AzureCoreNetworkFunctionArmTemplateApplication, self).__init__(**kwargs) + self.artifact_type = 'ArmTemplate' # type: str + self.artifact_profile = kwargs.get('artifact_profile', None) + self.deploy_parameters_mapping_rule_profile = kwargs.get('deploy_parameters_mapping_rule_profile', None) + + +class VirtualNetworkFunctionTemplate(msrest.serialization.Model): + """Virtual network function template. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureCoreNetworkFunctionTemplate, AzureOperatorNexusNetworkFunctionTemplate. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.VirtualNetworkFunctionNFVIType + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + } + + _subtype_map = { + 'nfvi_type': {'AzureCore': 'AzureCoreNetworkFunctionTemplate', 'AzureOperatorNexus': 'AzureOperatorNexusNetworkFunctionTemplate'} + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(VirtualNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = None # type: Optional[str] + + +class AzureCoreNetworkFunctionTemplate(VirtualNetworkFunctionTemplate): + """Azure virtual network function template. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.VirtualNetworkFunctionNFVIType + :ivar network_function_applications: Network function applications. + :vartype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureCoreNetworkFunctionApplication] + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'network_function_applications': {'key': 'networkFunctionApplications', 'type': '[AzureCoreNetworkFunctionApplication]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword network_function_applications: Network function applications. + :paramtype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureCoreNetworkFunctionApplication] + """ + super(AzureCoreNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = 'AzureCore' # type: str + self.network_function_applications = kwargs.get('network_function_applications', None) + + +class AzureCoreNetworkFunctionVhdApplication(AzureCoreNetworkFunctionApplication): + """Azure core network function vhd application definition. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "VhdImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureCoreArtifactType + :ivar artifact_profile: Azure vhd image artifact profile. + :vartype artifact_profile: ~Microsoft.HybridNetwork.models.AzureCoreVhdImageArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreVhdImageDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureCoreVhdImageArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreVhdImageDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure vhd image artifact profile. + :paramtype artifact_profile: ~Microsoft.HybridNetwork.models.AzureCoreVhdImageArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreVhdImageDeployMappingRuleProfile + """ + super(AzureCoreNetworkFunctionVhdApplication, self).__init__(**kwargs) + self.artifact_type = 'VhdImageFile' # type: str + self.artifact_profile = kwargs.get('artifact_profile', None) + self.deploy_parameters_mapping_rule_profile = kwargs.get('deploy_parameters_mapping_rule_profile', None) + + +class AzureCoreNFVIDetails(NFVIs): + """The Azure Core NFVI detail. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the nfvi. + :vartype name: str + :ivar nfvi_type: Required. The NFVI type.Constant filled by server. Possible values include: + "Unknown", "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :ivar location: Location of the Azure core. + :vartype location: str + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'location': {'key': 'location', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: Name of the nfvi. + :paramtype name: str + :keyword location: Location of the Azure core. + :paramtype location: str + """ + super(AzureCoreNFVIDetails, self).__init__(**kwargs) + self.nfvi_type = 'AzureCore' # type: str + self.location = kwargs.get('location', None) + + +class AzureCoreVhdImageArtifactProfile(ArtifactProfile): + """Azure vhd artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar vhd_artifact_profile: Vhd artifact profile. + :vartype vhd_artifact_profile: ~Microsoft.HybridNetwork.models.VhdImageArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'vhd_artifact_profile': {'key': 'vhdArtifactProfile', 'type': 'VhdImageArtifactProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword vhd_artifact_profile: Vhd artifact profile. + :paramtype vhd_artifact_profile: ~Microsoft.HybridNetwork.models.VhdImageArtifactProfile + """ + super(AzureCoreVhdImageArtifactProfile, self).__init__(**kwargs) + self.vhd_artifact_profile = kwargs.get('vhd_artifact_profile', None) + + +class AzureCoreVhdImageDeployMappingRuleProfile(MappingRuleProfile): + """Azure vhd deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar vhd_image_mapping_rule_profile: The vhd mapping rule profile. + :vartype vhd_image_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.VhdImageMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'vhd_image_mapping_rule_profile': {'key': 'vhdImageMappingRuleProfile', 'type': 'VhdImageMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword vhd_image_mapping_rule_profile: The vhd mapping rule profile. + :paramtype vhd_image_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.VhdImageMappingRuleProfile + """ + super(AzureCoreVhdImageDeployMappingRuleProfile, self).__init__(**kwargs) + self.vhd_image_mapping_rule_profile = kwargs.get('vhd_image_mapping_rule_profile', None) + + +class AzureKubernetesServiceNetworkFunctionReadyK8S(NetworkFunctionReadyK8SPropertiesFormat): + """Azure based kubernetes service cluster prerequisite properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the NetworkFunctionReadyK8s resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar cluster_type: Required. The cluster type.Constant filled by server. Possible values + include: "AzureKubernetesService", "ArcConnectedK8s", "HybridAKS". + :vartype cluster_type: str or ~Microsoft.HybridNetwork.models.ClusterType + :ivar cluster_reference: Required. The k8s/Connected cluster ARM id. + :vartype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar custom_location_reference: The read only custom location ARM id. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar user_assigned_managed_identity: Required. The User Assigned Managed Identity ARM id + enabled on the AKS cluster. + :vartype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'cluster_type': {'required': True}, + 'cluster_reference': {'required': True}, + 'custom_location_reference': {'readonly': True}, + 'user_assigned_managed_identity': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'cluster_type': {'key': 'clusterType', 'type': 'str'}, + 'cluster_reference': {'key': 'clusterReference', 'type': 'ReferencedResource'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + 'user_assigned_managed_identity': {'key': 'userAssignedManagedIdentity', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword cluster_reference: Required. The k8s/Connected cluster ARM id. + :paramtype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword user_assigned_managed_identity: Required. The User Assigned Managed Identity ARM id + enabled on the AKS cluster. + :paramtype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(AzureKubernetesServiceNetworkFunctionReadyK8S, self).__init__(**kwargs) + self.cluster_type = 'AzureKubernetesService' # type: str + self.user_assigned_managed_identity = kwargs['user_assigned_managed_identity'] + + +class AzureOperatorNexusArmTemplateArtifactProfile(ArtifactProfile): + """Azure Operator Distributed Services vhd artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar template_artifact_profile: Template artifact profile. + :vartype template_artifact_profile: ~Microsoft.HybridNetwork.models.ArmTemplateArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'template_artifact_profile': {'key': 'templateArtifactProfile', 'type': 'ArmTemplateArtifactProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword template_artifact_profile: Template artifact profile. + :paramtype template_artifact_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateArtifactProfile + """ + super(AzureOperatorNexusArmTemplateArtifactProfile, self).__init__(**kwargs) + self.template_artifact_profile = kwargs.get('template_artifact_profile', None) + + +class AzureOperatorNexusArmTemplateDeployMappingRuleProfile(MappingRuleProfile): + """Azure Operator Distributed Services template deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar template_mapping_rule_profile: The template mapping rule profile. + :vartype template_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'template_mapping_rule_profile': {'key': 'templateMappingRuleProfile', 'type': 'ArmTemplateMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword template_mapping_rule_profile: The template mapping rule profile. + :paramtype template_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateMappingRuleProfile + """ + super(AzureOperatorNexusArmTemplateDeployMappingRuleProfile, self).__init__(**kwargs) + self.template_mapping_rule_profile = kwargs.get('template_mapping_rule_profile', None) + + +class AzureOperatorNexusClusterNFVIDetails(NFVIs): + """The AzureOperatorNexusCluster NFVI detail. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the nfvi. + :vartype name: str + :ivar nfvi_type: Required. The NFVI type.Constant filled by server. Possible values include: + "Unknown", "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :ivar custom_location_reference: The reference to the custom location. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: Name of the nfvi. + :paramtype name: str + :keyword custom_location_reference: The reference to the custom location. + :paramtype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(AzureOperatorNexusClusterNFVIDetails, self).__init__(**kwargs) + self.nfvi_type = 'AzureOperatorNexus' # type: str + self.custom_location_reference = kwargs.get('custom_location_reference', None) + + +class AzureOperatorNexusImageArtifactProfile(ArtifactProfile): + """Azure Operator Distributed Services image artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar image_artifact_profile: Image artifact profile. + :vartype image_artifact_profile: ~Microsoft.HybridNetwork.models.ImageArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'image_artifact_profile': {'key': 'imageArtifactProfile', 'type': 'ImageArtifactProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword image_artifact_profile: Image artifact profile. + :paramtype image_artifact_profile: ~Microsoft.HybridNetwork.models.ImageArtifactProfile + """ + super(AzureOperatorNexusImageArtifactProfile, self).__init__(**kwargs) + self.image_artifact_profile = kwargs.get('image_artifact_profile', None) + + +class AzureOperatorNexusImageDeployMappingRuleProfile(MappingRuleProfile): + """Azure Operator Distributed Services image deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar image_mapping_rule_profile: The vhd mapping rule profile. + :vartype image_mapping_rule_profile: ~Microsoft.HybridNetwork.models.ImageMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'image_mapping_rule_profile': {'key': 'imageMappingRuleProfile', 'type': 'ImageMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword image_mapping_rule_profile: The vhd mapping rule profile. + :paramtype image_mapping_rule_profile: ~Microsoft.HybridNetwork.models.ImageMappingRuleProfile + """ + super(AzureOperatorNexusImageDeployMappingRuleProfile, self).__init__(**kwargs) + self.image_mapping_rule_profile = kwargs.get('image_mapping_rule_profile', None) + + +class AzureOperatorNexusNetworkFunctionApplication(NetworkFunctionApplication): + """Azure Operator Distributed Services network function application definition. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureOperatorNexusNetworkFunctionArmTemplateApplication, AzureOperatorNexusNetworkFunctionImageApplication. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "ImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureOperatorNexusArtifactType + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + } + + _subtype_map = { + 'artifact_type': {'ArmTemplate': 'AzureOperatorNexusNetworkFunctionArmTemplateApplication', 'ImageFile': 'AzureOperatorNexusNetworkFunctionImageApplication'} + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(AzureOperatorNexusNetworkFunctionApplication, self).__init__(**kwargs) + self.artifact_type = 'AzureOperatorNexusNetworkFunctionApplication' # type: str + + +class AzureOperatorNexusNetworkFunctionArmTemplateApplication(AzureOperatorNexusNetworkFunctionApplication): + """Azure Operator Distributed Services network function Template application definition. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "ImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureOperatorNexusArtifactType + :ivar artifact_profile: Azure Operator Distributed Services Template artifact profile. + :vartype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusArmTemplateArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusArmTemplateDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureOperatorNexusArmTemplateArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureOperatorNexusArmTemplateDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure Operator Distributed Services Template artifact profile. + :paramtype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusArmTemplateArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusArmTemplateDeployMappingRuleProfile + """ + super(AzureOperatorNexusNetworkFunctionArmTemplateApplication, self).__init__(**kwargs) + self.artifact_type = 'ArmTemplate' # type: str + self.artifact_profile = kwargs.get('artifact_profile', None) + self.deploy_parameters_mapping_rule_profile = kwargs.get('deploy_parameters_mapping_rule_profile', None) + + +class AzureOperatorNexusNetworkFunctionImageApplication(AzureOperatorNexusNetworkFunctionApplication): + """Azure Operator Distributed Services network function image application definition. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "ImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureOperatorNexusArtifactType + :ivar artifact_profile: Azure Operator Distributed Services image artifact profile. + :vartype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusImageArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusImageDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureOperatorNexusImageArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureOperatorNexusImageDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure Operator Distributed Services image artifact profile. + :paramtype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusImageArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusImageDeployMappingRuleProfile + """ + super(AzureOperatorNexusNetworkFunctionImageApplication, self).__init__(**kwargs) + self.artifact_type = 'ImageFile' # type: str + self.artifact_profile = kwargs.get('artifact_profile', None) + self.deploy_parameters_mapping_rule_profile = kwargs.get('deploy_parameters_mapping_rule_profile', None) + + +class AzureOperatorNexusNetworkFunctionTemplate(VirtualNetworkFunctionTemplate): + """Azure Operator Distributed Services network function template. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.VirtualNetworkFunctionNFVIType + :ivar network_function_applications: Network function applications. + :vartype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureOperatorNexusNetworkFunctionApplication] + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'network_function_applications': {'key': 'networkFunctionApplications', 'type': '[AzureOperatorNexusNetworkFunctionApplication]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword network_function_applications: Network function applications. + :paramtype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureOperatorNexusNetworkFunctionApplication] + """ + super(AzureOperatorNexusNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = 'AzureOperatorNexus' # type: str + self.network_function_applications = kwargs.get('network_function_applications', None) + + +class AzureStorageAccountContainerCredential(msrest.serialization.Model): + """The azure storage account container credential definition. + + :ivar container_name: The storage account container name. + :vartype container_name: str + :ivar container_sas_uri: The storage account container sas uri. + :vartype container_sas_uri: str + """ + + _attribute_map = { + 'container_name': {'key': 'containerName', 'type': 'str'}, + 'container_sas_uri': {'key': 'containerSasUri', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword container_name: The storage account container name. + :paramtype container_name: str + :keyword container_sas_uri: The storage account container sas uri. + :paramtype container_sas_uri: str + """ + super(AzureStorageAccountContainerCredential, self).__init__(**kwargs) + self.container_name = kwargs.get('container_name', None) + self.container_sas_uri = kwargs.get('container_sas_uri', None) + + +class AzureStorageAccountCredential(ArtifactAccessCredential): + """The azure storage account credential definition. + + All required parameters must be populated in order to send to Azure. + + :ivar credential_type: Required. The credential type.Constant filled by server. Possible values + include: "Unknown", "AzureContainerRegistryScopedToken", "AzureStorageAccountToken". + :vartype credential_type: str or ~Microsoft.HybridNetwork.models.CredentialType + :ivar storage_account_id: The storage account Id. + :vartype storage_account_id: str + :ivar container_credentials: The containers that could be accessed using the current + credential. + :vartype container_credentials: + list[~Microsoft.HybridNetwork.models.AzureStorageAccountContainerCredential] + :ivar expiry: The UTC time when credential will expire. + :vartype expiry: ~datetime.datetime + """ + + _validation = { + 'credential_type': {'required': True}, + } + + _attribute_map = { + 'credential_type': {'key': 'credentialType', 'type': 'str'}, + 'storage_account_id': {'key': 'storageAccountId', 'type': 'str'}, + 'container_credentials': {'key': 'containerCredentials', 'type': '[AzureStorageAccountContainerCredential]'}, + 'expiry': {'key': 'expiry', 'type': 'iso-8601'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword storage_account_id: The storage account Id. + :paramtype storage_account_id: str + :keyword container_credentials: The containers that could be accessed using the current + credential. + :paramtype container_credentials: + list[~Microsoft.HybridNetwork.models.AzureStorageAccountContainerCredential] + :keyword expiry: The UTC time when credential will expire. + :paramtype expiry: ~datetime.datetime + """ + super(AzureStorageAccountCredential, self).__init__(**kwargs) + self.credential_type = 'AzureStorageAccountToken' # type: str + self.storage_account_id = kwargs.get('storage_account_id', None) + self.container_credentials = kwargs.get('container_credentials', None) + self.expiry = kwargs.get('expiry', None) + + +class ProxyResource(Resource): + """The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ProxyResource, self).__init__(**kwargs) + + +class Component(ProxyResource): + """The component sub resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar provisioning_state: The provisioning state of the component resource. Possible values + include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", "Deleted", + "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar deployment_profile: The JSON-serialized deployment profile of the component resource. + :vartype deployment_profile: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'provisioning_state': {'readonly': True}, + 'deployment_profile': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'deployment_profile': {'key': 'properties.deploymentProfile', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(Component, self).__init__(**kwargs) + self.provisioning_state = None + self.deployment_profile = None + + +class ComponentListResult(msrest.serialization.Model): + """Response for list component API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of component resources in a networkFunction. + :vartype value: list[~Microsoft.HybridNetwork.models.Component] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[Component]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of component resources in a networkFunction. + :paramtype value: list[~Microsoft.HybridNetwork.models.Component] + """ + super(ComponentListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class ConfigurationDefinitionResourceElementTemplate(msrest.serialization.Model): + """The configuration definition resource element template details. + + :ivar name: The name of the network function to apply the configuration to. + :vartype name: str + :ivar nf_agent_type: The type of NF agent that should handle this configuration. + :vartype nf_agent_type: str + :ivar configuration_type: The type of configuration to be handled by the NF agent. + :vartype configuration_type: str + :ivar configuration_generation_type: The configuration generation type. Possible values + include: "Unknown", "HandlebarTemplate". + :vartype configuration_generation_type: str or + ~Microsoft.HybridNetwork.models.ConfigurationGenerationType + :ivar parameter_values: Name and value pairs that define the parameter values. It can be a well + formed escaped JSON string. + :vartype parameter_values: str + :ivar artifact_profile: Artifact profile properties. + :vartype artifact_profile: ~Microsoft.HybridNetwork.models.NSDArtifactProfile + :ivar extra_artifact_profiles: List of extra artifact profiles required by the configuration. + :vartype extra_artifact_profiles: list[~Microsoft.HybridNetwork.models.NSDArtifactProfile] + """ + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'nf_agent_type': {'key': 'nfAgentType', 'type': 'str'}, + 'configuration_type': {'key': 'configurationType', 'type': 'str'}, + 'configuration_generation_type': {'key': 'configurationGenerationType', 'type': 'str'}, + 'parameter_values': {'key': 'parameterValues', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'NSDArtifactProfile'}, + 'extra_artifact_profiles': {'key': 'extraArtifactProfiles', 'type': '[NSDArtifactProfile]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The name of the network function to apply the configuration to. + :paramtype name: str + :keyword nf_agent_type: The type of NF agent that should handle this configuration. + :paramtype nf_agent_type: str + :keyword configuration_type: The type of configuration to be handled by the NF agent. + :paramtype configuration_type: str + :keyword configuration_generation_type: The configuration generation type. Possible values + include: "Unknown", "HandlebarTemplate". + :paramtype configuration_generation_type: str or + ~Microsoft.HybridNetwork.models.ConfigurationGenerationType + :keyword parameter_values: Name and value pairs that define the parameter values. It can be a + well formed escaped JSON string. + :paramtype parameter_values: str + :keyword artifact_profile: Artifact profile properties. + :paramtype artifact_profile: ~Microsoft.HybridNetwork.models.NSDArtifactProfile + :keyword extra_artifact_profiles: List of extra artifact profiles required by the + configuration. + :paramtype extra_artifact_profiles: list[~Microsoft.HybridNetwork.models.NSDArtifactProfile] + """ + super(ConfigurationDefinitionResourceElementTemplate, self).__init__(**kwargs) + self.name = kwargs.get('name', None) + self.nf_agent_type = kwargs.get('nf_agent_type', None) + self.configuration_type = kwargs.get('configuration_type', None) + self.configuration_generation_type = kwargs.get('configuration_generation_type', None) + self.parameter_values = kwargs.get('parameter_values', None) + self.artifact_profile = kwargs.get('artifact_profile', None) + self.extra_artifact_profiles = kwargs.get('extra_artifact_profiles', None) + + +class ConfigurationDefinitionResourceElementTemplateDetails(ResourceElementTemplate): + """The configuration definition resource element template details. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the resource element template. + :vartype name: str + :ivar type: Required. The resource element template type.Constant filled by server. Possible + values include: "Unknown", "ArmResourceDefinition", "ConfigurationDefinition", + "NetworkFunctionDefinition". + :vartype type: str or ~Microsoft.HybridNetwork.models.Type + :ivar depends_on_profile: The depends on profile. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar configuration: The resource element template type. + :vartype configuration: + ~Microsoft.HybridNetwork.models.ConfigurationDefinitionResourceElementTemplate + """ + + _validation = { + 'type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'configuration': {'key': 'configuration', 'type': 'ConfigurationDefinitionResourceElementTemplate'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: Name of the resource element template. + :paramtype name: str + :keyword depends_on_profile: The depends on profile. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword configuration: The resource element template type. + :paramtype configuration: + ~Microsoft.HybridNetwork.models.ConfigurationDefinitionResourceElementTemplate + """ + super(ConfigurationDefinitionResourceElementTemplateDetails, self).__init__(**kwargs) + self.type = 'ConfigurationDefinition' # type: str + self.configuration = kwargs.get('configuration', None) + + +class ConfigurationGroupSchema(TrackedResource): + """Configuration group schema resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the Configuration group schema resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The configuration group schema version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar schema_definition: Name and value pairs that define the configuration value. It can be a + well formed escaped JSON string. + :vartype schema_definition: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'version_state': {'key': 'properties.versionState', 'type': 'str'}, + 'schema_definition': {'key': 'properties.schemaDefinition', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword schema_definition: Name and value pairs that define the configuration value. It can be + a well formed escaped JSON string. + :paramtype schema_definition: str + """ + super(ConfigurationGroupSchema, self).__init__(**kwargs) + self.provisioning_state = None + self.version_state = None + self.schema_definition = kwargs.get('schema_definition', None) + + +class ConfigurationGroupSchemaListResult(msrest.serialization.Model): + """A list of configuration group schema resources. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of configuration group schema. + :vartype value: list[~Microsoft.HybridNetwork.models.ConfigurationGroupSchema] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ConfigurationGroupSchema]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of configuration group schema. + :paramtype value: list[~Microsoft.HybridNetwork.models.ConfigurationGroupSchema] + """ + super(ConfigurationGroupSchemaListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class ConfigurationGroupSchemaVersionUpdateState(msrest.serialization.Model): + """Publisher configuration group schema update request definition. + + :ivar version_state: The configuration group schema state. Possible values include: "Unknown", + "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + + _attribute_map = { + 'version_state': {'key': 'versionState', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword version_state: The configuration group schema state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :paramtype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + super(ConfigurationGroupSchemaVersionUpdateState, self).__init__(**kwargs) + self.version_state = kwargs.get('version_state', None) + + +class ConfigurationGroupValue(TrackedResource): + """Hybrid configuration group value resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the site resource. Possible values include: + "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar publisher_name: The publisher name for the configuration group schema. + :vartype publisher_name: str + :ivar publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :vartype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :ivar configuration_group_schema_name: The configuration group schema name. + :vartype configuration_group_schema_name: str + :ivar configuration_group_schema_offering_location: The location of the configuration group + schema offering. + :vartype configuration_group_schema_offering_location: str + :ivar configuration_value: Name and value pairs that define the configuration value. It can be + a well formed escaped JSON string. + :vartype configuration_value: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'publisher_name': {'key': 'properties.publisherName', 'type': 'str'}, + 'publisher_scope': {'key': 'properties.publisherScope', 'type': 'str'}, + 'configuration_group_schema_name': {'key': 'properties.configurationGroupSchemaName', 'type': 'str'}, + 'configuration_group_schema_offering_location': {'key': 'properties.configurationGroupSchemaOfferingLocation', 'type': 'str'}, + 'configuration_value': {'key': 'properties.configurationValue', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword publisher_name: The publisher name for the configuration group schema. + :paramtype publisher_name: str + :keyword publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :paramtype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :keyword configuration_group_schema_name: The configuration group schema name. + :paramtype configuration_group_schema_name: str + :keyword configuration_group_schema_offering_location: The location of the configuration group + schema offering. + :paramtype configuration_group_schema_offering_location: str + :keyword configuration_value: Name and value pairs that define the configuration value. It can + be a well formed escaped JSON string. + :paramtype configuration_value: str + """ + super(ConfigurationGroupValue, self).__init__(**kwargs) + self.provisioning_state = None + self.publisher_name = kwargs.get('publisher_name', None) + self.publisher_scope = kwargs.get('publisher_scope', None) + self.configuration_group_schema_name = kwargs.get('configuration_group_schema_name', None) + self.configuration_group_schema_offering_location = kwargs.get('configuration_group_schema_offering_location', None) + self.configuration_value = kwargs.get('configuration_value', None) + + +class ConfigurationGroupValueListResult(msrest.serialization.Model): + """Response for hybrid configurationGroups API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of hybrid configurationGroups. + :vartype value: list[~Microsoft.HybridNetwork.models.ConfigurationGroupValue] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ConfigurationGroupValue]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of hybrid configurationGroups. + :paramtype value: list[~Microsoft.HybridNetwork.models.ConfigurationGroupValue] + """ + super(ConfigurationGroupValueListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class NetworkFunctionDefinitionVersionPropertiesFormat(msrest.serialization.Model): + """Network function definition version properties. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: ContainerizedNetworkFunctionDefinitionVersion, DelegatedNetworkFunctionDefinitionVersion, VirtualNetworkFunctionDefinitionVersion. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the network function definition version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network function definition version description. + :vartype description: str + :ivar deploy_parameters: The deployment parameters of the network function definition version. + :vartype deploy_parameters: str + :ivar network_function_type: Required. The network function type.Constant filled by server. + Possible values include: "Unknown", "VirtualNetworkFunction", "ContainerizedNetworkFunction", + "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + 'network_function_type': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'version_state': {'key': 'versionState', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + 'deploy_parameters': {'key': 'deployParameters', 'type': 'str'}, + 'network_function_type': {'key': 'networkFunctionType', 'type': 'str'}, + } + + _subtype_map = { + 'network_function_type': {'ContainerizedNetworkFunction': 'ContainerizedNetworkFunctionDefinitionVersion', 'DelegatedNetworkFunction': 'DelegatedNetworkFunctionDefinitionVersion', 'VirtualNetworkFunction': 'VirtualNetworkFunctionDefinitionVersion'} + } + + def __init__( + self, + **kwargs + ): + """ + :keyword description: The network function definition version description. + :paramtype description: str + :keyword deploy_parameters: The deployment parameters of the network function definition + version. + :paramtype deploy_parameters: str + """ + super(NetworkFunctionDefinitionVersionPropertiesFormat, self).__init__(**kwargs) + self.provisioning_state = None + self.version_state = None + self.description = kwargs.get('description', None) + self.deploy_parameters = kwargs.get('deploy_parameters', None) + self.network_function_type = None # type: Optional[str] + + +class ContainerizedNetworkFunctionDefinitionVersion(NetworkFunctionDefinitionVersionPropertiesFormat): + """Containerized network function network function definition version properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the network function definition version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network function definition version description. + :vartype description: str + :ivar deploy_parameters: The deployment parameters of the network function definition version. + :vartype deploy_parameters: str + :ivar network_function_type: Required. The network function type.Constant filled by server. + Possible values include: "Unknown", "VirtualNetworkFunction", "ContainerizedNetworkFunction", + "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + :ivar network_function_template: Containerized network function template. + :vartype network_function_template: + ~Microsoft.HybridNetwork.models.ContainerizedNetworkFunctionTemplate + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + 'network_function_type': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'version_state': {'key': 'versionState', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + 'deploy_parameters': {'key': 'deployParameters', 'type': 'str'}, + 'network_function_type': {'key': 'networkFunctionType', 'type': 'str'}, + 'network_function_template': {'key': 'networkFunctionTemplate', 'type': 'ContainerizedNetworkFunctionTemplate'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword description: The network function definition version description. + :paramtype description: str + :keyword deploy_parameters: The deployment parameters of the network function definition + version. + :paramtype deploy_parameters: str + :keyword network_function_template: Containerized network function template. + :paramtype network_function_template: + ~Microsoft.HybridNetwork.models.ContainerizedNetworkFunctionTemplate + """ + super(ContainerizedNetworkFunctionDefinitionVersion, self).__init__(**kwargs) + self.network_function_type = 'ContainerizedNetworkFunction' # type: str + self.network_function_template = kwargs.get('network_function_template', None) + + +class CustomLocationResourceId(msrest.serialization.Model): + """Reference to an Azure ARC custom location resource. + + :ivar id: Azure ARC custom location resource ID. + :vartype id: str + """ + + _validation = { + 'id': {'pattern': r'^/[sS][uU][bB][sS][cC][rR][iI][pP][tT][iI][oO][nN][sS]/[^/?#]+/[rR][eE][sS][oO][uU][rR][cC][eE][gG][rR][oO][uU][pP][sS]/[^/?#]+/[pP][rR][oO][vV][iI][dD][eE][rR][sS]/[mM][iI][cC][rR][oO][sS][oO][fF][tT]\.[eE][xX][tT][eE][nN][dD][eE][dD][lL][oO][cC][aA][tT][iI][oO][nN]/[cC][uU][sS][tT][oO][mM][lL][oO][cC][aA][tT][iI][oO][nN][sS]/[^/?#]+$'}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword id: Azure ARC custom location resource ID. + :paramtype id: str + """ + super(CustomLocationResourceId, self).__init__(**kwargs) + self.id = kwargs.get('id', None) + + +class DelegatedNetworkFunctionDefinitionVersion(NetworkFunctionDefinitionVersionPropertiesFormat): + """Delegated network function network function definition version properties . + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the network function definition version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network function definition version description. + :vartype description: str + :ivar deploy_parameters: The deployment parameters of the network function definition version. + :vartype deploy_parameters: str + :ivar network_function_type: Required. The network function type.Constant filled by server. + Possible values include: "Unknown", "VirtualNetworkFunction", "ContainerizedNetworkFunction", + "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + :ivar network_function_template: Delegated network function template. + :vartype network_function_template: + ~Microsoft.HybridNetwork.models.DelegatedNetworkFunctionTemplate + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + 'network_function_type': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'version_state': {'key': 'versionState', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + 'deploy_parameters': {'key': 'deployParameters', 'type': 'str'}, + 'network_function_type': {'key': 'networkFunctionType', 'type': 'str'}, + 'network_function_template': {'key': 'networkFunctionTemplate', 'type': 'DelegatedNetworkFunctionTemplate'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword description: The network function definition version description. + :paramtype description: str + :keyword deploy_parameters: The deployment parameters of the network function definition + version. + :paramtype deploy_parameters: str + :keyword network_function_template: Delegated network function template. + :paramtype network_function_template: + ~Microsoft.HybridNetwork.models.DelegatedNetworkFunctionTemplate + """ + super(DelegatedNetworkFunctionDefinitionVersion, self).__init__(**kwargs) + self.network_function_type = 'DelegatedNetworkFunction' # type: str + self.network_function_template = kwargs.get('network_function_template', None) + + +class DependsOnProfile(msrest.serialization.Model): + """Depends on profile definition. + + :ivar install_depends_on: Application installation operation dependency. + :vartype install_depends_on: list[str] + :ivar uninstall_depends_on: Application deletion operation dependency. + :vartype uninstall_depends_on: list[str] + :ivar update_depends_on: Application update operation dependency. + :vartype update_depends_on: list[str] + """ + + _attribute_map = { + 'install_depends_on': {'key': 'installDependsOn', 'type': '[str]'}, + 'uninstall_depends_on': {'key': 'uninstallDependsOn', 'type': '[str]'}, + 'update_depends_on': {'key': 'updateDependsOn', 'type': '[str]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword install_depends_on: Application installation operation dependency. + :paramtype install_depends_on: list[str] + :keyword uninstall_depends_on: Application deletion operation dependency. + :paramtype uninstall_depends_on: list[str] + :keyword update_depends_on: Application update operation dependency. + :paramtype update_depends_on: list[str] + """ + super(DependsOnProfile, self).__init__(**kwargs) + self.install_depends_on = kwargs.get('install_depends_on', None) + self.uninstall_depends_on = kwargs.get('uninstall_depends_on', None) + self.update_depends_on = kwargs.get('update_depends_on', None) + + +class ErrorAdditionalInfo(msrest.serialization.Model): + """The resource management error additional info. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar type: The additional info type. + :vartype type: str + :ivar info: The additional info. + :vartype info: any + """ + + _validation = { + 'type': {'readonly': True}, + 'info': {'readonly': True}, + } + + _attribute_map = { + 'type': {'key': 'type', 'type': 'str'}, + 'info': {'key': 'info', 'type': 'object'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ErrorAdditionalInfo, self).__init__(**kwargs) + self.type = None + self.info = None + + +class ErrorDetail(msrest.serialization.Model): + """The error detail. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar code: The error code. + :vartype code: str + :ivar message: The error message. + :vartype message: str + :ivar target: The error target. + :vartype target: str + :ivar details: The error details. + :vartype details: list[~Microsoft.HybridNetwork.models.ErrorDetail] + :ivar additional_info: The error additional info. + :vartype additional_info: list[~Microsoft.HybridNetwork.models.ErrorAdditionalInfo] + """ + + _validation = { + 'code': {'readonly': True}, + 'message': {'readonly': True}, + 'target': {'readonly': True}, + 'details': {'readonly': True}, + 'additional_info': {'readonly': True}, + } + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + 'target': {'key': 'target', 'type': 'str'}, + 'details': {'key': 'details', 'type': '[ErrorDetail]'}, + 'additional_info': {'key': 'additionalInfo', 'type': '[ErrorAdditionalInfo]'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ErrorDetail, self).__init__(**kwargs) + self.code = None + self.message = None + self.target = None + self.details = None + self.additional_info = None + + +class ErrorResponse(msrest.serialization.Model): + """Common error response for all Azure Resource Manager APIs to return error details for failed operations. (This also follows the OData error response format.). + + :ivar error: The error object. + :vartype error: ~Microsoft.HybridNetwork.models.ErrorDetail + """ + + _attribute_map = { + 'error': {'key': 'error', 'type': 'ErrorDetail'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword error: The error object. + :paramtype error: ~Microsoft.HybridNetwork.models.ErrorDetail + """ + super(ErrorResponse, self).__init__(**kwargs) + self.error = kwargs.get('error', None) + + +class ExecuteRequestParameters(msrest.serialization.Model): + """Payload for execute request post call. + + All required parameters must be populated in order to send to Azure. + + :ivar service_endpoint: Required. The endpoint of service to call. + :vartype service_endpoint: str + :ivar request_metadata: Required. The request metadata. + :vartype request_metadata: ~Microsoft.HybridNetwork.models.RequestMetadata + """ + + _validation = { + 'service_endpoint': {'required': True}, + 'request_metadata': {'required': True}, + } + + _attribute_map = { + 'service_endpoint': {'key': 'serviceEndpoint', 'type': 'str'}, + 'request_metadata': {'key': 'requestMetadata', 'type': 'RequestMetadata'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword service_endpoint: Required. The endpoint of service to call. + :paramtype service_endpoint: str + :keyword request_metadata: Required. The request metadata. + :paramtype request_metadata: ~Microsoft.HybridNetwork.models.RequestMetadata + """ + super(ExecuteRequestParameters, self).__init__(**kwargs) + self.service_endpoint = kwargs['service_endpoint'] + self.request_metadata = kwargs['request_metadata'] + + +class HelmArtifactProfile(msrest.serialization.Model): + """Helm artifact profile. + + :ivar helm_package_name: Helm package name. + :vartype helm_package_name: str + :ivar helm_package_version_range: Helm package version range. + :vartype helm_package_version_range: str + :ivar registry_values_paths: The registry values path list. + :vartype registry_values_paths: list[str] + :ivar image_pull_secrets_values_paths: The image pull secrets values path list. + :vartype image_pull_secrets_values_paths: list[str] + """ + + _attribute_map = { + 'helm_package_name': {'key': 'helmPackageName', 'type': 'str'}, + 'helm_package_version_range': {'key': 'helmPackageVersionRange', 'type': 'str'}, + 'registry_values_paths': {'key': 'registryValuesPaths', 'type': '[str]'}, + 'image_pull_secrets_values_paths': {'key': 'imagePullSecretsValuesPaths', 'type': '[str]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword helm_package_name: Helm package name. + :paramtype helm_package_name: str + :keyword helm_package_version_range: Helm package version range. + :paramtype helm_package_version_range: str + :keyword registry_values_paths: The registry values path list. + :paramtype registry_values_paths: list[str] + :keyword image_pull_secrets_values_paths: The image pull secrets values path list. + :paramtype image_pull_secrets_values_paths: list[str] + """ + super(HelmArtifactProfile, self).__init__(**kwargs) + self.helm_package_name = kwargs.get('helm_package_name', None) + self.helm_package_version_range = kwargs.get('helm_package_version_range', None) + self.registry_values_paths = kwargs.get('registry_values_paths', None) + self.image_pull_secrets_values_paths = kwargs.get('image_pull_secrets_values_paths', None) + + +class HelmMappingRuleProfile(msrest.serialization.Model): + """Helm mapping rule profile. + + :ivar release_namespace: Helm release namespace. + :vartype release_namespace: str + :ivar release_name: Helm release name. + :vartype release_name: str + :ivar helm_package_version: Helm package version. + :vartype helm_package_version: str + :ivar values: Helm release values. + :vartype values: str + """ + + _attribute_map = { + 'release_namespace': {'key': 'releaseNamespace', 'type': 'str'}, + 'release_name': {'key': 'releaseName', 'type': 'str'}, + 'helm_package_version': {'key': 'helmPackageVersion', 'type': 'str'}, + 'values': {'key': 'values', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword release_namespace: Helm release namespace. + :paramtype release_namespace: str + :keyword release_name: Helm release name. + :paramtype release_name: str + :keyword helm_package_version: Helm package version. + :paramtype helm_package_version: str + :keyword values: Helm release values. + :paramtype values: str + """ + super(HelmMappingRuleProfile, self).__init__(**kwargs) + self.release_namespace = kwargs.get('release_namespace', None) + self.release_name = kwargs.get('release_name', None) + self.helm_package_version = kwargs.get('helm_package_version', None) + self.values = kwargs.get('values', None) + + +class HelmPackageApplicationOverview(NetworkFunctionDefinitionApplicationOverview): + """Helm Package Application overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the application. + :vartype name: str + :ivar artifact_type: Required. The application overview artifact type.Constant filled by + server. Possible values include: "Unknown", "HelmPackage", "VhdImageFile", "ArmTemplate", + "ImageFile". + :vartype artifact_type: str or + ~Microsoft.HybridNetwork.models.NetworkFunctionPublisherArtifactType + :ivar deploy_parameters_mapping_rule_profile: The deployment parameters mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureArcKubernetesDeployMappingRuleProfile + """ + + _validation = { + 'name': {'readonly': True}, + 'artifact_type': {'required': True}, + 'deploy_parameters_mapping_rule_profile': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureArcKubernetesDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(HelmPackageApplicationOverview, self).__init__(**kwargs) + self.artifact_type = 'HelmPackage' # type: str + self.deploy_parameters_mapping_rule_profile = None + + +class HybridAKSNetworkFunctionReadyK8S(NetworkFunctionReadyK8SPropertiesFormat): + """Azure based kubernetes service cluster prerequisite properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the NetworkFunctionReadyK8s resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar cluster_type: Required. The cluster type.Constant filled by server. Possible values + include: "AzureKubernetesService", "ArcConnectedK8s", "HybridAKS". + :vartype cluster_type: str or ~Microsoft.HybridNetwork.models.ClusterType + :ivar cluster_reference: Required. The k8s/Connected cluster ARM id. + :vartype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar custom_location_reference: The read only custom location ARM id. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar user_assigned_managed_identity: The User Assigned Managed Identity ARM id giving access + to the HybridAKS cluster if outside AOSM flow. + :vartype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'cluster_type': {'required': True}, + 'cluster_reference': {'required': True}, + 'custom_location_reference': {'readonly': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'cluster_type': {'key': 'clusterType', 'type': 'str'}, + 'cluster_reference': {'key': 'clusterReference', 'type': 'ReferencedResource'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + 'user_assigned_managed_identity': {'key': 'userAssignedManagedIdentity', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword cluster_reference: Required. The k8s/Connected cluster ARM id. + :paramtype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword user_assigned_managed_identity: The User Assigned Managed Identity ARM id giving + access to the HybridAKS cluster if outside AOSM flow. + :paramtype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(HybridAKSNetworkFunctionReadyK8S, self).__init__(**kwargs) + self.cluster_type = 'HybridAKS' # type: str + self.user_assigned_managed_identity = kwargs.get('user_assigned_managed_identity', None) + + +class ImageArtifactProfile(msrest.serialization.Model): + """Image artifact profile. + + :ivar image_name: Image name. + :vartype image_name: str + :ivar image_version: Image version. + :vartype image_version: str + """ + + _attribute_map = { + 'image_name': {'key': 'imageName', 'type': 'str'}, + 'image_version': {'key': 'imageVersion', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword image_name: Image name. + :paramtype image_name: str + :keyword image_version: Image version. + :paramtype image_version: str + """ + super(ImageArtifactProfile, self).__init__(**kwargs) + self.image_name = kwargs.get('image_name', None) + self.image_version = kwargs.get('image_version', None) + + +class ImageFileApplicationOverview(NetworkFunctionDefinitionApplicationOverview): + """Image file Application overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the application. + :vartype name: str + :ivar artifact_type: Required. The application overview artifact type.Constant filled by + server. Possible values include: "Unknown", "HelmPackage", "VhdImageFile", "ArmTemplate", + "ImageFile". + :vartype artifact_type: str or + ~Microsoft.HybridNetwork.models.NetworkFunctionPublisherArtifactType + :ivar deploy_parameters_mapping_rule_profile: The deployment parameters mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreDelegatedImageDeployMappingRuleProfile + """ + + _validation = { + 'name': {'readonly': True}, + 'artifact_type': {'required': True}, + 'deploy_parameters_mapping_rule_profile': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreDelegatedImageDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ImageFileApplicationOverview, self).__init__(**kwargs) + self.artifact_type = 'ImageFile' # type: str + self.deploy_parameters_mapping_rule_profile = None + + +class ImageMappingRuleProfile(msrest.serialization.Model): + """Image mapping rule profile. + + :ivar user_configuration: List of values. + :vartype user_configuration: str + """ + + _attribute_map = { + 'user_configuration': {'key': 'userConfiguration', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword user_configuration: List of values. + :paramtype user_configuration: str + """ + super(ImageMappingRuleProfile, self).__init__(**kwargs) + self.user_configuration = kwargs.get('user_configuration', None) + + +class ManagedResourceGroupConfiguration(msrest.serialization.Model): + """Managed resource group configuration. + + :ivar name: Managed resource group name. + :vartype name: str + :ivar location: Managed resource group location. + :vartype location: str + """ + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'location': {'key': 'location', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: Managed resource group name. + :paramtype name: str + :keyword location: Managed resource group location. + :paramtype location: str + """ + super(ManagedResourceGroupConfiguration, self).__init__(**kwargs) + self.name = kwargs.get('name', None) + self.location = kwargs.get('location', None) + + +class ManagedServiceIdentity(msrest.serialization.Model): + """Managed service identity (system assigned and/or user assigned identities). + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar principal_id: The service principal ID of the system assigned identity. This property + will only be provided for a system assigned identity. + :vartype principal_id: str + :ivar tenant_id: The tenant ID of the system assigned identity. This property will only be + provided for a system assigned identity. + :vartype tenant_id: str + :ivar type: Required. Type of managed service identity (where both SystemAssigned and + UserAssigned types are allowed). Possible values include: "None", "SystemAssigned", + "UserAssigned", "SystemAssigned,UserAssigned". + :vartype type: str or ~Microsoft.HybridNetwork.models.ManagedServiceIdentityType + :ivar user_assigned_identities: The set of user assigned identities associated with the + resource. The userAssignedIdentities dictionary keys will be ARM resource ids in the form: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. + The dictionary values can be empty objects ({}) in requests. + :vartype user_assigned_identities: dict[str, + ~Microsoft.HybridNetwork.models.UserAssignedIdentity] + """ + + _validation = { + 'principal_id': {'readonly': True}, + 'tenant_id': {'readonly': True}, + 'type': {'required': True}, + } + + _attribute_map = { + 'principal_id': {'key': 'principalId', 'type': 'str'}, + 'tenant_id': {'key': 'tenantId', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'user_assigned_identities': {'key': 'userAssignedIdentities', 'type': '{UserAssignedIdentity}'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword type: Required. Type of managed service identity (where both SystemAssigned and + UserAssigned types are allowed). Possible values include: "None", "SystemAssigned", + "UserAssigned", "SystemAssigned,UserAssigned". + :paramtype type: str or ~Microsoft.HybridNetwork.models.ManagedServiceIdentityType + :keyword user_assigned_identities: The set of user assigned identities associated with the + resource. The userAssignedIdentities dictionary keys will be ARM resource ids in the form: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. + The dictionary values can be empty objects ({}) in requests. + :paramtype user_assigned_identities: dict[str, + ~Microsoft.HybridNetwork.models.UserAssignedIdentity] + """ + super(ManagedServiceIdentity, self).__init__(**kwargs) + self.principal_id = None + self.tenant_id = None + self.type = kwargs['type'] + self.user_assigned_identities = kwargs.get('user_assigned_identities', None) + + +class ManifestArtifactFormat(msrest.serialization.Model): + """Manifest artifact properties. + + :ivar artifact_name: The artifact name. + :vartype artifact_name: str + :ivar artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :ivar artifact_version: The artifact version. + :vartype artifact_version: str + """ + + _attribute_map = { + 'artifact_name': {'key': 'artifactName', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_version': {'key': 'artifactVersion', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_name: The artifact name. + :paramtype artifact_name: str + :keyword artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :paramtype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :keyword artifact_version: The artifact version. + :paramtype artifact_version: str + """ + super(ManifestArtifactFormat, self).__init__(**kwargs) + self.artifact_name = kwargs.get('artifact_name', None) + self.artifact_type = kwargs.get('artifact_type', None) + self.artifact_version = kwargs.get('artifact_version', None) + + +class NetworkFunction(TrackedResource): + """Network function resource response. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar etag: A unique read-only string that changes whenever the resource is updated. + :vartype etag: str + :ivar identity: The managed identity of the Network function, if configured. + :vartype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :ivar provisioning_state: The provisioning state of the network function resource. Possible + values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar publisher_name: The publisher name for the network function. + :vartype publisher_name: str + :ivar publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :vartype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :ivar network_function_definition_group_name: The network function definition group name for + the network function. + :vartype network_function_definition_group_name: str + :ivar network_function_definition_version: The network function definition version for the + network function. + :vartype network_function_definition_version: str + :ivar network_function_definition_offering_location: The location of the network function + definition offering. + :vartype network_function_definition_offering_location: str + :ivar nfvi_type: The nfvi type for the network function. Possible values include: "Unknown", + "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :ivar nfvi_id: The nfviId for the network function. + :vartype nfvi_id: str + :ivar allow_software_update: Indicates if software updates are allowed during deployment. + :vartype allow_software_update: bool + :ivar deployment_values: The JSON-serialized deployment values from the user. + :vartype deployment_values: str + :ivar role_override_values: The role configuration override values from the user. + :vartype role_override_values: list[str] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'etag': {'key': 'etag', 'type': 'str'}, + 'identity': {'key': 'identity', 'type': 'ManagedServiceIdentity'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'publisher_name': {'key': 'properties.publisherName', 'type': 'str'}, + 'publisher_scope': {'key': 'properties.publisherScope', 'type': 'str'}, + 'network_function_definition_group_name': {'key': 'properties.networkFunctionDefinitionGroupName', 'type': 'str'}, + 'network_function_definition_version': {'key': 'properties.networkFunctionDefinitionVersion', 'type': 'str'}, + 'network_function_definition_offering_location': {'key': 'properties.networkFunctionDefinitionOfferingLocation', 'type': 'str'}, + 'nfvi_type': {'key': 'properties.nfviType', 'type': 'str'}, + 'nfvi_id': {'key': 'properties.nfviId', 'type': 'str'}, + 'allow_software_update': {'key': 'properties.allowSoftwareUpdate', 'type': 'bool'}, + 'deployment_values': {'key': 'properties.deploymentValues', 'type': 'str'}, + 'role_override_values': {'key': 'properties.roleOverrideValues', 'type': '[str]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword etag: A unique read-only string that changes whenever the resource is updated. + :paramtype etag: str + :keyword identity: The managed identity of the Network function, if configured. + :paramtype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :keyword publisher_name: The publisher name for the network function. + :paramtype publisher_name: str + :keyword publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :paramtype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :keyword network_function_definition_group_name: The network function definition group name for + the network function. + :paramtype network_function_definition_group_name: str + :keyword network_function_definition_version: The network function definition version for the + network function. + :paramtype network_function_definition_version: str + :keyword network_function_definition_offering_location: The location of the network function + definition offering. + :paramtype network_function_definition_offering_location: str + :keyword nfvi_type: The nfvi type for the network function. Possible values include: "Unknown", + "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :paramtype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :keyword nfvi_id: The nfviId for the network function. + :paramtype nfvi_id: str + :keyword allow_software_update: Indicates if software updates are allowed during deployment. + :paramtype allow_software_update: bool + :keyword deployment_values: The JSON-serialized deployment values from the user. + :paramtype deployment_values: str + :keyword role_override_values: The role configuration override values from the user. + :paramtype role_override_values: list[str] + """ + super(NetworkFunction, self).__init__(**kwargs) + self.etag = kwargs.get('etag', None) + self.identity = kwargs.get('identity', None) + self.provisioning_state = None + self.publisher_name = kwargs.get('publisher_name', None) + self.publisher_scope = kwargs.get('publisher_scope', None) + self.network_function_definition_group_name = kwargs.get('network_function_definition_group_name', None) + self.network_function_definition_version = kwargs.get('network_function_definition_version', None) + self.network_function_definition_offering_location = kwargs.get('network_function_definition_offering_location', None) + self.nfvi_type = kwargs.get('nfvi_type', None) + self.nfvi_id = kwargs.get('nfvi_id', None) + self.allow_software_update = kwargs.get('allow_software_update', None) + self.deployment_values = kwargs.get('deployment_values', None) + self.role_override_values = kwargs.get('role_override_values', None) + + +class NetworkFunctionDefinitionGroup(TrackedResource): + """Network function definition group resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the network function definition groups + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar description: The network function definition group description. + :vartype description: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword description: The network function definition group description. + :paramtype description: str + """ + super(NetworkFunctionDefinitionGroup, self).__init__(**kwargs) + self.provisioning_state = None + self.description = kwargs.get('description', None) + + +class NetworkFunctionDefinitionGroupListResult(msrest.serialization.Model): + """A list of network function definition group resources. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network function definition group. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunctionDefinitionGroup]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of network function definition group. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup] + """ + super(NetworkFunctionDefinitionGroupListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class NetworkFunctionDefinitionGroupOverview(ProxyResource): + """Network function definition group overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar description: Network function definition group description. + :vartype description: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'description': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(NetworkFunctionDefinitionGroupOverview, self).__init__(**kwargs) + self.description = None + + +class NetworkFunctionDefinitionGroupOverviewListResult(msrest.serialization.Model): + """A list of available network function definition groups. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: The network function group list properties. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroupOverview] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunctionDefinitionGroupOverview]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: The network function group list properties. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroupOverview] + """ + super(NetworkFunctionDefinitionGroupOverviewListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class NetworkFunctionDefinitionResourceElementTemplateDetails(ResourceElementTemplate): + """The network function definition resource element template details. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the resource element template. + :vartype name: str + :ivar type: Required. The resource element template type.Constant filled by server. Possible + values include: "Unknown", "ArmResourceDefinition", "ConfigurationDefinition", + "NetworkFunctionDefinition". + :vartype type: str or ~Microsoft.HybridNetwork.models.Type + :ivar depends_on_profile: The depends on profile. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar configuration: The resource element template type. + :vartype configuration: + ~Microsoft.HybridNetwork.models.ArmResourceDefinitionResourceElementTemplate + """ + + _validation = { + 'type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'configuration': {'key': 'configuration', 'type': 'ArmResourceDefinitionResourceElementTemplate'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: Name of the resource element template. + :paramtype name: str + :keyword depends_on_profile: The depends on profile. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword configuration: The resource element template type. + :paramtype configuration: + ~Microsoft.HybridNetwork.models.ArmResourceDefinitionResourceElementTemplate + """ + super(NetworkFunctionDefinitionResourceElementTemplateDetails, self).__init__(**kwargs) + self.type = 'NetworkFunctionDefinition' # type: str + self.configuration = kwargs.get('configuration', None) + + +class NetworkFunctionDefinitionVersion(TrackedResource): + """Network function definition version. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the network function definition version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network function definition version description. + :vartype description: str + :ivar deploy_parameters: The deployment parameters of the network function definition version. + :vartype deploy_parameters: str + :ivar network_function_type: The network function type.Constant filled by server. Possible + values include: "Unknown", "VirtualNetworkFunction", "ContainerizedNetworkFunction", + "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'version_state': {'key': 'properties.versionState', 'type': 'str'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + 'deploy_parameters': {'key': 'properties.deployParameters', 'type': 'str'}, + 'network_function_type': {'key': 'properties.networkFunctionType', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword description: The network function definition version description. + :paramtype description: str + :keyword deploy_parameters: The deployment parameters of the network function definition + version. + :paramtype deploy_parameters: str + """ + super(NetworkFunctionDefinitionVersion, self).__init__(**kwargs) + self.provisioning_state = None + self.version_state = None + self.description = kwargs.get('description', None) + self.deploy_parameters = kwargs.get('deploy_parameters', None) + self.network_function_type = None # type: Optional[str] + + +class NetworkFunctionDefinitionVersionListResult(msrest.serialization.Model): + """A list of network function definition versions. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network function definition versions. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion] + :ivar next_link: The URI to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunctionDefinitionVersion]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of network function definition versions. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion] + """ + super(NetworkFunctionDefinitionVersionListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class NetworkFunctionDefinitionVersionOverview(ProxyResource): + """Network function definition version overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar description: The network function definition version description properties. + :vartype description: str + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar network_function_type: The network function type. Possible values include: "Unknown", + "VirtualNetworkFunction", "ContainerizedNetworkFunction", "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + :ivar nfvi_type: The nfvi type for the network function. Possible values include: "Unknown", + "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :ivar deploy_parameters: The deployment parameters. + :vartype deploy_parameters: str + :ivar network_function_applications: The network function definition application overview. + :vartype network_function_applications: + list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionApplicationOverview] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'description': {'readonly': True}, + 'deploy_parameters': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + 'version_state': {'key': 'properties.versionState', 'type': 'str'}, + 'network_function_type': {'key': 'properties.networkFunctionType', 'type': 'str'}, + 'nfvi_type': {'key': 'properties.nfviType', 'type': 'str'}, + 'deploy_parameters': {'key': 'properties.deployParameters', 'type': 'str'}, + 'network_function_applications': {'key': 'properties.networkFunctionApplications', 'type': '[NetworkFunctionDefinitionApplicationOverview]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :paramtype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :keyword network_function_type: The network function type. Possible values include: "Unknown", + "VirtualNetworkFunction", "ContainerizedNetworkFunction", "DelegatedNetworkFunction". + :paramtype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + :keyword nfvi_type: The nfvi type for the network function. Possible values include: "Unknown", + "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :paramtype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :keyword network_function_applications: The network function definition application overview. + :paramtype network_function_applications: + list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionApplicationOverview] + """ + super(NetworkFunctionDefinitionVersionOverview, self).__init__(**kwargs) + self.description = None + self.version_state = kwargs.get('version_state', None) + self.network_function_type = kwargs.get('network_function_type', None) + self.nfvi_type = kwargs.get('nfvi_type', None) + self.deploy_parameters = None + self.network_function_applications = kwargs.get('network_function_applications', None) + + +class NetworkFunctionDefinitionVersionOverviewListResult(msrest.serialization.Model): + """A list of available network function definition groups. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: The network function definition overview properties. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionOverview] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunctionDefinitionVersionOverview]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: The network function definition overview properties. + :paramtype value: + list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionOverview] + """ + super(NetworkFunctionDefinitionVersionOverviewListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class NetworkFunctionDefinitionVersionUpdateState(msrest.serialization.Model): + """Publisher network function definition version update request definition. + + :ivar version_state: The network function definition version state. Only the 'Active' and + 'Deprecated' states are allowed for updates. Other states are used for internal state + transitioning. Possible values include: "Unknown", "Preview", "Active", "Deprecated", + "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + + _attribute_map = { + 'version_state': {'key': 'versionState', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword version_state: The network function definition version state. Only the 'Active' and + 'Deprecated' states are allowed for updates. Other states are used for internal state + transitioning. Possible values include: "Unknown", "Preview", "Active", "Deprecated", + "Validating", "ValidationFailed". + :paramtype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + super(NetworkFunctionDefinitionVersionUpdateState, self).__init__(**kwargs) + self.version_state = kwargs.get('version_state', None) + + +class NetworkFunctionListResult(msrest.serialization.Model): + """Response for network function API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network function resources in a subscription or resource group. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunction] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunction]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of network function resources in a subscription or resource group. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkFunction] + """ + super(NetworkFunctionListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class NetworkFunctionReadyK8S(TrackedResource): + """NetworkFunctionReadyK8s resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar identity: The managed identity of the NetworkFunctionReadyK8s, if configured. + :vartype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :ivar provisioning_state: The provisioning state of the NetworkFunctionReadyK8s resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar cluster_type: The cluster type.Constant filled by server. Possible values include: + "AzureKubernetesService", "ArcConnectedK8s", "HybridAKS". + :vartype cluster_type: str or ~Microsoft.HybridNetwork.models.ClusterType + :ivar cluster_reference: The k8s/Connected cluster ARM id. + :vartype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar custom_location_reference: The read only custom location ARM id. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'custom_location_reference': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'identity': {'key': 'identity', 'type': 'ManagedServiceIdentity'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'cluster_type': {'key': 'properties.clusterType', 'type': 'str'}, + 'cluster_reference': {'key': 'properties.clusterReference', 'type': 'ReferencedResource'}, + 'custom_location_reference': {'key': 'properties.customLocationReference', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword identity: The managed identity of the NetworkFunctionReadyK8s, if configured. + :paramtype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :keyword cluster_reference: The k8s/Connected cluster ARM id. + :paramtype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(NetworkFunctionReadyK8S, self).__init__(**kwargs) + self.identity = kwargs.get('identity', None) + self.provisioning_state = None + self.cluster_type = None # type: Optional[str] + self.cluster_reference = kwargs.get('cluster_reference', None) + self.custom_location_reference = None + + +class NetworkFunctionReadyK8SListResult(msrest.serialization.Model): + """Response for NetworkFunctionReadyK8s API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network function ready K8s. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunctionReadyK8S]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of network function ready K8s. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S] + """ + super(NetworkFunctionReadyK8SListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class NetworkServiceDesignGroup(TrackedResource): + """network service design group resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the network service design groups resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar description: The network service design group description. + :vartype description: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword description: The network service design group description. + :paramtype description: str + """ + super(NetworkServiceDesignGroup, self).__init__(**kwargs) + self.provisioning_state = None + self.description = kwargs.get('description', None) + + +class NetworkServiceDesignGroupListResult(msrest.serialization.Model): + """A list of network service design group resources. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network service design group. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkServiceDesignGroup]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of network service design group. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup] + """ + super(NetworkServiceDesignGroupListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class NetworkServiceDesignVersion(TrackedResource): + """network service design version. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the network service design version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network service design version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network service design version description. + :vartype description: str + :ivar configuration_group_schema_references: The configuration schemas to used to define the + values. + :vartype configuration_group_schema_references: dict[str, + ~Microsoft.HybridNetwork.models.ReferencedResource] + :ivar nfvis_from_site: The nfvis from the site. + :vartype nfvis_from_site: dict[str, ~Microsoft.HybridNetwork.models.NfviDetails] + :ivar resource_element_templates: List of resource element template. + :vartype resource_element_templates: + list[~Microsoft.HybridNetwork.models.ResourceElementTemplate] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'version_state': {'key': 'properties.versionState', 'type': 'str'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + 'configuration_group_schema_references': {'key': 'properties.configurationGroupSchemaReferences', 'type': '{ReferencedResource}'}, + 'nfvis_from_site': {'key': 'properties.nfvisFromSite', 'type': '{NfviDetails}'}, + 'resource_element_templates': {'key': 'properties.resourceElementTemplates', 'type': '[ResourceElementTemplate]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword description: The network service design version description. + :paramtype description: str + :keyword configuration_group_schema_references: The configuration schemas to used to define the + values. + :paramtype configuration_group_schema_references: dict[str, + ~Microsoft.HybridNetwork.models.ReferencedResource] + :keyword nfvis_from_site: The nfvis from the site. + :paramtype nfvis_from_site: dict[str, ~Microsoft.HybridNetwork.models.NfviDetails] + :keyword resource_element_templates: List of resource element template. + :paramtype resource_element_templates: + list[~Microsoft.HybridNetwork.models.ResourceElementTemplate] + """ + super(NetworkServiceDesignVersion, self).__init__(**kwargs) + self.provisioning_state = None + self.version_state = None + self.description = kwargs.get('description', None) + self.configuration_group_schema_references = kwargs.get('configuration_group_schema_references', None) + self.nfvis_from_site = kwargs.get('nfvis_from_site', None) + self.resource_element_templates = kwargs.get('resource_element_templates', None) + + +class NetworkServiceDesignVersionListResult(msrest.serialization.Model): + """A list of network service design versions. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network service design versions. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion] + :ivar next_link: The URI to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkServiceDesignVersion]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of network service design versions. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion] + """ + super(NetworkServiceDesignVersionListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class NetworkServiceDesignVersionUpdateState(msrest.serialization.Model): + """Publisher network service design version update request definition. + + :ivar version_state: The network service design version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + + _attribute_map = { + 'version_state': {'key': 'versionState', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword version_state: The network service design version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :paramtype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + super(NetworkServiceDesignVersionUpdateState, self).__init__(**kwargs) + self.version_state = kwargs.get('version_state', None) + + +class NfviDetails(msrest.serialization.Model): + """The nfvi details. + + :ivar name: The nfvi name. + :vartype name: str + :ivar type: The nfvi type. + :vartype type: str + """ + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword name: The nfvi name. + :paramtype name: str + :keyword type: The nfvi type. + :paramtype type: str + """ + super(NfviDetails, self).__init__(**kwargs) + self.name = kwargs.get('name', None) + self.type = kwargs.get('type', None) + + +class NSDArtifactProfile(msrest.serialization.Model): + """Artifact profile properties. + + :ivar artifact_store_reference: The artifact store resource id. + :vartype artifact_store_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar artifact_name: Artifact name. + :vartype artifact_name: str + :ivar artifact_version: Artifact version. + :vartype artifact_version: str + """ + + _attribute_map = { + 'artifact_store_reference': {'key': 'artifactStoreReference', 'type': 'ReferencedResource'}, + 'artifact_name': {'key': 'artifactName', 'type': 'str'}, + 'artifact_version': {'key': 'artifactVersion', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_store_reference: The artifact store resource id. + :paramtype artifact_store_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword artifact_name: Artifact name. + :paramtype artifact_name: str + :keyword artifact_version: Artifact version. + :paramtype artifact_version: str + """ + super(NSDArtifactProfile, self).__init__(**kwargs) + self.artifact_store_reference = kwargs.get('artifact_store_reference', None) + self.artifact_name = kwargs.get('artifact_name', None) + self.artifact_version = kwargs.get('artifact_version', None) + + +class Operation(msrest.serialization.Model): + """Object that describes a single Microsoft.HybridNetwork operation. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar name: Operation name: {provider}/{resource}/{operation}. + :vartype name: str + :ivar display: The object that represents the operation. + :vartype display: ~Microsoft.HybridNetwork.models.OperationDisplay + """ + + _validation = { + 'name': {'readonly': True}, + 'display': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'display': {'key': 'display', 'type': 'OperationDisplay'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(Operation, self).__init__(**kwargs) + self.name = None + self.display = None + + +class OperationDisplay(msrest.serialization.Model): + """The object that represents the operation. + + :ivar provider: Service provider: Microsoft.HybridNetwork. + :vartype provider: str + :ivar resource: Resource on which the operation is performed: Registration definition, + registration assignment, etc. + :vartype resource: str + :ivar operation: Operation type: Read, write, delete, etc. + :vartype operation: str + :ivar description: Description of the operation. + :vartype description: str + """ + + _attribute_map = { + 'provider': {'key': 'provider', 'type': 'str'}, + 'resource': {'key': 'resource', 'type': 'str'}, + 'operation': {'key': 'operation', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword provider: Service provider: Microsoft.HybridNetwork. + :paramtype provider: str + :keyword resource: Resource on which the operation is performed: Registration definition, + registration assignment, etc. + :paramtype resource: str + :keyword operation: Operation type: Read, write, delete, etc. + :paramtype operation: str + :keyword description: Description of the operation. + :paramtype description: str + """ + super(OperationDisplay, self).__init__(**kwargs) + self.provider = kwargs.get('provider', None) + self.resource = kwargs.get('resource', None) + self.operation = kwargs.get('operation', None) + self.description = kwargs.get('description', None) + + +class OperationList(msrest.serialization.Model): + """A list of the operations. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of Microsoft.HybridNetwork operations. + :vartype value: list[~Microsoft.HybridNetwork.models.Operation] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'value': {'readonly': True}, + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[Operation]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(OperationList, self).__init__(**kwargs) + self.value = None + self.next_link = None + + +class PreviewSubscription(TrackedResource): + """Customer subscription which can use a preview network function definition version. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the preview subscription resource. Possible + values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + """ + super(PreviewSubscription, self).__init__(**kwargs) + self.provisioning_state = None + + +class PreviewSubscriptionsList(msrest.serialization.Model): + """A list of customer subscriptions which can use a preview network function definition version. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of preview subscriptions. + :vartype value: list[~Microsoft.HybridNetwork.models.PreviewSubscription] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[PreviewSubscription]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of preview subscriptions. + :paramtype value: list[~Microsoft.HybridNetwork.models.PreviewSubscription] + """ + super(PreviewSubscriptionsList, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class ProxyArtifactListOverview(ProxyResource): + """The proxy artifact overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ProxyArtifactListOverview, self).__init__(**kwargs) + + +class ProxyArtifactOverview(ProxyResource): + """The proxy artifact overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar artifact_versions: The proxy artifact overview properties. + :vartype artifact_versions: + list[~Microsoft.HybridNetwork.models.ProxyArtifactOverviewPropertiesValue] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'artifact_versions': {'key': 'properties.artifactVersions', 'type': '[ProxyArtifactOverviewPropertiesValue]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_versions: The proxy artifact overview properties. + :paramtype artifact_versions: + list[~Microsoft.HybridNetwork.models.ProxyArtifactOverviewPropertiesValue] + """ + super(ProxyArtifactOverview, self).__init__(**kwargs) + self.artifact_versions = kwargs.get('artifact_versions', None) + + +class ProxyArtifactOverviewListResult(msrest.serialization.Model): + """The proxy artifact list result. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of available proxy artifacts. + :vartype value: list[~Microsoft.HybridNetwork.models.ProxyArtifactListOverview] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ProxyArtifactListOverview]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of available proxy artifacts. + :paramtype value: list[~Microsoft.HybridNetwork.models.ProxyArtifactListOverview] + """ + super(ProxyArtifactOverviewListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class ProxyArtifactOverviewPropertiesValue(msrest.serialization.Model): + """ProxyArtifactOverviewPropertiesValue. + + :ivar artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :ivar artifact_version: The artifact version. + :vartype artifact_version: str + :ivar artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :vartype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + + _attribute_map = { + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_version': {'key': 'artifactVersion', 'type': 'str'}, + 'artifact_state': {'key': 'artifactState', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :paramtype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :keyword artifact_version: The artifact version. + :paramtype artifact_version: str + :keyword artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :paramtype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + super(ProxyArtifactOverviewPropertiesValue, self).__init__(**kwargs) + self.artifact_type = kwargs.get('artifact_type', None) + self.artifact_version = kwargs.get('artifact_version', None) + self.artifact_state = kwargs.get('artifact_state', None) + + +class ProxyArtifactVersionsListOverview(ProxyResource): + """The proxy artifact overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :ivar artifact_version: The artifact version. + :vartype artifact_version: str + :ivar artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :vartype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'artifact_type': {'key': 'properties.artifactType', 'type': 'str'}, + 'artifact_version': {'key': 'properties.artifactVersion', 'type': 'str'}, + 'artifact_state': {'key': 'properties.artifactState', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :paramtype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :keyword artifact_version: The artifact version. + :paramtype artifact_version: str + :keyword artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :paramtype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + super(ProxyArtifactVersionsListOverview, self).__init__(**kwargs) + self.artifact_type = kwargs.get('artifact_type', None) + self.artifact_version = kwargs.get('artifact_version', None) + self.artifact_state = kwargs.get('artifact_state', None) + + +class ProxyArtifactVersionsOverviewListResult(msrest.serialization.Model): + """The proxy artifact list result. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of available proxy artifacts. + :vartype value: list[~Microsoft.HybridNetwork.models.ProxyArtifactVersionsListOverview] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ProxyArtifactVersionsListOverview]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of available proxy artifacts. + :paramtype value: list[~Microsoft.HybridNetwork.models.ProxyArtifactVersionsListOverview] + """ + super(ProxyArtifactVersionsOverviewListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class ProxyPublisherOverview(ProxyResource): + """The proxy publisher overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ProxyPublisherOverview, self).__init__(**kwargs) + + +class ProxyPublisherOverviewListResult(msrest.serialization.Model): + """The proxy publisher list result. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of available proxy publishers. + :vartype value: list[~Microsoft.HybridNetwork.models.ProxyPublisherOverview] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ProxyPublisherOverview]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of available proxy publishers. + :paramtype value: list[~Microsoft.HybridNetwork.models.ProxyPublisherOverview] + """ + super(ProxyPublisherOverviewListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class Publisher(TrackedResource): + """publisher resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the publisher resource. Possible values + include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", "Deleted", + "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar scope: The publisher scope. Possible values include: "Unknown", "Public", "Private". + :vartype scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'scope': {'key': 'properties.scope', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword scope: The publisher scope. Possible values include: "Unknown", "Public", "Private". + :paramtype scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + """ + super(Publisher, self).__init__(**kwargs) + self.provisioning_state = None + self.scope = kwargs.get('scope', None) + + +class PublisherListResult(msrest.serialization.Model): + """A list of publishers. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of publishers. + :vartype value: list[~Microsoft.HybridNetwork.models.Publisher] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[Publisher]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of publishers. + :paramtype value: list[~Microsoft.HybridNetwork.models.Publisher] + """ + super(PublisherListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class ReferencedResource(msrest.serialization.Model): + """Reference to another resource. + + :ivar id: Resource ID. + :vartype id: str + """ + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword id: Resource ID. + :paramtype id: str + """ + super(ReferencedResource, self).__init__(**kwargs) + self.id = kwargs.get('id', None) + + +class RequestMetadata(msrest.serialization.Model): + """Request metadata of execute request post call payload. + + All required parameters must be populated in order to send to Azure. + + :ivar relative_path: Required. The relative path of the request. + :vartype relative_path: str + :ivar http_method: Required. The http method of the request. Possible values include: + "Unknown", "Post", "Put", "Get", "Patch", "Delete". + :vartype http_method: str or ~Microsoft.HybridNetwork.models.HttpMethod + :ivar serialized_body: Required. The serialized body of the request. + :vartype serialized_body: str + :ivar api_version: The api version of the request. + :vartype api_version: str + """ + + _validation = { + 'relative_path': {'required': True}, + 'http_method': {'required': True}, + 'serialized_body': {'required': True}, + } + + _attribute_map = { + 'relative_path': {'key': 'relativePath', 'type': 'str'}, + 'http_method': {'key': 'httpMethod', 'type': 'str'}, + 'serialized_body': {'key': 'serializedBody', 'type': 'str'}, + 'api_version': {'key': 'apiVersion', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword relative_path: Required. The relative path of the request. + :paramtype relative_path: str + :keyword http_method: Required. The http method of the request. Possible values include: + "Unknown", "Post", "Put", "Get", "Patch", "Delete". + :paramtype http_method: str or ~Microsoft.HybridNetwork.models.HttpMethod + :keyword serialized_body: Required. The serialized body of the request. + :paramtype serialized_body: str + :keyword api_version: The api version of the request. + :paramtype api_version: str + """ + super(RequestMetadata, self).__init__(**kwargs) + self.relative_path = kwargs['relative_path'] + self.http_method = kwargs['http_method'] + self.serialized_body = kwargs['serialized_body'] + self.api_version = kwargs.get('api_version', None) + + +class Site(TrackedResource): + """Site resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the site resource. **TODO**\ : Confirm if + this is needed. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", + "Failed", "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar nfvis: List of NFVIs. + :vartype nfvis: list[~Microsoft.HybridNetwork.models.NFVIs] + :ivar site_network_service_references: The list of site network services on the site. + :vartype site_network_service_references: + list[~Microsoft.HybridNetwork.models.ReferencedResource] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'site_network_service_references': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'nfvis': {'key': 'properties.nfvis', 'type': '[NFVIs]'}, + 'site_network_service_references': {'key': 'properties.siteNetworkServiceReferences', 'type': '[ReferencedResource]'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword nfvis: List of NFVIs. + :paramtype nfvis: list[~Microsoft.HybridNetwork.models.NFVIs] + """ + super(Site, self).__init__(**kwargs) + self.provisioning_state = None + self.nfvis = kwargs.get('nfvis', None) + self.site_network_service_references = None + + +class SiteListResult(msrest.serialization.Model): + """Response for sites API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of sites in a resource group. + :vartype value: list[~Microsoft.HybridNetwork.models.Site] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[Site]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of sites in a resource group. + :paramtype value: list[~Microsoft.HybridNetwork.models.Site] + """ + super(SiteListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class SiteNetworkService(TrackedResource): + """Site network service resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar identity: The managed identity of the Site network service, if configured. + :vartype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :ivar provisioning_state: The provisioning state of the site network service resource. Possible + values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar managed_resource_group_configuration: Managed resource group configuration. + :vartype managed_resource_group_configuration: + ~Microsoft.HybridNetwork.models.ManagedResourceGroupConfiguration + :ivar site_reference: The site details. + :vartype site_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar publisher_name: The publisher name for the site network service. + :vartype publisher_name: str + :ivar publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :vartype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :ivar network_service_design_group_name: The network service design group name for the site + network service. + :vartype network_service_design_group_name: str + :ivar network_service_design_version_name: The network service design version for the site + network service. + :vartype network_service_design_version_name: str + :ivar network_service_design_version_offering_location: The location of the network service + design offering. + :vartype network_service_design_version_offering_location: str + :ivar desired_state_configuration_group_value_references: The goal state of the site network + service resource. This has references to the configuration group value objects that describe + the desired state of the site network service. + :vartype desired_state_configuration_group_value_references: dict[str, + ~Microsoft.HybridNetwork.models.ReferencedResource] + :ivar last_state_network_service_design_version_name: The network service design version for + the site network service. + :vartype last_state_network_service_design_version_name: str + :ivar last_state_configuration_group_value_references: The last state of the site network + service resource. + :vartype last_state_configuration_group_value_references: dict[str, + ~Microsoft.HybridNetwork.models.ReferencedResource] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'network_service_design_version_name': {'pattern': r'^[0-9]+\.[0-9]+\.[0-9]+$'}, + 'last_state_network_service_design_version_name': {'readonly': True, 'pattern': r'^[0-9]+\.[0-9]+\.[0-9]+$'}, + 'last_state_configuration_group_value_references': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'identity': {'key': 'identity', 'type': 'ManagedServiceIdentity'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'managed_resource_group_configuration': {'key': 'properties.managedResourceGroupConfiguration', 'type': 'ManagedResourceGroupConfiguration'}, + 'site_reference': {'key': 'properties.siteReference', 'type': 'ReferencedResource'}, + 'publisher_name': {'key': 'properties.publisherName', 'type': 'str'}, + 'publisher_scope': {'key': 'properties.publisherScope', 'type': 'str'}, + 'network_service_design_group_name': {'key': 'properties.networkServiceDesignGroupName', 'type': 'str'}, + 'network_service_design_version_name': {'key': 'properties.networkServiceDesignVersionName', 'type': 'str'}, + 'network_service_design_version_offering_location': {'key': 'properties.networkServiceDesignVersionOfferingLocation', 'type': 'str'}, + 'desired_state_configuration_group_value_references': {'key': 'properties.desiredStateConfigurationGroupValueReferences', 'type': '{ReferencedResource}'}, + 'last_state_network_service_design_version_name': {'key': 'properties.lastStateNetworkServiceDesignVersionName', 'type': 'str'}, + 'last_state_configuration_group_value_references': {'key': 'properties.lastStateConfigurationGroupValueReferences', 'type': '{ReferencedResource}'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword identity: The managed identity of the Site network service, if configured. + :paramtype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :keyword managed_resource_group_configuration: Managed resource group configuration. + :paramtype managed_resource_group_configuration: + ~Microsoft.HybridNetwork.models.ManagedResourceGroupConfiguration + :keyword site_reference: The site details. + :paramtype site_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword publisher_name: The publisher name for the site network service. + :paramtype publisher_name: str + :keyword publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :paramtype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :keyword network_service_design_group_name: The network service design group name for the site + network service. + :paramtype network_service_design_group_name: str + :keyword network_service_design_version_name: The network service design version for the site + network service. + :paramtype network_service_design_version_name: str + :keyword network_service_design_version_offering_location: The location of the network service + design offering. + :paramtype network_service_design_version_offering_location: str + :keyword desired_state_configuration_group_value_references: The goal state of the site network + service resource. This has references to the configuration group value objects that describe + the desired state of the site network service. + :paramtype desired_state_configuration_group_value_references: dict[str, + ~Microsoft.HybridNetwork.models.ReferencedResource] + """ + super(SiteNetworkService, self).__init__(**kwargs) + self.identity = kwargs.get('identity', None) + self.provisioning_state = None + self.managed_resource_group_configuration = kwargs.get('managed_resource_group_configuration', None) + self.site_reference = kwargs.get('site_reference', None) + self.publisher_name = kwargs.get('publisher_name', None) + self.publisher_scope = kwargs.get('publisher_scope', None) + self.network_service_design_group_name = kwargs.get('network_service_design_group_name', None) + self.network_service_design_version_name = kwargs.get('network_service_design_version_name', None) + self.network_service_design_version_offering_location = kwargs.get('network_service_design_version_offering_location', None) + self.desired_state_configuration_group_value_references = kwargs.get('desired_state_configuration_group_value_references', None) + self.last_state_network_service_design_version_name = None + self.last_state_configuration_group_value_references = None + + +class SiteNetworkServiceListResult(msrest.serialization.Model): + """Response for site network services API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of site network services in a resource group. + :vartype value: list[~Microsoft.HybridNetwork.models.SiteNetworkService] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[SiteNetworkService]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword value: A list of site network services in a resource group. + :paramtype value: list[~Microsoft.HybridNetwork.models.SiteNetworkService] + """ + super(SiteNetworkServiceListResult, self).__init__(**kwargs) + self.value = kwargs.get('value', None) + self.next_link = None + + +class SystemData(msrest.serialization.Model): + """Metadata pertaining to creation and last modification of the resource. + + :ivar created_by: The identity that created the resource. + :vartype created_by: str + :ivar created_by_type: The type of identity that created the resource. Possible values include: + "User", "Application", "ManagedIdentity", "Key". + :vartype created_by_type: str or ~Microsoft.HybridNetwork.models.CreatedByType + :ivar created_at: The timestamp of resource creation (UTC). + :vartype created_at: ~datetime.datetime + :ivar last_modified_by: The identity that last modified the resource. + :vartype last_modified_by: str + :ivar last_modified_by_type: The type of identity that last modified the resource. Possible + values include: "User", "Application", "ManagedIdentity", "Key". + :vartype last_modified_by_type: str or ~Microsoft.HybridNetwork.models.CreatedByType + :ivar last_modified_at: The timestamp of resource last modification (UTC). + :vartype last_modified_at: ~datetime.datetime + """ + + _attribute_map = { + 'created_by': {'key': 'createdBy', 'type': 'str'}, + 'created_by_type': {'key': 'createdByType', 'type': 'str'}, + 'created_at': {'key': 'createdAt', 'type': 'iso-8601'}, + 'last_modified_by': {'key': 'lastModifiedBy', 'type': 'str'}, + 'last_modified_by_type': {'key': 'lastModifiedByType', 'type': 'str'}, + 'last_modified_at': {'key': 'lastModifiedAt', 'type': 'iso-8601'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword created_by: The identity that created the resource. + :paramtype created_by: str + :keyword created_by_type: The type of identity that created the resource. Possible values + include: "User", "Application", "ManagedIdentity", "Key". + :paramtype created_by_type: str or ~Microsoft.HybridNetwork.models.CreatedByType + :keyword created_at: The timestamp of resource creation (UTC). + :paramtype created_at: ~datetime.datetime + :keyword last_modified_by: The identity that last modified the resource. + :paramtype last_modified_by: str + :keyword last_modified_by_type: The type of identity that last modified the resource. Possible + values include: "User", "Application", "ManagedIdentity", "Key". + :paramtype last_modified_by_type: str or ~Microsoft.HybridNetwork.models.CreatedByType + :keyword last_modified_at: The timestamp of resource last modification (UTC). + :paramtype last_modified_at: ~datetime.datetime + """ + super(SystemData, self).__init__(**kwargs) + self.created_by = kwargs.get('created_by', None) + self.created_by_type = kwargs.get('created_by_type', None) + self.created_at = kwargs.get('created_at', None) + self.last_modified_by = kwargs.get('last_modified_by', None) + self.last_modified_by_type = kwargs.get('last_modified_by_type', None) + self.last_modified_at = kwargs.get('last_modified_at', None) + + +class TagsObject(msrest.serialization.Model): + """Tags object for patch operations. + + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + """ + + _attribute_map = { + 'tags': {'key': 'tags', 'type': '{str}'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + """ + super(TagsObject, self).__init__(**kwargs) + self.tags = kwargs.get('tags', None) + + +class UserAssignedIdentity(msrest.serialization.Model): + """User assigned identity properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar principal_id: The principal ID of the assigned identity. + :vartype principal_id: str + :ivar client_id: The client ID of the assigned identity. + :vartype client_id: str + """ + + _validation = { + 'principal_id': {'readonly': True}, + 'client_id': {'readonly': True}, + } + + _attribute_map = { + 'principal_id': {'key': 'principalId', 'type': 'str'}, + 'client_id': {'key': 'clientId', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(UserAssignedIdentity, self).__init__(**kwargs) + self.principal_id = None + self.client_id = None + + +class VhdImageArtifactProfile(msrest.serialization.Model): + """Vhd artifact profile. + + :ivar vhd_name: Vhd name. + :vartype vhd_name: str + :ivar vhd_version: Vhd version. + :vartype vhd_version: str + """ + + _attribute_map = { + 'vhd_name': {'key': 'vhdName', 'type': 'str'}, + 'vhd_version': {'key': 'vhdVersion', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword vhd_name: Vhd name. + :paramtype vhd_name: str + :keyword vhd_version: Vhd version. + :paramtype vhd_version: str + """ + super(VhdImageArtifactProfile, self).__init__(**kwargs) + self.vhd_name = kwargs.get('vhd_name', None) + self.vhd_version = kwargs.get('vhd_version', None) + + +class VhdImageFileApplicationOverview(NetworkFunctionDefinitionApplicationOverview): + """Vhd image file Application overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the application. + :vartype name: str + :ivar artifact_type: Required. The application overview artifact type.Constant filled by + server. Possible values include: "Unknown", "HelmPackage", "VhdImageFile", "ArmTemplate", + "ImageFile". + :vartype artifact_type: str or + ~Microsoft.HybridNetwork.models.NetworkFunctionPublisherArtifactType + :ivar deploy_parameters_mapping_rule_profile: The deployment parameters mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreVhdImageDeployMappingRuleProfile + """ + + _validation = { + 'name': {'readonly': True}, + 'artifact_type': {'required': True}, + 'deploy_parameters_mapping_rule_profile': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreVhdImageDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(VhdImageFileApplicationOverview, self).__init__(**kwargs) + self.artifact_type = 'VhdImageFile' # type: str + self.deploy_parameters_mapping_rule_profile = None + + +class VhdImageMappingRuleProfile(msrest.serialization.Model): + """Vhd mapping rule profile. + + :ivar user_configuration: List of values. + :vartype user_configuration: str + """ + + _attribute_map = { + 'user_configuration': {'key': 'userConfiguration', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword user_configuration: List of values. + :paramtype user_configuration: str + """ + super(VhdImageMappingRuleProfile, self).__init__(**kwargs) + self.user_configuration = kwargs.get('user_configuration', None) + + +class VirtualNetworkFunctionDefinitionVersion(NetworkFunctionDefinitionVersionPropertiesFormat): + """Virtual network function network function definition version properties . + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the network function definition version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network function definition version description. + :vartype description: str + :ivar deploy_parameters: The deployment parameters of the network function definition version. + :vartype deploy_parameters: str + :ivar network_function_type: Required. The network function type.Constant filled by server. + Possible values include: "Unknown", "VirtualNetworkFunction", "ContainerizedNetworkFunction", + "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + :ivar network_function_template: Virtual network function template. + :vartype network_function_template: + ~Microsoft.HybridNetwork.models.VirtualNetworkFunctionTemplate + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + 'network_function_type': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'version_state': {'key': 'versionState', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + 'deploy_parameters': {'key': 'deployParameters', 'type': 'str'}, + 'network_function_type': {'key': 'networkFunctionType', 'type': 'str'}, + 'network_function_template': {'key': 'networkFunctionTemplate', 'type': 'VirtualNetworkFunctionTemplate'}, + } + + def __init__( + self, + **kwargs + ): + """ + :keyword description: The network function definition version description. + :paramtype description: str + :keyword deploy_parameters: The deployment parameters of the network function definition + version. + :paramtype deploy_parameters: str + :keyword network_function_template: Virtual network function template. + :paramtype network_function_template: + ~Microsoft.HybridNetwork.models.VirtualNetworkFunctionTemplate + """ + super(VirtualNetworkFunctionDefinitionVersion, self).__init__(**kwargs) + self.network_function_type = 'VirtualNetworkFunction' # type: str + self.network_function_template = kwargs.get('network_function_template', None) diff --git a/src/aosm/azext_aosm/vendored_sdks/models/_models_py3.py b/src/aosm/azext_aosm/vendored_sdks/models/_models_py3.py new file mode 100644 index 00000000000..3acbe9f86a8 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/models/_models_py3.py @@ -0,0 +1,6446 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +import datetime +from typing import Dict, List, Optional, Union + +from azure.core.exceptions import HttpResponseError +import msrest.serialization + +from ._hybrid_network_management_client_enums import * + + +class NetworkFunctionReadyK8SPropertiesFormat(msrest.serialization.Model): + """NetworkFunctionReadyK8s properties. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: ArcConnectedK8SNetworkFunctionReadyK8S, AzureKubernetesServiceNetworkFunctionReadyK8S, HybridAKSNetworkFunctionReadyK8S. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the NetworkFunctionReadyK8s resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar cluster_type: Required. The cluster type.Constant filled by server. Possible values + include: "AzureKubernetesService", "ArcConnectedK8s", "HybridAKS". + :vartype cluster_type: str or ~Microsoft.HybridNetwork.models.ClusterType + :ivar cluster_reference: Required. The k8s/Connected cluster ARM id. + :vartype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar custom_location_reference: The read only custom location ARM id. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'cluster_type': {'required': True}, + 'cluster_reference': {'required': True}, + 'custom_location_reference': {'readonly': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'cluster_type': {'key': 'clusterType', 'type': 'str'}, + 'cluster_reference': {'key': 'clusterReference', 'type': 'ReferencedResource'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + } + + _subtype_map = { + 'cluster_type': {'ArcConnectedK8s': 'ArcConnectedK8SNetworkFunctionReadyK8S', 'AzureKubernetesService': 'AzureKubernetesServiceNetworkFunctionReadyK8S', 'HybridAKS': 'HybridAKSNetworkFunctionReadyK8S'} + } + + def __init__( + self, + *, + cluster_reference: "ReferencedResource", + **kwargs + ): + """ + :keyword cluster_reference: Required. The k8s/Connected cluster ARM id. + :paramtype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(NetworkFunctionReadyK8SPropertiesFormat, self).__init__(**kwargs) + self.provisioning_state = None + self.cluster_type = None # type: Optional[str] + self.cluster_reference = cluster_reference + self.custom_location_reference = None + + +class ArcConnectedK8SNetworkFunctionReadyK8S(NetworkFunctionReadyK8SPropertiesFormat): + """Arc Connected kubernetes cluster prerequisite properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the NetworkFunctionReadyK8s resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar cluster_type: Required. The cluster type.Constant filled by server. Possible values + include: "AzureKubernetesService", "ArcConnectedK8s", "HybridAKS". + :vartype cluster_type: str or ~Microsoft.HybridNetwork.models.ClusterType + :ivar cluster_reference: Required. The k8s/Connected cluster ARM id. + :vartype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar custom_location_reference: The read only custom location ARM id. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar user_assigned_managed_identity: Required. The User Assigned Managed Identity ARM id + which has access to the connected cluster. + :vartype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'cluster_type': {'required': True}, + 'cluster_reference': {'required': True}, + 'custom_location_reference': {'readonly': True}, + 'user_assigned_managed_identity': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'cluster_type': {'key': 'clusterType', 'type': 'str'}, + 'cluster_reference': {'key': 'clusterReference', 'type': 'ReferencedResource'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + 'user_assigned_managed_identity': {'key': 'userAssignedManagedIdentity', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + *, + cluster_reference: "ReferencedResource", + user_assigned_managed_identity: "ReferencedResource", + **kwargs + ): + """ + :keyword cluster_reference: Required. The k8s/Connected cluster ARM id. + :paramtype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword user_assigned_managed_identity: Required. The User Assigned Managed Identity ARM id + which has access to the connected cluster. + :paramtype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(ArcConnectedK8SNetworkFunctionReadyK8S, self).__init__(cluster_reference=cluster_reference, **kwargs) + self.cluster_type = 'ArcConnectedK8s' # type: str + self.user_assigned_managed_identity = user_assigned_managed_identity + + +class ArmResourceDefinitionResourceElementTemplate(msrest.serialization.Model): + """The arm template RE. + + :ivar template_type: The template type. Possible values include: "Unknown", "ArmTemplate". + :vartype template_type: str or ~Microsoft.HybridNetwork.models.TemplateType + :ivar parameter_values: Name and value pairs that define the parameter values. It can be a + well formed escaped JSON string. + :vartype parameter_values: str + :ivar artifact_profile: Artifact profile properties. + :vartype artifact_profile: ~Microsoft.HybridNetwork.models.NSDArtifactProfile + """ + + _attribute_map = { + 'template_type': {'key': 'templateType', 'type': 'str'}, + 'parameter_values': {'key': 'parameterValues', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'NSDArtifactProfile'}, + } + + def __init__( + self, + *, + template_type: Optional[Union[str, "TemplateType"]] = None, + parameter_values: Optional[str] = None, + artifact_profile: Optional["NSDArtifactProfile"] = None, + **kwargs + ): + """ + :keyword template_type: The template type. Possible values include: "Unknown", "ArmTemplate". + :paramtype template_type: str or ~Microsoft.HybridNetwork.models.TemplateType + :keyword parameter_values: Name and value pairs that define the parameter values. It can be a + well formed escaped JSON string. + :paramtype parameter_values: str + :keyword artifact_profile: Artifact profile properties. + :paramtype artifact_profile: ~Microsoft.HybridNetwork.models.NSDArtifactProfile + """ + super(ArmResourceDefinitionResourceElementTemplate, self).__init__(**kwargs) + self.template_type = template_type + self.parameter_values = parameter_values + self.artifact_profile = artifact_profile + + +class ResourceElementTemplate(msrest.serialization.Model): + """The resource element template object. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: ArmResourceDefinitionResourceElementTemplateDetails, ConfigurationDefinitionResourceElementTemplateDetails, NetworkFunctionDefinitionResourceElementTemplateDetails. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the resource element template. + :vartype name: str + :ivar type: Required. The resource element template type.Constant filled by server. Possible + values include: "Unknown", "ArmResourceDefinition", "ConfigurationDefinition", + "NetworkFunctionDefinition". + :vartype type: str or ~Microsoft.HybridNetwork.models.Type + :ivar depends_on_profile: The depends on profile. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + + _validation = { + 'type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + } + + _subtype_map = { + 'type': {'ArmResourceDefinition': 'ArmResourceDefinitionResourceElementTemplateDetails', 'ConfigurationDefinition': 'ConfigurationDefinitionResourceElementTemplateDetails', 'NetworkFunctionDefinition': 'NetworkFunctionDefinitionResourceElementTemplateDetails'} + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + **kwargs + ): + """ + :keyword name: Name of the resource element template. + :paramtype name: str + :keyword depends_on_profile: The depends on profile. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(ResourceElementTemplate, self).__init__(**kwargs) + self.name = name + self.type = None # type: Optional[str] + self.depends_on_profile = depends_on_profile + + +class ArmResourceDefinitionResourceElementTemplateDetails(ResourceElementTemplate): + """The arm resource definition resource element template details. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the resource element template. + :vartype name: str + :ivar type: Required. The resource element template type.Constant filled by server. Possible + values include: "Unknown", "ArmResourceDefinition", "ConfigurationDefinition", + "NetworkFunctionDefinition". + :vartype type: str or ~Microsoft.HybridNetwork.models.Type + :ivar depends_on_profile: The depends on profile. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar configuration: The resource element template type. + :vartype configuration: + ~Microsoft.HybridNetwork.models.ArmResourceDefinitionResourceElementTemplate + """ + + _validation = { + 'type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'configuration': {'key': 'configuration', 'type': 'ArmResourceDefinitionResourceElementTemplate'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + configuration: Optional["ArmResourceDefinitionResourceElementTemplate"] = None, + **kwargs + ): + """ + :keyword name: Name of the resource element template. + :paramtype name: str + :keyword depends_on_profile: The depends on profile. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword configuration: The resource element template type. + :paramtype configuration: + ~Microsoft.HybridNetwork.models.ArmResourceDefinitionResourceElementTemplate + """ + super(ArmResourceDefinitionResourceElementTemplateDetails, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.type = 'ArmResourceDefinition' # type: str + self.configuration = configuration + + +class NetworkFunctionDefinitionApplicationOverview(msrest.serialization.Model): + """The network function definition application overview. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: ArmTemplateApplicationOverview, HelmPackageApplicationOverview, ImageFileApplicationOverview, VhdImageFileApplicationOverview. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the application. + :vartype name: str + :ivar artifact_type: Required. The application overview artifact type.Constant filled by + server. Possible values include: "Unknown", "HelmPackage", "VhdImageFile", "ArmTemplate", + "ImageFile". + :vartype artifact_type: str or + ~Microsoft.HybridNetwork.models.NetworkFunctionPublisherArtifactType + """ + + _validation = { + 'name': {'readonly': True}, + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + } + + _subtype_map = { + 'artifact_type': {'ArmTemplate': 'ArmTemplateApplicationOverview', 'HelmPackage': 'HelmPackageApplicationOverview', 'ImageFile': 'ImageFileApplicationOverview', 'VhdImageFile': 'VhdImageFileApplicationOverview'} + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(NetworkFunctionDefinitionApplicationOverview, self).__init__(**kwargs) + self.name = None + self.artifact_type = None # type: Optional[str] + + +class ArmTemplateApplicationOverview(NetworkFunctionDefinitionApplicationOverview): + """Arm template Application overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the application. + :vartype name: str + :ivar artifact_type: Required. The application overview artifact type.Constant filled by + server. Possible values include: "Unknown", "HelmPackage", "VhdImageFile", "ArmTemplate", + "ImageFile". + :vartype artifact_type: str or + ~Microsoft.HybridNetwork.models.NetworkFunctionPublisherArtifactType + :ivar deploy_parameters_mapping_rule_profile: The deployment parameters mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreArmTemplateDeployMappingRuleProfile + """ + + _validation = { + 'name': {'readonly': True}, + 'artifact_type': {'required': True}, + 'deploy_parameters_mapping_rule_profile': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreArmTemplateDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ArmTemplateApplicationOverview, self).__init__(**kwargs) + self.artifact_type = 'ArmTemplate' # type: str + self.deploy_parameters_mapping_rule_profile = None + + +class ArmTemplateArtifactProfile(msrest.serialization.Model): + """Template artifact profile. + + :ivar template_name: Template name. + :vartype template_name: str + :ivar template_version: Template version. + :vartype template_version: str + """ + + _attribute_map = { + 'template_name': {'key': 'templateName', 'type': 'str'}, + 'template_version': {'key': 'templateVersion', 'type': 'str'}, + } + + def __init__( + self, + *, + template_name: Optional[str] = None, + template_version: Optional[str] = None, + **kwargs + ): + """ + :keyword template_name: Template name. + :paramtype template_name: str + :keyword template_version: Template version. + :paramtype template_version: str + """ + super(ArmTemplateArtifactProfile, self).__init__(**kwargs) + self.template_name = template_name + self.template_version = template_version + + +class ArmTemplateMappingRuleProfile(msrest.serialization.Model): + """Template mapping rule profile. + + :ivar template_parameters: List of template parameters. + :vartype template_parameters: str + """ + + _attribute_map = { + 'template_parameters': {'key': 'templateParameters', 'type': 'str'}, + } + + def __init__( + self, + *, + template_parameters: Optional[str] = None, + **kwargs + ): + """ + :keyword template_parameters: List of template parameters. + :paramtype template_parameters: str + """ + super(ArmTemplateMappingRuleProfile, self).__init__(**kwargs) + self.template_parameters = template_parameters + + +class ArtifactAccessCredential(msrest.serialization.Model): + """The artifact manifest credential definition. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureContainerRegistryScopedTokenCredential, AzureStorageAccountCredential. + + All required parameters must be populated in order to send to Azure. + + :ivar credential_type: Required. The credential type.Constant filled by server. Possible values + include: "Unknown", "AzureContainerRegistryScopedToken", "AzureStorageAccountToken". + :vartype credential_type: str or ~Microsoft.HybridNetwork.models.CredentialType + """ + + _validation = { + 'credential_type': {'required': True}, + } + + _attribute_map = { + 'credential_type': {'key': 'credentialType', 'type': 'str'}, + } + + _subtype_map = { + 'credential_type': {'AzureContainerRegistryScopedToken': 'AzureContainerRegistryScopedTokenCredential', 'AzureStorageAccountToken': 'AzureStorageAccountCredential'} + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ArtifactAccessCredential, self).__init__(**kwargs) + self.credential_type = None # type: Optional[str] + + +class ArtifactChangeState(msrest.serialization.Model): + """The artifact updating request payload. + + :ivar properties: Artifact update state properties. + :vartype properties: ~Microsoft.HybridNetwork.models.ArtifactChangeStateProperties + """ + + _attribute_map = { + 'properties': {'key': 'properties', 'type': 'ArtifactChangeStateProperties'}, + } + + def __init__( + self, + *, + properties: Optional["ArtifactChangeStateProperties"] = None, + **kwargs + ): + """ + :keyword properties: Artifact update state properties. + :paramtype properties: ~Microsoft.HybridNetwork.models.ArtifactChangeStateProperties + """ + super(ArtifactChangeState, self).__init__(**kwargs) + self.properties = properties + + +class ArtifactChangeStateProperties(msrest.serialization.Model): + """The artifact update state properties. + + :ivar artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :vartype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + + _attribute_map = { + 'artifact_state': {'key': 'artifactState', 'type': 'str'}, + } + + def __init__( + self, + *, + artifact_state: Optional[Union[str, "ArtifactState"]] = None, + **kwargs + ): + """ + :keyword artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :paramtype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + super(ArtifactChangeStateProperties, self).__init__(**kwargs) + self.artifact_state = artifact_state + + +class Resource(msrest.serialization.Model): + """Common fields that are returned in the response for all Azure Resource Manager resources. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(Resource, self).__init__(**kwargs) + self.id = None + self.name = None + self.type = None + self.system_data = None + + +class TrackedResource(Resource): + """The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + """ + super(TrackedResource, self).__init__(**kwargs) + self.tags = tags + self.location = location + + +class ArtifactManifest(TrackedResource): + """Artifact manifest properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the ArtifactManifest resource. Possible + values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar artifact_manifest_state: The artifact manifest state. Possible values include: "Unknown", + "Uploading", "Uploaded", "Validating", "ValidationFailed", "Succeeded". + :vartype artifact_manifest_state: str or ~Microsoft.HybridNetwork.models.ArtifactManifestState + :ivar artifacts: The artifacts list. + :vartype artifacts: list[~Microsoft.HybridNetwork.models.ManifestArtifactFormat] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'artifact_manifest_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'artifact_manifest_state': {'key': 'properties.artifactManifestState', 'type': 'str'}, + 'artifacts': {'key': 'properties.artifacts', 'type': '[ManifestArtifactFormat]'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + artifacts: Optional[List["ManifestArtifactFormat"]] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword artifacts: The artifacts list. + :paramtype artifacts: list[~Microsoft.HybridNetwork.models.ManifestArtifactFormat] + """ + super(ArtifactManifest, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + self.artifact_manifest_state = None + self.artifacts = artifacts + + +class ArtifactManifestListResult(msrest.serialization.Model): + """A list of artifact manifests. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of artifact manifests. + :vartype value: list[~Microsoft.HybridNetwork.models.ArtifactManifest] + :ivar next_link: The URI to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ArtifactManifest]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["ArtifactManifest"]] = None, + **kwargs + ): + """ + :keyword value: A list of artifact manifests. + :paramtype value: list[~Microsoft.HybridNetwork.models.ArtifactManifest] + """ + super(ArtifactManifestListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class ArtifactManifestUpdateState(msrest.serialization.Model): + """The artifact manifest updating request payload. Only the 'Uploaded' state is allowed for updates. Other states are used for internal state transitioning. + + :ivar artifact_manifest_state: The artifact manifest state. Possible values include: "Unknown", + "Uploading", "Uploaded", "Validating", "ValidationFailed", "Succeeded". + :vartype artifact_manifest_state: str or ~Microsoft.HybridNetwork.models.ArtifactManifestState + """ + + _attribute_map = { + 'artifact_manifest_state': {'key': 'artifactManifestState', 'type': 'str'}, + } + + def __init__( + self, + *, + artifact_manifest_state: Optional[Union[str, "ArtifactManifestState"]] = None, + **kwargs + ): + """ + :keyword artifact_manifest_state: The artifact manifest state. Possible values include: + "Unknown", "Uploading", "Uploaded", "Validating", "ValidationFailed", "Succeeded". + :paramtype artifact_manifest_state: str or + ~Microsoft.HybridNetwork.models.ArtifactManifestState + """ + super(ArtifactManifestUpdateState, self).__init__(**kwargs) + self.artifact_manifest_state = artifact_manifest_state + + +class ArtifactProfile(msrest.serialization.Model): + """Artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + *, + artifact_store: Optional["ReferencedResource"] = None, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(ArtifactProfile, self).__init__(**kwargs) + self.artifact_store = artifact_store + + +class ArtifactStore(TrackedResource): + """Artifact store properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the application groups resource. Possible + values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar store_type: The artifact store type. Possible values include: "Unknown", + "AzureContainerRegistry", "AzureStorageAccount". + :vartype store_type: str or ~Microsoft.HybridNetwork.models.ArtifactStoreType + :ivar replication_strategy: The replication strategy. Possible values include: "Unknown", + "SingleReplication", "GeoReplication". + :vartype replication_strategy: str or + ~Microsoft.HybridNetwork.models.ArtifactReplicationStrategy + :ivar managed_resource_group_configuration: + :vartype managed_resource_group_configuration: + ~Microsoft.HybridNetwork.models.ArtifactStorePropertiesFormatManagedResourceGroupConfiguration + :ivar storage_resource_id: The created storage resource id. + :vartype storage_resource_id: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'storage_resource_id': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'store_type': {'key': 'properties.storeType', 'type': 'str'}, + 'replication_strategy': {'key': 'properties.replicationStrategy', 'type': 'str'}, + 'managed_resource_group_configuration': {'key': 'properties.managedResourceGroupConfiguration', 'type': 'ArtifactStorePropertiesFormatManagedResourceGroupConfiguration'}, + 'storage_resource_id': {'key': 'properties.storageResourceId', 'type': 'str'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + store_type: Optional[Union[str, "ArtifactStoreType"]] = None, + replication_strategy: Optional[Union[str, "ArtifactReplicationStrategy"]] = None, + managed_resource_group_configuration: Optional["ArtifactStorePropertiesFormatManagedResourceGroupConfiguration"] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword store_type: The artifact store type. Possible values include: "Unknown", + "AzureContainerRegistry", "AzureStorageAccount". + :paramtype store_type: str or ~Microsoft.HybridNetwork.models.ArtifactStoreType + :keyword replication_strategy: The replication strategy. Possible values include: "Unknown", + "SingleReplication", "GeoReplication". + :paramtype replication_strategy: str or + ~Microsoft.HybridNetwork.models.ArtifactReplicationStrategy + :keyword managed_resource_group_configuration: + :paramtype managed_resource_group_configuration: + ~Microsoft.HybridNetwork.models.ArtifactStorePropertiesFormatManagedResourceGroupConfiguration + """ + super(ArtifactStore, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + self.store_type = store_type + self.replication_strategy = replication_strategy + self.managed_resource_group_configuration = managed_resource_group_configuration + self.storage_resource_id = None + + +class ArtifactStoreListResult(msrest.serialization.Model): + """A list of artifact stores. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of artifact stores. + :vartype value: list[~Microsoft.HybridNetwork.models.ArtifactStore] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ArtifactStore]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["ArtifactStore"]] = None, + **kwargs + ): + """ + :keyword value: A list of artifact stores. + :paramtype value: list[~Microsoft.HybridNetwork.models.ArtifactStore] + """ + super(ArtifactStoreListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class ArtifactStorePropertiesFormatManagedResourceGroupConfiguration(msrest.serialization.Model): + """ArtifactStorePropertiesFormatManagedResourceGroupConfiguration. + + :ivar name: The managed resource group name. + :vartype name: str + :ivar location: The managed resource group location. + :vartype location: str + """ + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'location': {'key': 'location', 'type': 'str'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + location: Optional[str] = None, + **kwargs + ): + """ + :keyword name: The managed resource group name. + :paramtype name: str + :keyword location: The managed resource group location. + :paramtype location: str + """ + super(ArtifactStorePropertiesFormatManagedResourceGroupConfiguration, self).__init__(**kwargs) + self.name = name + self.location = location + + +class NFVIs(msrest.serialization.Model): + """The NFVI object. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureArcK8SClusterNFVIDetails, AzureCoreNFVIDetails, AzureOperatorNexusClusterNFVIDetails. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the nfvi. + :vartype name: str + :ivar nfvi_type: Required. The NFVI type.Constant filled by server. Possible values include: + "Unknown", "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + } + + _subtype_map = { + 'nfvi_type': {'AzureArcKubernetes': 'AzureArcK8SClusterNFVIDetails', 'AzureCore': 'AzureCoreNFVIDetails', 'AzureOperatorNexus': 'AzureOperatorNexusClusterNFVIDetails'} + } + + def __init__( + self, + *, + name: Optional[str] = None, + **kwargs + ): + """ + :keyword name: Name of the nfvi. + :paramtype name: str + """ + super(NFVIs, self).__init__(**kwargs) + self.name = name + self.nfvi_type = None # type: Optional[str] + + +class AzureArcK8SClusterNFVIDetails(NFVIs): + """The AzureArcK8sCluster NFVI detail. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the nfvi. + :vartype name: str + :ivar nfvi_type: Required. The NFVI type.Constant filled by server. Possible values include: + "Unknown", "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :ivar custom_location_reference: The reference to the custom location. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + custom_location_reference: Optional["ReferencedResource"] = None, + **kwargs + ): + """ + :keyword name: Name of the nfvi. + :paramtype name: str + :keyword custom_location_reference: The reference to the custom location. + :paramtype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(AzureArcK8SClusterNFVIDetails, self).__init__(name=name, **kwargs) + self.nfvi_type = 'AzureArcKubernetes' # type: str + self.custom_location_reference = custom_location_reference + + +class AzureArcKubernetesArtifactProfile(ArtifactProfile): + """Azure arc kubernetes artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar helm_artifact_profile: Helm artifact profile. + :vartype helm_artifact_profile: ~Microsoft.HybridNetwork.models.HelmArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'helm_artifact_profile': {'key': 'helmArtifactProfile', 'type': 'HelmArtifactProfile'}, + } + + def __init__( + self, + *, + artifact_store: Optional["ReferencedResource"] = None, + helm_artifact_profile: Optional["HelmArtifactProfile"] = None, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword helm_artifact_profile: Helm artifact profile. + :paramtype helm_artifact_profile: ~Microsoft.HybridNetwork.models.HelmArtifactProfile + """ + super(AzureArcKubernetesArtifactProfile, self).__init__(artifact_store=artifact_store, **kwargs) + self.helm_artifact_profile = helm_artifact_profile + + +class MappingRuleProfile(msrest.serialization.Model): + """Mapping rule profile properties. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + } + + def __init__( + self, + *, + application_enablement: Optional[Union[str, "ApplicationEnablement"]] = None, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + """ + super(MappingRuleProfile, self).__init__(**kwargs) + self.application_enablement = application_enablement + + +class AzureArcKubernetesDeployMappingRuleProfile(MappingRuleProfile): + """Azure arc kubernetes deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar helm_mapping_rule_profile: The helm mapping rule profile. + :vartype helm_mapping_rule_profile: ~Microsoft.HybridNetwork.models.HelmMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'helm_mapping_rule_profile': {'key': 'helmMappingRuleProfile', 'type': 'HelmMappingRuleProfile'}, + } + + def __init__( + self, + *, + application_enablement: Optional[Union[str, "ApplicationEnablement"]] = None, + helm_mapping_rule_profile: Optional["HelmMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword helm_mapping_rule_profile: The helm mapping rule profile. + :paramtype helm_mapping_rule_profile: ~Microsoft.HybridNetwork.models.HelmMappingRuleProfile + """ + super(AzureArcKubernetesDeployMappingRuleProfile, self).__init__(application_enablement=application_enablement, **kwargs) + self.helm_mapping_rule_profile = helm_mapping_rule_profile + + +class NetworkFunctionApplication(msrest.serialization.Model): + """Network function application definition. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(NetworkFunctionApplication, self).__init__(**kwargs) + self.name = name + self.depends_on_profile = depends_on_profile + + +class AzureArcKubernetesNetworkFunctionApplication(NetworkFunctionApplication): + """Azure arc kubernetes network function application definition. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureArcKubernetesHelmApplication. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "HelmPackage". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureArcKubernetesArtifactType + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + } + + _subtype_map = { + 'artifact_type': {'HelmPackage': 'AzureArcKubernetesHelmApplication'} + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(AzureArcKubernetesNetworkFunctionApplication, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.artifact_type = 'AzureArcKubernetesNetworkFunctionApplication' # type: str + + +class AzureArcKubernetesHelmApplication(AzureArcKubernetesNetworkFunctionApplication): + """Azure arc kubernetes helm application configurations. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "HelmPackage". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureArcKubernetesArtifactType + :ivar artifact_profile: Azure arc kubernetes artifact profile. + :vartype artifact_profile: ~Microsoft.HybridNetwork.models.AzureArcKubernetesArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureArcKubernetesDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureArcKubernetesArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureArcKubernetesDeployMappingRuleProfile'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + artifact_profile: Optional["AzureArcKubernetesArtifactProfile"] = None, + deploy_parameters_mapping_rule_profile: Optional["AzureArcKubernetesDeployMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure arc kubernetes artifact profile. + :paramtype artifact_profile: ~Microsoft.HybridNetwork.models.AzureArcKubernetesArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureArcKubernetesDeployMappingRuleProfile + """ + super(AzureArcKubernetesHelmApplication, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.artifact_type = 'HelmPackage' # type: str + self.artifact_profile = artifact_profile + self.deploy_parameters_mapping_rule_profile = deploy_parameters_mapping_rule_profile + + +class ContainerizedNetworkFunctionTemplate(msrest.serialization.Model): + """Containerized network function template. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureArcKubernetesNetworkFunctionTemplate. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureArcKubernetes". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.ContainerizedNetworkFunctionNFVIType + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + } + + _subtype_map = { + 'nfvi_type': {'AzureArcKubernetes': 'AzureArcKubernetesNetworkFunctionTemplate'} + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ContainerizedNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = None # type: Optional[str] + + +class AzureArcKubernetesNetworkFunctionTemplate(ContainerizedNetworkFunctionTemplate): + """Azure Arc kubernetes network function template. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureArcKubernetes". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.ContainerizedNetworkFunctionNFVIType + :ivar network_function_applications: Network function applications. + :vartype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureArcKubernetesNetworkFunctionApplication] + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'network_function_applications': {'key': 'networkFunctionApplications', 'type': '[AzureArcKubernetesNetworkFunctionApplication]'}, + } + + def __init__( + self, + *, + network_function_applications: Optional[List["AzureArcKubernetesNetworkFunctionApplication"]] = None, + **kwargs + ): + """ + :keyword network_function_applications: Network function applications. + :paramtype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureArcKubernetesNetworkFunctionApplication] + """ + super(AzureArcKubernetesNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = 'AzureArcKubernetes' # type: str + self.network_function_applications = network_function_applications + + +class AzureContainerRegistryScopedTokenCredential(ArtifactAccessCredential): + """The azure container registry scoped token credential definition. + + All required parameters must be populated in order to send to Azure. + + :ivar credential_type: Required. The credential type.Constant filled by server. Possible values + include: "Unknown", "AzureContainerRegistryScopedToken", "AzureStorageAccountToken". + :vartype credential_type: str or ~Microsoft.HybridNetwork.models.CredentialType + :ivar username: The username of the credential. + :vartype username: str + :ivar acr_token: The credential value. + :vartype acr_token: str + :ivar acr_server_url: The Acr server url. + :vartype acr_server_url: str + :ivar repositories: The repositories that could be accessed using the current credential. + :vartype repositories: list[str] + :ivar expiry: The UTC time when credential will expire. + :vartype expiry: ~datetime.datetime + """ + + _validation = { + 'credential_type': {'required': True}, + } + + _attribute_map = { + 'credential_type': {'key': 'credentialType', 'type': 'str'}, + 'username': {'key': 'username', 'type': 'str'}, + 'acr_token': {'key': 'acrToken', 'type': 'str'}, + 'acr_server_url': {'key': 'acrServerUrl', 'type': 'str'}, + 'repositories': {'key': 'repositories', 'type': '[str]'}, + 'expiry': {'key': 'expiry', 'type': 'iso-8601'}, + } + + def __init__( + self, + *, + username: Optional[str] = None, + acr_token: Optional[str] = None, + acr_server_url: Optional[str] = None, + repositories: Optional[List[str]] = None, + expiry: Optional[datetime.datetime] = None, + **kwargs + ): + """ + :keyword username: The username of the credential. + :paramtype username: str + :keyword acr_token: The credential value. + :paramtype acr_token: str + :keyword acr_server_url: The Acr server url. + :paramtype acr_server_url: str + :keyword repositories: The repositories that could be accessed using the current credential. + :paramtype repositories: list[str] + :keyword expiry: The UTC time when credential will expire. + :paramtype expiry: ~datetime.datetime + """ + super(AzureContainerRegistryScopedTokenCredential, self).__init__(**kwargs) + self.credential_type = 'AzureContainerRegistryScopedToken' # type: str + self.username = username + self.acr_token = acr_token + self.acr_server_url = acr_server_url + self.repositories = repositories + self.expiry = expiry + + +class AzureCoreArmTemplateArtifactProfile(ArtifactProfile): + """Azure template artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar template_artifact_profile: Template artifact profile. + :vartype template_artifact_profile: ~Microsoft.HybridNetwork.models.ArmTemplateArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'template_artifact_profile': {'key': 'templateArtifactProfile', 'type': 'ArmTemplateArtifactProfile'}, + } + + def __init__( + self, + *, + artifact_store: Optional["ReferencedResource"] = None, + template_artifact_profile: Optional["ArmTemplateArtifactProfile"] = None, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword template_artifact_profile: Template artifact profile. + :paramtype template_artifact_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateArtifactProfile + """ + super(AzureCoreArmTemplateArtifactProfile, self).__init__(artifact_store=artifact_store, **kwargs) + self.template_artifact_profile = template_artifact_profile + + +class AzureCoreArmTemplateDeployMappingRuleProfile(MappingRuleProfile): + """Azure template deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar template_mapping_rule_profile: The template mapping rule profile. + :vartype template_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'template_mapping_rule_profile': {'key': 'templateMappingRuleProfile', 'type': 'ArmTemplateMappingRuleProfile'}, + } + + def __init__( + self, + *, + application_enablement: Optional[Union[str, "ApplicationEnablement"]] = None, + template_mapping_rule_profile: Optional["ArmTemplateMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword template_mapping_rule_profile: The template mapping rule profile. + :paramtype template_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateMappingRuleProfile + """ + super(AzureCoreArmTemplateDeployMappingRuleProfile, self).__init__(application_enablement=application_enablement, **kwargs) + self.template_mapping_rule_profile = template_mapping_rule_profile + + +class AzureCoreDelegatedImageArtifactProfile(ArtifactProfile): + """Azure Image artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar image_artifact_profile: Image artifact profile. + :vartype image_artifact_profile: ~Microsoft.HybridNetwork.models.ImageArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'image_artifact_profile': {'key': 'imageArtifactProfile', 'type': 'ImageArtifactProfile'}, + } + + def __init__( + self, + *, + artifact_store: Optional["ReferencedResource"] = None, + image_artifact_profile: Optional["ImageArtifactProfile"] = None, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword image_artifact_profile: Image artifact profile. + :paramtype image_artifact_profile: ~Microsoft.HybridNetwork.models.ImageArtifactProfile + """ + super(AzureCoreDelegatedImageArtifactProfile, self).__init__(artifact_store=artifact_store, **kwargs) + self.image_artifact_profile = image_artifact_profile + + +class AzureCoreDelegatedImageDeployMappingRuleProfile(MappingRuleProfile): + """Azure Image deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar image_mapping_rule_profile: The Image mapping rule profile. + :vartype image_mapping_rule_profile: ~Microsoft.HybridNetwork.models.ImageMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'image_mapping_rule_profile': {'key': 'imageMappingRuleProfile', 'type': 'ImageMappingRuleProfile'}, + } + + def __init__( + self, + *, + application_enablement: Optional[Union[str, "ApplicationEnablement"]] = None, + image_mapping_rule_profile: Optional["ImageMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword image_mapping_rule_profile: The Image mapping rule profile. + :paramtype image_mapping_rule_profile: ~Microsoft.HybridNetwork.models.ImageMappingRuleProfile + """ + super(AzureCoreDelegatedImageDeployMappingRuleProfile, self).__init__(application_enablement=application_enablement, **kwargs) + self.image_mapping_rule_profile = image_mapping_rule_profile + + +class AzureCoreDelegatedNetworkFunctionApplication(NetworkFunctionApplication): + """Azure delegated network function application definition. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureCoreDelegatedNetworkFunctionImageApplication. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "ImageFile". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureCoreDelegatedArtifactType + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + } + + _subtype_map = { + 'artifact_type': {'ImageFile': 'AzureCoreDelegatedNetworkFunctionImageApplication'} + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(AzureCoreDelegatedNetworkFunctionApplication, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.artifact_type = 'AzureCoreDelegatedNetworkFunctionApplication' # type: str + + +class AzureCoreDelegatedNetworkFunctionImageApplication(AzureCoreDelegatedNetworkFunctionApplication): + """Azure core network function Image application definition. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "ImageFile". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureCoreDelegatedArtifactType + :ivar artifact_profile: Azure Image artifact profile. + :vartype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureCoreDelegatedImageArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreDelegatedImageDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureCoreDelegatedImageArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreDelegatedImageDeployMappingRuleProfile'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + artifact_profile: Optional["AzureCoreDelegatedImageArtifactProfile"] = None, + deploy_parameters_mapping_rule_profile: Optional["AzureCoreDelegatedImageDeployMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure Image artifact profile. + :paramtype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureCoreDelegatedImageArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreDelegatedImageDeployMappingRuleProfile + """ + super(AzureCoreDelegatedNetworkFunctionImageApplication, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.artifact_type = 'ImageFile' # type: str + self.artifact_profile = artifact_profile + self.deploy_parameters_mapping_rule_profile = deploy_parameters_mapping_rule_profile + + +class DelegatedNetworkFunctionTemplate(msrest.serialization.Model): + """Delegated network function template. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureCoreDelegatedNetworkFunctionTemplate. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureCore". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.DelegatedNetworkFunctionNFVIType + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + } + + _subtype_map = { + 'nfvi_type': {'AzureCore': 'AzureCoreDelegatedNetworkFunctionTemplate'} + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(DelegatedNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = None # type: Optional[str] + + +class AzureCoreDelegatedNetworkFunctionTemplate(DelegatedNetworkFunctionTemplate): + """Azure delegated network function template. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureCore". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.DelegatedNetworkFunctionNFVIType + :ivar network_function_applications: Network function applications. + :vartype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureCoreDelegatedNetworkFunctionApplication] + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'network_function_applications': {'key': 'networkFunctionApplications', 'type': '[AzureCoreDelegatedNetworkFunctionApplication]'}, + } + + def __init__( + self, + *, + network_function_applications: Optional[List["AzureCoreDelegatedNetworkFunctionApplication"]] = None, + **kwargs + ): + """ + :keyword network_function_applications: Network function applications. + :paramtype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureCoreDelegatedNetworkFunctionApplication] + """ + super(AzureCoreDelegatedNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = 'AzureCore' # type: str + self.network_function_applications = network_function_applications + + +class AzureCoreNetworkFunctionApplication(NetworkFunctionApplication): + """Azure virtual network function application definition. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureCoreNetworkFunctionArmTemplateApplication, AzureCoreNetworkFunctionVhdApplication. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "VhdImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureCoreArtifactType + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + } + + _subtype_map = { + 'artifact_type': {'ArmTemplate': 'AzureCoreNetworkFunctionArmTemplateApplication', 'VhdImageFile': 'AzureCoreNetworkFunctionVhdApplication'} + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(AzureCoreNetworkFunctionApplication, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.artifact_type = 'AzureCoreNetworkFunctionApplication' # type: str + + +class AzureCoreNetworkFunctionArmTemplateApplication(AzureCoreNetworkFunctionApplication): + """Azure core network function Template application definition. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "VhdImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureCoreArtifactType + :ivar artifact_profile: Azure template artifact profile. + :vartype artifact_profile: ~Microsoft.HybridNetwork.models.AzureCoreArmTemplateArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreArmTemplateDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureCoreArmTemplateArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreArmTemplateDeployMappingRuleProfile'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + artifact_profile: Optional["AzureCoreArmTemplateArtifactProfile"] = None, + deploy_parameters_mapping_rule_profile: Optional["AzureCoreArmTemplateDeployMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure template artifact profile. + :paramtype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureCoreArmTemplateArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreArmTemplateDeployMappingRuleProfile + """ + super(AzureCoreNetworkFunctionArmTemplateApplication, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.artifact_type = 'ArmTemplate' # type: str + self.artifact_profile = artifact_profile + self.deploy_parameters_mapping_rule_profile = deploy_parameters_mapping_rule_profile + + +class VirtualNetworkFunctionTemplate(msrest.serialization.Model): + """Virtual network function template. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureCoreNetworkFunctionTemplate, AzureOperatorNexusNetworkFunctionTemplate. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.VirtualNetworkFunctionNFVIType + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + } + + _subtype_map = { + 'nfvi_type': {'AzureCore': 'AzureCoreNetworkFunctionTemplate', 'AzureOperatorNexus': 'AzureOperatorNexusNetworkFunctionTemplate'} + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(VirtualNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = None # type: Optional[str] + + +class AzureCoreNetworkFunctionTemplate(VirtualNetworkFunctionTemplate): + """Azure virtual network function template. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.VirtualNetworkFunctionNFVIType + :ivar network_function_applications: Network function applications. + :vartype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureCoreNetworkFunctionApplication] + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'network_function_applications': {'key': 'networkFunctionApplications', 'type': '[AzureCoreNetworkFunctionApplication]'}, + } + + def __init__( + self, + *, + network_function_applications: Optional[List["AzureCoreNetworkFunctionApplication"]] = None, + **kwargs + ): + """ + :keyword network_function_applications: Network function applications. + :paramtype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureCoreNetworkFunctionApplication] + """ + super(AzureCoreNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = 'AzureCore' # type: str + self.network_function_applications = network_function_applications + + +class AzureCoreNetworkFunctionVhdApplication(AzureCoreNetworkFunctionApplication): + """Azure core network function vhd application definition. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "VhdImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureCoreArtifactType + :ivar artifact_profile: Azure vhd image artifact profile. + :vartype artifact_profile: ~Microsoft.HybridNetwork.models.AzureCoreVhdImageArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreVhdImageDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureCoreVhdImageArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreVhdImageDeployMappingRuleProfile'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + artifact_profile: Optional["AzureCoreVhdImageArtifactProfile"] = None, + deploy_parameters_mapping_rule_profile: Optional["AzureCoreVhdImageDeployMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure vhd image artifact profile. + :paramtype artifact_profile: ~Microsoft.HybridNetwork.models.AzureCoreVhdImageArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreVhdImageDeployMappingRuleProfile + """ + super(AzureCoreNetworkFunctionVhdApplication, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.artifact_type = 'VhdImageFile' # type: str + self.artifact_profile = artifact_profile + self.deploy_parameters_mapping_rule_profile = deploy_parameters_mapping_rule_profile + + +class AzureCoreNFVIDetails(NFVIs): + """The Azure Core NFVI detail. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the nfvi. + :vartype name: str + :ivar nfvi_type: Required. The NFVI type.Constant filled by server. Possible values include: + "Unknown", "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :ivar location: Location of the Azure core. + :vartype location: str + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'location': {'key': 'location', 'type': 'str'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + location: Optional[str] = None, + **kwargs + ): + """ + :keyword name: Name of the nfvi. + :paramtype name: str + :keyword location: Location of the Azure core. + :paramtype location: str + """ + super(AzureCoreNFVIDetails, self).__init__(name=name, **kwargs) + self.nfvi_type = 'AzureCore' # type: str + self.location = location + + +class AzureCoreVhdImageArtifactProfile(ArtifactProfile): + """Azure vhd artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar vhd_artifact_profile: Vhd artifact profile. + :vartype vhd_artifact_profile: ~Microsoft.HybridNetwork.models.VhdImageArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'vhd_artifact_profile': {'key': 'vhdArtifactProfile', 'type': 'VhdImageArtifactProfile'}, + } + + def __init__( + self, + *, + artifact_store: Optional["ReferencedResource"] = None, + vhd_artifact_profile: Optional["VhdImageArtifactProfile"] = None, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword vhd_artifact_profile: Vhd artifact profile. + :paramtype vhd_artifact_profile: ~Microsoft.HybridNetwork.models.VhdImageArtifactProfile + """ + super(AzureCoreVhdImageArtifactProfile, self).__init__(artifact_store=artifact_store, **kwargs) + self.vhd_artifact_profile = vhd_artifact_profile + + +class AzureCoreVhdImageDeployMappingRuleProfile(MappingRuleProfile): + """Azure vhd deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar vhd_image_mapping_rule_profile: The vhd mapping rule profile. + :vartype vhd_image_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.VhdImageMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'vhd_image_mapping_rule_profile': {'key': 'vhdImageMappingRuleProfile', 'type': 'VhdImageMappingRuleProfile'}, + } + + def __init__( + self, + *, + application_enablement: Optional[Union[str, "ApplicationEnablement"]] = None, + vhd_image_mapping_rule_profile: Optional["VhdImageMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword vhd_image_mapping_rule_profile: The vhd mapping rule profile. + :paramtype vhd_image_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.VhdImageMappingRuleProfile + """ + super(AzureCoreVhdImageDeployMappingRuleProfile, self).__init__(application_enablement=application_enablement, **kwargs) + self.vhd_image_mapping_rule_profile = vhd_image_mapping_rule_profile + + +class AzureKubernetesServiceNetworkFunctionReadyK8S(NetworkFunctionReadyK8SPropertiesFormat): + """Azure based kubernetes service cluster prerequisite properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the NetworkFunctionReadyK8s resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar cluster_type: Required. The cluster type.Constant filled by server. Possible values + include: "AzureKubernetesService", "ArcConnectedK8s", "HybridAKS". + :vartype cluster_type: str or ~Microsoft.HybridNetwork.models.ClusterType + :ivar cluster_reference: Required. The k8s/Connected cluster ARM id. + :vartype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar custom_location_reference: The read only custom location ARM id. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar user_assigned_managed_identity: Required. The User Assigned Managed Identity ARM id + enabled on the AKS cluster. + :vartype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'cluster_type': {'required': True}, + 'cluster_reference': {'required': True}, + 'custom_location_reference': {'readonly': True}, + 'user_assigned_managed_identity': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'cluster_type': {'key': 'clusterType', 'type': 'str'}, + 'cluster_reference': {'key': 'clusterReference', 'type': 'ReferencedResource'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + 'user_assigned_managed_identity': {'key': 'userAssignedManagedIdentity', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + *, + cluster_reference: "ReferencedResource", + user_assigned_managed_identity: "ReferencedResource", + **kwargs + ): + """ + :keyword cluster_reference: Required. The k8s/Connected cluster ARM id. + :paramtype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword user_assigned_managed_identity: Required. The User Assigned Managed Identity ARM id + enabled on the AKS cluster. + :paramtype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(AzureKubernetesServiceNetworkFunctionReadyK8S, self).__init__(cluster_reference=cluster_reference, **kwargs) + self.cluster_type = 'AzureKubernetesService' # type: str + self.user_assigned_managed_identity = user_assigned_managed_identity + + +class AzureOperatorNexusArmTemplateArtifactProfile(ArtifactProfile): + """Azure Operator Distributed Services vhd artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar template_artifact_profile: Template artifact profile. + :vartype template_artifact_profile: ~Microsoft.HybridNetwork.models.ArmTemplateArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'template_artifact_profile': {'key': 'templateArtifactProfile', 'type': 'ArmTemplateArtifactProfile'}, + } + + def __init__( + self, + *, + artifact_store: Optional["ReferencedResource"] = None, + template_artifact_profile: Optional["ArmTemplateArtifactProfile"] = None, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword template_artifact_profile: Template artifact profile. + :paramtype template_artifact_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateArtifactProfile + """ + super(AzureOperatorNexusArmTemplateArtifactProfile, self).__init__(artifact_store=artifact_store, **kwargs) + self.template_artifact_profile = template_artifact_profile + + +class AzureOperatorNexusArmTemplateDeployMappingRuleProfile(MappingRuleProfile): + """Azure Operator Distributed Services template deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar template_mapping_rule_profile: The template mapping rule profile. + :vartype template_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'template_mapping_rule_profile': {'key': 'templateMappingRuleProfile', 'type': 'ArmTemplateMappingRuleProfile'}, + } + + def __init__( + self, + *, + application_enablement: Optional[Union[str, "ApplicationEnablement"]] = None, + template_mapping_rule_profile: Optional["ArmTemplateMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword template_mapping_rule_profile: The template mapping rule profile. + :paramtype template_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.ArmTemplateMappingRuleProfile + """ + super(AzureOperatorNexusArmTemplateDeployMappingRuleProfile, self).__init__(application_enablement=application_enablement, **kwargs) + self.template_mapping_rule_profile = template_mapping_rule_profile + + +class AzureOperatorNexusClusterNFVIDetails(NFVIs): + """The AzureOperatorNexusCluster NFVI detail. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the nfvi. + :vartype name: str + :ivar nfvi_type: Required. The NFVI type.Constant filled by server. Possible values include: + "Unknown", "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :ivar custom_location_reference: The reference to the custom location. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + custom_location_reference: Optional["ReferencedResource"] = None, + **kwargs + ): + """ + :keyword name: Name of the nfvi. + :paramtype name: str + :keyword custom_location_reference: The reference to the custom location. + :paramtype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(AzureOperatorNexusClusterNFVIDetails, self).__init__(name=name, **kwargs) + self.nfvi_type = 'AzureOperatorNexus' # type: str + self.custom_location_reference = custom_location_reference + + +class AzureOperatorNexusImageArtifactProfile(ArtifactProfile): + """Azure Operator Distributed Services image artifact profile properties. + + :ivar artifact_store: The reference to artifact store. + :vartype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar image_artifact_profile: Image artifact profile. + :vartype image_artifact_profile: ~Microsoft.HybridNetwork.models.ImageArtifactProfile + """ + + _attribute_map = { + 'artifact_store': {'key': 'artifactStore', 'type': 'ReferencedResource'}, + 'image_artifact_profile': {'key': 'imageArtifactProfile', 'type': 'ImageArtifactProfile'}, + } + + def __init__( + self, + *, + artifact_store: Optional["ReferencedResource"] = None, + image_artifact_profile: Optional["ImageArtifactProfile"] = None, + **kwargs + ): + """ + :keyword artifact_store: The reference to artifact store. + :paramtype artifact_store: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword image_artifact_profile: Image artifact profile. + :paramtype image_artifact_profile: ~Microsoft.HybridNetwork.models.ImageArtifactProfile + """ + super(AzureOperatorNexusImageArtifactProfile, self).__init__(artifact_store=artifact_store, **kwargs) + self.image_artifact_profile = image_artifact_profile + + +class AzureOperatorNexusImageDeployMappingRuleProfile(MappingRuleProfile): + """Azure Operator Distributed Services image deploy mapping rule profile. + + :ivar application_enablement: The application enablement. Possible values include: "Unknown", + "Enabled", "Disabled". + :vartype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :ivar image_mapping_rule_profile: The vhd mapping rule profile. + :vartype image_mapping_rule_profile: ~Microsoft.HybridNetwork.models.ImageMappingRuleProfile + """ + + _attribute_map = { + 'application_enablement': {'key': 'applicationEnablement', 'type': 'str'}, + 'image_mapping_rule_profile': {'key': 'imageMappingRuleProfile', 'type': 'ImageMappingRuleProfile'}, + } + + def __init__( + self, + *, + application_enablement: Optional[Union[str, "ApplicationEnablement"]] = None, + image_mapping_rule_profile: Optional["ImageMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword application_enablement: The application enablement. Possible values include: + "Unknown", "Enabled", "Disabled". + :paramtype application_enablement: str or ~Microsoft.HybridNetwork.models.ApplicationEnablement + :keyword image_mapping_rule_profile: The vhd mapping rule profile. + :paramtype image_mapping_rule_profile: ~Microsoft.HybridNetwork.models.ImageMappingRuleProfile + """ + super(AzureOperatorNexusImageDeployMappingRuleProfile, self).__init__(application_enablement=application_enablement, **kwargs) + self.image_mapping_rule_profile = image_mapping_rule_profile + + +class AzureOperatorNexusNetworkFunctionApplication(NetworkFunctionApplication): + """Azure Operator Distributed Services network function application definition. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: AzureOperatorNexusNetworkFunctionArmTemplateApplication, AzureOperatorNexusNetworkFunctionImageApplication. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "ImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureOperatorNexusArtifactType + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + } + + _subtype_map = { + 'artifact_type': {'ArmTemplate': 'AzureOperatorNexusNetworkFunctionArmTemplateApplication', 'ImageFile': 'AzureOperatorNexusNetworkFunctionImageApplication'} + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + """ + super(AzureOperatorNexusNetworkFunctionApplication, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.artifact_type = 'AzureOperatorNexusNetworkFunctionApplication' # type: str + + +class AzureOperatorNexusNetworkFunctionArmTemplateApplication(AzureOperatorNexusNetworkFunctionApplication): + """Azure Operator Distributed Services network function Template application definition. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "ImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureOperatorNexusArtifactType + :ivar artifact_profile: Azure Operator Distributed Services Template artifact profile. + :vartype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusArmTemplateArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusArmTemplateDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureOperatorNexusArmTemplateArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureOperatorNexusArmTemplateDeployMappingRuleProfile'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + artifact_profile: Optional["AzureOperatorNexusArmTemplateArtifactProfile"] = None, + deploy_parameters_mapping_rule_profile: Optional["AzureOperatorNexusArmTemplateDeployMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure Operator Distributed Services Template artifact profile. + :paramtype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusArmTemplateArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusArmTemplateDeployMappingRuleProfile + """ + super(AzureOperatorNexusNetworkFunctionArmTemplateApplication, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.artifact_type = 'ArmTemplate' # type: str + self.artifact_profile = artifact_profile + self.deploy_parameters_mapping_rule_profile = deploy_parameters_mapping_rule_profile + + +class AzureOperatorNexusNetworkFunctionImageApplication(AzureOperatorNexusNetworkFunctionApplication): + """Azure Operator Distributed Services network function image application definition. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the network function application. + :vartype name: str + :ivar depends_on_profile: Depends on profile definition. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar artifact_type: Required. The artifact type.Constant filled by server. Possible values + include: "Unknown", "ImageFile", "ArmTemplate". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.AzureOperatorNexusArtifactType + :ivar artifact_profile: Azure Operator Distributed Services image artifact profile. + :vartype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusImageArtifactProfile + :ivar deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusImageDeployMappingRuleProfile + """ + + _validation = { + 'artifact_type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'AzureOperatorNexusImageArtifactProfile'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureOperatorNexusImageDeployMappingRuleProfile'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + artifact_profile: Optional["AzureOperatorNexusImageArtifactProfile"] = None, + deploy_parameters_mapping_rule_profile: Optional["AzureOperatorNexusImageDeployMappingRuleProfile"] = None, + **kwargs + ): + """ + :keyword name: The name of the network function application. + :paramtype name: str + :keyword depends_on_profile: Depends on profile definition. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword artifact_profile: Azure Operator Distributed Services image artifact profile. + :paramtype artifact_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusImageArtifactProfile + :keyword deploy_parameters_mapping_rule_profile: Deploy mapping rule profile. + :paramtype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureOperatorNexusImageDeployMappingRuleProfile + """ + super(AzureOperatorNexusNetworkFunctionImageApplication, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.artifact_type = 'ImageFile' # type: str + self.artifact_profile = artifact_profile + self.deploy_parameters_mapping_rule_profile = deploy_parameters_mapping_rule_profile + + +class AzureOperatorNexusNetworkFunctionTemplate(VirtualNetworkFunctionTemplate): + """Azure Operator Distributed Services network function template. + + All required parameters must be populated in order to send to Azure. + + :ivar nfvi_type: Required. The network function type.Constant filled by server. Possible values + include: "Unknown", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.VirtualNetworkFunctionNFVIType + :ivar network_function_applications: Network function applications. + :vartype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureOperatorNexusNetworkFunctionApplication] + """ + + _validation = { + 'nfvi_type': {'required': True}, + } + + _attribute_map = { + 'nfvi_type': {'key': 'nfviType', 'type': 'str'}, + 'network_function_applications': {'key': 'networkFunctionApplications', 'type': '[AzureOperatorNexusNetworkFunctionApplication]'}, + } + + def __init__( + self, + *, + network_function_applications: Optional[List["AzureOperatorNexusNetworkFunctionApplication"]] = None, + **kwargs + ): + """ + :keyword network_function_applications: Network function applications. + :paramtype network_function_applications: + list[~Microsoft.HybridNetwork.models.AzureOperatorNexusNetworkFunctionApplication] + """ + super(AzureOperatorNexusNetworkFunctionTemplate, self).__init__(**kwargs) + self.nfvi_type = 'AzureOperatorNexus' # type: str + self.network_function_applications = network_function_applications + + +class AzureStorageAccountContainerCredential(msrest.serialization.Model): + """The azure storage account container credential definition. + + :ivar container_name: The storage account container name. + :vartype container_name: str + :ivar container_sas_uri: The storage account container sas uri. + :vartype container_sas_uri: str + """ + + _attribute_map = { + 'container_name': {'key': 'containerName', 'type': 'str'}, + 'container_sas_uri': {'key': 'containerSasUri', 'type': 'str'}, + } + + def __init__( + self, + *, + container_name: Optional[str] = None, + container_sas_uri: Optional[str] = None, + **kwargs + ): + """ + :keyword container_name: The storage account container name. + :paramtype container_name: str + :keyword container_sas_uri: The storage account container sas uri. + :paramtype container_sas_uri: str + """ + super(AzureStorageAccountContainerCredential, self).__init__(**kwargs) + self.container_name = container_name + self.container_sas_uri = container_sas_uri + + +class AzureStorageAccountCredential(ArtifactAccessCredential): + """The azure storage account credential definition. + + All required parameters must be populated in order to send to Azure. + + :ivar credential_type: Required. The credential type.Constant filled by server. Possible values + include: "Unknown", "AzureContainerRegistryScopedToken", "AzureStorageAccountToken". + :vartype credential_type: str or ~Microsoft.HybridNetwork.models.CredentialType + :ivar storage_account_id: The storage account Id. + :vartype storage_account_id: str + :ivar container_credentials: The containers that could be accessed using the current + credential. + :vartype container_credentials: + list[~Microsoft.HybridNetwork.models.AzureStorageAccountContainerCredential] + :ivar expiry: The UTC time when credential will expire. + :vartype expiry: ~datetime.datetime + """ + + _validation = { + 'credential_type': {'required': True}, + } + + _attribute_map = { + 'credential_type': {'key': 'credentialType', 'type': 'str'}, + 'storage_account_id': {'key': 'storageAccountId', 'type': 'str'}, + 'container_credentials': {'key': 'containerCredentials', 'type': '[AzureStorageAccountContainerCredential]'}, + 'expiry': {'key': 'expiry', 'type': 'iso-8601'}, + } + + def __init__( + self, + *, + storage_account_id: Optional[str] = None, + container_credentials: Optional[List["AzureStorageAccountContainerCredential"]] = None, + expiry: Optional[datetime.datetime] = None, + **kwargs + ): + """ + :keyword storage_account_id: The storage account Id. + :paramtype storage_account_id: str + :keyword container_credentials: The containers that could be accessed using the current + credential. + :paramtype container_credentials: + list[~Microsoft.HybridNetwork.models.AzureStorageAccountContainerCredential] + :keyword expiry: The UTC time when credential will expire. + :paramtype expiry: ~datetime.datetime + """ + super(AzureStorageAccountCredential, self).__init__(**kwargs) + self.credential_type = 'AzureStorageAccountToken' # type: str + self.storage_account_id = storage_account_id + self.container_credentials = container_credentials + self.expiry = expiry + + +class ProxyResource(Resource): + """The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ProxyResource, self).__init__(**kwargs) + + +class Component(ProxyResource): + """The component sub resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar provisioning_state: The provisioning state of the component resource. Possible values + include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", "Deleted", + "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar deployment_profile: The JSON-serialized deployment profile of the component resource. + :vartype deployment_profile: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'provisioning_state': {'readonly': True}, + 'deployment_profile': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'deployment_profile': {'key': 'properties.deploymentProfile', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(Component, self).__init__(**kwargs) + self.provisioning_state = None + self.deployment_profile = None + + +class ComponentListResult(msrest.serialization.Model): + """Response for list component API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of component resources in a networkFunction. + :vartype value: list[~Microsoft.HybridNetwork.models.Component] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[Component]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["Component"]] = None, + **kwargs + ): + """ + :keyword value: A list of component resources in a networkFunction. + :paramtype value: list[~Microsoft.HybridNetwork.models.Component] + """ + super(ComponentListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class ConfigurationDefinitionResourceElementTemplate(msrest.serialization.Model): + """The configuration definition resource element template details. + + :ivar name: The name of the network function to apply the configuration to. + :vartype name: str + :ivar nf_agent_type: The type of NF agent that should handle this configuration. + :vartype nf_agent_type: str + :ivar configuration_type: The type of configuration to be handled by the NF agent. + :vartype configuration_type: str + :ivar configuration_generation_type: The configuration generation type. Possible values + include: "Unknown", "HandlebarTemplate". + :vartype configuration_generation_type: str or + ~Microsoft.HybridNetwork.models.ConfigurationGenerationType + :ivar parameter_values: Name and value pairs that define the parameter values. It can be a well + formed escaped JSON string. + :vartype parameter_values: str + :ivar artifact_profile: Artifact profile properties. + :vartype artifact_profile: ~Microsoft.HybridNetwork.models.NSDArtifactProfile + :ivar extra_artifact_profiles: List of extra artifact profiles required by the configuration. + :vartype extra_artifact_profiles: list[~Microsoft.HybridNetwork.models.NSDArtifactProfile] + """ + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'nf_agent_type': {'key': 'nfAgentType', 'type': 'str'}, + 'configuration_type': {'key': 'configurationType', 'type': 'str'}, + 'configuration_generation_type': {'key': 'configurationGenerationType', 'type': 'str'}, + 'parameter_values': {'key': 'parameterValues', 'type': 'str'}, + 'artifact_profile': {'key': 'artifactProfile', 'type': 'NSDArtifactProfile'}, + 'extra_artifact_profiles': {'key': 'extraArtifactProfiles', 'type': '[NSDArtifactProfile]'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + nf_agent_type: Optional[str] = None, + configuration_type: Optional[str] = None, + configuration_generation_type: Optional[Union[str, "ConfigurationGenerationType"]] = None, + parameter_values: Optional[str] = None, + artifact_profile: Optional["NSDArtifactProfile"] = None, + extra_artifact_profiles: Optional[List["NSDArtifactProfile"]] = None, + **kwargs + ): + """ + :keyword name: The name of the network function to apply the configuration to. + :paramtype name: str + :keyword nf_agent_type: The type of NF agent that should handle this configuration. + :paramtype nf_agent_type: str + :keyword configuration_type: The type of configuration to be handled by the NF agent. + :paramtype configuration_type: str + :keyword configuration_generation_type: The configuration generation type. Possible values + include: "Unknown", "HandlebarTemplate". + :paramtype configuration_generation_type: str or + ~Microsoft.HybridNetwork.models.ConfigurationGenerationType + :keyword parameter_values: Name and value pairs that define the parameter values. It can be a + well formed escaped JSON string. + :paramtype parameter_values: str + :keyword artifact_profile: Artifact profile properties. + :paramtype artifact_profile: ~Microsoft.HybridNetwork.models.NSDArtifactProfile + :keyword extra_artifact_profiles: List of extra artifact profiles required by the + configuration. + :paramtype extra_artifact_profiles: list[~Microsoft.HybridNetwork.models.NSDArtifactProfile] + """ + super(ConfigurationDefinitionResourceElementTemplate, self).__init__(**kwargs) + self.name = name + self.nf_agent_type = nf_agent_type + self.configuration_type = configuration_type + self.configuration_generation_type = configuration_generation_type + self.parameter_values = parameter_values + self.artifact_profile = artifact_profile + self.extra_artifact_profiles = extra_artifact_profiles + + +class ConfigurationDefinitionResourceElementTemplateDetails(ResourceElementTemplate): + """The configuration definition resource element template details. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the resource element template. + :vartype name: str + :ivar type: Required. The resource element template type.Constant filled by server. Possible + values include: "Unknown", "ArmResourceDefinition", "ConfigurationDefinition", + "NetworkFunctionDefinition". + :vartype type: str or ~Microsoft.HybridNetwork.models.Type + :ivar depends_on_profile: The depends on profile. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar configuration: The resource element template type. + :vartype configuration: + ~Microsoft.HybridNetwork.models.ConfigurationDefinitionResourceElementTemplate + """ + + _validation = { + 'type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'configuration': {'key': 'configuration', 'type': 'ConfigurationDefinitionResourceElementTemplate'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + configuration: Optional["ConfigurationDefinitionResourceElementTemplate"] = None, + **kwargs + ): + """ + :keyword name: Name of the resource element template. + :paramtype name: str + :keyword depends_on_profile: The depends on profile. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword configuration: The resource element template type. + :paramtype configuration: + ~Microsoft.HybridNetwork.models.ConfigurationDefinitionResourceElementTemplate + """ + super(ConfigurationDefinitionResourceElementTemplateDetails, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.type = 'ConfigurationDefinition' # type: str + self.configuration = configuration + + +class ConfigurationGroupSchema(TrackedResource): + """Configuration group schema resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the Configuration group schema resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The configuration group schema version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar schema_definition: Name and value pairs that define the configuration value. It can be a + well formed escaped JSON string. + :vartype schema_definition: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'version_state': {'key': 'properties.versionState', 'type': 'str'}, + 'schema_definition': {'key': 'properties.schemaDefinition', 'type': 'str'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + schema_definition: Optional[str] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword schema_definition: Name and value pairs that define the configuration value. It can be + a well formed escaped JSON string. + :paramtype schema_definition: str + """ + super(ConfigurationGroupSchema, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + self.version_state = None + self.schema_definition = schema_definition + + +class ConfigurationGroupSchemaListResult(msrest.serialization.Model): + """A list of configuration group schema resources. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of configuration group schema. + :vartype value: list[~Microsoft.HybridNetwork.models.ConfigurationGroupSchema] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ConfigurationGroupSchema]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["ConfigurationGroupSchema"]] = None, + **kwargs + ): + """ + :keyword value: A list of configuration group schema. + :paramtype value: list[~Microsoft.HybridNetwork.models.ConfigurationGroupSchema] + """ + super(ConfigurationGroupSchemaListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class ConfigurationGroupSchemaVersionUpdateState(msrest.serialization.Model): + """Publisher configuration group schema update request definition. + + :ivar version_state: The configuration group schema state. Possible values include: "Unknown", + "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + + _attribute_map = { + 'version_state': {'key': 'versionState', 'type': 'str'}, + } + + def __init__( + self, + *, + version_state: Optional[Union[str, "VersionState"]] = None, + **kwargs + ): + """ + :keyword version_state: The configuration group schema state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :paramtype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + super(ConfigurationGroupSchemaVersionUpdateState, self).__init__(**kwargs) + self.version_state = version_state + + +class ConfigurationGroupValue(TrackedResource): + """Hybrid configuration group value resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the site resource. Possible values include: + "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar publisher_name: The publisher name for the configuration group schema. + :vartype publisher_name: str + :ivar publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :vartype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :ivar configuration_group_schema_name: The configuration group schema name. + :vartype configuration_group_schema_name: str + :ivar configuration_group_schema_offering_location: The location of the configuration group + schema offering. + :vartype configuration_group_schema_offering_location: str + :ivar configuration_value: Name and value pairs that define the configuration value. It can be + a well formed escaped JSON string. + :vartype configuration_value: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'publisher_name': {'key': 'properties.publisherName', 'type': 'str'}, + 'publisher_scope': {'key': 'properties.publisherScope', 'type': 'str'}, + 'configuration_group_schema_name': {'key': 'properties.configurationGroupSchemaName', 'type': 'str'}, + 'configuration_group_schema_offering_location': {'key': 'properties.configurationGroupSchemaOfferingLocation', 'type': 'str'}, + 'configuration_value': {'key': 'properties.configurationValue', 'type': 'str'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + publisher_name: Optional[str] = None, + publisher_scope: Optional[Union[str, "PublisherScope"]] = None, + configuration_group_schema_name: Optional[str] = None, + configuration_group_schema_offering_location: Optional[str] = None, + configuration_value: Optional[str] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword publisher_name: The publisher name for the configuration group schema. + :paramtype publisher_name: str + :keyword publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :paramtype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :keyword configuration_group_schema_name: The configuration group schema name. + :paramtype configuration_group_schema_name: str + :keyword configuration_group_schema_offering_location: The location of the configuration group + schema offering. + :paramtype configuration_group_schema_offering_location: str + :keyword configuration_value: Name and value pairs that define the configuration value. It can + be a well formed escaped JSON string. + :paramtype configuration_value: str + """ + super(ConfigurationGroupValue, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + self.publisher_name = publisher_name + self.publisher_scope = publisher_scope + self.configuration_group_schema_name = configuration_group_schema_name + self.configuration_group_schema_offering_location = configuration_group_schema_offering_location + self.configuration_value = configuration_value + + +class ConfigurationGroupValueListResult(msrest.serialization.Model): + """Response for hybrid configurationGroups API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of hybrid configurationGroups. + :vartype value: list[~Microsoft.HybridNetwork.models.ConfigurationGroupValue] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ConfigurationGroupValue]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["ConfigurationGroupValue"]] = None, + **kwargs + ): + """ + :keyword value: A list of hybrid configurationGroups. + :paramtype value: list[~Microsoft.HybridNetwork.models.ConfigurationGroupValue] + """ + super(ConfigurationGroupValueListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class NetworkFunctionDefinitionVersionPropertiesFormat(msrest.serialization.Model): + """Network function definition version properties. + + You probably want to use the sub-classes and not this class directly. Known + sub-classes are: ContainerizedNetworkFunctionDefinitionVersion, DelegatedNetworkFunctionDefinitionVersion, VirtualNetworkFunctionDefinitionVersion. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the network function definition version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network function definition version description. + :vartype description: str + :ivar deploy_parameters: The deployment parameters of the network function definition version. + :vartype deploy_parameters: str + :ivar network_function_type: Required. The network function type.Constant filled by server. + Possible values include: "Unknown", "VirtualNetworkFunction", "ContainerizedNetworkFunction", + "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + 'network_function_type': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'version_state': {'key': 'versionState', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + 'deploy_parameters': {'key': 'deployParameters', 'type': 'str'}, + 'network_function_type': {'key': 'networkFunctionType', 'type': 'str'}, + } + + _subtype_map = { + 'network_function_type': {'ContainerizedNetworkFunction': 'ContainerizedNetworkFunctionDefinitionVersion', 'DelegatedNetworkFunction': 'DelegatedNetworkFunctionDefinitionVersion', 'VirtualNetworkFunction': 'VirtualNetworkFunctionDefinitionVersion'} + } + + def __init__( + self, + *, + description: Optional[str] = None, + deploy_parameters: Optional[str] = None, + **kwargs + ): + """ + :keyword description: The network function definition version description. + :paramtype description: str + :keyword deploy_parameters: The deployment parameters of the network function definition + version. + :paramtype deploy_parameters: str + """ + super(NetworkFunctionDefinitionVersionPropertiesFormat, self).__init__(**kwargs) + self.provisioning_state = None + self.version_state = None + self.description = description + self.deploy_parameters = deploy_parameters + self.network_function_type = None # type: Optional[str] + + +class ContainerizedNetworkFunctionDefinitionVersion(NetworkFunctionDefinitionVersionPropertiesFormat): + """Containerized network function network function definition version properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the network function definition version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network function definition version description. + :vartype description: str + :ivar deploy_parameters: The deployment parameters of the network function definition version. + :vartype deploy_parameters: str + :ivar network_function_type: Required. The network function type.Constant filled by server. + Possible values include: "Unknown", "VirtualNetworkFunction", "ContainerizedNetworkFunction", + "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + :ivar network_function_template: Containerized network function template. + :vartype network_function_template: + ~Microsoft.HybridNetwork.models.ContainerizedNetworkFunctionTemplate + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + 'network_function_type': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'version_state': {'key': 'versionState', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + 'deploy_parameters': {'key': 'deployParameters', 'type': 'str'}, + 'network_function_type': {'key': 'networkFunctionType', 'type': 'str'}, + 'network_function_template': {'key': 'networkFunctionTemplate', 'type': 'ContainerizedNetworkFunctionTemplate'}, + } + + def __init__( + self, + *, + description: Optional[str] = None, + deploy_parameters: Optional[str] = None, + network_function_template: Optional["ContainerizedNetworkFunctionTemplate"] = None, + **kwargs + ): + """ + :keyword description: The network function definition version description. + :paramtype description: str + :keyword deploy_parameters: The deployment parameters of the network function definition + version. + :paramtype deploy_parameters: str + :keyword network_function_template: Containerized network function template. + :paramtype network_function_template: + ~Microsoft.HybridNetwork.models.ContainerizedNetworkFunctionTemplate + """ + super(ContainerizedNetworkFunctionDefinitionVersion, self).__init__(description=description, deploy_parameters=deploy_parameters, **kwargs) + self.network_function_type = 'ContainerizedNetworkFunction' # type: str + self.network_function_template = network_function_template + + +class CustomLocationResourceId(msrest.serialization.Model): + """Reference to an Azure ARC custom location resource. + + :ivar id: Azure ARC custom location resource ID. + :vartype id: str + """ + + _validation = { + 'id': {'pattern': r'^/[sS][uU][bB][sS][cC][rR][iI][pP][tT][iI][oO][nN][sS]/[^/?#]+/[rR][eE][sS][oO][uU][rR][cC][eE][gG][rR][oO][uU][pP][sS]/[^/?#]+/[pP][rR][oO][vV][iI][dD][eE][rR][sS]/[mM][iI][cC][rR][oO][sS][oO][fF][tT]\.[eE][xX][tT][eE][nN][dD][eE][dD][lL][oO][cC][aA][tT][iI][oO][nN]/[cC][uU][sS][tT][oO][mM][lL][oO][cC][aA][tT][iI][oO][nN][sS]/[^/?#]+$'}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + } + + def __init__( + self, + *, + id: Optional[str] = None, + **kwargs + ): + """ + :keyword id: Azure ARC custom location resource ID. + :paramtype id: str + """ + super(CustomLocationResourceId, self).__init__(**kwargs) + self.id = id + + +class DelegatedNetworkFunctionDefinitionVersion(NetworkFunctionDefinitionVersionPropertiesFormat): + """Delegated network function network function definition version properties . + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the network function definition version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network function definition version description. + :vartype description: str + :ivar deploy_parameters: The deployment parameters of the network function definition version. + :vartype deploy_parameters: str + :ivar network_function_type: Required. The network function type.Constant filled by server. + Possible values include: "Unknown", "VirtualNetworkFunction", "ContainerizedNetworkFunction", + "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + :ivar network_function_template: Delegated network function template. + :vartype network_function_template: + ~Microsoft.HybridNetwork.models.DelegatedNetworkFunctionTemplate + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + 'network_function_type': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'version_state': {'key': 'versionState', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + 'deploy_parameters': {'key': 'deployParameters', 'type': 'str'}, + 'network_function_type': {'key': 'networkFunctionType', 'type': 'str'}, + 'network_function_template': {'key': 'networkFunctionTemplate', 'type': 'DelegatedNetworkFunctionTemplate'}, + } + + def __init__( + self, + *, + description: Optional[str] = None, + deploy_parameters: Optional[str] = None, + network_function_template: Optional["DelegatedNetworkFunctionTemplate"] = None, + **kwargs + ): + """ + :keyword description: The network function definition version description. + :paramtype description: str + :keyword deploy_parameters: The deployment parameters of the network function definition + version. + :paramtype deploy_parameters: str + :keyword network_function_template: Delegated network function template. + :paramtype network_function_template: + ~Microsoft.HybridNetwork.models.DelegatedNetworkFunctionTemplate + """ + super(DelegatedNetworkFunctionDefinitionVersion, self).__init__(description=description, deploy_parameters=deploy_parameters, **kwargs) + self.network_function_type = 'DelegatedNetworkFunction' # type: str + self.network_function_template = network_function_template + + +class DependsOnProfile(msrest.serialization.Model): + """Depends on profile definition. + + :ivar install_depends_on: Application installation operation dependency. + :vartype install_depends_on: list[str] + :ivar uninstall_depends_on: Application deletion operation dependency. + :vartype uninstall_depends_on: list[str] + :ivar update_depends_on: Application update operation dependency. + :vartype update_depends_on: list[str] + """ + + _attribute_map = { + 'install_depends_on': {'key': 'installDependsOn', 'type': '[str]'}, + 'uninstall_depends_on': {'key': 'uninstallDependsOn', 'type': '[str]'}, + 'update_depends_on': {'key': 'updateDependsOn', 'type': '[str]'}, + } + + def __init__( + self, + *, + install_depends_on: Optional[List[str]] = None, + uninstall_depends_on: Optional[List[str]] = None, + update_depends_on: Optional[List[str]] = None, + **kwargs + ): + """ + :keyword install_depends_on: Application installation operation dependency. + :paramtype install_depends_on: list[str] + :keyword uninstall_depends_on: Application deletion operation dependency. + :paramtype uninstall_depends_on: list[str] + :keyword update_depends_on: Application update operation dependency. + :paramtype update_depends_on: list[str] + """ + super(DependsOnProfile, self).__init__(**kwargs) + self.install_depends_on = install_depends_on + self.uninstall_depends_on = uninstall_depends_on + self.update_depends_on = update_depends_on + + +class ErrorAdditionalInfo(msrest.serialization.Model): + """The resource management error additional info. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar type: The additional info type. + :vartype type: str + :ivar info: The additional info. + :vartype info: any + """ + + _validation = { + 'type': {'readonly': True}, + 'info': {'readonly': True}, + } + + _attribute_map = { + 'type': {'key': 'type', 'type': 'str'}, + 'info': {'key': 'info', 'type': 'object'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ErrorAdditionalInfo, self).__init__(**kwargs) + self.type = None + self.info = None + + +class ErrorDetail(msrest.serialization.Model): + """The error detail. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar code: The error code. + :vartype code: str + :ivar message: The error message. + :vartype message: str + :ivar target: The error target. + :vartype target: str + :ivar details: The error details. + :vartype details: list[~Microsoft.HybridNetwork.models.ErrorDetail] + :ivar additional_info: The error additional info. + :vartype additional_info: list[~Microsoft.HybridNetwork.models.ErrorAdditionalInfo] + """ + + _validation = { + 'code': {'readonly': True}, + 'message': {'readonly': True}, + 'target': {'readonly': True}, + 'details': {'readonly': True}, + 'additional_info': {'readonly': True}, + } + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + 'target': {'key': 'target', 'type': 'str'}, + 'details': {'key': 'details', 'type': '[ErrorDetail]'}, + 'additional_info': {'key': 'additionalInfo', 'type': '[ErrorAdditionalInfo]'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ErrorDetail, self).__init__(**kwargs) + self.code = None + self.message = None + self.target = None + self.details = None + self.additional_info = None + + +class ErrorResponse(msrest.serialization.Model): + """Common error response for all Azure Resource Manager APIs to return error details for failed operations. (This also follows the OData error response format.). + + :ivar error: The error object. + :vartype error: ~Microsoft.HybridNetwork.models.ErrorDetail + """ + + _attribute_map = { + 'error': {'key': 'error', 'type': 'ErrorDetail'}, + } + + def __init__( + self, + *, + error: Optional["ErrorDetail"] = None, + **kwargs + ): + """ + :keyword error: The error object. + :paramtype error: ~Microsoft.HybridNetwork.models.ErrorDetail + """ + super(ErrorResponse, self).__init__(**kwargs) + self.error = error + + +class ExecuteRequestParameters(msrest.serialization.Model): + """Payload for execute request post call. + + All required parameters must be populated in order to send to Azure. + + :ivar service_endpoint: Required. The endpoint of service to call. + :vartype service_endpoint: str + :ivar request_metadata: Required. The request metadata. + :vartype request_metadata: ~Microsoft.HybridNetwork.models.RequestMetadata + """ + + _validation = { + 'service_endpoint': {'required': True}, + 'request_metadata': {'required': True}, + } + + _attribute_map = { + 'service_endpoint': {'key': 'serviceEndpoint', 'type': 'str'}, + 'request_metadata': {'key': 'requestMetadata', 'type': 'RequestMetadata'}, + } + + def __init__( + self, + *, + service_endpoint: str, + request_metadata: "RequestMetadata", + **kwargs + ): + """ + :keyword service_endpoint: Required. The endpoint of service to call. + :paramtype service_endpoint: str + :keyword request_metadata: Required. The request metadata. + :paramtype request_metadata: ~Microsoft.HybridNetwork.models.RequestMetadata + """ + super(ExecuteRequestParameters, self).__init__(**kwargs) + self.service_endpoint = service_endpoint + self.request_metadata = request_metadata + + +class HelmArtifactProfile(msrest.serialization.Model): + """Helm artifact profile. + + :ivar helm_package_name: Helm package name. + :vartype helm_package_name: str + :ivar helm_package_version_range: Helm package version range. + :vartype helm_package_version_range: str + :ivar registry_values_paths: The registry values path list. + :vartype registry_values_paths: list[str] + :ivar image_pull_secrets_values_paths: The image pull secrets values path list. + :vartype image_pull_secrets_values_paths: list[str] + """ + + _attribute_map = { + 'helm_package_name': {'key': 'helmPackageName', 'type': 'str'}, + 'helm_package_version_range': {'key': 'helmPackageVersionRange', 'type': 'str'}, + 'registry_values_paths': {'key': 'registryValuesPaths', 'type': '[str]'}, + 'image_pull_secrets_values_paths': {'key': 'imagePullSecretsValuesPaths', 'type': '[str]'}, + } + + def __init__( + self, + *, + helm_package_name: Optional[str] = None, + helm_package_version_range: Optional[str] = None, + registry_values_paths: Optional[List[str]] = None, + image_pull_secrets_values_paths: Optional[List[str]] = None, + **kwargs + ): + """ + :keyword helm_package_name: Helm package name. + :paramtype helm_package_name: str + :keyword helm_package_version_range: Helm package version range. + :paramtype helm_package_version_range: str + :keyword registry_values_paths: The registry values path list. + :paramtype registry_values_paths: list[str] + :keyword image_pull_secrets_values_paths: The image pull secrets values path list. + :paramtype image_pull_secrets_values_paths: list[str] + """ + super(HelmArtifactProfile, self).__init__(**kwargs) + self.helm_package_name = helm_package_name + self.helm_package_version_range = helm_package_version_range + self.registry_values_paths = registry_values_paths + self.image_pull_secrets_values_paths = image_pull_secrets_values_paths + + +class HelmMappingRuleProfile(msrest.serialization.Model): + """Helm mapping rule profile. + + :ivar release_namespace: Helm release namespace. + :vartype release_namespace: str + :ivar release_name: Helm release name. + :vartype release_name: str + :ivar helm_package_version: Helm package version. + :vartype helm_package_version: str + :ivar values: Helm release values. + :vartype values: str + """ + + _attribute_map = { + 'release_namespace': {'key': 'releaseNamespace', 'type': 'str'}, + 'release_name': {'key': 'releaseName', 'type': 'str'}, + 'helm_package_version': {'key': 'helmPackageVersion', 'type': 'str'}, + 'values': {'key': 'values', 'type': 'str'}, + } + + def __init__( + self, + *, + release_namespace: Optional[str] = None, + release_name: Optional[str] = None, + helm_package_version: Optional[str] = None, + values: Optional[str] = None, + **kwargs + ): + """ + :keyword release_namespace: Helm release namespace. + :paramtype release_namespace: str + :keyword release_name: Helm release name. + :paramtype release_name: str + :keyword helm_package_version: Helm package version. + :paramtype helm_package_version: str + :keyword values: Helm release values. + :paramtype values: str + """ + super(HelmMappingRuleProfile, self).__init__(**kwargs) + self.release_namespace = release_namespace + self.release_name = release_name + self.helm_package_version = helm_package_version + self.values = values + + +class HelmPackageApplicationOverview(NetworkFunctionDefinitionApplicationOverview): + """Helm Package Application overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the application. + :vartype name: str + :ivar artifact_type: Required. The application overview artifact type.Constant filled by + server. Possible values include: "Unknown", "HelmPackage", "VhdImageFile", "ArmTemplate", + "ImageFile". + :vartype artifact_type: str or + ~Microsoft.HybridNetwork.models.NetworkFunctionPublisherArtifactType + :ivar deploy_parameters_mapping_rule_profile: The deployment parameters mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureArcKubernetesDeployMappingRuleProfile + """ + + _validation = { + 'name': {'readonly': True}, + 'artifact_type': {'required': True}, + 'deploy_parameters_mapping_rule_profile': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureArcKubernetesDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(HelmPackageApplicationOverview, self).__init__(**kwargs) + self.artifact_type = 'HelmPackage' # type: str + self.deploy_parameters_mapping_rule_profile = None + + +class HybridAKSNetworkFunctionReadyK8S(NetworkFunctionReadyK8SPropertiesFormat): + """Azure based kubernetes service cluster prerequisite properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the NetworkFunctionReadyK8s resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar cluster_type: Required. The cluster type.Constant filled by server. Possible values + include: "AzureKubernetesService", "ArcConnectedK8s", "HybridAKS". + :vartype cluster_type: str or ~Microsoft.HybridNetwork.models.ClusterType + :ivar cluster_reference: Required. The k8s/Connected cluster ARM id. + :vartype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar custom_location_reference: The read only custom location ARM id. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar user_assigned_managed_identity: The User Assigned Managed Identity ARM id giving access + to the HybridAKS cluster if outside AOSM flow. + :vartype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'cluster_type': {'required': True}, + 'cluster_reference': {'required': True}, + 'custom_location_reference': {'readonly': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'cluster_type': {'key': 'clusterType', 'type': 'str'}, + 'cluster_reference': {'key': 'clusterReference', 'type': 'ReferencedResource'}, + 'custom_location_reference': {'key': 'customLocationReference', 'type': 'ReferencedResource'}, + 'user_assigned_managed_identity': {'key': 'userAssignedManagedIdentity', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + *, + cluster_reference: "ReferencedResource", + user_assigned_managed_identity: Optional["ReferencedResource"] = None, + **kwargs + ): + """ + :keyword cluster_reference: Required. The k8s/Connected cluster ARM id. + :paramtype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword user_assigned_managed_identity: The User Assigned Managed Identity ARM id giving + access to the HybridAKS cluster if outside AOSM flow. + :paramtype user_assigned_managed_identity: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(HybridAKSNetworkFunctionReadyK8S, self).__init__(cluster_reference=cluster_reference, **kwargs) + self.cluster_type = 'HybridAKS' # type: str + self.user_assigned_managed_identity = user_assigned_managed_identity + + +class ImageArtifactProfile(msrest.serialization.Model): + """Image artifact profile. + + :ivar image_name: Image name. + :vartype image_name: str + :ivar image_version: Image version. + :vartype image_version: str + """ + + _attribute_map = { + 'image_name': {'key': 'imageName', 'type': 'str'}, + 'image_version': {'key': 'imageVersion', 'type': 'str'}, + } + + def __init__( + self, + *, + image_name: Optional[str] = None, + image_version: Optional[str] = None, + **kwargs + ): + """ + :keyword image_name: Image name. + :paramtype image_name: str + :keyword image_version: Image version. + :paramtype image_version: str + """ + super(ImageArtifactProfile, self).__init__(**kwargs) + self.image_name = image_name + self.image_version = image_version + + +class ImageFileApplicationOverview(NetworkFunctionDefinitionApplicationOverview): + """Image file Application overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the application. + :vartype name: str + :ivar artifact_type: Required. The application overview artifact type.Constant filled by + server. Possible values include: "Unknown", "HelmPackage", "VhdImageFile", "ArmTemplate", + "ImageFile". + :vartype artifact_type: str or + ~Microsoft.HybridNetwork.models.NetworkFunctionPublisherArtifactType + :ivar deploy_parameters_mapping_rule_profile: The deployment parameters mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreDelegatedImageDeployMappingRuleProfile + """ + + _validation = { + 'name': {'readonly': True}, + 'artifact_type': {'required': True}, + 'deploy_parameters_mapping_rule_profile': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreDelegatedImageDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ImageFileApplicationOverview, self).__init__(**kwargs) + self.artifact_type = 'ImageFile' # type: str + self.deploy_parameters_mapping_rule_profile = None + + +class ImageMappingRuleProfile(msrest.serialization.Model): + """Image mapping rule profile. + + :ivar user_configuration: List of values. + :vartype user_configuration: str + """ + + _attribute_map = { + 'user_configuration': {'key': 'userConfiguration', 'type': 'str'}, + } + + def __init__( + self, + *, + user_configuration: Optional[str] = None, + **kwargs + ): + """ + :keyword user_configuration: List of values. + :paramtype user_configuration: str + """ + super(ImageMappingRuleProfile, self).__init__(**kwargs) + self.user_configuration = user_configuration + + +class ManagedResourceGroupConfiguration(msrest.serialization.Model): + """Managed resource group configuration. + + :ivar name: Managed resource group name. + :vartype name: str + :ivar location: Managed resource group location. + :vartype location: str + """ + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'location': {'key': 'location', 'type': 'str'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + location: Optional[str] = None, + **kwargs + ): + """ + :keyword name: Managed resource group name. + :paramtype name: str + :keyword location: Managed resource group location. + :paramtype location: str + """ + super(ManagedResourceGroupConfiguration, self).__init__(**kwargs) + self.name = name + self.location = location + + +class ManagedServiceIdentity(msrest.serialization.Model): + """Managed service identity (system assigned and/or user assigned identities). + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar principal_id: The service principal ID of the system assigned identity. This property + will only be provided for a system assigned identity. + :vartype principal_id: str + :ivar tenant_id: The tenant ID of the system assigned identity. This property will only be + provided for a system assigned identity. + :vartype tenant_id: str + :ivar type: Required. Type of managed service identity (where both SystemAssigned and + UserAssigned types are allowed). Possible values include: "None", "SystemAssigned", + "UserAssigned", "SystemAssigned,UserAssigned". + :vartype type: str or ~Microsoft.HybridNetwork.models.ManagedServiceIdentityType + :ivar user_assigned_identities: The set of user assigned identities associated with the + resource. The userAssignedIdentities dictionary keys will be ARM resource ids in the form: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. + The dictionary values can be empty objects ({}) in requests. + :vartype user_assigned_identities: dict[str, + ~Microsoft.HybridNetwork.models.UserAssignedIdentity] + """ + + _validation = { + 'principal_id': {'readonly': True}, + 'tenant_id': {'readonly': True}, + 'type': {'required': True}, + } + + _attribute_map = { + 'principal_id': {'key': 'principalId', 'type': 'str'}, + 'tenant_id': {'key': 'tenantId', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'user_assigned_identities': {'key': 'userAssignedIdentities', 'type': '{UserAssignedIdentity}'}, + } + + def __init__( + self, + *, + type: Union[str, "ManagedServiceIdentityType"], + user_assigned_identities: Optional[Dict[str, "UserAssignedIdentity"]] = None, + **kwargs + ): + """ + :keyword type: Required. Type of managed service identity (where both SystemAssigned and + UserAssigned types are allowed). Possible values include: "None", "SystemAssigned", + "UserAssigned", "SystemAssigned,UserAssigned". + :paramtype type: str or ~Microsoft.HybridNetwork.models.ManagedServiceIdentityType + :keyword user_assigned_identities: The set of user assigned identities associated with the + resource. The userAssignedIdentities dictionary keys will be ARM resource ids in the form: + '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. + The dictionary values can be empty objects ({}) in requests. + :paramtype user_assigned_identities: dict[str, + ~Microsoft.HybridNetwork.models.UserAssignedIdentity] + """ + super(ManagedServiceIdentity, self).__init__(**kwargs) + self.principal_id = None + self.tenant_id = None + self.type = type + self.user_assigned_identities = user_assigned_identities + + +class ManifestArtifactFormat(msrest.serialization.Model): + """Manifest artifact properties. + + :ivar artifact_name: The artifact name. + :vartype artifact_name: str + :ivar artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :ivar artifact_version: The artifact version. + :vartype artifact_version: str + """ + + _attribute_map = { + 'artifact_name': {'key': 'artifactName', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_version': {'key': 'artifactVersion', 'type': 'str'}, + } + + def __init__( + self, + *, + artifact_name: Optional[str] = None, + artifact_type: Optional[Union[str, "ArtifactType"]] = None, + artifact_version: Optional[str] = None, + **kwargs + ): + """ + :keyword artifact_name: The artifact name. + :paramtype artifact_name: str + :keyword artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :paramtype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :keyword artifact_version: The artifact version. + :paramtype artifact_version: str + """ + super(ManifestArtifactFormat, self).__init__(**kwargs) + self.artifact_name = artifact_name + self.artifact_type = artifact_type + self.artifact_version = artifact_version + + +class NetworkFunction(TrackedResource): + """Network function resource response. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar etag: A unique read-only string that changes whenever the resource is updated. + :vartype etag: str + :ivar identity: The managed identity of the Network function, if configured. + :vartype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :ivar provisioning_state: The provisioning state of the network function resource. Possible + values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar publisher_name: The publisher name for the network function. + :vartype publisher_name: str + :ivar publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :vartype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :ivar network_function_definition_group_name: The network function definition group name for + the network function. + :vartype network_function_definition_group_name: str + :ivar network_function_definition_version: The network function definition version for the + network function. + :vartype network_function_definition_version: str + :ivar network_function_definition_offering_location: The location of the network function + definition offering. + :vartype network_function_definition_offering_location: str + :ivar nfvi_type: The nfvi type for the network function. Possible values include: "Unknown", + "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :ivar nfvi_id: The nfviId for the network function. + :vartype nfvi_id: str + :ivar allow_software_update: Indicates if software updates are allowed during deployment. + :vartype allow_software_update: bool + :ivar deployment_values: The JSON-serialized deployment values from the user. + :vartype deployment_values: str + :ivar role_override_values: The role configuration override values from the user. + :vartype role_override_values: list[str] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'etag': {'key': 'etag', 'type': 'str'}, + 'identity': {'key': 'identity', 'type': 'ManagedServiceIdentity'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'publisher_name': {'key': 'properties.publisherName', 'type': 'str'}, + 'publisher_scope': {'key': 'properties.publisherScope', 'type': 'str'}, + 'network_function_definition_group_name': {'key': 'properties.networkFunctionDefinitionGroupName', 'type': 'str'}, + 'network_function_definition_version': {'key': 'properties.networkFunctionDefinitionVersion', 'type': 'str'}, + 'network_function_definition_offering_location': {'key': 'properties.networkFunctionDefinitionOfferingLocation', 'type': 'str'}, + 'nfvi_type': {'key': 'properties.nfviType', 'type': 'str'}, + 'nfvi_id': {'key': 'properties.nfviId', 'type': 'str'}, + 'allow_software_update': {'key': 'properties.allowSoftwareUpdate', 'type': 'bool'}, + 'deployment_values': {'key': 'properties.deploymentValues', 'type': 'str'}, + 'role_override_values': {'key': 'properties.roleOverrideValues', 'type': '[str]'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + etag: Optional[str] = None, + identity: Optional["ManagedServiceIdentity"] = None, + publisher_name: Optional[str] = None, + publisher_scope: Optional[Union[str, "PublisherScope"]] = None, + network_function_definition_group_name: Optional[str] = None, + network_function_definition_version: Optional[str] = None, + network_function_definition_offering_location: Optional[str] = None, + nfvi_type: Optional[Union[str, "NFVIType"]] = None, + nfvi_id: Optional[str] = None, + allow_software_update: Optional[bool] = None, + deployment_values: Optional[str] = None, + role_override_values: Optional[List[str]] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword etag: A unique read-only string that changes whenever the resource is updated. + :paramtype etag: str + :keyword identity: The managed identity of the Network function, if configured. + :paramtype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :keyword publisher_name: The publisher name for the network function. + :paramtype publisher_name: str + :keyword publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :paramtype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :keyword network_function_definition_group_name: The network function definition group name for + the network function. + :paramtype network_function_definition_group_name: str + :keyword network_function_definition_version: The network function definition version for the + network function. + :paramtype network_function_definition_version: str + :keyword network_function_definition_offering_location: The location of the network function + definition offering. + :paramtype network_function_definition_offering_location: str + :keyword nfvi_type: The nfvi type for the network function. Possible values include: "Unknown", + "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :paramtype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :keyword nfvi_id: The nfviId for the network function. + :paramtype nfvi_id: str + :keyword allow_software_update: Indicates if software updates are allowed during deployment. + :paramtype allow_software_update: bool + :keyword deployment_values: The JSON-serialized deployment values from the user. + :paramtype deployment_values: str + :keyword role_override_values: The role configuration override values from the user. + :paramtype role_override_values: list[str] + """ + super(NetworkFunction, self).__init__(tags=tags, location=location, **kwargs) + self.etag = etag + self.identity = identity + self.provisioning_state = None + self.publisher_name = publisher_name + self.publisher_scope = publisher_scope + self.network_function_definition_group_name = network_function_definition_group_name + self.network_function_definition_version = network_function_definition_version + self.network_function_definition_offering_location = network_function_definition_offering_location + self.nfvi_type = nfvi_type + self.nfvi_id = nfvi_id + self.allow_software_update = allow_software_update + self.deployment_values = deployment_values + self.role_override_values = role_override_values + + +class NetworkFunctionDefinitionGroup(TrackedResource): + """Network function definition group resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the network function definition groups + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar description: The network function definition group description. + :vartype description: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + description: Optional[str] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword description: The network function definition group description. + :paramtype description: str + """ + super(NetworkFunctionDefinitionGroup, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + self.description = description + + +class NetworkFunctionDefinitionGroupListResult(msrest.serialization.Model): + """A list of network function definition group resources. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network function definition group. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunctionDefinitionGroup]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["NetworkFunctionDefinitionGroup"]] = None, + **kwargs + ): + """ + :keyword value: A list of network function definition group. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup] + """ + super(NetworkFunctionDefinitionGroupListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class NetworkFunctionDefinitionGroupOverview(ProxyResource): + """Network function definition group overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar description: Network function definition group description. + :vartype description: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'description': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(NetworkFunctionDefinitionGroupOverview, self).__init__(**kwargs) + self.description = None + + +class NetworkFunctionDefinitionGroupOverviewListResult(msrest.serialization.Model): + """A list of available network function definition groups. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: The network function group list properties. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroupOverview] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunctionDefinitionGroupOverview]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["NetworkFunctionDefinitionGroupOverview"]] = None, + **kwargs + ): + """ + :keyword value: The network function group list properties. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroupOverview] + """ + super(NetworkFunctionDefinitionGroupOverviewListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class NetworkFunctionDefinitionResourceElementTemplateDetails(ResourceElementTemplate): + """The network function definition resource element template details. + + All required parameters must be populated in order to send to Azure. + + :ivar name: Name of the resource element template. + :vartype name: str + :ivar type: Required. The resource element template type.Constant filled by server. Possible + values include: "Unknown", "ArmResourceDefinition", "ConfigurationDefinition", + "NetworkFunctionDefinition". + :vartype type: str or ~Microsoft.HybridNetwork.models.Type + :ivar depends_on_profile: The depends on profile. + :vartype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :ivar configuration: The resource element template type. + :vartype configuration: + ~Microsoft.HybridNetwork.models.ArmResourceDefinitionResourceElementTemplate + """ + + _validation = { + 'type': {'required': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'depends_on_profile': {'key': 'dependsOnProfile', 'type': 'DependsOnProfile'}, + 'configuration': {'key': 'configuration', 'type': 'ArmResourceDefinitionResourceElementTemplate'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + depends_on_profile: Optional["DependsOnProfile"] = None, + configuration: Optional["ArmResourceDefinitionResourceElementTemplate"] = None, + **kwargs + ): + """ + :keyword name: Name of the resource element template. + :paramtype name: str + :keyword depends_on_profile: The depends on profile. + :paramtype depends_on_profile: ~Microsoft.HybridNetwork.models.DependsOnProfile + :keyword configuration: The resource element template type. + :paramtype configuration: + ~Microsoft.HybridNetwork.models.ArmResourceDefinitionResourceElementTemplate + """ + super(NetworkFunctionDefinitionResourceElementTemplateDetails, self).__init__(name=name, depends_on_profile=depends_on_profile, **kwargs) + self.type = 'NetworkFunctionDefinition' # type: str + self.configuration = configuration + + +class NetworkFunctionDefinitionVersion(TrackedResource): + """Network function definition version. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the network function definition version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network function definition version description. + :vartype description: str + :ivar deploy_parameters: The deployment parameters of the network function definition version. + :vartype deploy_parameters: str + :ivar network_function_type: The network function type.Constant filled by server. Possible + values include: "Unknown", "VirtualNetworkFunction", "ContainerizedNetworkFunction", + "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'version_state': {'key': 'properties.versionState', 'type': 'str'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + 'deploy_parameters': {'key': 'properties.deployParameters', 'type': 'str'}, + 'network_function_type': {'key': 'properties.networkFunctionType', 'type': 'str'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + description: Optional[str] = None, + deploy_parameters: Optional[str] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword description: The network function definition version description. + :paramtype description: str + :keyword deploy_parameters: The deployment parameters of the network function definition + version. + :paramtype deploy_parameters: str + """ + super(NetworkFunctionDefinitionVersion, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + self.version_state = None + self.description = description + self.deploy_parameters = deploy_parameters + self.network_function_type = None # type: Optional[str] + + +class NetworkFunctionDefinitionVersionListResult(msrest.serialization.Model): + """A list of network function definition versions. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network function definition versions. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion] + :ivar next_link: The URI to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunctionDefinitionVersion]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["NetworkFunctionDefinitionVersion"]] = None, + **kwargs + ): + """ + :keyword value: A list of network function definition versions. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion] + """ + super(NetworkFunctionDefinitionVersionListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class NetworkFunctionDefinitionVersionOverview(ProxyResource): + """Network function definition version overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar description: The network function definition version description properties. + :vartype description: str + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar network_function_type: The network function type. Possible values include: "Unknown", + "VirtualNetworkFunction", "ContainerizedNetworkFunction", "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + :ivar nfvi_type: The nfvi type for the network function. Possible values include: "Unknown", + "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :vartype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :ivar deploy_parameters: The deployment parameters. + :vartype deploy_parameters: str + :ivar network_function_applications: The network function definition application overview. + :vartype network_function_applications: + list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionApplicationOverview] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'description': {'readonly': True}, + 'deploy_parameters': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + 'version_state': {'key': 'properties.versionState', 'type': 'str'}, + 'network_function_type': {'key': 'properties.networkFunctionType', 'type': 'str'}, + 'nfvi_type': {'key': 'properties.nfviType', 'type': 'str'}, + 'deploy_parameters': {'key': 'properties.deployParameters', 'type': 'str'}, + 'network_function_applications': {'key': 'properties.networkFunctionApplications', 'type': '[NetworkFunctionDefinitionApplicationOverview]'}, + } + + def __init__( + self, + *, + version_state: Optional[Union[str, "VersionState"]] = None, + network_function_type: Optional[Union[str, "NetworkFunctionType"]] = None, + nfvi_type: Optional[Union[str, "NFVIType"]] = None, + network_function_applications: Optional[List["NetworkFunctionDefinitionApplicationOverview"]] = None, + **kwargs + ): + """ + :keyword version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :paramtype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :keyword network_function_type: The network function type. Possible values include: "Unknown", + "VirtualNetworkFunction", "ContainerizedNetworkFunction", "DelegatedNetworkFunction". + :paramtype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + :keyword nfvi_type: The nfvi type for the network function. Possible values include: "Unknown", + "AzureArcKubernetes", "AzureCore", "AzureOperatorNexus". + :paramtype nfvi_type: str or ~Microsoft.HybridNetwork.models.NFVIType + :keyword network_function_applications: The network function definition application overview. + :paramtype network_function_applications: + list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionApplicationOverview] + """ + super(NetworkFunctionDefinitionVersionOverview, self).__init__(**kwargs) + self.description = None + self.version_state = version_state + self.network_function_type = network_function_type + self.nfvi_type = nfvi_type + self.deploy_parameters = None + self.network_function_applications = network_function_applications + + +class NetworkFunctionDefinitionVersionOverviewListResult(msrest.serialization.Model): + """A list of available network function definition groups. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: The network function definition overview properties. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionOverview] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunctionDefinitionVersionOverview]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["NetworkFunctionDefinitionVersionOverview"]] = None, + **kwargs + ): + """ + :keyword value: The network function definition overview properties. + :paramtype value: + list[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionOverview] + """ + super(NetworkFunctionDefinitionVersionOverviewListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class NetworkFunctionDefinitionVersionUpdateState(msrest.serialization.Model): + """Publisher network function definition version update request definition. + + :ivar version_state: The network function definition version state. Only the 'Active' and + 'Deprecated' states are allowed for updates. Other states are used for internal state + transitioning. Possible values include: "Unknown", "Preview", "Active", "Deprecated", + "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + + _attribute_map = { + 'version_state': {'key': 'versionState', 'type': 'str'}, + } + + def __init__( + self, + *, + version_state: Optional[Union[str, "VersionState"]] = None, + **kwargs + ): + """ + :keyword version_state: The network function definition version state. Only the 'Active' and + 'Deprecated' states are allowed for updates. Other states are used for internal state + transitioning. Possible values include: "Unknown", "Preview", "Active", "Deprecated", + "Validating", "ValidationFailed". + :paramtype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + super(NetworkFunctionDefinitionVersionUpdateState, self).__init__(**kwargs) + self.version_state = version_state + + +class NetworkFunctionListResult(msrest.serialization.Model): + """Response for network function API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network function resources in a subscription or resource group. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunction] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunction]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["NetworkFunction"]] = None, + **kwargs + ): + """ + :keyword value: A list of network function resources in a subscription or resource group. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkFunction] + """ + super(NetworkFunctionListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class NetworkFunctionReadyK8S(TrackedResource): + """NetworkFunctionReadyK8s resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar identity: The managed identity of the NetworkFunctionReadyK8s, if configured. + :vartype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :ivar provisioning_state: The provisioning state of the NetworkFunctionReadyK8s resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar cluster_type: The cluster type.Constant filled by server. Possible values include: + "AzureKubernetesService", "ArcConnectedK8s", "HybridAKS". + :vartype cluster_type: str or ~Microsoft.HybridNetwork.models.ClusterType + :ivar cluster_reference: The k8s/Connected cluster ARM id. + :vartype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar custom_location_reference: The read only custom location ARM id. + :vartype custom_location_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'custom_location_reference': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'identity': {'key': 'identity', 'type': 'ManagedServiceIdentity'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'cluster_type': {'key': 'properties.clusterType', 'type': 'str'}, + 'cluster_reference': {'key': 'properties.clusterReference', 'type': 'ReferencedResource'}, + 'custom_location_reference': {'key': 'properties.customLocationReference', 'type': 'ReferencedResource'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + identity: Optional["ManagedServiceIdentity"] = None, + cluster_reference: Optional["ReferencedResource"] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword identity: The managed identity of the NetworkFunctionReadyK8s, if configured. + :paramtype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :keyword cluster_reference: The k8s/Connected cluster ARM id. + :paramtype cluster_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + """ + super(NetworkFunctionReadyK8S, self).__init__(tags=tags, location=location, **kwargs) + self.identity = identity + self.provisioning_state = None + self.cluster_type = None # type: Optional[str] + self.cluster_reference = cluster_reference + self.custom_location_reference = None + + +class NetworkFunctionReadyK8SListResult(msrest.serialization.Model): + """Response for NetworkFunctionReadyK8s API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network function ready K8s. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkFunctionReadyK8S]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["NetworkFunctionReadyK8S"]] = None, + **kwargs + ): + """ + :keyword value: A list of network function ready K8s. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S] + """ + super(NetworkFunctionReadyK8SListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class NetworkServiceDesignGroup(TrackedResource): + """network service design group resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the network service design groups resource. + Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar description: The network service design group description. + :vartype description: str + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + description: Optional[str] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword description: The network service design group description. + :paramtype description: str + """ + super(NetworkServiceDesignGroup, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + self.description = description + + +class NetworkServiceDesignGroupListResult(msrest.serialization.Model): + """A list of network service design group resources. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network service design group. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkServiceDesignGroup]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["NetworkServiceDesignGroup"]] = None, + **kwargs + ): + """ + :keyword value: A list of network service design group. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup] + """ + super(NetworkServiceDesignGroupListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class NetworkServiceDesignVersion(TrackedResource): + """network service design version. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the network service design version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network service design version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network service design version description. + :vartype description: str + :ivar configuration_group_schema_references: The configuration schemas to used to define the + values. + :vartype configuration_group_schema_references: dict[str, + ~Microsoft.HybridNetwork.models.ReferencedResource] + :ivar nfvis_from_site: The nfvis from the site. + :vartype nfvis_from_site: dict[str, ~Microsoft.HybridNetwork.models.NfviDetails] + :ivar resource_element_templates: List of resource element template. + :vartype resource_element_templates: + list[~Microsoft.HybridNetwork.models.ResourceElementTemplate] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'version_state': {'key': 'properties.versionState', 'type': 'str'}, + 'description': {'key': 'properties.description', 'type': 'str'}, + 'configuration_group_schema_references': {'key': 'properties.configurationGroupSchemaReferences', 'type': '{ReferencedResource}'}, + 'nfvis_from_site': {'key': 'properties.nfvisFromSite', 'type': '{NfviDetails}'}, + 'resource_element_templates': {'key': 'properties.resourceElementTemplates', 'type': '[ResourceElementTemplate]'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + description: Optional[str] = None, + configuration_group_schema_references: Optional[Dict[str, "ReferencedResource"]] = None, + nfvis_from_site: Optional[Dict[str, "NfviDetails"]] = None, + resource_element_templates: Optional[List["ResourceElementTemplate"]] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword description: The network service design version description. + :paramtype description: str + :keyword configuration_group_schema_references: The configuration schemas to used to define the + values. + :paramtype configuration_group_schema_references: dict[str, + ~Microsoft.HybridNetwork.models.ReferencedResource] + :keyword nfvis_from_site: The nfvis from the site. + :paramtype nfvis_from_site: dict[str, ~Microsoft.HybridNetwork.models.NfviDetails] + :keyword resource_element_templates: List of resource element template. + :paramtype resource_element_templates: + list[~Microsoft.HybridNetwork.models.ResourceElementTemplate] + """ + super(NetworkServiceDesignVersion, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + self.version_state = None + self.description = description + self.configuration_group_schema_references = configuration_group_schema_references + self.nfvis_from_site = nfvis_from_site + self.resource_element_templates = resource_element_templates + + +class NetworkServiceDesignVersionListResult(msrest.serialization.Model): + """A list of network service design versions. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of network service design versions. + :vartype value: list[~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion] + :ivar next_link: The URI to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[NetworkServiceDesignVersion]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["NetworkServiceDesignVersion"]] = None, + **kwargs + ): + """ + :keyword value: A list of network service design versions. + :paramtype value: list[~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion] + """ + super(NetworkServiceDesignVersionListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class NetworkServiceDesignVersionUpdateState(msrest.serialization.Model): + """Publisher network service design version update request definition. + + :ivar version_state: The network service design version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + + _attribute_map = { + 'version_state': {'key': 'versionState', 'type': 'str'}, + } + + def __init__( + self, + *, + version_state: Optional[Union[str, "VersionState"]] = None, + **kwargs + ): + """ + :keyword version_state: The network service design version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :paramtype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + """ + super(NetworkServiceDesignVersionUpdateState, self).__init__(**kwargs) + self.version_state = version_state + + +class NfviDetails(msrest.serialization.Model): + """The nfvi details. + + :ivar name: The nfvi name. + :vartype name: str + :ivar type: The nfvi type. + :vartype type: str + """ + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + } + + def __init__( + self, + *, + name: Optional[str] = None, + type: Optional[str] = None, + **kwargs + ): + """ + :keyword name: The nfvi name. + :paramtype name: str + :keyword type: The nfvi type. + :paramtype type: str + """ + super(NfviDetails, self).__init__(**kwargs) + self.name = name + self.type = type + + +class NSDArtifactProfile(msrest.serialization.Model): + """Artifact profile properties. + + :ivar artifact_store_reference: The artifact store resource id. + :vartype artifact_store_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar artifact_name: Artifact name. + :vartype artifact_name: str + :ivar artifact_version: Artifact version. + :vartype artifact_version: str + """ + + _attribute_map = { + 'artifact_store_reference': {'key': 'artifactStoreReference', 'type': 'ReferencedResource'}, + 'artifact_name': {'key': 'artifactName', 'type': 'str'}, + 'artifact_version': {'key': 'artifactVersion', 'type': 'str'}, + } + + def __init__( + self, + *, + artifact_store_reference: Optional["ReferencedResource"] = None, + artifact_name: Optional[str] = None, + artifact_version: Optional[str] = None, + **kwargs + ): + """ + :keyword artifact_store_reference: The artifact store resource id. + :paramtype artifact_store_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword artifact_name: Artifact name. + :paramtype artifact_name: str + :keyword artifact_version: Artifact version. + :paramtype artifact_version: str + """ + super(NSDArtifactProfile, self).__init__(**kwargs) + self.artifact_store_reference = artifact_store_reference + self.artifact_name = artifact_name + self.artifact_version = artifact_version + + +class Operation(msrest.serialization.Model): + """Object that describes a single Microsoft.HybridNetwork operation. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar name: Operation name: {provider}/{resource}/{operation}. + :vartype name: str + :ivar display: The object that represents the operation. + :vartype display: ~Microsoft.HybridNetwork.models.OperationDisplay + """ + + _validation = { + 'name': {'readonly': True}, + 'display': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'display': {'key': 'display', 'type': 'OperationDisplay'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(Operation, self).__init__(**kwargs) + self.name = None + self.display = None + + +class OperationDisplay(msrest.serialization.Model): + """The object that represents the operation. + + :ivar provider: Service provider: Microsoft.HybridNetwork. + :vartype provider: str + :ivar resource: Resource on which the operation is performed: Registration definition, + registration assignment, etc. + :vartype resource: str + :ivar operation: Operation type: Read, write, delete, etc. + :vartype operation: str + :ivar description: Description of the operation. + :vartype description: str + """ + + _attribute_map = { + 'provider': {'key': 'provider', 'type': 'str'}, + 'resource': {'key': 'resource', 'type': 'str'}, + 'operation': {'key': 'operation', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + } + + def __init__( + self, + *, + provider: Optional[str] = None, + resource: Optional[str] = None, + operation: Optional[str] = None, + description: Optional[str] = None, + **kwargs + ): + """ + :keyword provider: Service provider: Microsoft.HybridNetwork. + :paramtype provider: str + :keyword resource: Resource on which the operation is performed: Registration definition, + registration assignment, etc. + :paramtype resource: str + :keyword operation: Operation type: Read, write, delete, etc. + :paramtype operation: str + :keyword description: Description of the operation. + :paramtype description: str + """ + super(OperationDisplay, self).__init__(**kwargs) + self.provider = provider + self.resource = resource + self.operation = operation + self.description = description + + +class OperationList(msrest.serialization.Model): + """A list of the operations. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of Microsoft.HybridNetwork operations. + :vartype value: list[~Microsoft.HybridNetwork.models.Operation] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'value': {'readonly': True}, + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[Operation]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(OperationList, self).__init__(**kwargs) + self.value = None + self.next_link = None + + +class PreviewSubscription(TrackedResource): + """Customer subscription which can use a preview network function definition version. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the preview subscription resource. Possible + values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + """ + super(PreviewSubscription, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + + +class PreviewSubscriptionsList(msrest.serialization.Model): + """A list of customer subscriptions which can use a preview network function definition version. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of preview subscriptions. + :vartype value: list[~Microsoft.HybridNetwork.models.PreviewSubscription] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[PreviewSubscription]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["PreviewSubscription"]] = None, + **kwargs + ): + """ + :keyword value: A list of preview subscriptions. + :paramtype value: list[~Microsoft.HybridNetwork.models.PreviewSubscription] + """ + super(PreviewSubscriptionsList, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class ProxyArtifactListOverview(ProxyResource): + """The proxy artifact overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ProxyArtifactListOverview, self).__init__(**kwargs) + + +class ProxyArtifactOverview(ProxyResource): + """The proxy artifact overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar artifact_versions: The proxy artifact overview properties. + :vartype artifact_versions: + list[~Microsoft.HybridNetwork.models.ProxyArtifactOverviewPropertiesValue] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'artifact_versions': {'key': 'properties.artifactVersions', 'type': '[ProxyArtifactOverviewPropertiesValue]'}, + } + + def __init__( + self, + *, + artifact_versions: Optional[List["ProxyArtifactOverviewPropertiesValue"]] = None, + **kwargs + ): + """ + :keyword artifact_versions: The proxy artifact overview properties. + :paramtype artifact_versions: + list[~Microsoft.HybridNetwork.models.ProxyArtifactOverviewPropertiesValue] + """ + super(ProxyArtifactOverview, self).__init__(**kwargs) + self.artifact_versions = artifact_versions + + +class ProxyArtifactOverviewListResult(msrest.serialization.Model): + """The proxy artifact list result. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of available proxy artifacts. + :vartype value: list[~Microsoft.HybridNetwork.models.ProxyArtifactListOverview] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ProxyArtifactListOverview]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["ProxyArtifactListOverview"]] = None, + **kwargs + ): + """ + :keyword value: A list of available proxy artifacts. + :paramtype value: list[~Microsoft.HybridNetwork.models.ProxyArtifactListOverview] + """ + super(ProxyArtifactOverviewListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class ProxyArtifactOverviewPropertiesValue(msrest.serialization.Model): + """ProxyArtifactOverviewPropertiesValue. + + :ivar artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :ivar artifact_version: The artifact version. + :vartype artifact_version: str + :ivar artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :vartype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + + _attribute_map = { + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'artifact_version': {'key': 'artifactVersion', 'type': 'str'}, + 'artifact_state': {'key': 'artifactState', 'type': 'str'}, + } + + def __init__( + self, + *, + artifact_type: Optional[Union[str, "ArtifactType"]] = None, + artifact_version: Optional[str] = None, + artifact_state: Optional[Union[str, "ArtifactState"]] = None, + **kwargs + ): + """ + :keyword artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :paramtype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :keyword artifact_version: The artifact version. + :paramtype artifact_version: str + :keyword artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :paramtype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + super(ProxyArtifactOverviewPropertiesValue, self).__init__(**kwargs) + self.artifact_type = artifact_type + self.artifact_version = artifact_version + self.artifact_state = artifact_state + + +class ProxyArtifactVersionsListOverview(ProxyResource): + """The proxy artifact overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :vartype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :ivar artifact_version: The artifact version. + :vartype artifact_version: str + :ivar artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :vartype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'artifact_type': {'key': 'properties.artifactType', 'type': 'str'}, + 'artifact_version': {'key': 'properties.artifactVersion', 'type': 'str'}, + 'artifact_state': {'key': 'properties.artifactState', 'type': 'str'}, + } + + def __init__( + self, + *, + artifact_type: Optional[Union[str, "ArtifactType"]] = None, + artifact_version: Optional[str] = None, + artifact_state: Optional[Union[str, "ArtifactState"]] = None, + **kwargs + ): + """ + :keyword artifact_type: The artifact type. Possible values include: "Unknown", "OCIArtifact", + "VhdImageFile", "ArmTemplate", "ImageFile". + :paramtype artifact_type: str or ~Microsoft.HybridNetwork.models.ArtifactType + :keyword artifact_version: The artifact version. + :paramtype artifact_version: str + :keyword artifact_state: The artifact state. Possible values include: "Unknown", "Preview", + "Active", "Deprecated". + :paramtype artifact_state: str or ~Microsoft.HybridNetwork.models.ArtifactState + """ + super(ProxyArtifactVersionsListOverview, self).__init__(**kwargs) + self.artifact_type = artifact_type + self.artifact_version = artifact_version + self.artifact_state = artifact_state + + +class ProxyArtifactVersionsOverviewListResult(msrest.serialization.Model): + """The proxy artifact list result. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of available proxy artifacts. + :vartype value: list[~Microsoft.HybridNetwork.models.ProxyArtifactVersionsListOverview] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ProxyArtifactVersionsListOverview]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["ProxyArtifactVersionsListOverview"]] = None, + **kwargs + ): + """ + :keyword value: A list of available proxy artifacts. + :paramtype value: list[~Microsoft.HybridNetwork.models.ProxyArtifactVersionsListOverview] + """ + super(ProxyArtifactVersionsOverviewListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class ProxyPublisherOverview(ProxyResource): + """The proxy publisher overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(ProxyPublisherOverview, self).__init__(**kwargs) + + +class ProxyPublisherOverviewListResult(msrest.serialization.Model): + """The proxy publisher list result. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of available proxy publishers. + :vartype value: list[~Microsoft.HybridNetwork.models.ProxyPublisherOverview] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[ProxyPublisherOverview]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["ProxyPublisherOverview"]] = None, + **kwargs + ): + """ + :keyword value: A list of available proxy publishers. + :paramtype value: list[~Microsoft.HybridNetwork.models.ProxyPublisherOverview] + """ + super(ProxyPublisherOverviewListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class Publisher(TrackedResource): + """publisher resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the publisher resource. Possible values + include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", "Deleted", + "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar scope: The publisher scope. Possible values include: "Unknown", "Public", "Private". + :vartype scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'scope': {'key': 'properties.scope', 'type': 'str'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + scope: Optional[Union[str, "PublisherScope"]] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword scope: The publisher scope. Possible values include: "Unknown", "Public", "Private". + :paramtype scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + """ + super(Publisher, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + self.scope = scope + + +class PublisherListResult(msrest.serialization.Model): + """A list of publishers. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of publishers. + :vartype value: list[~Microsoft.HybridNetwork.models.Publisher] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[Publisher]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["Publisher"]] = None, + **kwargs + ): + """ + :keyword value: A list of publishers. + :paramtype value: list[~Microsoft.HybridNetwork.models.Publisher] + """ + super(PublisherListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class ReferencedResource(msrest.serialization.Model): + """Reference to another resource. + + :ivar id: Resource ID. + :vartype id: str + """ + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + } + + def __init__( + self, + *, + id: Optional[str] = None, + **kwargs + ): + """ + :keyword id: Resource ID. + :paramtype id: str + """ + super(ReferencedResource, self).__init__(**kwargs) + self.id = id + + +class RequestMetadata(msrest.serialization.Model): + """Request metadata of execute request post call payload. + + All required parameters must be populated in order to send to Azure. + + :ivar relative_path: Required. The relative path of the request. + :vartype relative_path: str + :ivar http_method: Required. The http method of the request. Possible values include: + "Unknown", "Post", "Put", "Get", "Patch", "Delete". + :vartype http_method: str or ~Microsoft.HybridNetwork.models.HttpMethod + :ivar serialized_body: Required. The serialized body of the request. + :vartype serialized_body: str + :ivar api_version: The api version of the request. + :vartype api_version: str + """ + + _validation = { + 'relative_path': {'required': True}, + 'http_method': {'required': True}, + 'serialized_body': {'required': True}, + } + + _attribute_map = { + 'relative_path': {'key': 'relativePath', 'type': 'str'}, + 'http_method': {'key': 'httpMethod', 'type': 'str'}, + 'serialized_body': {'key': 'serializedBody', 'type': 'str'}, + 'api_version': {'key': 'apiVersion', 'type': 'str'}, + } + + def __init__( + self, + *, + relative_path: str, + http_method: Union[str, "HttpMethod"], + serialized_body: str, + api_version: Optional[str] = None, + **kwargs + ): + """ + :keyword relative_path: Required. The relative path of the request. + :paramtype relative_path: str + :keyword http_method: Required. The http method of the request. Possible values include: + "Unknown", "Post", "Put", "Get", "Patch", "Delete". + :paramtype http_method: str or ~Microsoft.HybridNetwork.models.HttpMethod + :keyword serialized_body: Required. The serialized body of the request. + :paramtype serialized_body: str + :keyword api_version: The api version of the request. + :paramtype api_version: str + """ + super(RequestMetadata, self).__init__(**kwargs) + self.relative_path = relative_path + self.http_method = http_method + self.serialized_body = serialized_body + self.api_version = api_version + + +class Site(TrackedResource): + """Site resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar provisioning_state: The provisioning state of the site resource. **TODO**\ : Confirm if + this is needed. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", + "Failed", "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar nfvis: List of NFVIs. + :vartype nfvis: list[~Microsoft.HybridNetwork.models.NFVIs] + :ivar site_network_service_references: The list of site network services on the site. + :vartype site_network_service_references: + list[~Microsoft.HybridNetwork.models.ReferencedResource] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'site_network_service_references': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'nfvis': {'key': 'properties.nfvis', 'type': '[NFVIs]'}, + 'site_network_service_references': {'key': 'properties.siteNetworkServiceReferences', 'type': '[ReferencedResource]'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + nfvis: Optional[List["NFVIs"]] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword nfvis: List of NFVIs. + :paramtype nfvis: list[~Microsoft.HybridNetwork.models.NFVIs] + """ + super(Site, self).__init__(tags=tags, location=location, **kwargs) + self.provisioning_state = None + self.nfvis = nfvis + self.site_network_service_references = None + + +class SiteListResult(msrest.serialization.Model): + """Response for sites API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of sites in a resource group. + :vartype value: list[~Microsoft.HybridNetwork.models.Site] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[Site]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["Site"]] = None, + **kwargs + ): + """ + :keyword value: A list of sites in a resource group. + :paramtype value: list[~Microsoft.HybridNetwork.models.Site] + """ + super(SiteListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class SiteNetworkService(TrackedResource): + """Site network service resource. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar id: Fully qualified resource ID for the resource. Ex - + /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + :vartype id: str + :ivar name: The name of the resource. + :vartype name: str + :ivar type: The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or + "Microsoft.Storage/storageAccounts". + :vartype type: str + :ivar system_data: Azure Resource Manager metadata containing createdBy and modifiedBy + information. + :vartype system_data: ~Microsoft.HybridNetwork.models.SystemData + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + :ivar location: Required. The geo-location where the resource lives. + :vartype location: str + :ivar identity: The managed identity of the Site network service, if configured. + :vartype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :ivar provisioning_state: The provisioning state of the site network service resource. Possible + values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", "Canceled", + "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar managed_resource_group_configuration: Managed resource group configuration. + :vartype managed_resource_group_configuration: + ~Microsoft.HybridNetwork.models.ManagedResourceGroupConfiguration + :ivar site_reference: The site details. + :vartype site_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :ivar publisher_name: The publisher name for the site network service. + :vartype publisher_name: str + :ivar publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :vartype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :ivar network_service_design_group_name: The network service design group name for the site + network service. + :vartype network_service_design_group_name: str + :ivar network_service_design_version_name: The network service design version for the site + network service. + :vartype network_service_design_version_name: str + :ivar network_service_design_version_offering_location: The location of the network service + design offering. + :vartype network_service_design_version_offering_location: str + :ivar desired_state_configuration_group_value_references: The goal state of the site network + service resource. This has references to the configuration group value objects that describe + the desired state of the site network service. + :vartype desired_state_configuration_group_value_references: dict[str, + ~Microsoft.HybridNetwork.models.ReferencedResource] + :ivar last_state_network_service_design_version_name: The network service design version for + the site network service. + :vartype last_state_network_service_design_version_name: str + :ivar last_state_configuration_group_value_references: The last state of the site network + service resource. + :vartype last_state_configuration_group_value_references: dict[str, + ~Microsoft.HybridNetwork.models.ReferencedResource] + """ + + _validation = { + 'id': {'readonly': True}, + 'name': {'readonly': True}, + 'type': {'readonly': True}, + 'system_data': {'readonly': True}, + 'location': {'required': True}, + 'provisioning_state': {'readonly': True}, + 'network_service_design_version_name': {'pattern': r'^[0-9]+\.[0-9]+\.[0-9]+$'}, + 'last_state_network_service_design_version_name': {'readonly': True, 'pattern': r'^[0-9]+\.[0-9]+\.[0-9]+$'}, + 'last_state_configuration_group_value_references': {'readonly': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + 'name': {'key': 'name', 'type': 'str'}, + 'type': {'key': 'type', 'type': 'str'}, + 'system_data': {'key': 'systemData', 'type': 'SystemData'}, + 'tags': {'key': 'tags', 'type': '{str}'}, + 'location': {'key': 'location', 'type': 'str'}, + 'identity': {'key': 'identity', 'type': 'ManagedServiceIdentity'}, + 'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'}, + 'managed_resource_group_configuration': {'key': 'properties.managedResourceGroupConfiguration', 'type': 'ManagedResourceGroupConfiguration'}, + 'site_reference': {'key': 'properties.siteReference', 'type': 'ReferencedResource'}, + 'publisher_name': {'key': 'properties.publisherName', 'type': 'str'}, + 'publisher_scope': {'key': 'properties.publisherScope', 'type': 'str'}, + 'network_service_design_group_name': {'key': 'properties.networkServiceDesignGroupName', 'type': 'str'}, + 'network_service_design_version_name': {'key': 'properties.networkServiceDesignVersionName', 'type': 'str'}, + 'network_service_design_version_offering_location': {'key': 'properties.networkServiceDesignVersionOfferingLocation', 'type': 'str'}, + 'desired_state_configuration_group_value_references': {'key': 'properties.desiredStateConfigurationGroupValueReferences', 'type': '{ReferencedResource}'}, + 'last_state_network_service_design_version_name': {'key': 'properties.lastStateNetworkServiceDesignVersionName', 'type': 'str'}, + 'last_state_configuration_group_value_references': {'key': 'properties.lastStateConfigurationGroupValueReferences', 'type': '{ReferencedResource}'}, + } + + def __init__( + self, + *, + location: str, + tags: Optional[Dict[str, str]] = None, + identity: Optional["ManagedServiceIdentity"] = None, + managed_resource_group_configuration: Optional["ManagedResourceGroupConfiguration"] = None, + site_reference: Optional["ReferencedResource"] = None, + publisher_name: Optional[str] = None, + publisher_scope: Optional[Union[str, "PublisherScope"]] = None, + network_service_design_group_name: Optional[str] = None, + network_service_design_version_name: Optional[str] = None, + network_service_design_version_offering_location: Optional[str] = None, + desired_state_configuration_group_value_references: Optional[Dict[str, "ReferencedResource"]] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + :keyword location: Required. The geo-location where the resource lives. + :paramtype location: str + :keyword identity: The managed identity of the Site network service, if configured. + :paramtype identity: ~Microsoft.HybridNetwork.models.ManagedServiceIdentity + :keyword managed_resource_group_configuration: Managed resource group configuration. + :paramtype managed_resource_group_configuration: + ~Microsoft.HybridNetwork.models.ManagedResourceGroupConfiguration + :keyword site_reference: The site details. + :paramtype site_reference: ~Microsoft.HybridNetwork.models.ReferencedResource + :keyword publisher_name: The publisher name for the site network service. + :paramtype publisher_name: str + :keyword publisher_scope: The scope of the publisher. Possible values include: "Unknown", + "Public", "Private". + :paramtype publisher_scope: str or ~Microsoft.HybridNetwork.models.PublisherScope + :keyword network_service_design_group_name: The network service design group name for the site + network service. + :paramtype network_service_design_group_name: str + :keyword network_service_design_version_name: The network service design version for the site + network service. + :paramtype network_service_design_version_name: str + :keyword network_service_design_version_offering_location: The location of the network service + design offering. + :paramtype network_service_design_version_offering_location: str + :keyword desired_state_configuration_group_value_references: The goal state of the site network + service resource. This has references to the configuration group value objects that describe + the desired state of the site network service. + :paramtype desired_state_configuration_group_value_references: dict[str, + ~Microsoft.HybridNetwork.models.ReferencedResource] + """ + super(SiteNetworkService, self).__init__(tags=tags, location=location, **kwargs) + self.identity = identity + self.provisioning_state = None + self.managed_resource_group_configuration = managed_resource_group_configuration + self.site_reference = site_reference + self.publisher_name = publisher_name + self.publisher_scope = publisher_scope + self.network_service_design_group_name = network_service_design_group_name + self.network_service_design_version_name = network_service_design_version_name + self.network_service_design_version_offering_location = network_service_design_version_offering_location + self.desired_state_configuration_group_value_references = desired_state_configuration_group_value_references + self.last_state_network_service_design_version_name = None + self.last_state_configuration_group_value_references = None + + +class SiteNetworkServiceListResult(msrest.serialization.Model): + """Response for site network services API service call. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar value: A list of site network services in a resource group. + :vartype value: list[~Microsoft.HybridNetwork.models.SiteNetworkService] + :ivar next_link: The URL to get the next set of results. + :vartype next_link: str + """ + + _validation = { + 'next_link': {'readonly': True}, + } + + _attribute_map = { + 'value': {'key': 'value', 'type': '[SiteNetworkService]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + value: Optional[List["SiteNetworkService"]] = None, + **kwargs + ): + """ + :keyword value: A list of site network services in a resource group. + :paramtype value: list[~Microsoft.HybridNetwork.models.SiteNetworkService] + """ + super(SiteNetworkServiceListResult, self).__init__(**kwargs) + self.value = value + self.next_link = None + + +class SystemData(msrest.serialization.Model): + """Metadata pertaining to creation and last modification of the resource. + + :ivar created_by: The identity that created the resource. + :vartype created_by: str + :ivar created_by_type: The type of identity that created the resource. Possible values include: + "User", "Application", "ManagedIdentity", "Key". + :vartype created_by_type: str or ~Microsoft.HybridNetwork.models.CreatedByType + :ivar created_at: The timestamp of resource creation (UTC). + :vartype created_at: ~datetime.datetime + :ivar last_modified_by: The identity that last modified the resource. + :vartype last_modified_by: str + :ivar last_modified_by_type: The type of identity that last modified the resource. Possible + values include: "User", "Application", "ManagedIdentity", "Key". + :vartype last_modified_by_type: str or ~Microsoft.HybridNetwork.models.CreatedByType + :ivar last_modified_at: The timestamp of resource last modification (UTC). + :vartype last_modified_at: ~datetime.datetime + """ + + _attribute_map = { + 'created_by': {'key': 'createdBy', 'type': 'str'}, + 'created_by_type': {'key': 'createdByType', 'type': 'str'}, + 'created_at': {'key': 'createdAt', 'type': 'iso-8601'}, + 'last_modified_by': {'key': 'lastModifiedBy', 'type': 'str'}, + 'last_modified_by_type': {'key': 'lastModifiedByType', 'type': 'str'}, + 'last_modified_at': {'key': 'lastModifiedAt', 'type': 'iso-8601'}, + } + + def __init__( + self, + *, + created_by: Optional[str] = None, + created_by_type: Optional[Union[str, "CreatedByType"]] = None, + created_at: Optional[datetime.datetime] = None, + last_modified_by: Optional[str] = None, + last_modified_by_type: Optional[Union[str, "CreatedByType"]] = None, + last_modified_at: Optional[datetime.datetime] = None, + **kwargs + ): + """ + :keyword created_by: The identity that created the resource. + :paramtype created_by: str + :keyword created_by_type: The type of identity that created the resource. Possible values + include: "User", "Application", "ManagedIdentity", "Key". + :paramtype created_by_type: str or ~Microsoft.HybridNetwork.models.CreatedByType + :keyword created_at: The timestamp of resource creation (UTC). + :paramtype created_at: ~datetime.datetime + :keyword last_modified_by: The identity that last modified the resource. + :paramtype last_modified_by: str + :keyword last_modified_by_type: The type of identity that last modified the resource. Possible + values include: "User", "Application", "ManagedIdentity", "Key". + :paramtype last_modified_by_type: str or ~Microsoft.HybridNetwork.models.CreatedByType + :keyword last_modified_at: The timestamp of resource last modification (UTC). + :paramtype last_modified_at: ~datetime.datetime + """ + super(SystemData, self).__init__(**kwargs) + self.created_by = created_by + self.created_by_type = created_by_type + self.created_at = created_at + self.last_modified_by = last_modified_by + self.last_modified_by_type = last_modified_by_type + self.last_modified_at = last_modified_at + + +class TagsObject(msrest.serialization.Model): + """Tags object for patch operations. + + :ivar tags: A set of tags. Resource tags. + :vartype tags: dict[str, str] + """ + + _attribute_map = { + 'tags': {'key': 'tags', 'type': '{str}'}, + } + + def __init__( + self, + *, + tags: Optional[Dict[str, str]] = None, + **kwargs + ): + """ + :keyword tags: A set of tags. Resource tags. + :paramtype tags: dict[str, str] + """ + super(TagsObject, self).__init__(**kwargs) + self.tags = tags + + +class UserAssignedIdentity(msrest.serialization.Model): + """User assigned identity properties. + + Variables are only populated by the server, and will be ignored when sending a request. + + :ivar principal_id: The principal ID of the assigned identity. + :vartype principal_id: str + :ivar client_id: The client ID of the assigned identity. + :vartype client_id: str + """ + + _validation = { + 'principal_id': {'readonly': True}, + 'client_id': {'readonly': True}, + } + + _attribute_map = { + 'principal_id': {'key': 'principalId', 'type': 'str'}, + 'client_id': {'key': 'clientId', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(UserAssignedIdentity, self).__init__(**kwargs) + self.principal_id = None + self.client_id = None + + +class VhdImageArtifactProfile(msrest.serialization.Model): + """Vhd artifact profile. + + :ivar vhd_name: Vhd name. + :vartype vhd_name: str + :ivar vhd_version: Vhd version. + :vartype vhd_version: str + """ + + _attribute_map = { + 'vhd_name': {'key': 'vhdName', 'type': 'str'}, + 'vhd_version': {'key': 'vhdVersion', 'type': 'str'}, + } + + def __init__( + self, + *, + vhd_name: Optional[str] = None, + vhd_version: Optional[str] = None, + **kwargs + ): + """ + :keyword vhd_name: Vhd name. + :paramtype vhd_name: str + :keyword vhd_version: Vhd version. + :paramtype vhd_version: str + """ + super(VhdImageArtifactProfile, self).__init__(**kwargs) + self.vhd_name = vhd_name + self.vhd_version = vhd_version + + +class VhdImageFileApplicationOverview(NetworkFunctionDefinitionApplicationOverview): + """Vhd image file Application overview. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar name: The name of the application. + :vartype name: str + :ivar artifact_type: Required. The application overview artifact type.Constant filled by + server. Possible values include: "Unknown", "HelmPackage", "VhdImageFile", "ArmTemplate", + "ImageFile". + :vartype artifact_type: str or + ~Microsoft.HybridNetwork.models.NetworkFunctionPublisherArtifactType + :ivar deploy_parameters_mapping_rule_profile: The deployment parameters mapping rule profile. + :vartype deploy_parameters_mapping_rule_profile: + ~Microsoft.HybridNetwork.models.AzureCoreVhdImageDeployMappingRuleProfile + """ + + _validation = { + 'name': {'readonly': True}, + 'artifact_type': {'required': True}, + 'deploy_parameters_mapping_rule_profile': {'readonly': True}, + } + + _attribute_map = { + 'name': {'key': 'name', 'type': 'str'}, + 'artifact_type': {'key': 'artifactType', 'type': 'str'}, + 'deploy_parameters_mapping_rule_profile': {'key': 'deployParametersMappingRuleProfile', 'type': 'AzureCoreVhdImageDeployMappingRuleProfile'}, + } + + def __init__( + self, + **kwargs + ): + """ + """ + super(VhdImageFileApplicationOverview, self).__init__(**kwargs) + self.artifact_type = 'VhdImageFile' # type: str + self.deploy_parameters_mapping_rule_profile = None + + +class VhdImageMappingRuleProfile(msrest.serialization.Model): + """Vhd mapping rule profile. + + :ivar user_configuration: List of values. + :vartype user_configuration: str + """ + + _attribute_map = { + 'user_configuration': {'key': 'userConfiguration', 'type': 'str'}, + } + + def __init__( + self, + *, + user_configuration: Optional[str] = None, + **kwargs + ): + """ + :keyword user_configuration: List of values. + :paramtype user_configuration: str + """ + super(VhdImageMappingRuleProfile, self).__init__(**kwargs) + self.user_configuration = user_configuration + + +class VirtualNetworkFunctionDefinitionVersion(NetworkFunctionDefinitionVersionPropertiesFormat): + """Virtual network function network function definition version properties . + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :ivar provisioning_state: The provisioning state of the network function definition version + resource. Possible values include: "Unknown", "Succeeded", "Accepted", "Deleting", "Failed", + "Canceled", "Deleted", "Converging". + :vartype provisioning_state: str or ~Microsoft.HybridNetwork.models.ProvisioningState + :ivar version_state: The network function definition version state. Possible values include: + "Unknown", "Preview", "Active", "Deprecated", "Validating", "ValidationFailed". + :vartype version_state: str or ~Microsoft.HybridNetwork.models.VersionState + :ivar description: The network function definition version description. + :vartype description: str + :ivar deploy_parameters: The deployment parameters of the network function definition version. + :vartype deploy_parameters: str + :ivar network_function_type: Required. The network function type.Constant filled by server. + Possible values include: "Unknown", "VirtualNetworkFunction", "ContainerizedNetworkFunction", + "DelegatedNetworkFunction". + :vartype network_function_type: str or ~Microsoft.HybridNetwork.models.NetworkFunctionType + :ivar network_function_template: Virtual network function template. + :vartype network_function_template: + ~Microsoft.HybridNetwork.models.VirtualNetworkFunctionTemplate + """ + + _validation = { + 'provisioning_state': {'readonly': True}, + 'version_state': {'readonly': True}, + 'network_function_type': {'required': True}, + } + + _attribute_map = { + 'provisioning_state': {'key': 'provisioningState', 'type': 'str'}, + 'version_state': {'key': 'versionState', 'type': 'str'}, + 'description': {'key': 'description', 'type': 'str'}, + 'deploy_parameters': {'key': 'deployParameters', 'type': 'str'}, + 'network_function_type': {'key': 'networkFunctionType', 'type': 'str'}, + 'network_function_template': {'key': 'networkFunctionTemplate', 'type': 'VirtualNetworkFunctionTemplate'}, + } + + def __init__( + self, + *, + description: Optional[str] = None, + deploy_parameters: Optional[str] = None, + network_function_template: Optional["VirtualNetworkFunctionTemplate"] = None, + **kwargs + ): + """ + :keyword description: The network function definition version description. + :paramtype description: str + :keyword deploy_parameters: The deployment parameters of the network function definition + version. + :paramtype deploy_parameters: str + :keyword network_function_template: Virtual network function template. + :paramtype network_function_template: + ~Microsoft.HybridNetwork.models.VirtualNetworkFunctionTemplate + """ + super(VirtualNetworkFunctionDefinitionVersion, self).__init__(description=description, deploy_parameters=deploy_parameters, **kwargs) + self.network_function_type = 'VirtualNetworkFunction' # type: str + self.network_function_template = network_function_template diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py b/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py new file mode 100644 index 00000000000..6c86a395e1f --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py @@ -0,0 +1,53 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._configuration_group_schemas_operations import ConfigurationGroupSchemasOperations +from ._configuration_group_values_operations import ConfigurationGroupValuesOperations +from ._network_functions_operations import NetworkFunctionsOperations +from ._components_operations import ComponentsOperations +from ._network_function_definition_groups_operations import NetworkFunctionDefinitionGroupsOperations +from ._preview_subscriptions_operations import PreviewSubscriptionsOperations +from ._network_function_definition_versions_operations import NetworkFunctionDefinitionVersionsOperations +from ._network_function_ready_k8_s_operations import NetworkFunctionReadyK8SOperations +from ._network_service_design_groups_operations import NetworkServiceDesignGroupsOperations +from ._network_service_design_versions_operations import NetworkServiceDesignVersionsOperations +from ._operations import Operations +from ._proxy_publisher_operations import ProxyPublisherOperations +from ._proxy_network_function_definition_groups_operations import ProxyNetworkFunctionDefinitionGroupsOperations +from ._proxy_network_function_definition_versions_operations import ProxyNetworkFunctionDefinitionVersionsOperations +from ._publishers_operations import PublishersOperations +from ._artifact_stores_operations import ArtifactStoresOperations +from ._artifact_manifests_operations import ArtifactManifestsOperations +from ._proxy_artifact_operations import ProxyArtifactOperations +from ._hybrid_network_management_client_operations import HybridNetworkManagementClientOperationsMixin +from ._sites_operations import SitesOperations +from ._site_network_services_operations import SiteNetworkServicesOperations + +__all__ = [ + 'ConfigurationGroupSchemasOperations', + 'ConfigurationGroupValuesOperations', + 'NetworkFunctionsOperations', + 'ComponentsOperations', + 'NetworkFunctionDefinitionGroupsOperations', + 'PreviewSubscriptionsOperations', + 'NetworkFunctionDefinitionVersionsOperations', + 'NetworkFunctionReadyK8SOperations', + 'NetworkServiceDesignGroupsOperations', + 'NetworkServiceDesignVersionsOperations', + 'Operations', + 'ProxyPublisherOperations', + 'ProxyNetworkFunctionDefinitionGroupsOperations', + 'ProxyNetworkFunctionDefinitionVersionsOperations', + 'PublishersOperations', + 'ArtifactStoresOperations', + 'ArtifactManifestsOperations', + 'ProxyArtifactOperations', + 'HybridNetworkManagementClientOperationsMixin', + 'SitesOperations', + 'SiteNetworkServicesOperations', +] diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_artifact_manifests_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_artifact_manifests_operations.py new file mode 100644 index 00000000000..3bbbfa5626c --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_artifact_manifests_operations.py @@ -0,0 +1,1050 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_by_artifact_store_request( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_delete_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactManifestName": _SERIALIZER.url("artifact_manifest_name", artifact_manifest_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactManifestName": _SERIALIZER.url("artifact_manifest_name", artifact_manifest_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactManifestName": _SERIALIZER.url("artifact_manifest_name", artifact_manifest_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_request( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactManifestName": _SERIALIZER.url("artifact_manifest_name", artifact_manifest_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_credential_request( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}/listCredential") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactManifestName": _SERIALIZER.url("artifact_manifest_name", artifact_manifest_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="POST", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_state_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}/updateState") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactManifestName": _SERIALIZER.url("artifact_manifest_name", artifact_manifest_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="POST", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class ArtifactManifestsOperations(object): + """ArtifactManifestsOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_artifact_store( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.ArtifactManifestListResult"] + """Gets information about the artifact manifest. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ArtifactManifestListResult or the result of + cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.ArtifactManifestListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifestListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_artifact_store_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_artifact_store.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_artifact_store_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ArtifactManifestListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_artifact_store.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests"} # type: ignore + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes the specified artifact manifest. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + def _create_or_update_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + parameters, # type: "_models.ArtifactManifest" + **kwargs # type: Any + ): + # type: (...) -> "_models.ArtifactManifest" + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifest"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ArtifactManifest') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('ArtifactManifest', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('ArtifactManifest', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + parameters, # type: "_models.ArtifactManifest" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.ArtifactManifest"] + """Creates or updates a artifact manifest. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :param parameters: Parameters supplied to the create or update artifact manifest operation. + :type parameters: ~Microsoft.HybridNetwork.models.ArtifactManifest + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either ArtifactManifest or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.ArtifactManifest] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifest"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ArtifactManifest', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.ArtifactManifest" + """Gets information about a artifact manifest resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ArtifactManifest, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ArtifactManifest + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifest"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ArtifactManifest', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + + @distributed_trace + def update( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.ArtifactManifest" + """Updates a artifact manifest resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :param parameters: Parameters supplied to the create or update artifact manifest operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ArtifactManifest, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ArtifactManifest + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifest"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ArtifactManifest', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}"} # type: ignore + + + @distributed_trace + def list_credential( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.ArtifactAccessCredential" + """List credential for publishing artifacts defined in artifact manifest. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ArtifactAccessCredential, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ArtifactAccessCredential + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactAccessCredential"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_list_credential_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_credential.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ArtifactAccessCredential', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + list_credential.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}/listCredential"} # type: ignore + + + def _update_state_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + parameters, # type: "_models.ArtifactManifestUpdateState" + **kwargs # type: Any + ): + # type: (...) -> Optional["_models.ArtifactManifestUpdateState"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.ArtifactManifestUpdateState"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ArtifactManifestUpdateState') + + request = build_update_state_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._update_state_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('ArtifactManifestUpdateState', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _update_state_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}/updateState"} # type: ignore + + + @distributed_trace + def begin_update_state( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_manifest_name, # type: str + parameters, # type: "_models.ArtifactManifestUpdateState" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.ArtifactManifestUpdateState"] + """Update state for artifact manifest. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest_name: The name of the artifact manifest. + :type artifact_manifest_name: str + :param parameters: Parameters supplied to update the state of artifact manifest. + :type parameters: ~Microsoft.HybridNetwork.models.ArtifactManifestUpdateState + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either ArtifactManifestUpdateState or the result + of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.ArtifactManifestUpdateState] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactManifestUpdateState"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._update_state_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ArtifactManifestUpdateState', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_update_state.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactManifests/{artifactManifestName}/updateState"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_artifact_stores_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_artifact_stores_operations.py new file mode 100644 index 00000000000..a70ff6449df --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_artifact_stores_operations.py @@ -0,0 +1,721 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_by_publisher_request( + resource_group_name, # type: str + publisher_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_delete_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_request( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class ArtifactStoresOperations(object): + """ArtifactStoresOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_publisher( + self, + resource_group_name, # type: str + publisher_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.ArtifactStoreListResult"] + """Gets information of the ArtifactStores under publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ArtifactStoreListResult or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.ArtifactStoreListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactStoreListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_publisher.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ArtifactStoreListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_publisher.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores"} # type: ignore + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes the specified artifact store. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + + def _create_or_update_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + parameters, # type: "_models.ArtifactStore" + **kwargs # type: Any + ): + # type: (...) -> "_models.ArtifactStore" + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactStore"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ArtifactStore') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('ArtifactStore', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('ArtifactStore', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + parameters, # type: "_models.ArtifactStore" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.ArtifactStore"] + """Creates or updates a artifact store. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param parameters: Parameters supplied to the create or update application group operation. + :type parameters: ~Microsoft.HybridNetwork.models.ArtifactStore + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either ArtifactStore or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.ArtifactStore] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactStore"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ArtifactStore', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.ArtifactStore" + """Gets information about the specified artifact store. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ArtifactStore, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ArtifactStore + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactStore"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ArtifactStore', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + + + @distributed_trace + def update( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.ArtifactStore" + """Update artifact store resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param parameters: Parameters supplied to the create or update application group operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ArtifactStore, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ArtifactStore + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ArtifactStore"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ArtifactStore', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_components_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_components_operations.py new file mode 100644 index 00000000000..dfc62a9c4b8 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_components_operations.py @@ -0,0 +1,277 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_get_request( + resource_group_name, # type: str + network_function_name, # type: str + component_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/components/{componentName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "networkFunctionName": _SERIALIZER.url("network_function_name", network_function_name, 'str'), + "componentName": _SERIALIZER.url("component_name", component_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_network_function_request( + resource_group_name, # type: str + subscription_id, # type: str + network_function_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/components") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "networkFunctionName": _SERIALIZER.url("network_function_name", network_function_name, 'str'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class ComponentsOperations(object): + """ComponentsOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def get( + self, + resource_group_name, # type: str + network_function_name, # type: str + component_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.Component" + """Gets information about the specified application instance resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: The name of the network function resource. + :type network_function_name: str + :param component_name: The name of the component. + :type component_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Component, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.Component + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.Component"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + component_name=component_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Component', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/components/{componentName}"} # type: ignore + + + @distributed_trace + def list_by_network_function( + self, + resource_group_name, # type: str + network_function_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.ComponentListResult"] + """Lists all the component resources in a network function. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: The name of the network function. + :type network_function_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ComponentListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.ComponentListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ComponentListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_network_function_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + network_function_name=network_function_name, + api_version=api_version, + template_url=self.list_by_network_function.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_network_function_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + network_function_name=network_function_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ComponentListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_network_function.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/components"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_configuration_group_schemas_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_configuration_group_schemas_operations.py new file mode 100644 index 00000000000..b4a05913f46 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_configuration_group_schemas_operations.py @@ -0,0 +1,900 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_by_publisher_request( + resource_group_name, # type: str + publisher_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_delete_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "configurationGroupSchemaName": _SERIALIZER.url("configuration_group_schema_name", configuration_group_schema_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "configurationGroupSchemaName": _SERIALIZER.url("configuration_group_schema_name", configuration_group_schema_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "configurationGroupSchemaName": _SERIALIZER.url("configuration_group_schema_name", configuration_group_schema_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_request( + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "configurationGroupSchemaName": _SERIALIZER.url("configuration_group_schema_name", configuration_group_schema_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_state_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}/updateState") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "configurationGroupSchemaName": _SERIALIZER.url("configuration_group_schema_name", configuration_group_schema_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="POST", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class ConfigurationGroupSchemasOperations(object): + """ConfigurationGroupSchemasOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_publisher( + self, + resource_group_name, # type: str + publisher_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.ConfigurationGroupSchemaListResult"] + """Gets information of the configuration group schemas under a publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ConfigurationGroupSchemaListResult or the result + of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.ConfigurationGroupSchemaListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchemaListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_publisher.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ConfigurationGroupSchemaListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_publisher.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas"} # type: ignore + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes a specified configuration group schema. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param configuration_group_schema_name: The name of the configuration group schema. + :type configuration_group_schema_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + def _create_or_update_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + parameters, # type: "_models.ConfigurationGroupSchema" + **kwargs # type: Any + ): + # type: (...) -> "_models.ConfigurationGroupSchema" + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchema"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ConfigurationGroupSchema') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('ConfigurationGroupSchema', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('ConfigurationGroupSchema', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + parameters, # type: "_models.ConfigurationGroupSchema" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.ConfigurationGroupSchema"] + """Creates or updates a configuration group schema. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param configuration_group_schema_name: The name of the configuration group schema. + :type configuration_group_schema_name: str + :param parameters: Parameters supplied to the create or update configuration group schema + resource. + :type parameters: ~Microsoft.HybridNetwork.models.ConfigurationGroupSchema + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either ConfigurationGroupSchema or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.ConfigurationGroupSchema] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchema"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ConfigurationGroupSchema', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.ConfigurationGroupSchema" + """Gets information about the specified configuration group schema. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param configuration_group_schema_name: The name of the configuration group schema. + :type configuration_group_schema_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ConfigurationGroupSchema, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ConfigurationGroupSchema + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchema"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ConfigurationGroupSchema', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + + @distributed_trace + def update( + self, + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.ConfigurationGroupSchema" + """Updates a configuration group schema resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param configuration_group_schema_name: The name of the configuration group schema. + :type configuration_group_schema_name: str + :param parameters: Parameters supplied to the create or update network service design version + operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ConfigurationGroupSchema, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ConfigurationGroupSchema + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchema"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ConfigurationGroupSchema', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}"} # type: ignore + + + def _update_state_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + parameters, # type: "_models.ConfigurationGroupSchemaVersionUpdateState" + **kwargs # type: Any + ): + # type: (...) -> Optional["_models.ConfigurationGroupSchemaVersionUpdateState"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.ConfigurationGroupSchemaVersionUpdateState"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ConfigurationGroupSchemaVersionUpdateState') + + request = build_update_state_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._update_state_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('ConfigurationGroupSchemaVersionUpdateState', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _update_state_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}/updateState"} # type: ignore + + + @distributed_trace + def begin_update_state( + self, + resource_group_name, # type: str + publisher_name, # type: str + configuration_group_schema_name, # type: str + parameters, # type: "_models.ConfigurationGroupSchemaVersionUpdateState" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.ConfigurationGroupSchemaVersionUpdateState"] + """Update configuration group schema state. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param configuration_group_schema_name: The name of the configuration group schema. + :type configuration_group_schema_name: str + :param parameters: Parameters supplied to update the state of configuration group schema. + :type parameters: ~Microsoft.HybridNetwork.models.ConfigurationGroupSchemaVersionUpdateState + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either + ConfigurationGroupSchemaVersionUpdateState or the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.ConfigurationGroupSchemaVersionUpdateState] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupSchemaVersionUpdateState"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._update_state_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + configuration_group_schema_name=configuration_group_schema_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ConfigurationGroupSchemaVersionUpdateState', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_update_state.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/configurationGroupSchemas/{configurationGroupSchemaName}/updateState"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_configuration_group_values_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_configuration_group_values_operations.py new file mode 100644 index 00000000000..f575f04f744 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_configuration_group_values_operations.py @@ -0,0 +1,796 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_delete_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + configuration_group_value_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "configurationGroupValueName": _SERIALIZER.url("configuration_group_value_name", configuration_group_value_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + subscription_id, # type: str + resource_group_name, # type: str + configuration_group_value_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "configurationGroupValueName": _SERIALIZER.url("configuration_group_value_name", configuration_group_value_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + configuration_group_value_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "configurationGroupValueName": _SERIALIZER.url("configuration_group_value_name", configuration_group_value_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_tags_request( + subscription_id, # type: str + resource_group_name, # type: str + configuration_group_value_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "configurationGroupValueName": _SERIALIZER.url("configuration_group_value_name", configuration_group_value_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_subscription_request( + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/configurationGroupValues") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_resource_group_request( + subscription_id, # type: str + resource_group_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class ConfigurationGroupValuesOperations(object): + """ConfigurationGroupValuesOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + configuration_group_value_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + configuration_group_value_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes the specified hybrid configuration group value. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param configuration_group_value_name: The name of the configuration group value. + :type configuration_group_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + configuration_group_value_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.ConfigurationGroupValue" + """Gets information about the specified hybrid configuration group values. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param configuration_group_value_name: The name of the configuration group value. + :type configuration_group_value_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ConfigurationGroupValue, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ConfigurationGroupValue + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValue"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ConfigurationGroupValue', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + + def _create_or_update_initial( + self, + resource_group_name, # type: str + configuration_group_value_name, # type: str + parameters, # type: "_models.ConfigurationGroupValue" + **kwargs # type: Any + ): + # type: (...) -> "_models.ConfigurationGroupValue" + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValue"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ConfigurationGroupValue') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('ConfigurationGroupValue', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('ConfigurationGroupValue', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + configuration_group_value_name, # type: str + parameters, # type: "_models.ConfigurationGroupValue" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.ConfigurationGroupValue"] + """Creates or updates a hybrid configuration group value. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param configuration_group_value_name: The name of the configuration group value. + :type configuration_group_value_name: str + :param parameters: Parameters supplied to the create or update configuration group value + resource. + :type parameters: ~Microsoft.HybridNetwork.models.ConfigurationGroupValue + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either ConfigurationGroupValue or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.ConfigurationGroupValue] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValue"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ConfigurationGroupValue', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + @distributed_trace + def update_tags( + self, + resource_group_name, # type: str + configuration_group_value_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.ConfigurationGroupValue" + """Updates a hybrid configuration group tags. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param configuration_group_value_name: The name of the configuration group value. + :type configuration_group_value_name: str + :param parameters: Parameters supplied to update configuration group values tags. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ConfigurationGroupValue, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ConfigurationGroupValue + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValue"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_tags_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + configuration_group_value_name=configuration_group_value_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update_tags.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ConfigurationGroupValue', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update_tags.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues/{configurationGroupValueName}"} # type: ignore + + + @distributed_trace + def list_by_subscription( + self, + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.ConfigurationGroupValueListResult"] + """Lists all sites in the configuration group value in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ConfigurationGroupValueListResult or the result of + cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.ConfigurationGroupValueListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValueListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ConfigurationGroupValueListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/configurationGroupValues"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.ConfigurationGroupValueListResult"] + """Lists all the hybrid network configurationGroupValues in a resource group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ConfigurationGroupValueListResult or the result of + cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.ConfigurationGroupValueListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ConfigurationGroupValueListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ConfigurationGroupValueListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/configurationGroupValues"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_hybrid_network_management_client_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_hybrid_network_management_client_operations.py new file mode 100644 index 00000000000..67abfbe2c26 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_hybrid_network_management_client_operations.py @@ -0,0 +1,227 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_change_artifact_state_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_version_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + artifact_name = kwargs.pop('artifact_name') # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactVersions/{artifactVersionName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactVersionName": _SERIALIZER.url("artifact_version_name", artifact_version_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['artifactName'] = _SERIALIZER.query("artifact_name", artifact_name, 'str', max_length=64, min_length=0) + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class HybridNetworkManagementClientOperationsMixin(object): + + def _change_artifact_state_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_name, # type: str + artifact_version_name, # type: str + parameters, # type: "_models.ArtifactChangeState" + **kwargs # type: Any + ): + # type: (...) -> Optional["_models.ProxyArtifactVersionsListOverview"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.ProxyArtifactVersionsListOverview"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ArtifactChangeState') + + request = build_change_artifact_state_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_version_name=artifact_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + artifact_name=artifact_name, + json=_json, + template_url=self._change_artifact_state_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('ProxyArtifactVersionsListOverview', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _change_artifact_state_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactVersions/{artifactVersionName}"} # type: ignore + + + @distributed_trace + def begin_change_artifact_state( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_name, # type: str + artifact_version_name, # type: str + parameters, # type: "_models.ArtifactChangeState" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.ProxyArtifactVersionsListOverview"] + """Change artifact state defined in artifact store. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_name: The name of the artifact. + :type artifact_name: str + :param artifact_version_name: The name of the artifact version. + :type artifact_version_name: str + :param parameters: Parameters supplied to update the state of artifact manifest. + :type parameters: ~Microsoft.HybridNetwork.models.ArtifactChangeState + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either ProxyArtifactVersionsListOverview or the + result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.ProxyArtifactVersionsListOverview] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.ProxyArtifactVersionsListOverview"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._change_artifact_state_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_name=artifact_name, + artifact_version_name=artifact_version_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('ProxyArtifactVersionsListOverview', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_change_artifact_state.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactVersions/{artifactVersionName}"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_network_function_definition_groups_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_network_function_definition_groups_operations.py new file mode 100644 index 00000000000..4761e907eb4 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_network_function_definition_groups_operations.py @@ -0,0 +1,729 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_by_publisher_request( + resource_group_name, # type: str + publisher_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_delete_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_request( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class NetworkFunctionDefinitionGroupsOperations(object): + """NetworkFunctionDefinitionGroupsOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_publisher( + self, + resource_group_name, # type: str + publisher_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.NetworkFunctionDefinitionGroupListResult"] + """Gets information of the network function definition groups under a publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionDefinitionGroupListResult or the + result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroupListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroupListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_publisher.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_publisher_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionDefinitionGroupListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_publisher.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups"} # type: ignore + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes a specified network function definition group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + + def _create_or_update_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + parameters, # type: "_models.NetworkFunctionDefinitionGroup" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionDefinitionGroup" + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkFunctionDefinitionGroup') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkFunctionDefinitionGroup', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkFunctionDefinitionGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + parameters, # type: "_models.NetworkFunctionDefinitionGroup" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.NetworkFunctionDefinitionGroup"] + """Creates or updates a network function definition group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param parameters: Parameters supplied to the create or update publisher network function + definition group operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either NetworkFunctionDefinitionGroup or the + result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroup"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkFunctionDefinitionGroup', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionDefinitionGroup" + """Gets information about the specified networkFunctionDefinition group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionGroup, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + + + @distributed_trace + def update( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionDefinitionGroup" + """Updates a network function definition group resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param parameters: Parameters supplied to the create or update publisher network function + definition group operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionGroup, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroup + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_network_function_definition_versions_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_network_function_definition_versions_operations.py new file mode 100644 index 00000000000..2901c53336b --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_network_function_definition_versions_operations.py @@ -0,0 +1,962 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_delete_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionVersionName": _SERIALIZER.url("network_function_definition_version_name", network_function_definition_version_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionVersionName": _SERIALIZER.url("network_function_definition_version_name", network_function_definition_version_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionVersionName": _SERIALIZER.url("network_function_definition_version_name", network_function_definition_version_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_request( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionVersionName": _SERIALIZER.url("network_function_definition_version_name", network_function_definition_version_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_network_function_definition_group_request( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_state_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}/updateState") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionVersionName": _SERIALIZER.url("network_function_definition_version_name", network_function_definition_version_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="POST", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class NetworkFunctionDefinitionVersionsOperations(object): + """NetworkFunctionDefinitionVersionsOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes the specified network function definition version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + def _create_or_update_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + parameters, # type: "_models.NetworkFunctionDefinitionVersion" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionDefinitionVersion" + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkFunctionDefinitionVersion') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkFunctionDefinitionVersion', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkFunctionDefinitionVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + parameters, # type: "_models.NetworkFunctionDefinitionVersion" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.NetworkFunctionDefinitionVersion"] + """Creates or updates a network function definition version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :param parameters: Parameters supplied to the create or update network function definition + version operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either NetworkFunctionDefinitionVersion or the + result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersion"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkFunctionDefinitionVersion', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionDefinitionVersion" + """Gets information about a network function definition version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionVersion, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + + @distributed_trace + def update( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionDefinitionVersion" + """Updates a network function definition version resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :param parameters: Parameters supplied to the create or update network function definition + version operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionVersion, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersion + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + + + @distributed_trace + def list_by_network_function_definition_group( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.NetworkFunctionDefinitionVersionListResult"] + """Gets information about a list of network function definition versions under a network function + definition group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionDefinitionVersionListResult or the + result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersionListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_network_function_definition_group_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_network_function_definition_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_network_function_definition_group_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionDefinitionVersionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_network_function_definition_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions"} # type: ignore + + def _update_state_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + parameters, # type: "_models.NetworkFunctionDefinitionVersionUpdateState" + **kwargs # type: Any + ): + # type: (...) -> Optional["_models.NetworkFunctionDefinitionVersionUpdateState"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.NetworkFunctionDefinitionVersionUpdateState"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkFunctionDefinitionVersionUpdateState') + + request = build_update_state_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._update_state_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('NetworkFunctionDefinitionVersionUpdateState', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _update_state_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}/updateState"} # type: ignore + + + @distributed_trace + def begin_update_state( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + parameters, # type: "_models.NetworkFunctionDefinitionVersionUpdateState" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.NetworkFunctionDefinitionVersionUpdateState"] + """Update network function definition version state. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :param parameters: Parameters supplied to update the state of network function definition + version. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionUpdateState + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either + NetworkFunctionDefinitionVersionUpdateState or the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionUpdateState] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersionUpdateState"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._update_state_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkFunctionDefinitionVersionUpdateState', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_update_state.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}/updateState"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_network_function_ready_k8_s_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_network_function_ready_k8_s_operations.py new file mode 100644 index 00000000000..0f1dacc47bb --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_network_function_ready_k8_s_operations.py @@ -0,0 +1,796 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_delete_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + network_function_ready_k8_s_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "networkFunctionReadyK8sName": _SERIALIZER.url("network_function_ready_k8_s_name", network_function_ready_k8_s_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + subscription_id, # type: str + resource_group_name, # type: str + network_function_ready_k8_s_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "networkFunctionReadyK8sName": _SERIALIZER.url("network_function_ready_k8_s_name", network_function_ready_k8_s_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + network_function_ready_k8_s_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "networkFunctionReadyK8sName": _SERIALIZER.url("network_function_ready_k8_s_name", network_function_ready_k8_s_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_tags_request( + subscription_id, # type: str + resource_group_name, # type: str + network_function_ready_k8_s_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "networkFunctionReadyK8sName": _SERIALIZER.url("network_function_ready_k8_s_name", network_function_ready_k8_s_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_subscription_request( + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_resource_group_request( + subscription_id, # type: str + resource_group_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class NetworkFunctionReadyK8SOperations(object): + """NetworkFunctionReadyK8SOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + network_function_ready_k8_s_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + network_function_ready_k8_s_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes the specified network function ready K8s. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_ready_k8_s_name: The name of the network function ready K8s. + :type network_function_ready_k8_s_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + network_function_ready_k8_s_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionReadyK8S" + """Gets information about the specified network function ready K8s. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_ready_k8_s_name: The name of the network function ready K8s. + :type network_function_ready_k8_s_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionReadyK8S, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8S"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionReadyK8S', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + + def _create_or_update_initial( + self, + resource_group_name, # type: str + network_function_ready_k8_s_name, # type: str + parameters, # type: "_models.NetworkFunctionReadyK8S" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionReadyK8S" + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8S"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkFunctionReadyK8S') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkFunctionReadyK8S', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkFunctionReadyK8S', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + network_function_ready_k8_s_name, # type: str + parameters, # type: "_models.NetworkFunctionReadyK8S" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.NetworkFunctionReadyK8S"] + """Creates or updates a network function ready K8s. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_ready_k8_s_name: The name of the network function ready K8s. + :type network_function_ready_k8_s_name: str + :param parameters: Parameters supplied to the create or update network function ready K8s + operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either NetworkFunctionReadyK8S or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8S"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkFunctionReadyK8S', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + @distributed_trace + def update_tags( + self, + resource_group_name, # type: str + network_function_ready_k8_s_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionReadyK8S" + """Updates a network function ready K8s update tags. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_ready_k8_s_name: The name of the network function ready K8s. + :type network_function_ready_k8_s_name: str + :param parameters: Parameters supplied to update network function ready K8s tags. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionReadyK8S, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8S + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8S"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_tags_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + network_function_ready_k8_s_name=network_function_ready_k8_s_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update_tags.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionReadyK8S', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update_tags.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s/{networkFunctionReadyK8sName}"} # type: ignore + + + @distributed_trace + def list_by_subscription( + self, + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.NetworkFunctionReadyK8SListResult"] + """Lists all network function ready K8s in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionReadyK8SListResult or the result of + cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8SListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8SListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionReadyK8SListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.NetworkFunctionReadyK8SListResult"] + """Lists all network function ready K8s in the resource group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionReadyK8SListResult or the result of + cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionReadyK8SListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionReadyK8SListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionReadyK8SListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctionReadyK8s"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_network_functions_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_network_functions_operations.py new file mode 100644 index 00000000000..55ce90894c3 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_network_functions_operations.py @@ -0,0 +1,951 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_delete_request_initial( + resource_group_name, # type: str + network_function_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "networkFunctionName": _SERIALIZER.url("network_function_name", network_function_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + resource_group_name, # type: str + network_function_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "networkFunctionName": _SERIALIZER.url("network_function_name", network_function_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + resource_group_name, # type: str + network_function_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "networkFunctionName": _SERIALIZER.url("network_function_name", network_function_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_tags_request( + resource_group_name, # type: str + network_function_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "networkFunctionName": _SERIALIZER.url("network_function_name", network_function_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_subscription_request( + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/networkFunctions") + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_resource_group_request( + resource_group_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_execute_request_request_initial( + resource_group_name, # type: str + network_function_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/executeRequest") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "networkFunctionName": _SERIALIZER.url("network_function_name", network_function_name, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="POST", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class NetworkFunctionsOperations(object): + """NetworkFunctionsOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + network_function_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + network_function_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes the specified network function resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: The name of the network function. + :type network_function_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + network_function_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunction" + """Gets information about the specified network function resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: The name of the network function resource. + :type network_function_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunction, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunction + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunction"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunction', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + + def _create_or_update_initial( + self, + resource_group_name, # type: str + network_function_name, # type: str + parameters, # type: "_models.NetworkFunction" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunction" + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunction"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkFunction') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkFunction', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkFunction', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + network_function_name, # type: str + parameters, # type: "_models.NetworkFunction" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.NetworkFunction"] + """Creates or updates a network function resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: Resource name for the network function resource. + :type network_function_name: str + :param parameters: Parameters supplied in the body to the create or update network function + operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkFunction + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either NetworkFunction or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.NetworkFunction] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunction"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkFunction', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + @distributed_trace + def update_tags( + self, + resource_group_name, # type: str + network_function_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunction" + """Updates the tags for the network function resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: Resource name for the network function resource. + :type network_function_name: str + :param parameters: Parameters supplied to the update network function tags operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunction, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunction + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunction"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_tags_request( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update_tags.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunction', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update_tags.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}"} # type: ignore + + + @distributed_trace + def list_by_subscription( + self, + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.NetworkFunctionListResult"] + """Lists all the network functions in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionListResult or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/networkFunctions"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.NetworkFunctionListResult"] + """Lists all the network function resources in a resource group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionListResult or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions"} # type: ignore + + def _execute_request_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + network_function_name, # type: str + parameters, # type: "_models.ExecuteRequestParameters" + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'ExecuteRequestParameters') + + request = build_execute_request_request_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._execute_request_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _execute_request_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/executeRequest"} # type: ignore + + + @distributed_trace + def begin_execute_request( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + network_function_name, # type: str + parameters, # type: "_models.ExecuteRequestParameters" + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Execute a request to services on a network function. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param network_function_name: The name of the network function. + :type network_function_name: str + :param parameters: Payload for execute request post call. + :type parameters: ~Microsoft.HybridNetwork.models.ExecuteRequestParameters + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._execute_request_initial( + resource_group_name=resource_group_name, + network_function_name=network_function_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_execute_request.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/networkFunctions/{networkFunctionName}/executeRequest"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_network_service_design_groups_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_network_service_design_groups_operations.py new file mode 100644 index 00000000000..699e58e52fd --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_network_service_design_groups_operations.py @@ -0,0 +1,725 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_by_publisher_request( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_delete_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignGroupName": _SERIALIZER.url("network_service_design_group_name", network_service_design_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignGroupName": _SERIALIZER.url("network_service_design_group_name", network_service_design_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignGroupName": _SERIALIZER.url("network_service_design_group_name", network_service_design_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_request( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignGroupName": _SERIALIZER.url("network_service_design_group_name", network_service_design_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class NetworkServiceDesignGroupsOperations(object): + """NetworkServiceDesignGroupsOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_publisher( + self, + resource_group_name, # type: str + publisher_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.NetworkServiceDesignGroupListResult"] + """Gets information of the network service design groups under a publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkServiceDesignGroupListResult or the result + of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.NetworkServiceDesignGroupListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignGroupListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_publisher_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + api_version=api_version, + template_url=self.list_by_publisher.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_publisher_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkServiceDesignGroupListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_publisher.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups"} # type: ignore + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes a specified network service design group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + + def _create_or_update_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + parameters, # type: "_models.NetworkServiceDesignGroup" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkServiceDesignGroup" + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkServiceDesignGroup') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkServiceDesignGroup', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkServiceDesignGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + parameters, # type: "_models.NetworkServiceDesignGroup" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.NetworkServiceDesignGroup"] + """Creates or updates a network service design group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param parameters: Parameters supplied to the create or update publisher network service design + group operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either NetworkServiceDesignGroup or the result + of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignGroup"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkServiceDesignGroup', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkServiceDesignGroup" + """Gets information about the specified networkServiceDesign group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkServiceDesignGroup, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkServiceDesignGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + + + @distributed_trace + def update( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkServiceDesignGroup" + """Updates a network service design groups resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param parameters: Parameters supplied to the create or update publisher network service design + group operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkServiceDesignGroup, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkServiceDesignGroup + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignGroup"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkServiceDesignGroup', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_network_service_design_versions_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_network_service_design_versions_operations.py new file mode 100644 index 00000000000..ee4decf9ff7 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_network_service_design_versions_operations.py @@ -0,0 +1,950 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_delete_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignGroupName": _SERIALIZER.url("network_service_design_group_name", network_service_design_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignVersionName": _SERIALIZER.url("network_service_design_version_name", network_service_design_version_name, 'str', max_length=64, min_length=0), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignGroupName": _SERIALIZER.url("network_service_design_group_name", network_service_design_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignVersionName": _SERIALIZER.url("network_service_design_version_name", network_service_design_version_name, 'str', max_length=64, min_length=0), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignGroupName": _SERIALIZER.url("network_service_design_group_name", network_service_design_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignVersionName": _SERIALIZER.url("network_service_design_version_name", network_service_design_version_name, 'str', max_length=64, min_length=0), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_request( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignGroupName": _SERIALIZER.url("network_service_design_group_name", network_service_design_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignVersionName": _SERIALIZER.url("network_service_design_version_name", network_service_design_version_name, 'str', max_length=64, min_length=0), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_network_service_design_group_request( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignGroupName": _SERIALIZER.url("network_service_design_group_name", network_service_design_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_state_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}/updateState") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignGroupName": _SERIALIZER.url("network_service_design_group_name", network_service_design_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkServiceDesignVersionName": _SERIALIZER.url("network_service_design_version_name", network_service_design_version_name, 'str', max_length=64, min_length=0), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="POST", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class NetworkServiceDesignVersionsOperations(object): + """NetworkServiceDesignVersionsOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes the specified network service design version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version_name: The name of the network service design version. The + name should conform to the SemVer 2.0.0 specification: https://semver.org/spec/v2.0.0.html. + :type network_service_design_version_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + def _create_or_update_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + parameters, # type: "_models.NetworkServiceDesignVersion" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkServiceDesignVersion" + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkServiceDesignVersion') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('NetworkServiceDesignVersion', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('NetworkServiceDesignVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + parameters, # type: "_models.NetworkServiceDesignVersion" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.NetworkServiceDesignVersion"] + """Creates or updates a network service design version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version_name: The name of the network service design version. The + name should conform to the SemVer 2.0.0 specification: https://semver.org/spec/v2.0.0.html. + :type network_service_design_version_name: str + :param parameters: Parameters supplied to the create or update network service design version + operation. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either NetworkServiceDesignVersion or the result + of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersion"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkServiceDesignVersion', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkServiceDesignVersion" + """Gets information about a network service design version. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version_name: The name of the network service design version. The + name should conform to the SemVer 2.0.0 specification: https://semver.org/spec/v2.0.0.html. + :type network_service_design_version_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkServiceDesignVersion, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkServiceDesignVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + + @distributed_trace + def update( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkServiceDesignVersion" + """Updates a network service design version resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version_name: The name of the network service design version. The + name should conform to the SemVer 2.0.0 specification: https://semver.org/spec/v2.0.0.html. + :type network_service_design_version_name: str + :param parameters: Parameters supplied to the create or update network service design version + operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkServiceDesignVersion, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkServiceDesignVersion + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersion"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkServiceDesignVersion', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}"} # type: ignore + + + @distributed_trace + def list_by_network_service_design_group( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.NetworkServiceDesignVersionListResult"] + """Gets information about a list of network service design versions under a network service design + group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkServiceDesignVersionListResult or the + result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.NetworkServiceDesignVersionListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersionListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_network_service_design_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + template_url=self.list_by_network_service_design_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_network_service_design_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkServiceDesignVersionListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_network_service_design_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions"} # type: ignore + + def _update_state_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + parameters, # type: "_models.NetworkServiceDesignVersionUpdateState" + **kwargs # type: Any + ): + # type: (...) -> Optional["_models.NetworkServiceDesignVersionUpdateState"] + cls = kwargs.pop('cls', None) # type: ClsType[Optional["_models.NetworkServiceDesignVersionUpdateState"]] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'NetworkServiceDesignVersionUpdateState') + + request = build_update_state_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._update_state_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + deserialized = None + if response.status_code == 200: + deserialized = self._deserialize('NetworkServiceDesignVersionUpdateState', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _update_state_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}/updateState"} # type: ignore + + + @distributed_trace + def begin_update_state( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_service_design_group_name, # type: str + network_service_design_version_name, # type: str + parameters, # type: "_models.NetworkServiceDesignVersionUpdateState" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.NetworkServiceDesignVersionUpdateState"] + """Update network service design version state. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version_name: The name of the network service design version. The + name should conform to the SemVer 2.0.0 specification: https://semver.org/spec/v2.0.0.html. + :type network_service_design_version_name: str + :param parameters: Parameters supplied to update the state of network service design version. + :type parameters: ~Microsoft.HybridNetwork.models.NetworkServiceDesignVersionUpdateState + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either NetworkServiceDesignVersionUpdateState or + the result of cls(response) + :rtype: + ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.NetworkServiceDesignVersionUpdateState] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkServiceDesignVersionUpdateState"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._update_state_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('NetworkServiceDesignVersionUpdateState', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_update_state.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkServiceDesignGroups/{networkServiceDesignGroupName}/networkServiceDesignVersions/{networkServiceDesignVersionName}/updateState"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_operations.py new file mode 100644 index 00000000000..819603c5cff --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_operations.py @@ -0,0 +1,152 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat + +from .. import models as _models +from .._vendor import _convert_request + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_request( + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/providers/Microsoft.HybridNetwork/operations") + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class Operations(object): + """Operations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list( + self, + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.OperationList"] + """Gets a list of the operations. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either OperationList or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.OperationList] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.OperationList"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_request( + api_version=api_version, + template_url=self.list.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_request( + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("OperationList", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list.metadata = {'url': "/providers/Microsoft.HybridNetwork/operations"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_preview_subscriptions_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_preview_subscriptions_operations.py new file mode 100644 index 00000000000..3dcd75f1e26 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_preview_subscriptions_operations.py @@ -0,0 +1,763 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_by_network_function_definition_group_request( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_delete_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + preview_subscription, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "previewSubscription": _SERIALIZER.url("preview_subscription", preview_subscription, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + preview_subscription, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "previewSubscription": _SERIALIZER.url("preview_subscription", preview_subscription, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + preview_subscription, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "previewSubscription": _SERIALIZER.url("preview_subscription", preview_subscription, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_request( + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + preview_subscription, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "previewSubscription": _SERIALIZER.url("preview_subscription", preview_subscription, 'str'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class PreviewSubscriptionsOperations(object): + """PreviewSubscriptionsOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_network_function_definition_group( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.PreviewSubscriptionsList"] + """Lists all the preview subscriptions of a network function definition group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PreviewSubscriptionsList or the result of + cls(response) + :rtype: ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.PreviewSubscriptionsList] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.PreviewSubscriptionsList"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_network_function_definition_group_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_network_function_definition_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_network_function_definition_group_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PreviewSubscriptionsList", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_network_function_definition_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions"} # type: ignore + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + preview_subscription, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + preview_subscription, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes a preview subscription resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param preview_subscription: Preview subscription ID. + :type preview_subscription: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + + def _create_or_update_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + preview_subscription, # type: str + parameters, # type: "_models.PreviewSubscription" + **kwargs # type: Any + ): + # type: (...) -> "_models.PreviewSubscription" + cls = kwargs.pop('cls', None) # type: ClsType["_models.PreviewSubscription"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'PreviewSubscription') + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('PreviewSubscription', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('PreviewSubscription', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + preview_subscription, # type: str + parameters, # type: "_models.PreviewSubscription" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.PreviewSubscription"] + """Creates or updates preview subscription resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param preview_subscription: Preview subscription ID. + :type preview_subscription: str + :param parameters: Parameters supplied to the create or update publisher preview subscription + operation. + :type parameters: ~Microsoft.HybridNetwork.models.PreviewSubscription + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either PreviewSubscription or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.PreviewSubscription] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.PreviewSubscription"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('PreviewSubscription', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + preview_subscription, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.PreviewSubscription" + """Gets the preview subscription resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param preview_subscription: Preview subscription ID. + :type preview_subscription: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PreviewSubscription, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.PreviewSubscription + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.PreviewSubscription"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('PreviewSubscription', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + + + @distributed_trace + def update( + self, + resource_group_name, # type: str + publisher_name, # type: str + network_function_definition_group_name, # type: str + preview_subscription, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.PreviewSubscription" + """Update a preview subscription resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param preview_subscription: Preview subscription ID. + :type preview_subscription: str + :param parameters: Parameters supplied to the create or update publisher preview subscription + operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: PreviewSubscription, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.PreviewSubscription + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.PreviewSubscription"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + preview_subscription=preview_subscription, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('PreviewSubscription', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/previewSubscriptions/{previewSubscription}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_artifact_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_artifact_operations.py new file mode 100644 index 00000000000..8c5a15b5a3d --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_artifact_operations.py @@ -0,0 +1,319 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_request( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifacts") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + artifact_name = kwargs.pop('artifact_name') # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactVersions") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "artifactStoreName": _SERIALIZER.url("artifact_store_name", artifact_store_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['artifactName'] = _SERIALIZER.query("artifact_name", artifact_name, 'str', max_length=64, min_length=0) + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class ProxyArtifactOperations(object): + """ProxyArtifactOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.ProxyArtifactOverviewListResult"] + """Lists all the available artifacts in the parent Artifact Store. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ProxyArtifactOverviewListResult or the result of + cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.ProxyArtifactOverviewListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ProxyArtifactOverviewListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ProxyArtifactOverviewListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifacts"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + publisher_name, # type: str + artifact_store_name, # type: str + artifact_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.ProxyArtifactVersionsOverviewListResult"] + """Get a Artifact overview information. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_name: The name of the artifact. + :type artifact_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ProxyArtifactVersionsOverviewListResult or the + result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.ProxyArtifactVersionsOverviewListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ProxyArtifactVersionsOverviewListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + artifact_name=artifact_name, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + artifact_name=artifact_name, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ProxyArtifactVersionsOverviewListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}/artifactStores/{artifactStoreName}/artifactVersions"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_network_function_definition_groups_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_network_function_definition_groups_operations.py new file mode 100644 index 00000000000..5fa10463480 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_network_function_definition_groups_operations.py @@ -0,0 +1,293 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_by_publisher_request( + proxy_publisher_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + publisher_scope_name = kwargs.pop('publisher_scope_name') # type: str + publisher_location_name = kwargs.pop('publisher_location_name') # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups") # pylint: disable=line-too-long + path_format_arguments = { + "proxyPublisherName": _SERIALIZER.url("proxy_publisher_name", proxy_publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['publisherScopeName'] = _SERIALIZER.query("publisher_scope_name", publisher_scope_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['publisherLocationName'] = _SERIALIZER.query("publisher_location_name", publisher_location_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + proxy_publisher_name, # type: str + network_function_definition_group_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + publisher_scope_name = kwargs.pop('publisher_scope_name') # type: str + publisher_location_name = kwargs.pop('publisher_location_name') # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}") # pylint: disable=line-too-long + path_format_arguments = { + "proxyPublisherName": _SERIALIZER.url("proxy_publisher_name", proxy_publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['publisherScopeName'] = _SERIALIZER.query("publisher_scope_name", publisher_scope_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['publisherLocationName'] = _SERIALIZER.query("publisher_location_name", publisher_location_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class ProxyNetworkFunctionDefinitionGroupsOperations(object): + """ProxyNetworkFunctionDefinitionGroupsOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_publisher( + self, + publisher_scope_name, # type: str + publisher_location_name, # type: str + proxy_publisher_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.NetworkFunctionDefinitionGroupOverviewListResult"] + """Lists all available network function definition group under a publisher. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :param proxy_publisher_name: The name of the proxy publisher. + :type proxy_publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionDefinitionGroupOverviewListResult + or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroupOverviewListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroupOverviewListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_publisher_request( + proxy_publisher_name=proxy_publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.list_by_publisher.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_publisher_request( + proxy_publisher_name=proxy_publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionDefinitionGroupOverviewListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_publisher.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups"} # type: ignore + + @distributed_trace + def get( + self, + publisher_scope_name, # type: str + publisher_location_name, # type: str + proxy_publisher_name, # type: str + network_function_definition_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionDefinitionGroupOverview" + """Get information about network function definition overview. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :param proxy_publisher_name: The name of the proxy publisher. + :type proxy_publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionGroupOverview, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionGroupOverview + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionGroupOverview"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + proxy_publisher_name=proxy_publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionGroupOverview', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_network_function_definition_versions_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_network_function_definition_versions_operations.py new file mode 100644 index 00000000000..7f0e01c882e --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_network_function_definition_versions_operations.py @@ -0,0 +1,309 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_by_network_function_definition_group_request( + proxy_publisher_name, # type: str + network_function_definition_group_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + publisher_scope_name = kwargs.pop('publisher_scope_name') # type: str + publisher_location_name = kwargs.pop('publisher_location_name') # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions") # pylint: disable=line-too-long + path_format_arguments = { + "proxyPublisherName": _SERIALIZER.url("proxy_publisher_name", proxy_publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['publisherScopeName'] = _SERIALIZER.query("publisher_scope_name", publisher_scope_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['publisherLocationName'] = _SERIALIZER.query("publisher_location_name", publisher_location_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + proxy_publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + publisher_scope_name = kwargs.pop('publisher_scope_name') # type: str + publisher_location_name = kwargs.pop('publisher_location_name') # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}") # pylint: disable=line-too-long + path_format_arguments = { + "proxyPublisherName": _SERIALIZER.url("proxy_publisher_name", proxy_publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionGroupName": _SERIALIZER.url("network_function_definition_group_name", network_function_definition_group_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "networkFunctionDefinitionVersionName": _SERIALIZER.url("network_function_definition_version_name", network_function_definition_version_name, 'str', max_length=64, min_length=0), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['publisherScopeName'] = _SERIALIZER.query("publisher_scope_name", publisher_scope_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['publisherLocationName'] = _SERIALIZER.query("publisher_location_name", publisher_location_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class ProxyNetworkFunctionDefinitionVersionsOperations(object): + """ProxyNetworkFunctionDefinitionVersionsOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_network_function_definition_group( + self, + publisher_scope_name, # type: str + publisher_location_name, # type: str + proxy_publisher_name, # type: str + network_function_definition_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.NetworkFunctionDefinitionVersionOverviewListResult"] + """Lists available network function versions under a network function definition group. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :param proxy_publisher_name: The name of the proxy publisher. + :type proxy_publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either NetworkFunctionDefinitionVersionOverviewListResult + or the result of cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionOverviewListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersionOverviewListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_network_function_definition_group_request( + proxy_publisher_name=proxy_publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.list_by_network_function_definition_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_network_function_definition_group_request( + proxy_publisher_name=proxy_publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("NetworkFunctionDefinitionVersionOverviewListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_network_function_definition_group.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions"} # type: ignore + + @distributed_trace + def get( + self, + publisher_scope_name, # type: str + publisher_location_name, # type: str + proxy_publisher_name, # type: str + network_function_definition_group_name, # type: str + network_function_definition_version_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.NetworkFunctionDefinitionVersionOverview" + """Get information about network function definition version overview. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :param proxy_publisher_name: The name of the proxy publisher. + :type proxy_publisher_name: str + :param network_function_definition_group_name: The name of the network function definition + group. + :type network_function_definition_group_name: str + :param network_function_definition_version_name: The name of the network function definition + version. The name should conform to the SemVer 2.0.0 specification: + https://semver.org/spec/v2.0.0.html. + :type network_function_definition_version_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: NetworkFunctionDefinitionVersionOverview, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.NetworkFunctionDefinitionVersionOverview + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.NetworkFunctionDefinitionVersionOverview"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + proxy_publisher_name=proxy_publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('NetworkFunctionDefinitionVersionOverview', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}/networkFunctionDefinitionGroups/{networkFunctionDefinitionGroupName}/networkFunctionDefinitionVersions/{networkFunctionDefinitionVersionName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_publisher_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_publisher_operations.py new file mode 100644 index 00000000000..e98e6431136 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_proxy_publisher_operations.py @@ -0,0 +1,279 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_by_location_request( + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + publisher_scope_name = kwargs.pop('publisher_scope_name') # type: str + publisher_location_name = kwargs.pop('publisher_location_name') # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers") + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['publisherScopeName'] = _SERIALIZER.query("publisher_scope_name", publisher_scope_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['publisherLocationName'] = _SERIALIZER.query("publisher_location_name", publisher_location_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + proxy_publisher_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + publisher_scope_name = kwargs.pop('publisher_scope_name') # type: str + publisher_location_name = kwargs.pop('publisher_location_name') # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}") # pylint: disable=line-too-long + path_format_arguments = { + "proxyPublisherName": _SERIALIZER.url("proxy_publisher_name", proxy_publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['publisherScopeName'] = _SERIALIZER.query("publisher_scope_name", publisher_scope_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['publisherLocationName'] = _SERIALIZER.query("publisher_location_name", publisher_location_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$') + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class ProxyPublisherOperations(object): + """ProxyPublisherOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_location( + self, + publisher_scope_name, # type: str + publisher_location_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.ProxyPublisherOverviewListResult"] + """Lists all the available network function definition and network service design publishers. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ProxyPublisherOverviewListResult or the result of + cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.ProxyPublisherOverviewListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.ProxyPublisherOverviewListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_location_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.list_by_location.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_location_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("ProxyPublisherOverviewListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_location.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers"} # type: ignore + + @distributed_trace + def get( + self, + publisher_scope_name, # type: str + publisher_location_name, # type: str + proxy_publisher_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.ProxyPublisherOverview" + """Get a publisher overview information. + + :param publisher_scope_name: The name of the publisher scope. + :type publisher_scope_name: str + :param publisher_location_name: The name of the publisher location. + :type publisher_location_name: str + :param proxy_publisher_name: The name of the proxy publisher. + :type proxy_publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: ProxyPublisherOverview, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.ProxyPublisherOverview + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.ProxyPublisherOverview"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + proxy_publisher_name=proxy_publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + publisher_scope_name=publisher_scope_name, + publisher_location_name=publisher_location_name, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('ProxyPublisherOverview', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/proxyPublishers/{proxyPublisherName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_publishers_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_publishers_operations.py new file mode 100644 index 00000000000..8475d51061e --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_publishers_operations.py @@ -0,0 +1,796 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_list_by_subscription_request( + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/publishers") + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_resource_group_request( + resource_group_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_delete_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + resource_group_name, # type: str + publisher_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + resource_group_name, # type: str + publisher_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_request( + resource_group_name, # type: str + publisher_name, # type: str + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}") # pylint: disable=line-too-long + path_format_arguments = { + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "publisherName": _SERIALIZER.url("publisher_name", publisher_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class PublishersOperations(object): + """PublishersOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + @distributed_trace + def list_by_subscription( + self, + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.PublisherListResult"] + """Lists all the publishers in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PublisherListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.PublisherListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.PublisherListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PublisherListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/publishers"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.PublisherListResult"] + """Lists all the publishers in a resource group. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either PublisherListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.PublisherListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.PublisherListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + resource_group_name=resource_group_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("PublisherListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers"} # type: ignore + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + publisher_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes the specified publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + publisher_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.Publisher" + """Gets information about the specified publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Publisher, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.Publisher + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.Publisher"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Publisher', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + + + def _create_or_update_initial( + self, + resource_group_name, # type: str + publisher_name, # type: str + parameters=None, # type: Optional["_models.Publisher"] + **kwargs # type: Any + ): + # type: (...) -> "_models.Publisher" + cls = kwargs.pop('cls', None) # type: ClsType["_models.Publisher"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + if parameters is not None: + _json = self._serialize.body(parameters, 'Publisher') + else: + _json = None + + request = build_create_or_update_request_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('Publisher', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('Publisher', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + publisher_name, # type: str + parameters=None, # type: Optional["_models.Publisher"] + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.Publisher"] + """Creates or updates a publisher. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param parameters: Parameters supplied to the create publisher operation. + :type parameters: ~Microsoft.HybridNetwork.models.Publisher + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either Publisher or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.Publisher] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.Publisher"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('Publisher', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + + @distributed_trace + def update( + self, + resource_group_name, # type: str + publisher_name, # type: str + parameters=None, # type: Optional["_models.TagsObject"] + **kwargs # type: Any + ): + # type: (...) -> "_models.Publisher" + """Update a publisher resource. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param parameters: Parameters supplied to the create publisher operation. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Publisher, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.Publisher + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.Publisher"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + if parameters is not None: + _json = self._serialize.body(parameters, 'TagsObject') + else: + _json = None + + request = build_update_request( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + subscription_id=self._config.subscription_id, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Publisher', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/publishers/{publisherName}"} # type: ignore + diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_site_network_services_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_site_network_services_operations.py new file mode 100644 index 00000000000..41e06145a43 --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_site_network_services_operations.py @@ -0,0 +1,795 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_delete_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + site_network_service_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "siteNetworkServiceName": _SERIALIZER.url("site_network_service_name", site_network_service_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + subscription_id, # type: str + resource_group_name, # type: str + site_network_service_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "siteNetworkServiceName": _SERIALIZER.url("site_network_service_name", site_network_service_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + site_network_service_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "siteNetworkServiceName": _SERIALIZER.url("site_network_service_name", site_network_service_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_tags_request( + subscription_id, # type: str + resource_group_name, # type: str + site_network_service_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "siteNetworkServiceName": _SERIALIZER.url("site_network_service_name", site_network_service_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_subscription_request( + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/siteNetworkServices") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_resource_group_request( + subscription_id, # type: str + resource_group_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class SiteNetworkServicesOperations(object): + """SiteNetworkServicesOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + site_network_service_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + site_network_service_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes the specified site network service. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_network_service_name: The name of the site network service. + :type site_network_service_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + site_network_service_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.SiteNetworkService" + """Gets information about the specified site network service. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_network_service_name: The name of the site network service. + :type site_network_service_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SiteNetworkService, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.SiteNetworkService + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkService"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SiteNetworkService', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + + def _create_or_update_initial( + self, + resource_group_name, # type: str + site_network_service_name, # type: str + parameters, # type: "_models.SiteNetworkService" + **kwargs # type: Any + ): + # type: (...) -> "_models.SiteNetworkService" + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkService"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'SiteNetworkService') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('SiteNetworkService', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('SiteNetworkService', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + site_network_service_name, # type: str + parameters, # type: "_models.SiteNetworkService" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.SiteNetworkService"] + """Creates or updates a network site. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_network_service_name: The name of the site network service. + :type site_network_service_name: str + :param parameters: Parameters supplied to the create or update site network service operation. + :type parameters: ~Microsoft.HybridNetwork.models.SiteNetworkService + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either SiteNetworkService or the result of + cls(response) + :rtype: ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.SiteNetworkService] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkService"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('SiteNetworkService', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + @distributed_trace + def update_tags( + self, + resource_group_name, # type: str + site_network_service_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.SiteNetworkService" + """Updates a site update tags. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_network_service_name: The name of the site network service. + :type site_network_service_name: str + :param parameters: Parameters supplied to update network site tags. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SiteNetworkService, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.SiteNetworkService + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkService"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_tags_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_network_service_name=site_network_service_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update_tags.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('SiteNetworkService', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update_tags.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices/{siteNetworkServiceName}"} # type: ignore + + + @distributed_trace + def list_by_subscription( + self, + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.SiteNetworkServiceListResult"] + """Lists all sites in the network service in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either SiteNetworkServiceListResult or the result of + cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.SiteNetworkServiceListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkServiceListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("SiteNetworkServiceListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/siteNetworkServices"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.SiteNetworkServiceListResult"] + """Lists all site network services. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either SiteNetworkServiceListResult or the result of + cls(response) + :rtype: + ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.SiteNetworkServiceListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteNetworkServiceListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("SiteNetworkServiceListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/siteNetworkServices"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/_sites_operations.py b/src/aosm/azext_aosm/vendored_sdks/operations/_sites_operations.py new file mode 100644 index 00000000000..ce2948d2a2c --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/operations/_sites_operations.py @@ -0,0 +1,790 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# 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 Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error +from azure.core.paging import ItemPaged +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.polling import LROPoller, NoPolling, PollingMethod +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace +from azure.mgmt.core.exceptions import ARMErrorFormat +from azure.mgmt.core.polling.arm_polling import ARMPolling + +from .. import models as _models +from .._vendor import _convert_request, _format_url_section + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Iterable, Optional, TypeVar, Union + T = TypeVar('T') + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_delete_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + site_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "siteName": _SERIALIZER.url("site_name", site_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="DELETE", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_get_request( + subscription_id, # type: str + resource_group_name, # type: str + site_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "siteName": _SERIALIZER.url("site_name", site_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_create_or_update_request_initial( + subscription_id, # type: str + resource_group_name, # type: str + site_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "siteName": _SERIALIZER.url("site_name", site_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PUT", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_update_tags_request( + subscription_id, # type: str + resource_group_name, # type: str + site_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', None) # type: Optional[str] + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + "siteName": _SERIALIZER.url("site_name", site_name, 'str', max_length=64, min_length=0, pattern=r'^[a-zA-Z0-9][a-zA-Z0-9_-]*$'), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + if content_type is not None: + _header_parameters['Content-Type'] = _SERIALIZER.header("content_type", content_type, 'str') + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="PATCH", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_subscription_request( + subscription_id, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/sites") + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + + +def build_list_by_resource_group_request( + subscription_id, # type: str + resource_group_name, # type: str + **kwargs # type: Any +): + # type: (...) -> HttpRequest + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites") # pylint: disable=line-too-long + path_format_arguments = { + "subscriptionId": _SERIALIZER.url("subscription_id", subscription_id, 'str', min_length=1), + "resourceGroupName": _SERIALIZER.url("resource_group_name", resource_group_name, 'str', max_length=90, min_length=1), + } + + _url = _format_url_section(_url, **path_format_arguments) + + # Construct parameters + _query_parameters = kwargs.pop("params", {}) # type: Dict[str, Any] + _query_parameters['api-version'] = _SERIALIZER.query("api_version", api_version, 'str') + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + params=_query_parameters, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class SitesOperations(object): + """SitesOperations operations. + + You should not instantiate this class directly. Instead, you should create a Client instance that + instantiates it for you and attaches it as an attribute. + + :ivar models: Alias to model classes used in this operation group. + :type models: ~Microsoft.HybridNetwork.models + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = _models + + def __init__(self, client, config, serializer, deserializer): + self._client = client + self._serialize = serializer + self._deserialize = deserializer + self._config = config + + def _delete_initial( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + site_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> None + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_delete_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_name=site_name, + api_version=api_version, + template_url=self._delete_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 202, 204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if cls: + return cls(pipeline_response, None, {}) + + _delete_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + + @distributed_trace + def begin_delete( # pylint: disable=inconsistent-return-statements + self, + resource_group_name, # type: str + site_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> LROPoller[None] + """Deletes the specified network site. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_name: The name of the network service site. + :type site_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either None or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[None] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType[None] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._delete_initial( + resource_group_name=resource_group_name, + site_name=site_name, + api_version=api_version, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + if cls: + return cls(pipeline_response, None, {}) + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'location'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_delete.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + @distributed_trace + def get( + self, + resource_group_name, # type: str + site_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> "_models.Site" + """Gets information about the specified network site. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_name: The name of the network service site. + :type site_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Site, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.Site + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.Site"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + + request = build_get_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_name=site_name, + api_version=api_version, + template_url=self.get.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Site', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + get.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + + def _create_or_update_initial( + self, + resource_group_name, # type: str + site_name, # type: str + parameters, # type: "_models.Site" + **kwargs # type: Any + ): + # type: (...) -> "_models.Site" + cls = kwargs.pop('cls', None) # type: ClsType["_models.Site"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'Site') + + request = build_create_or_update_request_initial( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_name=site_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self._create_or_update_initial.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200, 201]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + if response.status_code == 200: + deserialized = self._deserialize('Site', pipeline_response) + + if response.status_code == 201: + deserialized = self._deserialize('Site', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + _create_or_update_initial.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + + @distributed_trace + def begin_create_or_update( + self, + resource_group_name, # type: str + site_name, # type: str + parameters, # type: "_models.Site" + **kwargs # type: Any + ): + # type: (...) -> LROPoller["_models.Site"] + """Creates or updates a network site. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_name: The name of the network service site. + :type site_name: str + :param parameters: Parameters supplied to the create or update network site operation. + :type parameters: ~Microsoft.HybridNetwork.models.Site + :keyword callable cls: A custom type or function that will be passed the direct response + :keyword str continuation_token: A continuation token to restart a poller from a saved state. + :keyword polling: By default, your polling method will be ARMPolling. Pass in False for this + operation to not poll, or pass in your own initialized polling object for a personal polling + strategy. + :paramtype polling: bool or ~azure.core.polling.PollingMethod + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no + Retry-After header is present. + :return: An instance of LROPoller that returns either Site or the result of cls(response) + :rtype: ~azure.core.polling.LROPoller[~Microsoft.HybridNetwork.models.Site] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + polling = kwargs.pop('polling', True) # type: Union[bool, PollingMethod] + cls = kwargs.pop('cls', None) # type: ClsType["_models.Site"] + lro_delay = kwargs.pop( + 'polling_interval', + self._config.polling_interval + ) + cont_token = kwargs.pop('continuation_token', None) # type: Optional[str] + if cont_token is None: + raw_result = self._create_or_update_initial( + resource_group_name=resource_group_name, + site_name=site_name, + parameters=parameters, + api_version=api_version, + content_type=content_type, + cls=lambda x,y,z: x, + **kwargs + ) + kwargs.pop('error_map', None) + + def get_long_running_output(pipeline_response): + response = pipeline_response.http_response + deserialized = self._deserialize('Site', pipeline_response) + if cls: + return cls(pipeline_response, deserialized, {}) + return deserialized + + + if polling is True: polling_method = ARMPolling(lro_delay, lro_options={'final-state-via': 'azure-async-operation'}, **kwargs) + elif polling is False: polling_method = NoPolling() + else: polling_method = polling + if cont_token: + return LROPoller.from_continuation_token( + polling_method=polling_method, + continuation_token=cont_token, + client=self._client, + deserialization_callback=get_long_running_output + ) + return LROPoller(self._client, raw_result, get_long_running_output, polling_method) + + begin_create_or_update.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + @distributed_trace + def update_tags( + self, + resource_group_name, # type: str + site_name, # type: str + parameters, # type: "_models.TagsObject" + **kwargs # type: Any + ): + # type: (...) -> "_models.Site" + """Updates a site update tags. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :param site_name: The name of the network service site. + :type site_name: str + :param parameters: Parameters supplied to update network site tags. + :type parameters: ~Microsoft.HybridNetwork.models.TagsObject + :keyword callable cls: A custom type or function that will be passed the direct response + :return: Site, or the result of cls(response) + :rtype: ~Microsoft.HybridNetwork.models.Site + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["_models.Site"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + content_type = kwargs.pop('content_type', "application/json") # type: Optional[str] + + _json = self._serialize.body(parameters, 'TagsObject') + + request = build_update_tags_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + site_name=site_name, + api_version=api_version, + content_type=content_type, + json=_json, + template_url=self.update_tags.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + deserialized = self._deserialize('Site', pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + update_tags.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites/{siteName}"} # type: ignore + + + @distributed_trace + def list_by_subscription( + self, + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.SiteListResult"] + """Lists all sites in the network service in a subscription. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either SiteListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.SiteListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=self.list_by_subscription.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_subscription_request( + subscription_id=self._config.subscription_id, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("SiteListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_subscription.metadata = {'url': "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/sites"} # type: ignore + + @distributed_trace + def list_by_resource_group( + self, + resource_group_name, # type: str + **kwargs # type: Any + ): + # type: (...) -> Iterable["_models.SiteListResult"] + """Lists all sites in the network service. + + :param resource_group_name: The name of the resource group. The name is case insensitive. + :type resource_group_name: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either SiteListResult or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~Microsoft.HybridNetwork.models.SiteListResult] + :raises: ~azure.core.exceptions.HttpResponseError + """ + api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + + cls = kwargs.pop('cls', None) # type: ClsType["_models.SiteListResult"] + error_map = { + 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError + } + error_map.update(kwargs.pop('error_map', {})) + def prepare_request(next_link=None): + if not next_link: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=self.list_by_resource_group.metadata['url'], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + else: + + request = build_list_by_resource_group_request( + subscription_id=self._config.subscription_id, + resource_group_name=resource_group_name, + api_version=api_version, + template_url=next_link, + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + request.method = "GET" + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize("SiteListResult", pipeline_response) + list_of_elem = deserialized.value + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, + stream=False, + **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat) + + return pipeline_response + + + return ItemPaged( + get_next, extract_data + ) + list_by_resource_group.metadata = {'url': "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HybridNetwork/sites"} # type: ignore diff --git a/src/aosm/azext_aosm/vendored_sdks/py.typed b/src/aosm/azext_aosm/vendored_sdks/py.typed new file mode 100644 index 00000000000..e5aff4f83af --- /dev/null +++ b/src/aosm/azext_aosm/vendored_sdks/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. \ No newline at end of file diff --git a/src/aosm/setup.py b/src/aosm/setup.py index cec93421831..83ecad46f31 100644 --- a/src/aosm/setup.py +++ b/src/aosm/setup.py @@ -55,4 +55,4 @@ packages=find_packages(), install_requires=DEPENDENCIES, package_data={'azext_aosm': ['azext_metadata.json']}, -) \ No newline at end of file +) From af1accc02117d2296545c4c5ef83beb7d61fe657 Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Mon, 24 Apr 2023 19:12:34 +0100 Subject: [PATCH 003/145] Add missing file --- src/aosm/azext_aosm/_configuration.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/aosm/azext_aosm/_configuration.py diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py new file mode 100644 index 00000000000..b41a6f2c82a --- /dev/null +++ b/src/aosm/azext_aosm/_configuration.py @@ -0,0 +1,24 @@ +from dataclasses import dataclass +from typing import Optional + +@dataclass +class ArtifactConfig: + artifact_name: str = "Name of the artifact" + file_path: Optional[str] = "File path of the artifact you wish to upload from your local disk" + blob_sas_url: Optional[str] = "SAS URL of the blob artifact you wish to copy to your Artifact Store" + + +@dataclass +class Configuration(): + publisher_name: str = "Name of the Publisher resource you want you definition published to" + publisher_resource_group_name: str = "Resource group the Publisher resource is in or you want it to be in" + name: str = "Name of NF definition" + version: str = "Version of the NF definition" + acr_artifact_store_name: str = "Name of the ACR Artifact Store resource" + + +@dataclass +class VNFConfiguration(Configuration): + blob_artifact_store_name: str = "Name of the storage account Artifact Store resource" + arm_template: ArtifactConfig = ArtifactConfig() + vhd: ArtifactConfig = ArtifactConfig() From d4ee4e6971a9694f4381715937d913debb8aa835 Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Wed, 26 Apr 2023 11:47:30 +0100 Subject: [PATCH 004/145] Commit changes --- src/aosm/azext_aosm/_client_factory.py | 6 ++ src/aosm/azext_aosm/_configuration.py | 17 ++++ src/aosm/azext_aosm/custom.py | 110 +++++++++++++++++++------ 3 files changed, 106 insertions(+), 27 deletions(-) diff --git a/src/aosm/azext_aosm/_client_factory.py b/src/aosm/azext_aosm/_client_factory.py index ab281c30153..084e448b769 100644 --- a/src/aosm/azext_aosm/_client_factory.py +++ b/src/aosm/azext_aosm/_client_factory.py @@ -4,7 +4,13 @@ # -------------------------------------------------------------------------------------------- from azure.cli.core.commands.client_factory import get_mgmt_service_client +from azure.cli.core.profiles import ResourceType from .vendored_sdks import HybridNetworkManagementClient def cf_aosm(cli_ctx, *_) -> HybridNetworkManagementClient: return get_mgmt_service_client(cli_ctx, HybridNetworkManagementClient) + +def cf_resources(cli_ctx, subscription_id=None): + return get_mgmt_service_client( + cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id + ).resources diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index b41a6f2c82a..eefd5a5e600 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,5 +1,6 @@ from dataclasses import dataclass from typing import Optional +from knack.util import CLIError @dataclass class ArtifactConfig: @@ -22,3 +23,19 @@ class VNFConfiguration(Configuration): blob_artifact_store_name: str = "Name of the storage account Artifact Store resource" arm_template: ArtifactConfig = ArtifactConfig() vhd: ArtifactConfig = ArtifactConfig() + + +def get_configuration(definition_type, config_as_dict=None): + if config_as_dict is None: + config_as_dict = {} + + if definition_type == "vnf": + config = VNFConfiguration(**config_as_dict) + elif definition_type == "cnf": + config = Configuration(**config_as_dict) + elif definition_type == "nsd": + config = Configuration(**config_as_dict) + else: + raise CLIError("Definition type not recognized, options are: vnf, cnf or nsd") + + return config diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 2b29643a015..345bcc43fe3 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -4,47 +4,103 @@ # -------------------------------------------------------------------------------------------- import json - from dataclasses import asdict +from typing import Optional, Tuple from knack.log import get_logger -from knack.util import CLIError +from azure.cli.core.azclierror import AzCLIError +from azure.mgmt.resource import ResourceManagementClient from .vendored_sdks import HybridNetworkManagementClient -from .vendored_sdks.models import Publisher -from ._configuration import Configuration, VNFConfiguration +from .vendored_sdks.models import Publisher, NetworkFunctionDefinitionVersion +from ._client_factory import cf_resources +from ._configuration import Configuration, VNFConfiguration, get_configuration + logger = get_logger(__name__) -def build_definition(cmd, definition_type, config_file, publish=False): - with open(config_file, "r") as f: - config_dict = json.loads(f) +PUBLISHER_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers" +ARTIFACT_STORE_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/artifactstores" +NFDG_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/networkfunctiondefinitiongroups" +NSDG_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/networkservicedesigngroups" + +def _required_resources_exist( + cli_ctx, definition_type: str, config: Configuration +) -> bool: + resource_client = cf_resources(cli_ctx) - if definition_type == "vnf": - config = VNFConfiguration(**config_dict) - elif definition_type == "cnf": - config = Configuration(**config_dict) - elif definition_type == "nsd": - config = Configuration(**config_dict) + if resource_client.check_existence( + config.publisher_resource_group_name, + PUBLISHER_RESOURCE_TYPE, + config.publisher_name, + ): + if not resource_client.check_existence( + config.publisher_resource_group_name, + "Microsoft.HybridNetwork/publishers/artifactstores", + config.acr_artifact_store_name, + ): + return False + if definition_type == "vnf": + if not resource_client.check_existence( + config.publisher_resource_group_name, + NFDG_RESOURCE_TYPE, + config.name, + ): + return False + elif definition_type == "nsd": + if not resource_client.check_existence( + config.publisher_resource_group_name, + NSDG_RESOURCE_TYPE, + config.name, + ): + return False + elif definition_type == "cnf": + if not resource_client.check_existence( + config.publisher_resource_group_name, + NFDG_RESOURCE_TYPE, + config.name, + ): + return False + else: + raise AzCLIError( + "Invalid definition type. Valid values are vnf, nsd and cnf." + ) else: - raise CLIError("Definition type not recognized, options are: vnf, cnf or nsd") + return False + +def _create_required_resources(definition_type, config): + pass + +def build_definition( + cmd, + client: HybridNetworkManagementClient, + definition_type, + config_file, + publish=False, +): + with open(config_file, "r", encoding="utf-8") as f: + config_as_dict = json.loads(f) + + config = get_configuration(definition_type, config_as_dict) + # Generate the NFD/NSD and the artifact manifest. + + + # Write the ARM/bicep template if that's what we are doing + + # Publish the definition if publish is true if publish: + if not _required_resources_exist(cmd.cli_ctx, definition_type, config): + _create_required_resources(definition_type, config) def generate_definition_config(cmd, definition_type, output_file="input.json"): - if definition_type == "vnf": - config = VNFConfiguration() - elif definition_type == "cnf": - config = Configuration() - elif definition_type == "nsd": - config = Configuration() - else: - raise CLIError("Definition type not recognized, options are: vnf, cnf or nsd") + config = get_configuration(definition_type) + config_as_dict = json.dumps(asdict(config), indent=4) with open(output_file, "w", encoding="utf-8") as f: - config_as_dict = json.dumps(asdict(config), indent=4) f.write(config_as_dict) - logger.info("Empty definition configuration has been written to %s", output_file) + logger.info( + "Empty definition configuration has been written to %s", + output_file, + ) + -def show_publisher(cmd, client: HybridNetworkManagementClient, resource_group_name, publisher_name): - publisher: Publisher = client.publishers.get(resource_group_name, publisher_name) - print(f"Publisher id = {publisher.id}") From cff0186be3669afa1040bf291dd7bc225f5966ed Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 26 Apr 2023 15:36:53 +0100 Subject: [PATCH 005/145] VNF NFD generator --- src/aosm/azext_aosm/_configuration.py | 7 +-- src/aosm/azext_aosm/_constants.py | 14 ++++++ src/aosm/azext_aosm/_params.py | 3 +- src/aosm/azext_aosm/custom.py | 26 ++++++++-- .../generate_nfd/cnf_nfd_generator.py | 21 +++++++++ .../generate_nfd/nfd_generator_base.py | 30 ++++++++++++ .../generate_nfd/vnf_nfd_generator.py | 47 +++++++++++++++++++ 7 files changed, 139 insertions(+), 9 deletions(-) create mode 100644 src/aosm/azext_aosm/_constants.py create mode 100644 src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py create mode 100644 src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py create mode 100644 src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index eefd5a5e600..797e484c9c0 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,6 +1,7 @@ from dataclasses import dataclass from typing import Optional from knack.util import CLIError +from ._constants import VNF, CNF, NSD @dataclass class ArtifactConfig: @@ -29,11 +30,11 @@ def get_configuration(definition_type, config_as_dict=None): if config_as_dict is None: config_as_dict = {} - if definition_type == "vnf": + if definition_type == VNF: config = VNFConfiguration(**config_as_dict) - elif definition_type == "cnf": + elif definition_type == CNF: config = Configuration(**config_as_dict) - elif definition_type == "nsd": + elif definition_type == NSD: config = Configuration(**config_as_dict) else: raise CLIError("Definition type not recognized, options are: vnf, cnf or nsd") diff --git a/src/aosm/azext_aosm/_constants.py b/src/aosm/azext_aosm/_constants.py new file mode 100644 index 00000000000..42db56a3e3e --- /dev/null +++ b/src/aosm/azext_aosm/_constants.py @@ -0,0 +1,14 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +"""Constants used across aosm cli extension.""" + +# The types of definition that can be generated +VNF = "vnf" +CNF = "cnf" +NSD = "nsd" + +# Artifact Types +VHD_ARTIFACT = "VhdImageFile" +ARM_TEMPLATE_ARTIFACT = "ArmTemplate" diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index e25ea08b478..4bf374f9e95 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -7,13 +7,14 @@ from argcomplete.completers import FilesCompleter from azure.cli.core import AzCommandsLoader from knack.arguments import CLIArgumentType +from ._constants import VNF, CNF, NSD def load_arguments(self: AzCommandsLoader, _): from azure.cli.core.commands.parameters import file_type, get_enum_type, get_three_state_flag - definition_type = get_enum_type(["vnf", "cnf", "nsd"]) + definition_type = get_enum_type([VNF, CNF, NSD]) # Set the argument context so these options are only available when this specific command # is called. diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 345bcc43fe3..82a53ce2f4a 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -6,6 +6,9 @@ import json from dataclasses import asdict from typing import Optional, Tuple +from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator +from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator from knack.log import get_logger from azure.cli.core.azclierror import AzCLIError from azure.mgmt.resource import ResourceManagementClient @@ -13,6 +16,7 @@ from .vendored_sdks.models import Publisher, NetworkFunctionDefinitionVersion from ._client_factory import cf_resources from ._configuration import Configuration, VNFConfiguration, get_configuration +from ._constants import VNF, CNF, NSD logger = get_logger(__name__) @@ -38,21 +42,21 @@ def _required_resources_exist( config.acr_artifact_store_name, ): return False - if definition_type == "vnf": + if definition_type == VNF: if not resource_client.check_existence( config.publisher_resource_group_name, NFDG_RESOURCE_TYPE, config.name, ): return False - elif definition_type == "nsd": + elif definition_type == NSD: if not resource_client.check_existence( config.publisher_resource_group_name, NSDG_RESOURCE_TYPE, config.name, ): return False - elif definition_type == "cnf": + elif definition_type == CNF: if not resource_client.check_existence( config.publisher_resource_group_name, NFDG_RESOURCE_TYPE, @@ -102,5 +106,17 @@ def generate_definition_config(cmd, definition_type, output_file="input.json"): "Empty definition configuration has been written to %s", output_file, ) - - + +def _generate_nfd(definition_type, config): + """_summary_ + + :param definition_type: _description_ + :type definition_type: _type_ + """ + nfd_generator: NFDGenerator + if definition_type == VNF: + nfd_generator = VnfNfdGenerator(config) + elif definition_type == CNF: + nfd_generator = CnfNfdGenerator(config) + + nfd_generator.generate_nfd() diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py new file mode 100644 index 00000000000..77627b30885 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -0,0 +1,21 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains a class for generating VNF NFDs and associated resources.""" +from typing import Dict, Any +from .nfd_generator_base import NFDGenerator + +class CnfNfdGenerator(NFDGenerator): + """_summary_ + + :param NFDGenerator: _description_ + :type NFDGenerator: _type_ + """ + def __init__( + self, + config: Dict[Any, Any] + ): + super(NFDGenerator, self).__init__( + config=config, + ) diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py new file mode 100644 index 00000000000..3de8cd253eb --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -0,0 +1,30 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains a base class for generating NFDs.""" +from typing import Dict, Any +from knack.log import get_logger +logger = get_logger(__name__) + +class NFDGenerator: + """A class for generating an NFD from a config file.""" + + def __init__( + self, + config: Dict[Any, Any] + ) -> None: + """_summary_ + + :param definition_type: _description_ + :type definition_type: str + :param config: _description_ + :type config: Dict[Any, Any] + """ + self.config = config + + def generate_nfd(self) -> None: + """No-op on base class + """ + logger.error("Generate NFD called on base class. No-op") + return diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py new file mode 100644 index 00000000000..daa9802c872 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -0,0 +1,47 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains a class for generating VNF NFDs and associated resources.""" +from typing import Dict, Any +from .nfd_generator_base import NFDGenerator +from knack.log import get_logger +from azext_aosm.vendored_sdks import HybridNetworkManagementClient +from azext_aosm.vendored_sdks.models import Publisher, NetworkFunctionDefinitionVersion, NetworkFunctionDefinitionGroup, ArtifactManifest, ManifestArtifactFormat +from azext_aosm._constants import VHD_ARTIFACT, ARM_TEMPLATE_ARTIFACT + + +logger = get_logger(__name__) + +class VnfNfdGenerator(NFDGenerator): + """_summary_ + + :param NFDGenerator: _description_ + :type NFDGenerator: _type_ + """ + def __init__( + self, + config: Dict[Any, Any] + ): + super(NFDGenerator, self).__init__( + config=config, + ) + + def generate_nfd(self) -> None: + """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. + """ + arty_manny_sa = ArtifactManifest(location="blah", + tags={"blah": "blah"}, + artifacts=[ManifestArtifactFormat(artifact_name="blah", + artifact_type=VHD_ARTIFACT, + artifact_version="blah")]) + + arty_manny_acr = ArtifactManifest(location="blah", + tags={"blah": "blah"}, + artifacts=[ManifestArtifactFormat(artifact_name="blah", + artifact_type=ARM_TEMPLATE_ARTIFACT, + artifact_version="blah")]) + + + + From 5cdd0d8f8ba2107f982ca12f3276542f647404a7 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 26 Apr 2023 18:15:43 +0100 Subject: [PATCH 006/145] Draft create NFDV using python SDK --- src/aosm/azext_aosm/_configuration.py | 25 ++++++- src/aosm/azext_aosm/_constants.py | 4 - src/aosm/azext_aosm/custom.py | 15 +++- .../generate_nfd/cnf_nfd_generator.py | 2 +- .../generate_nfd/nfd_generator_base.py | 8 +- .../generate_nfd/vnf_nfd_generator.py | 73 ++++++++++++++----- .../publisher_resources.py | 27 +++++++ 7 files changed, 121 insertions(+), 33 deletions(-) create mode 100644 src/aosm/azext_aosm/publisher_resources/publisher_resources.py diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 797e484c9c0..17be230e6db 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,13 +1,15 @@ from dataclasses import dataclass from typing import Optional -from knack.util import CLIError +from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError from ._constants import VNF, CNF, NSD + @dataclass class ArtifactConfig: artifact_name: str = "Name of the artifact" file_path: Optional[str] = "File path of the artifact you wish to upload from your local disk" blob_sas_url: Optional[str] = "SAS URL of the blob artifact you wish to copy to your Artifact Store" + version: str = "Version of the artifact. For VHDs this must be in format A-B-C. For ARM templates this must be in format A.B.C" @dataclass @@ -17,6 +19,7 @@ class Configuration(): name: str = "Name of NF definition" version: str = "Version of the NF definition" acr_artifact_store_name: str = "Name of the ACR Artifact Store resource" + location: str = "azure location of the resources" @dataclass @@ -26,7 +29,7 @@ class VNFConfiguration(Configuration): vhd: ArtifactConfig = ArtifactConfig() -def get_configuration(definition_type, config_as_dict=None): +def get_configuration(definition_type, config_as_dict=None) -> Configuration: if config_as_dict is None: config_as_dict = {} @@ -37,6 +40,22 @@ def get_configuration(definition_type, config_as_dict=None): elif definition_type == NSD: config = Configuration(**config_as_dict) else: - raise CLIError("Definition type not recognized, options are: vnf, cnf or nsd") + raise InvalidArgumentValueError("Definition type not recognized, options are: vnf, cnf or nsd") return config + +def validate_configuration(config: Configuration) -> None: + """Validate the configuration passed in + + :param config: _description_ + :type config: Configuration + """ + # Do we want to do this validation here or pass it to the service?? If the service + # had good error messages I'd say let the service do the validation. But it would + # certainly be quicker to catch here. + if isinstance(config, VNFConfiguration): + if "." in config.vhd.version or "-" not in config.vhd.version: + # Not sure about raising this particular one. + raise ValidationError("Config validation error. VHD artifact version should be in format A-B-C") + if "." not in config.arm_template.version or "-" in config.arm_template.version: + raise ValidationError("Config validation error. ARM template artifact version should be in format A.B.C") diff --git a/src/aosm/azext_aosm/_constants.py b/src/aosm/azext_aosm/_constants.py index 42db56a3e3e..2c0e1fd993e 100644 --- a/src/aosm/azext_aosm/_constants.py +++ b/src/aosm/azext_aosm/_constants.py @@ -8,7 +8,3 @@ VNF = "vnf" CNF = "cnf" NSD = "nsd" - -# Artifact Types -VHD_ARTIFACT = "VhdImageFile" -ARM_TEMPLATE_ARTIFACT = "ArmTemplate" diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 82a53ce2f4a..2e1fe81edc0 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -6,12 +6,14 @@ import json from dataclasses import asdict from typing import Optional, Tuple -from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator -from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator -from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator from knack.log import get_logger from azure.cli.core.azclierror import AzCLIError from azure.mgmt.resource import ResourceManagementClient + +from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator +from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator + from .vendored_sdks import HybridNetworkManagementClient from .vendored_sdks.models import Publisher, NetworkFunctionDefinitionVersion from ._client_factory import cf_resources @@ -84,7 +86,7 @@ def build_definition( config_as_dict = json.loads(f) config = get_configuration(definition_type, config_as_dict) - + validate_config(config) # Generate the NFD/NSD and the artifact manifest. @@ -118,5 +120,10 @@ def _generate_nfd(definition_type, config): nfd_generator = VnfNfdGenerator(config) elif definition_type == CNF: nfd_generator = CnfNfdGenerator(config) + else: + from azure.cli.core.azclierror import CLIInternalError + raise CLIInternalError( + "Generate NFD called for unrecognised definition_type. Only VNF and CNF have been implemented." + ) nfd_generator.generate_nfd() diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 77627b30885..623f35f1f8f 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------- """Contains a class for generating VNF NFDs and associated resources.""" from typing import Dict, Any -from .nfd_generator_base import NFDGenerator +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator class CnfNfdGenerator(NFDGenerator): """_summary_ diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index 3de8cd253eb..e022fd0152c 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -3,8 +3,10 @@ # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- """Contains a base class for generating NFDs.""" -from typing import Dict, Any from knack.log import get_logger +from azext_aosm._configuration import Configuration + + logger = get_logger(__name__) class NFDGenerator: @@ -12,14 +14,14 @@ class NFDGenerator: def __init__( self, - config: Dict[Any, Any] + config: Configuration ) -> None: """_summary_ :param definition_type: _description_ :type definition_type: str :param config: _description_ - :type config: Dict[Any, Any] + :type config: Configuration """ self.config = config diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index daa9802c872..abed6ef421a 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -3,12 +3,23 @@ # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- """Contains a class for generating VNF NFDs and associated resources.""" -from typing import Dict, Any -from .nfd_generator_base import NFDGenerator from knack.log import get_logger + +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.vendored_sdks import HybridNetworkManagementClient -from azext_aosm.vendored_sdks.models import Publisher, NetworkFunctionDefinitionVersion, NetworkFunctionDefinitionGroup, ArtifactManifest, ManifestArtifactFormat -from azext_aosm._constants import VHD_ARTIFACT, ARM_TEMPLATE_ARTIFACT +from azext_aosm.vendored_sdks.models import ( + NetworkFunctionDefinitionVersion, + NetworkFunctionDefinitionGroup, + ArtifactManifest, + ManifestArtifactFormat, + VersionState, + NetworkFunctionType, + NFVIType, + ArtifactType +) + +from azext_aosm._configuration import VNFConfiguration +from azext_aosm.publisher_resources.publisher_resources import PublisherResourceGenerator logger = get_logger(__name__) @@ -21,27 +32,53 @@ class VnfNfdGenerator(NFDGenerator): """ def __init__( self, - config: Dict[Any, Any] + config: VNFConfiguration ): super(NFDGenerator, self).__init__( config=config, - ) + ) def generate_nfd(self) -> None: """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. """ - arty_manny_sa = ArtifactManifest(location="blah", - tags={"blah": "blah"}, - artifacts=[ManifestArtifactFormat(artifact_name="blah", - artifact_type=VHD_ARTIFACT, - artifact_version="blah")]) + assert isinstance(self.config, VNFConfiguration) + arty_manny_sa = ArtifactManifest(location=self.config.location, + #tags={"blah": "blah"}, + artifacts=[ManifestArtifactFormat(artifact_name=self.config.vhd.artifact_name, + artifact_type=ArtifactType.VHD_IMAGE_FILE, + artifact_version=self.config.vhd.version)]) + + arty_manny_acr = ArtifactManifest(location=self.config.location, + #tags={"blah": "blah"}, + artifacts=[ManifestArtifactFormat(artifact_name=self.config.arm_template.artifact_name, + artifact_type=ArtifactType.ARM_TEMPLATE, + artifact_version=self.config.arm_template.version)]) + common_generator = PublisherResourceGenerator(config=self.config) + nfdg: NetworkFunctionDefinitionGroup = common_generator.generate_nfd_group() + + + def _generate_nfdv(self) -> NetworkFunctionDefinitionVersion: + """Generate an NFDV for a VNF + + :return: _description_ + :rtype: NetworkFunctionDefinitionVersion + """ + nfdv = NetworkFunctionDefinitionVersion(location=self.config.location, + # Think kwargs map magically to properties in bicep, somehow + kwargs= + { + "versionState": VersionState.PREVIEW, + "deployParameters": "TODO", + "networkFunctionType": NetworkFunctionType.VIRTUAL_NETWORK_FUNCTION, + "networkFunctionTemplate" : { + "nfviType": NFVIType.AZURE_CORE, + "networkFunctionApplications": [ + + ] + } + + }) - arty_manny_acr = ArtifactManifest(location="blah", - tags={"blah": "blah"}, - artifacts=[ManifestArtifactFormat(artifact_name="blah", - artifact_type=ARM_TEMPLATE_ARTIFACT, - artifact_version="blah")]) - - + diff --git a/src/aosm/azext_aosm/publisher_resources/publisher_resources.py b/src/aosm/azext_aosm/publisher_resources/publisher_resources.py new file mode 100644 index 00000000000..201ad439c91 --- /dev/null +++ b/src/aosm/azext_aosm/publisher_resources/publisher_resources.py @@ -0,0 +1,27 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Shared publisher resources""" +from dataclasses import dataclass +from knack.log import get_logger +from azext_aosm.vendored_sdks.models import NetworkFunctionDefinitionGroup +from azext_aosm._configuration import Configuration + + +logger = get_logger(__name__) + +@dataclass +class PublisherResourceGenerator: + """Class for generating publisher resources used by various other classes.""" + config: Configuration + + def generate_nfd_group(self) -> NetworkFunctionDefinitionGroup: + """Generate a NFD group with location and description from config. + + :return: _description_ + :rtype: NetworkFunctionDefinitionGroup + """ + return NetworkFunctionDefinitionGroup(location=self.config.location, + description=f"NFD Group for versions of NFDs for {self.config.name}") + From 8cdf766609f4eeec393fa8b573e360257a11b1eb Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Thu, 27 Apr 2023 14:44:31 +0100 Subject: [PATCH 007/145] Add deployer class --- src/aosm/azext_aosm/_deployer.py | 316 +++++++++++++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 src/aosm/azext_aosm/_deployer.py diff --git a/src/aosm/azext_aosm/_deployer.py b/src/aosm/azext_aosm/_deployer.py new file mode 100644 index 00000000000..6ba51f81549 --- /dev/null +++ b/src/aosm/azext_aosm/_deployer.py @@ -0,0 +1,316 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains class for deploying generated definitions.""" + +from knack.log import get_logger +from azure.mgmt.resource import ResourceManagementClient +from .vendored_sdks import HybridNetworkManagementClient +from .vendored_sdks.models import ( + ArtifactStore, + ArtifactStoreType, + ArtifactType, + ArtifactManifest, + NetworkFunctionDefinitionGroup, + NetworkFunctionDefinitionVersion, + NetworkServiceDesignGroup, + NetworkServiceDesignVersion, + Publisher, +) + +logger = get_logger(__name__) + + +class Deployer: + """A class for publishing definitions.""" + + def __init__( + self, + aosm_client: HybridNetworkManagementClient, + resource_client: ResourceManagementClient, + ) -> None: + """ + Initializes a new instance of the Deployer class. + + :param aosm_client: The client to use for managing AOSM resources. + :type aosm_client: HybridNetworkManagementClient + :param resource_client: The client to use for managing Azure resources. + :type resource_client: ResourceManagementClient + """ + + self.aosm_client = aosm_client + self.resource_client = resource_client + + def _ensure_publisher_exists( + self, resource_group_name: str, publisher_name: str, location: str + ) -> None: + """ + Ensures that the publisher exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param location: The location of the publisher. + :type location: str + """ + + logger.info( + "Creating publisher %s if it does not exist", publisher_name + ) + if not self.resource_client.resources.check_existance( + resource_group_name=resource_group_name, + resource_type="Microsoft.HybridNetwork/publishers", + resource_name=publisher_name, + ): + self.aosm_client.publishers.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + parameters=Publisher(location=location, scope="Public"), + ) + + def _ensure_artifact_store_exists( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_store_type: ArtifactStoreType, + location: str, + ) -> None: + """ + Ensures that the artifact store exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_store_type: The type of the artifact store. + :type artifact_store_type: ArtifactStoreType + :param location: The location of the artifact store. + :type location: str + """ + + logger.info( + "Creating artifact store %s if it does not exist", + artifact_store_name, + ) + self.aosm_client.artifact_stores.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + parameters=ArtifactStore( + location=location, + artifact_store_type=artifact_store_type, + ), + ) + + def _ensure_nfdg_exists( + self, + resource_group_name: str, + publisher_name: str, + nfdg_name: str, + location: str, + ): + """ + Ensures that the network function definition group exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param nfdg_name: The name of the network function definition group. + :type nfdg_name: str + :param location: The location of the network function definition group. + :type location: str + """ + + logger.info( + "Creating network function definition group %s if it does not exist", + nfdg_name, + ) + self.aosm_client.network_function_definition_groups.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=nfdg_name, + parameters=NetworkFunctionDefinitionGroup(location=location), + ) + + def _ensure_nsdg_exists( + self, + resource_group_name: str, + publisher_name: str, + nsdg_name: str, + location: str, + ): + """ + Ensures that the network service design group exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param nsdg_name: The name of the network service design group. + :type nsdg_name: str + :param location: The location of the network service design group. + :type location: str + """ + + logger.info( + "Creating network service design group %s if it does not exist", + nsdg_name, + ) + self.aosm_client.network_service_design_groups.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=nsdg_name, + parameters=NetworkServiceDesignGroup(location=location), + ) + + def publish_artifact_manifest( + self, + resource_group_name: str, + location: str, + publisher_name: str, + artifact_store_name: str, + artifact_manifest: ArtifactManifest, + ) -> None: + """ + Publishes an artifact manifest. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param location: The location of the artifact manifest. + :type location: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_manifest: The artifact manifest. + :type artifact_manifest: ArtifactManifest + """ + + self._ensure_publisher_exists( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + location=location, + ) + + artifact_types = [a.artifact_type for a in artifact_manifest.artifacts] + + if ( + ArtifactType.VHD_IMAGE_FILE + or ArtifactType.IMAGE_FILE in artifact_types + ): + artifact_store_type = ArtifactStoreType.AZURE_STORAGE_ACCOUNT + else: + artifact_store_type = ArtifactStoreType.AZURE_CONTAINER_REGISTRY + + self._ensure_artifact_store_exists( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_store_type=artifact_store_type, + location=location, + ) + + logger.info("Creating artifact manifest %s", artifact_manifest.name) + self.aosm_client.artifact_manifests.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + artifact_manifest_name=artifact_manifest.name, + parameters=artifact_manifest, + ) + + def publish_network_function_definition_version( + self, + resource_group_name: str, + publisher_name: str, + location: str, + network_function_definition_group_name: str, + network_function_definition_version: NetworkFunctionDefinitionVersion, + ) -> None: + """ + Publishes a network function definition version. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param location: The location of the network function definition version. + :type location: str + :param network_function_definition_group_name: The name of the network function definition group. + :type network_function_definition_group_name: str + :param network_function_definition_version: The network function definition version. + :type network_function_definition_version: NetworkFunctionDefinitionVersion + """ + + self._ensure_publisher_exists( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + location=location, + ) + + self._ensure_nfdg_exists( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + nfdg_name=network_function_definition_group_name, + location=location, + ) + + logger.info("Publishing network function definition version") + self.aosm_client.network_function_definition_versions.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=network_function_definition_group_name, + network_function_definition_version_name=network_function_definition_version.name, + parameters=network_function_definition_version, + ) + + def publish_network_service_design_version( + self, + resource_group_name: str, + publisher_name: str, + location: str, + network_service_design_group_name: str, + network_service_design_version: NetworkServiceDesignVersion, + ) -> None: + """ + Publishes a network service design version. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param location: The location of the network service design version. + :type location: str + :param network_service_design_group_name: The name of the network service design group. + :type network_service_design_group_name: str + :param network_service_design_version: The network service design version. + :type network_service_design_version: NetworkServiceDesignVersion + """ + + self._ensure_publisher_exists( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + location=location, + ) + + self._ensure_nsdg_exists( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + nsdg_name=network_service_design_group_name, + location=location, + ) + + logger.info("Publishing network service design version") + self.aosm_client.network_service_design_versions.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=network_service_design_group_name, + network_service_design_version_name=network_service_design_version.name, + parameters=network_service_design_version, + ) From 105c80973f281941b1b7f2b187e0133b23d5ea65 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Thu, 27 Apr 2023 17:13:33 +0100 Subject: [PATCH 008/145] pushing this but then moving on to delete --- .../generate_nfd/vnf_nfd_generator.py | 35 +++++++++++-------- src/aosm/azext_aosm/test.py | 35 +++++++++++++++++++ 2 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 src/aosm/azext_aosm/test.py diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index abed6ef421a..1363839e315 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -15,7 +15,11 @@ VersionState, NetworkFunctionType, NFVIType, - ArtifactType + ArtifactType, + VirtualNetworkFunctionDefinitionVersion, # this is actually properties, badly named + AzureCoreNetworkFunctionTemplate, + AzureCoreNetworkFunctionVhdApplication, + AzureCoreNetworkFunctionArmTemplateApplication ) from azext_aosm._configuration import VNFConfiguration @@ -63,21 +67,22 @@ def _generate_nfdv(self) -> NetworkFunctionDefinitionVersion: :return: _description_ :rtype: NetworkFunctionDefinitionVersion """ + + vnf_props = VirtualNetworkFunctionDefinitionVersion( + version_state=VersionState.PREVIEW, + deploy_parameters= "TODO", + network_function_femplate=AzureCoreNetworkFunctionTemplate( + network_function_applications= [ + AzureCoreNetworkFunctionVhdApplication(), + AzureCoreNetworkFunctionArmTemplateApplication() + ] + )) + nfdv = NetworkFunctionDefinitionVersion(location=self.config.location, - # Think kwargs map magically to properties in bicep, somehow - kwargs= - { - "versionState": VersionState.PREVIEW, - "deployParameters": "TODO", - "networkFunctionType": NetworkFunctionType.VIRTUAL_NETWORK_FUNCTION, - "networkFunctionTemplate" : { - "nfviType": NFVIType.AZURE_CORE, - "networkFunctionApplications": [ - - ] - } - - }) + # Think kwargs map magically to properties in bicep, somehow + kwargs=vnf_props) + + return nfdv diff --git a/src/aosm/azext_aosm/test.py b/src/aosm/azext_aosm/test.py new file mode 100644 index 00000000000..edaf2e5caef --- /dev/null +++ b/src/aosm/azext_aosm/test.py @@ -0,0 +1,35 @@ +from azext_aosm.vendored_sdks import HybridNetworkManagementClient +from azext_aosm.vendored_sdks.models import ( + NetworkFunctionDefinitionVersion, + NetworkFunctionDefinitionGroup, + ArtifactManifest, + ManifestArtifactFormat, + VersionState, + NetworkFunctionType, + NFVIType, + ArtifactType, + VirtualNetworkFunctionDefinitionVersion, # this is actually properties, badly named + AzureCoreNetworkFunctionTemplate, + AzureCoreNetworkFunctionVhdApplication, + AzureCoreNetworkFunctionArmTemplateApplication +) + +vnf_props = VirtualNetworkFunctionDefinitionVersion( + version_state=VersionState.PREVIEW, + deploy_parameters= "TODO", + network_function_template=AzureCoreNetworkFunctionTemplate( + network_function_applications= [ + AzureCoreNetworkFunctionVhdApplication(), + AzureCoreNetworkFunctionArmTemplateApplication() + ] +)) + +#test_dict = dict(**vnf_props) +print(vnf_props.__dict__) + +nfdv = NetworkFunctionDefinitionVersion(location="uksouth", + #network_function_type="VirtualNetworkFunction", + # Think kwargs map magically to properties in bicep, somehow + **vnf_props.__dict__) + +print(nfdv) From 9baaeb3df054a17b15162fc004f3c671da56d2f0 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 28 Apr 2023 11:52:02 +0100 Subject: [PATCH 009/145] start to move to bicep deployer --- src/aosm/azext_aosm/_configuration.py | 4 +- src/aosm/azext_aosm/commands.py | 3 +- src/aosm/azext_aosm/custom.py | 22 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 244 ++++++++++++++++++ .../deploy_with_sdk.py} | 168 ++---------- src/aosm/azext_aosm/deploy/pre_deploy.py | 167 ++++++++++++ .../generate_nfd/nfd_generator_base.py | 8 +- .../templates/publisher_definition.bicep | 15 ++ .../templates/vnfdefinition.bicep | 145 +++++++++++ .../generate_nfd/vnf_bicep_nfd_generator.py | 211 +++++++++++++++ .../generate_nfd/vnf_nfd_generator.py | 89 ------- 11 files changed, 825 insertions(+), 251 deletions(-) create mode 100644 src/aosm/azext_aosm/deploy/deploy_with_arm.py rename src/aosm/azext_aosm/{_deployer.py => deploy/deploy_with_sdk.py} (56%) create mode 100644 src/aosm/azext_aosm/deploy/pre_deploy.py create mode 100644 src/aosm/azext_aosm/generate_nfd/templates/publisher_definition.bicep create mode 100644 src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep create mode 100644 src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py delete mode 100644 src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 17be230e6db..40f88eed329 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -54,8 +54,8 @@ def validate_configuration(config: Configuration) -> None: # had good error messages I'd say let the service do the validation. But it would # certainly be quicker to catch here. if isinstance(config, VNFConfiguration): - if "." in config.vhd.version or "-" not in config.vhd.version: + if "." in config.vhd["version"] or "-" not in config.vhd["version"]: # Not sure about raising this particular one. raise ValidationError("Config validation error. VHD artifact version should be in format A-B-C") - if "." not in config.arm_template.version or "-" in config.arm_template.version: + if "." not in config.arm_template["version"] or "-" in config.arm_template["version"]: raise ValidationError("Config validation error. ARM template artifact version should be in format A.B.C") diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index ffa2263d0e4..f4546cac9b8 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -18,8 +18,9 @@ def load_command_table(self: AzCommandsLoader, _): with self.command_group('aosm definition', client_factory=cf_aosm) as g: # Add each command and bind it to a function in custom.py - g.custom_command('build', 'build_definition') g.custom_command('generate-config', 'generate_definition_config') + g.custom_command('build', 'build_definition') + g.custom_command('publish', 'publish_definition') g.custom_command('show', 'show_publisher') with self.command_group('aosm', is_preview=True): diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 2e1fe81edc0..cd8ae5cd23d 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -12,12 +12,12 @@ from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator -from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator +from azext_aosm.generate_nfd.vnf_bicep_nfd_generator import VnfBicepNfdGenerator from .vendored_sdks import HybridNetworkManagementClient from .vendored_sdks.models import Publisher, NetworkFunctionDefinitionVersion from ._client_factory import cf_resources -from ._configuration import Configuration, VNFConfiguration, get_configuration +from ._configuration import Configuration, VNFConfiguration, get_configuration, validate_configuration from ._constants import VNF, CNF, NSD @@ -83,13 +83,15 @@ def build_definition( publish=False, ): with open(config_file, "r", encoding="utf-8") as f: - config_as_dict = json.loads(f) - + config_as_dict = json.loads(f.read()) + + # TODO - this isn't deserializing the config properly - any sub-objects are left + # as a dictionary instead of being converted to the object (e.g. ArtifactConfig) + # se we have to reference them as dictionary values config = get_configuration(definition_type, config_as_dict) - validate_config(config) + validate_configuration(config) # Generate the NFD/NSD and the artifact manifest. - - + _generate_nfd(definition_type=definition_type, config=config) # Write the ARM/bicep template if that's what we are doing # Publish the definition if publish is true @@ -117,7 +119,7 @@ def _generate_nfd(definition_type, config): """ nfd_generator: NFDGenerator if definition_type == VNF: - nfd_generator = VnfNfdGenerator(config) + nfd_generator = VnfBicepNfdGenerator(config) elif definition_type == CNF: nfd_generator = CnfNfdGenerator(config) else: @@ -127,3 +129,7 @@ def _generate_nfd(definition_type, config): ) nfd_generator.generate_nfd() + +def publish_nfd +def show_publisher(): + pass diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py new file mode 100644 index 00000000000..cedfe6d1991 --- /dev/null +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -0,0 +1,244 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains class for deploying generated definitions using the Python SDK.""" +import json +import logging +import os +import shutil +import subprocess # noqa +from functools import cached_property +from typing import Any, Dict + +from knack.log import get_logger +from azure.identity import DefaultAzureCredential +from azure.mgmt.resource import ResourceManagementClient +from azure.mgmt.resource.resources.v2021_04_01.models import DeploymentExtended + +from azext_aosm.vendored_sdks import HybridNetworkManagementClient +from azext_aosm.vendored_sdks.models import ( + NetworkFunctionDefinitionVersion, + NetworkServiceDesignVersion, + ArtifactStoreType, + ArtifactType, + ArtifactManifest, +) +from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK + + +logger = get_logger(__name__) + + +class DeployerViaArm: + """A class to deploy Artifact Manifests, NFDs and NSDs from a bicep template using ARM.""" + # @@@TODO - not sure this class is required as we can't publish complex objects + # using the SDK + + def __init__( + self, + aosm_client: HybridNetworkManagementClient, + resource_client: ResourceManagementClient, + subscription_id: str, + resource_group: str + ) -> None: + """ + Initializes a new instance of the Deployer class. + + :param aosm_client: The client to use for managing AOSM resources. + :type aosm_client: HybridNetworkManagementClient + :param resource_client: The client to use for managing Azure resources. + :type resource_client: ResourceManagementClient + """ + logger.debug("Create ARM/Bicep Deployer") + self.aosm_client = aosm_client + + self.subscription_id = subscription_id + self.credentials = DefaultAzureCredential() + self.resource_group = resource_group + self.pre_deployer = PreDeployerViaSDK(aosm_client, self.resource_client) + + @cached_property + def resource_client(self) -> ResourceManagementClient: + """ + Create a client that can create resources on Azure. + + :return: A ResourceManagementClient + """ + logger.debug("Create resource client") + return ResourceManagementClient(self.credentials, self.subscription_id) + + def deploy_bicep_template( + self, bicep_template_path: str, parameters: Dict[Any, Any] + ) -> Any: + """ + Deploy a bicep template. + + :param bicep_template_path: Path to the bicep template + :param parameters: Parameters for the bicep template + """ + logger.info("Deploy %s", bicep_template_path) + arm_template_json = self.convert_bicep_to_arm(bicep_template_path) + + return self.validate_and_deploy_arm_template( + arm_template_json, parameters, self.resource_group + ) + + def resource_exists(self, resource_name: str) -> bool: + """ + Determine if a resource with the given name exists. + + :param resource_name: The name of the resource to check. + """ + logger.debug("Check if %s exists", resource_name) + resources = self.resource_client.resources.list_by_resource_group( + resource_group_name=self.resource_group + ) + + resource_exists = False + + for resource in resources: + if resource.name == resource_name: + resource_exists = True + break + + return resource_exists + + def validate_and_deploy_arm_template( + self, template: Any, parameters: Dict[Any, Any], resource_group: str + ) -> Any: + """ + Validate and deploy an individual ARM template. + + This ARM template will be created in the resource group passed in. + + :param template: The JSON contents of the template to deploy + :param parameters: The JSON contents of the parameters file + :param resource_group: The name of the resource group that has been deployed + + :raise RuntimeError if validation or deploy fails + :return: Output dictionary from the bicep template. + """ + deployment_name = f"nfd_into_{resource_group}" + + validation = self.resource_client.deployments.begin_validate( + resource_group_name=resource_group, + deployment_name=deployment_name, + parameters={ + "properties": { + "mode": "Incremental", + "template": template, + "parameters": parameters, + } + }, + ) + + validation_res = validation.result() + logger.debug(f"Validation Result {validation_res}") + if validation_res.error: + # Validation failed so don't even try to deploy + logger.error( + f"Template for resource group {resource_group} " + f"has failed validation. The message was: " + f"{validation_res.error.message}. See logs for additional details." + ) + logger.debug( + f"Template for resource group {resource_group} " + f"failed validation. Full error details: {validation_res.error}." + ) + raise RuntimeError("Azure template validation failed.") + + # Validation succeeded so proceed with deployment + logger.debug(f"Successfully validated resources for {resource_group}") + + poller = self.resource_client.deployments.begin_create_or_update( + resource_group_name=resource_group, + deployment_name=deployment_name, + parameters={ + "properties": { + "mode": "Incremental", + "template": template, + "parameters": parameters, + } + }, + ) + logger.debug(poller) + + # Wait for the deployment to complete and get the outputs + deployment: DeploymentExtended = poller.result() + + if deployment.properties is not None: + depl_props = deployment.properties + else: + raise RuntimeError("The deployment has no properties.\nAborting") + logger.debug(f"Deployed: {deployment.name} {deployment.id} {depl_props}") + + if depl_props.provisioning_state != "Succeeded": + logger.debug(f"Failed to provision: {depl_props}") + raise RuntimeError( + f"Deploy of template to resource group" + f" {resource_group} proceeded but the provisioning" + f" state returned is {depl_props.provisioning_state}. " + f"\nAborting" + ) + logger.debug( + f"Provisioning state of {resource_group}" + f": {depl_props.provisioning_state}" + ) + + return depl_props.outputs + + def convert_bicep_to_arm(self, bicep_template: str) -> Any: + """ + Convert a bicep template into an ARM template. + + :param bicep_template: The path to the bicep template to be converted + + :raise RuntimeError if az CLI is not installed. + :return: Output dictionary from the bicep template. + """ + if not shutil.which("az"): + logger.error( + "The Azure CLI is not installed - follow " + "https://github.com/Azure/bicep/blob/main/docs/installing.md#linux" + ) + raise RuntimeError( + "The Azure CLI is not installed - cannot render ARM templates." + ) + logger.debug(f"Converting {bicep_template} to ARM template") + + arm_template_name = bicep_template.replace(".bicep", ".json") + + try: + bicep_output = subprocess.run( # noqa + [ + str(shutil.which("az")), + "bicep", + "build", + "--file", + bicep_template, + "--outfile", + arm_template_name, + ], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + logger.debug("az bicep output: %s", str(bicep_output)) + except subprocess.CalledProcessError as e: + logger.error( + "ARM template compilation failed! See logs for full " + "output. The failing command was %s", + e.cmd, + ) + logger.debug("bicep build stdout: %s", e.stdout) + logger.debug("bicep build stderr: %s", e.stderr) + raise + + with open(arm_template_name, "r", encoding="utf-8") as template_file: + arm_json = json.loads(template_file.read()) + + os.remove(arm_template_name) + + return arm_json + diff --git a/src/aosm/azext_aosm/_deployer.py b/src/aosm/azext_aosm/deploy/deploy_with_sdk.py similarity index 56% rename from src/aosm/azext_aosm/_deployer.py rename to src/aosm/azext_aosm/deploy/deploy_with_sdk.py index 6ba51f81549..4ba73156e8c 100644 --- a/src/aosm/azext_aosm/_deployer.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_sdk.py @@ -2,29 +2,29 @@ # Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- -"""Contains class for deploying generated definitions.""" +"""Contains class for deploying generated definitions using the Python SDK.""" from knack.log import get_logger from azure.mgmt.resource import ResourceManagementClient -from .vendored_sdks import HybridNetworkManagementClient -from .vendored_sdks.models import ( - ArtifactStore, +from azext_aosm.vendored_sdks import HybridNetworkManagementClient +from azext_aosm.vendored_sdks.models import ( + NetworkFunctionDefinitionVersion, + NetworkServiceDesignVersion, ArtifactStoreType, ArtifactType, ArtifactManifest, - NetworkFunctionDefinitionGroup, - NetworkFunctionDefinitionVersion, - NetworkServiceDesignGroup, - NetworkServiceDesignVersion, - Publisher, ) +from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK -logger = get_logger(__name__) +logger = get_logger(__name__) -class Deployer: - """A class for publishing definitions.""" +class DeployerViaSDK: + """A class to deploy Artifact Manifests, NFDs and NSDs using the python SDK.""" + # @@@TODO - not sure this class is required as we can't publish complex objects + # using the SDK + def __init__( self, aosm_client: HybridNetworkManagementClient, @@ -41,134 +41,8 @@ def __init__( self.aosm_client = aosm_client self.resource_client = resource_client - - def _ensure_publisher_exists( - self, resource_group_name: str, publisher_name: str, location: str - ) -> None: - """ - Ensures that the publisher exists in the resource group. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param location: The location of the publisher. - :type location: str - """ - - logger.info( - "Creating publisher %s if it does not exist", publisher_name - ) - if not self.resource_client.resources.check_existance( - resource_group_name=resource_group_name, - resource_type="Microsoft.HybridNetwork/publishers", - resource_name=publisher_name, - ): - self.aosm_client.publishers.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - parameters=Publisher(location=location, scope="Public"), - ) - - def _ensure_artifact_store_exists( - self, - resource_group_name: str, - publisher_name: str, - artifact_store_name: str, - artifact_store_type: ArtifactStoreType, - location: str, - ) -> None: - """ - Ensures that the artifact store exists in the resource group. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param artifact_store_name: The name of the artifact store. - :type artifact_store_name: str - :param artifact_store_type: The type of the artifact store. - :type artifact_store_type: ArtifactStoreType - :param location: The location of the artifact store. - :type location: str - """ - - logger.info( - "Creating artifact store %s if it does not exist", - artifact_store_name, - ) - self.aosm_client.artifact_stores.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - artifact_store_name=artifact_store_name, - parameters=ArtifactStore( - location=location, - artifact_store_type=artifact_store_type, - ), - ) - - def _ensure_nfdg_exists( - self, - resource_group_name: str, - publisher_name: str, - nfdg_name: str, - location: str, - ): - """ - Ensures that the network function definition group exists in the resource group. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param nfdg_name: The name of the network function definition group. - :type nfdg_name: str - :param location: The location of the network function definition group. - :type location: str - """ - - logger.info( - "Creating network function definition group %s if it does not exist", - nfdg_name, - ) - self.aosm_client.network_function_definition_groups.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - network_function_definition_group_name=nfdg_name, - parameters=NetworkFunctionDefinitionGroup(location=location), - ) - - def _ensure_nsdg_exists( - self, - resource_group_name: str, - publisher_name: str, - nsdg_name: str, - location: str, - ): - """ - Ensures that the network service design group exists in the resource group. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param nsdg_name: The name of the network service design group. - :type nsdg_name: str - :param location: The location of the network service design group. - :type location: str - """ - - logger.info( - "Creating network service design group %s if it does not exist", - nsdg_name, - ) - self.aosm_client.network_service_design_groups.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - network_service_design_group_name=nsdg_name, - parameters=NetworkServiceDesignGroup(location=location), - ) - + self.pre_deployer = PreDeployerViaSDK(aosm_client, resource_client) + def publish_artifact_manifest( self, resource_group_name: str, @@ -192,7 +66,7 @@ def publish_artifact_manifest( :type artifact_manifest: ArtifactManifest """ - self._ensure_publisher_exists( + self.pre_deployer.ensure_publisher_exists( resource_group_name=resource_group_name, publisher_name=publisher_name, location=location, @@ -208,7 +82,7 @@ def publish_artifact_manifest( else: artifact_store_type = ArtifactStoreType.AZURE_CONTAINER_REGISTRY - self._ensure_artifact_store_exists( + self.pre_deployer.ensure_artifact_store_exists( resource_group_name=resource_group_name, publisher_name=publisher_name, artifact_store_name=artifact_store_name, @@ -224,7 +98,7 @@ def publish_artifact_manifest( artifact_manifest_name=artifact_manifest.name, parameters=artifact_manifest, ) - + def publish_network_function_definition_version( self, resource_group_name: str, @@ -248,13 +122,13 @@ def publish_network_function_definition_version( :type network_function_definition_version: NetworkFunctionDefinitionVersion """ - self._ensure_publisher_exists( + self.pre_deployer.ensure_publisher_exists( resource_group_name=resource_group_name, publisher_name=publisher_name, location=location, ) - self._ensure_nfdg_exists( + self.pre_deployer.ensure_nfdg_exists( resource_group_name=resource_group_name, publisher_name=publisher_name, nfdg_name=network_function_definition_group_name, @@ -293,13 +167,13 @@ def publish_network_service_design_version( :type network_service_design_version: NetworkServiceDesignVersion """ - self._ensure_publisher_exists( + self.pre_deployer.ensure_publisher_exists( resource_group_name=resource_group_name, publisher_name=publisher_name, location=location, ) - self._ensure_nsdg_exists( + self.pre_deployer.ensure_nsdg_exists( resource_group_name=resource_group_name, publisher_name=publisher_name, nsdg_name=network_service_design_group_name, diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py new file mode 100644 index 00000000000..d99658af491 --- /dev/null +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -0,0 +1,167 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains class for deploying resources required by NFDs/NSDs via the SDK.""" + +from knack.log import get_logger +from azure.mgmt.resource import ResourceManagementClient + +from azext_aosm.vendored_sdks import HybridNetworkManagementClient +from azext_aosm.vendored_sdks.models import ( + ArtifactStore, + ArtifactStoreType, + NetworkFunctionDefinitionGroup, + NetworkServiceDesignGroup, + Publisher, +) + +logger = get_logger(__name__) + + +class PreDeployerViaSDK: + """A class for checking or publishing resources required by NFDs/NSDs.""" + + def __init__( + self, + aosm_client: HybridNetworkManagementClient, + resource_client: ResourceManagementClient, + ) -> None: + """ + Initializes a new instance of the Deployer class. + + :param aosm_client: The client to use for managing AOSM resources. + :type aosm_client: HybridNetworkManagementClient + :param resource_client: The client to use for managing Azure resources. + :type resource_client: ResourceManagementClient + """ + + self.aosm_client = aosm_client + self.resource_client = resource_client + + def ensure_publisher_exists( + self, resource_group_name: str, publisher_name: str, location: str + ) -> None: + """ + Ensures that the publisher exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param location: The location of the publisher. + :type location: str + """ + + logger.info( + "Creating publisher %s if it does not exist", publisher_name + ) + if not self.resource_client.resources.check_existance( + resource_group_name=resource_group_name, + resource_type="Microsoft.HybridNetwork/publishers", + resource_name=publisher_name, + ): + self.aosm_client.publishers.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + parameters=Publisher(location=location, scope="Public"), + ) + + def ensure_artifact_store_exists( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_store_type: ArtifactStoreType, + location: str, + ) -> None: + """ + Ensures that the artifact store exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_store_type: The type of the artifact store. + :type artifact_store_type: ArtifactStoreType + :param location: The location of the artifact store. + :type location: str + """ + + logger.info( + "Creating artifact store %s if it does not exist", + artifact_store_name, + ) + self.aosm_client.artifact_stores.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + parameters=ArtifactStore( + location=location, + artifact_store_type=artifact_store_type, + ), + ) + + def ensure_nfdg_exists( + self, + resource_group_name: str, + publisher_name: str, + nfdg_name: str, + location: str, + ): + """ + Ensures that the network function definition group exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param nfdg_name: The name of the network function definition group. + :type nfdg_name: str + :param location: The location of the network function definition group. + :type location: str + """ + + logger.info( + "Creating network function definition group %s if it does not exist", + nfdg_name, + ) + self.aosm_client.network_function_definition_groups.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=nfdg_name, + parameters=NetworkFunctionDefinitionGroup(location=location), + ) + + def ensure_nsdg_exists( + self, + resource_group_name: str, + publisher_name: str, + nsdg_name: str, + location: str, + ): + """ + Ensures that the network service design group exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param nsdg_name: The name of the network service design group. + :type nsdg_name: str + :param location: The location of the network service design group. + :type location: str + """ + + logger.info( + "Creating network service design group %s if it does not exist", + nsdg_name, + ) + self.aosm_client.network_service_design_groups.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=nsdg_name, + parameters=NetworkServiceDesignGroup(location=location), + ) diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index e022fd0152c..3458ad8e0c8 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -11,10 +11,10 @@ class NFDGenerator: """A class for generating an NFD from a config file.""" - + def __init__( self, - config: Configuration + #config: Configuration ) -> None: """_summary_ @@ -23,8 +23,8 @@ def __init__( :param config: _description_ :type config: Configuration """ - self.config = config - + #self.config = config + def generate_nfd(self) -> None: """No-op on base class """ diff --git a/src/aosm/azext_aosm/generate_nfd/templates/publisher_definition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/publisher_definition.bicep new file mode 100644 index 00000000000..62fd4aef354 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/templates/publisher_definition.bicep @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Highly Confidential Material +// Bicep template to create a Publisher +param location string = resourceGroup().location +@description('Name you want to give the new Publisher object') +param publisherName string + +resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' = { + name: publisherName + scope: resourceGroup() + location: location + properties: { + scope: 'Private' + } +} diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep new file mode 100644 index 00000000000..5a87f8b511b --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep @@ -0,0 +1,145 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an NF definition for a VNF +param location string = resourceGroup().location +@description('Name of an existing publisher, expected to be in the resource group where you deploy the template') +param publisherName string +@description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') +param acrArtifactStoreName string +@description('Name of an existing Storage Account-backed Artifact Store, deployed under the publisher.') +param saArtifactStoreName string +@description('Name of Network Function. Used predominantly as a prefix for other variable names') +param nfName string +@description('Name of an existing Network Function Definition Group') +param nfDefinitionGroup string +@description('The version of the NFDV you want to deploy, in format A-B-C') +param nfDefinitionVersion string +@description('The name under which to store the VHD') +param vhdName string +@description('The version that you want to name the NFM VHD artifact, in format A-B-C. e.g. 6-13-0') +param vhdVersion string +@description('The name under which to store the ARM template') +param armTemplateName string +@description('The version that you want to name the NFM template artifact, in format A.B.C. e.g. 6.13.0. If testing for development, you can use any numbers you like.') +param armTemplateVersion string + +resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { + name: publisherName + scope: resourceGroup() +} + +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' = { + parent: publisher + name: acrArtifactStoreName + location: location + properties: { + storeType: 'AzureContainerRegistry' + } +} + +resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' = { + parent: publisher + name: saArtifactStoreName + location: location + properties: { + storeType: 'AzureStorageAccount' + } +} + +resource nfdg 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups@2022-09-01-preview' = { + parent: publisher + name: nfDefinitionGroup + location: location +} + +resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { + parent: saArtifactStore + name: '${nfName}-sa-manifest-${replace(nfDefinitionVersion, '.', '-')}' + location: location + properties: { + artifacts: [ + { + artifactName: '${vhdName}' + artifactType: 'VhdImageFile' + artifactVersion: vhdVersion + } + ] + } +} + +resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { + parent: acrArtifactStore + name: '${nfName}-acr-manifest-${replace(nfDefinitionVersion, '.', '-')}' + location: location + properties: { + artifacts: [ + { + artifactName: '${armTemplateName}' + artifactType: 'ArmTemplate' + artifactVersion: armTemplateVersion + } + ] + } +} + +resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups/networkfunctiondefinitionversions@2022-09-01-preview' = { + parent: nfdg + name: nfDefinitionVersion + location: location + properties: { + // versionState should be changed to 'Active' once it is finalized. + versionState: 'Preview' + deployParameters: string(loadJsonContent('schemas/deploymentParameters.json')) + networkFunctionType: 'VirtualNetworkFunction' + networkFunctionTemplate: { + nfviType: 'AzureCore' + networkFunctionApplications: [ + { + artifactType: 'VhdImageFile' + name: '${nfName}Image' + dependsOnProfile: null + artifactProfile: { + vhdArtifactProfile: { + vhdName: '${nfName}-vhd' + vhdVersion: vhdVersion + } + artifactStore: { + id: saArtifactStore.id + } + } + // mapping deploy param vals to vals required by this network function application object + deployParametersMappingRuleProfile: { + vhdImageMappingRuleProfile: { + userConfiguration: string(loadJsonContent('configMappings/vhdParameters.json')) + } + // ?? + applicationEnablement: 'Unknown' + } + } + { + artifactType: 'ArmTemplate' + name: nfName + dependsOnProfile: null + artifactProfile: { + templateArtifactProfile: { + templateName: '${nfName}-arm-template' + templateVersion: armTemplateVersion + } + artifactStore: { + id: acrArtifactStore.id + } + } + deployParametersMappingRuleProfile: { + templateMappingRuleProfile: { + templateParameters: string(loadJsonContent('configMappings/templateParameters.json')) + } + applicationEnablement: 'Unknown' + } + } + ] + } + } +} + +output acr_manifest_id string = acrArtifactManifest.id +output sa_manifest_id string = saArtifactManifest.id diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py new file mode 100644 index 00000000000..2520bbf0cc8 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -0,0 +1,211 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains a class for generating VNF NFDs and associated resources.""" +from knack.log import get_logger +import json +import logging +import os +import shutil +from functools import cached_property +from pathlib import Path +from typing import Any, Dict, Optional + +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator + +from azext_aosm._configuration import VNFConfiguration +from azext_aosm.publisher_resources.publisher_resources import PublisherResourceGenerator + + +logger = get_logger(__name__) + +class VnfBicepNfdGenerator(NFDGenerator): + """_summary_ + + :param NFDGenerator: _description_ + :type NFDGenerator: _type_ + """ + def __init__( + self, + config: VNFConfiguration + ): + super(NFDGenerator, self).__init__( + #config=config, + ) + self.config = config + self.bicep_template_name = "vnfdefinition.bicep" + + self.arm_template_path = self.config.arm_template["file_path"] + self.folder_name = f"nfd-bicep-{Path(str(self.arm_template_path)).stem}" + + self._bicep_path = os.path.join(self.folder_name, self.bicep_template_name) + + def generate_nfd(self) -> None: + """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. + """ + #assert isinstance(self.config, VNFConfiguration) + if self.bicep_path: + logger.info("Using the existing NFD bicep template %s.", self.bicep_path) + logger.info( + 'To generate a new NFD, delete the folder "%s" and re-run this command.', + os.path.dirname(self.bicep_path), + ) + else: + self.write() + + def construct_parameters(self) -> Dict[str, Any]: + """ + Create the parmeters dictionary for nfdefinitions.bicep. + + :param config: The contents of the configuration file. + """ + #assert isinstance(self.config, VNFConfiguration) + return { + "publisherName": {"value": self.config.publisher_name}, + "acrArtifactStoreName": {"value": f"{self.config.publisher_name}-artifact-store"}, + "saArtifactStoreName": {"value": f"{self.config.publisher_name}-storage-account"}, + "nfName": {"value": self.config.name}, + "nfDefinitionGroup": {"value": f"{self.config.name}-nfdg"}, + "nfDefinitionVersion": {"value": self.config.version}, + "vhdName": {"value": self.config.vhd["artifact_name"]}, + "vhdVersion": {"value": self.config.vhd["version"]}, + "armTemplateName": {"value": self.config.arm_template["artifact_name"]}, + "armTemplateVersion": {"value": self.config.arm_template["version"]}, + } + + def write(self) -> None: + """ + Create a bicep template for an NFD from the ARM template for the VNF. + + :param arm_template_path: The path to the ARM template for deploying the VNF. + :param nf_name: The name of the NF. + + :return: Path to the bicep file. + """ + logger.info("Generate NFD bicep template for %s", self.arm_template_path) + + self._create_nfd_folder() + self.create_parameter_files() + self.copy_bicep() + + @property + def bicep_path(self) -> Optional[str]: + """Returns the path to the bicep file for the NFD if it has been created.""" + if os.path.exists(self._bicep_path): + return self._bicep_path + + return None + + def _create_nfd_folder(self) -> None: + """ + Create the folder for the NFD bicep files. + + :raises RuntimeError: If the user aborts. + """ + if os.path.exists(self.folder_name): + carry_on = input( + f"The folder {self.folder_name} already exists - delete it and continue? (y/n)" + ) + if carry_on != "y": + raise RuntimeError("User aborted!") + + shutil.rmtree(self.folder_name) + + logger.info("Create NFD bicep %s", self.folder_name) + os.mkdir(self.folder_name) + + @cached_property + def vm_parameters(self) -> Dict[str, Any]: + """The parameters from the VM ARM template.""" + with open(self.arm_template_path, "r") as _file: + parameters: Dict[str, Any] = json.load(_file)["parameters"] + + return parameters + + def create_parameter_files(self) -> None: + """Create the Deployment and Template json parameter files.""" + schemas_folder_path = os.path.join(self.folder_name, "schemas") + os.mkdir(schemas_folder_path) + self.write_deployment_parameters(schemas_folder_path) + + mappings_folder_path = os.path.join(self.folder_name, "configMappings") + os.mkdir(mappings_folder_path) + self.write_template_parameters(mappings_folder_path) + self.write_vhd_parameters(mappings_folder_path) + + def write_deployment_parameters(self, folder_path: str) -> None: + """ + Write out the NFD deploymentParameters.json file. + + :param folder_path: The folder to put this file in. + """ + logger.debug("Create deploymentParameters.json") + + nfd_parameters: Dict[str, Any] = { + key: {"type": self.vm_parameters[key]["type"]} for key in self.vm_parameters + } + + deployment_parameters_path = os.path.join( + folder_path, "deploymentParameters.json" + ) + + with open(deployment_parameters_path, "w") as _file: + _file.write(json.dumps(nfd_parameters, indent=4)) + + logger.debug("%s created", deployment_parameters_path) + + def write_template_parameters(self, folder_path: str) -> None: + """ + Write out the NFD templateParameters.json file. + + :param folder_path: The folder to put this file in. + """ + logger.debug("Create templateParameters.json") + template_parameters = { + key: f"{{deployParameters.{key}}}" for key in self.vm_parameters + } + + template_parameters_path = os.path.join(folder_path, "templateParameters.json") + + with open(template_parameters_path, "w") as _file: + _file.write(json.dumps(template_parameters, indent=4)) + + logger.debug("%s created", template_parameters_path) + + def write_vhd_parameters(self, folder_path: str) -> None: + """ + Write out the NFD vhdParameters.json file. + + :param folder_path: The folder to put this file in. + """ + vhd_parameters = { + "imageName": f"{self.config.name}Image", + "azureDeployLocation": "{deployParameters.location}", + } + + vhd_parameters_path = os.path.join(folder_path, "vhdParameters.json") + + with open(vhd_parameters_path, "w", encoding="utf-8") as _file: + _file.write(json.dumps(vhd_parameters, indent=4)) + + logger.debug("%s created", vhd_parameters_path) + + def copy_bicep(self) -> None: + """ + Copy the bicep template into place. + + :param folder_name: The name of the folder to copy the bicep template to. + + :returns: Path to the bicep file + """ + code_dir = os.path.dirname(__file__) + + bicep_path = os.path.join(code_dir, "templates", self.bicep_template_name) + + shutil.copy(bicep_path, self.folder_name) + + + + + diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py deleted file mode 100644 index 1363839e315..00000000000 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ /dev/null @@ -1,89 +0,0 @@ -# -------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT -# License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------- -"""Contains a class for generating VNF NFDs and associated resources.""" -from knack.log import get_logger - -from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator -from azext_aosm.vendored_sdks import HybridNetworkManagementClient -from azext_aosm.vendored_sdks.models import ( - NetworkFunctionDefinitionVersion, - NetworkFunctionDefinitionGroup, - ArtifactManifest, - ManifestArtifactFormat, - VersionState, - NetworkFunctionType, - NFVIType, - ArtifactType, - VirtualNetworkFunctionDefinitionVersion, # this is actually properties, badly named - AzureCoreNetworkFunctionTemplate, - AzureCoreNetworkFunctionVhdApplication, - AzureCoreNetworkFunctionArmTemplateApplication -) - -from azext_aosm._configuration import VNFConfiguration -from azext_aosm.publisher_resources.publisher_resources import PublisherResourceGenerator - - -logger = get_logger(__name__) - -class VnfNfdGenerator(NFDGenerator): - """_summary_ - - :param NFDGenerator: _description_ - :type NFDGenerator: _type_ - """ - def __init__( - self, - config: VNFConfiguration - ): - super(NFDGenerator, self).__init__( - config=config, - ) - - def generate_nfd(self) -> None: - """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. - """ - assert isinstance(self.config, VNFConfiguration) - arty_manny_sa = ArtifactManifest(location=self.config.location, - #tags={"blah": "blah"}, - artifacts=[ManifestArtifactFormat(artifact_name=self.config.vhd.artifact_name, - artifact_type=ArtifactType.VHD_IMAGE_FILE, - artifact_version=self.config.vhd.version)]) - - arty_manny_acr = ArtifactManifest(location=self.config.location, - #tags={"blah": "blah"}, - artifacts=[ManifestArtifactFormat(artifact_name=self.config.arm_template.artifact_name, - artifact_type=ArtifactType.ARM_TEMPLATE, - artifact_version=self.config.arm_template.version)]) - common_generator = PublisherResourceGenerator(config=self.config) - nfdg: NetworkFunctionDefinitionGroup = common_generator.generate_nfd_group() - - - def _generate_nfdv(self) -> NetworkFunctionDefinitionVersion: - """Generate an NFDV for a VNF - - :return: _description_ - :rtype: NetworkFunctionDefinitionVersion - """ - - vnf_props = VirtualNetworkFunctionDefinitionVersion( - version_state=VersionState.PREVIEW, - deploy_parameters= "TODO", - network_function_femplate=AzureCoreNetworkFunctionTemplate( - network_function_applications= [ - AzureCoreNetworkFunctionVhdApplication(), - AzureCoreNetworkFunctionArmTemplateApplication() - ] - )) - - nfdv = NetworkFunctionDefinitionVersion(location=self.config.location, - # Think kwargs map magically to properties in bicep, somehow - kwargs=vnf_props) - - return nfdv - - - - From 4fa8b8af5a32a26d640a6129ea8d53074aa88293 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 28 Apr 2023 17:11:52 +0100 Subject: [PATCH 010/145] VNF generate and deploy bare bones, not working --- src/aosm/azext_aosm/_configuration.py | 10 ++- src/aosm/azext_aosm/_constants.py | 4 + src/aosm/azext_aosm/commands.py | 2 +- src/aosm/azext_aosm/custom.py | 86 +++++++------------ src/aosm/azext_aosm/deploy/deploy_with_arm.py | 86 +++++++++++++------ src/aosm/azext_aosm/deploy/pre_deploy.py | 59 ++++++++++++- .../templates/vnfdefinition.bicep | 19 ++-- .../generate_nfd/vnf_bicep_nfd_generator.py | 57 ++++-------- .../publisher_resources.py | 11 ++- 9 files changed, 195 insertions(+), 139 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 40f88eed329..3602a3c1219 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -16,11 +16,15 @@ class ArtifactConfig: class Configuration(): publisher_name: str = "Name of the Publisher resource you want you definition published to" publisher_resource_group_name: str = "Resource group the Publisher resource is in or you want it to be in" - name: str = "Name of NF definition" + nf_name: str = "Name of NF definition" version: str = "Version of the NF definition" acr_artifact_store_name: str = "Name of the ACR Artifact Store resource" - location: str = "azure location of the resources" + location: str = "Azure location of the resources" + @property + def nfdg_name(self) -> str: + """Return the NFD Group name from the NFD name.""" + return f"{self.nf_name}-nfdg" @dataclass class VNFConfiguration(Configuration): @@ -32,7 +36,7 @@ class VNFConfiguration(Configuration): def get_configuration(definition_type, config_as_dict=None) -> Configuration: if config_as_dict is None: config_as_dict = {} - + # TODO - fix up the fact that ArtifactConfig remains as a Dict. if definition_type == VNF: config = VNFConfiguration(**config_as_dict) elif definition_type == CNF: diff --git a/src/aosm/azext_aosm/_constants.py b/src/aosm/azext_aosm/_constants.py index 2c0e1fd993e..aeeef0de14c 100644 --- a/src/aosm/azext_aosm/_constants.py +++ b/src/aosm/azext_aosm/_constants.py @@ -8,3 +8,7 @@ VNF = "vnf" CNF = "cnf" NSD = "nsd" + +# Names of files used in the repo +VNF_DEFINITION_BICEP_SOURCE_TEMPLATE = "vnfdefinition.bicep" +VNF_DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index f4546cac9b8..474d9d66b4f 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -20,7 +20,7 @@ def load_command_table(self: AzCommandsLoader, _): # Add each command and bind it to a function in custom.py g.custom_command('generate-config', 'generate_definition_config') g.custom_command('build', 'build_definition') - g.custom_command('publish', 'publish_definition') + #g.custom_command('publish', 'publish_definition') g.custom_command('show', 'show_publisher') with self.command_group('aosm', is_preview=True): diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index cd8ae5cd23d..e249bf7f889 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -17,63 +17,26 @@ from .vendored_sdks import HybridNetworkManagementClient from .vendored_sdks.models import Publisher, NetworkFunctionDefinitionVersion from ._client_factory import cf_resources -from ._configuration import Configuration, VNFConfiguration, get_configuration, validate_configuration +from ._configuration import ( + Configuration, + VNFConfiguration, + get_configuration, + validate_configuration, +) +from azext_aosm.deploy.deploy_with_arm import DeployerViaArm from ._constants import VNF, CNF, NSD + logger = get_logger(__name__) PUBLISHER_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers" ARTIFACT_STORE_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/artifactstores" -NFDG_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/networkfunctiondefinitiongroups" +NFDG_RESOURCE_TYPE = ( + "Microsoft.HybridNetwork/publishers/networkfunctiondefinitiongroups" +) NSDG_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/networkservicedesigngroups" -def _required_resources_exist( - cli_ctx, definition_type: str, config: Configuration -) -> bool: - resource_client = cf_resources(cli_ctx) - - if resource_client.check_existence( - config.publisher_resource_group_name, - PUBLISHER_RESOURCE_TYPE, - config.publisher_name, - ): - if not resource_client.check_existence( - config.publisher_resource_group_name, - "Microsoft.HybridNetwork/publishers/artifactstores", - config.acr_artifact_store_name, - ): - return False - if definition_type == VNF: - if not resource_client.check_existence( - config.publisher_resource_group_name, - NFDG_RESOURCE_TYPE, - config.name, - ): - return False - elif definition_type == NSD: - if not resource_client.check_existence( - config.publisher_resource_group_name, - NSDG_RESOURCE_TYPE, - config.name, - ): - return False - elif definition_type == CNF: - if not resource_client.check_existence( - config.publisher_resource_group_name, - NFDG_RESOURCE_TYPE, - config.name, - ): - return False - else: - raise AzCLIError( - "Invalid definition type. Valid values are vnf, nsd and cnf." - ) - else: - return False - -def _create_required_resources(definition_type, config): - pass def build_definition( cmd, @@ -84,7 +47,7 @@ def build_definition( ): with open(config_file, "r", encoding="utf-8") as f: config_as_dict = json.loads(f.read()) - + # TODO - this isn't deserializing the config properly - any sub-objects are left # as a dictionary instead of being converted to the object (e.g. ArtifactConfig) # se we have to reference them as dictionary values @@ -96,8 +59,13 @@ def build_definition( # Publish the definition if publish is true if publish: - if not _required_resources_exist(cmd.cli_ctx, definition_type, config): - _create_required_resources(definition_type, config) + if definition_type == VNF: + deployer = DeployerViaArm(aosm_client=client, + resource_client=cf_resources(cmd.cli_ctx), + config=config) + output = deployer.deploy_vnfd_from_bicep() + else: + print("TODO - cannot publish CNF or NSD yet.") def generate_definition_config(cmd, definition_type, output_file="input.json"): @@ -106,11 +74,16 @@ def generate_definition_config(cmd, definition_type, output_file="input.json"): with open(output_file, "w", encoding="utf-8") as f: f.write(config_as_dict) + print( + "Empty definition configuration has been written to %s", + output_file, + ) logger.info( "Empty definition configuration has been written to %s", output_file, ) - + + def _generate_nfd(definition_type, config): """_summary_ @@ -124,12 +97,13 @@ def _generate_nfd(definition_type, config): nfd_generator = CnfNfdGenerator(config) else: from azure.cli.core.azclierror import CLIInternalError + raise CLIInternalError( - "Generate NFD called for unrecognised definition_type. Only VNF and CNF have been implemented." - ) - + "Generate NFD called for unrecognised definition_type. Only VNF and CNF have been implemented." + ) + nfd_generator.generate_nfd() -def publish_nfd + def show_publisher(): pass diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index cedfe6d1991..e227a93de39 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -12,19 +12,14 @@ from typing import Any, Dict from knack.log import get_logger -from azure.identity import DefaultAzureCredential from azure.mgmt.resource import ResourceManagementClient from azure.mgmt.resource.resources.v2021_04_01.models import DeploymentExtended +from pathlib import Path from azext_aosm.vendored_sdks import HybridNetworkManagementClient -from azext_aosm.vendored_sdks.models import ( - NetworkFunctionDefinitionVersion, - NetworkServiceDesignVersion, - ArtifactStoreType, - ArtifactType, - ArtifactManifest, -) from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK +from azext_aosm._configuration import Configuration, VNFConfiguration +from azext_aosm._constants import VNF_DEFINITION_OUTPUT_BICEP_PREFIX, VNF_DEFINITION_BICEP_SOURCE_TEMPLATE logger = get_logger(__name__) @@ -32,15 +27,14 @@ class DeployerViaArm: """A class to deploy Artifact Manifests, NFDs and NSDs from a bicep template using ARM.""" + # @@@TODO - not sure this class is required as we can't publish complex objects # using the SDK - def __init__( self, aosm_client: HybridNetworkManagementClient, resource_client: ResourceManagementClient, - subscription_id: str, - resource_group: str + config: Configuration, ) -> None: """ Initializes a new instance of the Deployer class. @@ -52,21 +46,66 @@ def __init__( """ logger.debug("Create ARM/Bicep Deployer") self.aosm_client = aosm_client + self.resource_client = resource_client + self.config = config + self.pre_deployer = PreDeployerViaSDK( + aosm_client, self.resource_client, self.config + ) + + def deploy_vnfd_from_bicep(self) -> Any: + """Deploy the bicep template defining the VNFD. + + Also ensure that all required predeploy resources are deployed. - self.subscription_id = subscription_id - self.credentials = DefaultAzureCredential() - self.resource_group = resource_group - self.pre_deployer = PreDeployerViaSDK(aosm_client, self.resource_client) + :param bicep_template_path: The path to the bicep template of the + :type bicep_template_path: str + """ + assert isinstance(self.config, VNFConfiguration) + + # TODO - duplicated from vnf_bicep_nfd_generator and won't work if file exists + arm_template_path = self.config.arm_template["file_path"] + folder_name = f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" + bicep_template_name = VNF_DEFINITION_BICEP_SOURCE_TEMPLATE + bicep_path = os.path.join(folder_name, bicep_template_name) - @cached_property - def resource_client(self) -> ResourceManagementClient: + parameters = self.construct_vnfd_parameters() + # Create or check required resources + self.vnfd_predeploy() + output = self.deploy_bicep_template(bicep_path, parameters) + + return output + + def vnfd_predeploy(self): + """ + All the predeploy steps for a VNF. Create publisher, artifact stores and NFDG. + + VNF specific """ - Create a client that can create resources on Azure. + logger.debug("Ensure all required resources exist") + self.pre_deployer.ensure_config_publisher_exists() + self.pre_deployer.ensure_acr_artifact_store_exists() + self.pre_deployer.ensure_sa_artifact_store_exists() + self.pre_deployer.ensure_config_nfdg_exists() - :return: A ResourceManagementClient + def construct_vnfd_parameters(self) -> Dict[str, Any]: """ - logger.debug("Create resource client") - return ResourceManagementClient(self.credentials, self.subscription_id) + Create the parmeters dictionary for vnfdefinitions.bicep. VNF specific. + + :param config: The contents of the configuration file. + """ + assert isinstance(self.config, VNFConfiguration) + return { + "publisherName": {"value": self.config.publisher_name}, + "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, + "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, + "nfName": {"value": self.config.nf_name}, + "nfDefinitionGroup": {"value": self.config.nfdg_name}, + "nfDefinitionVersion": {"value": self.config.version}, + "vhdName": {"value": self.config.vhd["artifact_name"]}, + "vhdVersion": {"value": self.config.vhd["version"]}, + "armTemplateName": {"value": self.config.arm_template["artifact_name"]}, + "armTemplateVersion": {"value": self.config.arm_template["version"]}, + } def deploy_bicep_template( self, bicep_template_path: str, parameters: Dict[Any, Any] @@ -81,7 +120,7 @@ def deploy_bicep_template( arm_template_json = self.convert_bicep_to_arm(bicep_template_path) return self.validate_and_deploy_arm_template( - arm_template_json, parameters, self.resource_group + arm_template_json, parameters, self.config.publisher_resource_group_name ) def resource_exists(self, resource_name: str) -> bool: @@ -92,7 +131,7 @@ def resource_exists(self, resource_name: str) -> bool: """ logger.debug("Check if %s exists", resource_name) resources = self.resource_client.resources.list_by_resource_group( - resource_group_name=self.resource_group + resource_group_name=self.config.publisher_resource_group_name ) resource_exists = False @@ -241,4 +280,3 @@ def convert_bicep_to_arm(self, bicep_template: str) -> Any: os.remove(arm_template_name) return arm_json - diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index d99658af491..54e09de3ac1 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -6,6 +6,7 @@ from knack.log import get_logger from azure.mgmt.resource import ResourceManagementClient +from azure.cli.core.azclierror import AzCLIError from azext_aosm.vendored_sdks import HybridNetworkManagementClient from azext_aosm.vendored_sdks.models import ( @@ -15,6 +16,7 @@ NetworkServiceDesignGroup, Publisher, ) +from azext_aosm._configuration import Configuration, VNFConfiguration logger = get_logger(__name__) @@ -26,6 +28,7 @@ def __init__( self, aosm_client: HybridNetworkManagementClient, resource_client: ResourceManagementClient, + config: Configuration, ) -> None: """ Initializes a new instance of the Deployer class. @@ -38,6 +41,7 @@ def __init__( self.aosm_client = aosm_client self.resource_client = resource_client + self.config = config def ensure_publisher_exists( self, resource_group_name: str, publisher_name: str, location: str @@ -56,7 +60,7 @@ def ensure_publisher_exists( logger.info( "Creating publisher %s if it does not exist", publisher_name ) - if not self.resource_client.resources.check_existance( + if not self.resource_client.check_existence( resource_group_name=resource_group_name, resource_type="Microsoft.HybridNetwork/publishers", resource_name=publisher_name, @@ -66,6 +70,16 @@ def ensure_publisher_exists( publisher_name=publisher_name, parameters=Publisher(location=location, scope="Public"), ) + + def ensure_config_publisher_exists(self) -> None: + """ + Ensures that the publisher exists in the resource group. + + Finds the parameters from self.config + """ + self.ensure_publisher_exists(self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.location) def ensure_artifact_store_exists( self, @@ -103,6 +117,36 @@ def ensure_artifact_store_exists( artifact_store_type=artifact_store_type, ), ) + + def ensure_acr_artifact_store_exists(self) -> None: + """ + Ensures that the ACR Artifact store exists. + + Finds the parameters from self.config + """ + self.ensure_artifact_store_exists(self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.acr_artifact_store_name, + ArtifactStoreType.AZURE_CONTAINER_REGISTRY, + self.config.location) + + + def ensure_sa_artifact_store_exists(self) -> None: + """ + Ensures that the Storage Account Artifact store for VNF exists. + + Finds the parameters from self.config + """ + if not isinstance(self.config, VNFConfiguration): + raise AzCLIError( + "Check that storage account artifact store exists failed as requires VNFConfiguration file" + ) + + self.ensure_artifact_store_exists(self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.blob_artifact_store_name, + ArtifactStoreType.AZURE_STORAGE_ACCOUNT, + self.config.location) def ensure_nfdg_exists( self, @@ -134,6 +178,19 @@ def ensure_nfdg_exists( network_function_definition_group_name=nfdg_name, parameters=NetworkFunctionDefinitionGroup(location=location), ) + + def ensure_config_nfdg_exists( + self, + ): + """ + Ensures that the Network Function Definition Group exists. + + Finds the parameters from self.config + """ + self.ensure_nfdg_exists(self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.nfdg_name, + self.config.location) def ensure_nsdg_exists( self, diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep index 5a87f8b511b..6f200f43f6b 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep @@ -23,33 +23,28 @@ param armTemplateName string @description('The version that you want to name the NFM template artifact, in format A.B.C. e.g. 6.13.0. If testing for development, you can use any numbers you like.') param armTemplateVersion string +// Created by the az aosm definition publish command before the template is deployed resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { name: publisherName scope: resourceGroup() } -resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' = { +// Created by the az aosm definition publish command before the template is deployed +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { parent: publisher name: acrArtifactStoreName - location: location - properties: { - storeType: 'AzureContainerRegistry' - } } -resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' = { +// Created by the az aosm definition publish command before the template is deployed +resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { parent: publisher name: saArtifactStoreName - location: location - properties: { - storeType: 'AzureStorageAccount' - } } -resource nfdg 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups@2022-09-01-preview' = { +// Created by the az aosm definition publish command before the template is deployed +resource nfdg 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups@2022-09-01-preview' existing = { parent: publisher name: nfDefinitionGroup - location: location } resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 2520bbf0cc8..87c5209e59b 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -15,36 +15,40 @@ from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm._configuration import VNFConfiguration -from azext_aosm.publisher_resources.publisher_resources import PublisherResourceGenerator +from azext_aosm.publisher_resources.publisher_resources import ( + PublisherResourceGenerator, +) +from azext_aosm._constants import ( + VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, + VNF_DEFINITION_OUTPUT_BICEP_PREFIX, +) logger = get_logger(__name__) + class VnfBicepNfdGenerator(NFDGenerator): """_summary_ :param NFDGenerator: _description_ :type NFDGenerator: _type_ """ - def __init__( - self, - config: VNFConfiguration - ): + + def __init__(self, config: VNFConfiguration): super(NFDGenerator, self).__init__( - #config=config, + # config=config, ) self.config = config - self.bicep_template_name = "vnfdefinition.bicep" + self.bicep_template_name = VNF_DEFINITION_BICEP_SOURCE_TEMPLATE self.arm_template_path = self.config.arm_template["file_path"] - self.folder_name = f"nfd-bicep-{Path(str(self.arm_template_path)).stem}" + self.folder_name = f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(self.arm_template_path)).stem}" self._bicep_path = os.path.join(self.folder_name, self.bicep_template_name) - + def generate_nfd(self) -> None: - """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. - """ - #assert isinstance(self.config, VNFConfiguration) + """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" + # assert isinstance(self.config, VNFConfiguration) if self.bicep_path: logger.info("Using the existing NFD bicep template %s.", self.bicep_path) logger.info( @@ -53,27 +57,7 @@ def generate_nfd(self) -> None: ) else: self.write() - - def construct_parameters(self) -> Dict[str, Any]: - """ - Create the parmeters dictionary for nfdefinitions.bicep. - :param config: The contents of the configuration file. - """ - #assert isinstance(self.config, VNFConfiguration) - return { - "publisherName": {"value": self.config.publisher_name}, - "acrArtifactStoreName": {"value": f"{self.config.publisher_name}-artifact-store"}, - "saArtifactStoreName": {"value": f"{self.config.publisher_name}-storage-account"}, - "nfName": {"value": self.config.name}, - "nfDefinitionGroup": {"value": f"{self.config.name}-nfdg"}, - "nfDefinitionVersion": {"value": self.config.version}, - "vhdName": {"value": self.config.vhd["artifact_name"]}, - "vhdVersion": {"value": self.config.vhd["version"]}, - "armTemplateName": {"value": self.config.arm_template["artifact_name"]}, - "armTemplateVersion": {"value": self.config.arm_template["version"]}, - } - def write(self) -> None: """ Create a bicep template for an NFD from the ARM template for the VNF. @@ -84,10 +68,12 @@ def write(self) -> None: :return: Path to the bicep file. """ logger.info("Generate NFD bicep template for %s", self.arm_template_path) + print(f"Generate NFD bicep template for {self.arm_template_path}") self._create_nfd_folder() self.create_parameter_files() self.copy_bicep() + print(f"Generated NFD bicep template created in {self.folder_name}") @property def bicep_path(self) -> Optional[str]: @@ -180,7 +166,7 @@ def write_vhd_parameters(self, folder_path: str) -> None: :param folder_path: The folder to put this file in. """ vhd_parameters = { - "imageName": f"{self.config.name}Image", + "imageName": f"{self.config.nf_name}Image", "azureDeployLocation": "{deployParameters.location}", } @@ -204,8 +190,3 @@ def copy_bicep(self) -> None: bicep_path = os.path.join(code_dir, "templates", self.bicep_template_name) shutil.copy(bicep_path, self.folder_name) - - - - - diff --git a/src/aosm/azext_aosm/publisher_resources/publisher_resources.py b/src/aosm/azext_aosm/publisher_resources/publisher_resources.py index 201ad439c91..2bde15ca9aa 100644 --- a/src/aosm/azext_aosm/publisher_resources/publisher_resources.py +++ b/src/aosm/azext_aosm/publisher_resources/publisher_resources.py @@ -11,17 +11,20 @@ logger = get_logger(__name__) + @dataclass class PublisherResourceGenerator: """Class for generating publisher resources used by various other classes.""" + config: Configuration - + def generate_nfd_group(self) -> NetworkFunctionDefinitionGroup: """Generate a NFD group with location and description from config. :return: _description_ :rtype: NetworkFunctionDefinitionGroup """ - return NetworkFunctionDefinitionGroup(location=self.config.location, - description=f"NFD Group for versions of NFDs for {self.config.name}") - + return NetworkFunctionDefinitionGroup( + location=self.config.location, + description=f"NFD Group for versions of NFDs for {self.config.nf_name}", + ) From 4ea921a50354fa5e4f903ac38ba76877a5f68857 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Tue, 2 May 2023 16:58:24 +0100 Subject: [PATCH 011/145] predeployer maybe working --- src/aosm/azext_aosm/_client_factory.py | 2 +- src/aosm/azext_aosm/_constants.py | 2 + src/aosm/azext_aosm/custom.py | 9 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 17 ++- src/aosm/azext_aosm/deploy/pre_deploy.py | 79 +++++++--- .../azext_aosm/util/management_clients.py | 140 ++++++++++++++++++ 6 files changed, 215 insertions(+), 34 deletions(-) create mode 100644 src/aosm/azext_aosm/util/management_clients.py diff --git a/src/aosm/azext_aosm/_client_factory.py b/src/aosm/azext_aosm/_client_factory.py index 084e448b769..dd7d5cdf2de 100644 --- a/src/aosm/azext_aosm/_client_factory.py +++ b/src/aosm/azext_aosm/_client_factory.py @@ -13,4 +13,4 @@ def cf_aosm(cli_ctx, *_) -> HybridNetworkManagementClient: def cf_resources(cli_ctx, subscription_id=None): return get_mgmt_service_client( cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id - ).resources + ) diff --git a/src/aosm/azext_aosm/_constants.py b/src/aosm/azext_aosm/_constants.py index aeeef0de14c..44428add0f5 100644 --- a/src/aosm/azext_aosm/_constants.py +++ b/src/aosm/azext_aosm/_constants.py @@ -4,6 +4,8 @@ # -------------------------------------------------------------------------------------------- """Constants used across aosm cli extension.""" +AOSM_API_VERSION="2022-09-01-preview" + # The types of definition that can be generated VNF = "vnf" CNF = "cnf" diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index e249bf7f889..d082e6c9874 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -24,7 +24,8 @@ validate_configuration, ) from azext_aosm.deploy.deploy_with_arm import DeployerViaArm -from ._constants import VNF, CNF, NSD +from azext_aosm._constants import VNF, CNF, NSD +from azext_aosm.util.management_clients import ApiClientsAndCaches @@ -48,6 +49,9 @@ def build_definition( with open(config_file, "r", encoding="utf-8") as f: config_as_dict = json.loads(f.read()) + apiClientsAndCaches = ApiClientsAndCaches(aosm_client=client, + resource_client=cf_resources(cmd.cli_ctx)) + # TODO - this isn't deserializing the config properly - any sub-objects are left # as a dictionary instead of being converted to the object (e.g. ArtifactConfig) # se we have to reference them as dictionary values @@ -60,8 +64,7 @@ def build_definition( # Publish the definition if publish is true if publish: if definition_type == VNF: - deployer = DeployerViaArm(aosm_client=client, - resource_client=cf_resources(cmd.cli_ctx), + deployer = DeployerViaArm(apiClientsAndCaches, config=config) output = deployer.deploy_vnfd_from_bicep() else: diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index e227a93de39..50de009c41a 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -13,6 +13,7 @@ from knack.log import get_logger from azure.mgmt.resource import ResourceManagementClient +from azext_aosm.util.management_clients import ApiClientsAndCaches from azure.mgmt.resource.resources.v2021_04_01.models import DeploymentExtended from pathlib import Path @@ -32,8 +33,7 @@ class DeployerViaArm: # using the SDK def __init__( self, - aosm_client: HybridNetworkManagementClient, - resource_client: ResourceManagementClient, + apiClientsAndCaches: ApiClientsAndCaches, config: Configuration, ) -> None: """ @@ -45,11 +45,10 @@ def __init__( :type resource_client: ResourceManagementClient """ logger.debug("Create ARM/Bicep Deployer") - self.aosm_client = aosm_client - self.resource_client = resource_client + self.api_clients = apiClientsAndCaches self.config = config self.pre_deployer = PreDeployerViaSDK( - aosm_client, self.resource_client, self.config + apiClientsAndCaches, self.config ) def deploy_vnfd_from_bicep(self) -> Any: @@ -69,6 +68,7 @@ def deploy_vnfd_from_bicep(self) -> Any: bicep_path = os.path.join(folder_name, bicep_template_name) parameters = self.construct_vnfd_parameters() + print(parameters) # Create or check required resources self.vnfd_predeploy() output = self.deploy_bicep_template(bicep_path, parameters) @@ -82,6 +82,7 @@ def vnfd_predeploy(self): VNF specific """ logger.debug("Ensure all required resources exist") + self.pre_deployer.ensure_config_resource_group_exists() self.pre_deployer.ensure_config_publisher_exists() self.pre_deployer.ensure_acr_artifact_store_exists() self.pre_deployer.ensure_sa_artifact_store_exists() @@ -130,7 +131,7 @@ def resource_exists(self, resource_name: str) -> bool: :param resource_name: The name of the resource to check. """ logger.debug("Check if %s exists", resource_name) - resources = self.resource_client.resources.list_by_resource_group( + resources = self.api_clients.resource_client.resources.list_by_resource_group( resource_group_name=self.config.publisher_resource_group_name ) @@ -160,7 +161,7 @@ def validate_and_deploy_arm_template( """ deployment_name = f"nfd_into_{resource_group}" - validation = self.resource_client.deployments.begin_validate( + validation = self.api_clients.resource_client.deployments.begin_validate( resource_group_name=resource_group, deployment_name=deployment_name, parameters={ @@ -190,7 +191,7 @@ def validate_and_deploy_arm_template( # Validation succeeded so proceed with deployment logger.debug(f"Successfully validated resources for {resource_group}") - poller = self.resource_client.deployments.begin_create_or_update( + poller = self.api_clients.resource_client.deployments.begin_create_or_update( resource_group_name=resource_group, deployment_name=deployment_name, parameters={ diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 54e09de3ac1..ba6df2085df 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -5,9 +5,15 @@ """Contains class for deploying resources required by NFDs/NSDs via the SDK.""" from knack.log import get_logger -from azure.mgmt.resource import ResourceManagementClient + +from azure.core import exceptions as azure_exceptions from azure.cli.core.azclierror import AzCLIError +from azure.mgmt.resource.resources.v2022_09_01.models import ( + ResourceGroup +) +from azure.mgmt.resource import ResourceManagementClient +from azext_aosm.util.management_clients import ApiClientsAndCaches from azext_aosm.vendored_sdks import HybridNetworkManagementClient from azext_aosm.vendored_sdks.models import ( ArtifactStore, @@ -17,6 +23,7 @@ Publisher, ) from azext_aosm._configuration import Configuration, VNFConfiguration +from azext_aosm._constants import AOSM_API_VERSION logger = get_logger(__name__) @@ -26,8 +33,7 @@ class PreDeployerViaSDK: def __init__( self, - aosm_client: HybridNetworkManagementClient, - resource_client: ResourceManagementClient, + apiClientsAndCaches: ApiClientsAndCaches, config: Configuration, ) -> None: """ @@ -39,9 +45,37 @@ def __init__( :type resource_client: ResourceManagementClient """ - self.aosm_client = aosm_client - self.resource_client = resource_client + self.api_clients = apiClientsAndCaches self.config = config + + def ensure_resource_group_exists(self, resource_group_name: str)-> None: + """ + Checks whether a particular resource group exists on the subscription. + Copied from virtutils + + :param resource_group_name: The name of the resource group + + Raises a NotFoundError exception if the resource group does not exist. + Raises a PermissionsError exception if we don't have permissions to check resource group existence. + """ + rg: ResourceGroup + if not self.api_clients.resource_client.resource_groups.check_existence(resource_group_name): + logger.info(f"RG {resource_group_name} not found. Create it.") + print(f"Creating resource group {resource_group_name}.") + rg_params: ResourceGroup = ResourceGroup(location=self.config.location) + rg = self.api_clients.resource_client.resource_groups.create_or_update(resource_group_name, rg_params) + else: + print(f"Resource group {resource_group_name} exists.") + rg = self.api_clients.resource_client.resource_groups.get(resource_group_name) + + def ensure_config_resource_group_exists(self) -> None: + """ + Ensures that the publisher exists in the resource group. + + Finds the parameters from self.config + """ + self.ensure_resource_group_exists(self.config.publisher_resource_group_name) + def ensure_publisher_exists( self, resource_group_name: str, publisher_name: str, location: str @@ -56,20 +90,21 @@ def ensure_publisher_exists( :param location: The location of the publisher. :type location: str """ - logger.info( "Creating publisher %s if it does not exist", publisher_name ) - if not self.resource_client.check_existence( - resource_group_name=resource_group_name, - resource_type="Microsoft.HybridNetwork/publishers", - resource_name=publisher_name, - ): - self.aosm_client.publishers.begin_create_or_update( + try: + pubby = self.api_clients.aosm_client.publishers.get(resource_group_name, publisher_name) + print(f"Publisher {pubby.name} exists in resource group {resource_group_name}") + except azure_exceptions.ResourceNotFoundError: + # Create the publisher + print(f"Creating publisher {publisher_name} in resource group {resource_group_name}") + self.api_clients.aosm_client.publishers.begin_create_or_update( resource_group_name=resource_group_name, publisher_name=publisher_name, - parameters=Publisher(location=location, scope="Public"), + parameters=Publisher(location=location, scope="Private"), ) + def ensure_config_publisher_exists(self) -> None: """ @@ -77,9 +112,9 @@ def ensure_config_publisher_exists(self) -> None: Finds the parameters from self.config """ - self.ensure_publisher_exists(self.config.publisher_resource_group_name, - self.config.publisher_name, - self.config.location) + self.ensure_publisher_exists(resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + location=self.config.location) def ensure_artifact_store_exists( self, @@ -103,21 +138,21 @@ def ensure_artifact_store_exists( :param location: The location of the artifact store. :type location: str """ - logger.info( "Creating artifact store %s if it does not exist", artifact_store_name, ) - self.aosm_client.artifact_stores.begin_create_or_update( + + self.api_clients.aosm_client.artifact_stores.begin_create_or_update( resource_group_name=resource_group_name, publisher_name=publisher_name, artifact_store_name=artifact_store_name, parameters=ArtifactStore( location=location, - artifact_store_type=artifact_store_type, + store_type=artifact_store_type, ), ) - + def ensure_acr_artifact_store_exists(self) -> None: """ Ensures that the ACR Artifact store exists. @@ -172,7 +207,7 @@ def ensure_nfdg_exists( "Creating network function definition group %s if it does not exist", nfdg_name, ) - self.aosm_client.network_function_definition_groups.begin_create_or_update( + self.api_clients.aosm_client.network_function_definition_groups.begin_create_or_update( resource_group_name=resource_group_name, publisher_name=publisher_name, network_function_definition_group_name=nfdg_name, @@ -216,7 +251,7 @@ def ensure_nsdg_exists( "Creating network service design group %s if it does not exist", nsdg_name, ) - self.aosm_client.network_service_design_groups.begin_create_or_update( + self.api_clients.aosm_client.network_service_design_groups.begin_create_or_update( resource_group_name=resource_group_name, publisher_name=publisher_name, network_service_design_group_name=nsdg_name, diff --git a/src/aosm/azext_aosm/util/management_clients.py b/src/aosm/azext_aosm/util/management_clients.py new file mode 100644 index 00000000000..05cf0f7e794 --- /dev/null +++ b/src/aosm/azext_aosm/util/management_clients.py @@ -0,0 +1,140 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +"""Clients for the python SDK along with useful caches.""" + +from knack.log import get_logger +from dataclasses import dataclass +from azure.mgmt.resource import ResourceManagementClient +from azext_aosm.vendored_sdks import HybridNetworkManagementClient +from typing import Dict, Optional +from azure.mgmt.resource.resources.v2022_09_01.models import ( + Provider +) + +logger = get_logger(__name__) + +@dataclass +class ProviderInfo: + namespace: str + resource_type: str + + +class ApiClientsAndCaches: + """A cache for API Clients and API versions for various resources. + """ + + def __init__(self, aosm_client: HybridNetworkManagementClient, resource_client: ResourceManagementClient): + self.aosm_client = aosm_client + self.resource_client = resource_client + + # We need to find an Azure API version relevant to each resource type. This is + # used in resource finding. We just use the latest and cache these as they are + # expensive to query. + self.resource_type_api_versions_cache: Dict[str, str] = {} + self.providers_cache: Dict[str, Provider] = {} + + def find_latest_api_ver_for_resource_type( + self, resource_type: str + ) -> Optional[str]: + """ + Copied from virtutils. Turns out maybe not needed yet. Expect we will need + when we want to delete resources. + + Find the latest Azure API version for a given resource. + + We do this querying the Azure Providers API + + We just use the latest and cache these as they are expensive to query. + + param: resource_type: String in the format that the providers API uses e.g. + Microsoft.Compute/disks or Microsoft.Compute/virtualMachines/extensions + + Find the namespace and resource type in the format that the providers + API uses by splitting the resource type returned from list_by_resource_group + at the first forward-slash (/), + e.g. Microsoft.Compute/disks would give us namespace Microsoft.Compute and + provider resource type disks + whereas Microsoft.Compute/virtualMachines/extensions would give us + namespace Microsoft.Compute and provicer resource type + virtualMachines/extensions. This seems to match what the provider API + uses. + + We cache values as this can take a few seconds to return. + + :param resource: A resource, as returned from list_by_resource_group + :raises RuntimeError: If no provider found in Azure for this resource + :raises RuntimeError: If the resource type is an unexpected format + """ + logger.debug(f"Find API version for {resource_type}") + # We need to find an API version relevant to the resource. + if resource_type in self.resource_type_api_versions_cache.keys(): + # We have one cached, just return that + logger.debug("Return cached API version") + return self.resource_type_api_versions_cache.get(resource_type) + + # Start with e.g. Microsoft.Compute/disks (resource_type) + assert resource_type is not None + prov_info = self.get_provider_info(resource_type) + # We now have Microsoft.Compute and disks + if prov_info.namespace not in self.providers_cache.keys(): + # Get the provider e.g. Microsoft.Compute + logger.debug(f"Find provider {prov_info.namespace}") + try: + provider = self.resource_client.providers.get(prov_info.namespace) + except Exception as provEx: + raise RuntimeError( + f"Could not find provider {prov_info.namespace} required " + f"to query resource of type {resource_type}. Aborting" + ) from provEx + + self.providers_cache[prov_info.namespace] = provider + else: + # Resource type that we haven't found before but the provider is cached + # so use that. + provider = self.providers_cache[prov_info.namespace] + + # Iterate through the providers resource types and find the one + # we want, e.g. disks or virtualMachines/extensions + for res_type in provider.resource_types: + if res_type.resource_type == prov_info.resource_type: + # Find the latest API version and cache it + # The first index appears to always be the latest version + api_version = res_type.api_versions[0] + logger.debug(f"Use API version {api_version} for {resource_type}") + + assert resource_type is not None + self.resource_type_api_versions_cache[resource_type] = api_version + return api_version + + raise RuntimeError( + f"Azure API did not return an API version for {resource_type}." + f"Cannot query API version" + ) + + def get_provider_info(self, resource_type: str) -> ProviderInfo: + """ + Find provider namespace and resource_type, given a full resource_type. + + param: resource_type: String in the format that the providers API uses e.g. + Microsoft.Compute/disks or Microsoft.Compute/virtualMachines/extensions + + Find the namespace and resource type in the format that the providers + API uses by splitting the resource type returned from list_by_resource_group + at the first forward-slash (/), + e.g. Microsoft.Compute/disks would give us namespace Microsoft.Compute and + provider resource type disks + whereas Microsoft.Compute/virtualMachines/extensions would give us + namespace Microsoft.Compute and provicer resource type + virtualMachines/extensions. This seems to match what the provider API + uses. + """ + prov_namespace_type = resource_type.split("/", 1) + if len(prov_namespace_type) != 2: + raise RuntimeError( + f"Azure resource type {resource_type} " + "is in unexpected format. Cannot find API version." + ) + #print(f"Namespace {prov_namespace_type[0]} type {prov_namespace_type[1]}") + return ProviderInfo(prov_namespace_type[0], prov_namespace_type[1]) From 27a259751f24c549dc26a835394cb88129681427 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Tue, 2 May 2023 18:14:55 +0100 Subject: [PATCH 012/145] Fix up VNF generate and deploy --- src/aosm/azext_aosm/_constants.py | 3 + src/aosm/azext_aosm/deploy/pre_deploy.py | 69 +++++++++++++++---- .../generate_nfd/vnf_bicep_nfd_generator.py | 28 ++++++-- 3 files changed, 81 insertions(+), 19 deletions(-) diff --git a/src/aosm/azext_aosm/_constants.py b/src/aosm/azext_aosm/_constants.py index 44428add0f5..daea47a7c9c 100644 --- a/src/aosm/azext_aosm/_constants.py +++ b/src/aosm/azext_aosm/_constants.py @@ -14,3 +14,6 @@ # Names of files used in the repo VNF_DEFINITION_BICEP_SOURCE_TEMPLATE = "vnfdefinition.bicep" VNF_DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" + +# Provisioning States +PROV_STATE_SUCCEEDED = "Succeeded" diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index ba6df2085df..3cbe97c7494 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -23,7 +23,7 @@ Publisher, ) from azext_aosm._configuration import Configuration, VNFConfiguration -from azext_aosm._constants import AOSM_API_VERSION +from azext_aosm._constants import PROV_STATE_SUCCEEDED logger = get_logger(__name__) @@ -99,11 +99,12 @@ def ensure_publisher_exists( except azure_exceptions.ResourceNotFoundError: # Create the publisher print(f"Creating publisher {publisher_name} in resource group {resource_group_name}") - self.api_clients.aosm_client.publishers.begin_create_or_update( + pub = self.api_clients.aosm_client.publishers.begin_create_or_update( resource_group_name=resource_group_name, publisher_name=publisher_name, parameters=Publisher(location=location, scope="Private"), ) + pub.result() def ensure_config_publisher_exists(self) -> None: @@ -142,16 +143,37 @@ def ensure_artifact_store_exists( "Creating artifact store %s if it does not exist", artifact_store_name, ) + try: + self.api_clients.aosm_client.artifact_stores.get(resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name) + print(f"Artifact store {artifact_store_name} exists in resource group {resource_group_name}") + except azure_exceptions.ResourceNotFoundError: + print(f"Create Artifact Store {artifact_store_name} of type {artifact_store_type}") + poller = self.api_clients.aosm_client.artifact_stores.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + parameters=ArtifactStore( + location=location, + store_type=artifact_store_type, + ), + ) + # Asking for result waits for provisioning state Succeeded before carrying + # on + arty: ArtifactStore = poller.result() - self.api_clients.aosm_client.artifact_stores.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - artifact_store_name=artifact_store_name, - parameters=ArtifactStore( - location=location, - store_type=artifact_store_type, - ), - ) + if arty.provisioning_state != PROV_STATE_SUCCEEDED: + logger.debug(f"Failed to provision artifact store: {arty.name}") + raise RuntimeError( + f"Creation of artifact store proceeded, but the provisioning" + f" state returned is {arty.provisioning_state}. " + f"\nAborting" + ) + logger.debug( + f"Provisioning state of {artifact_store_name}" + f": {arty.provisioning_state}" + ) def ensure_acr_artifact_store_exists(self) -> None: """ @@ -164,8 +186,8 @@ def ensure_acr_artifact_store_exists(self) -> None: self.config.acr_artifact_store_name, ArtifactStoreType.AZURE_CONTAINER_REGISTRY, self.config.location) - - + + def ensure_sa_artifact_store_exists(self) -> None: """ Ensures that the Storage Account Artifact store for VNF exists. @@ -257,3 +279,24 @@ def ensure_nsdg_exists( network_service_design_group_name=nsdg_name, parameters=NetworkServiceDesignGroup(location=location), ) + + def resource_exists_by_name(self, rg_name: str, resource_name: str) -> bool: + """ + Determine if a resource with the given name exists. No checking is done as + to the type. + + :param resource_name: The name of the resource to check. + """ + logger.debug("Check if %s exists", resource_name) + resources = self.api_clients.resource_client.resources.list_by_resource_group( + resource_group_name=rg_name + ) + + resource_exists = False + + for resource in resources: + if resource.name == resource_name: + resource_exists = True + break + + return resource_exists diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 87c5209e59b..6ed9738bb6f 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -50,10 +50,9 @@ def generate_nfd(self) -> None: """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" # assert isinstance(self.config, VNFConfiguration) if self.bicep_path: - logger.info("Using the existing NFD bicep template %s.", self.bicep_path) - logger.info( - 'To generate a new NFD, delete the folder "%s" and re-run this command.', - os.path.dirname(self.bicep_path), + print(f"Using the existing NFD bicep template {self.bicep_path}." ) + print( + f'To generate a new NFD, delete the folder {os.path.dirname(self.bicep_path)} and re-run this command.' ) else: self.write() @@ -135,9 +134,17 @@ def write_deployment_parameters(self, folder_path: str) -> None: deployment_parameters_path = os.path.join( folder_path, "deploymentParameters.json" ) + + # Heading for the deployParameters schema + deploy_parameters_full: Dict[str, Any] = { + "$schema": "https://json-schema.org/draft-07/schema#", + "title": "DeployParametersSchema", + "type": "object", + "properties": nfd_parameters + } with open(deployment_parameters_path, "w") as _file: - _file.write(json.dumps(nfd_parameters, indent=4)) + _file.write(json.dumps(deploy_parameters_full, indent=4)) logger.debug("%s created", deployment_parameters_path) @@ -165,9 +172,18 @@ def write_vhd_parameters(self, folder_path: str) -> None: :param folder_path: The folder to put this file in. """ + azureDeployLocation: str + if self.vm_parameters.get("location"): + # Location can be passed in as deploy parameter + azureDeployLocation = "{deployParameters.location}" + else: + # Couldn't find a location parameter in the source template, so hard code to + # the location we are deploying the publisher to. + azureDeployLocation = self.config.location + vhd_parameters = { "imageName": f"{self.config.nf_name}Image", - "azureDeployLocation": "{deployParameters.location}", + "azureDeployLocation": azureDeployLocation, } vhd_parameters_path = os.path.join(folder_path, "vhdParameters.json") From c19920edf549efb4e0ec35d34f9c628d02976f93 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Tue, 2 May 2023 18:24:22 +0100 Subject: [PATCH 013/145] printing --- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 50de009c41a..22f8562aa82 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -68,10 +68,14 @@ def deploy_vnfd_from_bicep(self) -> Any: bicep_path = os.path.join(folder_name, bicep_template_name) parameters = self.construct_vnfd_parameters() - print(parameters) + logger.debug(parameters) + # Create or check required resources self.vnfd_predeploy() output = self.deploy_bicep_template(bicep_path, parameters) + print(f"Deployed NFD {self.config.nf_name} version {self.config.version} " + f"into {self.config.publisher_resource_group_name} under publisher " + f"{self.config.publisher_name}") return output From 8bbe2b7ff84a3e0a940690ded39b71172e2ea32f Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 3 May 2023 15:19:57 +0100 Subject: [PATCH 014/145] artifact upload half broken --- src/aosm/azext_aosm/deploy/artifact.py | 83 ++++++++++++ .../azext_aosm/deploy/artifact_manifest.py | 120 ++++++++++++++++++ src/aosm/azext_aosm/deploy/deploy_with_arm.py | 25 +++- .../templates/vnfdefinition.bicep | 2 + src/aosm/setup.py | 5 +- 5 files changed, 227 insertions(+), 8 deletions(-) create mode 100644 src/aosm/azext_aosm/deploy/artifact.py create mode 100644 src/aosm/azext_aosm/deploy/artifact_manifest.py diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py new file mode 100644 index 00000000000..057a6f409d1 --- /dev/null +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -0,0 +1,83 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Highly Confidential Material +"""A module to handle interacting with artifacts.""" + +from knack.log import get_logger +from dataclasses import dataclass +from typing import Union + +from azure.storage.blob import BlobClient +from azext_aosm._configuration import ArtifactConfig +from oras.client import OrasClient + +logger = get_logger(__name__) + + +@dataclass +class Artifact: + """Artifact class.""" + + artifact_name: str + artifact_type: str + artifact_version: str + artifact_client: Union[BlobClient, OrasClient] + + def upload(self, artifact_config: ArtifactConfig) -> None: + """ + Upload aritfact. + + :param artifact_config: configuration for the artifact being uploaded + """ + if self.artifact_type == "OCIArtifact" or self.artifact_type == "ArmTemplate": + self._upload_to_acr(artifact_config) + else: + self._upload_to_storage_account(artifact_config) + + def _upload_to_acr(self, artifact_config: ArtifactConfig) -> None: + """ + Upload artifact to ACR. + + :param artifact_config: configuration for the artifact being uploaded + """ + assert type(self.artifact_client) == OrasClient + + if "file_path" in artifact_config.keys(): + target = f"{self.artifact_client.remote.hostname.replace('https://', '')}/{self.artifact_name}:{self.artifact_version}" + logger.debug(f"Uploading {artifact_config['file_path']} to {target}") + self.artifact_client.push( + file=artifact_config["file_path"], + target=target, + ) + else: + raise NotImplementedError( + "Copying artifacts is not implemented for ACR artifacts stores." + ) + + def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: + """ + Upload artifact to storage account. + + :param artifact_config: configuration for the artifact being uploaded + """ + assert type(self.artifact_client) == BlobClient + + # If the file path is given, upload the artifact, else, copy it from an existing blob. + if "file_path" in artifact_config.keys(): + with open(artifact_config["file_path"], "rb") as artifact: + self.artifact_client.upload_blob(artifact, overwrite=True) + logger.info( + f"Successfully uploaded {artifact_config['file_path']} to {self.artifact_client.account_name}" + ) + else: + source_blob = BlobClient.from_blob_url(artifact_config["blob_sas_url"]) + + if source_blob.exists(): + logger.debug(source_blob.url) + self.artifact_client.start_copy_from_url(source_blob.url) + logger.info( + f"Successfully copied {source_blob.blob_name} from {source_blob.account_name} to {self.artifact_client.account_name}" + ) + else: + raise RuntimeError( + f"{source_blob.blob_name} does not exist in {source_blob.account_name}." + ) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py new file mode 100644 index 00000000000..29c4635864c --- /dev/null +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -0,0 +1,120 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Highly Confidential Material +"""A module to handle interacting with artifact manifests.""" + +from knack.log import get_logger +from functools import cached_property +from typing import Any, List, Union + +import requests +from azext_aosm.deploy.artifact import Artifact +from azure.storage.blob import BlobClient +from oras.client import OrasClient +from azext_aosm._configuration import Configuration, VNFConfiguration +from azext_aosm.vendored_sdks.models import ArtifactAccessCredential + +from azext_aosm.util.management_clients import ApiClientsAndCaches + +logger = get_logger(__name__) + + +class ArtifactManifest: + """ArtifactManifest class.""" + + def __init__(self, config: Configuration, api_clients: ApiClientsAndCaches, store_name: str, manifest_name: str) -> None: + """Init.""" + self.manifest_name = manifest_name + self.api_clients = api_clients + self.config = config + self.artifacts = self._get_artifact_list() + self.store_name = store_name + self._manifest_credentials = None + + @cached_property + def _manifest_credentials(self) -> ArtifactAccessCredential: + """Gets the details for uploading the artifacts in the manifest.""" + + return self.api_clients.aosm_client.artifact_manifests.list_credential( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + artifact_store_name=self.store_name, + artifact_manifest_name=self.manifest_name + ) + + + def _oras_client(self, acr_url: str) -> OrasClient: + """ + Returns an OrasClient object for uploading to the artifact str Returns an OrasClient object for uploading to the artifact store ACR.oe ACR. + + :param arc_url: URL of the ACR backing the artifact manifest + """ + client = OrasClient(hostname=acr_url) + client.login( + username=self._manifest_credentials.as_dict()["username"], + password=self._manifest_credentials["acrToken"], + ) + + return client + + def _get_artifact_list(self) -> List[Artifact]: + """Get the list of Artifacts in the Artifact Manifest.""" + url = f"https://management.azure.com/{self.resource_id.lstrip('/')}?api-version=2022-09-01-preview" + response = requests.get( + url=url, + headers={ + "Authorization": f"Bearer {self._access_token}", + }, + allow_redirects=True, + timeout=30, + ) + + artifacts = [] + + # Instatiate an Artifact object for each artifact in the manifest. + for artifact in response.json()["properties"]["artifacts"]: + artifact_name = artifact["artifactName"] + artifact_version = artifact["artifactVersion"] + + artifacts.append( + Artifact( + artifact_name=artifact_name, + artifact_type=artifact["artifactType"], + artifact_version=artifact_version, + artifact_client=self._get_artifact_client( + artifact_name, artifact_version + ), + ) + ) + + return artifacts + + def _get_artifact_client( + self, artifact_name: str, artifact_version: str + ) -> Union[BlobClient, OrasClient]: + """ + Get the artifact client required for uploading the artifact. + + :param artifact_name: name of the artifact + :param artifact_version: artifact version + """ + if self._manifest_credentials["credentialType"] == "AzureStorageAccountToken": + container_basename = artifact_name.replace("-", "") + blob_url = self._get_blob_url(f"{container_basename}-{artifact_version}") + return BlobClient.from_blob_url(blob_url) + else: + return self._oras_client(self._manifest_credentials["acrServerUrl"]) + + def _get_blob_url(self, container_name: str) -> str: + """ + Get the URL for the blob to be uploaded to the storage account artifact store. + + :param container_name: name of the container + """ + for container_credential in self._manifest_credentials["containerCredentials"]: + if container_credential["containerName"] == container_name: + sas_uri = str(container_credential["containerSasUri"]) + sas_uri_prefix = sas_uri.split("?")[0] + sas_uri_token = sas_uri.split("?")[1] + + return f"{sas_uri_prefix}/{container_name}?{sas_uri_token}" + raise KeyError(f"Manifest does not include a credential for {container_name}.") diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 22f8562aa82..d645e47e36b 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -4,20 +4,17 @@ # -------------------------------------------------------------------------------------- """Contains class for deploying generated definitions using the Python SDK.""" import json -import logging import os import shutil import subprocess # noqa -from functools import cached_property from typing import Any, Dict from knack.log import get_logger -from azure.mgmt.resource import ResourceManagementClient +from azext_aosm.deploy.artifact_manifest import ArtifactManifest from azext_aosm.util.management_clients import ApiClientsAndCaches from azure.mgmt.resource.resources.v2021_04_01.models import DeploymentExtended from pathlib import Path -from azext_aosm.vendored_sdks import HybridNetworkManagementClient from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK from azext_aosm._configuration import Configuration, VNFConfiguration from azext_aosm._constants import VNF_DEFINITION_OUTPUT_BICEP_PREFIX, VNF_DEFINITION_BICEP_SOURCE_TEMPLATE @@ -51,7 +48,7 @@ def __init__( apiClientsAndCaches, self.config ) - def deploy_vnfd_from_bicep(self) -> Any: + def deploy_vnfd_from_bicep(self) -> None: """Deploy the bicep template defining the VNFD. Also ensure that all required predeploy resources are deployed. @@ -76,8 +73,22 @@ def deploy_vnfd_from_bicep(self) -> Any: print(f"Deployed NFD {self.config.nf_name} version {self.config.version} " f"into {self.config.publisher_resource_group_name} under publisher " f"{self.config.publisher_name}") - - return output + + storage_account_manifest = ArtifactManifest(self.config, + self.api_clients, + self.config.vhd["blob_artifact_store_name"], + output["sa_manifest_name"]["value"]) + acr_manifest = ArtifactManifest(self.config, self.api_clients, output["acr_manifest_name"]["value"]) + + vhd_artifact = storage_account_manifest.artifacts[0] + arm_template_artifact = acr_manifest.artifacts[0] + + print("Uploading VHD artifact") + vhd_artifact.upload(self.config.vhd) + print("Uploading ARM template artifact") + arm_template_artifact.upload(self.config.arm_template) + print("Done") + def vnfd_predeploy(self): """ diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep index 6f200f43f6b..4c8cf06e230 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep @@ -138,3 +138,5 @@ resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroup output acr_manifest_id string = acrArtifactManifest.id output sa_manifest_id string = saArtifactManifest.id +output acr_manifest_name string = acrArtifactManifest.name +output sa_manifest_name string = saArtifactManifest.name diff --git a/src/aosm/setup.py b/src/aosm/setup.py index 83ecad46f31..542dd7a2aae 100644 --- a/src/aosm/setup.py +++ b/src/aosm/setup.py @@ -33,7 +33,10 @@ ] # TODO: Add any additional SDK dependencies here -DEPENDENCIES = [] +DEPENDENCIES = [ + 'oras~=0.1.17', + 'azure-storage-blob>=12.15.0' +] with open('README.rst', 'r', encoding='utf-8') as f: README = f.read() From 91cfe36c7e405aa91e53000d244a119971056fbe Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 3 May 2023 16:24:45 +0100 Subject: [PATCH 015/145] Artifact manifest stuff over to SDK --- .../azext_aosm/deploy/artifact_manifest.py | 77 ++++++++++--------- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 20 ++++- .../azext_aosm/util/management_clients.py | 1 + 3 files changed, 58 insertions(+), 40 deletions(-) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 29c4635864c..1a0ef7d061e 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -11,27 +11,33 @@ from azure.storage.blob import BlobClient from oras.client import OrasClient from azext_aosm._configuration import Configuration, VNFConfiguration -from azext_aosm.vendored_sdks.models import ArtifactAccessCredential +from azext_aosm.vendored_sdks.models import ( + ArtifactAccessCredential, + ArtifactManifest) from azext_aosm.util.management_clients import ApiClientsAndCaches logger = get_logger(__name__) -class ArtifactManifest: +class ArtifactManifestOperator: """ArtifactManifest class.""" - def __init__(self, config: Configuration, api_clients: ApiClientsAndCaches, store_name: str, manifest_name: str) -> None: + def __init__(self, + config: Configuration, + api_clients: ApiClientsAndCaches, + store_name: str, + manifest_name: str) -> None: """Init.""" self.manifest_name = manifest_name self.api_clients = api_clients self.config = config - self.artifacts = self._get_artifact_list() self.store_name = store_name + self.artifacts = self._get_artifact_list() self._manifest_credentials = None @cached_property - def _manifest_credentials(self) -> ArtifactAccessCredential: + def _manifest_credentials(self) -> Any: """Gets the details for uploading the artifacts in the manifest.""" return self.api_clients.aosm_client.artifact_manifests.list_credential( @@ -39,7 +45,7 @@ def _manifest_credentials(self) -> ArtifactAccessCredential: publisher_name=self.config.publisher_name, artifact_store_name=self.store_name, artifact_manifest_name=self.manifest_name - ) + ).as_dict() def _oras_client(self, acr_url: str) -> OrasClient: @@ -50,41 +56,40 @@ def _oras_client(self, acr_url: str) -> OrasClient: """ client = OrasClient(hostname=acr_url) client.login( - username=self._manifest_credentials.as_dict()["username"], - password=self._manifest_credentials["acrToken"], + username=self._manifest_credentials["username"], + password=self._manifest_credentials["acr_token"], ) return client def _get_artifact_list(self) -> List[Artifact]: """Get the list of Artifacts in the Artifact Manifest.""" - url = f"https://management.azure.com/{self.resource_id.lstrip('/')}?api-version=2022-09-01-preview" - response = requests.get( - url=url, - headers={ - "Authorization": f"Bearer {self._access_token}", - }, - allow_redirects=True, - timeout=30, - ) - artifacts = [] + + manifest: ArtifactManifest = self.api_clients.aosm_client.artifact_manifests.get( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + artifact_store_name=self.store_name, + artifact_manifest_name=self.manifest_name + ) # Instatiate an Artifact object for each artifact in the manifest. - for artifact in response.json()["properties"]["artifacts"]: - artifact_name = artifact["artifactName"] - artifact_version = artifact["artifactVersion"] - - artifacts.append( - Artifact( - artifact_name=artifact_name, - artifact_type=artifact["artifactType"], - artifact_version=artifact_version, - artifact_client=self._get_artifact_client( - artifact_name, artifact_version - ), + if manifest.artifacts: + for artifact in manifest.artifacts: + assert artifact.artifact_name + assert artifact.artifact_type + assert artifact.artifact_version + + artifacts.append( + Artifact( + artifact_name=artifact.artifact_name, + artifact_type=artifact.artifact_type, + artifact_version=artifact.artifact_version, + artifact_client=self._get_artifact_client( + artifact.artifact_name, artifact.artifact_version + ), + ) ) - ) return artifacts @@ -97,12 +102,12 @@ def _get_artifact_client( :param artifact_name: name of the artifact :param artifact_version: artifact version """ - if self._manifest_credentials["credentialType"] == "AzureStorageAccountToken": + if self._manifest_credentials["credential_type"] == "AzureStorageAccountToken": container_basename = artifact_name.replace("-", "") blob_url = self._get_blob_url(f"{container_basename}-{artifact_version}") return BlobClient.from_blob_url(blob_url) else: - return self._oras_client(self._manifest_credentials["acrServerUrl"]) + return self._oras_client(self._manifest_credentials["acr_server_url"]) def _get_blob_url(self, container_name: str) -> str: """ @@ -110,9 +115,9 @@ def _get_blob_url(self, container_name: str) -> str: :param container_name: name of the container """ - for container_credential in self._manifest_credentials["containerCredentials"]: - if container_credential["containerName"] == container_name: - sas_uri = str(container_credential["containerSasUri"]) + for container_credential in self._manifest_credentials["container_credentials"]: + if container_credential["container_name"] == container_name: + sas_uri = str(container_credential["container_sas_uri"]) sas_uri_prefix = sas_uri.split("?")[0] sas_uri_token = sas_uri.split("?")[1] diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index d645e47e36b..5682fe23b44 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -10,7 +10,7 @@ from typing import Any, Dict from knack.log import get_logger -from azext_aosm.deploy.artifact_manifest import ArtifactManifest +from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator from azext_aosm.util.management_clients import ApiClientsAndCaches from azure.mgmt.resource.resources.v2021_04_01.models import DeploymentExtended from pathlib import Path @@ -74,11 +74,23 @@ def deploy_vnfd_from_bicep(self) -> None: f"into {self.config.publisher_resource_group_name} under publisher " f"{self.config.publisher_name}") - storage_account_manifest = ArtifactManifest(self.config, + storage_account_manifest = ArtifactManifestOperator(self.config, self.api_clients, - self.config.vhd["blob_artifact_store_name"], + self.config.blob_artifact_store_name, output["sa_manifest_name"]["value"]) - acr_manifest = ArtifactManifest(self.config, self.api_clients, output["acr_manifest_name"]["value"]) + acr_manifest = ArtifactManifestOperator(self.config, + self.api_clients, + self.config.acr_artifact_store_name, + output["acr_manifest_name"]["value"]) + + # storage_account_manifest = ArtifactManifestOperator(self.config, + # self.api_clients, + # self.config.blob_artifact_store_name, + # "sunnyvnf-sa-manifest-1-0-5") + # acr_manifest = ArtifactManifestOperator(self.config, + # self.api_clients, + # self.config.acr_artifact_store_name, + # "sunnyvnf-acr-manifest-1-0-5") vhd_artifact = storage_account_manifest.artifacts[0] arm_template_artifact = acr_manifest.artifacts[0] diff --git a/src/aosm/azext_aosm/util/management_clients.py b/src/aosm/azext_aosm/util/management_clients.py index 05cf0f7e794..86432531a45 100644 --- a/src/aosm/azext_aosm/util/management_clients.py +++ b/src/aosm/azext_aosm/util/management_clients.py @@ -17,6 +17,7 @@ @dataclass class ProviderInfo: + """Class to return Provider Info information""" namespace: str resource_type: str From a2410b4e698c73841086018e4c5991f4bb24f2d4 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 3 May 2023 18:01:28 +0100 Subject: [PATCH 016/145] delete NFD function --- src/aosm/azext_aosm/_configuration.py | 10 + src/aosm/azext_aosm/_help.py | 5 + src/aosm/azext_aosm/_params.py | 5 +- src/aosm/azext_aosm/commands.py | 2 +- src/aosm/azext_aosm/custom.py | 18 ++ src/aosm/azext_aosm/delete/delete.py | 239 ++++++++++++++++++ src/aosm/azext_aosm/deploy/deploy_with_arm.py | 18 +- .../templates/vnfdefinition.bicep | 13 +- src/aosm/azext_aosm/util/utils.py | 16 ++ 9 files changed, 304 insertions(+), 22 deletions(-) create mode 100644 src/aosm/azext_aosm/delete/delete.py create mode 100644 src/aosm/azext_aosm/util/utils.py diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 3602a3c1219..f039c57ca8c 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -25,12 +25,22 @@ class Configuration(): def nfdg_name(self) -> str: """Return the NFD Group name from the NFD name.""" return f"{self.nf_name}-nfdg" + + @property + def acr_manifest_name(self) -> str: + """Return the ACR manifest name from the NFD name""" + return f"{self.nf_name}-acr-manifest-{self.version.replace('.', '-')}" @dataclass class VNFConfiguration(Configuration): blob_artifact_store_name: str = "Name of the storage account Artifact Store resource" arm_template: ArtifactConfig = ArtifactConfig() vhd: ArtifactConfig = ArtifactConfig() + + @property + def sa_manifest_name(self) -> str: + """Return the Storage account manifest name from the NFD name""" + return f"{self.nf_name}-sa-manifest-{self.version.replace('.', '-')}" def get_configuration(definition_type, config_as_dict=None) -> Configuration: diff --git a/src/aosm/azext_aosm/_help.py b/src/aosm/azext_aosm/_help.py index 1fb3bb11b3f..bb9af1e5334 100644 --- a/src/aosm/azext_aosm/_help.py +++ b/src/aosm/azext_aosm/_help.py @@ -26,3 +26,8 @@ type: command short-summary: Generate configuration file for building an AOSM publisher definition. """ + +helps['aosm definition delete'] = """ + type: command + short-summary: Delete AOSM publisher definition. +""" diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index 4bf374f9e95..69e6624dcab 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -22,7 +22,7 @@ def load_arguments(self: AzCommandsLoader, _): c.argument( 'definition_type', arg_type=definition_type, - help='Type of AOSM definition to generate.' + help='Type of AOSM definition.' ) c.argument( 'config_file', @@ -32,6 +32,7 @@ def load_arguments(self: AzCommandsLoader, _): help='The path to the configuration file.' ) c.argument('publish', arg_type=get_three_state_flag(), help='Publishes generated AOSM definition.') - + c.argument('all', arg_type=get_three_state_flag(), help='Also delete artifact stores, NFD Group and Publisher. Use with care.') + with self.argument_context('aosm generate-config') as c: c.argument('definition_type', arg_type=definition_type, help='Type of AOSM definition config to generate.') diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index 474d9d66b4f..625feca0110 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -20,7 +20,7 @@ def load_command_table(self: AzCommandsLoader, _): # Add each command and bind it to a function in custom.py g.custom_command('generate-config', 'generate_definition_config') g.custom_command('build', 'build_definition') - #g.custom_command('publish', 'publish_definition') + g.custom_command('delete', 'delete_published_definition') g.custom_command('show', 'show_publisher') with self.command_group('aosm', is_preview=True): diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index d082e6c9874..875d60f6a6b 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -106,7 +106,25 @@ def _generate_nfd(definition_type, config): ) nfd_generator.generate_nfd() + +def delete_published_definition( + cmd, + client: HybridNetworkManagementClient, + definition_type, + config_file, + all=False, +): + with open(config_file, "r", encoding="utf-8") as f: + config_as_dict = json.loads(f.read()) + config = get_configuration(definition_type, config_as_dict) + validate_configuration(config) + api_clients = ApiClientsAndCaches(aosm_client=client, + resource_client=cf_resources(cmd.cli_ctx)) + from azext_aosm.delete.delete import ResourceDeleter + delly = ResourceDeleter(api_clients, config) + if definition_type == VNF: + delly.delete_vnf(all) def show_publisher(): pass diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py new file mode 100644 index 00000000000..943b0f12ba4 --- /dev/null +++ b/src/aosm/azext_aosm/delete/delete.py @@ -0,0 +1,239 @@ + +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains class for deploying generated definitions using the Python SDK.""" +from typing import Any, Dict +from knack.log import get_logger + +from azure.mgmt.resource.resources.v2021_04_01.models import ( + GenericResourceExpanded, + Provider, +) + +from azext_aosm.util.management_clients import ApiClientsAndCaches +from azext_aosm._configuration import Configuration, VNFConfiguration +from azext_aosm.util.utils import input_ack + + +logger = get_logger(__name__) + + +class ResourceDeleter(): + def __init__( + self, + apiClientsAndCaches: ApiClientsAndCaches, + config: Configuration, + ) -> None: + """ + Initializes a new instance of the Deployer class. + + :param aosm_client: The client to use for managing AOSM resources. + :type aosm_client: HybridNetworkManagementClient + :param resource_client: The client to use for managing Azure resources. + :type resource_client: ResourceManagementClient + """ + logger.debug("Create ARM/Bicep Deployer") + self.api_clients = apiClientsAndCaches + self.config = config + + def delete_vnf(self, all: bool = False): + """Delete the NFDV and manifests. + + :param all: Delete the NFDG, artifact stores and publisher too. + defaults to False + Use with care. + + """ + assert isinstance(self.config, VNFConfiguration) + if all: + print(f"Are you sure you want to delete all resources associated with NFD {self.config.nf_name} including the artifact stores and publisher {self.config.publisher_name}?") + logger.warning("This command will fail if other NFD versions exist in the NFD group.") + logger.warning("Only do this if you are SURE you are not sharing the publisher and artifact stores with other NFDs") + print("There is no undo. Type the publisher name to confirm.") + if not input_ack(self.config.publisher_name.lower(), "Confirm delete:"): + print("Not proceeding with delete") + return + else: + print(f"Are you sure you want to delete the NFD Version {self.config.version} and associated manifests from group {self.config.nfdg_name} and publisher {self.config.publisher_name}?") + print("There is no undo. Type 'delete' to confirm") + if not input_ack("delete", "Confirm delete:"): + print("Not proceeding with delete") + return + + self.delete_nfdv() + self.delete_artifact_manifest("sa") + self.delete_artifact_manifest("acr") + + if all: + logger.info("Delete called for all resources.") + self.delete_nfdg() + self.delete_artifact_store("acr") + self.delete_artifact_store("sa") + self.delete_publisher() + + + + def delete_nfdv(self): + message: str = f"Delete NFDV {self.config.version} from group {self.config.nfdg_name} and publisher {self.config.publisher_name}" + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.network_function_definition_versions.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + network_function_definition_group_name=self.config.nfdg_name, + network_function_definition_version_name=self.config.version + ) + poller.result() + print("Deleted NFDV.") + except Exception: + logger.error(f"Failed to delete NFDV {self.config.version} from group {self.config.nfdg_name}") + raise + + def delete_artifact_manifest(self, store_type: str) -> None: + """_summary_ + + :param store_type: "sa" or "acr" + :raises CLIInternalError: If called with any other store type + :raises Exception if delete throws an exception + """ + if store_type == "sa": + assert isinstance(self.config, VNFConfiguration) + store_name = self.config.blob_artifact_store_name + manifest_name = self.config.sa_manifest_name + elif store_type == "acr": + store_name = self.config.acr_artifact_store_name + manifest_name = self.config.acr_manifest_name + else: + from azure.cli.core.azclierror import CLIInternalError + + raise CLIInternalError( + "Delete artifact manifest called for invalid store type. Valid types are sa and acr." + ) + message: str = f"Delete Artifact manifest {manifest_name} from artifact store {store_name}" + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.artifact_manifests.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + artifact_store_name=store_name, + artifact_manifest_name=manifest_name + ) + poller.result() + print("Deleted Artifact Manifest") + except Exception: + logger.error(f"Failed to delete Artifact manifest {manifest_name} from artifact store {store_name}") + raise + + def delete_nfdg(self)-> None: + """Delete the NFDG + """ + message: str = f"Delete NFD Group {self.config.nfdg_name}" + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.network_function_definition_groups.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + network_function_definition_group_name=self.config.nfdg_name + ) + poller.result() + print("Delete NFD Group") + except Exception: + logger.error(f"Failed to delete NFDG.") + raise + + def delete_artifact_store(self, store_type: str) -> None: + """Delete an artifact store + :param store_type: "sa" or "acr" + :raises CLIInternalError: If called with any other store type + :raises Exception if delete throws an exception + """ + if store_type == "sa": + assert isinstance(self.config, VNFConfiguration) + store_name = self.config.blob_artifact_store_name + elif store_type == "acr": + store_name = self.config.acr_artifact_store_name + else: + from azure.cli.core.azclierror import CLIInternalError + + raise CLIInternalError( + "Delete artifact store called for invalid store type. Valid types are sa and acr." + ) + message: str = f"Delete Artifact store {store_name}" + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.artifact_stores.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + artifact_store_name=store_name + ) + poller.result() + print("Deleted Artifact Store") + except Exception: + logger.error(f"Failed to delete Artifact store {store_name}") + raise + + def delete_publisher(self) -> None: + """Delete the publisher. Warning - dangerous""" + message: str = f"Delete Publisher {self.config.publisher_name}" + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.publishers.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name + ) + poller.result() + print("Deleted Publisher") + except Exception: + logger.error(f"Failed to delete publisher") + raise + + # def delete_resource(self, resource: GenericResourceExpanded) -> bool: + # """ + # Delete a resource. + + # They can fail to delete if resources are deleted out of dependency order. We + # catch exceptions in this case, log them, and return False. + + # :param resource: The resource to delete + # :return: True/False on whether we successfully deleted. + # """ + # # We need to find an API version relevant to the resource. + # if resource.type not in self.resource_type_api_versions_cache.keys(): + # api_version = self.find_latest_api_ver_for_resource_type(resource) + + # if not api_version: + # raise RuntimeError( + # f"Azure API did not return an API version for {resource.type}." + # f"Cannot delete resource {resource.name}" + # ) + # else: + # assert resource.type is not None + # self.resource_type_api_versions_cache[resource.type] = api_version + + # try: + # # Now delete the resource + # assert resource.id is not None + # logger.debug( + # f"Delete the resource {resource.id} with " + # f"api_version {self.resource_type_api_versions_cache.get(resource.type)}" + # ) + # poller = self.resource_client.resources.begin_delete_by_id( + # resource_id=resource.id, + # api_version=self.resource_type_api_versions_cache.get(resource.type), + # ) + # # This makes it wait to be done. + # poller.result() + # except Exception as delEx: + # # We expect these to happen if resources are deleted out of dependency + # # order + # logger.info(f"Failed to delete {resource.name} {delEx}") + # return False + + # return True diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 5682fe23b44..9c352b0b86c 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -69,7 +69,7 @@ def deploy_vnfd_from_bicep(self) -> None: # Create or check required resources self.vnfd_predeploy() - output = self.deploy_bicep_template(bicep_path, parameters) + self.deploy_bicep_template(bicep_path, parameters) print(f"Deployed NFD {self.config.nf_name} version {self.config.version} " f"into {self.config.publisher_resource_group_name} under publisher " f"{self.config.publisher_name}") @@ -77,20 +77,11 @@ def deploy_vnfd_from_bicep(self) -> None: storage_account_manifest = ArtifactManifestOperator(self.config, self.api_clients, self.config.blob_artifact_store_name, - output["sa_manifest_name"]["value"]) + self.config.sa_manifest_name) acr_manifest = ArtifactManifestOperator(self.config, self.api_clients, self.config.acr_artifact_store_name, - output["acr_manifest_name"]["value"]) - - # storage_account_manifest = ArtifactManifestOperator(self.config, - # self.api_clients, - # self.config.blob_artifact_store_name, - # "sunnyvnf-sa-manifest-1-0-5") - # acr_manifest = ArtifactManifestOperator(self.config, - # self.api_clients, - # self.config.acr_artifact_store_name, - # "sunnyvnf-acr-manifest-1-0-5") + self.config.acr_manifest_name) vhd_artifact = storage_account_manifest.artifacts[0] arm_template_artifact = acr_manifest.artifacts[0] @@ -126,6 +117,8 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: "publisherName": {"value": self.config.publisher_name}, "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, + "acrManifesteName": {"value": self.config.acr_manifest_name}, + "saManifesteName": {"value": self.config.sa_manifest_name}, "nfName": {"value": self.config.nf_name}, "nfDefinitionGroup": {"value": self.config.nfdg_name}, "nfDefinitionVersion": {"value": self.config.version}, @@ -143,6 +136,7 @@ def deploy_bicep_template( :param bicep_template_path: Path to the bicep template :param parameters: Parameters for the bicep template + :return Any output that the template produces """ logger.info("Deploy %s", bicep_template_path) arm_template_json = self.convert_bicep_to_arm(bicep_template_path) diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep index 4c8cf06e230..aafdd474de5 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep @@ -8,6 +8,10 @@ param publisherName string param acrArtifactStoreName string @description('Name of an existing Storage Account-backed Artifact Store, deployed under the publisher.') param saArtifactStoreName string +@description('Name of the manifest to deploy for the ACR-backed Artifact Store') +param acrManifestName string +@description('Name of the manifest to deploy for the Storage Account-backed Artifact Store') +param saManifestName string @description('Name of Network Function. Used predominantly as a prefix for other variable names') param nfName string @description('Name of an existing Network Function Definition Group') @@ -49,7 +53,7 @@ resource nfdg 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroup resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { parent: saArtifactStore - name: '${nfName}-sa-manifest-${replace(nfDefinitionVersion, '.', '-')}' + name: saManifestName location: location properties: { artifacts: [ @@ -64,7 +68,7 @@ resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/a resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { parent: acrArtifactStore - name: '${nfName}-acr-manifest-${replace(nfDefinitionVersion, '.', '-')}' + name: acrManifestName location: location properties: { artifacts: [ @@ -135,8 +139,3 @@ resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroup } } } - -output acr_manifest_id string = acrArtifactManifest.id -output sa_manifest_id string = saArtifactManifest.id -output acr_manifest_name string = acrArtifactManifest.name -output sa_manifest_name string = saArtifactManifest.name diff --git a/src/aosm/azext_aosm/util/utils.py b/src/aosm/azext_aosm/util/utils.py new file mode 100644 index 00000000000..da6fe2f59ee --- /dev/null +++ b/src/aosm/azext_aosm/util/utils.py @@ -0,0 +1,16 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +"""Utility functions.""" + +def input_ack(ack: str, request_to_user: str) -> bool: + """ + Overarching function to request, sanitise and return True if input is specified ack. + + This prints the question string and asks for user input. which is santised by + removing all whitespaces in the string, and made lowercase. True is returned if the + user input is equal to supplied acknowledgement string and False if anything else + """ + unsanitised_ans = input(request_to_user) + return str(unsanitised_ans.strip().replace(" ", "").lower()) == ack From bfadbeb526cefcf77bb7afefc37458ed2827e7d6 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 3 May 2023 18:11:31 +0100 Subject: [PATCH 017/145] linting --- src/aosm/azext_aosm/__init__.py | 10 +- src/aosm/azext_aosm/_client_factory.py | 2 + src/aosm/azext_aosm/_configuration.py | 59 ++++-- src/aosm/azext_aosm/_constants.py | 2 +- src/aosm/azext_aosm/_help.py | 20 +- src/aosm/azext_aosm/_params.py | 41 ++-- src/aosm/azext_aosm/_validators.py | 7 +- src/aosm/azext_aosm/commands.py | 15 +- src/aosm/azext_aosm/custom.py | 63 +++--- src/aosm/azext_aosm/delete/delete.py | 81 ++++---- .../azext_aosm/deploy/artifact_manifest.py | 39 ++-- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 51 +++-- src/aosm/azext_aosm/deploy/deploy_with_sdk.py | 12 +- src/aosm/azext_aosm/deploy/pre_deploy.py | 121 +++++++----- .../generate_nfd/cnf_nfd_generator.py | 10 +- .../generate_nfd/nfd_generator_base.py | 11 +- .../generate_nfd/vnf_bicep_nfd_generator.py | 11 +- .../publisher_resources.py | 5 +- src/aosm/azext_aosm/test.py | 35 ++-- src/aosm/azext_aosm/tests/__init__.py | 2 +- src/aosm/azext_aosm/tests/latest/__init__.py | 2 +- .../tests/latest/test_aosm_scenario.py | 48 ++--- .../azext_aosm/util/management_clients.py | 179 +++++++++--------- src/aosm/azext_aosm/util/utils.py | 1 + 24 files changed, 469 insertions(+), 358 deletions(-) diff --git a/src/aosm/azext_aosm/__init__.py b/src/aosm/azext_aosm/__init__.py index a360b6ceca5..a9098c4d1fb 100644 --- a/src/aosm/azext_aosm/__init__.py +++ b/src/aosm/azext_aosm/__init__.py @@ -9,19 +9,23 @@ class AosmCommandsLoader(AzCommandsLoader): - def __init__(self, cli_ctx=None): from azure.cli.core.commands import CliCommandType - aosm_custom = CliCommandType(operations_tmpl='azext_aosm.custom#{}') - super(AosmCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=aosm_custom) + + aosm_custom = CliCommandType(operations_tmpl="azext_aosm.custom#{}") + super(AosmCommandsLoader, self).__init__( + cli_ctx=cli_ctx, custom_command_type=aosm_custom + ) def load_command_table(self, args): from azext_aosm.commands import load_command_table + load_command_table(self, args) return self.command_table def load_arguments(self, command): from azext_aosm._params import load_arguments + load_arguments(self, command) diff --git a/src/aosm/azext_aosm/_client_factory.py b/src/aosm/azext_aosm/_client_factory.py index dd7d5cdf2de..e55e6142d25 100644 --- a/src/aosm/azext_aosm/_client_factory.py +++ b/src/aosm/azext_aosm/_client_factory.py @@ -7,9 +7,11 @@ from azure.cli.core.profiles import ResourceType from .vendored_sdks import HybridNetworkManagementClient + def cf_aosm(cli_ctx, *_) -> HybridNetworkManagementClient: return get_mgmt_service_client(cli_ctx, HybridNetworkManagementClient) + def cf_resources(cli_ctx, subscription_id=None): return get_mgmt_service_client( cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index f039c57ca8c..e601b6308d7 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -7,15 +7,26 @@ @dataclass class ArtifactConfig: artifact_name: str = "Name of the artifact" - file_path: Optional[str] = "File path of the artifact you wish to upload from your local disk" - blob_sas_url: Optional[str] = "SAS URL of the blob artifact you wish to copy to your Artifact Store" - version: str = "Version of the artifact. For VHDs this must be in format A-B-C. For ARM templates this must be in format A.B.C" + file_path: Optional[ + str + ] = "File path of the artifact you wish to upload from your local disk" + blob_sas_url: Optional[ + str + ] = "SAS URL of the blob artifact you wish to copy to your Artifact Store" + version: str = ( + "Version of the artifact. For VHDs this must be in format A-B-C. " + "For ARM templates this must be in format A.B.C" + ) @dataclass -class Configuration(): - publisher_name: str = "Name of the Publisher resource you want you definition published to" - publisher_resource_group_name: str = "Resource group the Publisher resource is in or you want it to be in" +class Configuration: + publisher_name: str = ( + "Name of the Publisher resource you want you definition published to" + ) + publisher_resource_group_name: str = ( + "Resource group the Publisher resource is in or you want it to be in" + ) nf_name: str = "Name of NF definition" version: str = "Version of the NF definition" acr_artifact_store_name: str = "Name of the ACR Artifact Store resource" @@ -25,22 +36,25 @@ class Configuration(): def nfdg_name(self) -> str: """Return the NFD Group name from the NFD name.""" return f"{self.nf_name}-nfdg" - + @property def acr_manifest_name(self) -> str: - """Return the ACR manifest name from the NFD name""" + """Return the ACR manifest name from the NFD name.""" return f"{self.nf_name}-acr-manifest-{self.version.replace('.', '-')}" + @dataclass class VNFConfiguration(Configuration): - blob_artifact_store_name: str = "Name of the storage account Artifact Store resource" + blob_artifact_store_name: str = ( + "Name of the storage account Artifact Store resource" + ) arm_template: ArtifactConfig = ArtifactConfig() vhd: ArtifactConfig = ArtifactConfig() - + @property def sa_manifest_name(self) -> str: - """Return the Storage account manifest name from the NFD name""" - return f"{self.nf_name}-sa-manifest-{self.version.replace('.', '-')}" + """Return the Storage account manifest name from the NFD name.""" + return f"{self.nf_name}-sa-manifest-{self.version.replace('.', '-')}" def get_configuration(definition_type, config_as_dict=None) -> Configuration: @@ -54,12 +68,16 @@ def get_configuration(definition_type, config_as_dict=None) -> Configuration: elif definition_type == NSD: config = Configuration(**config_as_dict) else: - raise InvalidArgumentValueError("Definition type not recognized, options are: vnf, cnf or nsd") + raise InvalidArgumentValueError( + "Definition type not recognized, options are: vnf, cnf or nsd" + ) return config + def validate_configuration(config: Configuration) -> None: - """Validate the configuration passed in + """ + Validate the configuration passed in. :param config: _description_ :type config: Configuration @@ -70,6 +88,13 @@ def validate_configuration(config: Configuration) -> None: if isinstance(config, VNFConfiguration): if "." in config.vhd["version"] or "-" not in config.vhd["version"]: # Not sure about raising this particular one. - raise ValidationError("Config validation error. VHD artifact version should be in format A-B-C") - if "." not in config.arm_template["version"] or "-" in config.arm_template["version"]: - raise ValidationError("Config validation error. ARM template artifact version should be in format A.B.C") + raise ValidationError( + "Config validation error. VHD artifact version should be in format A-B-C" + ) + if ( + "." not in config.arm_template["version"] + or "-" in config.arm_template["version"] + ): + raise ValidationError( + "Config validation error. ARM template artifact version should be in format A.B.C" + ) diff --git a/src/aosm/azext_aosm/_constants.py b/src/aosm/azext_aosm/_constants.py index daea47a7c9c..8b232eff0bf 100644 --- a/src/aosm/azext_aosm/_constants.py +++ b/src/aosm/azext_aosm/_constants.py @@ -4,7 +4,7 @@ # -------------------------------------------------------------------------------------------- """Constants used across aosm cli extension.""" -AOSM_API_VERSION="2022-09-01-preview" +AOSM_API_VERSION = "2022-09-01-preview" # The types of definition that can be generated VNF = "vnf" diff --git a/src/aosm/azext_aosm/_help.py b/src/aosm/azext_aosm/_help.py index bb9af1e5334..d5169d49c0d 100644 --- a/src/aosm/azext_aosm/_help.py +++ b/src/aosm/azext_aosm/_help.py @@ -7,27 +7,37 @@ from knack.help_files import helps # pylint: disable=unused-import -helps['aosm'] = """ +helps[ + "aosm" +] = """ type: group short-summary: Commands to interact with Azure Operator Service Manager (AOSM). """ -helps['aosm definition'] = """ +helps[ + "aosm definition" +] = """ type: group short-summary: Manage AOSM publisher definitions. """ -helps['aosm definition build'] = """ +helps[ + "aosm definition build" +] = """ type: command short-summary: Build an AOSM publisher definition. """ -helps['aosm definition generate-config'] = """ +helps[ + "aosm definition generate-config" +] = """ type: command short-summary: Generate configuration file for building an AOSM publisher definition. """ -helps['aosm definition delete'] = """ +helps[ + "aosm definition delete" +] = """ type: command short-summary: Delete AOSM publisher definition. """ diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index 69e6624dcab..c9339763f4d 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -6,33 +6,46 @@ from argcomplete.completers import FilesCompleter from azure.cli.core import AzCommandsLoader -from knack.arguments import CLIArgumentType +#from knack.arguments import CLIArgumentType from ._constants import VNF, CNF, NSD def load_arguments(self: AzCommandsLoader, _): - - from azure.cli.core.commands.parameters import file_type, get_enum_type, get_three_state_flag + from azure.cli.core.commands.parameters import ( + file_type, + get_enum_type, + get_three_state_flag, + ) definition_type = get_enum_type([VNF, CNF, NSD]) # Set the argument context so these options are only available when this specific command # is called. - with self.argument_context('aosm definition') as c: + with self.argument_context("aosm definition") as c: c.argument( - 'definition_type', - arg_type=definition_type, - help='Type of AOSM definition.' + "definition_type", arg_type=definition_type, help="Type of AOSM definition." ) c.argument( - 'config_file', + "config_file", options_list=["--config-file", "-f"], type=file_type, completer=FilesCompleter(allowednames="*.json"), - help='The path to the configuration file.' + help="The path to the configuration file.", + ) + c.argument( + "publish", + arg_type=get_three_state_flag(), + help="Publishes generated AOSM definition.", + ) + c.argument( + "clean", + arg_type=get_three_state_flag(), + help="Also delete artifact stores, NFD Group and Publisher. Use with care.", + ) + + with self.argument_context("aosm generate-config") as c: + c.argument( + "definition_type", + arg_type=definition_type, + help="Type of AOSM definition config to generate.", ) - c.argument('publish', arg_type=get_three_state_flag(), help='Publishes generated AOSM definition.') - c.argument('all', arg_type=get_three_state_flag(), help='Also delete artifact stores, NFD Group and Publisher. Use with care.') - - with self.argument_context('aosm generate-config') as c: - c.argument('definition_type', arg_type=definition_type, help='Type of AOSM definition config to generate.') diff --git a/src/aosm/azext_aosm/_validators.py b/src/aosm/azext_aosm/_validators.py index bdbc5023a4d..1a9f0e39617 100644 --- a/src/aosm/azext_aosm/_validators.py +++ b/src/aosm/azext_aosm/_validators.py @@ -10,12 +10,13 @@ def example_name_or_id_validator(cmd, namespace): # https://github.com/Azure/azure-cli/blob/dev/doc/authoring_command_modules/authoring_commands.md#supporting-name-or-id-parameters from azure.cli.core.commands.client_factory import get_subscription_id from msrestazure.tools import is_valid_resource_id, resource_id + if namespace.storage_account: if not is_valid_resource_id(namespace.RESOURCE): namespace.storage_account = resource_id( subscription=get_subscription_id(cmd.cli_ctx), resource_group=namespace.resource_group_name, - namespace='Microsoft.Storage', - type='storageAccounts', - name=namespace.storage_account + namespace="Microsoft.Storage", + type="storageAccounts", + name=namespace.storage_account, ) diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index 625feca0110..d57a4b9db3b 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -5,23 +5,22 @@ # pylint: disable=line-too-long from azure.cli.core import AzCommandsLoader -from azure.cli.core.commands import CliCommandType +#from azure.cli.core.commands import CliCommandType from azext_aosm._client_factory import cf_aosm def load_command_table(self: AzCommandsLoader, _): - # TODO: Add command type here # aosm_sdk = CliCommandType( # operations_tmpl='.operations#None.{}', # client_factory=cf_aosm) - with self.command_group('aosm definition', client_factory=cf_aosm) as g: + with self.command_group("aosm definition", client_factory=cf_aosm) as g: # Add each command and bind it to a function in custom.py - g.custom_command('generate-config', 'generate_definition_config') - g.custom_command('build', 'build_definition') - g.custom_command('delete', 'delete_published_definition') - g.custom_command('show', 'show_publisher') + g.custom_command("generate-config", "generate_definition_config") + g.custom_command("build", "build_definition") + g.custom_command("delete", "delete_published_definition") + g.custom_command("show", "show_publisher") - with self.command_group('aosm', is_preview=True): + with self.command_group("aosm", is_preview=True): pass diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 875d60f6a6b..f0fdf3a43ba 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -5,39 +5,24 @@ import json from dataclasses import asdict -from typing import Optional, Tuple from knack.log import get_logger -from azure.cli.core.azclierror import AzCLIError -from azure.mgmt.resource import ResourceManagementClient from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.generate_nfd.vnf_bicep_nfd_generator import VnfBicepNfdGenerator - +from azext_aosm.deploy.deploy_with_arm import DeployerViaArm +from azext_aosm._constants import VNF, CNF, NSD +from azext_aosm.util.management_clients import ApiClientsAndCaches from .vendored_sdks import HybridNetworkManagementClient -from .vendored_sdks.models import Publisher, NetworkFunctionDefinitionVersion from ._client_factory import cf_resources from ._configuration import ( - Configuration, - VNFConfiguration, get_configuration, validate_configuration, ) -from azext_aosm.deploy.deploy_with_arm import DeployerViaArm -from azext_aosm._constants import VNF, CNF, NSD -from azext_aosm.util.management_clients import ApiClientsAndCaches - logger = get_logger(__name__) -PUBLISHER_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers" -ARTIFACT_STORE_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/artifactstores" -NFDG_RESOURCE_TYPE = ( - "Microsoft.HybridNetwork/publishers/networkfunctiondefinitiongroups" -) -NSDG_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/networkservicedesigngroups" - def build_definition( cmd, @@ -46,11 +31,25 @@ def build_definition( config_file, publish=False, ): + """Build and optionally publish a definition + + :param cmd: _description_ + :type cmd: _type_ + :param client: _description_ + :type client: HybridNetworkManagementClient + :param definition_type: _description_ + :type definition_type: _type_ + :param config_file: _description_ + :type config_file: _type_ + :param publish: _description_, defaults to False + :type publish: bool, optional + """ with open(config_file, "r", encoding="utf-8") as f: config_as_dict = json.loads(f.read()) - apiClientsAndCaches = ApiClientsAndCaches(aosm_client=client, - resource_client=cf_resources(cmd.cli_ctx)) + apiClientsAndCaches = ApiClientsAndCaches( + aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) + ) # TODO - this isn't deserializing the config properly - any sub-objects are left # as a dictionary instead of being converted to the object (e.g. ArtifactConfig) @@ -64,14 +63,13 @@ def build_definition( # Publish the definition if publish is true if publish: if definition_type == VNF: - deployer = DeployerViaArm(apiClientsAndCaches, - config=config) - output = deployer.deploy_vnfd_from_bicep() + deployer = DeployerViaArm(apiClientsAndCaches, config=config) + deployer.deploy_vnfd_from_bicep() else: print("TODO - cannot publish CNF or NSD yet.") -def generate_definition_config(cmd, definition_type, output_file="input.json"): +def generate_definition_config(_, definition_type, output_file="input.json"): config = get_configuration(definition_type) config_as_dict = json.dumps(asdict(config), indent=4) @@ -88,7 +86,8 @@ def generate_definition_config(cmd, definition_type, output_file="input.json"): def _generate_nfd(definition_type, config): - """_summary_ + """ + _summary_ :param definition_type: _description_ :type definition_type: _type_ @@ -106,25 +105,29 @@ def _generate_nfd(definition_type, config): ) nfd_generator.generate_nfd() - + + def delete_published_definition( cmd, client: HybridNetworkManagementClient, definition_type, config_file, - all=False, + clean=False, ): with open(config_file, "r", encoding="utf-8") as f: config_as_dict = json.loads(f.read()) config = get_configuration(definition_type, config_as_dict) validate_configuration(config) - api_clients = ApiClientsAndCaches(aosm_client=client, - resource_client=cf_resources(cmd.cli_ctx)) + api_clients = ApiClientsAndCaches( + aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) + ) from azext_aosm.delete.delete import ResourceDeleter + delly = ResourceDeleter(api_clients, config) if definition_type == VNF: - delly.delete_vnf(all) + delly.delete_vnf(all=clean) + def show_publisher(): pass diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 943b0f12ba4..45ce6e3887c 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -1,4 +1,3 @@ - # -------------------------------------------------------------------------------------- # Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT # License. See License.txt in the project root for license information. @@ -20,7 +19,7 @@ logger = get_logger(__name__) -class ResourceDeleter(): +class ResourceDeleter: def __init__( self, apiClientsAndCaches: ApiClientsAndCaches, @@ -39,24 +38,32 @@ def __init__( self.config = config def delete_vnf(self, all: bool = False): - """Delete the NFDV and manifests. - + """ + Delete the NFDV and manifests. + :param all: Delete the NFDG, artifact stores and publisher too. defaults to False Use with care. - """ assert isinstance(self.config, VNFConfiguration) if all: - print(f"Are you sure you want to delete all resources associated with NFD {self.config.nf_name} including the artifact stores and publisher {self.config.publisher_name}?") - logger.warning("This command will fail if other NFD versions exist in the NFD group.") - logger.warning("Only do this if you are SURE you are not sharing the publisher and artifact stores with other NFDs") + print( + f"Are you sure you want to delete all resources associated with NFD {self.config.nf_name} including the artifact stores and publisher {self.config.publisher_name}?" + ) + logger.warning( + "This command will fail if other NFD versions exist in the NFD group." + ) + logger.warning( + "Only do this if you are SURE you are not sharing the publisher and artifact stores with other NFDs" + ) print("There is no undo. Type the publisher name to confirm.") if not input_ack(self.config.publisher_name.lower(), "Confirm delete:"): print("Not proceeding with delete") return else: - print(f"Are you sure you want to delete the NFD Version {self.config.version} and associated manifests from group {self.config.nfdg_name} and publisher {self.config.publisher_name}?") + print( + f"Are you sure you want to delete the NFD Version {self.config.version} and associated manifests from group {self.config.nfdg_name} and publisher {self.config.publisher_name}?" + ) print("There is no undo. Type 'delete' to confirm") if not input_ack("delete", "Confirm delete:"): print("Not proceeding with delete") @@ -65,7 +72,7 @@ def delete_vnf(self, all: bool = False): self.delete_nfdv() self.delete_artifact_manifest("sa") self.delete_artifact_manifest("acr") - + if all: logger.info("Delete called for all resources.") self.delete_nfdg() @@ -73,8 +80,6 @@ def delete_vnf(self, all: bool = False): self.delete_artifact_store("sa") self.delete_publisher() - - def delete_nfdv(self): message: str = f"Delete NFDV {self.config.version} from group {self.config.nfdg_name} and publisher {self.config.publisher_name}" logger.debug(message) @@ -84,16 +89,19 @@ def delete_nfdv(self): resource_group_name=self.config.publisher_resource_group_name, publisher_name=self.config.publisher_name, network_function_definition_group_name=self.config.nfdg_name, - network_function_definition_version_name=self.config.version + network_function_definition_version_name=self.config.version, ) poller.result() print("Deleted NFDV.") except Exception: - logger.error(f"Failed to delete NFDV {self.config.version} from group {self.config.nfdg_name}") + logger.error( + f"Failed to delete NFDV {self.config.version} from group {self.config.nfdg_name}" + ) raise - + def delete_artifact_manifest(self, store_type: str) -> None: - """_summary_ + """ + _summary_ :param store_type: "sa" or "acr" :raises CLIInternalError: If called with any other store type @@ -112,7 +120,9 @@ def delete_artifact_manifest(self, store_type: str) -> None: raise CLIInternalError( "Delete artifact manifest called for invalid store type. Valid types are sa and acr." ) - message: str = f"Delete Artifact manifest {manifest_name} from artifact store {store_name}" + message: str = ( + f"Delete Artifact manifest {manifest_name} from artifact store {store_name}" + ) logger.debug(message) print(message) try: @@ -120,32 +130,33 @@ def delete_artifact_manifest(self, store_type: str) -> None: resource_group_name=self.config.publisher_resource_group_name, publisher_name=self.config.publisher_name, artifact_store_name=store_name, - artifact_manifest_name=manifest_name + artifact_manifest_name=manifest_name, ) poller.result() print("Deleted Artifact Manifest") except Exception: - logger.error(f"Failed to delete Artifact manifest {manifest_name} from artifact store {store_name}") + logger.error( + f"Failed to delete Artifact manifest {manifest_name} from artifact store {store_name}" + ) raise - - def delete_nfdg(self)-> None: - """Delete the NFDG - """ + + def delete_nfdg(self) -> None: + """Delete the NFDG.""" message: str = f"Delete NFD Group {self.config.nfdg_name}" logger.debug(message) print(message) try: poller = self.api_clients.aosm_client.network_function_definition_groups.begin_delete( - resource_group_name=self.config.publisher_resource_group_name, + resource_group_name=self.config.publisher_resource_group_name, publisher_name=self.config.publisher_name, - network_function_definition_group_name=self.config.nfdg_name + network_function_definition_group_name=self.config.nfdg_name, ) poller.result() print("Delete NFD Group") except Exception: logger.error(f"Failed to delete NFDG.") raise - + def delete_artifact_store(self, store_type: str) -> None: """Delete an artifact store :param store_type: "sa" or "acr" @@ -170,30 +181,34 @@ def delete_artifact_store(self, store_type: str) -> None: poller = self.api_clients.aosm_client.artifact_stores.begin_delete( resource_group_name=self.config.publisher_resource_group_name, publisher_name=self.config.publisher_name, - artifact_store_name=store_name + artifact_store_name=store_name, ) poller.result() print("Deleted Artifact Store") except Exception: logger.error(f"Failed to delete Artifact store {store_name}") raise - + def delete_publisher(self) -> None: - """Delete the publisher. Warning - dangerous""" + """ + Delete the publisher. + + Warning - dangerous + """ message: str = f"Delete Publisher {self.config.publisher_name}" logger.debug(message) print(message) try: poller = self.api_clients.aosm_client.publishers.begin_delete( resource_group_name=self.config.publisher_resource_group_name, - publisher_name=self.config.publisher_name + publisher_name=self.config.publisher_name, ) poller.result() print("Deleted Publisher") except Exception: logger.error(f"Failed to delete publisher") - raise - + raise + # def delete_resource(self, resource: GenericResourceExpanded) -> bool: # """ # Delete a resource. @@ -236,4 +251,4 @@ def delete_publisher(self) -> None: # logger.info(f"Failed to delete {resource.name} {delEx}") # return False - # return True + # return True diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 1a0ef7d061e..42a655be533 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -11,9 +11,7 @@ from azure.storage.blob import BlobClient from oras.client import OrasClient from azext_aosm._configuration import Configuration, VNFConfiguration -from azext_aosm.vendored_sdks.models import ( - ArtifactAccessCredential, - ArtifactManifest) +from azext_aosm.vendored_sdks.models import ArtifactAccessCredential, ArtifactManifest from azext_aosm.util.management_clients import ApiClientsAndCaches @@ -23,11 +21,13 @@ class ArtifactManifestOperator: """ArtifactManifest class.""" - def __init__(self, - config: Configuration, - api_clients: ApiClientsAndCaches, - store_name: str, - manifest_name: str) -> None: + def __init__( + self, + config: Configuration, + api_clients: ApiClientsAndCaches, + store_name: str, + manifest_name: str, + ) -> None: """Init.""" self.manifest_name = manifest_name self.api_clients = api_clients @@ -39,15 +39,14 @@ def __init__(self, @cached_property def _manifest_credentials(self) -> Any: """Gets the details for uploading the artifacts in the manifest.""" - + return self.api_clients.aosm_client.artifact_manifests.list_credential( resource_group_name=self.config.publisher_resource_group_name, publisher_name=self.config.publisher_name, artifact_store_name=self.store_name, - artifact_manifest_name=self.manifest_name + artifact_manifest_name=self.manifest_name, ).as_dict() - def _oras_client(self, acr_url: str) -> OrasClient: """ Returns an OrasClient object for uploading to the artifact str Returns an OrasClient object for uploading to the artifact store ACR.oe ACR. @@ -65,12 +64,14 @@ def _oras_client(self, acr_url: str) -> OrasClient: def _get_artifact_list(self) -> List[Artifact]: """Get the list of Artifacts in the Artifact Manifest.""" artifacts = [] - - manifest: ArtifactManifest = self.api_clients.aosm_client.artifact_manifests.get( - resource_group_name=self.config.publisher_resource_group_name, - publisher_name=self.config.publisher_name, - artifact_store_name=self.store_name, - artifact_manifest_name=self.manifest_name + + manifest: ArtifactManifest = ( + self.api_clients.aosm_client.artifact_manifests.get( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + artifact_store_name=self.store_name, + artifact_manifest_name=self.manifest_name, + ) ) # Instatiate an Artifact object for each artifact in the manifest. @@ -102,7 +103,7 @@ def _get_artifact_client( :param artifact_name: name of the artifact :param artifact_version: artifact version """ - if self._manifest_credentials["credential_type"] == "AzureStorageAccountToken": + if self._manifest_credentials["credential_type"] == "AzureStorageAccountToken": container_basename = artifact_name.replace("-", "") blob_url = self._get_blob_url(f"{container_basename}-{artifact_version}") return BlobClient.from_blob_url(blob_url) @@ -113,7 +114,7 @@ def _get_blob_url(self, container_name: str) -> str: """ Get the URL for the blob to be uploaded to the storage account artifact store. - :param container_name: name of the container + :param container_name: name of the container """ for container_credential in self._manifest_credentials["container_credentials"]: if container_credential["container_name"] == container_name: diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 9c352b0b86c..adbf0725fda 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -17,7 +17,10 @@ from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK from azext_aosm._configuration import Configuration, VNFConfiguration -from azext_aosm._constants import VNF_DEFINITION_OUTPUT_BICEP_PREFIX, VNF_DEFINITION_BICEP_SOURCE_TEMPLATE +from azext_aosm._constants import ( + VNF_DEFINITION_OUTPUT_BICEP_PREFIX, + VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, +) logger = get_logger(__name__) @@ -44,12 +47,11 @@ def __init__( logger.debug("Create ARM/Bicep Deployer") self.api_clients = apiClientsAndCaches self.config = config - self.pre_deployer = PreDeployerViaSDK( - apiClientsAndCaches, self.config - ) + self.pre_deployer = PreDeployerViaSDK(apiClientsAndCaches, self.config) def deploy_vnfd_from_bicep(self) -> None: - """Deploy the bicep template defining the VNFD. + """ + Deploy the bicep template defining the VNFD. Also ensure that all required predeploy resources are deployed. @@ -57,31 +59,39 @@ def deploy_vnfd_from_bicep(self) -> None: :type bicep_template_path: str """ assert isinstance(self.config, VNFConfiguration) - + # TODO - duplicated from vnf_bicep_nfd_generator and won't work if file exists arm_template_path = self.config.arm_template["file_path"] - folder_name = f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" + folder_name = ( + f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" + ) bicep_template_name = VNF_DEFINITION_BICEP_SOURCE_TEMPLATE bicep_path = os.path.join(folder_name, bicep_template_name) - + parameters = self.construct_vnfd_parameters() logger.debug(parameters) # Create or check required resources self.vnfd_predeploy() self.deploy_bicep_template(bicep_path, parameters) - print(f"Deployed NFD {self.config.nf_name} version {self.config.version} " - f"into {self.config.publisher_resource_group_name} under publisher " - f"{self.config.publisher_name}") - - storage_account_manifest = ArtifactManifestOperator(self.config, - self.api_clients, - self.config.blob_artifact_store_name, - self.config.sa_manifest_name) - acr_manifest = ArtifactManifestOperator(self.config, - self.api_clients, - self.config.acr_artifact_store_name, - self.config.acr_manifest_name) + print( + f"Deployed NFD {self.config.nf_name} version {self.config.version} " + f"into {self.config.publisher_resource_group_name} under publisher " + f"{self.config.publisher_name}" + ) + + storage_account_manifest = ArtifactManifestOperator( + self.config, + self.api_clients, + self.config.blob_artifact_store_name, + self.config.sa_manifest_name, + ) + acr_manifest = ArtifactManifestOperator( + self.config, + self.api_clients, + self.config.acr_artifact_store_name, + self.config.acr_manifest_name, + ) vhd_artifact = storage_account_manifest.artifacts[0] arm_template_artifact = acr_manifest.artifacts[0] @@ -91,7 +101,6 @@ def deploy_vnfd_from_bicep(self) -> None: print("Uploading ARM template artifact") arm_template_artifact.upload(self.config.arm_template) print("Done") - def vnfd_predeploy(self): """ diff --git a/src/aosm/azext_aosm/deploy/deploy_with_sdk.py b/src/aosm/azext_aosm/deploy/deploy_with_sdk.py index 4ba73156e8c..0715a4b4b32 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_sdk.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_sdk.py @@ -22,9 +22,10 @@ class DeployerViaSDK: """A class to deploy Artifact Manifests, NFDs and NSDs using the python SDK.""" + # @@@TODO - not sure this class is required as we can't publish complex objects # using the SDK - + def __init__( self, aosm_client: HybridNetworkManagementClient, @@ -42,7 +43,7 @@ def __init__( self.aosm_client = aosm_client self.resource_client = resource_client self.pre_deployer = PreDeployerViaSDK(aosm_client, resource_client) - + def publish_artifact_manifest( self, resource_group_name: str, @@ -74,10 +75,7 @@ def publish_artifact_manifest( artifact_types = [a.artifact_type for a in artifact_manifest.artifacts] - if ( - ArtifactType.VHD_IMAGE_FILE - or ArtifactType.IMAGE_FILE in artifact_types - ): + if ArtifactType.VHD_IMAGE_FILE or ArtifactType.IMAGE_FILE in artifact_types: artifact_store_type = ArtifactStoreType.AZURE_STORAGE_ACCOUNT else: artifact_store_type = ArtifactStoreType.AZURE_CONTAINER_REGISTRY @@ -98,7 +96,7 @@ def publish_artifact_manifest( artifact_manifest_name=artifact_manifest.name, parameters=artifact_manifest, ) - + def publish_network_function_definition_version( self, resource_group_name: str, diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 3cbe97c7494..a4e332f5b34 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -8,9 +8,7 @@ from azure.core import exceptions as azure_exceptions from azure.cli.core.azclierror import AzCLIError -from azure.mgmt.resource.resources.v2022_09_01.models import ( - ResourceGroup -) +from azure.mgmt.resource.resources.v2022_09_01.models import ResourceGroup from azure.mgmt.resource import ResourceManagementClient from azext_aosm.util.management_clients import ApiClientsAndCaches @@ -47,11 +45,11 @@ def __init__( self.api_clients = apiClientsAndCaches self.config = config - - def ensure_resource_group_exists(self, resource_group_name: str)-> None: + + def ensure_resource_group_exists(self, resource_group_name: str) -> None: """ Checks whether a particular resource group exists on the subscription. - Copied from virtutils + Copied from virtutils. :param resource_group_name: The name of the resource group @@ -59,15 +57,21 @@ def ensure_resource_group_exists(self, resource_group_name: str)-> None: Raises a PermissionsError exception if we don't have permissions to check resource group existence. """ rg: ResourceGroup - if not self.api_clients.resource_client.resource_groups.check_existence(resource_group_name): + if not self.api_clients.resource_client.resource_groups.check_existence( + resource_group_name + ): logger.info(f"RG {resource_group_name} not found. Create it.") print(f"Creating resource group {resource_group_name}.") rg_params: ResourceGroup = ResourceGroup(location=self.config.location) - rg = self.api_clients.resource_client.resource_groups.create_or_update(resource_group_name, rg_params) + rg = self.api_clients.resource_client.resource_groups.create_or_update( + resource_group_name, rg_params + ) else: print(f"Resource group {resource_group_name} exists.") - rg = self.api_clients.resource_client.resource_groups.get(resource_group_name) - + rg = self.api_clients.resource_client.resource_groups.get( + resource_group_name + ) + def ensure_config_resource_group_exists(self) -> None: """ Ensures that the publisher exists in the resource group. @@ -76,7 +80,6 @@ def ensure_config_resource_group_exists(self) -> None: """ self.ensure_resource_group_exists(self.config.publisher_resource_group_name) - def ensure_publisher_exists( self, resource_group_name: str, publisher_name: str, location: str ) -> None: @@ -90,15 +93,19 @@ def ensure_publisher_exists( :param location: The location of the publisher. :type location: str """ - logger.info( - "Creating publisher %s if it does not exist", publisher_name - ) + logger.info("Creating publisher %s if it does not exist", publisher_name) try: - pubby = self.api_clients.aosm_client.publishers.get(resource_group_name, publisher_name) - print(f"Publisher {pubby.name} exists in resource group {resource_group_name}") + pubby = self.api_clients.aosm_client.publishers.get( + resource_group_name, publisher_name + ) + print( + f"Publisher {pubby.name} exists in resource group {resource_group_name}" + ) except azure_exceptions.ResourceNotFoundError: # Create the publisher - print(f"Creating publisher {publisher_name} in resource group {resource_group_name}") + print( + f"Creating publisher {publisher_name} in resource group {resource_group_name}" + ) pub = self.api_clients.aosm_client.publishers.begin_create_or_update( resource_group_name=resource_group_name, publisher_name=publisher_name, @@ -106,16 +113,17 @@ def ensure_publisher_exists( ) pub.result() - def ensure_config_publisher_exists(self) -> None: """ Ensures that the publisher exists in the resource group. Finds the parameters from self.config """ - self.ensure_publisher_exists(resource_group_name=self.config.publisher_resource_group_name, - publisher_name=self.config.publisher_name, - location=self.config.location) + self.ensure_publisher_exists( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + location=self.config.location, + ) def ensure_artifact_store_exists( self, @@ -144,20 +152,28 @@ def ensure_artifact_store_exists( artifact_store_name, ) try: - self.api_clients.aosm_client.artifact_stores.get(resource_group_name=resource_group_name, - publisher_name=publisher_name, - artifact_store_name=artifact_store_name) - print(f"Artifact store {artifact_store_name} exists in resource group {resource_group_name}") - except azure_exceptions.ResourceNotFoundError: - print(f"Create Artifact Store {artifact_store_name} of type {artifact_store_type}") - poller = self.api_clients.aosm_client.artifact_stores.begin_create_or_update( + self.api_clients.aosm_client.artifact_stores.get( resource_group_name=resource_group_name, publisher_name=publisher_name, artifact_store_name=artifact_store_name, - parameters=ArtifactStore( - location=location, - store_type=artifact_store_type, - ), + ) + print( + f"Artifact store {artifact_store_name} exists in resource group {resource_group_name}" + ) + except azure_exceptions.ResourceNotFoundError: + print( + f"Create Artifact Store {artifact_store_name} of type {artifact_store_type}" + ) + poller = ( + self.api_clients.aosm_client.artifact_stores.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + parameters=ArtifactStore( + location=location, + store_type=artifact_store_type, + ), + ) ) # Asking for result waits for provisioning state Succeeded before carrying # on @@ -181,12 +197,13 @@ def ensure_acr_artifact_store_exists(self) -> None: Finds the parameters from self.config """ - self.ensure_artifact_store_exists(self.config.publisher_resource_group_name, - self.config.publisher_name, - self.config.acr_artifact_store_name, - ArtifactStoreType.AZURE_CONTAINER_REGISTRY, - self.config.location) - + self.ensure_artifact_store_exists( + self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.acr_artifact_store_name, + ArtifactStoreType.AZURE_CONTAINER_REGISTRY, + self.config.location, + ) def ensure_sa_artifact_store_exists(self) -> None: """ @@ -199,11 +216,13 @@ def ensure_sa_artifact_store_exists(self) -> None: "Check that storage account artifact store exists failed as requires VNFConfiguration file" ) - self.ensure_artifact_store_exists(self.config.publisher_resource_group_name, - self.config.publisher_name, - self.config.blob_artifact_store_name, - ArtifactStoreType.AZURE_STORAGE_ACCOUNT, - self.config.location) + self.ensure_artifact_store_exists( + self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.blob_artifact_store_name, + ArtifactStoreType.AZURE_STORAGE_ACCOUNT, + self.config.location, + ) def ensure_nfdg_exists( self, @@ -235,7 +254,7 @@ def ensure_nfdg_exists( network_function_definition_group_name=nfdg_name, parameters=NetworkFunctionDefinitionGroup(location=location), ) - + def ensure_config_nfdg_exists( self, ): @@ -244,10 +263,12 @@ def ensure_config_nfdg_exists( Finds the parameters from self.config """ - self.ensure_nfdg_exists(self.config.publisher_resource_group_name, - self.config.publisher_name, - self.config.nfdg_name, - self.config.location) + self.ensure_nfdg_exists( + self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.nfdg_name, + self.config.location, + ) def ensure_nsdg_exists( self, @@ -279,10 +300,10 @@ def ensure_nsdg_exists( network_service_design_group_name=nsdg_name, parameters=NetworkServiceDesignGroup(location=location), ) - + def resource_exists_by_name(self, rg_name: str, resource_name: str) -> bool: """ - Determine if a resource with the given name exists. No checking is done as + Determine if a resource with the given name exists. No checking is done as to the type. :param resource_name: The name of the resource to check. diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 623f35f1f8f..df7afef18dc 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -6,16 +6,16 @@ from typing import Dict, Any from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator + class CnfNfdGenerator(NFDGenerator): - """_summary_ + """ + _summary_ :param NFDGenerator: _description_ :type NFDGenerator: _type_ """ - def __init__( - self, - config: Dict[Any, Any] - ): + + def __init__(self, config: Dict[Any, Any]): super(NFDGenerator, self).__init__( config=config, ) diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index 3458ad8e0c8..2408972bc34 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -9,24 +9,25 @@ logger = get_logger(__name__) + class NFDGenerator: """A class for generating an NFD from a config file.""" def __init__( self, - #config: Configuration + # config: Configuration ) -> None: - """_summary_ + """ + _summary_ :param definition_type: _description_ :type definition_type: str :param config: _description_ :type config: Configuration """ - #self.config = config + # self.config = config def generate_nfd(self) -> None: - """No-op on base class - """ + """No-op on base class.""" logger.error("Generate NFD called on base class. No-op") return diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 6ed9738bb6f..60ca960f63c 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -28,7 +28,8 @@ class VnfBicepNfdGenerator(NFDGenerator): - """_summary_ + """ + _summary_ :param NFDGenerator: _description_ :type NFDGenerator: _type_ @@ -50,9 +51,9 @@ def generate_nfd(self) -> None: """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" # assert isinstance(self.config, VNFConfiguration) if self.bicep_path: - print(f"Using the existing NFD bicep template {self.bicep_path}." ) + print(f"Using the existing NFD bicep template {self.bicep_path}.") print( - f'To generate a new NFD, delete the folder {os.path.dirname(self.bicep_path)} and re-run this command.' + f"To generate a new NFD, delete the folder {os.path.dirname(self.bicep_path)} and re-run this command." ) else: self.write() @@ -134,13 +135,13 @@ def write_deployment_parameters(self, folder_path: str) -> None: deployment_parameters_path = os.path.join( folder_path, "deploymentParameters.json" ) - + # Heading for the deployParameters schema deploy_parameters_full: Dict[str, Any] = { "$schema": "https://json-schema.org/draft-07/schema#", "title": "DeployParametersSchema", "type": "object", - "properties": nfd_parameters + "properties": nfd_parameters, } with open(deployment_parameters_path, "w") as _file: diff --git a/src/aosm/azext_aosm/publisher_resources/publisher_resources.py b/src/aosm/azext_aosm/publisher_resources/publisher_resources.py index 2bde15ca9aa..c2a93b785db 100644 --- a/src/aosm/azext_aosm/publisher_resources/publisher_resources.py +++ b/src/aosm/azext_aosm/publisher_resources/publisher_resources.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- -"""Shared publisher resources""" +"""Shared publisher resources.""" from dataclasses import dataclass from knack.log import get_logger from azext_aosm.vendored_sdks.models import NetworkFunctionDefinitionGroup @@ -19,7 +19,8 @@ class PublisherResourceGenerator: config: Configuration def generate_nfd_group(self) -> NetworkFunctionDefinitionGroup: - """Generate a NFD group with location and description from config. + """ + Generate a NFD group with location and description from config. :return: _description_ :rtype: NetworkFunctionDefinitionGroup diff --git a/src/aosm/azext_aosm/test.py b/src/aosm/azext_aosm/test.py index edaf2e5caef..4c914d0dc3c 100644 --- a/src/aosm/azext_aosm/test.py +++ b/src/aosm/azext_aosm/test.py @@ -1,35 +1,38 @@ from azext_aosm.vendored_sdks import HybridNetworkManagementClient from azext_aosm.vendored_sdks.models import ( - NetworkFunctionDefinitionVersion, - NetworkFunctionDefinitionGroup, - ArtifactManifest, - ManifestArtifactFormat, - VersionState, + NetworkFunctionDefinitionVersion, + NetworkFunctionDefinitionGroup, + ArtifactManifest, + ManifestArtifactFormat, + VersionState, NetworkFunctionType, NFVIType, ArtifactType, - VirtualNetworkFunctionDefinitionVersion, # this is actually properties, badly named + VirtualNetworkFunctionDefinitionVersion, # this is actually properties, badly named AzureCoreNetworkFunctionTemplate, AzureCoreNetworkFunctionVhdApplication, - AzureCoreNetworkFunctionArmTemplateApplication + AzureCoreNetworkFunctionArmTemplateApplication, ) vnf_props = VirtualNetworkFunctionDefinitionVersion( version_state=VersionState.PREVIEW, - deploy_parameters= "TODO", + deploy_parameters="TODO", network_function_template=AzureCoreNetworkFunctionTemplate( - network_function_applications= [ + network_function_applications=[ AzureCoreNetworkFunctionVhdApplication(), - AzureCoreNetworkFunctionArmTemplateApplication() + AzureCoreNetworkFunctionArmTemplateApplication(), ] -)) + ), +) -#test_dict = dict(**vnf_props) +# test_dict = dict(**vnf_props) print(vnf_props.__dict__) -nfdv = NetworkFunctionDefinitionVersion(location="uksouth", - #network_function_type="VirtualNetworkFunction", - # Think kwargs map magically to properties in bicep, somehow - **vnf_props.__dict__) +nfdv = NetworkFunctionDefinitionVersion( + location="uksouth", + # network_function_type="VirtualNetworkFunction", + # Think kwargs map magically to properties in bicep, somehow + **vnf_props.__dict__ +) print(nfdv) diff --git a/src/aosm/azext_aosm/tests/__init__.py b/src/aosm/azext_aosm/tests/__init__.py index 2dcf9bb68b3..99c0f28cd71 100644 --- a/src/aosm/azext_aosm/tests/__init__.py +++ b/src/aosm/azext_aosm/tests/__init__.py @@ -2,4 +2,4 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for # license information. -# ----------------------------------------------------------------------------- \ No newline at end of file +# ----------------------------------------------------------------------------- diff --git a/src/aosm/azext_aosm/tests/latest/__init__.py b/src/aosm/azext_aosm/tests/latest/__init__.py index 2dcf9bb68b3..99c0f28cd71 100644 --- a/src/aosm/azext_aosm/tests/latest/__init__.py +++ b/src/aosm/azext_aosm/tests/latest/__init__.py @@ -2,4 +2,4 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for # license information. -# ----------------------------------------------------------------------------- \ No newline at end of file +# ----------------------------------------------------------------------------- diff --git a/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py b/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py index a8b6975181d..0bc37d2e16e 100644 --- a/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py +++ b/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py @@ -7,34 +7,34 @@ import unittest # from azure_devtools.scenario_tests import AllowLargeResponse -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) +TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), "..")) class AosmScenarioTest(ScenarioTest): - - @ResourceGroupPreparer(name_prefix='cli_test_aosm') + @ResourceGroupPreparer(name_prefix="cli_test_aosm") def test_aosm(self, resource_group): - - self.kwargs.update({ - 'name': 'test1' - }) - - self.cmd('aosm create -g {rg} -n {name} --tags foo=doo', checks=[ - self.check('tags.foo', 'doo'), - self.check('name', '{name}') - ]) - self.cmd('aosm update -g {rg} -n {name} --tags foo=boo', checks=[ - self.check('tags.foo', 'boo') - ]) - count = len(self.cmd('aosm list').get_output_in_json()) - self.cmd('aosm show - {rg} -n {name}', checks=[ - self.check('name', '{name}'), - self.check('resourceGroup', '{rg}'), - self.check('tags.foo', 'boo') - ]) - self.cmd('aosm delete -g {rg} -n {name}') - final_count = len(self.cmd('aosm list').get_output_in_json()) + self.kwargs.update({"name": "test1"}) + + self.cmd( + "aosm create -g {rg} -n {name} --tags foo=doo", + checks=[self.check("tags.foo", "doo"), self.check("name", "{name}")], + ) + self.cmd( + "aosm update -g {rg} -n {name} --tags foo=boo", + checks=[self.check("tags.foo", "boo")], + ) + count = len(self.cmd("aosm list").get_output_in_json()) + self.cmd( + "aosm show - {rg} -n {name}", + checks=[ + self.check("name", "{name}"), + self.check("resourceGroup", "{rg}"), + self.check("tags.foo", "boo"), + ], + ) + self.cmd("aosm delete -g {rg} -n {name}") + final_count = len(self.cmd("aosm list").get_output_in_json()) self.assertTrue(final_count, count - 1) diff --git a/src/aosm/azext_aosm/util/management_clients.py b/src/aosm/azext_aosm/util/management_clients.py index 86432531a45..541b6686fbb 100644 --- a/src/aosm/azext_aosm/util/management_clients.py +++ b/src/aosm/azext_aosm/util/management_clients.py @@ -9,27 +9,30 @@ from azure.mgmt.resource import ResourceManagementClient from azext_aosm.vendored_sdks import HybridNetworkManagementClient from typing import Dict, Optional -from azure.mgmt.resource.resources.v2022_09_01.models import ( - Provider -) +from azure.mgmt.resource.resources.v2022_09_01.models import Provider logger = get_logger(__name__) + @dataclass class ProviderInfo: - """Class to return Provider Info information""" + """Class to return Provider Info information.""" + namespace: str resource_type: str class ApiClientsAndCaches: - """A cache for API Clients and API versions for various resources. - """ - - def __init__(self, aosm_client: HybridNetworkManagementClient, resource_client: ResourceManagementClient): + """A cache for API Clients and API versions for various resources.""" + + def __init__( + self, + aosm_client: HybridNetworkManagementClient, + resource_client: ResourceManagementClient, + ): self.aosm_client = aosm_client self.resource_client = resource_client - + # We need to find an Azure API version relevant to each resource type. This is # used in resource finding. We just use the latest and cache these as they are # expensive to query. @@ -37,87 +40,87 @@ def __init__(self, aosm_client: HybridNetworkManagementClient, resource_client: self.providers_cache: Dict[str, Provider] = {} def find_latest_api_ver_for_resource_type( - self, resource_type: str - ) -> Optional[str]: - """ - Copied from virtutils. Turns out maybe not needed yet. Expect we will need - when we want to delete resources. - - Find the latest Azure API version for a given resource. - - We do this querying the Azure Providers API - - We just use the latest and cache these as they are expensive to query. - - param: resource_type: String in the format that the providers API uses e.g. - Microsoft.Compute/disks or Microsoft.Compute/virtualMachines/extensions - - Find the namespace and resource type in the format that the providers - API uses by splitting the resource type returned from list_by_resource_group - at the first forward-slash (/), - e.g. Microsoft.Compute/disks would give us namespace Microsoft.Compute and - provider resource type disks - whereas Microsoft.Compute/virtualMachines/extensions would give us - namespace Microsoft.Compute and provicer resource type - virtualMachines/extensions. This seems to match what the provider API - uses. - - We cache values as this can take a few seconds to return. - - :param resource: A resource, as returned from list_by_resource_group - :raises RuntimeError: If no provider found in Azure for this resource - :raises RuntimeError: If the resource type is an unexpected format - """ - logger.debug(f"Find API version for {resource_type}") - # We need to find an API version relevant to the resource. - if resource_type in self.resource_type_api_versions_cache.keys(): - # We have one cached, just return that - logger.debug("Return cached API version") - return self.resource_type_api_versions_cache.get(resource_type) - - # Start with e.g. Microsoft.Compute/disks (resource_type) - assert resource_type is not None - prov_info = self.get_provider_info(resource_type) - # We now have Microsoft.Compute and disks - if prov_info.namespace not in self.providers_cache.keys(): - # Get the provider e.g. Microsoft.Compute - logger.debug(f"Find provider {prov_info.namespace}") - try: - provider = self.resource_client.providers.get(prov_info.namespace) - except Exception as provEx: - raise RuntimeError( - f"Could not find provider {prov_info.namespace} required " - f"to query resource of type {resource_type}. Aborting" - ) from provEx - - self.providers_cache[prov_info.namespace] = provider - else: - # Resource type that we haven't found before but the provider is cached - # so use that. - provider = self.providers_cache[prov_info.namespace] - - # Iterate through the providers resource types and find the one - # we want, e.g. disks or virtualMachines/extensions - for res_type in provider.resource_types: - if res_type.resource_type == prov_info.resource_type: - # Find the latest API version and cache it - # The first index appears to always be the latest version - api_version = res_type.api_versions[0] - logger.debug(f"Use API version {api_version} for {resource_type}") - - assert resource_type is not None - self.resource_type_api_versions_cache[resource_type] = api_version - return api_version - - raise RuntimeError( - f"Azure API did not return an API version for {resource_type}." - f"Cannot query API version" - ) - + self, resource_type: str + ) -> Optional[str]: + """ + Copied from virtutils. Turns out maybe not needed yet. Expect we will need + when we want to delete resources. + + Find the latest Azure API version for a given resource. + + We do this querying the Azure Providers API + + We just use the latest and cache these as they are expensive to query. + + param: resource_type: String in the format that the providers API uses e.g. + Microsoft.Compute/disks or Microsoft.Compute/virtualMachines/extensions + + Find the namespace and resource type in the format that the providers + API uses by splitting the resource type returned from list_by_resource_group + at the first forward-slash (/), + e.g. Microsoft.Compute/disks would give us namespace Microsoft.Compute and + provider resource type disks + whereas Microsoft.Compute/virtualMachines/extensions would give us + namespace Microsoft.Compute and provicer resource type + virtualMachines/extensions. This seems to match what the provider API + uses. + + We cache values as this can take a few seconds to return. + + :param resource: A resource, as returned from list_by_resource_group + :raises RuntimeError: If no provider found in Azure for this resource + :raises RuntimeError: If the resource type is an unexpected format + """ + logger.debug(f"Find API version for {resource_type}") + # We need to find an API version relevant to the resource. + if resource_type in self.resource_type_api_versions_cache.keys(): + # We have one cached, just return that + logger.debug("Return cached API version") + return self.resource_type_api_versions_cache.get(resource_type) + + # Start with e.g. Microsoft.Compute/disks (resource_type) + assert resource_type is not None + prov_info = self.get_provider_info(resource_type) + # We now have Microsoft.Compute and disks + if prov_info.namespace not in self.providers_cache.keys(): + # Get the provider e.g. Microsoft.Compute + logger.debug(f"Find provider {prov_info.namespace}") + try: + provider = self.resource_client.providers.get(prov_info.namespace) + except Exception as provEx: + raise RuntimeError( + f"Could not find provider {prov_info.namespace} required " + f"to query resource of type {resource_type}. Aborting" + ) from provEx + + self.providers_cache[prov_info.namespace] = provider + else: + # Resource type that we haven't found before but the provider is cached + # so use that. + provider = self.providers_cache[prov_info.namespace] + + # Iterate through the providers resource types and find the one + # we want, e.g. disks or virtualMachines/extensions + for res_type in provider.resource_types: + if res_type.resource_type == prov_info.resource_type: + # Find the latest API version and cache it + # The first index appears to always be the latest version + api_version = res_type.api_versions[0] + logger.debug(f"Use API version {api_version} for {resource_type}") + + assert resource_type is not None + self.resource_type_api_versions_cache[resource_type] = api_version + return api_version + + raise RuntimeError( + f"Azure API did not return an API version for {resource_type}." + f"Cannot query API version" + ) + def get_provider_info(self, resource_type: str) -> ProviderInfo: """ Find provider namespace and resource_type, given a full resource_type. - + param: resource_type: String in the format that the providers API uses e.g. Microsoft.Compute/disks or Microsoft.Compute/virtualMachines/extensions @@ -137,5 +140,5 @@ def get_provider_info(self, resource_type: str) -> ProviderInfo: f"Azure resource type {resource_type} " "is in unexpected format. Cannot find API version." ) - #print(f"Namespace {prov_namespace_type[0]} type {prov_namespace_type[1]}") + # print(f"Namespace {prov_namespace_type[0]} type {prov_namespace_type[1]}") return ProviderInfo(prov_namespace_type[0], prov_namespace_type[1]) diff --git a/src/aosm/azext_aosm/util/utils.py b/src/aosm/azext_aosm/util/utils.py index da6fe2f59ee..93e42f28dd0 100644 --- a/src/aosm/azext_aosm/util/utils.py +++ b/src/aosm/azext_aosm/util/utils.py @@ -4,6 +4,7 @@ # -------------------------------------------------------------------------------------------- """Utility functions.""" + def input_ack(ack: str, request_to_user: str) -> bool: """ Overarching function to request, sanitise and return True if input is specified ack. From 16258526b8b9b127ad4003075c464fc0025f0d61 Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Thu, 4 May 2023 15:11:18 +0100 Subject: [PATCH 018/145] add psudo code for CNF generation --- .../generate_nfd/cnf_nfd_generator.py | 76 ++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index df7afef18dc..331a29f0886 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -3,8 +3,13 @@ # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- """Contains a class for generating VNF NFDs and associated resources.""" -from typing import Dict, Any +import os +from typing import Dict, List, Any, Tuple from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator +from knack.log import get_logger +from azext_aosm.vendored_sdks.models import AzureArcKubernetesHelmApplication + +logger = get_logger(__name__) class CnfNfdGenerator(NFDGenerator): @@ -19,3 +24,72 @@ def __init__(self, config: Dict[Any, Any]): super(NFDGenerator, self).__init__( config=config, ) + + def generate_nfd(self): + pass + + def write(self): + pass + + def _create_nfd_folder(self): + pass + + def generate_nf_applications( + self, helm_packages_config: List[Any] + ) -> List[Dict[str, Any]]: + # This will mostly call the functions below. + nf_applications = [] + + for helm_package in helm_packages_config: + nf_applications.append(self.generate_nf_application(helm_package)) + return nf_applications + + def generate_nf_application( + self, helm_package: Dict[Any, Any] + ) -> Dict[str, Any]: + (name, version) = self.get_chart_name_and_version(helm_package) + return { + "artifactType": "HelmPackage", + "name": helm_package["name"], + "dependsOnProfile": helm_package["dependsOnProfile"], + "artifactProfile": { + "artifactStore": {"id": "acrArtifactStore.id"}, + "helmArtifactProfile": { + "helmPackageName": name, + "helmPackageVersionRange": version, + "registryValuesPaths": [ + "'global.registry.docker.repoPath'" + ], + "imagePullSecretsValuesPaths": [ + "'global.registry.docker.imagePullSecrets'" + ], + }, + }, + "deployParametersMappingRuleProfile": { + "applicationEnablement": "'Enabled'", + "helmMappingRuleProfile": { + "releaseNamespace": "'PACKAGE_NAME'", + "releaseName": "'PACKAGE_NAME'", + "helmPackageVersion": "'PACKAGE_VERSION'", + "values": self.generate_parmeter_mappings(), + }, + }, + } + + def generate_deployment_parameters_schema(self): + # We need to take the parameters requested by the mapping file (values.nondef.yaml) + # and generate the deployment parameters schema based on values.schema.json. + # Basically take the bits of the schema that are relevant to the parameters requested. + pass + + def get_chart_name_and_version(self, helm_package: Dict[Any, Any]) -> Tuple[str, str]: + # We need to get the chart name and version from the Chart.yaml file. + return ("chart_name", "chart_version") + + def some_fun_to_check_ragistry_and_image_secret_path(self): + # Need to work out what we are doing here??? + pass + + def generate_parmeter_mappings(self) -> str: + # Basically copy the values.nondef.yaml file to the right place. + pass From 18d00d08914cdec0d75af2bb2da17576be155ca9 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Thu, 4 May 2023 16:31:38 +0100 Subject: [PATCH 019/145] Fix up json config -> VNFConfiguration --- src/aosm/azext_aosm/_configuration.py | 28 ++++++++++++++----- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 10 +++---- .../generate_nfd/vnf_bicep_nfd_generator.py | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index e601b6308d7..cd5a6ed3116 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,5 +1,5 @@ from dataclasses import dataclass -from typing import Optional +from typing import Optional, Any from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError from ._constants import VNF, CNF, NSD @@ -48,8 +48,21 @@ class VNFConfiguration(Configuration): blob_artifact_store_name: str = ( "Name of the storage account Artifact Store resource" ) - arm_template: ArtifactConfig = ArtifactConfig() - vhd: ArtifactConfig = ArtifactConfig() + arm_template: Any = ArtifactConfig() + vhd: Any = ArtifactConfig() + + def __post_init__(self): + """ + Cope with deserializing subclasses from dicts to ArtifactConfig. + + Used when creating VNFConfiguration object from a loaded json config file. + """ + if isinstance(self.arm_template, dict): + self.arm_template = ArtifactConfig(**self.arm_template) + + if isinstance(self.vhd, dict): + self.vhd = ArtifactConfig(**self.vhd) + @property def sa_manifest_name(self) -> str: @@ -58,9 +71,10 @@ def sa_manifest_name(self) -> str: def get_configuration(definition_type, config_as_dict=None) -> Configuration: + if config_as_dict is None: config_as_dict = {} - # TODO - fix up the fact that ArtifactConfig remains as a Dict. + if definition_type == VNF: config = VNFConfiguration(**config_as_dict) elif definition_type == CNF: @@ -86,14 +100,14 @@ def validate_configuration(config: Configuration) -> None: # had good error messages I'd say let the service do the validation. But it would # certainly be quicker to catch here. if isinstance(config, VNFConfiguration): - if "." in config.vhd["version"] or "-" not in config.vhd["version"]: + if "." in config.vhd.version or "-" not in config.vhd.version: # Not sure about raising this particular one. raise ValidationError( "Config validation error. VHD artifact version should be in format A-B-C" ) if ( - "." not in config.arm_template["version"] - or "-" in config.arm_template["version"] + "." not in config.arm_template.version + or "-" in config.arm_template.version ): raise ValidationError( "Config validation error. ARM template artifact version should be in format A.B.C" diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index adbf0725fda..c669578b5c4 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -61,7 +61,7 @@ def deploy_vnfd_from_bicep(self) -> None: assert isinstance(self.config, VNFConfiguration) # TODO - duplicated from vnf_bicep_nfd_generator and won't work if file exists - arm_template_path = self.config.arm_template["file_path"] + arm_template_path = self.config.arm_template.file_path folder_name = ( f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" ) @@ -131,10 +131,10 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: "nfName": {"value": self.config.nf_name}, "nfDefinitionGroup": {"value": self.config.nfdg_name}, "nfDefinitionVersion": {"value": self.config.version}, - "vhdName": {"value": self.config.vhd["artifact_name"]}, - "vhdVersion": {"value": self.config.vhd["version"]}, - "armTemplateName": {"value": self.config.arm_template["artifact_name"]}, - "armTemplateVersion": {"value": self.config.arm_template["version"]}, + "vhdName": {"value": self.config.vhd.artifact_name}, + "vhdVersion": {"value": self.config.vhd.version.}, + "armTemplateName": {"value": self.config.arm_template.artifact_name}, + "armTemplateVersion": {"value": self.config.arm_template.version}, } def deploy_bicep_template( diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 60ca960f63c..5547cd1aa16 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -42,7 +42,7 @@ def __init__(self, config: VNFConfiguration): self.config = config self.bicep_template_name = VNF_DEFINITION_BICEP_SOURCE_TEMPLATE - self.arm_template_path = self.config.arm_template["file_path"] + self.arm_template_path = self.config.arm_template.file_path self.folder_name = f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(self.arm_template_path)).stem}" self._bicep_path = os.path.join(self.folder_name, self.bicep_template_name) From 1b77c7ef50b0796acf3fdb0a1692b65b64aaff93 Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Thu, 4 May 2023 15:11:18 +0100 Subject: [PATCH 020/145] add psudo code for CNF generation --- .../generate_nfd/cnf_nfd_generator.py | 76 ++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index df7afef18dc..331a29f0886 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -3,8 +3,13 @@ # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- """Contains a class for generating VNF NFDs and associated resources.""" -from typing import Dict, Any +import os +from typing import Dict, List, Any, Tuple from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator +from knack.log import get_logger +from azext_aosm.vendored_sdks.models import AzureArcKubernetesHelmApplication + +logger = get_logger(__name__) class CnfNfdGenerator(NFDGenerator): @@ -19,3 +24,72 @@ def __init__(self, config: Dict[Any, Any]): super(NFDGenerator, self).__init__( config=config, ) + + def generate_nfd(self): + pass + + def write(self): + pass + + def _create_nfd_folder(self): + pass + + def generate_nf_applications( + self, helm_packages_config: List[Any] + ) -> List[Dict[str, Any]]: + # This will mostly call the functions below. + nf_applications = [] + + for helm_package in helm_packages_config: + nf_applications.append(self.generate_nf_application(helm_package)) + return nf_applications + + def generate_nf_application( + self, helm_package: Dict[Any, Any] + ) -> Dict[str, Any]: + (name, version) = self.get_chart_name_and_version(helm_package) + return { + "artifactType": "HelmPackage", + "name": helm_package["name"], + "dependsOnProfile": helm_package["dependsOnProfile"], + "artifactProfile": { + "artifactStore": {"id": "acrArtifactStore.id"}, + "helmArtifactProfile": { + "helmPackageName": name, + "helmPackageVersionRange": version, + "registryValuesPaths": [ + "'global.registry.docker.repoPath'" + ], + "imagePullSecretsValuesPaths": [ + "'global.registry.docker.imagePullSecrets'" + ], + }, + }, + "deployParametersMappingRuleProfile": { + "applicationEnablement": "'Enabled'", + "helmMappingRuleProfile": { + "releaseNamespace": "'PACKAGE_NAME'", + "releaseName": "'PACKAGE_NAME'", + "helmPackageVersion": "'PACKAGE_VERSION'", + "values": self.generate_parmeter_mappings(), + }, + }, + } + + def generate_deployment_parameters_schema(self): + # We need to take the parameters requested by the mapping file (values.nondef.yaml) + # and generate the deployment parameters schema based on values.schema.json. + # Basically take the bits of the schema that are relevant to the parameters requested. + pass + + def get_chart_name_and_version(self, helm_package: Dict[Any, Any]) -> Tuple[str, str]: + # We need to get the chart name and version from the Chart.yaml file. + return ("chart_name", "chart_version") + + def some_fun_to_check_ragistry_and_image_secret_path(self): + # Need to work out what we are doing here??? + pass + + def generate_parmeter_mappings(self) -> str: + # Basically copy the values.nondef.yaml file to the right place. + pass From 0d15355e8d16a82134d6f63c0d197ff417080bbb Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Fri, 5 May 2023 11:45:31 +0100 Subject: [PATCH 021/145] Add CNFConfiguration --- src/aosm/azext_aosm/_configuration.py | 28 ++++++++++++++----- src/aosm/azext_aosm/custom.py | 2 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 2 +- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index cd5a6ed3116..0bcd9eaedeb 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,5 +1,5 @@ -from dataclasses import dataclass -from typing import Optional, Any +from dataclasses import dataclass, field +from typing import Optional, Any, List from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError from ._constants import VNF, CNF, NSD @@ -63,11 +63,25 @@ def __post_init__(self): if isinstance(self.vhd, dict): self.vhd = ArtifactConfig(**self.vhd) +@dataclass +class HelmPackageConfig: + name: str = "Name of the Helm package" + path_to_chart: str = "Path to the Helm chart" + depends_on: List[str] = field(default_factory=lambda: ["Names of the Helm packages this package depends on"]) - @property - def sa_manifest_name(self) -> str: - """Return the Storage account manifest name from the NFD name.""" - return f"{self.nf_name}-sa-manifest-{self.version.replace('.', '-')}" +@dataclass +class CNFConfiguration(Configuration): + helm_packages: List[Any] = field(default_factory=lambda: [HelmPackageConfig()]) + + def __post_init__(self): + """ + Cope with deserializing subclasses from dicts to HelmPackageConfig. + + Used when creating CNFConfiguration object from a loaded json config file. + """ + for package in self.helm_packages: + if isinstance(package, dict): + package = HelmPackageConfig(**dict(package)) def get_configuration(definition_type, config_as_dict=None) -> Configuration: @@ -78,7 +92,7 @@ def get_configuration(definition_type, config_as_dict=None) -> Configuration: if definition_type == VNF: config = VNFConfiguration(**config_as_dict) elif definition_type == CNF: - config = Configuration(**config_as_dict) + config = CNFConfiguration(**config_as_dict) elif definition_type == NSD: config = Configuration(**config_as_dict) else: diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index f0fdf3a43ba..0382c9f59df 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -69,7 +69,7 @@ def build_definition( print("TODO - cannot publish CNF or NSD yet.") -def generate_definition_config(_, definition_type, output_file="input.json"): +def generate_definition_config(definition_type, output_file="input.json"): config = get_configuration(definition_type) config_as_dict = json.dumps(asdict(config), indent=4) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index c669578b5c4..08b5a723d07 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -132,7 +132,7 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: "nfDefinitionGroup": {"value": self.config.nfdg_name}, "nfDefinitionVersion": {"value": self.config.version}, "vhdName": {"value": self.config.vhd.artifact_name}, - "vhdVersion": {"value": self.config.vhd.version.}, + "vhdVersion": {"value": self.config.vhd.version}, "armTemplateName": {"value": self.config.arm_template.artifact_name}, "armTemplateVersion": {"value": self.config.arm_template.version}, } From bf0a29f9744b0abb65b200133f2af574b479edeb Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 13:10:01 +0100 Subject: [PATCH 022/145] artifact manifests separate --- src/aosm/azext_aosm/_configuration.py | 78 +++++++++++----- src/aosm/azext_aosm/_constants.py | 1 + src/aosm/azext_aosm/_help.py | 13 ++- src/aosm/azext_aosm/_params.py | 15 ++++ src/aosm/azext_aosm/commands.py | 1 + src/aosm/azext_aosm/custom.py | 90 ++++++++++++++----- src/aosm/azext_aosm/deploy/artifact.py | 20 +++-- .../azext_aosm/deploy/artifact_manifest.py | 2 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 85 +++++++++++++----- src/aosm/azext_aosm/deploy/pre_deploy.py | 48 ++++++++++ .../templates/vnfartifactmanifests.bicep | 70 +++++++++++++++ .../templates/vnfdefinition.bicep | 38 -------- .../generate_nfd/vnf_bicep_nfd_generator.py | 15 +++- 13 files changed, 362 insertions(+), 114 deletions(-) create mode 100644 src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index cd5a6ed3116..d87b391f4eb 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,36 +1,54 @@ from dataclasses import dataclass -from typing import Optional, Any +from typing import Dict, Optional, Any from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError -from ._constants import VNF, CNF, NSD +from pathlib import Path +from azext_aosm._constants import ( + VNF_DEFINITION_OUTPUT_BICEP_PREFIX, + VNF, + CNF, + NSD +) + +DESCRIPTION_MAP: Dict[str,str] = { + "publisher_name": "Name of the Publisher resource you want you definition published to", + "publisher_resource_group_name": "Resource group the Publisher resource is in or you want it to be in", + "nf_name": "Name of NF definition", + "version": "Version of the NF definition", + "acr_artifact_store_name":"Name of the ACR Artifact Store resource", + "location": "Azure location of the resources", + "blob_artifact_store_name": "Name of the storage account Artifact Store resource", + "artifact_name": "Name of the artifact", + "file_path": "Optional. File path of the artifact you wish to upload from your local disk. Delete if not required.", + "blob_sas_url": "Optional. SAS URL of the blob artifact you wish to copy to your Artifact Store. Delete if not required.", + "artifact_version": ( + "Version of the artifact. For VHDs this must be in format A-B-C. " + "For ARM templates this must be in format A.B.C" + ) +} @dataclass class ArtifactConfig: - artifact_name: str = "Name of the artifact" + artifact_name: str = DESCRIPTION_MAP["artifact_name"] + # artifact.py checks for the presence of the default descriptions, change there if + # you change the descriptions. file_path: Optional[ str - ] = "File path of the artifact you wish to upload from your local disk" + ] = DESCRIPTION_MAP["file_path"] blob_sas_url: Optional[ str - ] = "SAS URL of the blob artifact you wish to copy to your Artifact Store" - version: str = ( - "Version of the artifact. For VHDs this must be in format A-B-C. " - "For ARM templates this must be in format A.B.C" - ) + ] = DESCRIPTION_MAP["blob_sas_url"] + version: str = DESCRIPTION_MAP["artifact_version"] @dataclass class Configuration: - publisher_name: str = ( - "Name of the Publisher resource you want you definition published to" - ) - publisher_resource_group_name: str = ( - "Resource group the Publisher resource is in or you want it to be in" - ) - nf_name: str = "Name of NF definition" - version: str = "Version of the NF definition" - acr_artifact_store_name: str = "Name of the ACR Artifact Store resource" - location: str = "Azure location of the resources" + publisher_name: str = DESCRIPTION_MAP["publisher_name"] + publisher_resource_group_name: str = DESCRIPTION_MAP["publisher_resource_group_name"] + nf_name: str = DESCRIPTION_MAP["nf_name"] + version: str = DESCRIPTION_MAP["version"] + acr_artifact_store_name: str = DESCRIPTION_MAP["acr_artifact_store_name"] + location: str = DESCRIPTION_MAP["location"] @property def nfdg_name(self) -> str: @@ -45,9 +63,7 @@ def acr_manifest_name(self) -> str: @dataclass class VNFConfiguration(Configuration): - blob_artifact_store_name: str = ( - "Name of the storage account Artifact Store resource" - ) + blob_artifact_store_name: str = DESCRIPTION_MAP["blob_artifact_store_name"] arm_template: Any = ArtifactConfig() vhd: Any = ArtifactConfig() @@ -68,9 +84,17 @@ def __post_init__(self): def sa_manifest_name(self) -> str: """Return the Storage account manifest name from the NFD name.""" return f"{self.nf_name}-sa-manifest-{self.version.replace('.', '-')}" + + @property + def build_output_folder_name(self) -> str: + """Return the local folder for generating the bicep template to.""" + arm_template_path = self.arm_template.file_path + return ( + f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" + ) -def get_configuration(definition_type, config_as_dict=None) -> Configuration: +def get_configuration(definition_type: str, config_as_dict: Optional[Dict[Any,Any]]=None) -> Configuration: if config_as_dict is None: config_as_dict = {} @@ -112,3 +136,11 @@ def validate_configuration(config: Configuration) -> None: raise ValidationError( "Config validation error. ARM template artifact version should be in format A.B.C" ) + + if not ((config.vhd.file_path or config.vhd.blob_sas_url) or ( + config.vhd.file_path == DESCRIPTION_MAP["file_path"] and + config.vhd.blob_sas_url == DESCRIPTION_MAP["blob_sas_url"]) + ): + raise ValidationError( + "Config validation error. VHD config must have either a local filepath or a blob SAS URL" + ) diff --git a/src/aosm/azext_aosm/_constants.py b/src/aosm/azext_aosm/_constants.py index 8b232eff0bf..6933f42f511 100644 --- a/src/aosm/azext_aosm/_constants.py +++ b/src/aosm/azext_aosm/_constants.py @@ -13,6 +13,7 @@ # Names of files used in the repo VNF_DEFINITION_BICEP_SOURCE_TEMPLATE = "vnfdefinition.bicep" +VNF_MANIFEST_BICEP_SOURCE_TEMPLATE = "vnfartifactmanifests.bicep" VNF_DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" # Provisioning States diff --git a/src/aosm/azext_aosm/_help.py b/src/aosm/azext_aosm/_help.py index d5169d49c0d..df276d4f8bd 100644 --- a/src/aosm/azext_aosm/_help.py +++ b/src/aosm/azext_aosm/_help.py @@ -21,6 +21,13 @@ short-summary: Manage AOSM publisher definitions. """ +helps[ + "aosm definition generate-config" +] = """ + type: command + short-summary: Generate configuration file for building an AOSM publisher definition. +""" + helps[ "aosm definition build" ] = """ @@ -29,12 +36,14 @@ """ helps[ - "aosm definition generate-config" + "aosm definition publish" ] = """ type: command - short-summary: Generate configuration file for building an AOSM publisher definition. + short-summary: Publish a pre-built AOSM publisher definition. """ + + helps[ "aosm definition delete" ] = """ diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index c9339763f4d..622f4998c76 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -42,6 +42,21 @@ def load_arguments(self: AzCommandsLoader, _): arg_type=get_three_state_flag(), help="Also delete artifact stores, NFD Group and Publisher. Use with care.", ) + c.argument( + "bicep_file", + options_list=["--bicep-file", "-b"], + type=file_type, + completer=FilesCompleter(allowednames="*.json"), + help="Optional path to a bicep file to publish. Use to override publish of the built definition with an alternative file.", + ) + c.argument( + "parameters_json_file", + options_list=["--parameters-file", "-p"], + type=file_type, + completer=FilesCompleter(allowednames="*.json"), + help="Optional path to a parameters file for the bicep definition file. Use to override publish of the built definition and config with alternative parameters.", + ) + with self.argument_context("aosm generate-config") as c: c.argument( diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index d57a4b9db3b..66b42311cbf 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -21,6 +21,7 @@ def load_command_table(self: AzCommandsLoader, _): g.custom_command("build", "build_definition") g.custom_command("delete", "delete_published_definition") g.custom_command("show", "show_publisher") + g.custom_command("publish", "publish_definition") with self.command_group("aosm", is_preview=True): pass diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index f0fdf3a43ba..c18facc45b7 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -6,6 +6,7 @@ import json from dataclasses import asdict from knack.log import get_logger +from typing import Optional from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator @@ -18,6 +19,7 @@ from ._configuration import ( get_configuration, validate_configuration, + Configuration ) @@ -27,8 +29,8 @@ def build_definition( cmd, client: HybridNetworkManagementClient, - definition_type, - config_file, + definition_type: str, + config_file: str, publish=False, ): """Build and optionally publish a definition @@ -44,18 +46,12 @@ def build_definition( :param publish: _description_, defaults to False :type publish: bool, optional """ - with open(config_file, "r", encoding="utf-8") as f: - config_as_dict = json.loads(f.read()) - - apiClientsAndCaches = ApiClientsAndCaches( + api_clients = ApiClientsAndCaches( aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) ) - # TODO - this isn't deserializing the config properly - any sub-objects are left - # as a dictionary instead of being converted to the object (e.g. ArtifactConfig) - # se we have to reference them as dictionary values - config = get_configuration(definition_type, config_as_dict) - validate_configuration(config) + config = _get_config_from_file(config_file, definition_type) + # Generate the NFD/NSD and the artifact manifest. _generate_nfd(definition_type=definition_type, config=config) # Write the ARM/bicep template if that's what we are doing @@ -63,26 +59,38 @@ def build_definition( # Publish the definition if publish is true if publish: if definition_type == VNF: - deployer = DeployerViaArm(apiClientsAndCaches, config=config) + deployer = DeployerViaArm(api_clients, config=config) deployer.deploy_vnfd_from_bicep() else: print("TODO - cannot publish CNF or NSD yet.") -def generate_definition_config(_, definition_type, output_file="input.json"): +def generate_definition_config(definition_type: str, output_file: str="input.json"): config = get_configuration(definition_type) config_as_dict = json.dumps(asdict(config), indent=4) with open(output_file, "w", encoding="utf-8") as f: f.write(config_as_dict) print( - "Empty definition configuration has been written to %s", - output_file, + f"Empty definition configuration has been written to {output_file}" ) logger.info( - "Empty definition configuration has been written to %s", - output_file, + f"Empty definition configuration has been written to {output_file}" ) + +def _get_config_from_file(config_file: str, definition_type: str) -> Configuration: + """Read input config file JSON and turn it into a Configuration object. + + :param config_file: path to the file + :param definition_type: VNF, CNF or NSD + :rtype: Configuration + """ + with open(config_file, "r", encoding="utf-8") as f: + config_as_dict = json.loads(f.read()) + + config = get_configuration(definition_type, config_as_dict) + validate_configuration(config) + return config def _generate_nfd(definition_type, config): @@ -105,6 +113,40 @@ def _generate_nfd(definition_type, config): ) nfd_generator.generate_nfd() + +def publish_definition( + cmd, + client: HybridNetworkManagementClient, + definition_type, + config_file, + bicep_file: Optional[str] = None, + parameters_json_file: Optional[str] = None +): + """_summary_ + + :param cmd: + :param client: + :type client: HybridNetworkManagementClient + :param definition_type: VNF or CNF + :param config_file: Path to the config file for the NFDV + :param bicep_file: Optional path to a bicep template to deploy, in case the user + wants to edit the built NFDV template. If omitted, the default + built NFDV template will be used + :param parameters_json_file: Optional path to a parameters file for the bicep file, + in case the user wants to edit the built NFDV template. If + omitted, parameters from config will be turned into parameters + for the bicep file + + """ + print("Publishing definition.") + api_clients = ApiClientsAndCaches( + aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) + ) + config = _get_config_from_file(config_file, definition_type) + if definition_type == VNF: + deployer = DeployerViaArm(api_clients, config=config) + deployer.deploy_vnfd_from_bicep(bicep_path=bicep_file, + parameters_json_file=parameters_json_file) def delete_published_definition( @@ -114,10 +156,16 @@ def delete_published_definition( config_file, clean=False, ): - with open(config_file, "r", encoding="utf-8") as f: - config_as_dict = json.loads(f.read()) - config = get_configuration(definition_type, config_as_dict) - validate_configuration(config) + """ + Delete a published definition. + + :param definition_type: CNF or VNF + :param config_file: Path to the config file + :param clean: if True, will delete the NFDG, artifact stores and publisher too. + Defaults to False. Only works if no resources have those as a parent. + Use with care. + """ + config = _get_config_from_file(config_file, definition_type) api_clients = ApiClientsAndCaches( aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 057a6f409d1..bbb647182be 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -7,7 +7,7 @@ from typing import Union from azure.storage.blob import BlobClient -from azext_aosm._configuration import ArtifactConfig +from azext_aosm._configuration import ArtifactConfig, DESCRIPTION_MAP from oras.client import OrasClient logger = get_logger(__name__) @@ -41,11 +41,13 @@ def _upload_to_acr(self, artifact_config: ArtifactConfig) -> None: """ assert type(self.artifact_client) == OrasClient - if "file_path" in artifact_config.keys(): + # If not included in config, the file path value will be the description of + # the field. + if artifact_config.file_path and not artifact_config.file_path == DESCRIPTION_MAP["file_path"]: target = f"{self.artifact_client.remote.hostname.replace('https://', '')}/{self.artifact_name}:{self.artifact_version}" - logger.debug(f"Uploading {artifact_config['file_path']} to {target}") + logger.debug(f"Uploading {artifact_config.file_path} to {target}") self.artifact_client.push( - file=artifact_config["file_path"], + file=artifact_config.file_path, target=target, ) else: @@ -62,14 +64,16 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: assert type(self.artifact_client) == BlobClient # If the file path is given, upload the artifact, else, copy it from an existing blob. - if "file_path" in artifact_config.keys(): - with open(artifact_config["file_path"], "rb") as artifact: + if artifact_config.file_path and not artifact_config.file_path == DESCRIPTION_MAP["file_path"]: + logger.info("Upload to blob store") + with open(artifact_config.file_path, "rb") as artifact: self.artifact_client.upload_blob(artifact, overwrite=True) logger.info( - f"Successfully uploaded {artifact_config['file_path']} to {self.artifact_client.account_name}" + f"Successfully uploaded {artifact_config.file_path} to {self.artifact_client.account_name}" ) else: - source_blob = BlobClient.from_blob_url(artifact_config["blob_sas_url"]) + logger.info("Copy from SAS URL to blob store") + source_blob = BlobClient.from_blob_url(artifact_config.blob_sas_url) if source_blob.exists(): logger.debug(source_blob.url) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 42a655be533..6dc3c31ea0d 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -49,7 +49,7 @@ def _manifest_credentials(self) -> Any: def _oras_client(self, acr_url: str) -> OrasClient: """ - Returns an OrasClient object for uploading to the artifact str Returns an OrasClient object for uploading to the artifact store ACR.oe ACR. + Returns an OrasClient object for uploading to the artifact store ACR. :param arc_url: URL of the ACR backing the artifact manifest """ diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index c669578b5c4..5748b8cf96f 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -7,7 +7,7 @@ import os import shutil import subprocess # noqa -from typing import Any, Dict +from typing import Any, Dict, Optional from knack.log import get_logger from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator @@ -18,8 +18,8 @@ from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK from azext_aosm._configuration import Configuration, VNFConfiguration from azext_aosm._constants import ( - VNF_DEFINITION_OUTPUT_BICEP_PREFIX, VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, + VNF_MANIFEST_BICEP_SOURCE_TEMPLATE ) @@ -49,7 +49,10 @@ def __init__( self.config = config self.pre_deployer = PreDeployerViaSDK(apiClientsAndCaches, self.config) - def deploy_vnfd_from_bicep(self) -> None: + def deploy_vnfd_from_bicep(self, + bicep_path: Optional[str] = None, + parameters_json_file: Optional[str] = None + ) -> None: """ Deploy the bicep template defining the VNFD. @@ -60,24 +63,48 @@ def deploy_vnfd_from_bicep(self) -> None: """ assert isinstance(self.config, VNFConfiguration) - # TODO - duplicated from vnf_bicep_nfd_generator and won't work if file exists - arm_template_path = self.config.arm_template.file_path - folder_name = ( - f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" - ) - bicep_template_name = VNF_DEFINITION_BICEP_SOURCE_TEMPLATE - bicep_path = os.path.join(folder_name, bicep_template_name) + if not bicep_path: + # User has not passed in a bicep template, so we are deploying the default + # one produced from building the NFDV using this CLI + bicep_path = os.path.join(self.config.build_output_folder_name, + VNF_DEFINITION_BICEP_SOURCE_TEMPLATE) + + if parameters_json_file: + message: str = f"Use parameters from file {parameters_json_file}" + logger.info(message) + print(message) + with open(parameters_json_file, "r", encoding="utf-8") as f: + parameters = json.loads(f.read()) + + else: + # User has not passed in parameters file, so we use the parameters required + # from config for the default bicep template produced from building the + # NFDV using this CLI + logger.debug("Create parameters for default NFDV template.") + parameters = self.construct_vnfd_parameters() - parameters = self.construct_vnfd_parameters() logger.debug(parameters) # Create or check required resources - self.vnfd_predeploy() + deploy_manifest_template = not self.vnfd_predeploy() + if deploy_manifest_template: + print(f"Deploy bicep template for Artifact manifests") + logger.debug("Deploy manifest bicep") + manifest_bicep_path = os.path.join(self.config.build_output_folder_name, + VNF_MANIFEST_BICEP_SOURCE_TEMPLATE) + manifest_params = self.construct_manifest_parameters() + self.deploy_bicep_template(manifest_bicep_path, manifest_params) + else: + print(f"Artifact manifests exist for NFD {self.config.nf_name} " + f"version {self.config.version}") + message = (f"Deploy bicep template for NFD {self.config.nf_name} version {self.config.version} " + f"into {self.config.publisher_resource_group_name} under publisher " + f"{self.config.publisher_name}") + print(message) + logger.info(message) self.deploy_bicep_template(bicep_path, parameters) print( - f"Deployed NFD {self.config.nf_name} version {self.config.version} " - f"into {self.config.publisher_resource_group_name} under publisher " - f"{self.config.publisher_name}" + f"Deployed NFD {self.config.nf_name} version {self.config.version}." ) storage_account_manifest = ArtifactManifestOperator( @@ -102,11 +129,12 @@ def deploy_vnfd_from_bicep(self) -> None: arm_template_artifact.upload(self.config.arm_template) print("Done") - def vnfd_predeploy(self): + def vnfd_predeploy(self) -> bool: """ All the predeploy steps for a VNF. Create publisher, artifact stores and NFDG. VNF specific + return True if artifact manifest already exists, False otherwise """ logger.debug("Ensure all required resources exist") self.pre_deployer.ensure_config_resource_group_exists() @@ -114,6 +142,7 @@ def vnfd_predeploy(self): self.pre_deployer.ensure_acr_artifact_store_exists() self.pre_deployer.ensure_sa_artifact_store_exists() self.pre_deployer.ensure_config_nfdg_exists() + return self.pre_deployer.do_config_artifact_manifests_exist() def construct_vnfd_parameters(self) -> Dict[str, Any]: """ @@ -126,16 +155,31 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: "publisherName": {"value": self.config.publisher_name}, "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, - "acrManifesteName": {"value": self.config.acr_manifest_name}, - "saManifesteName": {"value": self.config.sa_manifest_name}, "nfName": {"value": self.config.nf_name}, "nfDefinitionGroup": {"value": self.config.nfdg_name}, "nfDefinitionVersion": {"value": self.config.version}, + "vhdVersion": {"value": self.config.vhd.version}, + "armTemplateVersion": {"value": self.config.arm_template.version}, + } + + def construct_manifest_parameters(self) -> Dict[str, Any]: + """ + Create the parmeters dictionary for vnfdefinitions.bicep. VNF specific. + + :param config: The contents of the configuration file. + """ + assert isinstance(self.config, VNFConfiguration) + return { + "publisherName": {"value": self.config.publisher_name}, + "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, + "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, + "acrManifestName": {"value": self.config.acr_manifest_name}, + "saManifestName": {"value": self.config.sa_manifest_name}, "vhdName": {"value": self.config.vhd.artifact_name}, - "vhdVersion": {"value": self.config.vhd.version.}, + "vhdVersion": {"value": self.config.vhd.version}, "armTemplateName": {"value": self.config.arm_template.artifact_name}, "armTemplateVersion": {"value": self.config.arm_template.version}, - } + } def deploy_bicep_template( self, bicep_template_path: str, parameters: Dict[Any, Any] @@ -236,6 +280,7 @@ def validate_and_deploy_arm_template( # Wait for the deployment to complete and get the outputs deployment: DeploymentExtended = poller.result() + logger.debug("Finished deploying") if deployment.properties is not None: depl_props = deployment.properties diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index a4e332f5b34..f17edb7489f 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -269,6 +269,54 @@ def ensure_config_nfdg_exists( self.config.nfdg_name, self.config.location, ) + + def does_artifact_manifest_exist(self, + rg_name: str, + publisher_name: str, + store_name: str, + manifest_name: str + ) -> bool: + try: + self.api_clients.aosm_client.artifact_manifests.get( + resource_group_name=rg_name, + publisher_name=publisher_name, + artifact_store_name=store_name, + artifact_manifest_name=manifest_name + ) + logger.debug(f"Artifact manifest {manifest_name} exists") + return True + except azure_exceptions.ResourceNotFoundError: + logger.debug(f"Artifact manifest {manifest_name} does not exist") + return False + + def do_config_artifact_manifests_exist( + self, + ): + """ + Returns True if all required manifests exist, False otherwise + """ + acr_manny_exists: bool = self.does_artifact_manifest_exist( + rg_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + store_name=self.config.acr_artifact_store_name, + manifest_name=self.config.acr_manifest_name + ) + + if isinstance(self.config, VNFConfiguration): + sa_manny_exists: bool = self.does_artifact_manifest_exist( + rg_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + store_name=self.config.blob_artifact_store_name, + manifest_name=self.config.sa_manifest_name + ) + if acr_manny_exists and sa_manny_exists: + return True + elif acr_manny_exists or sa_manny_exists: + raise AzCLIError("Only one artifact manifest exists. Cannot proceed. Please delete the NFDV using `az aosm definition delete` and start the publish again from scratch.") + else: + return False + + return acr_manny_exists def ensure_nsdg_exists( self, diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep new file mode 100644 index 00000000000..20e7d5e2e2b --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an NF definition for a VNF +param location string = resourceGroup().location +@description('Name of an existing publisher, expected to be in the resource group where you deploy the template') +param publisherName string +@description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') +param acrArtifactStoreName string +@description('Name of an existing Storage Account-backed Artifact Store, deployed under the publisher.') +param saArtifactStoreName string +@description('Name of the manifest to deploy for the ACR-backed Artifact Store') +param acrManifestName string +@description('Name of the manifest to deploy for the Storage Account-backed Artifact Store') +param saManifestName string +@description('The name under which to store the VHD') +param vhdName string +@description('The version that you want to name the NFM VHD artifact, in format A-B-C. e.g. 6-13-0') +param vhdVersion string +@description('The name under which to store the ARM template') +param armTemplateName string +@description('The version that you want to name the NFM template artifact, in format A.B.C. e.g. 6.13.0. If testing for development, you can use any numbers you like.') +param armTemplateVersion string + +// Created by the az aosm definition publish command before the template is deployed +resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { + name: publisherName + scope: resourceGroup() +} + +// Created by the az aosm definition publish command before the template is deployed +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { + parent: publisher + name: acrArtifactStoreName +} + +// Created by the az aosm definition publish command before the template is deployed +resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { + parent: publisher + name: saArtifactStoreName +} + +resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { + parent: saArtifactStore + name: saManifestName + location: location + properties: { + artifacts: [ + { + artifactName: '${vhdName}' + artifactType: 'VhdImageFile' + artifactVersion: vhdVersion + } + ] + } +} + +resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { + parent: acrArtifactStore + name: acrManifestName + location: location + properties: { + artifacts: [ + { + artifactName: '${armTemplateName}' + artifactType: 'ArmTemplate' + artifactVersion: armTemplateVersion + } + ] + } +} diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep index aafdd474de5..87f3b93e15f 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep @@ -8,22 +8,14 @@ param publisherName string param acrArtifactStoreName string @description('Name of an existing Storage Account-backed Artifact Store, deployed under the publisher.') param saArtifactStoreName string -@description('Name of the manifest to deploy for the ACR-backed Artifact Store') -param acrManifestName string -@description('Name of the manifest to deploy for the Storage Account-backed Artifact Store') -param saManifestName string @description('Name of Network Function. Used predominantly as a prefix for other variable names') param nfName string @description('Name of an existing Network Function Definition Group') param nfDefinitionGroup string @description('The version of the NFDV you want to deploy, in format A-B-C') param nfDefinitionVersion string -@description('The name under which to store the VHD') -param vhdName string @description('The version that you want to name the NFM VHD artifact, in format A-B-C. e.g. 6-13-0') param vhdVersion string -@description('The name under which to store the ARM template') -param armTemplateName string @description('The version that you want to name the NFM template artifact, in format A.B.C. e.g. 6.13.0. If testing for development, you can use any numbers you like.') param armTemplateVersion string @@ -51,36 +43,6 @@ resource nfdg 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroup name: nfDefinitionGroup } -resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { - parent: saArtifactStore - name: saManifestName - location: location - properties: { - artifacts: [ - { - artifactName: '${vhdName}' - artifactType: 'VhdImageFile' - artifactVersion: vhdVersion - } - ] - } -} - -resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { - parent: acrArtifactStore - name: acrManifestName - location: location - properties: { - artifacts: [ - { - artifactName: '${armTemplateName}' - artifactType: 'ArmTemplate' - artifactVersion: armTemplateVersion - } - ] - } -} - resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups/networkfunctiondefinitionversions@2022-09-01-preview' = { parent: nfdg name: nfDefinitionVersion diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 5547cd1aa16..5f179d5207f 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -21,6 +21,7 @@ from azext_aosm._constants import ( VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, VNF_DEFINITION_OUTPUT_BICEP_PREFIX, + VNF_MANIFEST_BICEP_SOURCE_TEMPLATE ) @@ -41,11 +42,13 @@ def __init__(self, config: VNFConfiguration): ) self.config = config self.bicep_template_name = VNF_DEFINITION_BICEP_SOURCE_TEMPLATE + self.manifest_template_name = VNF_MANIFEST_BICEP_SOURCE_TEMPLATE self.arm_template_path = self.config.arm_template.file_path - self.folder_name = f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(self.arm_template_path)).stem}" + self.folder_name = self.config.build_output_folder_name self._bicep_path = os.path.join(self.folder_name, self.bicep_template_name) + self._manifest_path = os.path.join(self.folder_name, self.manifest_template_name) def generate_nfd(self) -> None: """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" @@ -82,6 +85,14 @@ def bicep_path(self) -> Optional[str]: return self._bicep_path return None + + @property + def manifest_path(self) -> Optional[str]: + """Returns the path to the bicep file for the NFD if it has been created.""" + if os.path.exists(self._manifest_path): + return self._manifest_path + + return None def _create_nfd_folder(self) -> None: """ @@ -205,5 +216,7 @@ def copy_bicep(self) -> None: code_dir = os.path.dirname(__file__) bicep_path = os.path.join(code_dir, "templates", self.bicep_template_name) + manifest_path = os.path.join(code_dir, "templates", self.manifest_template_name) shutil.copy(bicep_path, self.folder_name) + shutil.copy(manifest_path, self.folder_name) From c741773e5a6c3743a4a1098dcf09b7b0e1369f6f Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 15:41:56 +0100 Subject: [PATCH 023/145] style --- src/aosm/azext_aosm/_configuration.py | 55 ++++++++----------- src/aosm/azext_aosm/_help.py | 1 - src/aosm/azext_aosm/_params.py | 4 +- src/aosm/azext_aosm/commands.py | 3 +- src/aosm/azext_aosm/custom.py | 49 ++++++++--------- src/aosm/azext_aosm/deploy/artifact.py | 10 +++- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 51 +++++++++-------- src/aosm/azext_aosm/deploy/pre_deploy.py | 27 ++++----- .../generate_nfd/vnf_bicep_nfd_generator.py | 11 ++-- 9 files changed, 105 insertions(+), 106 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index d87b391f4eb..75df986414a 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -2,19 +2,14 @@ from typing import Dict, Optional, Any from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError from pathlib import Path -from azext_aosm._constants import ( - VNF_DEFINITION_OUTPUT_BICEP_PREFIX, - VNF, - CNF, - NSD -) - -DESCRIPTION_MAP: Dict[str,str] = { +from azext_aosm._constants import VNF_DEFINITION_OUTPUT_BICEP_PREFIX, VNF, CNF, NSD + +DESCRIPTION_MAP: Dict[str, str] = { "publisher_name": "Name of the Publisher resource you want you definition published to", "publisher_resource_group_name": "Resource group the Publisher resource is in or you want it to be in", "nf_name": "Name of NF definition", "version": "Version of the NF definition", - "acr_artifact_store_name":"Name of the ACR Artifact Store resource", + "acr_artifact_store_name": "Name of the ACR Artifact Store resource", "location": "Azure location of the resources", "blob_artifact_store_name": "Name of the storage account Artifact Store resource", "artifact_name": "Name of the artifact", @@ -23,7 +18,7 @@ "artifact_version": ( "Version of the artifact. For VHDs this must be in format A-B-C. " "For ARM templates this must be in format A.B.C" - ) + ), } @@ -32,19 +27,17 @@ class ArtifactConfig: artifact_name: str = DESCRIPTION_MAP["artifact_name"] # artifact.py checks for the presence of the default descriptions, change there if # you change the descriptions. - file_path: Optional[ - str - ] = DESCRIPTION_MAP["file_path"] - blob_sas_url: Optional[ - str - ] = DESCRIPTION_MAP["blob_sas_url"] + file_path: Optional[str] = DESCRIPTION_MAP["file_path"] + blob_sas_url: Optional[str] = DESCRIPTION_MAP["blob_sas_url"] version: str = DESCRIPTION_MAP["artifact_version"] @dataclass class Configuration: publisher_name: str = DESCRIPTION_MAP["publisher_name"] - publisher_resource_group_name: str = DESCRIPTION_MAP["publisher_resource_group_name"] + publisher_resource_group_name: str = DESCRIPTION_MAP[ + "publisher_resource_group_name" + ] nf_name: str = DESCRIPTION_MAP["nf_name"] version: str = DESCRIPTION_MAP["version"] acr_artifact_store_name: str = DESCRIPTION_MAP["acr_artifact_store_name"] @@ -66,25 +59,24 @@ class VNFConfiguration(Configuration): blob_artifact_store_name: str = DESCRIPTION_MAP["blob_artifact_store_name"] arm_template: Any = ArtifactConfig() vhd: Any = ArtifactConfig() - + def __post_init__(self): """ Cope with deserializing subclasses from dicts to ArtifactConfig. - + Used when creating VNFConfiguration object from a loaded json config file. """ if isinstance(self.arm_template, dict): self.arm_template = ArtifactConfig(**self.arm_template) - + if isinstance(self.vhd, dict): self.vhd = ArtifactConfig(**self.vhd) - @property def sa_manifest_name(self) -> str: """Return the Storage account manifest name from the NFD name.""" return f"{self.nf_name}-sa-manifest-{self.version.replace('.', '-')}" - + @property def build_output_folder_name(self) -> str: """Return the local folder for generating the bicep template to.""" @@ -94,8 +86,9 @@ def build_output_folder_name(self) -> str: ) -def get_configuration(definition_type: str, config_as_dict: Optional[Dict[Any,Any]]=None) -> Configuration: - +def get_configuration( + definition_type: str, config_as_dict: Optional[Dict[Any, Any]] = None +) -> Configuration: if config_as_dict is None: config_as_dict = {} @@ -129,17 +122,17 @@ def validate_configuration(config: Configuration) -> None: raise ValidationError( "Config validation error. VHD artifact version should be in format A-B-C" ) - if ( - "." not in config.arm_template.version - or "-" in config.arm_template.version - ): + if "." not in config.arm_template.version or "-" in config.arm_template.version: raise ValidationError( "Config validation error. ARM template artifact version should be in format A.B.C" ) - if not ((config.vhd.file_path or config.vhd.blob_sas_url) or ( - config.vhd.file_path == DESCRIPTION_MAP["file_path"] and - config.vhd.blob_sas_url == DESCRIPTION_MAP["blob_sas_url"]) + if not ( + (config.vhd.file_path or config.vhd.blob_sas_url) + or ( + config.vhd.file_path == DESCRIPTION_MAP["file_path"] + and config.vhd.blob_sas_url == DESCRIPTION_MAP["blob_sas_url"] + ) ): raise ValidationError( "Config validation error. VHD config must have either a local filepath or a blob SAS URL" diff --git a/src/aosm/azext_aosm/_help.py b/src/aosm/azext_aosm/_help.py index df276d4f8bd..2a9a3013fd9 100644 --- a/src/aosm/azext_aosm/_help.py +++ b/src/aosm/azext_aosm/_help.py @@ -43,7 +43,6 @@ """ - helps[ "aosm definition delete" ] = """ diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index 622f4998c76..e3fb517212b 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -6,7 +6,8 @@ from argcomplete.completers import FilesCompleter from azure.cli.core import AzCommandsLoader -#from knack.arguments import CLIArgumentType + +# from knack.arguments import CLIArgumentType from ._constants import VNF, CNF, NSD @@ -56,7 +57,6 @@ def load_arguments(self: AzCommandsLoader, _): completer=FilesCompleter(allowednames="*.json"), help="Optional path to a parameters file for the bicep definition file. Use to override publish of the built definition and config with alternative parameters.", ) - with self.argument_context("aosm generate-config") as c: c.argument( diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index 66b42311cbf..c906ca6947e 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -5,7 +5,8 @@ # pylint: disable=line-too-long from azure.cli.core import AzCommandsLoader -#from azure.cli.core.commands import CliCommandType + +# from azure.cli.core.commands import CliCommandType from azext_aosm._client_factory import cf_aosm diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index c18facc45b7..51fb7a55115 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -16,11 +16,7 @@ from azext_aosm.util.management_clients import ApiClientsAndCaches from .vendored_sdks import HybridNetworkManagementClient from ._client_factory import cf_resources -from ._configuration import ( - get_configuration, - validate_configuration, - Configuration -) +from ._configuration import get_configuration, validate_configuration, Configuration logger = get_logger(__name__) @@ -33,7 +29,8 @@ def build_definition( config_file: str, publish=False, ): - """Build and optionally publish a definition + """ + Build and optionally publish a definition. :param cmd: _description_ :type cmd: _type_ @@ -51,7 +48,7 @@ def build_definition( ) config = _get_config_from_file(config_file, definition_type) - + # Generate the NFD/NSD and the artifact manifest. _generate_nfd(definition_type=definition_type, config=config) # Write the ARM/bicep template if that's what we are doing @@ -65,21 +62,19 @@ def build_definition( print("TODO - cannot publish CNF or NSD yet.") -def generate_definition_config(definition_type: str, output_file: str="input.json"): +def generate_definition_config(definition_type: str, output_file: str = "input.json"): config = get_configuration(definition_type) config_as_dict = json.dumps(asdict(config), indent=4) with open(output_file, "w", encoding="utf-8") as f: f.write(config_as_dict) - print( - f"Empty definition configuration has been written to {output_file}" - ) - logger.info( - f"Empty definition configuration has been written to {output_file}" - ) - + print(f"Empty definition configuration has been written to {output_file}") + logger.info(f"Empty definition configuration has been written to {output_file}") + + def _get_config_from_file(config_file: str, definition_type: str) -> Configuration: - """Read input config file JSON and turn it into a Configuration object. + """ + Read input config file JSON and turn it into a Configuration object. :param config_file: path to the file :param definition_type: VNF, CNF or NSD @@ -113,30 +108,31 @@ def _generate_nfd(definition_type, config): ) nfd_generator.generate_nfd() - + + def publish_definition( cmd, client: HybridNetworkManagementClient, definition_type, config_file, bicep_file: Optional[str] = None, - parameters_json_file: Optional[str] = None + parameters_json_file: Optional[str] = None, ): - """_summary_ + """ + _summary_ - :param cmd: - :param client: + :param cmd: + :param client: :type client: HybridNetworkManagementClient :param definition_type: VNF or CNF :param config_file: Path to the config file for the NFDV :param bicep_file: Optional path to a bicep template to deploy, in case the user wants to edit the built NFDV template. If omitted, the default built NFDV template will be used - :param parameters_json_file: Optional path to a parameters file for the bicep file, - in case the user wants to edit the built NFDV template. If + :param parameters_json_file: Optional path to a parameters file for the bicep file, + in case the user wants to edit the built NFDV template. If omitted, parameters from config will be turned into parameters for the bicep file - """ print("Publishing definition.") api_clients = ApiClientsAndCaches( @@ -145,8 +141,9 @@ def publish_definition( config = _get_config_from_file(config_file, definition_type) if definition_type == VNF: deployer = DeployerViaArm(api_clients, config=config) - deployer.deploy_vnfd_from_bicep(bicep_path=bicep_file, - parameters_json_file=parameters_json_file) + deployer.deploy_vnfd_from_bicep( + bicep_path=bicep_file, parameters_json_file=parameters_json_file + ) def delete_published_definition( diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index bbb647182be..b8b0287b117 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -43,7 +43,10 @@ def _upload_to_acr(self, artifact_config: ArtifactConfig) -> None: # If not included in config, the file path value will be the description of # the field. - if artifact_config.file_path and not artifact_config.file_path == DESCRIPTION_MAP["file_path"]: + if ( + artifact_config.file_path + and not artifact_config.file_path == DESCRIPTION_MAP["file_path"] + ): target = f"{self.artifact_client.remote.hostname.replace('https://', '')}/{self.artifact_name}:{self.artifact_version}" logger.debug(f"Uploading {artifact_config.file_path} to {target}") self.artifact_client.push( @@ -64,7 +67,10 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: assert type(self.artifact_client) == BlobClient # If the file path is given, upload the artifact, else, copy it from an existing blob. - if artifact_config.file_path and not artifact_config.file_path == DESCRIPTION_MAP["file_path"]: + if ( + artifact_config.file_path + and not artifact_config.file_path == DESCRIPTION_MAP["file_path"] + ): logger.info("Upload to blob store") with open(artifact_config.file_path, "rb") as artifact: self.artifact_client.upload_blob(artifact, overwrite=True) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 5748b8cf96f..553020b7d6e 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -19,7 +19,7 @@ from azext_aosm._configuration import Configuration, VNFConfiguration from azext_aosm._constants import ( VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, - VNF_MANIFEST_BICEP_SOURCE_TEMPLATE + VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, ) @@ -49,10 +49,11 @@ def __init__( self.config = config self.pre_deployer = PreDeployerViaSDK(apiClientsAndCaches, self.config) - def deploy_vnfd_from_bicep(self, - bicep_path: Optional[str] = None, - parameters_json_file: Optional[str] = None - ) -> None: + def deploy_vnfd_from_bicep( + self, + bicep_path: Optional[str] = None, + parameters_json_file: Optional[str] = None, + ) -> None: """ Deploy the bicep template defining the VNFD. @@ -66,19 +67,21 @@ def deploy_vnfd_from_bicep(self, if not bicep_path: # User has not passed in a bicep template, so we are deploying the default # one produced from building the NFDV using this CLI - bicep_path = os.path.join(self.config.build_output_folder_name, - VNF_DEFINITION_BICEP_SOURCE_TEMPLATE) - + bicep_path = os.path.join( + self.config.build_output_folder_name, + VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, + ) + if parameters_json_file: message: str = f"Use parameters from file {parameters_json_file}" logger.info(message) print(message) with open(parameters_json_file, "r", encoding="utf-8") as f: parameters = json.loads(f.read()) - + else: # User has not passed in parameters file, so we use the parameters required - # from config for the default bicep template produced from building the + # from config for the default bicep template produced from building the # NFDV using this CLI logger.debug("Create parameters for default NFDV template.") parameters = self.construct_vnfd_parameters() @@ -90,22 +93,25 @@ def deploy_vnfd_from_bicep(self, if deploy_manifest_template: print(f"Deploy bicep template for Artifact manifests") logger.debug("Deploy manifest bicep") - manifest_bicep_path = os.path.join(self.config.build_output_folder_name, - VNF_MANIFEST_BICEP_SOURCE_TEMPLATE) + manifest_bicep_path = os.path.join( + self.config.build_output_folder_name, VNF_MANIFEST_BICEP_SOURCE_TEMPLATE + ) manifest_params = self.construct_manifest_parameters() self.deploy_bicep_template(manifest_bicep_path, manifest_params) else: - print(f"Artifact manifests exist for NFD {self.config.nf_name} " - f"version {self.config.version}") - message = (f"Deploy bicep template for NFD {self.config.nf_name} version {self.config.version} " + print( + f"Artifact manifests exist for NFD {self.config.nf_name} " + f"version {self.config.version}" + ) + message = ( + f"Deploy bicep template for NFD {self.config.nf_name} version {self.config.version} " f"into {self.config.publisher_resource_group_name} under publisher " - f"{self.config.publisher_name}") + f"{self.config.publisher_name}" + ) print(message) logger.info(message) self.deploy_bicep_template(bicep_path, parameters) - print( - f"Deployed NFD {self.config.nf_name} version {self.config.version}." - ) + print(f"Deployed NFD {self.config.nf_name} version {self.config.version}.") storage_account_manifest = ArtifactManifestOperator( self.config, @@ -133,8 +139,7 @@ def vnfd_predeploy(self) -> bool: """ All the predeploy steps for a VNF. Create publisher, artifact stores and NFDG. - VNF specific - return True if artifact manifest already exists, False otherwise + VNF specific return True if artifact manifest already exists, False otherwise """ logger.debug("Ensure all required resources exist") self.pre_deployer.ensure_config_resource_group_exists() @@ -161,7 +166,7 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: "vhdVersion": {"value": self.config.vhd.version}, "armTemplateVersion": {"value": self.config.arm_template.version}, } - + def construct_manifest_parameters(self) -> Dict[str, Any]: """ Create the parmeters dictionary for vnfdefinitions.bicep. VNF specific. @@ -179,7 +184,7 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: "vhdVersion": {"value": self.config.vhd.version}, "armTemplateName": {"value": self.config.arm_template.artifact_name}, "armTemplateVersion": {"value": self.config.arm_template.version}, - } + } def deploy_bicep_template( self, bicep_template_path: str, parameters: Dict[Any, Any] diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index f17edb7489f..5f4e7e6f280 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -269,37 +269,32 @@ def ensure_config_nfdg_exists( self.config.nfdg_name, self.config.location, ) - - def does_artifact_manifest_exist(self, - rg_name: str, - publisher_name: str, - store_name: str, - manifest_name: str - ) -> bool: + + def does_artifact_manifest_exist( + self, rg_name: str, publisher_name: str, store_name: str, manifest_name: str + ) -> bool: try: self.api_clients.aosm_client.artifact_manifests.get( resource_group_name=rg_name, publisher_name=publisher_name, artifact_store_name=store_name, - artifact_manifest_name=manifest_name + artifact_manifest_name=manifest_name, ) logger.debug(f"Artifact manifest {manifest_name} exists") return True except azure_exceptions.ResourceNotFoundError: logger.debug(f"Artifact manifest {manifest_name} does not exist") return False - + def do_config_artifact_manifests_exist( self, ): - """ - Returns True if all required manifests exist, False otherwise - """ + """Returns True if all required manifests exist, False otherwise.""" acr_manny_exists: bool = self.does_artifact_manifest_exist( rg_name=self.config.publisher_resource_group_name, publisher_name=self.config.publisher_name, store_name=self.config.acr_artifact_store_name, - manifest_name=self.config.acr_manifest_name + manifest_name=self.config.acr_manifest_name, ) if isinstance(self.config, VNFConfiguration): @@ -307,12 +302,14 @@ def do_config_artifact_manifests_exist( rg_name=self.config.publisher_resource_group_name, publisher_name=self.config.publisher_name, store_name=self.config.blob_artifact_store_name, - manifest_name=self.config.sa_manifest_name + manifest_name=self.config.sa_manifest_name, ) if acr_manny_exists and sa_manny_exists: return True elif acr_manny_exists or sa_manny_exists: - raise AzCLIError("Only one artifact manifest exists. Cannot proceed. Please delete the NFDV using `az aosm definition delete` and start the publish again from scratch.") + raise AzCLIError( + "Only one artifact manifest exists. Cannot proceed. Please delete the NFDV using `az aosm definition delete` and start the publish again from scratch." + ) else: return False diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 5f179d5207f..31f7bc7061b 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -20,8 +20,7 @@ ) from azext_aosm._constants import ( VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, - VNF_DEFINITION_OUTPUT_BICEP_PREFIX, - VNF_MANIFEST_BICEP_SOURCE_TEMPLATE + VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, ) @@ -48,7 +47,9 @@ def __init__(self, config: VNFConfiguration): self.folder_name = self.config.build_output_folder_name self._bicep_path = os.path.join(self.folder_name, self.bicep_template_name) - self._manifest_path = os.path.join(self.folder_name, self.manifest_template_name) + self._manifest_path = os.path.join( + self.folder_name, self.manifest_template_name + ) def generate_nfd(self) -> None: """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" @@ -85,14 +86,14 @@ def bicep_path(self) -> Optional[str]: return self._bicep_path return None - + @property def manifest_path(self) -> Optional[str]: """Returns the path to the bicep file for the NFD if it has been created.""" if os.path.exists(self._manifest_path): return self._manifest_path - return None + return None def _create_nfd_folder(self) -> None: """ From a956ce6cc6d80dabdcd886ad8606f3b45d0a7edb Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 16:02:49 +0100 Subject: [PATCH 024/145] renames --- src/aosm/azext_aosm/_params.py | 2 +- .../{_client_factory.py => client_factory.py} | 0 src/aosm/azext_aosm/commands.py | 2 +- .../{_configuration.py => configuration.py} | 2 +- src/aosm/azext_aosm/custom.py | 14 +- src/aosm/azext_aosm/delete/delete.py | 8 +- src/aosm/azext_aosm/deploy/artifact.py | 2 +- .../azext_aosm/deploy/artifact_manifest.py | 6 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 12 +- src/aosm/azext_aosm/deploy/pre_deploy.py | 12 +- .../generate_nfd/nfd_generator_base.py | 11 +- .../generate_nfd/vnf_bicep_nfd_generator.py | 39 ++---- .../publisher_resources.py | 31 ----- .../{_constants.py => util/constants.py} | 0 .../azext_aosm/util/management_clients.py | 125 +----------------- .../{_validators.py => validators.py} | 0 .../_hybrid_network_management_client.py | 2 +- .../aio/_hybrid_network_management_client.py | 2 +- .../vendored_sdks/aio/operations/__init__.py | 4 +- .../vendored_sdks/operations/__init__.py | 4 +- 20 files changed, 54 insertions(+), 224 deletions(-) rename src/aosm/azext_aosm/{_client_factory.py => client_factory.py} (100%) rename src/aosm/azext_aosm/{_configuration.py => configuration.py} (98%) delete mode 100644 src/aosm/azext_aosm/publisher_resources/publisher_resources.py rename src/aosm/azext_aosm/{_constants.py => util/constants.py} (100%) rename src/aosm/azext_aosm/{_validators.py => validators.py} (100%) diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index e3fb517212b..8fd8fd47cfd 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -8,7 +8,7 @@ from azure.cli.core import AzCommandsLoader # from knack.arguments import CLIArgumentType -from ._constants import VNF, CNF, NSD +from .util.constants import VNF, CNF, NSD def load_arguments(self: AzCommandsLoader, _): diff --git a/src/aosm/azext_aosm/_client_factory.py b/src/aosm/azext_aosm/client_factory.py similarity index 100% rename from src/aosm/azext_aosm/_client_factory.py rename to src/aosm/azext_aosm/client_factory.py diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index c906ca6947e..0f65c359929 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -7,7 +7,7 @@ from azure.cli.core import AzCommandsLoader # from azure.cli.core.commands import CliCommandType -from azext_aosm._client_factory import cf_aosm +from azext_aosm.client_factory import cf_aosm def load_command_table(self: AzCommandsLoader, _): diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/configuration.py similarity index 98% rename from src/aosm/azext_aosm/_configuration.py rename to src/aosm/azext_aosm/configuration.py index 75df986414a..b9a93efa6a2 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/configuration.py @@ -2,7 +2,7 @@ from typing import Dict, Optional, Any from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError from pathlib import Path -from azext_aosm._constants import VNF_DEFINITION_OUTPUT_BICEP_PREFIX, VNF, CNF, NSD +from azext_aosm.util.constants import VNF_DEFINITION_OUTPUT_BICEP_PREFIX, VNF, CNF, NSD DESCRIPTION_MAP: Dict[str, str] = { "publisher_name": "Name of the Publisher resource you want you definition published to", diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 51fb7a55115..feccdfdd1a5 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -12,11 +12,11 @@ from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.generate_nfd.vnf_bicep_nfd_generator import VnfBicepNfdGenerator from azext_aosm.deploy.deploy_with_arm import DeployerViaArm -from azext_aosm._constants import VNF, CNF, NSD -from azext_aosm.util.management_clients import ApiClientsAndCaches +from azext_aosm.util.constants import VNF, CNF, NSD +from azext_aosm.util.management_clients import ApiClients from .vendored_sdks import HybridNetworkManagementClient -from ._client_factory import cf_resources -from ._configuration import get_configuration, validate_configuration, Configuration +from .client_factory import cf_resources +from configuration import get_configuration, validate_configuration, Configuration logger = get_logger(__name__) @@ -43,7 +43,7 @@ def build_definition( :param publish: _description_, defaults to False :type publish: bool, optional """ - api_clients = ApiClientsAndCaches( + api_clients = ApiClients( aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) ) @@ -135,7 +135,7 @@ def publish_definition( for the bicep file """ print("Publishing definition.") - api_clients = ApiClientsAndCaches( + api_clients = ApiClients( aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) ) config = _get_config_from_file(config_file, definition_type) @@ -164,7 +164,7 @@ def delete_published_definition( """ config = _get_config_from_file(config_file, definition_type) - api_clients = ApiClientsAndCaches( + api_clients = ApiClients( aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) ) from azext_aosm.delete.delete import ResourceDeleter diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 45ce6e3887c..1d83ab489d6 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -11,8 +11,8 @@ Provider, ) -from azext_aosm.util.management_clients import ApiClientsAndCaches -from azext_aosm._configuration import Configuration, VNFConfiguration +from azext_aosm.util.management_clients import ApiClients +from azext_aosm.configuration import Configuration, VNFConfiguration from azext_aosm.util.utils import input_ack @@ -22,7 +22,7 @@ class ResourceDeleter: def __init__( self, - apiClientsAndCaches: ApiClientsAndCaches, + ApiClients: ApiClients, config: Configuration, ) -> None: """ @@ -34,7 +34,7 @@ def __init__( :type resource_client: ResourceManagementClient """ logger.debug("Create ARM/Bicep Deployer") - self.api_clients = apiClientsAndCaches + self.api_clients = ApiClients self.config = config def delete_vnf(self, all: bool = False): diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index b8b0287b117..b457a672c8e 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -7,7 +7,7 @@ from typing import Union from azure.storage.blob import BlobClient -from azext_aosm._configuration import ArtifactConfig, DESCRIPTION_MAP +from azext_aosm.configuration import ArtifactConfig, DESCRIPTION_MAP from oras.client import OrasClient logger = get_logger(__name__) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 6dc3c31ea0d..27ac2f003da 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -10,10 +10,10 @@ from azext_aosm.deploy.artifact import Artifact from azure.storage.blob import BlobClient from oras.client import OrasClient -from azext_aosm._configuration import Configuration, VNFConfiguration +from azext_aosm.configuration import Configuration, VNFConfiguration from azext_aosm.vendored_sdks.models import ArtifactAccessCredential, ArtifactManifest -from azext_aosm.util.management_clients import ApiClientsAndCaches +from azext_aosm.util.management_clients import ApiClients logger = get_logger(__name__) @@ -24,7 +24,7 @@ class ArtifactManifestOperator: def __init__( self, config: Configuration, - api_clients: ApiClientsAndCaches, + api_clients: ApiClients, store_name: str, manifest_name: str, ) -> None: diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 553020b7d6e..61dd1ff5346 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -11,13 +11,13 @@ from knack.log import get_logger from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator -from azext_aosm.util.management_clients import ApiClientsAndCaches +from azext_aosm.util.management_clients import ApiClients from azure.mgmt.resource.resources.v2021_04_01.models import DeploymentExtended from pathlib import Path from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK -from azext_aosm._configuration import Configuration, VNFConfiguration -from azext_aosm._constants import ( +from azext_aosm.configuration import Configuration, VNFConfiguration +from azext_aosm.util.constants import ( VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, ) @@ -33,7 +33,7 @@ class DeployerViaArm: # using the SDK def __init__( self, - apiClientsAndCaches: ApiClientsAndCaches, + api_clients: ApiClients, config: Configuration, ) -> None: """ @@ -45,9 +45,9 @@ def __init__( :type resource_client: ResourceManagementClient """ logger.debug("Create ARM/Bicep Deployer") - self.api_clients = apiClientsAndCaches + self.api_clients = api_clients self.config = config - self.pre_deployer = PreDeployerViaSDK(apiClientsAndCaches, self.config) + self.pre_deployer = PreDeployerViaSDK(api_clients, self.config) def deploy_vnfd_from_bicep( self, diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 5f4e7e6f280..174d5ddadca 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -10,9 +10,7 @@ from azure.cli.core.azclierror import AzCLIError from azure.mgmt.resource.resources.v2022_09_01.models import ResourceGroup -from azure.mgmt.resource import ResourceManagementClient -from azext_aosm.util.management_clients import ApiClientsAndCaches -from azext_aosm.vendored_sdks import HybridNetworkManagementClient +from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks.models import ( ArtifactStore, ArtifactStoreType, @@ -20,8 +18,8 @@ NetworkServiceDesignGroup, Publisher, ) -from azext_aosm._configuration import Configuration, VNFConfiguration -from azext_aosm._constants import PROV_STATE_SUCCEEDED +from azext_aosm.configuration import Configuration, VNFConfiguration +from azext_aosm.util.constants import PROV_STATE_SUCCEEDED logger = get_logger(__name__) @@ -31,7 +29,7 @@ class PreDeployerViaSDK: def __init__( self, - apiClientsAndCaches: ApiClientsAndCaches, + api_clients: ApiClients, config: Configuration, ) -> None: """ @@ -43,7 +41,7 @@ def __init__( :type resource_client: ResourceManagementClient """ - self.api_clients = apiClientsAndCaches + self.api_clients = api_clients self.config = config def ensure_resource_group_exists(self, resource_group_name: str) -> None: diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index 2408972bc34..21c2f0c5bac 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -4,7 +4,6 @@ # -------------------------------------------------------------------------------------- """Contains a base class for generating NFDs.""" from knack.log import get_logger -from azext_aosm._configuration import Configuration logger = get_logger(__name__) @@ -15,17 +14,11 @@ class NFDGenerator: def __init__( self, - # config: Configuration ) -> None: """ - _summary_ - - :param definition_type: _description_ - :type definition_type: str - :param config: _description_ - :type config: Configuration + Superclass for NFD generators. The sub-classes do the actual work """ - # self.config = config + pass def generate_nfd(self) -> None: """No-op on base class.""" diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 31f7bc7061b..d27c9642a23 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -14,11 +14,8 @@ from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator -from azext_aosm._configuration import VNFConfiguration -from azext_aosm.publisher_resources.publisher_resources import ( - PublisherResourceGenerator, -) -from azext_aosm._constants import ( +from azext_aosm.configuration import VNFConfiguration +from azext_aosm.util.constants import ( VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, ) @@ -29,15 +26,17 @@ class VnfBicepNfdGenerator(NFDGenerator): """ - _summary_ - - :param NFDGenerator: _description_ - :type NFDGenerator: _type_ + VNF NFD Generator. + + This takes a source ARM template and a config file, and outputs: + - A bicep file for the NFDV + - Parameters files that are used by the NFDV bicep file, these are the + deployParameters and the mapping profiles of those deploy parameters + - A bicep file for the Artifact manifests """ def __init__(self, config: VNFConfiguration): super(NFDGenerator, self).__init__( - # config=config, ) self.config = config self.bicep_template_name = VNF_DEFINITION_BICEP_SOURCE_TEMPLATE @@ -53,7 +52,6 @@ def __init__(self, config: VNFConfiguration): def generate_nfd(self) -> None: """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" - # assert isinstance(self.config, VNFConfiguration) if self.bicep_path: print(f"Using the existing NFD bicep template {self.bicep_path}.") print( @@ -65,13 +63,8 @@ def generate_nfd(self) -> None: def write(self) -> None: """ Create a bicep template for an NFD from the ARM template for the VNF. - - :param arm_template_path: The path to the ARM template for deploying the VNF. - :param nf_name: The name of the NF. - - :return: Path to the bicep file. """ - logger.info("Generate NFD bicep template for %s", self.arm_template_path) + logger.info(f"Generate NFD bicep template for {self.arm_template_path}") print(f"Generate NFD bicep template for {self.arm_template_path}") self._create_nfd_folder() @@ -159,7 +152,7 @@ def write_deployment_parameters(self, folder_path: str) -> None: with open(deployment_parameters_path, "w") as _file: _file.write(json.dumps(deploy_parameters_full, indent=4)) - logger.debug("%s created", deployment_parameters_path) + logger.debug(f"{deployment_parameters_path} created") def write_template_parameters(self, folder_path: str) -> None: """ @@ -177,7 +170,7 @@ def write_template_parameters(self, folder_path: str) -> None: with open(template_parameters_path, "w") as _file: _file.write(json.dumps(template_parameters, indent=4)) - logger.debug("%s created", template_parameters_path) + logger.debug(f"{template_parameters_path} created") def write_vhd_parameters(self, folder_path: str) -> None: """ @@ -204,15 +197,11 @@ def write_vhd_parameters(self, folder_path: str) -> None: with open(vhd_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(vhd_parameters, indent=4)) - logger.debug("%s created", vhd_parameters_path) + logger.debug(f"{vhd_parameters_path} created") def copy_bicep(self) -> None: """ - Copy the bicep template into place. - - :param folder_name: The name of the folder to copy the bicep template to. - - :returns: Path to the bicep file + Copy the bicep templates into the build output folder. """ code_dir = os.path.dirname(__file__) diff --git a/src/aosm/azext_aosm/publisher_resources/publisher_resources.py b/src/aosm/azext_aosm/publisher_resources/publisher_resources.py deleted file mode 100644 index c2a93b785db..00000000000 --- a/src/aosm/azext_aosm/publisher_resources/publisher_resources.py +++ /dev/null @@ -1,31 +0,0 @@ -# -------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT -# License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------- -"""Shared publisher resources.""" -from dataclasses import dataclass -from knack.log import get_logger -from azext_aosm.vendored_sdks.models import NetworkFunctionDefinitionGroup -from azext_aosm._configuration import Configuration - - -logger = get_logger(__name__) - - -@dataclass -class PublisherResourceGenerator: - """Class for generating publisher resources used by various other classes.""" - - config: Configuration - - def generate_nfd_group(self) -> NetworkFunctionDefinitionGroup: - """ - Generate a NFD group with location and description from config. - - :return: _description_ - :rtype: NetworkFunctionDefinitionGroup - """ - return NetworkFunctionDefinitionGroup( - location=self.config.location, - description=f"NFD Group for versions of NFDs for {self.config.nf_name}", - ) diff --git a/src/aosm/azext_aosm/_constants.py b/src/aosm/azext_aosm/util/constants.py similarity index 100% rename from src/aosm/azext_aosm/_constants.py rename to src/aosm/azext_aosm/util/constants.py diff --git a/src/aosm/azext_aosm/util/management_clients.py b/src/aosm/azext_aosm/util/management_clients.py index 541b6686fbb..01e90443a60 100644 --- a/src/aosm/azext_aosm/util/management_clients.py +++ b/src/aosm/azext_aosm/util/management_clients.py @@ -8,137 +8,18 @@ from dataclasses import dataclass from azure.mgmt.resource import ResourceManagementClient from azext_aosm.vendored_sdks import HybridNetworkManagementClient -from typing import Dict, Optional -from azure.mgmt.resource.resources.v2022_09_01.models import Provider logger = get_logger(__name__) -@dataclass -class ProviderInfo: - """Class to return Provider Info information.""" - - namespace: str - resource_type: str - - -class ApiClientsAndCaches: - """A cache for API Clients and API versions for various resources.""" +class ApiClients: + """A class for API Clients needed throughout.""" def __init__( self, aosm_client: HybridNetworkManagementClient, resource_client: ResourceManagementClient, ): + """Initialise with clients.""" self.aosm_client = aosm_client self.resource_client = resource_client - - # We need to find an Azure API version relevant to each resource type. This is - # used in resource finding. We just use the latest and cache these as they are - # expensive to query. - self.resource_type_api_versions_cache: Dict[str, str] = {} - self.providers_cache: Dict[str, Provider] = {} - - def find_latest_api_ver_for_resource_type( - self, resource_type: str - ) -> Optional[str]: - """ - Copied from virtutils. Turns out maybe not needed yet. Expect we will need - when we want to delete resources. - - Find the latest Azure API version for a given resource. - - We do this querying the Azure Providers API - - We just use the latest and cache these as they are expensive to query. - - param: resource_type: String in the format that the providers API uses e.g. - Microsoft.Compute/disks or Microsoft.Compute/virtualMachines/extensions - - Find the namespace and resource type in the format that the providers - API uses by splitting the resource type returned from list_by_resource_group - at the first forward-slash (/), - e.g. Microsoft.Compute/disks would give us namespace Microsoft.Compute and - provider resource type disks - whereas Microsoft.Compute/virtualMachines/extensions would give us - namespace Microsoft.Compute and provicer resource type - virtualMachines/extensions. This seems to match what the provider API - uses. - - We cache values as this can take a few seconds to return. - - :param resource: A resource, as returned from list_by_resource_group - :raises RuntimeError: If no provider found in Azure for this resource - :raises RuntimeError: If the resource type is an unexpected format - """ - logger.debug(f"Find API version for {resource_type}") - # We need to find an API version relevant to the resource. - if resource_type in self.resource_type_api_versions_cache.keys(): - # We have one cached, just return that - logger.debug("Return cached API version") - return self.resource_type_api_versions_cache.get(resource_type) - - # Start with e.g. Microsoft.Compute/disks (resource_type) - assert resource_type is not None - prov_info = self.get_provider_info(resource_type) - # We now have Microsoft.Compute and disks - if prov_info.namespace not in self.providers_cache.keys(): - # Get the provider e.g. Microsoft.Compute - logger.debug(f"Find provider {prov_info.namespace}") - try: - provider = self.resource_client.providers.get(prov_info.namespace) - except Exception as provEx: - raise RuntimeError( - f"Could not find provider {prov_info.namespace} required " - f"to query resource of type {resource_type}. Aborting" - ) from provEx - - self.providers_cache[prov_info.namespace] = provider - else: - # Resource type that we haven't found before but the provider is cached - # so use that. - provider = self.providers_cache[prov_info.namespace] - - # Iterate through the providers resource types and find the one - # we want, e.g. disks or virtualMachines/extensions - for res_type in provider.resource_types: - if res_type.resource_type == prov_info.resource_type: - # Find the latest API version and cache it - # The first index appears to always be the latest version - api_version = res_type.api_versions[0] - logger.debug(f"Use API version {api_version} for {resource_type}") - - assert resource_type is not None - self.resource_type_api_versions_cache[resource_type] = api_version - return api_version - - raise RuntimeError( - f"Azure API did not return an API version for {resource_type}." - f"Cannot query API version" - ) - - def get_provider_info(self, resource_type: str) -> ProviderInfo: - """ - Find provider namespace and resource_type, given a full resource_type. - - param: resource_type: String in the format that the providers API uses e.g. - Microsoft.Compute/disks or Microsoft.Compute/virtualMachines/extensions - - Find the namespace and resource type in the format that the providers - API uses by splitting the resource type returned from list_by_resource_group - at the first forward-slash (/), - e.g. Microsoft.Compute/disks would give us namespace Microsoft.Compute and - provider resource type disks - whereas Microsoft.Compute/virtualMachines/extensions would give us - namespace Microsoft.Compute and provicer resource type - virtualMachines/extensions. This seems to match what the provider API - uses. - """ - prov_namespace_type = resource_type.split("/", 1) - if len(prov_namespace_type) != 2: - raise RuntimeError( - f"Azure resource type {resource_type} " - "is in unexpected format. Cannot find API version." - ) - # print(f"Namespace {prov_namespace_type[0]} type {prov_namespace_type[1]}") - return ProviderInfo(prov_namespace_type[0], prov_namespace_type[1]) diff --git a/src/aosm/azext_aosm/_validators.py b/src/aosm/azext_aosm/validators.py similarity index 100% rename from src/aosm/azext_aosm/_validators.py rename to src/aosm/azext_aosm/validators.py diff --git a/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py b/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py index fa704c623bc..b3e1f4fbb59 100644 --- a/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py +++ b/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py @@ -14,7 +14,7 @@ from azure.mgmt.core import ARMPipelineClient from . import models -from ._configuration import HybridNetworkManagementClientConfiguration +from configuration import HybridNetworkManagementClientConfiguration from .operations import ArtifactManifestsOperations, ArtifactStoresOperations, ComponentsOperations, ConfigurationGroupSchemasOperations, ConfigurationGroupValuesOperations, HybridNetworkManagementClientOperationsMixin, NetworkFunctionDefinitionGroupsOperations, NetworkFunctionDefinitionVersionsOperations, NetworkFunctionReadyK8SOperations, NetworkFunctionsOperations, NetworkServiceDesignGroupsOperations, NetworkServiceDesignVersionsOperations, Operations, PreviewSubscriptionsOperations, ProxyArtifactOperations, ProxyNetworkFunctionDefinitionGroupsOperations, ProxyNetworkFunctionDefinitionVersionsOperations, ProxyPublisherOperations, PublishersOperations, SiteNetworkServicesOperations, SitesOperations if TYPE_CHECKING: diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py b/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py index 891ddcb7041..d1f51fc70f8 100644 --- a/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py +++ b/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py @@ -15,7 +15,7 @@ from azure.mgmt.core import AsyncARMPipelineClient from .. import models -from ._configuration import HybridNetworkManagementClientConfiguration +from configuration import HybridNetworkManagementClientConfiguration from .operations import ArtifactManifestsOperations, ArtifactStoresOperations, ComponentsOperations, ConfigurationGroupSchemasOperations, ConfigurationGroupValuesOperations, HybridNetworkManagementClientOperationsMixin, NetworkFunctionDefinitionGroupsOperations, NetworkFunctionDefinitionVersionsOperations, NetworkFunctionReadyK8SOperations, NetworkFunctionsOperations, NetworkServiceDesignGroupsOperations, NetworkServiceDesignVersionsOperations, Operations, PreviewSubscriptionsOperations, ProxyArtifactOperations, ProxyNetworkFunctionDefinitionGroupsOperations, ProxyNetworkFunctionDefinitionVersionsOperations, ProxyPublisherOperations, PublishersOperations, SiteNetworkServicesOperations, SitesOperations if TYPE_CHECKING: diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py index 6c86a395e1f..7fea97473ae 100644 --- a/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py @@ -6,8 +6,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._configuration_group_schemas_operations import ConfigurationGroupSchemasOperations -from ._configuration_group_values_operations import ConfigurationGroupValuesOperations +from configuration_group_schemas_operations import ConfigurationGroupSchemasOperations +from configuration_group_values_operations import ConfigurationGroupValuesOperations from ._network_functions_operations import NetworkFunctionsOperations from ._components_operations import ComponentsOperations from ._network_function_definition_groups_operations import NetworkFunctionDefinitionGroupsOperations diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py b/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py index 6c86a395e1f..7fea97473ae 100644 --- a/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py +++ b/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py @@ -6,8 +6,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from ._configuration_group_schemas_operations import ConfigurationGroupSchemasOperations -from ._configuration_group_values_operations import ConfigurationGroupValuesOperations +from configuration_group_schemas_operations import ConfigurationGroupSchemasOperations +from configuration_group_values_operations import ConfigurationGroupValuesOperations from ._network_functions_operations import NetworkFunctionsOperations from ._components_operations import ComponentsOperations from ._network_function_definition_groups_operations import NetworkFunctionDefinitionGroupsOperations From 7088b067ff771f1acb51beb71f3d29f9ccaa914f Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 16:03:43 +0100 Subject: [PATCH 025/145] style --- .../generate_nfd/nfd_generator_base.py | 4 +++- .../generate_nfd/vnf_bicep_nfd_generator.py | 17 ++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index 21c2f0c5bac..81afb4db802 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -16,7 +16,9 @@ def __init__( self, ) -> None: """ - Superclass for NFD generators. The sub-classes do the actual work + Superclass for NFD generators. + + The sub-classes do the actual work """ pass diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index d27c9642a23..88dd29c1b09 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -26,18 +26,17 @@ class VnfBicepNfdGenerator(NFDGenerator): """ - VNF NFD Generator. - + VNF NFD Generator. + This takes a source ARM template and a config file, and outputs: - A bicep file for the NFDV - - Parameters files that are used by the NFDV bicep file, these are the + - Parameters files that are used by the NFDV bicep file, these are the deployParameters and the mapping profiles of those deploy parameters - A bicep file for the Artifact manifests """ def __init__(self, config: VNFConfiguration): - super(NFDGenerator, self).__init__( - ) + super(NFDGenerator, self).__init__() self.config = config self.bicep_template_name = VNF_DEFINITION_BICEP_SOURCE_TEMPLATE self.manifest_template_name = VNF_MANIFEST_BICEP_SOURCE_TEMPLATE @@ -61,9 +60,7 @@ def generate_nfd(self) -> None: self.write() def write(self) -> None: - """ - Create a bicep template for an NFD from the ARM template for the VNF. - """ + """Create a bicep template for an NFD from the ARM template for the VNF.""" logger.info(f"Generate NFD bicep template for {self.arm_template_path}") print(f"Generate NFD bicep template for {self.arm_template_path}") @@ -200,9 +197,7 @@ def write_vhd_parameters(self, folder_path: str) -> None: logger.debug(f"{vhd_parameters_path} created") def copy_bicep(self) -> None: - """ - Copy the bicep templates into the build output folder. - """ + """Copy the bicep templates into the build output folder.""" code_dir = os.path.dirname(__file__) bicep_path = os.path.join(code_dir, "templates", self.bicep_template_name) From 3e224a2947c5af8847316b734e967fec9923d163 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 16:19:01 +0100 Subject: [PATCH 026/145] lint and reverse some renames --- src/aosm/azext_aosm/__init__.py | 2 +- .../{client_factory.py => _client_factory.py} | 0 .../azext_aosm/{validators.py => _validators.py} | 0 src/aosm/azext_aosm/commands.py | 2 +- src/aosm/azext_aosm/configuration.py | 12 +++++++++--- src/aosm/azext_aosm/custom.py | 10 +++++----- 6 files changed, 16 insertions(+), 10 deletions(-) rename src/aosm/azext_aosm/{client_factory.py => _client_factory.py} (100%) rename src/aosm/azext_aosm/{validators.py => _validators.py} (100%) diff --git a/src/aosm/azext_aosm/__init__.py b/src/aosm/azext_aosm/__init__.py index a9098c4d1fb..c81f2e277cc 100644 --- a/src/aosm/azext_aosm/__init__.py +++ b/src/aosm/azext_aosm/__init__.py @@ -13,7 +13,7 @@ def __init__(self, cli_ctx=None): from azure.cli.core.commands import CliCommandType aosm_custom = CliCommandType(operations_tmpl="azext_aosm.custom#{}") - super(AosmCommandsLoader, self).__init__( + super().__init__( cli_ctx=cli_ctx, custom_command_type=aosm_custom ) diff --git a/src/aosm/azext_aosm/client_factory.py b/src/aosm/azext_aosm/_client_factory.py similarity index 100% rename from src/aosm/azext_aosm/client_factory.py rename to src/aosm/azext_aosm/_client_factory.py diff --git a/src/aosm/azext_aosm/validators.py b/src/aosm/azext_aosm/_validators.py similarity index 100% rename from src/aosm/azext_aosm/validators.py rename to src/aosm/azext_aosm/_validators.py diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index 0f65c359929..c906ca6947e 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -7,7 +7,7 @@ from azure.cli.core import AzCommandsLoader # from azure.cli.core.commands import CliCommandType -from azext_aosm.client_factory import cf_aosm +from azext_aosm._client_factory import cf_aosm def load_command_table(self: AzCommandsLoader, _): diff --git a/src/aosm/azext_aosm/configuration.py b/src/aosm/azext_aosm/configuration.py index b9a93efa6a2..c0b6e1bdc7a 100644 --- a/src/aosm/azext_aosm/configuration.py +++ b/src/aosm/azext_aosm/configuration.py @@ -1,7 +1,7 @@ from dataclasses import dataclass from typing import Dict, Optional, Any -from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError from pathlib import Path +from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError from azext_aosm.util.constants import VNF_DEFINITION_OUTPUT_BICEP_PREFIX, VNF, CNF, NSD DESCRIPTION_MAP: Dict[str, str] = { @@ -13,8 +13,14 @@ "location": "Azure location of the resources", "blob_artifact_store_name": "Name of the storage account Artifact Store resource", "artifact_name": "Name of the artifact", - "file_path": "Optional. File path of the artifact you wish to upload from your local disk. Delete if not required.", - "blob_sas_url": "Optional. SAS URL of the blob artifact you wish to copy to your Artifact Store. Delete if not required.", + "file_path": ( + "Optional. File path of the artifact you wish to upload from your " + "local disk. Delete if not required." + ), + "blob_sas_url": ( + "Optional. SAS URL of the blob artifact you wish to copy to your " + "Artifact Store. Delete if not required." + ), "artifact_version": ( "Version of the artifact. For VHDs this must be in format A-B-C. " "For ARM templates this must be in format A.B.C" diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index feccdfdd1a5..171ca767b2f 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -5,18 +5,18 @@ import json from dataclasses import asdict -from knack.log import get_logger from typing import Optional +from knack.log import get_logger from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.generate_nfd.vnf_bicep_nfd_generator import VnfBicepNfdGenerator from azext_aosm.deploy.deploy_with_arm import DeployerViaArm -from azext_aosm.util.constants import VNF, CNF, NSD +from azext_aosm.util.constants import VNF, CNF #, NSD from azext_aosm.util.management_clients import ApiClients -from .vendored_sdks import HybridNetworkManagementClient -from .client_factory import cf_resources -from configuration import get_configuration, validate_configuration, Configuration +from azext_aosm.vendored_sdks import HybridNetworkManagementClient +from azext_aosm._client_factory import cf_resources +from azext_aosm.configuration import get_configuration, validate_configuration, Configuration logger = get_logger(__name__) From 155c53316e8ec1d336e1ece9b80cee5891d8464b Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 16:29:58 +0100 Subject: [PATCH 027/145] dev instructions --- src/aosm/setup.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/aosm/setup.md diff --git a/src/aosm/setup.md b/src/aosm/setup.md new file mode 100644 index 00000000000..72158ac3d44 --- /dev/null +++ b/src/aosm/setup.md @@ -0,0 +1,46 @@ +### Prerequisites + +1. `python 3.8+` + + +### Dev environment setup + +Follow [https://github.com/Azure/azure-cli-dev-tools](https://github.com/Azure/azure-cli-dev-tools) + +Clone both azure-cli and azure-cli-extensions +```bash +# Go into your git clone of az-cli-extensions +cd az-cli-extensions + +# Create a virtual environment to run in +python3.8 -m venv ~/.virtualenvs/az-cli-env +source ~/.virtualenvs/az-cli-env/bin/activate + +# Ensure you have pip +python -m pip install -U pip + +# Install azdev +pip install azdev + +# Install all the python dependencies you need +azdev setup --cli /home/developer/code/azure-cli --repo . + +# Add the extension to your local CLI +azdev extension add aosm +``` +### VSCode environment setup. + +Make sure your VSCode is running in the same python virtual environment + +### Linting and Tests +```bash +azdev style aosm +azdev linter --include-whl-extensions aosm +(Not written any tests yet) +azdev test aosm +``` +You can use python-static-checks in your dev environment if you want, to help you: +```bash +pip3 install -U --index-url https://pkgs.dev.azure.com/msazuredev/AzureForOperators/_packaging/python/pypi/simple/ python-static-checks==4.0.0 +python-static-checks fmt +``` From edd5d1022ea2020bc5b11a14fc0889a033b141ca Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 17:08:00 +0100 Subject: [PATCH 028/145] oops. bad find and replace work. --- .../vendored_sdks/_hybrid_network_management_client.py | 2 +- .../vendored_sdks/aio/_hybrid_network_management_client.py | 2 +- src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py | 4 ++-- src/aosm/azext_aosm/vendored_sdks/operations/__init__.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py b/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py index b3e1f4fbb59..aa35ac07132 100644 --- a/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py +++ b/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py @@ -14,7 +14,7 @@ from azure.mgmt.core import ARMPipelineClient from . import models -from configuration import HybridNetworkManagementClientConfiguration +from _configuration import HybridNetworkManagementClientConfiguration from .operations import ArtifactManifestsOperations, ArtifactStoresOperations, ComponentsOperations, ConfigurationGroupSchemasOperations, ConfigurationGroupValuesOperations, HybridNetworkManagementClientOperationsMixin, NetworkFunctionDefinitionGroupsOperations, NetworkFunctionDefinitionVersionsOperations, NetworkFunctionReadyK8SOperations, NetworkFunctionsOperations, NetworkServiceDesignGroupsOperations, NetworkServiceDesignVersionsOperations, Operations, PreviewSubscriptionsOperations, ProxyArtifactOperations, ProxyNetworkFunctionDefinitionGroupsOperations, ProxyNetworkFunctionDefinitionVersionsOperations, ProxyPublisherOperations, PublishersOperations, SiteNetworkServicesOperations, SitesOperations if TYPE_CHECKING: diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py b/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py index d1f51fc70f8..05b0ab4e4b5 100644 --- a/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py +++ b/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py @@ -15,7 +15,7 @@ from azure.mgmt.core import AsyncARMPipelineClient from .. import models -from configuration import HybridNetworkManagementClientConfiguration +from._configuration import HybridNetworkManagementClientConfiguration from .operations import ArtifactManifestsOperations, ArtifactStoresOperations, ComponentsOperations, ConfigurationGroupSchemasOperations, ConfigurationGroupValuesOperations, HybridNetworkManagementClientOperationsMixin, NetworkFunctionDefinitionGroupsOperations, NetworkFunctionDefinitionVersionsOperations, NetworkFunctionReadyK8SOperations, NetworkFunctionsOperations, NetworkServiceDesignGroupsOperations, NetworkServiceDesignVersionsOperations, Operations, PreviewSubscriptionsOperations, ProxyArtifactOperations, ProxyNetworkFunctionDefinitionGroupsOperations, ProxyNetworkFunctionDefinitionVersionsOperations, ProxyPublisherOperations, PublishersOperations, SiteNetworkServicesOperations, SitesOperations if TYPE_CHECKING: diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py index 7fea97473ae..fd005f9ca27 100644 --- a/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py @@ -6,8 +6,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from configuration_group_schemas_operations import ConfigurationGroupSchemasOperations -from configuration_group_values_operations import ConfigurationGroupValuesOperations +from._configuration_group_schemas_operations import ConfigurationGroupSchemasOperations +from._configuration_group_values_operations import ConfigurationGroupValuesOperations from ._network_functions_operations import NetworkFunctionsOperations from ._components_operations import ComponentsOperations from ._network_function_definition_groups_operations import NetworkFunctionDefinitionGroupsOperations diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py b/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py index 7fea97473ae..fd005f9ca27 100644 --- a/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py +++ b/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py @@ -6,8 +6,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from configuration_group_schemas_operations import ConfigurationGroupSchemasOperations -from configuration_group_values_operations import ConfigurationGroupValuesOperations +from._configuration_group_schemas_operations import ConfigurationGroupSchemasOperations +from._configuration_group_values_operations import ConfigurationGroupValuesOperations from ._network_functions_operations import NetworkFunctionsOperations from ._components_operations import ComponentsOperations from ._network_function_definition_groups_operations import NetworkFunctionDefinitionGroupsOperations From d2e19c28bd1feb4b208163204e6f4fd1a70dc678 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 17:17:53 +0100 Subject: [PATCH 029/145] undo friday afternoon bad changes --- .../{configuration.py => _configuration.py} | 0 src/aosm/azext_aosm/custom.py | 2 +- src/aosm/azext_aosm/delete/delete.py | 2 +- src/aosm/azext_aosm/deploy/artifact.py | 2 +- .../azext_aosm/deploy/artifact_manifest.py | 2 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 2 +- src/aosm/azext_aosm/deploy/pre_deploy.py | 2 +- .../generate_nfd/vnf_bicep_nfd_generator.py | 2 +- src/aosm/azext_aosm/test.py | 38 ------------------- .../_hybrid_network_management_client.py | 2 +- .../aio/_hybrid_network_management_client.py | 2 +- .../vendored_sdks/aio/operations/__init__.py | 4 +- .../vendored_sdks/operations/__init__.py | 4 +- 13 files changed, 13 insertions(+), 51 deletions(-) rename src/aosm/azext_aosm/{configuration.py => _configuration.py} (100%) delete mode 100644 src/aosm/azext_aosm/test.py diff --git a/src/aosm/azext_aosm/configuration.py b/src/aosm/azext_aosm/_configuration.py similarity index 100% rename from src/aosm/azext_aosm/configuration.py rename to src/aosm/azext_aosm/_configuration.py diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 171ca767b2f..9e8905d99e3 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -16,7 +16,7 @@ from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks import HybridNetworkManagementClient from azext_aosm._client_factory import cf_resources -from azext_aosm.configuration import get_configuration, validate_configuration, Configuration +from azext_aosm._configuration import get_configuration, validate_configuration, Configuration logger = get_logger(__name__) diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 1d83ab489d6..40d7987f086 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -12,7 +12,7 @@ ) from azext_aosm.util.management_clients import ApiClients -from azext_aosm.configuration import Configuration, VNFConfiguration +from azext_aosm._configuration import Configuration, VNFConfiguration from azext_aosm.util.utils import input_ack diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index b457a672c8e..b8b0287b117 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -7,7 +7,7 @@ from typing import Union from azure.storage.blob import BlobClient -from azext_aosm.configuration import ArtifactConfig, DESCRIPTION_MAP +from azext_aosm._configuration import ArtifactConfig, DESCRIPTION_MAP from oras.client import OrasClient logger = get_logger(__name__) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 27ac2f003da..0d460a717c0 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -10,7 +10,7 @@ from azext_aosm.deploy.artifact import Artifact from azure.storage.blob import BlobClient from oras.client import OrasClient -from azext_aosm.configuration import Configuration, VNFConfiguration +from azext_aosm._configuration import Configuration, VNFConfiguration from azext_aosm.vendored_sdks.models import ArtifactAccessCredential, ArtifactManifest from azext_aosm.util.management_clients import ApiClients diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 61dd1ff5346..c422f6fc2dc 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -16,7 +16,7 @@ from pathlib import Path from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK -from azext_aosm.configuration import Configuration, VNFConfiguration +from azext_aosm._configuration import Configuration, VNFConfiguration from azext_aosm.util.constants import ( VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 174d5ddadca..320139efadf 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -18,7 +18,7 @@ NetworkServiceDesignGroup, Publisher, ) -from azext_aosm.configuration import Configuration, VNFConfiguration +from azext_aosm._configuration import Configuration, VNFConfiguration from azext_aosm.util.constants import PROV_STATE_SUCCEEDED logger = get_logger(__name__) diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 88dd29c1b09..2b0768c6291 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -14,7 +14,7 @@ from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator -from azext_aosm.configuration import VNFConfiguration +from azext_aosm._configuration import VNFConfiguration from azext_aosm.util.constants import ( VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, diff --git a/src/aosm/azext_aosm/test.py b/src/aosm/azext_aosm/test.py deleted file mode 100644 index 4c914d0dc3c..00000000000 --- a/src/aosm/azext_aosm/test.py +++ /dev/null @@ -1,38 +0,0 @@ -from azext_aosm.vendored_sdks import HybridNetworkManagementClient -from azext_aosm.vendored_sdks.models import ( - NetworkFunctionDefinitionVersion, - NetworkFunctionDefinitionGroup, - ArtifactManifest, - ManifestArtifactFormat, - VersionState, - NetworkFunctionType, - NFVIType, - ArtifactType, - VirtualNetworkFunctionDefinitionVersion, # this is actually properties, badly named - AzureCoreNetworkFunctionTemplate, - AzureCoreNetworkFunctionVhdApplication, - AzureCoreNetworkFunctionArmTemplateApplication, -) - -vnf_props = VirtualNetworkFunctionDefinitionVersion( - version_state=VersionState.PREVIEW, - deploy_parameters="TODO", - network_function_template=AzureCoreNetworkFunctionTemplate( - network_function_applications=[ - AzureCoreNetworkFunctionVhdApplication(), - AzureCoreNetworkFunctionArmTemplateApplication(), - ] - ), -) - -# test_dict = dict(**vnf_props) -print(vnf_props.__dict__) - -nfdv = NetworkFunctionDefinitionVersion( - location="uksouth", - # network_function_type="VirtualNetworkFunction", - # Think kwargs map magically to properties in bicep, somehow - **vnf_props.__dict__ -) - -print(nfdv) diff --git a/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py b/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py index aa35ac07132..fa704c623bc 100644 --- a/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py +++ b/src/aosm/azext_aosm/vendored_sdks/_hybrid_network_management_client.py @@ -14,7 +14,7 @@ from azure.mgmt.core import ARMPipelineClient from . import models -from _configuration import HybridNetworkManagementClientConfiguration +from ._configuration import HybridNetworkManagementClientConfiguration from .operations import ArtifactManifestsOperations, ArtifactStoresOperations, ComponentsOperations, ConfigurationGroupSchemasOperations, ConfigurationGroupValuesOperations, HybridNetworkManagementClientOperationsMixin, NetworkFunctionDefinitionGroupsOperations, NetworkFunctionDefinitionVersionsOperations, NetworkFunctionReadyK8SOperations, NetworkFunctionsOperations, NetworkServiceDesignGroupsOperations, NetworkServiceDesignVersionsOperations, Operations, PreviewSubscriptionsOperations, ProxyArtifactOperations, ProxyNetworkFunctionDefinitionGroupsOperations, ProxyNetworkFunctionDefinitionVersionsOperations, ProxyPublisherOperations, PublishersOperations, SiteNetworkServicesOperations, SitesOperations if TYPE_CHECKING: diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py b/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py index 05b0ab4e4b5..891ddcb7041 100644 --- a/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py +++ b/src/aosm/azext_aosm/vendored_sdks/aio/_hybrid_network_management_client.py @@ -15,7 +15,7 @@ from azure.mgmt.core import AsyncARMPipelineClient from .. import models -from._configuration import HybridNetworkManagementClientConfiguration +from ._configuration import HybridNetworkManagementClientConfiguration from .operations import ArtifactManifestsOperations, ArtifactStoresOperations, ComponentsOperations, ConfigurationGroupSchemasOperations, ConfigurationGroupValuesOperations, HybridNetworkManagementClientOperationsMixin, NetworkFunctionDefinitionGroupsOperations, NetworkFunctionDefinitionVersionsOperations, NetworkFunctionReadyK8SOperations, NetworkFunctionsOperations, NetworkServiceDesignGroupsOperations, NetworkServiceDesignVersionsOperations, Operations, PreviewSubscriptionsOperations, ProxyArtifactOperations, ProxyNetworkFunctionDefinitionGroupsOperations, ProxyNetworkFunctionDefinitionVersionsOperations, ProxyPublisherOperations, PublishersOperations, SiteNetworkServicesOperations, SitesOperations if TYPE_CHECKING: diff --git a/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py b/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py index fd005f9ca27..6c86a395e1f 100644 --- a/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py +++ b/src/aosm/azext_aosm/vendored_sdks/aio/operations/__init__.py @@ -6,8 +6,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from._configuration_group_schemas_operations import ConfigurationGroupSchemasOperations -from._configuration_group_values_operations import ConfigurationGroupValuesOperations +from ._configuration_group_schemas_operations import ConfigurationGroupSchemasOperations +from ._configuration_group_values_operations import ConfigurationGroupValuesOperations from ._network_functions_operations import NetworkFunctionsOperations from ._components_operations import ComponentsOperations from ._network_function_definition_groups_operations import NetworkFunctionDefinitionGroupsOperations diff --git a/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py b/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py index fd005f9ca27..6c86a395e1f 100644 --- a/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py +++ b/src/aosm/azext_aosm/vendored_sdks/operations/__init__.py @@ -6,8 +6,8 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from._configuration_group_schemas_operations import ConfigurationGroupSchemasOperations -from._configuration_group_values_operations import ConfigurationGroupValuesOperations +from ._configuration_group_schemas_operations import ConfigurationGroupSchemasOperations +from ._configuration_group_values_operations import ConfigurationGroupValuesOperations from ._network_functions_operations import NetworkFunctionsOperations from ._components_operations import ComponentsOperations from ._network_function_definition_groups_operations import NetworkFunctionDefinitionGroupsOperations From 1aaa00a6931e548353c449ce4e70dc4a0196dcaa Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 17:36:16 +0100 Subject: [PATCH 030/145] manifest optional --- src/aosm/azext_aosm/__init__.py | 4 +- src/aosm/azext_aosm/_params.py | 18 ++++++- src/aosm/azext_aosm/custom.py | 53 ++++++++++++------- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 23 ++++++-- src/aosm/setup.md | 3 ++ 5 files changed, 71 insertions(+), 30 deletions(-) diff --git a/src/aosm/azext_aosm/__init__.py b/src/aosm/azext_aosm/__init__.py index c81f2e277cc..c15badcb435 100644 --- a/src/aosm/azext_aosm/__init__.py +++ b/src/aosm/azext_aosm/__init__.py @@ -13,9 +13,7 @@ def __init__(self, cli_ctx=None): from azure.cli.core.commands import CliCommandType aosm_custom = CliCommandType(operations_tmpl="azext_aosm.custom#{}") - super().__init__( - cli_ctx=cli_ctx, custom_command_type=aosm_custom - ) + super().__init__(cli_ctx=cli_ctx, custom_command_type=aosm_custom) def load_command_table(self, args): from azext_aosm.commands import load_command_table diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index 8fd8fd47cfd..9c13619fabf 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -44,8 +44,8 @@ def load_arguments(self: AzCommandsLoader, _): help="Also delete artifact stores, NFD Group and Publisher. Use with care.", ) c.argument( - "bicep_file", - options_list=["--bicep-file", "-b"], + "definition_file", + options_list=["--definition-file", "-b"], type=file_type, completer=FilesCompleter(allowednames="*.json"), help="Optional path to a bicep file to publish. Use to override publish of the built definition with an alternative file.", @@ -57,6 +57,20 @@ def load_arguments(self: AzCommandsLoader, _): completer=FilesCompleter(allowednames="*.json"), help="Optional path to a parameters file for the bicep definition file. Use to override publish of the built definition and config with alternative parameters.", ) + c.argument( + "manifest_file", + options_list=["--manifest-file", "-m"], + type=file_type, + completer=FilesCompleter(allowednames="*.json"), + help="Optional path to a bicep file to publish manifests. Use to override publish of the built definition with an alternative file.", + ) + c.argument( + "manifest_parameters_json_file", + options_list=["--manifest-parameters-file", "-mp"], + type=file_type, + completer=FilesCompleter(allowednames="*.json"), + help="Optional path to a parameters file for the manifest definition file. Use to override publish of the built definition and config with alternative parameters.", + ) with self.argument_context("aosm generate-config") as c: c.argument( diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 9e8905d99e3..b615e67916e 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -12,11 +12,15 @@ from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.generate_nfd.vnf_bicep_nfd_generator import VnfBicepNfdGenerator from azext_aosm.deploy.deploy_with_arm import DeployerViaArm -from azext_aosm.util.constants import VNF, CNF #, NSD +from azext_aosm.util.constants import VNF, CNF # , NSD from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks import HybridNetworkManagementClient from azext_aosm._client_factory import cf_resources -from azext_aosm._configuration import get_configuration, validate_configuration, Configuration +from azext_aosm._configuration import ( + get_configuration, + validate_configuration, + Configuration, +) logger = get_logger(__name__) @@ -32,14 +36,12 @@ def build_definition( """ Build and optionally publish a definition. - :param cmd: _description_ + :param cmd: :type cmd: _type_ - :param client: _description_ + :param client: :type client: HybridNetworkManagementClient - :param definition_type: _description_ - :type definition_type: _type_ - :param config_file: _description_ - :type config_file: _type_ + :param config_file: path to the file + :param definition_type: VNF, CNF or NSD :param publish: _description_, defaults to False :type publish: bool, optional """ @@ -47,11 +49,11 @@ def build_definition( aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) ) + # Read the config from the given file config = _get_config_from_file(config_file, definition_type) # Generate the NFD/NSD and the artifact manifest. _generate_nfd(definition_type=definition_type, config=config) - # Write the ARM/bicep template if that's what we are doing # Publish the definition if publish is true if publish: @@ -63,6 +65,13 @@ def build_definition( def generate_definition_config(definition_type: str, output_file: str = "input.json"): + """ + Generate an example config file for building a definition. + + :param definition_type: CNF, VNF or NSD + :param output_file: path to output config file, defaults to "input.json" + :type output_file: str, optional + """ config = get_configuration(definition_type) config_as_dict = json.dumps(asdict(config), indent=4) @@ -89,12 +98,7 @@ def _get_config_from_file(config_file: str, definition_type: str) -> Configurati def _generate_nfd(definition_type, config): - """ - _summary_ - - :param definition_type: _description_ - :type definition_type: _type_ - """ + """Generate a Network Function Definition for the given type and config.""" nfd_generator: NFDGenerator if definition_type == VNF: nfd_generator = VnfBicepNfdGenerator(config) @@ -115,24 +119,30 @@ def publish_definition( client: HybridNetworkManagementClient, definition_type, config_file, - bicep_file: Optional[str] = None, + definition_file: Optional[str] = None, parameters_json_file: Optional[str] = None, + manifest_file: Optional[str] = None, + manifest_parameters_json_file: Optional[str] = None, ): """ - _summary_ + Publish a generated definition. :param cmd: :param client: :type client: HybridNetworkManagementClient :param definition_type: VNF or CNF :param config_file: Path to the config file for the NFDV - :param bicep_file: Optional path to a bicep template to deploy, in case the user + :param definition_file: Optional path to a bicep template to deploy, in case the user wants to edit the built NFDV template. If omitted, the default - built NFDV template will be used + built NFDV template will be used. :param parameters_json_file: Optional path to a parameters file for the bicep file, in case the user wants to edit the built NFDV template. If omitted, parameters from config will be turned into parameters for the bicep file + :param manifest_file: Optional path to an override bicep template to deploy + manifests + :param manifest_parameters_json_file: Optional path to an override bicep parameters + file for manifest parameters """ print("Publishing definition.") api_clients = ApiClients( @@ -142,7 +152,10 @@ def publish_definition( if definition_type == VNF: deployer = DeployerViaArm(api_clients, config=config) deployer.deploy_vnfd_from_bicep( - bicep_path=bicep_file, parameters_json_file=parameters_json_file + bicep_path=definition_file, + parameters_json_file=parameters_json_file, + manifest_bicep_path=manifest_file, + manifest_parameters_json_file=manifest_parameters_json_file, ) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index c422f6fc2dc..753cb4864bf 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -53,14 +53,20 @@ def deploy_vnfd_from_bicep( self, bicep_path: Optional[str] = None, parameters_json_file: Optional[str] = None, + manifest_bicep_path: Optional[str] = None, + manifest_parameters_json_file: Optional[str] = None, ) -> None: """ Deploy the bicep template defining the VNFD. Also ensure that all required predeploy resources are deployed. - :param bicep_template_path: The path to the bicep template of the + :param bicep_template_path: The path to the bicep template of the nfdv :type bicep_template_path: str + :parameters_json_file: path to an override file of set parameters for the nfdv + :param manifest_bicep_path: The path to the bicep template of the manifest + :manifest_parameters_json_file: path to an override file of set parameters for + the manifest """ assert isinstance(self.config, VNFConfiguration) @@ -93,10 +99,17 @@ def deploy_vnfd_from_bicep( if deploy_manifest_template: print(f"Deploy bicep template for Artifact manifests") logger.debug("Deploy manifest bicep") - manifest_bicep_path = os.path.join( - self.config.build_output_folder_name, VNF_MANIFEST_BICEP_SOURCE_TEMPLATE - ) - manifest_params = self.construct_manifest_parameters() + if not manifest_bicep_path: + manifest_bicep_path = os.path.join( + self.config.build_output_folder_name, + VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, + ) + if not manifest_parameters_json_file: + manifest_params = self.construct_manifest_parameters() + else: + logger.info("Use provided manifest parameters") + with open(manifest_parameters_json_file, "r", encoding="utf-8") as f: + manifest_params = json.loads(f.read()) self.deploy_bicep_template(manifest_bicep_path, manifest_params) else: print( diff --git a/src/aosm/setup.md b/src/aosm/setup.md index 72158ac3d44..1930f5f1246 100644 --- a/src/aosm/setup.md +++ b/src/aosm/setup.md @@ -28,6 +28,9 @@ azdev setup --cli /home/developer/code/azure-cli --repo . # Add the extension to your local CLI azdev extension add aosm ``` +### Generating the AOSM Python SDK +TODO + ### VSCode environment setup. Make sure your VSCode is running in the same python virtual environment From 1c598cb6939d3838ff76d6664e5983e09d16b446 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 17:58:25 +0100 Subject: [PATCH 031/145] Basic README --- src/aosm/README.md | 57 +++++++++++++++++++++++++++++++++++++++++++++ src/aosm/README.rst | 5 ---- 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 src/aosm/README.md delete mode 100644 src/aosm/README.rst diff --git a/src/aosm/README.md b/src/aosm/README.md new file mode 100644 index 00000000000..61c796677aa --- /dev/null +++ b/src/aosm/README.md @@ -0,0 +1,57 @@ +# Microsoft Azure CLI 'aosm' Extension +========================================== + +This package is for the 'aosm' extension to support Azure Operator Service Manager +functions. +i.e. `az aosm` + +Install via `az extension add --name aosm` + + +# Background +The `az aosm` extension provides support for publishing Network Function Definitions +to use with Azure Operator Service Manager or Network Function Manager. + +# Pre-requisites +## VNFs +For VNFs, you will need a single ARM template which would create the Azure resources +for your VNF, for example a Virtual Machine, disks and NICs. You'll also need a VHD +image that would be used for the VNF Virtual Machine. + +# Command examples + +Get help on command arguments + +`az aosm -h` +`az aosm definition -h` +`az aosm definition build -h` +etc... + +All these commands take a `--definition-type` argument of `vnf`, `cnf` or (coming) `nsd` + +Create an example config file for building a definition + +`az aosm definition generate-config --config-file input.json` + +This will output a file called `input.json` which must be filled in. +Once the config file has been filled in the following commands can be run. + +Build a definition locally + +`az aosm definition build --config-file input.json` + +Build and publish a definition + +`az aosm definition build --config-file input.json --publish` + +Publish a pre-built definition + +`az aosm definition publish --config-file input.json` + +Delete a published definition + +`az aosm definition delete --config-file input.json` + +Delete a published definition and the publisher, artifact stores and NFD group + +`az aosm definition delete --config-file input.json --clean` diff --git a/src/aosm/README.rst b/src/aosm/README.rst deleted file mode 100644 index dca4757fd38..00000000000 --- a/src/aosm/README.rst +++ /dev/null @@ -1,5 +0,0 @@ -Microsoft Azure CLI 'aosm' Extension -========================================== - -This package is for the 'aosm' extension. -i.e. 'az aosm' \ No newline at end of file From 985ceb276e251533d68757d9146c0ccb9fb3079a Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 17:59:21 +0100 Subject: [PATCH 032/145] delete publisher definition --- .../templates/publisher_definition.bicep | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 src/aosm/azext_aosm/generate_nfd/templates/publisher_definition.bicep diff --git a/src/aosm/azext_aosm/generate_nfd/templates/publisher_definition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/publisher_definition.bicep deleted file mode 100644 index 62fd4aef354..00000000000 --- a/src/aosm/azext_aosm/generate_nfd/templates/publisher_definition.bicep +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Highly Confidential Material -// Bicep template to create a Publisher -param location string = resourceGroup().location -@description('Name you want to give the new Publisher object') -param publisherName string - -resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' = { - name: publisherName - scope: resourceGroup() - location: location - properties: { - scope: 'Private' - } -} From eb83c78c14242002d7f56692b9bf4881e5e06a32 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 18:00:25 +0100 Subject: [PATCH 033/145] unwanted constant --- src/aosm/azext_aosm/util/constants.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 6933f42f511..93c149185a1 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -4,8 +4,6 @@ # -------------------------------------------------------------------------------------------- """Constants used across aosm cli extension.""" -AOSM_API_VERSION = "2022-09-01-preview" - # The types of definition that can be generated VNF = "vnf" CNF = "cnf" From fe87a115af9993e06925a71ab9b9aa7297eb2af9 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Fri, 5 May 2023 18:17:27 +0100 Subject: [PATCH 034/145] d --- src/aosm/azext_aosm/delete/delete.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 40d7987f086..05a9904d7db 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -152,7 +152,7 @@ def delete_nfdg(self) -> None: network_function_definition_group_name=self.config.nfdg_name, ) poller.result() - print("Delete NFD Group") + print("Deleted NFD Group") except Exception: logger.error(f"Failed to delete NFDG.") raise From cb51f0a77705e98666ddd8d0ce44a67ecf6c7062 Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Tue, 9 May 2023 12:20:29 +0100 Subject: [PATCH 035/145] fill in init function --- src/aosm/azext_aosm/_constants.py | 1 + src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/aosm/azext_aosm/_constants.py b/src/aosm/azext_aosm/_constants.py index 8b232eff0bf..48425c52d88 100644 --- a/src/aosm/azext_aosm/_constants.py +++ b/src/aosm/azext_aosm/_constants.py @@ -14,6 +14,7 @@ # Names of files used in the repo VNF_DEFINITION_BICEP_SOURCE_TEMPLATE = "vnfdefinition.bicep" VNF_DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" +CNF_DEFINITION_BICEP_SOURCE_TEMPLATE = "cnfdefinition.bicep" # Provisioning States PROV_STATE_SUCCEEDED = "Succeeded" diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 331a29f0886..ac47f110184 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -7,8 +7,9 @@ from typing import Dict, List, Any, Tuple from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from knack.log import get_logger +from azext_aosm._configuration import CNFConfiguration from azext_aosm.vendored_sdks.models import AzureArcKubernetesHelmApplication - +from azext_aosm._constants import CNF_DEFINITION_BICEP_SOURCE_TEMPLATE logger = get_logger(__name__) @@ -20,10 +21,12 @@ class CnfNfdGenerator(NFDGenerator): :type NFDGenerator: _type_ """ - def __init__(self, config: Dict[Any, Any]): + def __init__(self, config: CNFConfiguration): super(NFDGenerator, self).__init__( config=config, ) + self.config = config + self.bicep_template_name = CNF_DEFINITION_BICEP_SOURCE_TEMPLATE def generate_nfd(self): pass From 08cbca0d566ee10d6d81450a07d08fe51af098c8 Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Wed, 10 May 2023 15:55:38 +0100 Subject: [PATCH 036/145] Add more boilerplate --- src/aosm/azext_aosm/_configuration.py | 7 + .../generate_nfd/cnf_nfd_generator.py | 164 ++++++++++++++---- .../generate_nfd/templates/cnfdefinition.json | 51 ++++++ 3 files changed, 190 insertions(+), 32 deletions(-) create mode 100644 src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.json diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index a44606bdd0f..d34d2939af0 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -111,6 +111,13 @@ def __post_init__(self): if isinstance(package, dict): package = HelmPackageConfig(**dict(package)) + @property + def build_output_folder_name(self) -> str: + """Return the local folder for generating the bicep template to.""" + return ( + f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}" + ) + def get_configuration( definition_type: str, config_as_dict: Optional[Dict[Any, Any]] = None diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index ac47f110184..6b137a3a6f5 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -3,13 +3,17 @@ # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- """Contains a class for generating VNF NFDs and associated resources.""" +import json import os -from typing import Dict, List, Any, Tuple +import shutil +import subprocess +import tarfile +from typing import Dict, List, Any, Tuple, Optional from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from knack.log import get_logger -from azext_aosm._configuration import CNFConfiguration -from azext_aosm.vendored_sdks.models import AzureArcKubernetesHelmApplication -from azext_aosm._constants import CNF_DEFINITION_BICEP_SOURCE_TEMPLATE +from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig +from azext_aosm.util.constants import CNF_DEFINITION_BICEP_SOURCE_TEMPLATE + logger = get_logger(__name__) @@ -22,41 +26,132 @@ class CnfNfdGenerator(NFDGenerator): """ def __init__(self, config: CNFConfiguration): - super(NFDGenerator, self).__init__( - config=config, - ) + super(NFDGenerator, self).__init__() self.config = config self.bicep_template_name = CNF_DEFINITION_BICEP_SOURCE_TEMPLATE + self.output_folder_name = self.config.build_output_folder_name + self.tmp_folder_name = "tmp" + + self.artifacts = [] + self.nf_applications = [] + self.deployment_parameter_schema = {} + + self._bicep_path = os.path.join( + self.output_folder_name, self.bicep_template_name + ) def generate_nfd(self): - pass + """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" + # Create tmp folder. + os.mkdir(self.tmp_folder_name) - def write(self): - pass + if self.bicep_path: + print(f"Using the existing NFD bicep template {self.bicep_path}.") + print( + f"To generate a new NFD, delete the folder {os.path.dirname(self.bicep_path)} and re-run this command." + ) + else: + for helm_package in self.config.helm_packages: + # Unpack the chart into the tmp folder + self._extract_chart(helm_package) + # Validate chart + # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) + self.deployment_parameter_schema["properties"].update(self.get_chart_mapping_schema(helm_package.name)) + # Add that schema to the big schema. + # generate the NF application for the chart + self.generate_nf_application(helm_package) + # Workout the list of artifacts for the chart + self.artifacts.append(self.get_artifact_list(helm_package.name)) + # Write NFD bicep + self.write_nfd_bicep_file() + # Write schema to schema/deploymentParameterSchema.json + # Write Artifact Mainfest bicep - def _create_nfd_folder(self): - pass + # Copy contents of tmp folder to output folder. + + # Delete tmp folder + shutil.rmtree(self.tmp_folder_name) + + @property + def bicep_path(self) -> Optional[str]: + """Returns the path to the bicep file for the NFD if it has been created.""" + if os.path.exists(self._bicep_path): + return self._bicep_path + + return None + + def _extract_chart(self, fname: str) -> None: + """ + Extract the chart into the tmp folder. + + :param helm_package: The helm package to extract. + :type helm_package: HelmPackageConfig + """ + if fname.endswith("tar.gz") or fname.endswith("tgz"): + tar = tarfile.open(fname, "r:gz") + tar.extractall(path=self.tmp_folder_name) + tar.close() + elif fname.endswith("tar"): + tar = tarfile.open(fname, "r:") + tar.extractall(path=self.tmp_folder_name) + tar.close() - def generate_nf_applications( - self, helm_packages_config: List[Any] - ) -> List[Dict[str, Any]]: - # This will mostly call the functions below. - nf_applications = [] + def _create_nfd_folder(self) -> None: + """ + Create the folder for the NFD bicep files. - for helm_package in helm_packages_config: - nf_applications.append(self.generate_nf_application(helm_package)) - return nf_applications + :raises RuntimeError: If the user aborts. + """ + if os.path.exists(self.output_folder_name): + carry_on = input( + f"The folder {self.output_folder_name} already exists - delete it and continue? (y/n)" + ) + if carry_on != "y": + raise RuntimeError("User aborted!") + + shutil.rmtree(self.output_folder_name) + + logger.info("Create NFD bicep %s", self.output_folder_name) + os.mkdir(self.output_folder_name) + + def write_nfd_bicep_file(self): + # This will write the bicep file for the NFD. + code_dir = os.path.dirname(__file__) + arm_template_path = os.path.join(code_dir, "templates/cnfdefinition.json") + + with open(arm_template_path, "r", encoding="UTF-8") as f: + cnf_arm_template_dict = json.load(f) + + cnf_arm_template_dict["resources"][0]["properties"][ + "networkFunctionTemplate" + ]["networkFunctionApplications"] = self.nf_applications + + self.write_arm_to_bicep(cnf_arm_template_dict, f"{self.tmp_folder_name}/{self.config.nf_name}-nfdv.json") + + def write_arm_to_bicep(self, arm_template_dict: Dict[Any, Any], arm_file: str): + with open(arm_file, 'w', encoding="UTF-8") as f: + print("Writing ARM template to json file.") + json.dump(arm_template_dict, f, indent=4) + try: + cmd = f"az bicep decompile --file {os.path.abspath(arm_file)} --only-show-errors" + subprocess.run(cmd, shell=True, check=True) + except subprocess.CalledProcessError as e: + raise e + finally: + os.remove(arm_file) def generate_nf_application( - self, helm_package: Dict[Any, Any] + self, helm_package: HelmPackageConfig ) -> Dict[str, Any]: - (name, version) = self.get_chart_name_and_version(helm_package) + (name, version) = self.get_chart_name_and_version(helm_package.path_to_chart) return { "artifactType": "HelmPackage", - "name": helm_package["name"], - "dependsOnProfile": helm_package["dependsOnProfile"], + "name": helm_package.name, + "dependsOnProfile": helm_package.depends_on, "artifactProfile": { - "artifactStore": {"id": "acrArtifactStore.id"}, + "artifactStore": { + "id": "[resourceId('Microsoft.HybridNetwork/publishers/artifactStores', parameters('publisherName'), parameters('acrArtifactStoreName'))]" + }, "helmArtifactProfile": { "helmPackageName": name, "helmPackageVersionRange": version, @@ -71,21 +166,26 @@ def generate_nf_application( "deployParametersMappingRuleProfile": { "applicationEnablement": "'Enabled'", "helmMappingRuleProfile": { - "releaseNamespace": "'PACKAGE_NAME'", - "releaseName": "'PACKAGE_NAME'", - "helmPackageVersion": "'PACKAGE_VERSION'", + "releaseNamespace": name, + "releaseName": name, + "helmPackageVersion": version, "values": self.generate_parmeter_mappings(), }, }, } - def generate_deployment_parameters_schema(self): - # We need to take the parameters requested by the mapping file (values.nondef.yaml) - # and generate the deployment parameters schema based on values.schema.json. + def get_artifact_list(self, helm_package: HelmPackageConfig) -> List[Any]: + pass + + def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, Any]: + # We need to take the mappings from the values.nondef.yaml file and generate the schema + # from the values.schema.json file. # Basically take the bits of the schema that are relevant to the parameters requested. pass - def get_chart_name_and_version(self, helm_package: Dict[Any, Any]) -> Tuple[str, str]: + def get_chart_name_and_version( + self, helm_package: Dict[Any, Any] + ) -> Tuple[str, str]: # We need to get the chart name and version from the Chart.yaml file. return ("chart_name", "chart_version") diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.json b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.json new file mode 100644 index 00000000000..f73a4472e73 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.json @@ -0,0 +1,51 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "publisherName": { + "type": "string", + "metadata": { + "description": "Name of an existing publisher, expected to be in the resource group where you deploy the template" + } + }, + "acrArtifactStoreName": { + "type": "string", + "metadata": { + "description": "Name of an existing ACR-backed Artifact Store, deployed under the publisher." + } + }, + "nfDefinitionGroup": { + "type": "string", + "metadata": { + "description": "Name of an existing Network Function Definition Group" + } + }, + "nfDefinitionVersion": { + "type": "string", + "metadata": { + "description": "The version of the NFDV you want to deploy, in format A-B-C" + } + } + }, + "resources": [ + { + "type": "Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups/networkfunctiondefinitionversions", + "apiVersion": "2023-04-01-preview", + "name": "[format('{0}/{1}/{2}', parameters('publisherName'), parameters('nfDefinitionGroup'), parameters('nfDefinitionVersion'))]", + "location": "[parameters('location')]", + "properties": { + "versionState": "Preview", + "deployParameters": "string(loadJsonContent('schemas/deploymentParameters.json'))", + "networkFunctionType": "ContainerizedNetworkFunction", + "networkFunctionTemplate": { + "nfviType": "AzureArcKubernetes", + "networkFunctionApplications": [] + } + } + } + ] +} \ No newline at end of file From b69aa14eedd12b8c7a1123f6cfba40aa373596fe Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 12 May 2023 10:33:37 +0100 Subject: [PATCH 037/145] initial commit; will remove input.json after testing done --- input.json | 31 +++++++++++++++ .../generate_nfd/cnf_nfd_generator.py | 38 +++++++++++++++++-- 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 input.json diff --git a/input.json b/input.json new file mode 100644 index 00000000000..26416a46b43 --- /dev/null +++ b/input.json @@ -0,0 +1,31 @@ +{ + "publisher_name": "Name of the Publisher resource you want you definition published to", + "publisher_resource_group_name": "Resource group the Publisher resource is in or you want it to be in", + "nf_name": "Name of NF definition", + "version": "Version of the NF definition", + "acr_artifact_store_name": "Name of the ACR Artifact Store resource", + "location": "Azure location of the resources", + "helm_packages": [ + { + "name": "fed-elastic-jl", + "path_to_chart": "/home/developer/smf_charts_with_nondef/fed-elastic", + "depends_on": [ + "Names of the Helm packages this package depends on" + ] + }, + { + "name": "fed-crds-jl", + "path_to_chart": "/home/developer/smf_charts_with_nondef/fed-crds", + "depends_on": [ + "THIS HAS AN INCORRECT VALUES DEF SO WE COULD TRY TO TEST OUR VALIDATION ON IT?" + ] + }, + { + "name": "fed-jl", + "path_to_chart": "/home/developer/fed-istio", + "depends_on": [ + "Names of the Helm packages this package depends on" + ] + } + ] +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 6b137a3a6f5..b712b565e62 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -9,6 +9,8 @@ import subprocess import tarfile from typing import Dict, List, Any, Tuple, Optional + +import yaml from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from knack.log import get_logger from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig @@ -53,10 +55,14 @@ def generate_nfd(self): else: for helm_package in self.config.helm_packages: # Unpack the chart into the tmp folder - self._extract_chart(helm_package) + print("HELMPACKAGE", helm_package) + # JORDAN: changes to pass in path to chart instead of whole package + self._extract_chart(helm_package['path_to_chart']) # Validate chart # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) - self.deployment_parameter_schema["properties"].update(self.get_chart_mapping_schema(helm_package.name)) + self.get_chart_mapping_schema(helm_package) + # self.deployment_parameter_schema["properties"].update(self.get_chart_mapping_schema(helm_package.name)) + print("DS", self.deployment_parameter_schema) # Add that schema to the big schema. # generate the NF application for the chart self.generate_nf_application(helm_package) @@ -87,6 +93,7 @@ def _extract_chart(self, fname: str) -> None: :param helm_package: The helm package to extract. :type helm_package: HelmPackageConfig """ + print("fname", fname) if fname.endswith("tar.gz") or fname.endswith("tgz"): tar = tarfile.open(fname, "r:gz") tar.extractall(path=self.tmp_folder_name) @@ -95,6 +102,9 @@ def _extract_chart(self, fname: str) -> None: tar = tarfile.open(fname, "r:") tar.extractall(path=self.tmp_folder_name) tar.close() + # JORDAN: avoiding tar extract errors + else: + shutil.copytree(fname, self.tmp_folder_name, dirs_exist_ok=True) def _create_nfd_folder(self) -> None: """ @@ -143,7 +153,7 @@ def write_arm_to_bicep(self, arm_template_dict: Dict[Any, Any], arm_file: str): def generate_nf_application( self, helm_package: HelmPackageConfig ) -> Dict[str, Any]: - (name, version) = self.get_chart_name_and_version(helm_package.path_to_chart) + (name, version) = self.get_chart_name_and_version(helm_package["path_to_chart"]) return { "artifactType": "HelmPackage", "name": helm_package.name, @@ -177,22 +187,42 @@ def generate_nf_application( def get_artifact_list(self, helm_package: HelmPackageConfig) -> List[Any]: pass + ## JORDAN DO THIS FIRST def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, Any]: # We need to take the mappings from the values.nondef.yaml file and generate the schema # from the values.schema.json file. # Basically take the bits of the schema that are relevant to the parameters requested. + non_def_values = helm_package['path_to_chart'] + "/values.nondef.yaml" + + with open(non_def_values) as f: + data = yaml.load(f, Loader=yaml.FullLoader) + print(data) + chart = helm_package['path_to_chart'] + '/Chart.yaml' + values = helm_package['path_to_chart'] + '/values.json' + schema = helm_package['path_to_chart'] + '/values.schema.json' + # go through schema, find the properties pass + ## Jordan DONE + ## think we need to be careful what we are naming things here, we've passed it the path to chart not the helm package def get_chart_name_and_version( self, helm_package: Dict[Any, Any] ) -> Tuple[str, str]: # We need to get the chart name and version from the Chart.yaml file. - return ("chart_name", "chart_version") + chart = helm_package + '/Chart.yaml' + + with open(chart) as f: + data = yaml.load(f, Loader=yaml.FullLoader) + chart_name = data["name"] + chart_version = data["version"] + + return (chart_name, chart_version) def some_fun_to_check_ragistry_and_image_secret_path(self): # Need to work out what we are doing here??? pass + ## JORDAN DO THIS 3rd def generate_parmeter_mappings(self) -> str: # Basically copy the values.nondef.yaml file to the right place. pass From 057ef05aa3f10ed3e39103f78caa6aff12bc48e4 Mon Sep 17 00:00:00 2001 From: sunnycarter <36891339+sunnycarter@users.noreply.github.com> Date: Fri, 12 May 2023 14:36:35 +0100 Subject: [PATCH 038/145] Sunny/bicep deployer (#3) * Draft create NFDV using python SDK * pushing this but then moving on to delete * start to move to bicep deployer * VNF generate and deploy bare bones, not working * predeployer maybe working * Fix up VNF generate and deploy * printing * artifact upload half broken * Artifact manifest stuff over to SDK * delete NFD function * linting * Fix up json config -> VNFConfiguration * artifact manifests separate * style * renames * style * lint and reverse some renames * dev instructions * oops. bad find and replace work. * undo friday afternoon bad changes * manifest optional * Basic README * delete publisher definition * unwanted constant * d * Update src/aosm/setup.py Suggestion from cyclam Co-authored-by: Cyclam <95434717+Cyclam@users.noreply.github.com> * markups * lint --------- Co-authored-by: Cyclam <95434717+Cyclam@users.noreply.github.com> --- src/aosm/README.md | 57 +++ src/aosm/README.rst | 5 - src/aosm/azext_aosm/__init__.py | 8 +- src/aosm/azext_aosm/_client_factory.py | 4 +- src/aosm/azext_aosm/_configuration.py | 154 ++++++- src/aosm/azext_aosm/_deployer.py | 316 --------------- src/aosm/azext_aosm/_help.py | 33 +- src/aosm/azext_aosm/_params.py | 68 +++- src/aosm/azext_aosm/_validators.py | 7 +- src/aosm/azext_aosm/commands.py | 20 +- src/aosm/azext_aosm/custom.py | 233 +++++++---- src/aosm/azext_aosm/delete/delete.py | 205 ++++++++++ src/aosm/azext_aosm/deploy/artifact.py | 87 ++++ .../azext_aosm/deploy/artifact_manifest.py | 156 +++++++ src/aosm/azext_aosm/deploy/deploy_with_arm.py | 379 ++++++++++++++++++ src/aosm/azext_aosm/deploy/pre_deploy.py | 369 +++++++++++++++++ .../generate_nfd/cnf_nfd_generator.py | 12 +- .../generate_nfd/nfd_generator_base.py | 22 +- .../templates/vnfartifactmanifests.bicep | 70 ++++ .../templates/vnfdefinition.bicep | 103 +++++ .../generate_nfd/vnf_bicep_nfd_generator.py | 207 ++++++++++ .../generate_nfd/vnf_nfd_generator.py | 47 --- src/aosm/azext_aosm/tests/__init__.py | 2 +- src/aosm/azext_aosm/tests/latest/__init__.py | 2 +- .../tests/latest/test_aosm_scenario.py | 48 +-- .../{_constants.py => util/constants.py} | 7 +- .../azext_aosm/util/management_clients.py | 24 ++ src/aosm/azext_aosm/util/utils.py | 17 + src/aosm/setup.md | 51 +++ src/aosm/setup.py | 44 +- 30 files changed, 2181 insertions(+), 576 deletions(-) create mode 100644 src/aosm/README.md delete mode 100644 src/aosm/README.rst delete mode 100644 src/aosm/azext_aosm/_deployer.py create mode 100644 src/aosm/azext_aosm/delete/delete.py create mode 100644 src/aosm/azext_aosm/deploy/artifact.py create mode 100644 src/aosm/azext_aosm/deploy/artifact_manifest.py create mode 100644 src/aosm/azext_aosm/deploy/deploy_with_arm.py create mode 100644 src/aosm/azext_aosm/deploy/pre_deploy.py create mode 100644 src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep create mode 100644 src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep create mode 100644 src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py delete mode 100644 src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py rename src/aosm/azext_aosm/{_constants.py => util/constants.py} (69%) create mode 100644 src/aosm/azext_aosm/util/management_clients.py create mode 100644 src/aosm/azext_aosm/util/utils.py create mode 100644 src/aosm/setup.md diff --git a/src/aosm/README.md b/src/aosm/README.md new file mode 100644 index 00000000000..61c796677aa --- /dev/null +++ b/src/aosm/README.md @@ -0,0 +1,57 @@ +# Microsoft Azure CLI 'aosm' Extension +========================================== + +This package is for the 'aosm' extension to support Azure Operator Service Manager +functions. +i.e. `az aosm` + +Install via `az extension add --name aosm` + + +# Background +The `az aosm` extension provides support for publishing Network Function Definitions +to use with Azure Operator Service Manager or Network Function Manager. + +# Pre-requisites +## VNFs +For VNFs, you will need a single ARM template which would create the Azure resources +for your VNF, for example a Virtual Machine, disks and NICs. You'll also need a VHD +image that would be used for the VNF Virtual Machine. + +# Command examples + +Get help on command arguments + +`az aosm -h` +`az aosm definition -h` +`az aosm definition build -h` +etc... + +All these commands take a `--definition-type` argument of `vnf`, `cnf` or (coming) `nsd` + +Create an example config file for building a definition + +`az aosm definition generate-config --config-file input.json` + +This will output a file called `input.json` which must be filled in. +Once the config file has been filled in the following commands can be run. + +Build a definition locally + +`az aosm definition build --config-file input.json` + +Build and publish a definition + +`az aosm definition build --config-file input.json --publish` + +Publish a pre-built definition + +`az aosm definition publish --config-file input.json` + +Delete a published definition + +`az aosm definition delete --config-file input.json` + +Delete a published definition and the publisher, artifact stores and NFD group + +`az aosm definition delete --config-file input.json --clean` diff --git a/src/aosm/README.rst b/src/aosm/README.rst deleted file mode 100644 index dca4757fd38..00000000000 --- a/src/aosm/README.rst +++ /dev/null @@ -1,5 +0,0 @@ -Microsoft Azure CLI 'aosm' Extension -========================================== - -This package is for the 'aosm' extension. -i.e. 'az aosm' \ No newline at end of file diff --git a/src/aosm/azext_aosm/__init__.py b/src/aosm/azext_aosm/__init__.py index a360b6ceca5..c15badcb435 100644 --- a/src/aosm/azext_aosm/__init__.py +++ b/src/aosm/azext_aosm/__init__.py @@ -9,19 +9,21 @@ class AosmCommandsLoader(AzCommandsLoader): - def __init__(self, cli_ctx=None): from azure.cli.core.commands import CliCommandType - aosm_custom = CliCommandType(operations_tmpl='azext_aosm.custom#{}') - super(AosmCommandsLoader, self).__init__(cli_ctx=cli_ctx, custom_command_type=aosm_custom) + + aosm_custom = CliCommandType(operations_tmpl="azext_aosm.custom#{}") + super().__init__(cli_ctx=cli_ctx, custom_command_type=aosm_custom) def load_command_table(self, args): from azext_aosm.commands import load_command_table + load_command_table(self, args) return self.command_table def load_arguments(self, command): from azext_aosm._params import load_arguments + load_arguments(self, command) diff --git a/src/aosm/azext_aosm/_client_factory.py b/src/aosm/azext_aosm/_client_factory.py index 084e448b769..e55e6142d25 100644 --- a/src/aosm/azext_aosm/_client_factory.py +++ b/src/aosm/azext_aosm/_client_factory.py @@ -7,10 +7,12 @@ from azure.cli.core.profiles import ResourceType from .vendored_sdks import HybridNetworkManagementClient + def cf_aosm(cli_ctx, *_) -> HybridNetworkManagementClient: return get_mgmt_service_client(cli_ctx, HybridNetworkManagementClient) + def cf_resources(cli_ctx, subscription_id=None): return get_mgmt_service_client( cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id - ).resources + ) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 797e484c9c0..50eb5d274dd 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,42 +1,156 @@ from dataclasses import dataclass -from typing import Optional -from knack.util import CLIError -from ._constants import VNF, CNF, NSD +from typing import Dict, Optional, Any +from pathlib import Path +from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError +from azext_aosm.util.constants import VNF_DEFINITION_OUTPUT_BICEP_PREFIX, VNF, CNF, NSD + +DESCRIPTION_MAP: Dict[str, str] = { + "publisher_resource_group_name": ( + "Resource group for the Publisher resource. Will be " + "created if it does not exist." + ), + "publisher_name": ("Name of the Publisher resource you want your definition " + "published to. Will be created if it does not exist." + ), + "nf_name": "Name of NF definition", + "version": "Version of the NF definition", + "acr_artifact_store_name": "Name of the ACR Artifact Store resource", + "location": "Azure location to use when creating resources", + "blob_artifact_store_name": "Name of the storage account Artifact Store resource", + "artifact_name": "Name of the artifact", + "file_path": ( + "Optional. File path of the artifact you wish to upload from your " + "local disk. Delete if not required." + ), + "blob_sas_url": ( + "Optional. SAS URL of the blob artifact you wish to copy to your " + "Artifact Store. Delete if not required." + ), + "artifact_version": ( + "Version of the artifact. For VHDs this must be in format A-B-C. " + "For ARM templates this must be in format A.B.C" + ), +} + @dataclass class ArtifactConfig: - artifact_name: str = "Name of the artifact" - file_path: Optional[str] = "File path of the artifact you wish to upload from your local disk" - blob_sas_url: Optional[str] = "SAS URL of the blob artifact you wish to copy to your Artifact Store" + artifact_name: str = DESCRIPTION_MAP["artifact_name"] + # artifact.py checks for the presence of the default descriptions, change there if + # you change the descriptions. + file_path: Optional[str] = DESCRIPTION_MAP["file_path"] + blob_sas_url: Optional[str] = DESCRIPTION_MAP["blob_sas_url"] + version: str = DESCRIPTION_MAP["artifact_version"] @dataclass -class Configuration(): - publisher_name: str = "Name of the Publisher resource you want you definition published to" - publisher_resource_group_name: str = "Resource group the Publisher resource is in or you want it to be in" - name: str = "Name of NF definition" - version: str = "Version of the NF definition" - acr_artifact_store_name: str = "Name of the ACR Artifact Store resource" +class NFConfiguration: + publisher_name: str = DESCRIPTION_MAP["publisher_name"] + publisher_resource_group_name: str = DESCRIPTION_MAP[ + "publisher_resource_group_name" + ] + nf_name: str = DESCRIPTION_MAP["nf_name"] + version: str = DESCRIPTION_MAP["version"] + acr_artifact_store_name: str = DESCRIPTION_MAP["acr_artifact_store_name"] + location: str = DESCRIPTION_MAP["location"] + + @property + def nfdg_name(self) -> str: + """Return the NFD Group name from the NFD name.""" + return f"{self.nf_name}-nfdg" + + @property + def acr_manifest_name(self) -> str: + """Return the ACR manifest name from the NFD name.""" + return f"{self.nf_name}-acr-manifest-{self.version.replace('.', '-')}" @dataclass -class VNFConfiguration(Configuration): - blob_artifact_store_name: str = "Name of the storage account Artifact Store resource" - arm_template: ArtifactConfig = ArtifactConfig() - vhd: ArtifactConfig = ArtifactConfig() +class VNFConfiguration(NFConfiguration): + blob_artifact_store_name: str = DESCRIPTION_MAP["blob_artifact_store_name"] + arm_template: Any = ArtifactConfig() + vhd: Any = ArtifactConfig() + + def __post_init__(self): + """ + Cope with deserializing subclasses from dicts to ArtifactConfig. + + Used when creating VNFConfiguration object from a loaded json config file. + """ + if isinstance(self.arm_template, dict): + self.arm_template = ArtifactConfig(**self.arm_template) + + if isinstance(self.vhd, dict): + self.vhd = ArtifactConfig(**self.vhd) + self.validate() + + def validate(self) -> None: + """ + Validate the configuration passed in. + + :raises ValidationError for any invalid config + """ + if self.vhd.version == DESCRIPTION_MAP["version"]: + # Config has not been filled in. Don't validate. + return + + if "." in self.vhd.version or "-" not in self.vhd.version: + raise ValidationError( + "Config validation error. VHD artifact version should be in format A-B-C" + ) + if "." not in self.arm_template.version or "-" in self.arm_template.version: + raise ValidationError( + "Config validation error. ARM template artifact version should be in format A.B.C" + ) + filepath_set = ( + self.vhd.file_path and self.vhd.file_path != DESCRIPTION_MAP["file_path"] + ) + sas_set = ( + self.vhd.blob_sas_url + and self.vhd.blob_sas_url != DESCRIPTION_MAP["blob_sas_url"] + ) + # If these are the same, either neither is set or both are, both of which are errors + if filepath_set == sas_set: + raise ValidationError( + "Config validation error. VHD config must have either a local filepath or a blob SAS URL" + ) + + if filepath_set: + # Explicitly set the blob SAS URL to None to avoid other code having to + # check if the value is the default description + self.vhd.blob_sas_url = None + elif sas_set: + self.vhd.file_path = None + + @property + def sa_manifest_name(self) -> str: + """Return the Storage account manifest name from the NFD name.""" + return f"{self.nf_name}-sa-manifest-{self.version.replace('.', '-')}" + + @property + def build_output_folder_name(self) -> str: + """Return the local folder for generating the bicep template to.""" + arm_template_path = self.arm_template.file_path + return ( + f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" + ) -def get_configuration(definition_type, config_as_dict=None): +def get_configuration( + definition_type: str, config_as_dict: Optional[Dict[Any, Any]] = None +) -> NFConfiguration: if config_as_dict is None: config_as_dict = {} if definition_type == VNF: config = VNFConfiguration(**config_as_dict) elif definition_type == CNF: - config = Configuration(**config_as_dict) + config = NFConfiguration(**config_as_dict) elif definition_type == NSD: - config = Configuration(**config_as_dict) + config = NFConfiguration(**config_as_dict) else: - raise CLIError("Definition type not recognized, options are: vnf, cnf or nsd") + raise InvalidArgumentValueError( + "Definition type not recognized, options are: vnf, cnf or nsd" + ) return config diff --git a/src/aosm/azext_aosm/_deployer.py b/src/aosm/azext_aosm/_deployer.py deleted file mode 100644 index 6ba51f81549..00000000000 --- a/src/aosm/azext_aosm/_deployer.py +++ /dev/null @@ -1,316 +0,0 @@ -# -------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT -# License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------- -"""Contains class for deploying generated definitions.""" - -from knack.log import get_logger -from azure.mgmt.resource import ResourceManagementClient -from .vendored_sdks import HybridNetworkManagementClient -from .vendored_sdks.models import ( - ArtifactStore, - ArtifactStoreType, - ArtifactType, - ArtifactManifest, - NetworkFunctionDefinitionGroup, - NetworkFunctionDefinitionVersion, - NetworkServiceDesignGroup, - NetworkServiceDesignVersion, - Publisher, -) - -logger = get_logger(__name__) - - -class Deployer: - """A class for publishing definitions.""" - - def __init__( - self, - aosm_client: HybridNetworkManagementClient, - resource_client: ResourceManagementClient, - ) -> None: - """ - Initializes a new instance of the Deployer class. - - :param aosm_client: The client to use for managing AOSM resources. - :type aosm_client: HybridNetworkManagementClient - :param resource_client: The client to use for managing Azure resources. - :type resource_client: ResourceManagementClient - """ - - self.aosm_client = aosm_client - self.resource_client = resource_client - - def _ensure_publisher_exists( - self, resource_group_name: str, publisher_name: str, location: str - ) -> None: - """ - Ensures that the publisher exists in the resource group. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param location: The location of the publisher. - :type location: str - """ - - logger.info( - "Creating publisher %s if it does not exist", publisher_name - ) - if not self.resource_client.resources.check_existance( - resource_group_name=resource_group_name, - resource_type="Microsoft.HybridNetwork/publishers", - resource_name=publisher_name, - ): - self.aosm_client.publishers.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - parameters=Publisher(location=location, scope="Public"), - ) - - def _ensure_artifact_store_exists( - self, - resource_group_name: str, - publisher_name: str, - artifact_store_name: str, - artifact_store_type: ArtifactStoreType, - location: str, - ) -> None: - """ - Ensures that the artifact store exists in the resource group. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param artifact_store_name: The name of the artifact store. - :type artifact_store_name: str - :param artifact_store_type: The type of the artifact store. - :type artifact_store_type: ArtifactStoreType - :param location: The location of the artifact store. - :type location: str - """ - - logger.info( - "Creating artifact store %s if it does not exist", - artifact_store_name, - ) - self.aosm_client.artifact_stores.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - artifact_store_name=artifact_store_name, - parameters=ArtifactStore( - location=location, - artifact_store_type=artifact_store_type, - ), - ) - - def _ensure_nfdg_exists( - self, - resource_group_name: str, - publisher_name: str, - nfdg_name: str, - location: str, - ): - """ - Ensures that the network function definition group exists in the resource group. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param nfdg_name: The name of the network function definition group. - :type nfdg_name: str - :param location: The location of the network function definition group. - :type location: str - """ - - logger.info( - "Creating network function definition group %s if it does not exist", - nfdg_name, - ) - self.aosm_client.network_function_definition_groups.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - network_function_definition_group_name=nfdg_name, - parameters=NetworkFunctionDefinitionGroup(location=location), - ) - - def _ensure_nsdg_exists( - self, - resource_group_name: str, - publisher_name: str, - nsdg_name: str, - location: str, - ): - """ - Ensures that the network service design group exists in the resource group. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param nsdg_name: The name of the network service design group. - :type nsdg_name: str - :param location: The location of the network service design group. - :type location: str - """ - - logger.info( - "Creating network service design group %s if it does not exist", - nsdg_name, - ) - self.aosm_client.network_service_design_groups.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - network_service_design_group_name=nsdg_name, - parameters=NetworkServiceDesignGroup(location=location), - ) - - def publish_artifact_manifest( - self, - resource_group_name: str, - location: str, - publisher_name: str, - artifact_store_name: str, - artifact_manifest: ArtifactManifest, - ) -> None: - """ - Publishes an artifact manifest. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param location: The location of the artifact manifest. - :type location: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param artifact_store_name: The name of the artifact store. - :type artifact_store_name: str - :param artifact_manifest: The artifact manifest. - :type artifact_manifest: ArtifactManifest - """ - - self._ensure_publisher_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - location=location, - ) - - artifact_types = [a.artifact_type for a in artifact_manifest.artifacts] - - if ( - ArtifactType.VHD_IMAGE_FILE - or ArtifactType.IMAGE_FILE in artifact_types - ): - artifact_store_type = ArtifactStoreType.AZURE_STORAGE_ACCOUNT - else: - artifact_store_type = ArtifactStoreType.AZURE_CONTAINER_REGISTRY - - self._ensure_artifact_store_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - artifact_store_name=artifact_store_name, - artifact_store_type=artifact_store_type, - location=location, - ) - - logger.info("Creating artifact manifest %s", artifact_manifest.name) - self.aosm_client.artifact_manifests.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - artifact_store_name=artifact_store_name, - artifact_manifest_name=artifact_manifest.name, - parameters=artifact_manifest, - ) - - def publish_network_function_definition_version( - self, - resource_group_name: str, - publisher_name: str, - location: str, - network_function_definition_group_name: str, - network_function_definition_version: NetworkFunctionDefinitionVersion, - ) -> None: - """ - Publishes a network function definition version. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param location: The location of the network function definition version. - :type location: str - :param network_function_definition_group_name: The name of the network function definition group. - :type network_function_definition_group_name: str - :param network_function_definition_version: The network function definition version. - :type network_function_definition_version: NetworkFunctionDefinitionVersion - """ - - self._ensure_publisher_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - location=location, - ) - - self._ensure_nfdg_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - nfdg_name=network_function_definition_group_name, - location=location, - ) - - logger.info("Publishing network function definition version") - self.aosm_client.network_function_definition_versions.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - network_function_definition_group_name=network_function_definition_group_name, - network_function_definition_version_name=network_function_definition_version.name, - parameters=network_function_definition_version, - ) - - def publish_network_service_design_version( - self, - resource_group_name: str, - publisher_name: str, - location: str, - network_service_design_group_name: str, - network_service_design_version: NetworkServiceDesignVersion, - ) -> None: - """ - Publishes a network service design version. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param location: The location of the network service design version. - :type location: str - :param network_service_design_group_name: The name of the network service design group. - :type network_service_design_group_name: str - :param network_service_design_version: The network service design version. - :type network_service_design_version: NetworkServiceDesignVersion - """ - - self._ensure_publisher_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - location=location, - ) - - self._ensure_nsdg_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - nsdg_name=network_service_design_group_name, - location=location, - ) - - logger.info("Publishing network service design version") - self.aosm_client.network_service_design_versions.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - network_service_design_group_name=network_service_design_group_name, - network_service_design_version_name=network_service_design_version.name, - parameters=network_service_design_version, - ) diff --git a/src/aosm/azext_aosm/_help.py b/src/aosm/azext_aosm/_help.py index 1fb3bb11b3f..2a9a3013fd9 100644 --- a/src/aosm/azext_aosm/_help.py +++ b/src/aosm/azext_aosm/_help.py @@ -7,22 +7,45 @@ from knack.help_files import helps # pylint: disable=unused-import -helps['aosm'] = """ +helps[ + "aosm" +] = """ type: group short-summary: Commands to interact with Azure Operator Service Manager (AOSM). """ -helps['aosm definition'] = """ +helps[ + "aosm definition" +] = """ type: group short-summary: Manage AOSM publisher definitions. """ -helps['aosm definition build'] = """ +helps[ + "aosm definition generate-config" +] = """ + type: command + short-summary: Generate configuration file for building an AOSM publisher definition. +""" + +helps[ + "aosm definition build" +] = """ type: command short-summary: Build an AOSM publisher definition. """ -helps['aosm definition generate-config'] = """ +helps[ + "aosm definition publish" +] = """ type: command - short-summary: Generate configuration file for building an AOSM publisher definition. + short-summary: Publish a pre-built AOSM publisher definition. +""" + + +helps[ + "aosm definition delete" +] = """ + type: command + short-summary: Delete AOSM publisher definition. """ diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index 4bf374f9e95..1b9bcf60651 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -6,32 +6,74 @@ from argcomplete.completers import FilesCompleter from azure.cli.core import AzCommandsLoader -from knack.arguments import CLIArgumentType -from ._constants import VNF, CNF, NSD +from .util.constants import VNF, CNF, NSD -def load_arguments(self: AzCommandsLoader, _): - from azure.cli.core.commands.parameters import file_type, get_enum_type, get_three_state_flag +def load_arguments(self: AzCommandsLoader, _): + from azure.cli.core.commands.parameters import ( + file_type, + get_enum_type, + get_three_state_flag, + ) definition_type = get_enum_type([VNF, CNF, NSD]) # Set the argument context so these options are only available when this specific command # is called. - with self.argument_context('aosm definition') as c: + with self.argument_context("aosm definition") as c: c.argument( - 'definition_type', - arg_type=definition_type, - help='Type of AOSM definition to generate.' + "definition_type", arg_type=definition_type, help="Type of AOSM definition." ) c.argument( - 'config_file', + "config_file", options_list=["--config-file", "-f"], type=file_type, completer=FilesCompleter(allowednames="*.json"), - help='The path to the configuration file.' + help="The path to the configuration file.", + ) + c.argument( + "publish", + arg_type=get_three_state_flag(), + help="Publishes generated AOSM definition.", + ) + c.argument( + "clean", + arg_type=get_three_state_flag(), + help="Also delete artifact stores, NFD Group and Publisher. Use with care.", + ) + c.argument( + "definition_file", + options_list=["--definition-file", "-b"], + type=file_type, + completer=FilesCompleter(allowednames="*.json"), + help="Optional path to a bicep file to publish. Use to override publish of the built definition with an alternative file.", + ) + c.argument( + "parameters_json_file", + options_list=["--parameters-file", "-p"], + type=file_type, + completer=FilesCompleter(allowednames="*.json"), + help="Optional path to a parameters file for the bicep definition file. Use to override publish of the built definition and config with alternative parameters.", + ) + c.argument( + "manifest_file", + options_list=["--manifest-file", "-m"], + type=file_type, + completer=FilesCompleter(allowednames="*.json"), + help="Optional path to a bicep file to publish manifests. Use to override publish of the built definition with an alternative file.", + ) + c.argument( + "manifest_parameters_json_file", + options_list=["--manifest-parameters-file", "-mp"], + type=file_type, + completer=FilesCompleter(allowednames="*.json"), + help="Optional path to a parameters file for the manifest definition file. Use to override publish of the built definition and config with alternative parameters.", ) - c.argument('publish', arg_type=get_three_state_flag(), help='Publishes generated AOSM definition.') - with self.argument_context('aosm generate-config') as c: - c.argument('definition_type', arg_type=definition_type, help='Type of AOSM definition config to generate.') + with self.argument_context("aosm generate-config") as c: + c.argument( + "definition_type", + arg_type=definition_type, + help="Type of AOSM definition config to generate.", + ) diff --git a/src/aosm/azext_aosm/_validators.py b/src/aosm/azext_aosm/_validators.py index bdbc5023a4d..1a9f0e39617 100644 --- a/src/aosm/azext_aosm/_validators.py +++ b/src/aosm/azext_aosm/_validators.py @@ -10,12 +10,13 @@ def example_name_or_id_validator(cmd, namespace): # https://github.com/Azure/azure-cli/blob/dev/doc/authoring_command_modules/authoring_commands.md#supporting-name-or-id-parameters from azure.cli.core.commands.client_factory import get_subscription_id from msrestazure.tools import is_valid_resource_id, resource_id + if namespace.storage_account: if not is_valid_resource_id(namespace.RESOURCE): namespace.storage_account = resource_id( subscription=get_subscription_id(cmd.cli_ctx), resource_group=namespace.resource_group_name, - namespace='Microsoft.Storage', - type='storageAccounts', - name=namespace.storage_account + namespace="Microsoft.Storage", + type="storageAccounts", + name=namespace.storage_account, ) diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index ffa2263d0e4..a25fcf9d2c4 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -5,22 +5,18 @@ # pylint: disable=line-too-long from azure.cli.core import AzCommandsLoader -from azure.cli.core.commands import CliCommandType + from azext_aosm._client_factory import cf_aosm def load_command_table(self: AzCommandsLoader, _): - - # TODO: Add command type here - # aosm_sdk = CliCommandType( - # operations_tmpl='.operations#None.{}', - # client_factory=cf_aosm) - - with self.command_group('aosm definition', client_factory=cf_aosm) as g: + with self.command_group("aosm definition", client_factory=cf_aosm) as g: # Add each command and bind it to a function in custom.py - g.custom_command('build', 'build_definition') - g.custom_command('generate-config', 'generate_definition_config') - g.custom_command('show', 'show_publisher') + g.custom_command("generate-config", "generate_definition_config") + g.custom_command("build", "build_definition") + g.custom_command("delete", "delete_published_definition") + g.custom_command("show", "show_publisher") + g.custom_command("publish", "publish_definition") - with self.command_group('aosm', is_preview=True): + with self.command_group("aosm", is_preview=True): pass diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 82a53ce2f4a..8a3f22198db 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -5,118 +5,185 @@ import json from dataclasses import asdict -from typing import Optional, Tuple +from typing import Optional +from knack.log import get_logger + from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator -from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator -from knack.log import get_logger -from azure.cli.core.azclierror import AzCLIError -from azure.mgmt.resource import ResourceManagementClient -from .vendored_sdks import HybridNetworkManagementClient -from .vendored_sdks.models import Publisher, NetworkFunctionDefinitionVersion -from ._client_factory import cf_resources -from ._configuration import Configuration, VNFConfiguration, get_configuration -from ._constants import VNF, CNF, NSD +from azext_aosm.generate_nfd.vnf_bicep_nfd_generator import VnfBicepNfdGenerator +from azext_aosm.delete.delete import ResourceDeleter +from azext_aosm.deploy.deploy_with_arm import DeployerViaArm +from azext_aosm.util.constants import VNF, CNF # , NSD +from azext_aosm.util.management_clients import ApiClients +from azext_aosm.vendored_sdks import HybridNetworkManagementClient +from azext_aosm._client_factory import cf_resources +from azext_aosm._configuration import ( + get_configuration, + NFConfiguration, +) logger = get_logger(__name__) -PUBLISHER_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers" -ARTIFACT_STORE_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/artifactstores" -NFDG_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/networkfunctiondefinitiongroups" -NSDG_RESOURCE_TYPE = "Microsoft.HybridNetwork/publishers/networkservicedesigngroups" - -def _required_resources_exist( - cli_ctx, definition_type: str, config: Configuration -) -> bool: - resource_client = cf_resources(cli_ctx) - - if resource_client.check_existence( - config.publisher_resource_group_name, - PUBLISHER_RESOURCE_TYPE, - config.publisher_name, - ): - if not resource_client.check_existence( - config.publisher_resource_group_name, - "Microsoft.HybridNetwork/publishers/artifactstores", - config.acr_artifact_store_name, - ): - return False - if definition_type == VNF: - if not resource_client.check_existence( - config.publisher_resource_group_name, - NFDG_RESOURCE_TYPE, - config.name, - ): - return False - elif definition_type == NSD: - if not resource_client.check_existence( - config.publisher_resource_group_name, - NSDG_RESOURCE_TYPE, - config.name, - ): - return False - elif definition_type == CNF: - if not resource_client.check_existence( - config.publisher_resource_group_name, - NFDG_RESOURCE_TYPE, - config.name, - ): - return False - else: - raise AzCLIError( - "Invalid definition type. Valid values are vnf, nsd and cnf." - ) - else: - return False - -def _create_required_resources(definition_type, config): - pass def build_definition( cmd, client: HybridNetworkManagementClient, - definition_type, - config_file, + definition_type: str, + config_file: str, publish=False, ): - with open(config_file, "r", encoding="utf-8") as f: - config_as_dict = json.loads(f) + """ + Build and optionally publish a definition. + + :param cmd: + :type cmd: _type_ + :param client: + :type client: HybridNetworkManagementClient + :param config_file: path to the file + :param definition_type: VNF, CNF or NSD + :param publish: _description_, defaults to False + :type publish: bool, optional + """ + api_clients = ApiClients( + aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) + ) - config = get_configuration(definition_type, config_as_dict) + # Read the config from the given file + config = _get_config_from_file(config_file, definition_type) # Generate the NFD/NSD and the artifact manifest. - - - # Write the ARM/bicep template if that's what we are doing + _generate_nfd(definition_type=definition_type, config=config) # Publish the definition if publish is true if publish: - if not _required_resources_exist(cmd.cli_ctx, definition_type, config): - _create_required_resources(definition_type, config) + if definition_type == VNF: + deployer = DeployerViaArm(api_clients, config=config) + deployer.deploy_vnfd_from_bicep() + else: + print("TODO - cannot publish CNF or NSD yet.") -def generate_definition_config(cmd, definition_type, output_file="input.json"): +def generate_definition_config(definition_type: str, output_file: str = "input.json"): + """ + Generate an example config file for building a definition. + + :param definition_type: CNF, VNF or NSD + :param output_file: path to output config file, defaults to "input.json" + :type output_file: str, optional + """ config = get_configuration(definition_type) config_as_dict = json.dumps(asdict(config), indent=4) with open(output_file, "w", encoding="utf-8") as f: f.write(config_as_dict) - logger.info( - "Empty definition configuration has been written to %s", - output_file, - ) - -def _generate_nfd(definition_type, config): - """_summary_ + print(f"Empty definition configuration has been written to {output_file}") + logger.info(f"Empty definition configuration has been written to {output_file}") + - :param definition_type: _description_ - :type definition_type: _type_ +def _get_config_from_file(config_file: str, definition_type: str) -> NFConfiguration: """ + Read input config file JSON and turn it into a Configuration object. + + :param config_file: path to the file + :param definition_type: VNF, CNF or NSD + :rtype: Configuration + """ + with open(config_file, "r", encoding="utf-8") as f: + config_as_dict = json.loads(f.read()) + + config = get_configuration(definition_type, config_as_dict) + return config + + +def _generate_nfd(definition_type, config): + """Generate a Network Function Definition for the given type and config.""" nfd_generator: NFDGenerator if definition_type == VNF: - nfd_generator = VnfNfdGenerator(config) + nfd_generator = VnfBicepNfdGenerator(config) elif definition_type == CNF: nfd_generator = CnfNfdGenerator(config) - + else: + from azure.cli.core.azclierror import CLIInternalError + + raise CLIInternalError( + "Generate NFD called for unrecognised definition_type. Only VNF and CNF have been implemented." + ) + nfd_generator.generate_nfd() + + +def publish_definition( + cmd, + client: HybridNetworkManagementClient, + definition_type, + config_file, + definition_file: Optional[str] = None, + parameters_json_file: Optional[str] = None, + manifest_file: Optional[str] = None, + manifest_parameters_json_file: Optional[str] = None, +): + """ + Publish a generated definition. + + :param cmd: + :param client: + :type client: HybridNetworkManagementClient + :param definition_type: VNF or CNF + :param config_file: Path to the config file for the NFDV + :param definition_file: Optional path to a bicep template to deploy, in case the user + wants to edit the built NFDV template. If omitted, the default + built NFDV template will be used. + :param parameters_json_file: Optional path to a parameters file for the bicep file, + in case the user wants to edit the built NFDV template. If + omitted, parameters from config will be turned into parameters + for the bicep file + :param manifest_file: Optional path to an override bicep template to deploy + manifests + :param manifest_parameters_json_file: Optional path to an override bicep parameters + file for manifest parameters + """ + print("Publishing definition.") + api_clients = ApiClients( + aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) + ) + config = _get_config_from_file(config_file, definition_type) + if definition_type == VNF: + deployer = DeployerViaArm(api_clients, config=config) + deployer.deploy_vnfd_from_bicep( + bicep_path=definition_file, + parameters_json_file=parameters_json_file, + manifest_bicep_path=manifest_file, + manifest_parameters_json_file=manifest_parameters_json_file, + ) + + +def delete_published_definition( + cmd, + client: HybridNetworkManagementClient, + definition_type, + config_file, + clean=False, +): + """ + Delete a published definition. + + :param definition_type: CNF or VNF + :param config_file: Path to the config file + :param clean: if True, will delete the NFDG, artifact stores and publisher too. + Defaults to False. Only works if no resources have those as a parent. + Use with care. + """ + config = _get_config_from_file(config_file, definition_type) + + api_clients = ApiClients( + aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) + ) + + delly = ResourceDeleter(api_clients, config) + if definition_type == VNF: + delly.delete_vnf(clean=clean) + + +def show_publisher(): + pass diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py new file mode 100644 index 00000000000..5e0de9be3d9 --- /dev/null +++ b/src/aosm/azext_aosm/delete/delete.py @@ -0,0 +1,205 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains class for deploying generated definitions using the Python SDK.""" +from knack.log import get_logger + +from azext_aosm.util.management_clients import ApiClients +from azext_aosm._configuration import NFConfiguration, VNFConfiguration +from azext_aosm.util.utils import input_ack + + +logger = get_logger(__name__) + + +class ResourceDeleter: + def __init__( + self, + api_clients: ApiClients, + config: NFConfiguration, + ) -> None: + """ + Initializes a new instance of the Deployer class. + + :param aosm_client: The client to use for managing AOSM resources. + :type aosm_client: HybridNetworkManagementClient + :param resource_client: The client to use for managing Azure resources. + :type resource_client: ResourceManagementClient + """ + logger.debug("Create ARM/Bicep Deployer") + self.api_clients = api_clients + self.config = config + + def delete_vnf(self, clean: bool = False): + """ + Delete the NFDV and manifests. If they don't exist it still reports them as + deleted. + + :param clean: Delete the NFDG, artifact stores and publisher too. + defaults to False + Use with care. + """ + assert isinstance(self.config, VNFConfiguration) + if clean: + print( + f"Are you sure you want to delete all resources associated with NFD {self.config.nf_name} including the artifact stores and publisher {self.config.publisher_name}?" + ) + logger.warning( + "This command will fail if other NFD versions exist in the NFD group." + ) + logger.warning( + "Only do this if you are SURE you are not sharing the publisher and artifact stores with other NFDs" + ) + print("There is no undo. Type the publisher name to confirm.") + if not input_ack(self.config.publisher_name.lower(), "Confirm delete:"): + print("Not proceeding with delete") + return + else: + print( + f"Are you sure you want to delete the NFD Version {self.config.version} and associated manifests from group {self.config.nfdg_name} and publisher {self.config.publisher_name}?" + ) + print("There is no undo. Type 'delete' to confirm") + if not input_ack("delete", "Confirm delete:"): + print("Not proceeding with delete") + return + + self.delete_nfdv() + self.delete_artifact_manifest("sa") + self.delete_artifact_manifest("acr") + + if clean: + logger.info("Delete called for all resources.") + self.delete_nfdg() + self.delete_artifact_store("acr") + self.delete_artifact_store("sa") + self.delete_publisher() + + def delete_nfdv(self): + message = f"Delete NFDV {self.config.version} from group {self.config.nfdg_name} and publisher {self.config.publisher_name}" + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.network_function_definition_versions.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + network_function_definition_group_name=self.config.nfdg_name, + network_function_definition_version_name=self.config.version, + ) + poller.result() + print("Deleted NFDV.") + except Exception: + logger.error( + f"Failed to delete NFDV {self.config.version} from group {self.config.nfdg_name}" + ) + raise + + def delete_artifact_manifest(self, store_type: str) -> None: + """ + _summary_ + + :param store_type: "sa" or "acr" + :raises CLIInternalError: If called with any other store type + :raises Exception if delete throws an exception + """ + if store_type == "sa": + assert isinstance(self.config, VNFConfiguration) + store_name = self.config.blob_artifact_store_name + manifest_name = self.config.sa_manifest_name + elif store_type == "acr": + store_name = self.config.acr_artifact_store_name + manifest_name = self.config.acr_manifest_name + else: + from azure.cli.core.azclierror import CLIInternalError + + raise CLIInternalError( + "Delete artifact manifest called for invalid store type. Valid types are sa and acr." + ) + message = ( + f"Delete Artifact manifest {manifest_name} from artifact store {store_name}" + ) + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.artifact_manifests.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + artifact_store_name=store_name, + artifact_manifest_name=manifest_name, + ) + poller.result() + print("Deleted Artifact Manifest") + except Exception: + logger.error( + f"Failed to delete Artifact manifest {manifest_name} from artifact store {store_name}" + ) + raise + + def delete_nfdg(self) -> None: + """Delete the NFDG.""" + message = f"Delete NFD Group {self.config.nfdg_name}" + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.network_function_definition_groups.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + network_function_definition_group_name=self.config.nfdg_name, + ) + poller.result() + print("Deleted NFD Group") + except Exception: + logger.error("Failed to delete NFDG.") + raise + + def delete_artifact_store(self, store_type: str) -> None: + """Delete an artifact store + :param store_type: "sa" or "acr" + :raises CLIInternalError: If called with any other store type + :raises Exception if delete throws an exception + """ + if store_type == "sa": + assert isinstance(self.config, VNFConfiguration) + store_name = self.config.blob_artifact_store_name + elif store_type == "acr": + store_name = self.config.acr_artifact_store_name + else: + from azure.cli.core.azclierror import CLIInternalError + + raise CLIInternalError( + "Delete artifact store called for invalid store type. Valid types are sa and acr." + ) + message = f"Delete Artifact store {store_name}" + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.artifact_stores.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + artifact_store_name=store_name, + ) + poller.result() + print("Deleted Artifact Store") + except Exception: + logger.error(f"Failed to delete Artifact store {store_name}") + raise + + def delete_publisher(self) -> None: + """ + Delete the publisher. + + Warning - dangerous + """ + message = f"Delete Publisher {self.config.publisher_name}" + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.publishers.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + ) + poller.result() + print("Deleted Publisher") + except Exception: + logger.error("Failed to delete publisher") + raise diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py new file mode 100644 index 00000000000..1d3f1ff095b --- /dev/null +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -0,0 +1,87 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Highly Confidential Material +"""A module to handle interacting with artifacts.""" + +from knack.log import get_logger +from dataclasses import dataclass +from typing import Union + +from azure.storage.blob import BlobClient +from azext_aosm._configuration import ArtifactConfig +from oras.client import OrasClient + +logger = get_logger(__name__) + + +@dataclass +class Artifact: + """Artifact class.""" + + artifact_name: str + artifact_type: str + artifact_version: str + artifact_client: Union[BlobClient, OrasClient] + + def upload(self, artifact_config: ArtifactConfig) -> None: + """ + Upload aritfact. + + :param artifact_config: configuration for the artifact being uploaded + """ + if type(self.artifact_client) == OrasClient: + self._upload_to_acr(artifact_config) + else: + self._upload_to_storage_account(artifact_config) + + def _upload_to_acr(self, artifact_config: ArtifactConfig) -> None: + """ + Upload artifact to ACR. + + :param artifact_config: configuration for the artifact being uploaded + """ + assert type(self.artifact_client) == OrasClient + + # If not included in config, the file path value will be the description of + # the field. + if artifact_config.file_path: + target = f"{self.artifact_client.remote.hostname.replace('https://', '')}/{self.artifact_name}:{self.artifact_version}" + logger.debug(f"Uploading {artifact_config.file_path} to {target}") + self.artifact_client.push( + file=artifact_config.file_path, + target=target, + ) + else: + raise NotImplementedError( + "Copying artifacts is not implemented for ACR artifacts stores." + ) + + def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: + """ + Upload artifact to storage account. + + :param artifact_config: configuration for the artifact being uploaded + """ + assert type(self.artifact_client) == BlobClient + + # If the file path is given, upload the artifact, else, copy it from an existing blob. + if artifact_config.file_path: + logger.info("Upload to blob store") + with open(artifact_config.file_path, "rb") as artifact: + self.artifact_client.upload_blob(artifact, overwrite=True) + logger.info( + f"Successfully uploaded {artifact_config.file_path} to {self.artifact_client.account_name}" + ) + else: + logger.info("Copy from SAS URL to blob store") + source_blob = BlobClient.from_blob_url(artifact_config.blob_sas_url) + + if source_blob.exists(): + logger.debug(source_blob.url) + self.artifact_client.start_copy_from_url(source_blob.url) + logger.info( + f"Successfully copied {source_blob.blob_name} from {source_blob.account_name} to {self.artifact_client.account_name}" + ) + else: + raise RuntimeError( + f"{source_blob.blob_name} does not exist in {source_blob.account_name}." + ) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py new file mode 100644 index 00000000000..8fa31fb30f4 --- /dev/null +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -0,0 +1,156 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Highly Confidential Material +"""A module to handle interacting with artifact manifests.""" + +from knack.log import get_logger +from functools import cached_property, lru_cache +from typing import Any, List, Union +from azure.cli.core.azclierror import AzCLIError +from azext_aosm.deploy.artifact import Artifact +from azure.storage.blob import BlobClient +from oras.client import OrasClient +from azext_aosm._configuration import NFConfiguration +from azext_aosm.vendored_sdks.models import ( + ArtifactManifest, + ManifestArtifactFormat, + CredentialType, + ArtifactType, +) + +from azext_aosm.util.management_clients import ApiClients + +logger = get_logger(__name__) + + +class ArtifactManifestOperator: + """ArtifactManifest class.""" + + def __init__( + self, + config: NFConfiguration, + api_clients: ApiClients, + store_name: str, + manifest_name: str, + ) -> None: + """Init.""" + self.manifest_name = manifest_name + self.api_clients = api_clients + self.config = config + self.store_name = store_name + self.artifacts = self._get_artifact_list() + + @cached_property + def _manifest_credentials(self) -> Any: + """Gets the details for uploading the artifacts in the manifest.""" + + return self.api_clients.aosm_client.artifact_manifests.list_credential( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + artifact_store_name=self.store_name, + artifact_manifest_name=self.manifest_name, + ).as_dict() + + @lru_cache(maxsize=32) # noqa: B019 + def _oras_client(self, acr_url: str) -> OrasClient: + """ + Returns an OrasClient object for uploading to the artifact store ACR. + + :param arc_url: URL of the ACR backing the artifact manifest + """ + client = OrasClient(hostname=acr_url) + client.login( + username=self._manifest_credentials["username"], + password=self._manifest_credentials["acr_token"], + ) + + return client + + def _get_artifact_list(self) -> List[Artifact]: + """Get the list of Artifacts in the Artifact Manifest.""" + artifacts = [] + + manifest: ArtifactManifest = ( + self.api_clients.aosm_client.artifact_manifests.get( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + artifact_store_name=self.store_name, + artifact_manifest_name=self.manifest_name, + ) + ) + + # Instatiate an Artifact object for each artifact in the manifest. + if manifest.artifacts: + for artifact in manifest.artifacts: + if not ( + artifact.artifact_name + and artifact.artifact_type + and artifact.artifact_version + ): + raise AzCLIError( + "Cannot upload artifact. Artifact returned from " + "manifest query is missing required information." + f"{artifact}" + ) + + artifacts.append( + Artifact( + artifact_name=artifact.artifact_name, + artifact_type=artifact.artifact_type, + artifact_version=artifact.artifact_version, + artifact_client=self._get_artifact_client(artifact), + ) + ) + + return artifacts + + def _get_artifact_client( + self, artifact: ManifestArtifactFormat + ) -> Union[BlobClient, OrasClient]: + """ + Get the artifact client required for uploading the artifact. + + :param artifact - a ManifestArtifactFormat with the artifact info. + """ + # Appease mypy - an error will be raised before this if these are blank + assert artifact.artifact_name + assert artifact.artifact_type + assert artifact.artifact_version + if ( + self._manifest_credentials["credential_type"] + == CredentialType.AZURE_STORAGE_ACCOUNT_TOKEN + ): + # Check we have the required artifact types for this credential. Indicates + # a coding error if we hit this but worth checking. + if not ( + artifact.artifact_type == ArtifactType.IMAGE_FILE + or artifact.artifact_type == ArtifactType.VHD_IMAGE_FILE + ): + raise AzCLIError( + f"Cannot upload artifact {artifact.artifact_name}." + " Artifact manifest credentials of type " + f"{CredentialType.AZURE_STORAGE_ACCOUNT_TOKEN} are not expected " + f"for Artifacts of type {artifact.artifact_type}" + ) + + container_basename = artifact.artifact_name.replace("-", "") + blob_url = self._get_blob_url( + f"{container_basename}-{artifact.artifact_version}" + ) + return BlobClient.from_blob_url(blob_url) + else: + return self._oras_client(self._manifest_credentials["acr_server_url"]) + + def _get_blob_url(self, container_name: str) -> str: + """ + Get the URL for the blob to be uploaded to the storage account artifact store. + + :param container_name: name of the container + """ + for container_credential in self._manifest_credentials["container_credentials"]: + if container_credential["container_name"] == container_name: + sas_uri = str(container_credential["container_sas_uri"]) + sas_uri_prefix = sas_uri.split("?")[0] + sas_uri_token = sas_uri.split("?")[1] + + return f"{sas_uri_prefix}/{container_name}?{sas_uri_token}" + raise KeyError(f"Manifest does not include a credential for {container_name}.") diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py new file mode 100644 index 00000000000..c825f48e705 --- /dev/null +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -0,0 +1,379 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains class for deploying generated definitions using ARM.""" +import json +import os +import shutil +import subprocess # noqa +from typing import Any, Dict, Optional +import tempfile + +from knack.log import get_logger +from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator +from azext_aosm.util.management_clients import ApiClients +from azure.mgmt.resource.resources.v2021_04_01.models import DeploymentExtended + +from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK +from azext_aosm._configuration import NFConfiguration, VNFConfiguration +from azext_aosm.util.constants import ( + VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, + VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, +) + + +logger = get_logger(__name__) + + +class DeployerViaArm: + """ + A class to deploy Artifact Manifests, NFDs and NSDs from bicep templates using ARM. + + Uses the SDK to pre-deploy less complex resources and then ARM to deploy the bicep + templates. + """ + + def __init__( + self, + api_clients: ApiClients, + config: NFConfiguration, + ) -> None: + """ + Initializes a new instance of the Deployer class. + + :param api_clients: ApiClients object for AOSM and ResourceManagement + :param config: The configuration for this NF + """ + logger.debug("Create ARM/Bicep Deployer") + self.api_clients = api_clients + self.config = config + self.pre_deployer = PreDeployerViaSDK(api_clients, self.config) + + def deploy_vnfd_from_bicep( + self, + bicep_path: Optional[str] = None, + parameters_json_file: Optional[str] = None, + manifest_bicep_path: Optional[str] = None, + manifest_parameters_json_file: Optional[str] = None, + ) -> None: + """ + Deploy the bicep template defining the VNFD. + + Also ensure that all required predeploy resources are deployed. + + :param bicep_template_path: The path to the bicep template of the nfdv + :type bicep_template_path: str + :parameters_json_file: path to an override file of set parameters for the nfdv + :param manifest_bicep_path: The path to the bicep template of the manifest + :manifest_parameters_json_file: path to an override file of set parameters for + the manifest + """ + assert isinstance(self.config, VNFConfiguration) + + if not bicep_path: + # User has not passed in a bicep template, so we are deploying the default + # one produced from building the NFDV using this CLI + bicep_path = os.path.join( + self.config.build_output_folder_name, + VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, + ) + + if parameters_json_file: + message = f"Use parameters from file {parameters_json_file}" + logger.info(message) + print(message) + with open(parameters_json_file, "r", encoding="utf-8") as f: + parameters = json.loads(f.read()) + + else: + # User has not passed in parameters file, so we use the parameters required + # from config for the default bicep template produced from building the + # NFDV using this CLI + logger.debug("Create parameters for default NFDV template.") + parameters = self.construct_vnfd_parameters() + + logger.debug(parameters) + + # Create or check required resources + deploy_manifest_template = not self.vnfd_predeploy() + if deploy_manifest_template: + print(f"Deploy bicep template for Artifact manifests") + logger.debug("Deploy manifest bicep") + if not manifest_bicep_path: + manifest_bicep_path = os.path.join( + self.config.build_output_folder_name, + VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, + ) + if not manifest_parameters_json_file: + manifest_params = self.construct_manifest_parameters() + else: + logger.info("Use provided manifest parameters") + with open(manifest_parameters_json_file, "r", encoding="utf-8") as f: + manifest_params = json.loads(f.read()) + self.deploy_bicep_template(manifest_bicep_path, manifest_params) + else: + print( + f"Artifact manifests exist for NFD {self.config.nf_name} " + f"version {self.config.version}" + ) + message = ( + f"Deploy bicep template for NFD {self.config.nf_name} version {self.config.version} " + f"into {self.config.publisher_resource_group_name} under publisher " + f"{self.config.publisher_name}" + ) + print(message) + logger.info(message) + self.deploy_bicep_template(bicep_path, parameters) + print(f"Deployed NFD {self.config.nf_name} version {self.config.version}.") + + storage_account_manifest = ArtifactManifestOperator( + self.config, + self.api_clients, + self.config.blob_artifact_store_name, + self.config.sa_manifest_name, + ) + acr_manifest = ArtifactManifestOperator( + self.config, + self.api_clients, + self.config.acr_artifact_store_name, + self.config.acr_manifest_name, + ) + + vhd_artifact = storage_account_manifest.artifacts[0] + arm_template_artifact = acr_manifest.artifacts[0] + + print("Uploading VHD artifact") + vhd_artifact.upload(self.config.vhd) + print("Uploading ARM template artifact") + arm_template_artifact.upload(self.config.arm_template) + print("Done") + + def vnfd_predeploy(self) -> bool: + """ + All the predeploy steps for a VNF. Create publisher, artifact stores and NFDG. + + VNF specific return True if artifact manifest already exists, False otherwise + """ + logger.debug("Ensure all required resources exist") + self.pre_deployer.ensure_config_resource_group_exists() + self.pre_deployer.ensure_config_publisher_exists() + self.pre_deployer.ensure_acr_artifact_store_exists() + self.pre_deployer.ensure_sa_artifact_store_exists() + self.pre_deployer.ensure_config_nfdg_exists() + return self.pre_deployer.do_config_artifact_manifests_exist() + + def construct_vnfd_parameters(self) -> Dict[str, Any]: + """ + Create the parmeters dictionary for vnfdefinitions.bicep. VNF specific. + + :param config: The contents of the configuration file. + """ + assert isinstance(self.config, VNFConfiguration) + return { + "publisherName": {"value": self.config.publisher_name}, + "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, + "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, + "nfName": {"value": self.config.nf_name}, + "nfDefinitionGroup": {"value": self.config.nfdg_name}, + "nfDefinitionVersion": {"value": self.config.version}, + "vhdVersion": {"value": self.config.vhd.version}, + "armTemplateVersion": {"value": self.config.arm_template.version}, + } + + def construct_manifest_parameters(self) -> Dict[str, Any]: + """ + Create the parmeters dictionary for vnfdefinitions.bicep. VNF specific. + + :param config: The contents of the configuration file. + """ + assert isinstance(self.config, VNFConfiguration) + return { + "publisherName": {"value": self.config.publisher_name}, + "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, + "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, + "acrManifestName": {"value": self.config.acr_manifest_name}, + "saManifestName": {"value": self.config.sa_manifest_name}, + "vhdName": {"value": self.config.vhd.artifact_name}, + "vhdVersion": {"value": self.config.vhd.version}, + "armTemplateName": {"value": self.config.arm_template.artifact_name}, + "armTemplateVersion": {"value": self.config.arm_template.version}, + } + + def deploy_bicep_template( + self, bicep_template_path: str, parameters: Dict[Any, Any] + ) -> Any: + """ + Deploy a bicep template. + + :param bicep_template_path: Path to the bicep template + :param parameters: Parameters for the bicep template + :return Any output that the template produces + """ + logger.info("Deploy %s", bicep_template_path) + arm_template_json = self.convert_bicep_to_arm(bicep_template_path) + + return self.validate_and_deploy_arm_template( + arm_template_json, parameters, self.config.publisher_resource_group_name + ) + + def resource_exists(self, resource_name: str) -> bool: + """ + Determine if a resource with the given name exists. + + :param resource_name: The name of the resource to check. + """ + logger.debug("Check if %s exists", resource_name) + resources = self.api_clients.resource_client.resources.list_by_resource_group( + resource_group_name=self.config.publisher_resource_group_name + ) + + resource_exists = False + + for resource in resources: + if resource.name == resource_name: + resource_exists = True + break + + return resource_exists + + def validate_and_deploy_arm_template( + self, template: Any, parameters: Dict[Any, Any], resource_group: str + ) -> Any: + """ + Validate and deploy an individual ARM template. + + This ARM template will be created in the resource group passed in. + + :param template: The JSON contents of the template to deploy + :param parameters: The JSON contents of the parameters file + :param resource_group: The name of the resource group that has been deployed + + :raise RuntimeError if validation or deploy fails + :return: Output dictionary from the bicep template. + """ + deployment_name = f"nfd_into_{resource_group}" + + validation = self.api_clients.resource_client.deployments.begin_validate( + resource_group_name=resource_group, + deployment_name=deployment_name, + parameters={ + "properties": { + "mode": "Incremental", + "template": template, + "parameters": parameters, + } + }, + ) + + validation_res = validation.result() + logger.debug(f"Validation Result {validation_res}") + if validation_res.error: + # Validation failed so don't even try to deploy + logger.error( + f"Template for resource group {resource_group} " + f"has failed validation. The message was: " + f"{validation_res.error.message}. See logs for additional details." + ) + logger.debug( + f"Template for resource group {resource_group} " + f"failed validation. Full error details: {validation_res.error}." + ) + raise RuntimeError("Azure template validation failed.") + + # Validation succeeded so proceed with deployment + logger.debug(f"Successfully validated resources for {resource_group}") + + poller = self.api_clients.resource_client.deployments.begin_create_or_update( + resource_group_name=resource_group, + deployment_name=deployment_name, + parameters={ + "properties": { + "mode": "Incremental", + "template": template, + "parameters": parameters, + } + }, + ) + logger.debug(poller) + + # Wait for the deployment to complete and get the outputs + deployment: DeploymentExtended = poller.result() + logger.debug("Finished deploying") + + if deployment.properties is not None: + depl_props = deployment.properties + else: + raise RuntimeError("The deployment has no properties.\nAborting") + logger.debug(f"Deployed: {deployment.name} {deployment.id} {depl_props}") + + if depl_props.provisioning_state != "Succeeded": + logger.debug(f"Failed to provision: {depl_props}") + raise RuntimeError( + f"Deploy of template to resource group" + f" {resource_group} proceeded but the provisioning" + f" state returned is {depl_props.provisioning_state}. " + f"\nAborting" + ) + logger.debug( + f"Provisioning state of {resource_group}" + f": {depl_props.provisioning_state}" + ) + + return depl_props.outputs + + def convert_bicep_to_arm(self, bicep_template_path: str) -> Any: + """ + Convert a bicep template into an ARM template. + + :param bicep_template_path: The path to the bicep template to be converted + + :raise RuntimeError if az CLI is not installed. + :return: Output dictionary from the bicep template. + """ + if not shutil.which("az"): + logger.error( + "The Azure CLI is not installed - follow " + "https://github.com/Azure/bicep/blob/main/docs/installing.md#linux" + ) + raise RuntimeError( + "The Azure CLI is not installed - cannot render ARM templates." + ) + logger.debug(f"Converting {bicep_template_path} to ARM template") + + with tempfile.TemporaryDirectory() as tmpdir: + bicep_filename = os.path.basename(bicep_template_path) + arm_template_name = bicep_filename.replace(".bicep", ".json") + + try: + bicep_output = subprocess.run( # noqa + [ + str(shutil.which("az")), + "bicep", + "build", + "--file", + bicep_template_path, + "--outfile", + os.path.join(tmpdir, arm_template_name), + ], + check=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + logger.debug("az bicep output: %s", str(bicep_output)) + except subprocess.CalledProcessError as e: + logger.error( + "ARM template compilation failed! See logs for full " + "output. The failing command was %s", + e.cmd, + ) + logger.debug("bicep build stdout: %s", e.stdout) + logger.debug("bicep build stderr: %s", e.stderr) + raise + + with open( + os.path.join(tmpdir, arm_template_name), "r", encoding="utf-8" + ) as template_file: + arm_json = json.loads(template_file.read()) + + return arm_json diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py new file mode 100644 index 00000000000..b00623ca9ea --- /dev/null +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -0,0 +1,369 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains class for deploying resources required by NFDs/NSDs via the SDK.""" + +from knack.log import get_logger + +from azure.core import exceptions as azure_exceptions +from azure.cli.core.azclierror import AzCLIError +from azure.mgmt.resource.resources.v2022_09_01.models import ResourceGroup + +from azext_aosm.util.management_clients import ApiClients +from azext_aosm.vendored_sdks.models import ( + ArtifactStore, + ArtifactStoreType, + NetworkFunctionDefinitionGroup, + NetworkServiceDesignGroup, + Publisher, + ProvisioningState, +) +from azext_aosm._configuration import NFConfiguration, VNFConfiguration + +logger = get_logger(__name__) + + +class PreDeployerViaSDK: + """ + A class for checking or publishing resources required by NFDs/NSDs. + + Uses the SDK to deploy rather than ARM, as the objects it deploys are not complex. + """ + + def __init__( + self, + api_clients: ApiClients, + config: NFConfiguration, + ) -> None: + """ + Initializes a new instance of the Deployer class. + + :param api_clients: ApiClients object for AOSM and ResourceManagement + :param config: The configuration for this NF + """ + + self.api_clients = api_clients + self.config = config + + def ensure_resource_group_exists(self, resource_group_name: str) -> None: + """ + Checks whether a particular resource group exists on the subscription. + Copied from virtutils. + + :param resource_group_name: The name of the resource group + + Raises a NotFoundError exception if the resource group does not exist. + Raises a PermissionsError exception if we don't have permissions to check resource group existence. + """ + if not self.api_clients.resource_client.resource_groups.check_existence( + resource_group_name + ): + logger.info(f"RG {resource_group_name} not found. Create it.") + print(f"Creating resource group {resource_group_name}.") + rg_params: ResourceGroup = ResourceGroup(location=self.config.location) + self.api_clients.resource_client.resource_groups.create_or_update( + resource_group_name, rg_params + ) + else: + print(f"Resource group {resource_group_name} exists.") + self.api_clients.resource_client.resource_groups.get( + resource_group_name + ) + + def ensure_config_resource_group_exists(self) -> None: + """ + Ensures that the publisher exists in the resource group. + + Finds the parameters from self.config + """ + self.ensure_resource_group_exists(self.config.publisher_resource_group_name) + + def ensure_publisher_exists( + self, resource_group_name: str, publisher_name: str, location: str + ) -> None: + """ + Ensures that the publisher exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param location: The location of the publisher. + :type location: str + """ + logger.info("Creating publisher %s if it does not exist", publisher_name) + try: + pubby = self.api_clients.aosm_client.publishers.get( + resource_group_name, publisher_name + ) + print( + f"Publisher {pubby.name} exists in resource group {resource_group_name}" + ) + except azure_exceptions.ResourceNotFoundError: + # Create the publisher + print( + f"Creating publisher {publisher_name} in resource group {resource_group_name}" + ) + pub = self.api_clients.aosm_client.publishers.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + parameters=Publisher(location=location, scope="Private"), + ) + pub.result() + + def ensure_config_publisher_exists(self) -> None: + """ + Ensures that the publisher exists in the resource group. + + Finds the parameters from self.config + """ + self.ensure_publisher_exists( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + location=self.config.location, + ) + + def ensure_artifact_store_exists( + self, + resource_group_name: str, + publisher_name: str, + artifact_store_name: str, + artifact_store_type: ArtifactStoreType, + location: str, + ) -> None: + """ + Ensures that the artifact store exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param artifact_store_name: The name of the artifact store. + :type artifact_store_name: str + :param artifact_store_type: The type of the artifact store. + :type artifact_store_type: ArtifactStoreType + :param location: The location of the artifact store. + :type location: str + """ + logger.info( + "Creating artifact store %s if it does not exist", + artifact_store_name, + ) + try: + self.api_clients.aosm_client.artifact_stores.get( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + ) + print( + f"Artifact store {artifact_store_name} exists in resource group {resource_group_name}" + ) + except azure_exceptions.ResourceNotFoundError: + print( + f"Create Artifact Store {artifact_store_name} of type {artifact_store_type}" + ) + poller = ( + self.api_clients.aosm_client.artifact_stores.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + artifact_store_name=artifact_store_name, + parameters=ArtifactStore( + location=location, + store_type=artifact_store_type, + ), + ) + ) + # Asking for result waits for provisioning state Succeeded before carrying + # on + arty: ArtifactStore = poller.result() + + if arty.provisioning_state != ProvisioningState.SUCCEEDED: + logger.debug(f"Failed to provision artifact store: {arty.name}") + raise RuntimeError( + f"Creation of artifact store proceeded, but the provisioning" + f" state returned is {arty.provisioning_state}. " + f"\nAborting" + ) + logger.debug( + f"Provisioning state of {artifact_store_name}" + f": {arty.provisioning_state}" + ) + + def ensure_acr_artifact_store_exists(self) -> None: + """ + Ensures that the ACR Artifact store exists. + + Finds the parameters from self.config + """ + self.ensure_artifact_store_exists( + self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.acr_artifact_store_name, + ArtifactStoreType.AZURE_CONTAINER_REGISTRY, + self.config.location, + ) + + def ensure_sa_artifact_store_exists(self) -> None: + """ + Ensures that the Storage Account Artifact store for VNF exists. + + Finds the parameters from self.config + """ + if not isinstance(self.config, VNFConfiguration): + # This is a coding error but worth checking. + raise AzCLIError( + "Cannot check that the storage account artifact store exists as " + "the configuration file doesn't map to VNFConfiguration" + ) + + self.ensure_artifact_store_exists( + self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.blob_artifact_store_name, + ArtifactStoreType.AZURE_STORAGE_ACCOUNT, + self.config.location, + ) + + def ensure_nfdg_exists( + self, + resource_group_name: str, + publisher_name: str, + nfdg_name: str, + location: str, + ): + """ + Ensures that the network function definition group exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param nfdg_name: The name of the network function definition group. + :type nfdg_name: str + :param location: The location of the network function definition group. + :type location: str + """ + + logger.info( + "Creating network function definition group %s if it does not exist", + nfdg_name, + ) + self.api_clients.aosm_client.network_function_definition_groups.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=nfdg_name, + parameters=NetworkFunctionDefinitionGroup(location=location), + ) + + def ensure_config_nfdg_exists( + self, + ): + """ + Ensures that the Network Function Definition Group exists. + + Finds the parameters from self.config + """ + self.ensure_nfdg_exists( + self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.nfdg_name, + self.config.location, + ) + + def does_artifact_manifest_exist( + self, rg_name: str, publisher_name: str, store_name: str, manifest_name: str + ) -> bool: + try: + self.api_clients.aosm_client.artifact_manifests.get( + resource_group_name=rg_name, + publisher_name=publisher_name, + artifact_store_name=store_name, + artifact_manifest_name=manifest_name, + ) + logger.debug(f"Artifact manifest {manifest_name} exists") + return True + except azure_exceptions.ResourceNotFoundError: + logger.debug(f"Artifact manifest {manifest_name} does not exist") + return False + + def do_config_artifact_manifests_exist( + self, + ): + """Returns True if all required manifests exist, False otherwise.""" + acr_manny_exists: bool = self.does_artifact_manifest_exist( + rg_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + store_name=self.config.acr_artifact_store_name, + manifest_name=self.config.acr_manifest_name, + ) + + if isinstance(self.config, VNFConfiguration): + sa_manny_exists: bool = self.does_artifact_manifest_exist( + rg_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + store_name=self.config.blob_artifact_store_name, + manifest_name=self.config.sa_manifest_name, + ) + if acr_manny_exists and sa_manny_exists: + return True + elif acr_manny_exists or sa_manny_exists: + raise AzCLIError( + "Only one artifact manifest exists. Cannot proceed. Please delete the NFDV using `az aosm definition delete` and start the publish again from scratch." + ) + else: + return False + + return acr_manny_exists + + def ensure_nsdg_exists( + self, + resource_group_name: str, + publisher_name: str, + nsdg_name: str, + location: str, + ): + """ + Ensures that the network service design group exists in the resource group. + + :param resource_group_name: The name of the resource group. + :type resource_group_name: str + :param publisher_name: The name of the publisher. + :type publisher_name: str + :param nsdg_name: The name of the network service design group. + :type nsdg_name: str + :param location: The location of the network service design group. + :type location: str + """ + + logger.info( + "Creating network service design group %s if it does not exist", + nsdg_name, + ) + self.api_clients.aosm_client.network_service_design_groups.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_service_design_group_name=nsdg_name, + parameters=NetworkServiceDesignGroup(location=location), + ) + + def resource_exists_by_name(self, rg_name: str, resource_name: str) -> bool: + """ + Determine if a resource with the given name exists. No checking is done as + to the type. + + :param resource_name: The name of the resource to check. + """ + logger.debug("Check if %s exists", resource_name) + resources = self.api_clients.resource_client.resources.list_by_resource_group( + resource_group_name=rg_name + ) + + resource_exists = False + + for resource in resources: + if resource.name == resource_name: + resource_exists = True + break + + return resource_exists diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 77627b30885..df7afef18dc 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -4,18 +4,18 @@ # -------------------------------------------------------------------------------------- """Contains a class for generating VNF NFDs and associated resources.""" from typing import Dict, Any -from .nfd_generator_base import NFDGenerator +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator + class CnfNfdGenerator(NFDGenerator): - """_summary_ + """ + _summary_ :param NFDGenerator: _description_ :type NFDGenerator: _type_ """ - def __init__( - self, - config: Dict[Any, Any] - ): + + def __init__(self, config: Dict[Any, Any]): super(NFDGenerator, self).__init__( config=config, ) diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index 3de8cd253eb..81afb4db802 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -3,28 +3,26 @@ # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- """Contains a base class for generating NFDs.""" -from typing import Dict, Any from knack.log import get_logger + + logger = get_logger(__name__) + class NFDGenerator: """A class for generating an NFD from a config file.""" - + def __init__( self, - config: Dict[Any, Any] ) -> None: - """_summary_ + """ + Superclass for NFD generators. - :param definition_type: _description_ - :type definition_type: str - :param config: _description_ - :type config: Dict[Any, Any] + The sub-classes do the actual work """ - self.config = config - + pass + def generate_nfd(self) -> None: - """No-op on base class - """ + """No-op on base class.""" logger.error("Generate NFD called on base class. No-op") return diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep new file mode 100644 index 00000000000..20e7d5e2e2b --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an NF definition for a VNF +param location string = resourceGroup().location +@description('Name of an existing publisher, expected to be in the resource group where you deploy the template') +param publisherName string +@description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') +param acrArtifactStoreName string +@description('Name of an existing Storage Account-backed Artifact Store, deployed under the publisher.') +param saArtifactStoreName string +@description('Name of the manifest to deploy for the ACR-backed Artifact Store') +param acrManifestName string +@description('Name of the manifest to deploy for the Storage Account-backed Artifact Store') +param saManifestName string +@description('The name under which to store the VHD') +param vhdName string +@description('The version that you want to name the NFM VHD artifact, in format A-B-C. e.g. 6-13-0') +param vhdVersion string +@description('The name under which to store the ARM template') +param armTemplateName string +@description('The version that you want to name the NFM template artifact, in format A.B.C. e.g. 6.13.0. If testing for development, you can use any numbers you like.') +param armTemplateVersion string + +// Created by the az aosm definition publish command before the template is deployed +resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { + name: publisherName + scope: resourceGroup() +} + +// Created by the az aosm definition publish command before the template is deployed +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { + parent: publisher + name: acrArtifactStoreName +} + +// Created by the az aosm definition publish command before the template is deployed +resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { + parent: publisher + name: saArtifactStoreName +} + +resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { + parent: saArtifactStore + name: saManifestName + location: location + properties: { + artifacts: [ + { + artifactName: '${vhdName}' + artifactType: 'VhdImageFile' + artifactVersion: vhdVersion + } + ] + } +} + +resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { + parent: acrArtifactStore + name: acrManifestName + location: location + properties: { + artifacts: [ + { + artifactName: '${armTemplateName}' + artifactType: 'ArmTemplate' + artifactVersion: armTemplateVersion + } + ] + } +} diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep new file mode 100644 index 00000000000..87f3b93e15f --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep @@ -0,0 +1,103 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an NF definition for a VNF +param location string = resourceGroup().location +@description('Name of an existing publisher, expected to be in the resource group where you deploy the template') +param publisherName string +@description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') +param acrArtifactStoreName string +@description('Name of an existing Storage Account-backed Artifact Store, deployed under the publisher.') +param saArtifactStoreName string +@description('Name of Network Function. Used predominantly as a prefix for other variable names') +param nfName string +@description('Name of an existing Network Function Definition Group') +param nfDefinitionGroup string +@description('The version of the NFDV you want to deploy, in format A-B-C') +param nfDefinitionVersion string +@description('The version that you want to name the NFM VHD artifact, in format A-B-C. e.g. 6-13-0') +param vhdVersion string +@description('The version that you want to name the NFM template artifact, in format A.B.C. e.g. 6.13.0. If testing for development, you can use any numbers you like.') +param armTemplateVersion string + +// Created by the az aosm definition publish command before the template is deployed +resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { + name: publisherName + scope: resourceGroup() +} + +// Created by the az aosm definition publish command before the template is deployed +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { + parent: publisher + name: acrArtifactStoreName +} + +// Created by the az aosm definition publish command before the template is deployed +resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { + parent: publisher + name: saArtifactStoreName +} + +// Created by the az aosm definition publish command before the template is deployed +resource nfdg 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups@2022-09-01-preview' existing = { + parent: publisher + name: nfDefinitionGroup +} + +resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups/networkfunctiondefinitionversions@2022-09-01-preview' = { + parent: nfdg + name: nfDefinitionVersion + location: location + properties: { + // versionState should be changed to 'Active' once it is finalized. + versionState: 'Preview' + deployParameters: string(loadJsonContent('schemas/deploymentParameters.json')) + networkFunctionType: 'VirtualNetworkFunction' + networkFunctionTemplate: { + nfviType: 'AzureCore' + networkFunctionApplications: [ + { + artifactType: 'VhdImageFile' + name: '${nfName}Image' + dependsOnProfile: null + artifactProfile: { + vhdArtifactProfile: { + vhdName: '${nfName}-vhd' + vhdVersion: vhdVersion + } + artifactStore: { + id: saArtifactStore.id + } + } + // mapping deploy param vals to vals required by this network function application object + deployParametersMappingRuleProfile: { + vhdImageMappingRuleProfile: { + userConfiguration: string(loadJsonContent('configMappings/vhdParameters.json')) + } + // ?? + applicationEnablement: 'Unknown' + } + } + { + artifactType: 'ArmTemplate' + name: nfName + dependsOnProfile: null + artifactProfile: { + templateArtifactProfile: { + templateName: '${nfName}-arm-template' + templateVersion: armTemplateVersion + } + artifactStore: { + id: acrArtifactStore.id + } + } + deployParametersMappingRuleProfile: { + templateMappingRuleProfile: { + templateParameters: string(loadJsonContent('configMappings/templateParameters.json')) + } + applicationEnablement: 'Unknown' + } + } + ] + } + } +} diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py new file mode 100644 index 00000000000..2b0768c6291 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -0,0 +1,207 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains a class for generating VNF NFDs and associated resources.""" +from knack.log import get_logger +import json +import logging +import os +import shutil +from functools import cached_property +from pathlib import Path +from typing import Any, Dict, Optional + +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator + +from azext_aosm._configuration import VNFConfiguration +from azext_aosm.util.constants import ( + VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, + VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, +) + + +logger = get_logger(__name__) + + +class VnfBicepNfdGenerator(NFDGenerator): + """ + VNF NFD Generator. + + This takes a source ARM template and a config file, and outputs: + - A bicep file for the NFDV + - Parameters files that are used by the NFDV bicep file, these are the + deployParameters and the mapping profiles of those deploy parameters + - A bicep file for the Artifact manifests + """ + + def __init__(self, config: VNFConfiguration): + super(NFDGenerator, self).__init__() + self.config = config + self.bicep_template_name = VNF_DEFINITION_BICEP_SOURCE_TEMPLATE + self.manifest_template_name = VNF_MANIFEST_BICEP_SOURCE_TEMPLATE + + self.arm_template_path = self.config.arm_template.file_path + self.folder_name = self.config.build_output_folder_name + + self._bicep_path = os.path.join(self.folder_name, self.bicep_template_name) + self._manifest_path = os.path.join( + self.folder_name, self.manifest_template_name + ) + + def generate_nfd(self) -> None: + """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" + if self.bicep_path: + print(f"Using the existing NFD bicep template {self.bicep_path}.") + print( + f"To generate a new NFD, delete the folder {os.path.dirname(self.bicep_path)} and re-run this command." + ) + else: + self.write() + + def write(self) -> None: + """Create a bicep template for an NFD from the ARM template for the VNF.""" + logger.info(f"Generate NFD bicep template for {self.arm_template_path}") + print(f"Generate NFD bicep template for {self.arm_template_path}") + + self._create_nfd_folder() + self.create_parameter_files() + self.copy_bicep() + print(f"Generated NFD bicep template created in {self.folder_name}") + + @property + def bicep_path(self) -> Optional[str]: + """Returns the path to the bicep file for the NFD if it has been created.""" + if os.path.exists(self._bicep_path): + return self._bicep_path + + return None + + @property + def manifest_path(self) -> Optional[str]: + """Returns the path to the bicep file for the NFD if it has been created.""" + if os.path.exists(self._manifest_path): + return self._manifest_path + + return None + + def _create_nfd_folder(self) -> None: + """ + Create the folder for the NFD bicep files. + + :raises RuntimeError: If the user aborts. + """ + if os.path.exists(self.folder_name): + carry_on = input( + f"The folder {self.folder_name} already exists - delete it and continue? (y/n)" + ) + if carry_on != "y": + raise RuntimeError("User aborted!") + + shutil.rmtree(self.folder_name) + + logger.info("Create NFD bicep %s", self.folder_name) + os.mkdir(self.folder_name) + + @cached_property + def vm_parameters(self) -> Dict[str, Any]: + """The parameters from the VM ARM template.""" + with open(self.arm_template_path, "r") as _file: + parameters: Dict[str, Any] = json.load(_file)["parameters"] + + return parameters + + def create_parameter_files(self) -> None: + """Create the Deployment and Template json parameter files.""" + schemas_folder_path = os.path.join(self.folder_name, "schemas") + os.mkdir(schemas_folder_path) + self.write_deployment_parameters(schemas_folder_path) + + mappings_folder_path = os.path.join(self.folder_name, "configMappings") + os.mkdir(mappings_folder_path) + self.write_template_parameters(mappings_folder_path) + self.write_vhd_parameters(mappings_folder_path) + + def write_deployment_parameters(self, folder_path: str) -> None: + """ + Write out the NFD deploymentParameters.json file. + + :param folder_path: The folder to put this file in. + """ + logger.debug("Create deploymentParameters.json") + + nfd_parameters: Dict[str, Any] = { + key: {"type": self.vm_parameters[key]["type"]} for key in self.vm_parameters + } + + deployment_parameters_path = os.path.join( + folder_path, "deploymentParameters.json" + ) + + # Heading for the deployParameters schema + deploy_parameters_full: Dict[str, Any] = { + "$schema": "https://json-schema.org/draft-07/schema#", + "title": "DeployParametersSchema", + "type": "object", + "properties": nfd_parameters, + } + + with open(deployment_parameters_path, "w") as _file: + _file.write(json.dumps(deploy_parameters_full, indent=4)) + + logger.debug(f"{deployment_parameters_path} created") + + def write_template_parameters(self, folder_path: str) -> None: + """ + Write out the NFD templateParameters.json file. + + :param folder_path: The folder to put this file in. + """ + logger.debug("Create templateParameters.json") + template_parameters = { + key: f"{{deployParameters.{key}}}" for key in self.vm_parameters + } + + template_parameters_path = os.path.join(folder_path, "templateParameters.json") + + with open(template_parameters_path, "w") as _file: + _file.write(json.dumps(template_parameters, indent=4)) + + logger.debug(f"{template_parameters_path} created") + + def write_vhd_parameters(self, folder_path: str) -> None: + """ + Write out the NFD vhdParameters.json file. + + :param folder_path: The folder to put this file in. + """ + azureDeployLocation: str + if self.vm_parameters.get("location"): + # Location can be passed in as deploy parameter + azureDeployLocation = "{deployParameters.location}" + else: + # Couldn't find a location parameter in the source template, so hard code to + # the location we are deploying the publisher to. + azureDeployLocation = self.config.location + + vhd_parameters = { + "imageName": f"{self.config.nf_name}Image", + "azureDeployLocation": azureDeployLocation, + } + + vhd_parameters_path = os.path.join(folder_path, "vhdParameters.json") + + with open(vhd_parameters_path, "w", encoding="utf-8") as _file: + _file.write(json.dumps(vhd_parameters, indent=4)) + + logger.debug(f"{vhd_parameters_path} created") + + def copy_bicep(self) -> None: + """Copy the bicep templates into the build output folder.""" + code_dir = os.path.dirname(__file__) + + bicep_path = os.path.join(code_dir, "templates", self.bicep_template_name) + manifest_path = os.path.join(code_dir, "templates", self.manifest_template_name) + + shutil.copy(bicep_path, self.folder_name) + shutil.copy(manifest_path, self.folder_name) diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py deleted file mode 100644 index daa9802c872..00000000000 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ /dev/null @@ -1,47 +0,0 @@ -# -------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT -# License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------- -"""Contains a class for generating VNF NFDs and associated resources.""" -from typing import Dict, Any -from .nfd_generator_base import NFDGenerator -from knack.log import get_logger -from azext_aosm.vendored_sdks import HybridNetworkManagementClient -from azext_aosm.vendored_sdks.models import Publisher, NetworkFunctionDefinitionVersion, NetworkFunctionDefinitionGroup, ArtifactManifest, ManifestArtifactFormat -from azext_aosm._constants import VHD_ARTIFACT, ARM_TEMPLATE_ARTIFACT - - -logger = get_logger(__name__) - -class VnfNfdGenerator(NFDGenerator): - """_summary_ - - :param NFDGenerator: _description_ - :type NFDGenerator: _type_ - """ - def __init__( - self, - config: Dict[Any, Any] - ): - super(NFDGenerator, self).__init__( - config=config, - ) - - def generate_nfd(self) -> None: - """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. - """ - arty_manny_sa = ArtifactManifest(location="blah", - tags={"blah": "blah"}, - artifacts=[ManifestArtifactFormat(artifact_name="blah", - artifact_type=VHD_ARTIFACT, - artifact_version="blah")]) - - arty_manny_acr = ArtifactManifest(location="blah", - tags={"blah": "blah"}, - artifacts=[ManifestArtifactFormat(artifact_name="blah", - artifact_type=ARM_TEMPLATE_ARTIFACT, - artifact_version="blah")]) - - - - diff --git a/src/aosm/azext_aosm/tests/__init__.py b/src/aosm/azext_aosm/tests/__init__.py index 2dcf9bb68b3..99c0f28cd71 100644 --- a/src/aosm/azext_aosm/tests/__init__.py +++ b/src/aosm/azext_aosm/tests/__init__.py @@ -2,4 +2,4 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for # license information. -# ----------------------------------------------------------------------------- \ No newline at end of file +# ----------------------------------------------------------------------------- diff --git a/src/aosm/azext_aosm/tests/latest/__init__.py b/src/aosm/azext_aosm/tests/latest/__init__.py index 2dcf9bb68b3..99c0f28cd71 100644 --- a/src/aosm/azext_aosm/tests/latest/__init__.py +++ b/src/aosm/azext_aosm/tests/latest/__init__.py @@ -2,4 +2,4 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for # license information. -# ----------------------------------------------------------------------------- \ No newline at end of file +# ----------------------------------------------------------------------------- diff --git a/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py b/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py index a8b6975181d..0bc37d2e16e 100644 --- a/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py +++ b/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py @@ -7,34 +7,34 @@ import unittest # from azure_devtools.scenario_tests import AllowLargeResponse -from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) +from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer -TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) +TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), "..")) class AosmScenarioTest(ScenarioTest): - - @ResourceGroupPreparer(name_prefix='cli_test_aosm') + @ResourceGroupPreparer(name_prefix="cli_test_aosm") def test_aosm(self, resource_group): - - self.kwargs.update({ - 'name': 'test1' - }) - - self.cmd('aosm create -g {rg} -n {name} --tags foo=doo', checks=[ - self.check('tags.foo', 'doo'), - self.check('name', '{name}') - ]) - self.cmd('aosm update -g {rg} -n {name} --tags foo=boo', checks=[ - self.check('tags.foo', 'boo') - ]) - count = len(self.cmd('aosm list').get_output_in_json()) - self.cmd('aosm show - {rg} -n {name}', checks=[ - self.check('name', '{name}'), - self.check('resourceGroup', '{rg}'), - self.check('tags.foo', 'boo') - ]) - self.cmd('aosm delete -g {rg} -n {name}') - final_count = len(self.cmd('aosm list').get_output_in_json()) + self.kwargs.update({"name": "test1"}) + + self.cmd( + "aosm create -g {rg} -n {name} --tags foo=doo", + checks=[self.check("tags.foo", "doo"), self.check("name", "{name}")], + ) + self.cmd( + "aosm update -g {rg} -n {name} --tags foo=boo", + checks=[self.check("tags.foo", "boo")], + ) + count = len(self.cmd("aosm list").get_output_in_json()) + self.cmd( + "aosm show - {rg} -n {name}", + checks=[ + self.check("name", "{name}"), + self.check("resourceGroup", "{rg}"), + self.check("tags.foo", "boo"), + ], + ) + self.cmd("aosm delete -g {rg} -n {name}") + final_count = len(self.cmd("aosm list").get_output_in_json()) self.assertTrue(final_count, count - 1) diff --git a/src/aosm/azext_aosm/_constants.py b/src/aosm/azext_aosm/util/constants.py similarity index 69% rename from src/aosm/azext_aosm/_constants.py rename to src/aosm/azext_aosm/util/constants.py index 42db56a3e3e..45561b5a719 100644 --- a/src/aosm/azext_aosm/_constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -9,6 +9,7 @@ CNF = "cnf" NSD = "nsd" -# Artifact Types -VHD_ARTIFACT = "VhdImageFile" -ARM_TEMPLATE_ARTIFACT = "ArmTemplate" +# Names of files used in the repo +VNF_DEFINITION_BICEP_SOURCE_TEMPLATE = "vnfdefinition.bicep" +VNF_MANIFEST_BICEP_SOURCE_TEMPLATE = "vnfartifactmanifests.bicep" +VNF_DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" diff --git a/src/aosm/azext_aosm/util/management_clients.py b/src/aosm/azext_aosm/util/management_clients.py new file mode 100644 index 00000000000..65ea9aa4afb --- /dev/null +++ b/src/aosm/azext_aosm/util/management_clients.py @@ -0,0 +1,24 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +"""Clients for the python SDK along with useful caches.""" + +from knack.log import get_logger +from azure.mgmt.resource import ResourceManagementClient +from azext_aosm.vendored_sdks import HybridNetworkManagementClient + +logger = get_logger(__name__) + + +class ApiClients: + """A class for API Clients needed throughout.""" + + def __init__( + self, + aosm_client: HybridNetworkManagementClient, + resource_client: ResourceManagementClient, + ): + """Initialise with clients.""" + self.aosm_client = aosm_client + self.resource_client = resource_client diff --git a/src/aosm/azext_aosm/util/utils.py b/src/aosm/azext_aosm/util/utils.py new file mode 100644 index 00000000000..93e42f28dd0 --- /dev/null +++ b/src/aosm/azext_aosm/util/utils.py @@ -0,0 +1,17 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +"""Utility functions.""" + + +def input_ack(ack: str, request_to_user: str) -> bool: + """ + Overarching function to request, sanitise and return True if input is specified ack. + + This prints the question string and asks for user input. which is santised by + removing all whitespaces in the string, and made lowercase. True is returned if the + user input is equal to supplied acknowledgement string and False if anything else + """ + unsanitised_ans = input(request_to_user) + return str(unsanitised_ans.strip().replace(" ", "").lower()) == ack diff --git a/src/aosm/setup.md b/src/aosm/setup.md new file mode 100644 index 00000000000..8e73437afa1 --- /dev/null +++ b/src/aosm/setup.md @@ -0,0 +1,51 @@ +### Prerequisites + +1. `python 3.8+` + + +### Dev environment setup + +Follow [https://github.com/Azure/azure-cli-dev-tools](https://github.com/Azure/azure-cli-dev-tools) + +Clone both azure-cli and azure-cli-extensions + +Note for azure-cli-extensions we are currently on a fork : https://github.com/jddarby/azure-cli-extensions +```bash +# Go into your git clone of az-cli-extensions +cd az-cli-extensions + +# Create a virtual environment to run in +python3.8 -m venv ~/.virtualenvs/az-cli-env +source ~/.virtualenvs/az-cli-env/bin/activate + +# Ensure you have pip +python -m pip install -U pip + +# Install azdev +pip install azdev + +# Install all the python dependencies you need +azdev setup --cli /home/developer/code/azure-cli --repo . + +# Add the extension to your local CLI +azdev extension add aosm +``` +### Generating the AOSM Python SDK +TODO + +### VSCode environment setup. + +Make sure your VSCode is running in the same python virtual environment + +### Linting and Tests +```bash +azdev style aosm +azdev linter --include-whl-extensions aosm +(Not written any tests yet) +azdev test aosm +``` +You can use python-static-checks in your dev environment if you want, to help you: +```bash +pip3 install -U --index-url https://pkgs.dev.azure.com/msazuredev/AzureForOperators/_packaging/python/pypi/simple/ python-static-checks==4.0.0 +python-static-checks fmt +``` diff --git a/src/aosm/setup.py b/src/aosm/setup.py index 83ecad46f31..a385f72b29c 100644 --- a/src/aosm/setup.py +++ b/src/aosm/setup.py @@ -8,51 +8,53 @@ from codecs import open from setuptools import setup, find_packages + try: from azure_bdist_wheel import cmdclass except ImportError: from distutils import log as logger + logger.warn("Wheel is not available, disabling bdist_wheel hook") # TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. -VERSION = '0.1.0' +VERSION = "0.1.0" # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers CLASSIFIERS = [ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'Intended Audience :: System Administrators', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'License :: OSI Approved :: MIT License', + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Intended Audience :: System Administrators", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "License :: OSI Approved :: MIT License", ] # TODO: Add any additional SDK dependencies here -DEPENDENCIES = [] +DEPENDENCIES = ["oras~=0.1.17", "azure-storage-blob>=12.15.0"] -with open('README.rst', 'r', encoding='utf-8') as f: +with open("README.md", "r", encoding="utf-8") as f: README = f.read() -with open('HISTORY.rst', 'r', encoding='utf-8') as f: +with open("HISTORY.rst", "r", encoding="utf-8") as f: HISTORY = f.read() setup( - name='aosm', + name="aosm", version=VERSION, - description='Microsoft Azure Command-Line Tools Aosm Extension', + description="Microsoft Azure Command-Line Tools Aosm Extension", # TODO: Update author and email, if applicable - author='Microsoft Corporation', - author_email='azpycli@microsoft.com', + author="Microsoft Corporation", + author_email="azpycli@microsoft.com", # TODO: change to your extension source code repo if the code will not be put in azure-cli-extensions repo - url='https://github.com/Azure/azure-cli-extensions/tree/master/src/aosm', - long_description=README + '\n\n' + HISTORY, - license='MIT', + url="https://github.com/Azure/azure-cli-extensions/tree/master/src/aosm", + long_description=README + "\n\n" + HISTORY, + license="MIT", classifiers=CLASSIFIERS, packages=find_packages(), install_requires=DEPENDENCIES, - package_data={'azext_aosm': ['azext_metadata.json']}, + package_data={"azext_aosm": ["azext_metadata.json"]}, ) From 9f2136ff0ffd8b5b9a17d557e1ab3989cd166bce Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 12 May 2023 17:02:28 +0100 Subject: [PATCH 039/145] tried a few functions --- .../generate_nfd/cnf_nfd_generator.py | 72 +++++++++++++------ 1 file changed, 52 insertions(+), 20 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index b712b565e62..280729d126c 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -36,6 +36,7 @@ def __init__(self, config: CNFConfiguration): self.artifacts = [] self.nf_applications = [] + # JORDAN: need to add the bit to schema before properties? self.deployment_parameter_schema = {} self._bicep_path = os.path.join( @@ -56,14 +57,15 @@ def generate_nfd(self): for helm_package in self.config.helm_packages: # Unpack the chart into the tmp folder print("HELMPACKAGE", helm_package) - # JORDAN: changes to pass in path to chart instead of whole package + # JORDAN: changes to pass in path to chart instead of whole package, check which way we want to do this self._extract_chart(helm_package['path_to_chart']) # Validate chart + # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) - self.get_chart_mapping_schema(helm_package) - # self.deployment_parameter_schema["properties"].update(self.get_chart_mapping_schema(helm_package.name)) - print("DS", self.deployment_parameter_schema) - # Add that schema to the big schema. + # + Add that schema to the big schema. + # Jordan: check if this should still be dict or if should be json by now? + self.deployment_parameter_schema["properties"] = self.get_chart_mapping_schema(helm_package) + # generate the NF application for the chart self.generate_nf_application(helm_package) # Workout the list of artifacts for the chart @@ -156,8 +158,8 @@ def generate_nf_application( (name, version) = self.get_chart_name_and_version(helm_package["path_to_chart"]) return { "artifactType": "HelmPackage", - "name": helm_package.name, - "dependsOnProfile": helm_package.depends_on, + "name": helm_package["name"], + "dependsOnProfile": helm_package["depends_on"], "artifactProfile": { "artifactStore": { "id": "[resourceId('Microsoft.HybridNetwork/publishers/artifactStores', parameters('publisherName'), parameters('acrArtifactStoreName'))]" @@ -179,7 +181,7 @@ def generate_nf_application( "releaseNamespace": name, "releaseName": name, "helmPackageVersion": version, - "values": self.generate_parmeter_mappings(), + "values": self.generate_parmeter_mappings(helm_package), }, }, } @@ -187,22 +189,37 @@ def generate_nf_application( def get_artifact_list(self, helm_package: HelmPackageConfig) -> List[Any]: pass - ## JORDAN DO THIS FIRST + ## JORDAN: this is done cheating by not actually looking at the schema def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, Any]: # We need to take the mappings from the values.nondef.yaml file and generate the schema # from the values.schema.json file. # Basically take the bits of the schema that are relevant to the parameters requested. non_def_values = helm_package['path_to_chart'] + "/values.nondef.yaml" - with open(non_def_values) as f: - data = yaml.load(f, Loader=yaml.FullLoader) - print(data) - chart = helm_package['path_to_chart'] + '/Chart.yaml' - values = helm_package['path_to_chart'] + '/values.json' - schema = helm_package['path_to_chart'] + '/values.schema.json' - # go through schema, find the properties - pass + with open(non_def_values, 'r') as stream: + data = yaml.load(stream, Loader=yaml.SafeLoader) + deploy_params_list = [] + params_for_schema = self.find_deploy_params(data, deploy_params_list) + + schema_dict = {} + for i in params_for_schema: + schema_dict[i] = {"type": "string", "description": "no descr"} + print(schema_dict) + return schema_dict + def find_deploy_params(self, nested_dict, deploy_params_list): + for k,v in nested_dict.items(): + if isinstance(v, str) and "deployParameters" in v: + # only add the parameter name (not deployParam. or anything after) + param = v.split(".",1)[1] + param = param.split('}', 1)[0] + deploy_params_list.append(param) + print(deploy_params_list) + elif hasattr(v, 'items'): #v is a dict + self.find_deploy_params(v, deploy_params_list) + + return deploy_params_list + ## Jordan DONE ## think we need to be careful what we are naming things here, we've passed it the path to chart not the helm package def get_chart_name_and_version( @@ -222,7 +239,22 @@ def some_fun_to_check_ragistry_and_image_secret_path(self): # Need to work out what we are doing here??? pass - ## JORDAN DO THIS 3rd - def generate_parmeter_mappings(self) -> str: + ## JORDAN talk to Jacob about ARM to bicep stuff + ## This is just experimenting, don't think this is returning correct format? + def generate_parmeter_mappings(self, helm_package: HelmPackageConfig) -> str: # Basically copy the values.nondef.yaml file to the right place. - pass + values = helm_package["path_to_chart"] + '/values.nondef.yaml' + with open(values) as f: + data = yaml.load(f, Loader=yaml.FullLoader) + with open('values.nondef.json', 'w') as file: + json.dump(data, file) + # values_json = json.dump(data, file) + + with open('values.nondef.json', 'r') as fi: + values_json = json.load(fi) + + return values_json + + # return "string(loadJsonContent('values.nondef.json')" + ## Note: if it was just bicep file, could return 'string(json....)' but because it is arm template to bicep we can't + # return "string(loadJsonContent('tmp/values.nondef.yaml'))" From da317e81b7cf8b0554ffee657a34435f8436d043 Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 15 May 2023 10:26:05 +0100 Subject: [PATCH 040/145] up to generate nf application --- src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 280729d126c..ed82312abb6 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -57,8 +57,10 @@ def generate_nfd(self): for helm_package in self.config.helm_packages: # Unpack the chart into the tmp folder print("HELMPACKAGE", helm_package) + helm_package = HelmPackageConfig(**helm_package) + print(type(helm_package)) # JORDAN: changes to pass in path to chart instead of whole package, check which way we want to do this - self._extract_chart(helm_package['path_to_chart']) + self._extract_chart(helm_package.path_to_chart) # Validate chart # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) @@ -181,6 +183,8 @@ def generate_nf_application( "releaseNamespace": name, "releaseName": name, "helmPackageVersion": version, + ## "values": "string(loadJsonContent('values.nondef.json')" + ## will process this after and will remove the "" so it will be valid "values": self.generate_parmeter_mappings(helm_package), }, }, From e1e8c67dd1b7a73409d80f52cf9bba888c70f76c Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 15 May 2023 10:49:14 +0100 Subject: [PATCH 041/145] tidied + fixed helmconfig as dict issue --- .../generate_nfd/cnf_nfd_generator.py | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index ed82312abb6..8f7eaeb1443 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -59,19 +59,20 @@ def generate_nfd(self): print("HELMPACKAGE", helm_package) helm_package = HelmPackageConfig(**helm_package) print(type(helm_package)) - # JORDAN: changes to pass in path to chart instead of whole package, check which way we want to do this + self._extract_chart(helm_package.path_to_chart) # Validate chart # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) # + Add that schema to the big schema. - # Jordan: check if this should still be dict or if should be json by now? self.deployment_parameter_schema["properties"] = self.get_chart_mapping_schema(helm_package) # generate the NF application for the chart self.generate_nf_application(helm_package) + # Workout the list of artifacts for the chart self.artifacts.append(self.get_artifact_list(helm_package.name)) + # Write NFD bicep self.write_nfd_bicep_file() # Write schema to schema/deploymentParameterSchema.json @@ -106,7 +107,7 @@ def _extract_chart(self, fname: str) -> None: tar = tarfile.open(fname, "r:") tar.extractall(path=self.tmp_folder_name) tar.close() - # JORDAN: avoiding tar extract errors + # JORDAN: avoiding tar extract errors, fix and remove later else: shutil.copytree(fname, self.tmp_folder_name, dirs_exist_ok=True) @@ -157,11 +158,11 @@ def write_arm_to_bicep(self, arm_template_dict: Dict[Any, Any], arm_file: str): def generate_nf_application( self, helm_package: HelmPackageConfig ) -> Dict[str, Any]: - (name, version) = self.get_chart_name_and_version(helm_package["path_to_chart"]) + (name, version) = self.get_chart_name_and_version(helm_package) return { "artifactType": "HelmPackage", - "name": helm_package["name"], - "dependsOnProfile": helm_package["depends_on"], + "name": helm_package.name, + "dependsOnProfile": helm_package.depends_on, "artifactProfile": { "artifactStore": { "id": "[resourceId('Microsoft.HybridNetwork/publishers/artifactStores', parameters('publisherName'), parameters('acrArtifactStoreName'))]" @@ -198,7 +199,7 @@ def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, # We need to take the mappings from the values.nondef.yaml file and generate the schema # from the values.schema.json file. # Basically take the bits of the schema that are relevant to the parameters requested. - non_def_values = helm_package['path_to_chart'] + "/values.nondef.yaml" + non_def_values = helm_package.path_to_chart + "/values.nondef.yaml" with open(non_def_values, 'r') as stream: data = yaml.load(stream, Loader=yaml.SafeLoader) @@ -211,6 +212,7 @@ def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, print(schema_dict) return schema_dict + ## JORDAN: change this to save the key and value that has deployParam in it so we can check the schema for the key def find_deploy_params(self, nested_dict, deploy_params_list): for k,v in nested_dict.items(): if isinstance(v, str) and "deployParameters" in v: @@ -224,13 +226,11 @@ def find_deploy_params(self, nested_dict, deploy_params_list): return deploy_params_list - ## Jordan DONE - ## think we need to be careful what we are naming things here, we've passed it the path to chart not the helm package def get_chart_name_and_version( - self, helm_package: Dict[Any, Any] + self, helm_package: HelmPackageConfig ) -> Tuple[str, str]: - # We need to get the chart name and version from the Chart.yaml file. - chart = helm_package + '/Chart.yaml' + + chart = helm_package.path_to_chart + '/Chart.yaml' with open(chart) as f: data = yaml.load(f, Loader=yaml.FullLoader) @@ -243,16 +243,14 @@ def some_fun_to_check_ragistry_and_image_secret_path(self): # Need to work out what we are doing here??? pass - ## JORDAN talk to Jacob about ARM to bicep stuff - ## This is just experimenting, don't think this is returning correct format? + ## JORDAN: change this to return string(loadJson).. with the file in output def generate_parmeter_mappings(self, helm_package: HelmPackageConfig) -> str: # Basically copy the values.nondef.yaml file to the right place. - values = helm_package["path_to_chart"] + '/values.nondef.yaml' + values = helm_package.path_to_chart + '/values.nondef.yaml' with open(values) as f: data = yaml.load(f, Loader=yaml.FullLoader) with open('values.nondef.json', 'w') as file: json.dump(data, file) - # values_json = json.dump(data, file) with open('values.nondef.json', 'r') as fi: values_json = json.load(fi) From 1eaa34fe94ad2182f5c43cde6ccb1dbc7fde3885 Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 15 May 2023 12:14:05 +0100 Subject: [PATCH 042/145] removed deploy with sdk --- src/aosm/azext_aosm/deploy/deploy_with_sdk.py | 188 ------------------ 1 file changed, 188 deletions(-) delete mode 100644 src/aosm/azext_aosm/deploy/deploy_with_sdk.py diff --git a/src/aosm/azext_aosm/deploy/deploy_with_sdk.py b/src/aosm/azext_aosm/deploy/deploy_with_sdk.py deleted file mode 100644 index 0715a4b4b32..00000000000 --- a/src/aosm/azext_aosm/deploy/deploy_with_sdk.py +++ /dev/null @@ -1,188 +0,0 @@ -# -------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT -# License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------- -"""Contains class for deploying generated definitions using the Python SDK.""" - -from knack.log import get_logger -from azure.mgmt.resource import ResourceManagementClient -from azext_aosm.vendored_sdks import HybridNetworkManagementClient -from azext_aosm.vendored_sdks.models import ( - NetworkFunctionDefinitionVersion, - NetworkServiceDesignVersion, - ArtifactStoreType, - ArtifactType, - ArtifactManifest, -) -from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK - - -logger = get_logger(__name__) - - -class DeployerViaSDK: - """A class to deploy Artifact Manifests, NFDs and NSDs using the python SDK.""" - - # @@@TODO - not sure this class is required as we can't publish complex objects - # using the SDK - - def __init__( - self, - aosm_client: HybridNetworkManagementClient, - resource_client: ResourceManagementClient, - ) -> None: - """ - Initializes a new instance of the Deployer class. - - :param aosm_client: The client to use for managing AOSM resources. - :type aosm_client: HybridNetworkManagementClient - :param resource_client: The client to use for managing Azure resources. - :type resource_client: ResourceManagementClient - """ - - self.aosm_client = aosm_client - self.resource_client = resource_client - self.pre_deployer = PreDeployerViaSDK(aosm_client, resource_client) - - def publish_artifact_manifest( - self, - resource_group_name: str, - location: str, - publisher_name: str, - artifact_store_name: str, - artifact_manifest: ArtifactManifest, - ) -> None: - """ - Publishes an artifact manifest. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param location: The location of the artifact manifest. - :type location: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param artifact_store_name: The name of the artifact store. - :type artifact_store_name: str - :param artifact_manifest: The artifact manifest. - :type artifact_manifest: ArtifactManifest - """ - - self.pre_deployer.ensure_publisher_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - location=location, - ) - - artifact_types = [a.artifact_type for a in artifact_manifest.artifacts] - - if ArtifactType.VHD_IMAGE_FILE or ArtifactType.IMAGE_FILE in artifact_types: - artifact_store_type = ArtifactStoreType.AZURE_STORAGE_ACCOUNT - else: - artifact_store_type = ArtifactStoreType.AZURE_CONTAINER_REGISTRY - - self.pre_deployer.ensure_artifact_store_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - artifact_store_name=artifact_store_name, - artifact_store_type=artifact_store_type, - location=location, - ) - - logger.info("Creating artifact manifest %s", artifact_manifest.name) - self.aosm_client.artifact_manifests.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - artifact_store_name=artifact_store_name, - artifact_manifest_name=artifact_manifest.name, - parameters=artifact_manifest, - ) - - def publish_network_function_definition_version( - self, - resource_group_name: str, - publisher_name: str, - location: str, - network_function_definition_group_name: str, - network_function_definition_version: NetworkFunctionDefinitionVersion, - ) -> None: - """ - Publishes a network function definition version. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param location: The location of the network function definition version. - :type location: str - :param network_function_definition_group_name: The name of the network function definition group. - :type network_function_definition_group_name: str - :param network_function_definition_version: The network function definition version. - :type network_function_definition_version: NetworkFunctionDefinitionVersion - """ - - self.pre_deployer.ensure_publisher_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - location=location, - ) - - self.pre_deployer.ensure_nfdg_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - nfdg_name=network_function_definition_group_name, - location=location, - ) - - logger.info("Publishing network function definition version") - self.aosm_client.network_function_definition_versions.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - network_function_definition_group_name=network_function_definition_group_name, - network_function_definition_version_name=network_function_definition_version.name, - parameters=network_function_definition_version, - ) - - def publish_network_service_design_version( - self, - resource_group_name: str, - publisher_name: str, - location: str, - network_service_design_group_name: str, - network_service_design_version: NetworkServiceDesignVersion, - ) -> None: - """ - Publishes a network service design version. - - :param resource_group_name: The name of the resource group. - :type resource_group_name: str - :param publisher_name: The name of the publisher. - :type publisher_name: str - :param location: The location of the network service design version. - :type location: str - :param network_service_design_group_name: The name of the network service design group. - :type network_service_design_group_name: str - :param network_service_design_version: The network service design version. - :type network_service_design_version: NetworkServiceDesignVersion - """ - - self.pre_deployer.ensure_publisher_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - location=location, - ) - - self.pre_deployer.ensure_nsdg_exists( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - nsdg_name=network_service_design_group_name, - location=location, - ) - - logger.info("Publishing network service design version") - self.aosm_client.network_service_design_versions.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - network_service_design_group_name=network_service_design_group_name, - network_service_design_version_name=network_service_design_version.name, - parameters=network_service_design_version, - ) From 21809b28767c050a6e73b03e3a60290d5149066d Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 16 May 2023 09:34:14 +0100 Subject: [PATCH 043/145] added artifact list --- .../generate_nfd/cnf_nfd_generator.py | 88 +++++++++++++------ 1 file changed, 63 insertions(+), 25 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 8f7eaeb1443..a8c3b212edd 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -5,6 +5,7 @@ """Contains a class for generating VNF NFDs and associated resources.""" import json import os +import re import shutil import subprocess import tarfile @@ -56,22 +57,21 @@ def generate_nfd(self): else: for helm_package in self.config.helm_packages: # Unpack the chart into the tmp folder - print("HELMPACKAGE", helm_package) helm_package = HelmPackageConfig(**helm_package) - print(type(helm_package)) - self._extract_chart(helm_package.path_to_chart) - # Validate chart + # Validate chartz # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) # + Add that schema to the big schema. self.deployment_parameter_schema["properties"] = self.get_chart_mapping_schema(helm_package) # generate the NF application for the chart - self.generate_nf_application(helm_package) - + self.nf_applications.append(self.generate_nf_application(helm_package)) # Workout the list of artifacts for the chart - self.artifacts.append(self.get_artifact_list(helm_package.name)) + self.artifacts += self.get_artifact_list(helm_package) + + with open('artifacts.json', 'w') as file: + json.dump(self.artifacts, file, indent=4) # Write NFD bicep self.write_nfd_bicep_file() @@ -184,23 +184,59 @@ def generate_nf_application( "releaseNamespace": name, "releaseName": name, "helmPackageVersion": version, - ## "values": "string(loadJsonContent('values.nondef.json')" ## will process this after and will remove the "" so it will be valid - "values": self.generate_parmeter_mappings(helm_package), + "values": f"string(loadJsonContent({self.generate_parmeter_mappings(helm_package)})", }, }, } def get_artifact_list(self, helm_package: HelmPackageConfig) -> List[Any]: - pass - + artifact_list = [] + (chart_name, chart_version) = self.get_chart_name_and_version(helm_package) + helm_artifact = { + "artifactName" : chart_name, + "artifactType" : "OCIArtifact", + "artifactVersion": chart_version + } + artifact_list.append(helm_artifact) + + image_versions = {} + path = os.path.join(self.tmp_folder_name, helm_package.name) + + for root, dirs, files in os.walk(path): + for filename in files: + if filename.endswith(".yaml") or filename.endswith(".yml"): + image_versions.update(self.find_images(os.path.join(root, filename))) + + for image_name,image_version in image_versions.items(): + artifact_list.append({ + "artifactName" : image_name, + "artifactType" : "OCIArtifact", + "artifactVersion": image_version + }) + + return artifact_list + + def find_images(self, filename): + image_versions = {} + with open(filename) as f: + image_matches = [re.search(r"/(.+):(.+)", line) for line in f if "image:" in line ] + + for match in image_matches: + if match and (match.group(1) not in image_versions): + version = re.sub('[^a-zA-Z0-9]+$', '', match.group(2)) + image_versions[match.group(1)] = version + + return image_versions + ## JORDAN: this is done cheating by not actually looking at the schema def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, Any]: # We need to take the mappings from the values.nondef.yaml file and generate the schema # from the values.schema.json file. # Basically take the bits of the schema that are relevant to the parameters requested. - non_def_values = helm_package.path_to_chart + "/values.nondef.yaml" + non_def_values = os.path.join(self.tmp_folder_name, helm_package.name, "values.nondef.yaml") + with open(non_def_values, 'r') as stream: data = yaml.load(stream, Loader=yaml.SafeLoader) deploy_params_list = [] @@ -209,7 +245,7 @@ def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, schema_dict = {} for i in params_for_schema: schema_dict[i] = {"type": "string", "description": "no descr"} - print(schema_dict) + return schema_dict ## JORDAN: change this to save the key and value that has deployParam in it so we can check the schema for the key @@ -230,7 +266,7 @@ def get_chart_name_and_version( self, helm_package: HelmPackageConfig ) -> Tuple[str, str]: - chart = helm_package.path_to_chart + '/Chart.yaml' + chart = os.path.join(self.tmp_folder_name, helm_package.name, "Chart.yaml") with open(chart) as f: data = yaml.load(f, Loader=yaml.FullLoader) @@ -246,17 +282,19 @@ def some_fun_to_check_ragistry_and_image_secret_path(self): ## JORDAN: change this to return string(loadJson).. with the file in output def generate_parmeter_mappings(self, helm_package: HelmPackageConfig) -> str: # Basically copy the values.nondef.yaml file to the right place. - values = helm_package.path_to_chart + '/values.nondef.yaml' + values = os.path.join(self.tmp_folder_name, helm_package.name, "values.nondef.yaml") + + mappings_folder_path = os.path.join(self.tmp_folder_name, "configMappings") + mappings_filename = f"{helm_package.name}-mappings.json" + if not os.path.exists(mappings_folder_path): + os.mkdir(mappings_folder_path) + + mapping_file_path = os.path.join(mappings_folder_path, mappings_filename) + with open(values) as f: data = yaml.load(f, Loader=yaml.FullLoader) - with open('values.nondef.json', 'w') as file: + + with open(mapping_file_path, 'w') as file: json.dump(data, file) - - with open('values.nondef.json', 'r') as fi: - values_json = json.load(fi) - - return values_json - - # return "string(loadJsonContent('values.nondef.json')" - ## Note: if it was just bicep file, could return 'string(json....)' but because it is arm template to bicep we can't - # return "string(loadJsonContent('tmp/values.nondef.yaml'))" + + return os.path.join("configMappings", mappings_filename) \ No newline at end of file From 89636e5ae0c3744be069f1d6effbf4522203044f Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Tue, 16 May 2023 11:00:43 +0100 Subject: [PATCH 044/145] push example cnf bicep --- .../templates/cnfdefinition.bicep | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep new file mode 100644 index 00000000000..b8f2cf98606 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep @@ -0,0 +1,81 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an NF definition for a VNF +param location string = resourceGroup().location +@description('Name of an existing publisher, expected to be in the resource group where you deploy the template') +param publisherName string +@description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') +param acrArtifactStoreName string +@description('Name of an existing Storage Account-backed Artifact Store, deployed under the publisher.') +param saArtifactStoreName string +@description('Name of an existing Network Function Definition Group') +param nfDefinitionGroup string +@description('The version of the NFDV you want to deploy, in format A-B-C') +param nfDefinitionVersion string +@description('The configuration of the network function applications') +param nfApplicationConfigurations array + +// Created by the az aosm definition publish command before the template is deployed +resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { + name: publisherName + scope: resourceGroup() +} + +// Created by the az aosm definition publish command before the template is deployed +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { + parent: publisher + name: acrArtifactStoreName +} + +// Created by the az aosm definition publish command before the template is deployed +resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-04-01-preview' existing = { + parent: publisher + name: saArtifactStoreName +} + +// Created by the az aosm definition publish command before the template is deployed +resource nfdg 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups@2023-04-01-preview' existing = { + parent: publisher + name: nfDefinitionGroup +} + +resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups/networkfunctiondefinitionversions@2023-04-01-preview' = { + parent: nfdg + name: nfDefinitionVersion + location: location + properties: { + // versionState should be changed to 'Active' once it is finalized. + versionState: 'Preview' + deployParameters: string(loadJsonContent('schemas/deploymentParameters.json')) + networkFunctionType: 'ContainerizedNetworkFunction' + networkFunctionTemplate: { + nfviType: 'AzureArcKubernetes' + networkFunctionApplications: [ for (application, index) in nfApplicationConfigurations: { + artifactType: 'HelmPackage' + name: application.name + dependsOnProfile: application.dependsOnProfile + artifactProfile: { + artifactStore: { + id: acrArtifactStore.id + } + helmArtifactProfile: { + helmPackageName: application.name + helmPackageVersionRange: application.name + registryValuesPaths: application.registryValuesPaths + imagePullSecretsValuesPaths: application.imagePullSecretsValuesPaths + } + } + deployParametersMappingRuleProfile: { + applicationEnablement: 'Enabled' + helmMappingRuleProfile: { + releaseNamespace: application.name + releaseName: application.name + helmPackageVersion: application.helmPackageVersion + values: string(loadFileAsBase64(nfApplicationConfigurations[index].valuesFilePath)) + } + } + } + ] + } + } +} From 715c9253baa21c656221c60289f5a86a1ce85a35 Mon Sep 17 00:00:00 2001 From: Chaos Date: Tue, 16 May 2023 11:24:33 +0100 Subject: [PATCH 045/145] Add temporary build workflow for AOSM extension (#4) * Add temporary build workflow for AOSM extension * Add Releaser to maintain a release with the latest build in a consistent place --- .github/workflows/BuildAOSMWheel.yml | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/BuildAOSMWheel.yml diff --git a/.github/workflows/BuildAOSMWheel.yml b/.github/workflows/BuildAOSMWheel.yml new file mode 100644 index 00000000000..36ad8f82bbb --- /dev/null +++ b/.github/workflows/BuildAOSMWheel.yml @@ -0,0 +1,31 @@ +on: + push: + branches: + - add-aosm-extension + +jobs: + build_aosm: + runs-on: ubuntu-latest + container: mcr.microsoft.com/azure-cli/tools:latest + permissions: write-all + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Build AOSM Wheel + run: | + # Pretend we have a valid git repo to satisfy azdev. + mkdir .git + azdev setup -r . + azdev extension build aosm + - name: Upload AOSM Wheel + uses: actions/upload-artifact@v3 + with: + name: aosm-extension + path: dist/*.whl + - name: Update Release + uses: pyTooling/Actions/releaser@r0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + files: | + dist/*.whl + tag: aosm-extension From 0f50403b7535c5b9d2c8db3a4d59d39663c030db Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 16 May 2023 13:56:07 +0100 Subject: [PATCH 046/145] added output dir; fixing getchartmappingschema --- .../generate_nfd/cnf_nfd_generator.py | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index a8c3b212edd..8b1ce1333c4 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -74,12 +74,19 @@ def generate_nfd(self): json.dump(self.artifacts, file, indent=4) # Write NFD bicep - self.write_nfd_bicep_file() + #' JRODAN: this needs to return the name of the file? so we can copy or we can just search for .bicep + nfd_bicep_file = self.write_nfd_bicep_file() # Write schema to schema/deploymentParameterSchema.json # Write Artifact Mainfest bicep # Copy contents of tmp folder to output folder. - + #JORDAN: check what files we def want: bicep, schema and mappings (deployParams and configMappings folders) + if not os.path.exists('output'): + os.mkdir('output') + nfd_bicep_path = os.path.join(self.tmp_folder_name,(nfd_bicep_file + '.bicep') ) + print(nfd_bicep_path) + shutil.copy(nfd_bicep_path, 'output') + # Delete tmp folder shutil.rmtree(self.tmp_folder_name) @@ -142,7 +149,9 @@ def write_nfd_bicep_file(self): ]["networkFunctionApplications"] = self.nf_applications self.write_arm_to_bicep(cnf_arm_template_dict, f"{self.tmp_folder_name}/{self.config.nf_name}-nfdv.json") - + + return f"{self.config.nf_name}-nfdv" + def write_arm_to_bicep(self, arm_template_dict: Dict[Any, Any], arm_file: str): with open(arm_file, 'w', encoding="UTF-8") as f: print("Writing ARM template to json file.") @@ -236,12 +245,19 @@ def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, # Basically take the bits of the schema that are relevant to the parameters requested. non_def_values = os.path.join(self.tmp_folder_name, helm_package.name, "values.nondef.yaml") - + values_schema = os.path.join(self.tmp_folder_name, helm_package.name, "values.schema.json") + with open(non_def_values, 'r') as stream: - data = yaml.load(stream, Loader=yaml.SafeLoader) - deploy_params_list = [] - params_for_schema = self.find_deploy_params(data, deploy_params_list) + values_data = yaml.load(stream, Loader=yaml.SafeLoader) + + with open(values_schema, 'r') as f: + data = json.load(f) + schema_data = data["properties"] + # print(schema_data) + deploy_params_list = [] + params_for_schema = self.find_deploy_params(values_data, schema_data, deploy_params_list, {}) + print("params", params_for_schema) schema_dict = {} for i in params_for_schema: schema_dict[i] = {"type": "string", "description": "no descr"} @@ -249,17 +265,25 @@ def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, return schema_dict ## JORDAN: change this to save the key and value that has deployParam in it so we can check the schema for the key - def find_deploy_params(self, nested_dict, deploy_params_list): + def find_deploy_params(self, nested_dict, schema_nested_dict, deploy_params_list, dict_path): for k,v in nested_dict.items(): + # #reset + # dict_path = {} + test = {} if isinstance(v, str) and "deployParameters" in v: # only add the parameter name (not deployParam. or anything after) param = v.split(".",1)[1] param = param.split('}', 1)[0] + # dict_path[k] = param + ## identify the zone param deploy_params_list.append(param) + test[k] = param print(deploy_params_list) + print(test) elif hasattr(v, 'items'): #v is a dict - self.find_deploy_params(v, deploy_params_list) - + # dict_path[k] = {} + self.find_deploy_params(v, deploy_params_list, dict_path) + # print("dict", dict_path) return deploy_params_list def get_chart_name_and_version( @@ -279,7 +303,6 @@ def some_fun_to_check_ragistry_and_image_secret_path(self): # Need to work out what we are doing here??? pass - ## JORDAN: change this to return string(loadJson).. with the file in output def generate_parmeter_mappings(self, helm_package: HelmPackageConfig) -> str: # Basically copy the values.nondef.yaml file to the right place. values = os.path.join(self.tmp_folder_name, helm_package.name, "values.nondef.yaml") From f92435c13f53c1c37da70a4dbc87e30090d9628e Mon Sep 17 00:00:00 2001 From: Chaos Chhapi Date: Tue, 16 May 2023 14:48:32 +0100 Subject: [PATCH 047/145] Add empty init files to inner modules so setuptools recognises them as modules --- src/aosm/azext_aosm/delete/__init__.py | 5 +++++ src/aosm/azext_aosm/deploy/__init__.py | 5 +++++ src/aosm/azext_aosm/generate_nfd/__init__.py | 5 +++++ src/aosm/azext_aosm/util/__init__.py | 5 +++++ 4 files changed, 20 insertions(+) create mode 100644 src/aosm/azext_aosm/delete/__init__.py create mode 100644 src/aosm/azext_aosm/deploy/__init__.py create mode 100644 src/aosm/azext_aosm/generate_nfd/__init__.py create mode 100644 src/aosm/azext_aosm/util/__init__.py diff --git a/src/aosm/azext_aosm/delete/__init__.py b/src/aosm/azext_aosm/delete/__init__.py new file mode 100644 index 00000000000..99c0f28cd71 --- /dev/null +++ b/src/aosm/azext_aosm/delete/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- diff --git a/src/aosm/azext_aosm/deploy/__init__.py b/src/aosm/azext_aosm/deploy/__init__.py new file mode 100644 index 00000000000..99c0f28cd71 --- /dev/null +++ b/src/aosm/azext_aosm/deploy/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- diff --git a/src/aosm/azext_aosm/generate_nfd/__init__.py b/src/aosm/azext_aosm/generate_nfd/__init__.py new file mode 100644 index 00000000000..99c0f28cd71 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- diff --git a/src/aosm/azext_aosm/util/__init__.py b/src/aosm/azext_aosm/util/__init__.py new file mode 100644 index 00000000000..99c0f28cd71 --- /dev/null +++ b/src/aosm/azext_aosm/util/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- From 599ac388f05d617997ccbd7d4fb449bb13ab3226 Mon Sep 17 00:00:00 2001 From: Chaos Chhapi Date: Tue, 16 May 2023 16:26:44 +0100 Subject: [PATCH 048/145] Use latest RG model to remove unnecessary dependency on version --- src/aosm/azext_aosm/deploy/pre_deploy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index b00623ca9ea..affb6d30fdb 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -8,7 +8,7 @@ from azure.core import exceptions as azure_exceptions from azure.cli.core.azclierror import AzCLIError -from azure.mgmt.resource.resources.v2022_09_01.models import ResourceGroup +from azure.mgmt.resource.resources.models import ResourceGroup from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks.models import ( From 2efdba6639dbe50bdf8de7d5611dd5cdc5108ae9 Mon Sep 17 00:00:00 2001 From: Chaos Chhapi Date: Tue, 16 May 2023 17:50:14 +0100 Subject: [PATCH 049/145] Use latest deployment model to remove unnecessary dependency on version --- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index c825f48e705..a712f2eed42 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -13,7 +13,7 @@ from knack.log import get_logger from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator from azext_aosm.util.management_clients import ApiClients -from azure.mgmt.resource.resources.v2021_04_01.models import DeploymentExtended +from azure.mgmt.resource.resources.models import DeploymentExtended from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK from azext_aosm._configuration import NFConfiguration, VNFConfiguration From dfd5790ef2bc44cf8b029bf9fb610360f8bd88e0 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 17 May 2023 15:16:41 +0100 Subject: [PATCH 050/145] fixed parameter mappings + copied needed files to output folder --- .../generate_nfd/cnf_nfd_generator.py | 106 ++++++++++-------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 8b1ce1333c4..9a5468b4686 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -16,7 +16,7 @@ from knack.log import get_logger from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig from azext_aosm.util.constants import CNF_DEFINITION_BICEP_SOURCE_TEMPLATE - +from azure.cli.core.azclierror import InvalidTemplateError logger = get_logger(__name__) @@ -46,7 +46,8 @@ def __init__(self, config: CNFConfiguration): def generate_nfd(self): """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" - # Create tmp folder. + + # Create tmp folder. os.mkdir(self.tmp_folder_name) if self.bicep_path: @@ -67,26 +68,23 @@ def generate_nfd(self): # generate the NF application for the chart self.nf_applications.append(self.generate_nf_application(helm_package)) + # Workout the list of artifacts for the chart self.artifacts += self.get_artifact_list(helm_package) - with open('artifacts.json', 'w') as file: json.dump(self.artifacts, file, indent=4) # Write NFD bicep - #' JRODAN: this needs to return the name of the file? so we can copy or we can just search for .bicep nfd_bicep_file = self.write_nfd_bicep_file() + # Write schema to schema/deploymentParameterSchema.json + self.write_schema_to_file() + # Write Artifact Mainfest bicep # Copy contents of tmp folder to output folder. - #JORDAN: check what files we def want: bicep, schema and mappings (deployParams and configMappings folders) - if not os.path.exists('output'): - os.mkdir('output') - nfd_bicep_path = os.path.join(self.tmp_folder_name,(nfd_bicep_file + '.bicep') ) - print(nfd_bicep_path) - shutil.copy(nfd_bicep_path, 'output') - + self.copy_to_output_folder(nfd_bicep_file) + # Delete tmp folder shutil.rmtree(self.tmp_folder_name) @@ -105,7 +103,6 @@ def _extract_chart(self, fname: str) -> None: :param helm_package: The helm package to extract. :type helm_package: HelmPackageConfig """ - print("fname", fname) if fname.endswith("tar.gz") or fname.endswith("tgz"): tar = tarfile.open(fname, "r:gz") tar.extractall(path=self.tmp_folder_name) @@ -136,6 +133,27 @@ def _create_nfd_folder(self) -> None: logger.info("Create NFD bicep %s", self.output_folder_name) os.mkdir(self.output_folder_name) + def write_schema_to_file(self): + full_schema = os.path.join(self.tmp_folder_name, 'deploymentParameters.json') + with open(full_schema, 'w', encoding="UTF-8") as f: + print("Writing schema to json file.") + json.dump(self.deployment_parameter_schema, f, indent=4) + + def copy_to_output_folder(self, nfd_bicep_file): + + if not os.path.exists(self.output_folder_name): + os.mkdir(self.output_folder_name) + os.mkdir(self.output_folder_name + '/schemas') + + nfd_bicep_path = os.path.join(self.tmp_folder_name,(nfd_bicep_file + '.bicep') ) + shutil.copy(nfd_bicep_path, self.output_folder_name) + + config_mappings_path = os.path.join(self.tmp_folder_name,'configMappings' ) + shutil.copytree(config_mappings_path, self.output_folder_name + '/configMappings', dirs_exist_ok=True) + + full_schema = os.path.join(self.tmp_folder_name, 'deploymentParameters.json') + shutil.copy(full_schema, self.output_folder_name + '/schemas' + '/deploymentParameters.json') + def write_nfd_bicep_file(self): # This will write the bicep file for the NFD. code_dir = os.path.dirname(__file__) @@ -238,12 +256,7 @@ def find_images(self, filename): return image_versions - ## JORDAN: this is done cheating by not actually looking at the schema - def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, Any]: - # We need to take the mappings from the values.nondef.yaml file and generate the schema - # from the values.schema.json file. - # Basically take the bits of the schema that are relevant to the parameters requested. - + def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, Any]: non_def_values = os.path.join(self.tmp_folder_name, helm_package.name, "values.nondef.yaml") values_schema = os.path.join(self.tmp_folder_name, helm_package.name, "values.schema.json") @@ -253,38 +266,38 @@ def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, with open(values_schema, 'r') as f: data = json.load(f) schema_data = data["properties"] - # print(schema_data) - deploy_params_list = [] - params_for_schema = self.find_deploy_params(values_data, schema_data, deploy_params_list, {}) + + try: + final_schema = self.find_deploy_params(values_data, schema_data, {}) + except KeyError: + raise InvalidTemplateError(f"ERROR: Your schema and values for the helm package '{helm_package.name}' do not match. Please fix this and run the command again.") - print("params", params_for_schema) - schema_dict = {} - for i in params_for_schema: - schema_dict[i] = {"type": "string", "description": "no descr"} - - return schema_dict - - ## JORDAN: change this to save the key and value that has deployParam in it so we can check the schema for the key - def find_deploy_params(self, nested_dict, schema_nested_dict, deploy_params_list, dict_path): + return final_schema + + def find_deploy_params(self, nested_dict, schema_nested_dict, final_schema): + original_schema_nested_dict = schema_nested_dict for k,v in nested_dict.items(): - # #reset - # dict_path = {} - test = {} - if isinstance(v, str) and "deployParameters" in v: + # if value is a string and contains deployParameters. + if isinstance(v, str) and f"deployParameters." in v: # only add the parameter name (not deployParam. or anything after) param = v.split(".",1)[1] param = param.split('}', 1)[0] - # dict_path[k] = param - ## identify the zone param - deploy_params_list.append(param) - test[k] = param - print(deploy_params_list) - print(test) - elif hasattr(v, 'items'): #v is a dict - # dict_path[k] = {} - self.find_deploy_params(v, deploy_params_list, dict_path) - # print("dict", dict_path) - return deploy_params_list + # add the schema for k (from the big schema) to the (smaller) schema + final_schema.update({k :schema_nested_dict["properties"][k]}) + + # else if value is a (non-empty) dictionary (i.e another layer of nesting) + elif hasattr(v, 'items') and v.items(): + # handling schema having properties which doesn't map directly to the values file nesting + if "properties" in schema_nested_dict.keys(): + schema_nested_dict = schema_nested_dict["properties"][k] + else: + schema_nested_dict = schema_nested_dict[k] + # recursively call function with values (i.e the nested dictionary) + self.find_deploy_params(v, schema_nested_dict, final_schema) + # reset the schema dict to its original value (once finished with that level of recursion) + schema_nested_dict = original_schema_nested_dict + + return final_schema def get_chart_name_and_version( self, helm_package: HelmPackageConfig @@ -309,11 +322,12 @@ def generate_parmeter_mappings(self, helm_package: HelmPackageConfig) -> str: mappings_folder_path = os.path.join(self.tmp_folder_name, "configMappings") mappings_filename = f"{helm_package.name}-mappings.json" + if not os.path.exists(mappings_folder_path): os.mkdir(mappings_folder_path) mapping_file_path = os.path.join(mappings_folder_path, mappings_filename) - + with open(values) as f: data = yaml.load(f, Loader=yaml.FullLoader) From 4747224e2fd201ef6012b4495e96d3ede1b9575c Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Wed, 17 May 2023 16:27:40 +0100 Subject: [PATCH 051/145] jinja2 and find value paths --- .../generate_nfd/cnf_nfd_generator.py | 304 ++++++++++-------- .../templates/cnfartifactmanifest.bicep.j2 | 39 +++ ...efinition.bicep => cnfdefinition.bicep.j2} | 29 +- src/aosm/azext_aosm/util/constants.py | 8 +- src/aosm/setup.py | 2 +- 5 files changed, 234 insertions(+), 148 deletions(-) create mode 100644 src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 rename src/aosm/azext_aosm/generate_nfd/templates/{cnfdefinition.bicep => cnfdefinition.bicep.j2} (74%) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index a8c3b212edd..43e3b14aa99 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -7,15 +7,22 @@ import os import re import shutil -import subprocess import tarfile -from typing import Dict, List, Any, Tuple, Optional +from typing import Dict, List, Any, Tuple, Optional, Iterator import yaml from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator +from jinja2 import Template, StrictUndefined from knack.log import get_logger from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig -from azext_aosm.util.constants import CNF_DEFINITION_BICEP_SOURCE_TEMPLATE +from azext_aosm.util.constants import ( + CNF_DEFINITION_BICEP_TEMPLATE, + CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE, + CNF_MANIFEST_BICEP_TEMPLATE, + CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE, + IMAGE_LINE_REGEX, + IMAGE_PULL_SECRET_LINE_REGEX, +) logger = get_logger(__name__) @@ -31,17 +38,18 @@ class CnfNfdGenerator(NFDGenerator): def __init__(self, config: CNFConfiguration): super(NFDGenerator, self).__init__() self.config = config - self.bicep_template_name = CNF_DEFINITION_BICEP_SOURCE_TEMPLATE + self.nfd_jinja2_template_path = os.path.join(os.path.dirname(__file__), "templates", CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE) + self.manifest_jinja2_template_path = os.path.join(os.path.dirname(__file__), "templates", CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE) self.output_folder_name = self.config.build_output_folder_name self.tmp_folder_name = "tmp" self.artifacts = [] - self.nf_applications = [] + self.nf_application_configurations = [] # JORDAN: need to add the bit to schema before properties? self.deployment_parameter_schema = {} self._bicep_path = os.path.join( - self.output_folder_name, self.bicep_template_name + self.output_folder_name, CNF_DEFINITION_BICEP_TEMPLATE ) def generate_nfd(self): @@ -56,32 +64,53 @@ def generate_nfd(self): ) else: for helm_package in self.config.helm_packages: - # Unpack the chart into the tmp folder + # Why are we having to do this??? helm_package = HelmPackageConfig(**helm_package) + # Unpack the chart into the tmp folder self._extract_chart(helm_package.path_to_chart) # Validate chartz - + # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) # + Add that schema to the big schema. - self.deployment_parameter_schema["properties"] = self.get_chart_mapping_schema(helm_package) + # self.deployment_parameter_schema[ + # "properties" + # ] = self.get_chart_mapping_schema(helm_package) + + # Get all image line matches for files in the chart. + image_line_matches = self.find_pattern_matches_in_chart( + helm_package, IMAGE_LINE_REGEX + ) + # Get all imagePullSecrets line matches for files in the chart. + image_pull_secret_line_matches = ( + self.find_pattern_matches_in_chart( + helm_package, IMAGE_PULL_SECRET_LINE_REGEX + ) + ) # generate the NF application for the chart - self.nf_applications.append(self.generate_nf_application(helm_package)) - # Workout the list of artifacts for the chart - self.artifacts += self.get_artifact_list(helm_package) - - with open('artifacts.json', 'w') as file: - json.dump(self.artifacts, file, indent=4) - + self.nf_application_configurations.append( + self.generate_nf_application_config( + helm_package, + image_line_matches, + image_pull_secret_line_matches, + ) + ) + # Workout the list of artifacts for the chart and + # update the list for the NFD + self.artifacts += self.get_artifact_list( + helm_package, set(image_line_matches) + ) + # Write NFD bicep self.write_nfd_bicep_file() # Write schema to schema/deploymentParameterSchema.json # Write Artifact Mainfest bicep + self.write__manifest_bicep_file() # Copy contents of tmp folder to output folder. # Delete tmp folder - shutil.rmtree(self.tmp_folder_name) + #shutil.rmtree(self.tmp_folder_name) @property def bicep_path(self) -> Optional[str]: @@ -107,7 +136,7 @@ def _extract_chart(self, fname: str) -> None: tar = tarfile.open(fname, "r:") tar.extractall(path=self.tmp_folder_name) tar.close() - # JORDAN: avoiding tar extract errors, fix and remove later + # JORDAN: avoiding tar extract errors, fix and remove later else: shutil.copytree(fname, self.tmp_folder_name, dirs_exist_ok=True) @@ -129,172 +158,181 @@ def _create_nfd_folder(self) -> None: logger.info("Create NFD bicep %s", self.output_folder_name) os.mkdir(self.output_folder_name) + def write__manifest_bicep_file(self): + # This will write the bicep file for the Artifact Manifest. + with open(self.manifest_jinja2_template_path, 'r', encoding='UTF-8') as f: + template: Template = Template( + f.read(), + undefined=StrictUndefined, + ) + + bicep_contents: str = template.render( + artifacts=self.artifacts, + ) + + path = os.path.join(self.tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE) + with open(path, "w", encoding="utf-8") as f: + f.write(bicep_contents) + def write_nfd_bicep_file(self): # This will write the bicep file for the NFD. - code_dir = os.path.dirname(__file__) - arm_template_path = os.path.join(code_dir, "templates/cnfdefinition.json") - - with open(arm_template_path, "r", encoding="UTF-8") as f: - cnf_arm_template_dict = json.load(f) - - cnf_arm_template_dict["resources"][0]["properties"][ - "networkFunctionTemplate" - ]["networkFunctionApplications"] = self.nf_applications - - self.write_arm_to_bicep(cnf_arm_template_dict, f"{self.tmp_folder_name}/{self.config.nf_name}-nfdv.json") - - def write_arm_to_bicep(self, arm_template_dict: Dict[Any, Any], arm_file: str): - with open(arm_file, 'w', encoding="UTF-8") as f: - print("Writing ARM template to json file.") - json.dump(arm_template_dict, f, indent=4) - try: - cmd = f"az bicep decompile --file {os.path.abspath(arm_file)} --only-show-errors" - subprocess.run(cmd, shell=True, check=True) - except subprocess.CalledProcessError as e: - raise e - finally: - os.remove(arm_file) - - def generate_nf_application( - self, helm_package: HelmPackageConfig + with open(self.nfd_jinja2_template_path, 'r', encoding='UTF-8') as f: + template: Template = Template( + f.read(), + undefined=StrictUndefined, + ) + + bicep_contents: str = template.render( + deployParametersPath="schema/deploymentParameterSchema.json", + nf_application_configurations=self.nf_application_configurations, + ) + + path = os.path.join(self.tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE) + with open(path, "w", encoding="utf-8") as f: + f.write(bicep_contents) + + def generate_nf_application_config( + self, + helm_package: HelmPackageConfig, + image_line_matches: List[Tuple[str, ...]], + image_pull_secret_line_matches: List[Tuple[str, ...]], ) -> Dict[str, Any]: (name, version) = self.get_chart_name_and_version(helm_package) + registryValuesPaths = set([m[0] for m in image_line_matches]) + imagePullSecretsValuesPaths = set(image_pull_secret_line_matches) + return { - "artifactType": "HelmPackage", "name": helm_package.name, + "chartName": name, + "chartVersion": version, "dependsOnProfile": helm_package.depends_on, - "artifactProfile": { - "artifactStore": { - "id": "[resourceId('Microsoft.HybridNetwork/publishers/artifactStores', parameters('publisherName'), parameters('acrArtifactStoreName'))]" - }, - "helmArtifactProfile": { - "helmPackageName": name, - "helmPackageVersionRange": version, - "registryValuesPaths": [ - "'global.registry.docker.repoPath'" - ], - "imagePullSecretsValuesPaths": [ - "'global.registry.docker.imagePullSecrets'" - ], - }, - }, - "deployParametersMappingRuleProfile": { - "applicationEnablement": "'Enabled'", - "helmMappingRuleProfile": { - "releaseNamespace": name, - "releaseName": name, - "helmPackageVersion": version, - ## will process this after and will remove the "" so it will be valid - "values": f"string(loadJsonContent({self.generate_parmeter_mappings(helm_package)})", - }, - }, + "registryValuesPaths": list(registryValuesPaths), + "imagePullSecretsValuesPaths": list(imagePullSecretsValuesPaths), + # "valueMappingsPath": self.generate_parmeter_mappings(helm_package), + "valueMappingsPath": "", } - def get_artifact_list(self, helm_package: HelmPackageConfig) -> List[Any]: + def _find_yaml_files(self, directory) -> Iterator[str]: + for root, dirs, files in os.walk(directory): + for file in files: + if file.endswith(".yaml") or file.endswith(".yml"): + yield os.path.join(root, file) + + def find_pattern_matches_in_chart( + self, helm_package: HelmPackageConfig, pattern: str + ) -> List[Tuple[str, ...]]: + chart_dir = os.path.join(self.tmp_folder_name, helm_package.name) + matches = [] + + for file in self._find_yaml_files(chart_dir): + with open(file, "r", encoding="UTF-8") as f: + contents = f.read() + matches += re.findall(pattern, contents) + + return matches + + def get_artifact_list( + self, + helm_package: HelmPackageConfig, + image_line_matches: List[Tuple[str, ...]], + ) -> List[Any]: artifact_list = [] - (chart_name, chart_version) = self.get_chart_name_and_version(helm_package) + (chart_name, chart_version) = self.get_chart_name_and_version( + helm_package + ) helm_artifact = { - "artifactName" : chart_name, - "artifactType" : "OCIArtifact", - "artifactVersion": chart_version + "name": chart_name, + "version": chart_version, } artifact_list.append(helm_artifact) - - image_versions = {} - path = os.path.join(self.tmp_folder_name, helm_package.name) - - for root, dirs, files in os.walk(path): - for filename in files: - if filename.endswith(".yaml") or filename.endswith(".yml"): - image_versions.update(self.find_images(os.path.join(root, filename))) - - for image_name,image_version in image_versions.items(): - artifact_list.append({ - "artifactName" : image_name, - "artifactType" : "OCIArtifact", - "artifactVersion": image_version - }) - + + for match in image_line_matches: + artifact_list.append( + { + "name": match[1], + "version": match[2], + } + ) + return artifact_list - - def find_images(self, filename): - image_versions = {} - with open(filename) as f: - image_matches = [re.search(r"/(.+):(.+)", line) for line in f if "image:" in line ] - - for match in image_matches: - if match and (match.group(1) not in image_versions): - version = re.sub('[^a-zA-Z0-9]+$', '', match.group(2)) - image_versions[match.group(1)] = version - - return image_versions - + ## JORDAN: this is done cheating by not actually looking at the schema - def get_chart_mapping_schema(self, helm_package: HelmPackageConfig) -> Dict[Any, Any]: + def get_chart_mapping_schema( + self, helm_package: HelmPackageConfig + ) -> Dict[Any, Any]: # We need to take the mappings from the values.nondef.yaml file and generate the schema # from the values.schema.json file. # Basically take the bits of the schema that are relevant to the parameters requested. - - non_def_values = os.path.join(self.tmp_folder_name, helm_package.name, "values.nondef.yaml") - with open(non_def_values, 'r') as stream: + non_def_values = os.path.join( + self.tmp_folder_name, helm_package.name, "values.nondef.yaml" + ) + + with open(non_def_values, "r") as stream: data = yaml.load(stream, Loader=yaml.SafeLoader) deploy_params_list = [] - params_for_schema = self.find_deploy_params(data, deploy_params_list) - + params_for_schema = self.find_deploy_params( + data, deploy_params_list + ) + schema_dict = {} for i in params_for_schema: schema_dict[i] = {"type": "string", "description": "no descr"} - + return schema_dict ## JORDAN: change this to save the key and value that has deployParam in it so we can check the schema for the key def find_deploy_params(self, nested_dict, deploy_params_list): - for k,v in nested_dict.items(): + for k, v in nested_dict.items(): if isinstance(v, str) and "deployParameters" in v: # only add the parameter name (not deployParam. or anything after) - param = v.split(".",1)[1] - param = param.split('}', 1)[0] + param = v.split(".", 1)[1] + param = param.split("}", 1)[0] deploy_params_list.append(param) print(deploy_params_list) - elif hasattr(v, 'items'): #v is a dict + elif hasattr(v, "items"): # v is a dict self.find_deploy_params(v, deploy_params_list) - + return deploy_params_list - + def get_chart_name_and_version( self, helm_package: HelmPackageConfig ) -> Tuple[str, str]: - - chart = os.path.join(self.tmp_folder_name, helm_package.name, "Chart.yaml") - + chart = os.path.join( + self.tmp_folder_name, helm_package.name, "Chart.yaml" + ) + with open(chart) as f: data = yaml.load(f, Loader=yaml.FullLoader) chart_name = data["name"] chart_version = data["version"] - - return (chart_name, chart_version) - def some_fun_to_check_ragistry_and_image_secret_path(self): - # Need to work out what we are doing here??? - pass + return (chart_name, chart_version) - ## JORDAN: change this to return string(loadJson).. with the file in output - def generate_parmeter_mappings(self, helm_package: HelmPackageConfig) -> str: + ## JORDAN: change this to return string(loadJson).. with the file in output + def generate_parmeter_mappings( + self, helm_package: HelmPackageConfig + ) -> str: # Basically copy the values.nondef.yaml file to the right place. - values = os.path.join(self.tmp_folder_name, helm_package.name, "values.nondef.yaml") - - mappings_folder_path = os.path.join(self.tmp_folder_name, "configMappings") + values = os.path.join( + self.tmp_folder_name, helm_package.name, "values.nondef.yaml" + ) + + mappings_folder_path = os.path.join( + self.tmp_folder_name, "configMappings" + ) mappings_filename = f"{helm_package.name}-mappings.json" if not os.path.exists(mappings_folder_path): os.mkdir(mappings_folder_path) - mapping_file_path = os.path.join(mappings_folder_path, mappings_filename) + mapping_file_path = os.path.join( + mappings_folder_path, mappings_filename + ) with open(values) as f: data = yaml.load(f, Loader=yaml.FullLoader) - with open(mapping_file_path, 'w') as file: + with open(mapping_file_path, "w") as file: json.dump(data, file) - return os.path.join("configMappings", mappings_filename) \ No newline at end of file + return os.path.join("configMappings", mappings_filename) diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 b/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 new file mode 100644 index 00000000000..35146795b59 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an NF definition for a VNF +param location string = resourceGroup().location +@description('Name of an existing publisher, expected to be in the resource group where you deploy the template') +param publisherName string +@description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') +param acrArtifactStoreName string +@description('Name of the manifest to deploy for the ACR-backed Artifact Store') +param acrManifestName string + +// Created by the az aosm definition publish command before the template is deployed +resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { + name: publisherName + scope: resourceGroup() +} + +// Created by the az aosm definition publish command before the template is deployed +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { + parent: publisher + name: acrArtifactStoreName +} + +resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { + parent: acrArtifactStore + name: acrManifestName + location: location + properties: { + artifacts: [ + {%- for artifact in artifacts %} + { + artifactName: '{{ artifact.name }}' + artifactType: 'OCIArtifact' + artifactVersion: '{{ artifact.version }}' + } + {%- endfor %} + ] + } +} diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 similarity index 74% rename from src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep rename to src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 index b8f2cf98606..a88fdb07bbb 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 @@ -46,36 +46,39 @@ resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroup properties: { // versionState should be changed to 'Active' once it is finalized. versionState: 'Preview' - deployParameters: string(loadJsonContent('schemas/deploymentParameters.json')) + deployParameters: string(loadJsonContent('{{ deployParametersPath }}')) networkFunctionType: 'ContainerizedNetworkFunction' networkFunctionTemplate: { nfviType: 'AzureArcKubernetes' - networkFunctionApplications: [ for (application, index) in nfApplicationConfigurations: { + networkFunctionApplications: [ + {%- for configuration in nf_application_configurations %} + { artifactType: 'HelmPackage' - name: application.name - dependsOnProfile: application.dependsOnProfile + name: '{{ configuration.name }}' + dependsOnProfile: {{ configuration.dependsOnProfile }} artifactProfile: { artifactStore: { id: acrArtifactStore.id } helmArtifactProfile: { - helmPackageName: application.name - helmPackageVersionRange: application.name - registryValuesPaths: application.registryValuesPaths - imagePullSecretsValuesPaths: application.imagePullSecretsValuesPaths + helmPackageName: '{{ configuration.chartName }}' + helmPackageVersionRange: '{{ configuration.chartVersion }}' + registryValuesPaths: {{ configuration.registryValuesPaths }} + imagePullSecretsValuesPaths: {{ configuration.imagePullSecretsValuesPaths }} } } deployParametersMappingRuleProfile: { applicationEnablement: 'Enabled' helmMappingRuleProfile: { - releaseNamespace: application.name - releaseName: application.name - helmPackageVersion: application.helmPackageVersion - values: string(loadFileAsBase64(nfApplicationConfigurations[index].valuesFilePath)) + releaseNamespace: '{{ configuration.chartName }}' + releaseName: '{{ configuration.chartName }}' + helmPackageVersion: '{{ configuration.chartVersion }}' + values: string(loadJsonContent('{{ configuration.valueMappingsPath }}')) } } } + {%- endfor %} ] } } -} +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index b33bd86218d..5100faad3e4 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -13,4 +13,10 @@ VNF_DEFINITION_BICEP_SOURCE_TEMPLATE = "vnfdefinition.bicep" VNF_MANIFEST_BICEP_SOURCE_TEMPLATE = "vnfartifactmanifests.bicep" VNF_DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" -CNF_DEFINITION_BICEP_SOURCE_TEMPLATE = "cnfdefinition.bicep" +CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE = "cnfdefinition.bicep.j2" +CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE = "cnfartifactmanifest.bicep.j2" +CNF_DEFINITION_BICEP_TEMPLATE = "cnfdefinition.bicep" +CNF_MANIFEST_BICEP_TEMPLATE = "cnfartifactmanifest.bicep" + +IMAGE_LINE_REGEX = r"image: \{\{ .Values.(.+?) \}\}/(.+?):(\d+\.\d+\.\d+(-\w+)?(\.\d+)?)" +IMAGE_PULL_SECRET_LINE_REGEX = r"imagePullSecrets: \[name: \{\{ .Values.(.+?) \}\}\]" diff --git a/src/aosm/setup.py b/src/aosm/setup.py index a385f72b29c..873894c392d 100644 --- a/src/aosm/setup.py +++ b/src/aosm/setup.py @@ -35,7 +35,7 @@ ] # TODO: Add any additional SDK dependencies here -DEPENDENCIES = ["oras~=0.1.17", "azure-storage-blob>=12.15.0"] +DEPENDENCIES = ["oras~=0.1.17", "azure-storage-blob>=12.15.0", "jinja2>=3.1.2"] with open("README.md", "r", encoding="utf-8") as f: README = f.read() From 3188399cbc0c58f1c26a34de7d6c835d5d1ddfb8 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 17 May 2023 16:58:45 +0100 Subject: [PATCH 052/145] fixed typos + self.aritfacts only has unique artifacts --- src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index b7166940446..bce20f485e8 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -109,10 +109,11 @@ def generate_nfd(self): ) # Workout the list of artifacts for the chart and # update the list for the NFD - self.artifacts += self.get_artifact_list( + chart_artifacts = self.get_artifact_list( helm_package, set(image_line_matches) ) - + self.artifacts += [a for a in chart_artifacts if a not in self.artifacts] + # Write NFD bicep self.write_nfd_bicep_file() @@ -126,7 +127,7 @@ def generate_nfd(self): self.copy_to_output_folder() # Delete tmp folder - # shutil.rmtree(self.tmp_folder_name) + shutil.rmtree(self.tmp_folder_name) @property def bicep_path(self) -> Optional[str]: @@ -200,7 +201,7 @@ def write_nfd_bicep_file(self): ) bicep_contents: str = template.render( - deployParametersPath="schema/deploymentParameterSchema.json", + deployParametersPath="schemas/deploymentParameters.json", nf_application_configurations=self.nf_application_configurations, ) From 30921b80cd1069c461abc92be5ea2540cd2ee9ca Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Thu, 18 May 2023 08:59:03 +0100 Subject: [PATCH 053/145] use regex instead of string to find deploy params --- .../generate_nfd/cnf_nfd_generator.py | 70 +++++++------------ src/aosm/azext_aosm/util/constants.py | 1 + 2 files changed, 26 insertions(+), 45 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index bce20f485e8..69040d97fd8 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -14,14 +14,13 @@ from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from jinja2 import Template, StrictUndefined from knack.log import get_logger -from azext_aosm._configuration import ( - CNFConfiguration, HelmPackageConfig -) +from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig from azext_aosm.util.constants import ( CNF_DEFINITION_BICEP_TEMPLATE, CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE, CNF_MANIFEST_BICEP_TEMPLATE, CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE, + DEPLOYMENT_PARAMETER_MAPPING_REGEX, IMAGE_LINE_REGEX, IMAGE_PULL_SECRET_LINE_REGEX, ) @@ -39,6 +38,7 @@ class CnfNfdGenerator(NFDGenerator): """ def __init__(self, config: CNFConfiguration): + """Create a new VNF NFD Generator.""" super(NFDGenerator, self).__init__() self.config = config self.nfd_jinja2_template_path = os.path.join( @@ -56,16 +56,14 @@ def __init__(self, config: CNFConfiguration): self.artifacts = [] self.nf_application_configurations = [] - # JORDAN: need to add the bit to schema before properties? self.deployment_parameter_schema = {} self._bicep_path = os.path.join( self.output_folder_name, CNF_DEFINITION_BICEP_TEMPLATE ) - def generate_nfd(self): + def generate_nfd(self) -> None: """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" - # Create tmp folder. os.mkdir(self.tmp_folder_name) @@ -80,52 +78,37 @@ def generate_nfd(self): helm_package = HelmPackageConfig(**helm_package) # Unpack the chart into the tmp folder self._extract_chart(helm_package.path_to_chart) - # Validate chartz - # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) - # + Add that schema to the big schema. - # self.deployment_parameter_schema[ - # "properties" - # ] = self.get_chart_mapping_schema(helm_package) + # TODO: Validate charts # Get all image line matches for files in the chart. + # Do this here so we don't have to do it multiple times. image_line_matches = self.find_pattern_matches_in_chart( helm_package, IMAGE_LINE_REGEX ) - # Get all imagePullSecrets line matches for files in the chart. - image_pull_secret_line_matches = ( - self.find_pattern_matches_in_chart( - helm_package, IMAGE_PULL_SECRET_LINE_REGEX - ) - ) - - # generate the NF application for the chart + # Generate the NF application configuration for the chart self.nf_application_configurations.append( self.generate_nf_application_config( helm_package, image_line_matches, - image_pull_secret_line_matches, + self.find_pattern_matches_in_chart( + helm_package, IMAGE_PULL_SECRET_LINE_REGEX + ), ) ) # Workout the list of artifacts for the chart and - # update the list for the NFD + # update the list for the NFD with any unique artifacts. chart_artifacts = self.get_artifact_list( helm_package, set(image_line_matches) ) - self.artifacts += [a for a in chart_artifacts if a not in self.artifacts] - - # Write NFD bicep - self.write_nfd_bicep_file() + self.artifacts += [ + a for a in chart_artifacts if a not in self.artifacts + ] - # Write schema to schema/deploymentParameterSchema.json + self.write_nfd_bicep_file() self.write_schema_to_file() - - # Write Artifact Mainfest bicep self.write_manifest_bicep_file() - - # Copy contents of tmp folder to output folder. self.copy_to_output_folder() - # Delete tmp folder shutil.rmtree(self.tmp_folder_name) @@ -152,8 +135,8 @@ def _extract_chart(self, fname: str) -> None: tar = tarfile.open(fname, "r:") tar.extractall(path=self.tmp_folder_name) tar.close() - # JORDAN: avoiding tar extract errors, fix and remove later else: + # Throw error here shutil.copytree(fname, self.tmp_folder_name, dirs_exist_ok=True) def _create_nfd_folder(self) -> None: @@ -174,7 +157,7 @@ def _create_nfd_folder(self) -> None: logger.info("Create NFD bicep %s", self.output_folder_name) os.mkdir(self.output_folder_name) - def write_manifest_bicep_file(self): + def write_manifest_bicep_file(self) -> None: # This will write the bicep file for the Artifact Manifest. with open( self.manifest_jinja2_template_path, "r", encoding="UTF-8" @@ -192,7 +175,7 @@ def write_manifest_bicep_file(self): with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) - def write_nfd_bicep_file(self): + def write_nfd_bicep_file(self) -> None: # This will write the bicep file for the NFD. with open(self.nfd_jinja2_template_path, "r", encoding="UTF-8") as f: template: Template = Template( @@ -211,7 +194,7 @@ def write_nfd_bicep_file(self): with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) - def write_schema_to_file(self): + def write_schema_to_file(self) -> None: full_schema = os.path.join( self.tmp_folder_name, "deploymentParameters.json" ) @@ -219,7 +202,7 @@ def write_schema_to_file(self): print("Writing schema to json file.") json.dump(self.deployment_parameter_schema, f, indent=4) - def copy_to_output_folder(self): + def copy_to_output_folder(self) -> None: if not os.path.exists(self.output_folder_name): os.mkdir(self.output_folder_name) os.mkdir(self.output_folder_name + "/schemas") @@ -327,10 +310,10 @@ def get_chart_mapping_schema( self.tmp_folder_name, helm_package.name, "values.schema.json" ) - with open(non_def_values, "r", encoding='utf-8') as stream: + with open(non_def_values, "r", encoding="utf-8") as stream: values_data = yaml.load(stream, Loader=yaml.SafeLoader) - with open(values_schema, "r", encoding='utf-8') as f: + with open(values_schema, "r", encoding="utf-8") as f: data = json.load(f) schema_data = data["properties"] @@ -347,14 +330,11 @@ def get_chart_mapping_schema( def find_deploy_params( self, nested_dict, schema_nested_dict, final_schema - ): + ) -> Dict[Any, Any]: original_schema_nested_dict = schema_nested_dict for k, v in nested_dict.items(): # if value is a string and contains deployParameters. - if isinstance(v, str) and f"deployParameters." in v: - # only add the parameter name (not deployParam. or anything after) - param = v.split(".", 1)[1] - param = param.split("}", 1)[0] + if isinstance(v, str) and re.search(DEPLOYMENT_PARAMETER_MAPPING_REGEX, v): # add the schema for k (from the big schema) to the (smaller) schema final_schema.update({k: schema_nested_dict["properties"][k]}) @@ -379,7 +359,7 @@ def get_chart_name_and_version( self.tmp_folder_name, helm_package.name, "Chart.yaml" ) - with open(chart, 'r', encoding='utf-8') as f: + with open(chart, "r", encoding="utf-8") as f: data = yaml.load(f, Loader=yaml.FullLoader) chart_name = data["name"] chart_version = data["version"] diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 5100faad3e4..641fd252fbb 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -20,3 +20,4 @@ IMAGE_LINE_REGEX = r"image: \{\{ .Values.(.+?) \}\}/(.+?):(\d+\.\d+\.\d+(-\w+)?(\.\d+)?)" IMAGE_PULL_SECRET_LINE_REGEX = r"imagePullSecrets: \[name: \{\{ .Values.(.+?) \}\}\]" +DEPLOYMENT_PARAMETER_MAPPING_REGEX = r"\{deployParameters.(.+?)\}" From 3501b827fd4ac40488059b23ab004608d7c7f337 Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Thu, 18 May 2023 09:41:21 +0100 Subject: [PATCH 054/145] delete accidentaly commited input.json --- input.json | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 input.json diff --git a/input.json b/input.json deleted file mode 100644 index 26416a46b43..00000000000 --- a/input.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "publisher_name": "Name of the Publisher resource you want you definition published to", - "publisher_resource_group_name": "Resource group the Publisher resource is in or you want it to be in", - "nf_name": "Name of NF definition", - "version": "Version of the NF definition", - "acr_artifact_store_name": "Name of the ACR Artifact Store resource", - "location": "Azure location of the resources", - "helm_packages": [ - { - "name": "fed-elastic-jl", - "path_to_chart": "/home/developer/smf_charts_with_nondef/fed-elastic", - "depends_on": [ - "Names of the Helm packages this package depends on" - ] - }, - { - "name": "fed-crds-jl", - "path_to_chart": "/home/developer/smf_charts_with_nondef/fed-crds", - "depends_on": [ - "THIS HAS AN INCORRECT VALUES DEF SO WE COULD TRY TO TEST OUR VALIDATION ON IT?" - ] - }, - { - "name": "fed-jl", - "path_to_chart": "/home/developer/fed-istio", - "depends_on": [ - "Names of the Helm packages this package depends on" - ] - } - ] -} \ No newline at end of file From 7064890d1e97dcc3bc3cd4adbf3cb7d9f60f5313 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 18 May 2023 10:01:23 +0100 Subject: [PATCH 055/145] fixed deploy params; added indent to mapping file --- .../generate_nfd/cnf_nfd_generator.py | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 69040d97fd8..792c5370d04 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -56,7 +56,11 @@ def __init__(self, config: CNFConfiguration): self.artifacts = [] self.nf_application_configurations = [] - self.deployment_parameter_schema = {} + self.deployment_parameter_schema = { + "$schema": "https://json-schema.org/draft-07/schema#", + "title": "DeployParametersSchema", + "type": "object", + "properties": {}} self._bicep_path = os.path.join( self.output_folder_name, CNF_DEFINITION_BICEP_TEMPLATE @@ -81,11 +85,20 @@ def generate_nfd(self) -> None: # TODO: Validate charts + # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) + # + Add that schema to the big schema. + self.deployment_parameter_schema[ + "properties" + ] = self.get_chart_mapping_schema(helm_package) + # Get all image line matches for files in the chart. # Do this here so we don't have to do it multiple times. image_line_matches = self.find_pattern_matches_in_chart( helm_package, IMAGE_LINE_REGEX ) + + + # Generate the NF application configuration for the chart self.nf_application_configurations.append( self.generate_nf_application_config( @@ -199,9 +212,8 @@ def write_schema_to_file(self) -> None: self.tmp_folder_name, "deploymentParameters.json" ) with open(full_schema, "w", encoding="UTF-8") as f: - print("Writing schema to json file.") json.dump(self.deployment_parameter_schema, f, indent=4) - + def copy_to_output_folder(self) -> None: if not os.path.exists(self.output_folder_name): os.mkdir(self.output_folder_name) @@ -335,8 +347,13 @@ def find_deploy_params( for k, v in nested_dict.items(): # if value is a string and contains deployParameters. if isinstance(v, str) and re.search(DEPLOYMENT_PARAMETER_MAPPING_REGEX, v): + + # only add the parameter name (e.g. from {deployParameter.zone} only param = zone) + param = v.split(".", 1)[1] + param = param.split("}", 1)[0] + # add the schema for k (from the big schema) to the (smaller) schema - final_schema.update({k: schema_nested_dict["properties"][k]}) + final_schema.update({param: { "type" : schema_nested_dict["properties"][k]["type"]}}) # else if value is a (non-empty) dictionary (i.e another layer of nesting) elif hasattr(v, "items") and v.items(): @@ -390,6 +407,6 @@ def generate_parmeter_mappings( data = yaml.load(f, Loader=yaml.FullLoader) with open(mapping_file_path, "w", encoding="utf-8") as file: - json.dump(data, file) + json.dump(data, file, indent=4) return os.path.join("configMappings", mappings_filename) From 2604a71bafe2456e9a27c9beb34f22366ec58c0c Mon Sep 17 00:00:00 2001 From: Chaos Chhapi Date: Thu, 18 May 2023 14:16:55 +0100 Subject: [PATCH 056/145] Update readme with install/bug reporting instructions --- src/aosm/README.md | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/src/aosm/README.md b/src/aosm/README.md index 61c796677aa..1f9c265dc14 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -5,20 +5,48 @@ This package is for the 'aosm' extension to support Azure Operator Service Manag functions. i.e. `az aosm` -Install via `az extension add --name aosm` +# Background +The `az aosm` extension is intended to provide support for working with AOSM +resources and definitions. Currently it only implements commands which aid the +process of publishing Network Function Definitions and Network Service Designs to +use with Azure Operator Service Manager or Network Function Manager. -# Background -The `az aosm` extension provides support for publishing Network Function Definitions -to use with Azure Operator Service Manager or Network Function Manager. +# Installation + +Eventually the extension will be published through the usual process and it will be +installed as usual, via `az extension add --name aosm` + +Until then, the latest development version can be found here: +https://github.com/jddarby/azure-cli-extensions/releases/download/aosm-extension/aosm-0.1.0-py2.py3-none-any.whl + +To install, download this wheel and run: +`az extension add --source path/to/aosm-0.1.0-py2.py3-none-any.whl` + +# Bug Reporting + +Especially as this extension is still in development, you may encounter bugs or +usability issues as you try to use it in its current form. It would be much +appreciated if you could report these so that we're aware of them! + +The process for bug reporting is here: +https://eng.ms/docs/strategic-missions-and-technologies/strategic-missions-and-technologies-organization/azure-for-operators/aiops/aiops-orchestration/aosm-product-docs/processes/bug_process + +CLI issues should be tagged and triaged as UX bugs. + +# Definitions + +These commands help with the publishing of Network Function Definition and Network +Service Design resources. + +## Pre-requisites -# Pre-requisites -## VNFs +### VNFs For VNFs, you will need a single ARM template which would create the Azure resources for your VNF, for example a Virtual Machine, disks and NICs. You'll also need a VHD image that would be used for the VNF Virtual Machine. -# Command examples +## Command examples Get help on command arguments @@ -27,7 +55,7 @@ Get help on command arguments `az aosm definition build -h` etc... -All these commands take a `--definition-type` argument of `vnf`, `cnf` or (coming) `nsd` +All these commands take a `--definition-type` argument of `vnf`, `cnf` or `nsd` Create an example config file for building a definition From 961daad0a09a41fc8fa0fe6e36e50131995a9991 Mon Sep 17 00:00:00 2001 From: Chaos Chhapi Date: Thu, 18 May 2023 14:23:07 +0100 Subject: [PATCH 057/145] Adjust headers so rendered readme looks nicer --- src/aosm/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/aosm/README.md b/src/aosm/README.md index 1f9c265dc14..2ab56762713 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -1,18 +1,17 @@ # Microsoft Azure CLI 'aosm' Extension -========================================== This package is for the 'aosm' extension to support Azure Operator Service Manager functions. i.e. `az aosm` -# Background +## Background The `az aosm` extension is intended to provide support for working with AOSM resources and definitions. Currently it only implements commands which aid the process of publishing Network Function Definitions and Network Service Designs to use with Azure Operator Service Manager or Network Function Manager. -# Installation +## Installation Eventually the extension will be published through the usual process and it will be installed as usual, via `az extension add --name aosm` @@ -23,7 +22,7 @@ https://github.com/jddarby/azure-cli-extensions/releases/download/aosm-extension To install, download this wheel and run: `az extension add --source path/to/aosm-0.1.0-py2.py3-none-any.whl` -# Bug Reporting +## Bug Reporting Especially as this extension is still in development, you may encounter bugs or usability issues as you try to use it in its current form. It would be much @@ -34,19 +33,20 @@ https://eng.ms/docs/strategic-missions-and-technologies/strategic-missions-and-t CLI issues should be tagged and triaged as UX bugs. -# Definitions +## Definitions These commands help with the publishing of Network Function Definition and Network Service Design resources. -## Pre-requisites +### Pre-requisites + +#### VNFs -### VNFs For VNFs, you will need a single ARM template which would create the Azure resources for your VNF, for example a Virtual Machine, disks and NICs. You'll also need a VHD image that would be used for the VNF Virtual Machine. -## Command examples +### Command examples Get help on command arguments From 8274996eb293aa2bec37f1aed48deffc411bbae0 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 18 May 2023 14:24:03 +0100 Subject: [PATCH 058/145] renamed values.nondef + added cli errors --- .../azext_aosm/generate_nfd/cnf_nfd_generator.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 792c5370d04..1d4c2ad74d5 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -72,13 +72,13 @@ def generate_nfd(self) -> None: os.mkdir(self.tmp_folder_name) if self.bicep_path: - print(f"Using the existing NFD bicep template {self.bicep_path}.") - print( - f"To generate a new NFD, delete the folder {os.path.dirname(self.bicep_path)} and re-run this command." + shutil.rmtree(self.tmp_folder_name) + raise InvalidTemplateError( + f"ERROR: Using the existing NFD bicep template {self.bicep_path}.\nPlease fix this and run the command again." ) else: for helm_package in self.config.helm_packages: - # Why are we having to do this??? + # TO FIGURE OUT: Why are we having to do this??? helm_package = HelmPackageConfig(**helm_package) # Unpack the chart into the tmp folder self._extract_chart(helm_package.path_to_chart) @@ -97,8 +97,6 @@ def generate_nfd(self) -> None: helm_package, IMAGE_LINE_REGEX ) - - # Generate the NF application configuration for the chart self.nf_application_configurations.append( self.generate_nf_application_config( @@ -316,7 +314,7 @@ def get_chart_mapping_schema( self, helm_package: HelmPackageConfig ) -> Dict[Any, Any]: non_def_values = os.path.join( - self.tmp_folder_name, helm_package.name, "values.nondef.yaml" + self.tmp_folder_name, helm_package.name, "values.mappings.yaml" ) values_schema = os.path.join( self.tmp_folder_name, helm_package.name, "values.schema.json" @@ -386,9 +384,9 @@ def get_chart_name_and_version( def generate_parmeter_mappings( self, helm_package: HelmPackageConfig ) -> str: - # Basically copy the values.nondef.yaml file to the right place. + # Basically copy the values.mappings.yaml file to the right place. values = os.path.join( - self.tmp_folder_name, helm_package.name, "values.nondef.yaml" + self.tmp_folder_name, helm_package.name, "values.mappings.yaml" ) mappings_folder_path = os.path.join( From d4fbc163adc2f94ab19c3cf751b780d9a82685b3 Mon Sep 17 00:00:00 2001 From: Chaos Chhapi Date: Thu, 18 May 2023 14:27:55 +0100 Subject: [PATCH 059/145] Split help command example lines --- src/aosm/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aosm/README.md b/src/aosm/README.md index 2ab56762713..14a7dae974b 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -50,9 +50,9 @@ image that would be used for the VNF Virtual Machine. Get help on command arguments -`az aosm -h` -`az aosm definition -h` -`az aosm definition build -h` +`az aosm -h` +`az aosm definition -h` +`az aosm definition build -h` etc... All these commands take a `--definition-type` argument of `vnf`, `cnf` or `nsd` From 671fb6400a814580387d252138afeaeac4cb00b7 Mon Sep 17 00:00:00 2001 From: Chaos Chhapi Date: Thu, 18 May 2023 14:37:26 +0100 Subject: [PATCH 060/145] Clarify that bug process is internal --- src/aosm/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aosm/README.md b/src/aosm/README.md index 14a7dae974b..f502aa78f58 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -28,7 +28,7 @@ Especially as this extension is still in development, you may encounter bugs or usability issues as you try to use it in its current form. It would be much appreciated if you could report these so that we're aware of them! -The process for bug reporting is here: +The (Microsoft internal) process for bug reporting during development is here: https://eng.ms/docs/strategic-missions-and-technologies/strategic-missions-and-technologies-organization/azure-for-operators/aiops/aiops-orchestration/aosm-product-docs/processes/bug_process CLI issues should be tagged and triaged as UX bugs. From eb3c1a5456d75090bb28fe52ffa92e8d542f7b14 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 18 May 2023 14:44:25 +0100 Subject: [PATCH 061/145] fixed parameter vals not updating --- src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 1d4c2ad74d5..f6dcf5a75a9 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -89,7 +89,7 @@ def generate_nfd(self) -> None: # + Add that schema to the big schema. self.deployment_parameter_schema[ "properties" - ] = self.get_chart_mapping_schema(helm_package) + ].update(self.get_chart_mapping_schema(helm_package)) # Get all image line matches for files in the chart. # Do this here so we don't have to do it multiple times. @@ -349,7 +349,7 @@ def find_deploy_params( # only add the parameter name (e.g. from {deployParameter.zone} only param = zone) param = v.split(".", 1)[1] param = param.split("}", 1)[0] - + # add the schema for k (from the big schema) to the (smaller) schema final_schema.update({param: { "type" : schema_nested_dict["properties"][k]["type"]}}) From 1a29b43730450a283853e99be6bb6aa4fa702083 Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Thu, 18 May 2023 15:45:13 +0100 Subject: [PATCH 062/145] delete unuseed temoplate and update jinja2 templates --- .../templates/cnfartifactmanifest.bicep.j2 | 6 +-- .../templates/cnfdefinition.bicep.j2 | 14 +---- .../generate_nfd/templates/cnfdefinition.json | 51 ------------------- 3 files changed, 5 insertions(+), 66 deletions(-) delete mode 100644 src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.json diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 b/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 index 35146795b59..a68e8a2d5f9 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 @@ -10,18 +10,18 @@ param acrArtifactStoreName string param acrManifestName string // Created by the az aosm definition publish command before the template is deployed -resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { +resource publisher 'Microsoft.HybridNetwork/publishers@2023-04-01-preview' existing = { name: publisherName scope: resourceGroup() } // Created by the az aosm definition publish command before the template is deployed -resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-04-01-preview' existing = { parent: publisher name: acrArtifactStoreName } -resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { +resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2023-04-01-preview' = { parent: acrArtifactStore name: acrManifestName location: location diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 index a88fdb07bbb..c11312057df 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 @@ -6,33 +6,23 @@ param location string = resourceGroup().location param publisherName string @description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') param acrArtifactStoreName string -@description('Name of an existing Storage Account-backed Artifact Store, deployed under the publisher.') -param saArtifactStoreName string @description('Name of an existing Network Function Definition Group') param nfDefinitionGroup string @description('The version of the NFDV you want to deploy, in format A-B-C') param nfDefinitionVersion string -@description('The configuration of the network function applications') -param nfApplicationConfigurations array // Created by the az aosm definition publish command before the template is deployed -resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { +resource publisher 'Microsoft.HybridNetwork/publishers@2023-04-01-preview' existing = { name: publisherName scope: resourceGroup() } // Created by the az aosm definition publish command before the template is deployed -resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-04-01-preview' existing = { parent: publisher name: acrArtifactStoreName } -// Created by the az aosm definition publish command before the template is deployed -resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-04-01-preview' existing = { - parent: publisher - name: saArtifactStoreName -} - // Created by the az aosm definition publish command before the template is deployed resource nfdg 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups@2023-04-01-preview' existing = { parent: publisher diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.json b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.json deleted file mode 100644 index f73a4472e73..00000000000 --- a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.json +++ /dev/null @@ -1,51 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "location": { - "type": "string", - "defaultValue": "[resourceGroup().location]" - }, - "publisherName": { - "type": "string", - "metadata": { - "description": "Name of an existing publisher, expected to be in the resource group where you deploy the template" - } - }, - "acrArtifactStoreName": { - "type": "string", - "metadata": { - "description": "Name of an existing ACR-backed Artifact Store, deployed under the publisher." - } - }, - "nfDefinitionGroup": { - "type": "string", - "metadata": { - "description": "Name of an existing Network Function Definition Group" - } - }, - "nfDefinitionVersion": { - "type": "string", - "metadata": { - "description": "The version of the NFDV you want to deploy, in format A-B-C" - } - } - }, - "resources": [ - { - "type": "Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups/networkfunctiondefinitionversions", - "apiVersion": "2023-04-01-preview", - "name": "[format('{0}/{1}/{2}', parameters('publisherName'), parameters('nfDefinitionGroup'), parameters('nfDefinitionVersion'))]", - "location": "[parameters('location')]", - "properties": { - "versionState": "Preview", - "deployParameters": "string(loadJsonContent('schemas/deploymentParameters.json'))", - "networkFunctionType": "ContainerizedNetworkFunction", - "networkFunctionTemplate": { - "nfviType": "AzureArcKubernetes", - "networkFunctionApplications": [] - } - } - } - ] -} \ No newline at end of file From 6099b7a783d8e915f16908af4e95e60d75f71db0 Mon Sep 17 00:00:00 2001 From: jordlay <72226943+jordlay@users.noreply.github.com> Date: Mon, 22 May 2023 13:50:35 +0100 Subject: [PATCH 063/145] Update README.md --- src/aosm/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/aosm/README.md b/src/aosm/README.md index f502aa78f58..0faf44bf684 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -22,6 +22,13 @@ https://github.com/jddarby/azure-cli-extensions/releases/download/aosm-extension To install, download this wheel and run: `az extension add --source path/to/aosm-0.1.0-py2.py3-none-any.whl` +## Updating + +We are currently not bumping versions, so if you would like the most up to date version of the CLI. You should run: +'az extension remove --name aosm' + +And then re-add with the new wheel, as detailed in Installation above. + ## Bug Reporting Especially as this extension is still in development, you may encounter bugs or From 3c52481127844900af6e60082f63e3667b759e4f Mon Sep 17 00:00:00 2001 From: jordlay <72226943+jordlay@users.noreply.github.com> Date: Mon, 22 May 2023 14:15:14 +0100 Subject: [PATCH 064/145] Update README.md --- src/aosm/README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/aosm/README.md b/src/aosm/README.md index 0faf44bf684..b8c13cbf599 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -53,6 +53,26 @@ For VNFs, you will need a single ARM template which would create the Azure resou for your VNF, for example a Virtual Machine, disks and NICs. You'll also need a VHD image that would be used for the VNF Virtual Machine. +#### CNFs + +For CNFs, you must provide helm packages with an associated schema. When filling in the input.json file, you must list helm packages in the order they are to be deployed. For example, if A must be deployed before B, your input.json should look something like this: + + "helm_packages": [ + { + "name": "A", + "path_to_chart": "Path to package A", + "depends_on": [ + "Names of the Helm packages this package depends on" + ] + }, + { + "name": "B", + "path_to_chart": "Path to package B", + "depends_on": [ + "Names of the Helm packages this package depends on" + ] + }, + ### Command examples Get help on command arguments @@ -66,7 +86,7 @@ All these commands take a `--definition-type` argument of `vnf`, `cnf` or `nsd` Create an example config file for building a definition -`az aosm definition generate-config --config-file input.json` +`az aosm definition generate-config` This will output a file called `input.json` which must be filled in. Once the config file has been filled in the following commands can be run. @@ -90,3 +110,5 @@ Delete a published definition Delete a published definition and the publisher, artifact stores and NFD group `az aosm definition delete --config-file input.json --clean` + + From 8c949052917503ea5d3e871757c68d195fbf360a Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 22 May 2023 15:26:08 +0100 Subject: [PATCH 065/145] added docstrings; added basic error catching with file handling --- .../generate_nfd/cnf_nfd_generator.py | 142 ++++++++++-------- 1 file changed, 80 insertions(+), 62 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index f6dcf5a75a9..85b51d6c802 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- -"""Contains a class for generating VNF NFDs and associated resources.""" +"""Contains a class for generating CNF NFDs and associated resources.""" import json import os import re @@ -38,7 +38,7 @@ class CnfNfdGenerator(NFDGenerator): """ def __init__(self, config: CNFConfiguration): - """Create a new VNF NFD Generator.""" + """Create a new CNF NFD Generator.""" super(NFDGenerator, self).__init__() self.config = config self.nfd_jinja2_template_path = os.path.join( @@ -60,14 +60,15 @@ def __init__(self, config: CNFConfiguration): "$schema": "https://json-schema.org/draft-07/schema#", "title": "DeployParametersSchema", "type": "object", - "properties": {}} + "properties": {}, + } self._bicep_path = os.path.join( self.output_folder_name, CNF_DEFINITION_BICEP_TEMPLATE ) def generate_nfd(self) -> None: - """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" + """Generate a CNF NFD which comprises a group, an Artifact Manifest and an NFDV.""" # Create tmp folder. os.mkdir(self.tmp_folder_name) @@ -78,7 +79,7 @@ def generate_nfd(self) -> None: ) else: for helm_package in self.config.helm_packages: - # TO FIGURE OUT: Why are we having to do this??? + helm_package = HelmPackageConfig(**helm_package) # Unpack the chart into the tmp folder self._extract_chart(helm_package.path_to_chart) @@ -87,16 +88,16 @@ def generate_nfd(self) -> None: # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) # + Add that schema to the big schema. - self.deployment_parameter_schema[ - "properties" - ].update(self.get_chart_mapping_schema(helm_package)) - + self.deployment_parameter_schema["properties"].update( + self.get_chart_mapping_schema(helm_package) + ) + # Get all image line matches for files in the chart. # Do this here so we don't have to do it multiple times. image_line_matches = self.find_pattern_matches_in_chart( helm_package, IMAGE_LINE_REGEX ) - + # Generate the NF application configuration for the chart self.nf_application_configurations.append( self.generate_nf_application_config( @@ -135,8 +136,8 @@ def _extract_chart(self, fname: str) -> None: """ Extract the chart into the tmp folder. - :param helm_package: The helm package to extract. - :type helm_package: HelmPackageConfig + :param fname: The path to helm package + """ if fname.endswith("tar.gz") or fname.endswith("tgz"): tar = tarfile.open(fname, "r:gz") @@ -169,10 +170,8 @@ def _create_nfd_folder(self) -> None: os.mkdir(self.output_folder_name) def write_manifest_bicep_file(self) -> None: - # This will write the bicep file for the Artifact Manifest. - with open( - self.manifest_jinja2_template_path, "r", encoding="UTF-8" - ) as f: + """Write the bicep file for the Artifact Manifest.""" + with open(self.manifest_jinja2_template_path, "r", encoding="UTF-8") as f: template: Template = Template( f.read(), undefined=StrictUndefined, @@ -187,7 +186,7 @@ def write_manifest_bicep_file(self) -> None: f.write(bicep_contents) def write_nfd_bicep_file(self) -> None: - # This will write the bicep file for the NFD. + """Write the bicep file for the NFD.""" with open(self.nfd_jinja2_template_path, "r", encoding="UTF-8") as f: template: Template = Template( f.read(), @@ -199,20 +198,18 @@ def write_nfd_bicep_file(self) -> None: nf_application_configurations=self.nf_application_configurations, ) - path = os.path.join( - self.tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE - ) + path = os.path.join(self.tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE) with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) def write_schema_to_file(self) -> None: - full_schema = os.path.join( - self.tmp_folder_name, "deploymentParameters.json" - ) + """Write the schema to file deploymentParameters.json.""" + full_schema = os.path.join(self.tmp_folder_name, "deploymentParameters.json") with open(full_schema, "w", encoding="UTF-8") as f: json.dump(self.deployment_parameter_schema, f, indent=4) - + def copy_to_output_folder(self) -> None: + """Copy the config mappings, schema and bicep templates (artifact manifest and NFDV) to the output folder.""" if not os.path.exists(self.output_folder_name): os.mkdir(self.output_folder_name) os.mkdir(self.output_folder_name + "/schemas") @@ -227,23 +224,17 @@ def copy_to_output_folder(self) -> None: ) shutil.copy(manifest_bicep_path, self.output_folder_name) - config_mappings_path = os.path.join( - self.tmp_folder_name, "configMappings" - ) + config_mappings_path = os.path.join(self.tmp_folder_name, "configMappings") shutil.copytree( config_mappings_path, self.output_folder_name + "/configMappings", dirs_exist_ok=True, ) - full_schema = os.path.join( - self.tmp_folder_name, "deploymentParameters.json" - ) + full_schema = os.path.join(self.tmp_folder_name, "deploymentParameters.json") shutil.copy( full_schema, - self.output_folder_name - + "/schemas" - + "/deploymentParameters.json", + self.output_folder_name + "/schemas" + "/deploymentParameters.json", ) def generate_nf_application_config( @@ -255,7 +246,7 @@ def generate_nf_application_config( (name, version) = self.get_chart_name_and_version(helm_package) registryValuesPaths = set([m[0] for m in image_line_matches]) imagePullSecretsValuesPaths = set(image_pull_secret_line_matches) - + """Generate NF application config""" return { "name": helm_package.name, "chartName": name, @@ -267,6 +258,11 @@ def generate_nf_application_config( } def _find_yaml_files(self, directory) -> Iterator[str]: + """ + Find all yaml files in given directory. + + :param directory: The directory to search. + """ for root, dirs, files in os.walk(directory): for file in files: if file.endswith(".yaml") or file.endswith(".yml"): @@ -275,6 +271,11 @@ def _find_yaml_files(self, directory) -> Iterator[str]: def find_pattern_matches_in_chart( self, helm_package: HelmPackageConfig, pattern: str ) -> List[Tuple[str, ...]]: + """ + Find pattern matches in Helm chart, using provided REGEX pattern. + param helm_package: The helm package config. + param pattern: The regex pattern to match. + """ chart_dir = os.path.join(self.tmp_folder_name, helm_package.name) matches = [] @@ -290,10 +291,13 @@ def get_artifact_list( helm_package: HelmPackageConfig, image_line_matches: List[Tuple[str, ...]], ) -> List[Any]: + """ + Get the list of artifacts for the chart. + param helm_package: The helm package config. + param image_line_matches: The list of image line matches. + """ artifact_list = [] - (chart_name, chart_version) = self.get_chart_name_and_version( - helm_package - ) + (chart_name, chart_version) = self.get_chart_name_and_version(helm_package) helm_artifact = { "name": chart_name, "version": chart_version, @@ -313,25 +317,42 @@ def get_artifact_list( def get_chart_mapping_schema( self, helm_package: HelmPackageConfig ) -> Dict[Any, Any]: + """ + Get the schema for the non default values (those with {deploymentParameter...}). + Based on user provided values.schema.json. + + param helm_package: The helm package config. + """ non_def_values = os.path.join( self.tmp_folder_name, helm_package.name, "values.mappings.yaml" ) values_schema = os.path.join( self.tmp_folder_name, helm_package.name, "values.schema.json" ) - - with open(non_def_values, "r", encoding="utf-8") as stream: - values_data = yaml.load(stream, Loader=yaml.SafeLoader) - - with open(values_schema, "r", encoding="utf-8") as f: - data = json.load(f) - schema_data = data["properties"] - + try: - final_schema = self.find_deploy_params( - values_data, schema_data, {} + with open(non_def_values, "r", encoding="utf-8") as stream: + values_data = yaml.load(stream, Loader=yaml.SafeLoader) + except: + shutil.rmtree(self.tmp_folder_name) + raise InvalidTemplateError( + f"ERROR: There is no values.mappings.yaml file for the helm package '{helm_package.name}'. Please fix this and run the command again." + ) + + try: + with open(values_schema, "r", encoding="utf-8") as f: + data = json.load(f) + schema_data = data["properties"] + except: + shutil.rmtree(self.tmp_folder_name) + raise InvalidTemplateError( + f"ERROR: There is no values.schema.json file for the helm package '{helm_package.name}'. Please fix this and run the command again." ) + + try: + final_schema = self.find_deploy_params(values_data, schema_data, {}) except KeyError as e: + shutil.rmtree(self.tmp_folder_name) raise InvalidTemplateError( f"ERROR: Your schema and values for the helm package '{helm_package.name}' do not match. Please fix this and run the command again." ) from e @@ -341,17 +362,21 @@ def get_chart_mapping_schema( def find_deploy_params( self, nested_dict, schema_nested_dict, final_schema ) -> Dict[Any, Any]: + """ + Find the deploy parameters in the values.mappings.yaml file and add them to the schema. + """ original_schema_nested_dict = schema_nested_dict for k, v in nested_dict.items(): # if value is a string and contains deployParameters. if isinstance(v, str) and re.search(DEPLOYMENT_PARAMETER_MAPPING_REGEX, v): - # only add the parameter name (e.g. from {deployParameter.zone} only param = zone) param = v.split(".", 1)[1] param = param.split("}", 1)[0] # add the schema for k (from the big schema) to the (smaller) schema - final_schema.update({param: { "type" : schema_nested_dict["properties"][k]["type"]}}) + final_schema.update( + {param: {"type": schema_nested_dict["properties"][k]["type"]}} + ) # else if value is a (non-empty) dictionary (i.e another layer of nesting) elif hasattr(v, "items") and v.items(): @@ -370,9 +395,8 @@ def find_deploy_params( def get_chart_name_and_version( self, helm_package: HelmPackageConfig ) -> Tuple[str, str]: - chart = os.path.join( - self.tmp_folder_name, helm_package.name, "Chart.yaml" - ) + """Get the name and version of the chart.""" + chart = os.path.join(self.tmp_folder_name, helm_package.name, "Chart.yaml") with open(chart, "r", encoding="utf-8") as f: data = yaml.load(f, Loader=yaml.FullLoader) @@ -381,25 +405,19 @@ def get_chart_name_and_version( return (chart_name, chart_version) - def generate_parmeter_mappings( - self, helm_package: HelmPackageConfig - ) -> str: - # Basically copy the values.mappings.yaml file to the right place. + def generate_parmeter_mappings(self, helm_package: HelmPackageConfig) -> str: + """ Generate parameter mappings for the given helm package.""" values = os.path.join( self.tmp_folder_name, helm_package.name, "values.mappings.yaml" ) - mappings_folder_path = os.path.join( - self.tmp_folder_name, "configMappings" - ) + mappings_folder_path = os.path.join(self.tmp_folder_name, "configMappings") mappings_filename = f"{helm_package.name}-mappings.json" if not os.path.exists(mappings_folder_path): os.mkdir(mappings_folder_path) - mapping_file_path = os.path.join( - mappings_folder_path, mappings_filename - ) + mapping_file_path = os.path.join(mappings_folder_path, mappings_filename) with open(values, "r", encoding="utf-8") as f: data = yaml.load(f, Loader=yaml.FullLoader) From aa0b0614fa332152020f3cbef54c4cd77b3993a8 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 23 May 2023 13:51:28 +0100 Subject: [PATCH 066/145] small refactor of generate nfd --- src/aosm/azext_aosm/custom.py | 12 ++- .../generate_nfd/cnf_nfd_generator.py | 102 ++++++++---------- .../generate_nfd/vnf_bicep_nfd_generator.py | 15 +-- 3 files changed, 59 insertions(+), 70 deletions(-) diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 8a3f22198db..b7d7bce7097 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -4,6 +4,7 @@ # -------------------------------------------------------------------------------------------- import json +import os from dataclasses import asdict from typing import Optional from knack.log import get_logger @@ -21,6 +22,7 @@ get_configuration, NFConfiguration, ) +from azure.cli.core.azclierror import InvalidTemplateError, CLIInternalError logger = get_logger(__name__) @@ -104,13 +106,15 @@ def _generate_nfd(definition_type, config): elif definition_type == CNF: nfd_generator = CnfNfdGenerator(config) else: - from azure.cli.core.azclierror import CLIInternalError - raise CLIInternalError( "Generate NFD called for unrecognised definition_type. Only VNF and CNF have been implemented." ) - - nfd_generator.generate_nfd() + if nfd_generator.bicep_path: + raise InvalidTemplateError( + f"ERROR: Using the existing NFD bicep template {nfd_generator.bicep_path}.\nTo generate a new NFD, delete the folder {os.path.dirname(nfd_generator.bicep_path)} and re-run this command." + ) + else: + nfd_generator.generate_nfd() def publish_definition( diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 85b51d6c802..1598713e295 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -10,6 +10,7 @@ import tarfile from typing import Dict, List, Any, Tuple, Optional, Iterator +import tempfile import yaml from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from jinja2 import Template, StrictUndefined @@ -52,7 +53,6 @@ def __init__(self, config: CNFConfiguration): CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE, ) self.output_folder_name = self.config.build_output_folder_name - self.tmp_folder_name = "tmp" self.artifacts = [] self.nf_application_configurations = [] @@ -69,60 +69,55 @@ def __init__(self, config: CNFConfiguration): def generate_nfd(self) -> None: """Generate a CNF NFD which comprises a group, an Artifact Manifest and an NFDV.""" - # Create tmp folder. - os.mkdir(self.tmp_folder_name) - - if self.bicep_path: - shutil.rmtree(self.tmp_folder_name) - raise InvalidTemplateError( - f"ERROR: Using the existing NFD bicep template {self.bicep_path}.\nPlease fix this and run the command again." - ) - else: - for helm_package in self.config.helm_packages: - - helm_package = HelmPackageConfig(**helm_package) - # Unpack the chart into the tmp folder - self._extract_chart(helm_package.path_to_chart) - - # TODO: Validate charts - - # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) - # + Add that schema to the big schema. - self.deployment_parameter_schema["properties"].update( - self.get_chart_mapping_schema(helm_package) - ) - - # Get all image line matches for files in the chart. - # Do this here so we don't have to do it multiple times. - image_line_matches = self.find_pattern_matches_in_chart( - helm_package, IMAGE_LINE_REGEX - ) + + # Create temporary folder. + with tempfile.TemporaryDirectory() as tmpdirname: + self.tmp_folder_name = tmpdirname + try: + for helm_package in self.config.helm_packages: + + helm_package = HelmPackageConfig(**helm_package) + # Unpack the chart into the tmp folder + self._extract_chart(helm_package.path_to_chart) + + # TODO: Validate charts + + # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) + # + Add that schema to the big schema. + self.deployment_parameter_schema["properties"].update( + self.get_chart_mapping_schema(helm_package) + ) - # Generate the NF application configuration for the chart - self.nf_application_configurations.append( - self.generate_nf_application_config( - helm_package, - image_line_matches, - self.find_pattern_matches_in_chart( - helm_package, IMAGE_PULL_SECRET_LINE_REGEX - ), + # Get all image line matches for files in the chart. + # Do this here so we don't have to do it multiple times. + image_line_matches = self.find_pattern_matches_in_chart( + helm_package, IMAGE_LINE_REGEX ) - ) - # Workout the list of artifacts for the chart and - # update the list for the NFD with any unique artifacts. - chart_artifacts = self.get_artifact_list( - helm_package, set(image_line_matches) - ) - self.artifacts += [ - a for a in chart_artifacts if a not in self.artifacts - ] - self.write_nfd_bicep_file() - self.write_schema_to_file() - self.write_manifest_bicep_file() - self.copy_to_output_folder() - # Delete tmp folder - shutil.rmtree(self.tmp_folder_name) + # Generate the NF application configuration for the chart + self.nf_application_configurations.append( + self.generate_nf_application_config( + helm_package, + image_line_matches, + self.find_pattern_matches_in_chart( + helm_package, IMAGE_PULL_SECRET_LINE_REGEX + ), + ) + ) + # Workout the list of artifacts for the chart and + # update the list for the NFD with any unique artifacts. + chart_artifacts = self.get_artifact_list( + helm_package, set(image_line_matches) + ) + self.artifacts += [ + a for a in chart_artifacts if a not in self.artifacts + ] + self.write_nfd_bicep_file() + self.write_schema_to_file() + self.write_manifest_bicep_file() + self.copy_to_output_folder() + except InvalidTemplateError as e: + raise e @property def bicep_path(self) -> Optional[str]: @@ -334,7 +329,6 @@ def get_chart_mapping_schema( with open(non_def_values, "r", encoding="utf-8") as stream: values_data = yaml.load(stream, Loader=yaml.SafeLoader) except: - shutil.rmtree(self.tmp_folder_name) raise InvalidTemplateError( f"ERROR: There is no values.mappings.yaml file for the helm package '{helm_package.name}'. Please fix this and run the command again." ) @@ -344,7 +338,6 @@ def get_chart_mapping_schema( data = json.load(f) schema_data = data["properties"] except: - shutil.rmtree(self.tmp_folder_name) raise InvalidTemplateError( f"ERROR: There is no values.schema.json file for the helm package '{helm_package.name}'. Please fix this and run the command again." ) @@ -352,7 +345,6 @@ def get_chart_mapping_schema( try: final_schema = self.find_deploy_params(values_data, schema_data, {}) except KeyError as e: - shutil.rmtree(self.tmp_folder_name) raise InvalidTemplateError( f"ERROR: Your schema and values for the helm package '{helm_package.name}' do not match. Please fix this and run the command again." ) from e diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 2b0768c6291..482a50b3c73 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -50,17 +50,10 @@ def __init__(self, config: VNFConfiguration): ) def generate_nfd(self) -> None: - """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" - if self.bicep_path: - print(f"Using the existing NFD bicep template {self.bicep_path}.") - print( - f"To generate a new NFD, delete the folder {os.path.dirname(self.bicep_path)} and re-run this command." - ) - else: - self.write() - - def write(self) -> None: - """Create a bicep template for an NFD from the ARM template for the VNF.""" + """ + Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. + Create a bicep template for an NFD from the ARM template for the VNF. + """ logger.info(f"Generate NFD bicep template for {self.arm_template_path}") print(f"Generate NFD bicep template for {self.arm_template_path}") From 9d15f95536d366773982c47afe2de5fa717f3c77 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 24 May 2023 09:13:09 +0100 Subject: [PATCH 067/145] fixed j2 template captions; added create_nfd to cnf; edited error messages; added deleting existing folder to custom.py --- src/aosm/azext_aosm/_configuration.py | 2 +- src/aosm/azext_aosm/custom.py | 17 +++++++--- .../generate_nfd/cnf_nfd_generator.py | 32 ++++++++----------- .../templates/cnfartifactmanifest.bicep.j2 | 2 +- .../templates/cnfdefinition.bicep.j2 | 2 +- .../generate_nfd/vnf_bicep_nfd_generator.py | 1 - 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index c02cfd59d5f..eafb91c0021 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -137,7 +137,7 @@ def build_output_folder_name(self) -> str: @dataclass class HelmPackageConfig: name: str = "Name of the Helm package" - path_to_chart: str = "Path to the Helm chart" + path_to_chart: str = "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz" depends_on: List[str] = field(default_factory=lambda: ["Names of the Helm packages this package depends on"]) @dataclass diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index b7d7bce7097..e182d85e521 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -5,6 +5,7 @@ import json import os +import shutil from dataclasses import asdict from typing import Optional from knack.log import get_logger @@ -110,12 +111,18 @@ def _generate_nfd(definition_type, config): "Generate NFD called for unrecognised definition_type. Only VNF and CNF have been implemented." ) if nfd_generator.bicep_path: - raise InvalidTemplateError( - f"ERROR: Using the existing NFD bicep template {nfd_generator.bicep_path}.\nTo generate a new NFD, delete the folder {os.path.dirname(nfd_generator.bicep_path)} and re-run this command." - ) - else: - nfd_generator.generate_nfd() + # raise InvalidTemplateError( + # f"ERROR: Using the existing NFD bicep template {nfd_generator.bicep_path}.\nTo generate a new NFD, delete the folder {os.path.dirname(nfd_generator.bicep_path)} and re-run this command." + # ) + carry_on = input( + f"The folder {os.path.dirname(nfd_generator.bicep_path)} already exists - delete it and continue? (y/n)" + ) + if carry_on != "y": + raise RuntimeError("User aborted!") + shutil.rmtree(os.path.dirname(nfd_generator.bicep_path)) + + nfd_generator.generate_nfd() def publish_definition( cmd, diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 1598713e295..0f085406c4c 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -69,7 +69,8 @@ def __init__(self, config: CNFConfiguration): def generate_nfd(self) -> None: """Generate a CNF NFD which comprises a group, an Artifact Manifest and an NFDV.""" - + # Create output folder + self._create_nfd_folder() # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: self.tmp_folder_name = tmpdirname @@ -116,6 +117,7 @@ def generate_nfd(self) -> None: self.write_schema_to_file() self.write_manifest_bicep_file() self.copy_to_output_folder() + print(f"Generated NFD bicep template created in {self.output_folder_name}") except InvalidTemplateError as e: raise e @@ -143,8 +145,7 @@ def _extract_chart(self, fname: str) -> None: tar.extractall(path=self.tmp_folder_name) tar.close() else: - # Throw error here - shutil.copytree(fname, self.tmp_folder_name, dirs_exist_ok=True) + raise InvalidTemplateError(f"ERROR: The helm package '{fname}' is not a .tgz, .tar or .tar.gz file. Please fix this and run the command again.") def _create_nfd_folder(self) -> None: """ @@ -249,7 +250,7 @@ def generate_nf_application_config( "dependsOnProfile": helm_package.depends_on, "registryValuesPaths": list(registryValuesPaths), "imagePullSecretsValuesPaths": list(imagePullSecretsValuesPaths), - "valueMappingsPath": self.generate_parmeter_mappings(helm_package), + "valueMappingsPath": self.generate_parameter_mappings(helm_package), } def _find_yaml_files(self, directory) -> Iterator[str]: @@ -314,7 +315,7 @@ def get_chart_mapping_schema( ) -> Dict[Any, Any]: """ Get the schema for the non default values (those with {deploymentParameter...}). - Based on user provided values.schema.json. + Based on user provided values.schema.json. param helm_package: The helm package config. """ @@ -325,22 +326,17 @@ def get_chart_mapping_schema( self.tmp_folder_name, helm_package.name, "values.schema.json" ) - try: - with open(non_def_values, "r", encoding="utf-8") as stream: - values_data = yaml.load(stream, Loader=yaml.SafeLoader) - except: + if not os.path.exists(non_def_values) or not os.path.exists(values_schema): raise InvalidTemplateError( - f"ERROR: There is no values.mappings.yaml file for the helm package '{helm_package.name}'. Please fix this and run the command again." + f"ERROR: The helm package '{helm_package.name}' is missing either values.mappings.yaml or values.schema.json. Please fix this and run the command again." ) - - try: + else: + with open(non_def_values, "r", encoding="utf-8") as stream: + values_data = yaml.load(stream, Loader=yaml.SafeLoader) + with open(values_schema, "r", encoding="utf-8") as f: data = json.load(f) schema_data = data["properties"] - except: - raise InvalidTemplateError( - f"ERROR: There is no values.schema.json file for the helm package '{helm_package.name}'. Please fix this and run the command again." - ) try: final_schema = self.find_deploy_params(values_data, schema_data, {}) @@ -397,12 +393,12 @@ def get_chart_name_and_version( return (chart_name, chart_version) - def generate_parmeter_mappings(self, helm_package: HelmPackageConfig) -> str: + def generate_parameter_mappings(self, helm_package: HelmPackageConfig) -> str: """ Generate parameter mappings for the given helm package.""" values = os.path.join( self.tmp_folder_name, helm_package.name, "values.mappings.yaml" ) - + mappings_folder_path = os.path.join(self.tmp_folder_name, "configMappings") mappings_filename = f"{helm_package.name}-mappings.json" diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 b/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 index a68e8a2d5f9..3027b2c25cf 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. -// This file creates an NF definition for a VNF +// This file creates an Artifact Manifest for a CNF param location string = resourceGroup().location @description('Name of an existing publisher, expected to be in the resource group where you deploy the template') param publisherName string diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 index c11312057df..0f57950481e 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. -// This file creates an NF definition for a VNF +// This file creates an NF definition for a CNF param location string = resourceGroup().location @description('Name of an existing publisher, expected to be in the resource group where you deploy the template') param publisherName string diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 482a50b3c73..d4e53714be2 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -52,7 +52,6 @@ def __init__(self, config: VNFConfiguration): def generate_nfd(self) -> None: """ Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. - Create a bicep template for an NFD from the ARM template for the VNF. """ logger.info(f"Generate NFD bicep template for {self.arm_template_path}") print(f"Generate NFD bicep template for {self.arm_template_path}") From 1853cba34bd40213864896792633534dffc080b3 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 24 May 2023 11:40:49 +0100 Subject: [PATCH 068/145] fixed file not found erroe --- src/aosm/azext_aosm/_configuration.py | 2 +- src/aosm/azext_aosm/custom.py | 4 ---- .../generate_nfd/cnf_nfd_generator.py | 20 +++++++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index eafb91c0021..79a0ecfc96b 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -138,7 +138,7 @@ def build_output_folder_name(self) -> str: class HelmPackageConfig: name: str = "Name of the Helm package" path_to_chart: str = "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz" - depends_on: List[str] = field(default_factory=lambda: ["Names of the Helm packages this package depends on"]) + depends_on: List[str] = field(default_factory=lambda: ["Names of the Helm packages this package depends on. Leave as an empty string if no dependencies"]) @dataclass class CNFConfiguration(NFConfiguration): diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index e182d85e521..1dc63d65b63 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -111,9 +111,6 @@ def _generate_nfd(definition_type, config): "Generate NFD called for unrecognised definition_type. Only VNF and CNF have been implemented." ) if nfd_generator.bicep_path: - # raise InvalidTemplateError( - # f"ERROR: Using the existing NFD bicep template {nfd_generator.bicep_path}.\nTo generate a new NFD, delete the folder {os.path.dirname(nfd_generator.bicep_path)} and re-run this command." - # ) carry_on = input( f"The folder {os.path.dirname(nfd_generator.bicep_path)} already exists - delete it and continue? (y/n)" ) @@ -121,7 +118,6 @@ def _generate_nfd(definition_type, config): raise RuntimeError("User aborted!") shutil.rmtree(os.path.dirname(nfd_generator.bicep_path)) - nfd_generator.generate_nfd() def publish_definition( diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 0f085406c4c..2d482ee53ca 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -71,6 +71,7 @@ def generate_nfd(self) -> None: """Generate a CNF NFD which comprises a group, an Artifact Manifest and an NFDV.""" # Create output folder self._create_nfd_folder() + # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: self.tmp_folder_name = tmpdirname @@ -153,14 +154,14 @@ def _create_nfd_folder(self) -> None: :raises RuntimeError: If the user aborts. """ - if os.path.exists(self.output_folder_name): - carry_on = input( - f"The folder {self.output_folder_name} already exists - delete it and continue? (y/n)" - ) - if carry_on != "y": - raise RuntimeError("User aborted!") + # if os.path.exists(self.output_folder_name): + # carry_on = input( + # f"The folder {self.output_folder_name} already exists - delete it and continue? (y/n)" + # ) + # if carry_on != "y": + # raise RuntimeError("User aborted!") - shutil.rmtree(self.output_folder_name) + # shutil.rmtree(self.output_folder_name) logger.info("Create NFD bicep %s", self.output_folder_name) os.mkdir(self.output_folder_name) @@ -206,9 +207,8 @@ def write_schema_to_file(self) -> None: def copy_to_output_folder(self) -> None: """Copy the config mappings, schema and bicep templates (artifact manifest and NFDV) to the output folder.""" - if not os.path.exists(self.output_folder_name): - os.mkdir(self.output_folder_name) - os.mkdir(self.output_folder_name + "/schemas") + + os.mkdir(self.output_folder_name + "/schemas") nfd_bicep_path = os.path.join( self.tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE From c6d6680f9c75e8d4ccfef3d5a731a5b2de657459 Mon Sep 17 00:00:00 2001 From: sunnycarter <36891339+sunnycarter@users.noreply.github.com> Date: Wed, 24 May 2023 11:54:32 +0100 Subject: [PATCH 069/145] Refactor commands to az aosm nfd|nsd build (#10) * Refactor commands to az aosm nfd|nsd build * setup.py version * Version was wrong * remove publish option from build * lint * wrong params --- src/aosm/HISTORY.rst | 10 +- src/aosm/README.md | 28 ++-- src/aosm/azext_aosm/_params.py | 24 ++-- src/aosm/azext_aosm/commands.py | 9 +- src/aosm/azext_aosm/custom.py | 126 +++++++++++++----- .../generate_nfd/vnf_bicep_nfd_generator.py | 7 +- src/aosm/setup.py | 2 +- 7 files changed, 141 insertions(+), 65 deletions(-) diff --git a/src/aosm/HISTORY.rst b/src/aosm/HISTORY.rst index 8c34bccfff8..e5bcecabf4b 100644 --- a/src/aosm/HISTORY.rst +++ b/src/aosm/HISTORY.rst @@ -3,6 +3,14 @@ Release History =============== +0.2.0 +++++++ +Breaking change to commands - now use `nfd` instead of `definition`. Publish option removed from build. +* `az aosm nfd generate-config` for vnf and cnf. This is for NFDVs +* `az aosm nfd build|publish|delete --definition-type vnf|cnf` for vnf and `build` only for cnf. This is for NFDVs + 0.1.0 ++++++ -* Initial release. \ No newline at end of file +* Initial release - alpha quality + * `az aosm definition generate-config` for vnf and cnf. This is for NFDVs + * `az aosm definition build|publish|delete` for vnf and `build` only for cnf. This is for NFDVs diff --git a/src/aosm/README.md b/src/aosm/README.md index b8c13cbf599..7cc02dce08f 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -17,10 +17,10 @@ Eventually the extension will be published through the usual process and it will installed as usual, via `az extension add --name aosm` Until then, the latest development version can be found here: -https://github.com/jddarby/azure-cli-extensions/releases/download/aosm-extension/aosm-0.1.0-py2.py3-none-any.whl +https://github.com/jddarby/azure-cli-extensions/releases/download/aosm-extension/aosm-0.2.0-py2.py3-none-any.whl To install, download this wheel and run: -`az extension add --source path/to/aosm-0.1.0-py2.py3-none-any.whl` +`az extension add --source path/to/aosm-0.2.0-py2.py3-none-any.whl` ## Updating @@ -77,38 +77,40 @@ For CNFs, you must provide helm packages with an associated schema. When filling Get help on command arguments -`az aosm -h` -`az aosm definition -h` -`az aosm definition build -h` +`az aosm -h` +`az aosm nfd -h` +`az aosm nfd build -h` etc... -All these commands take a `--definition-type` argument of `vnf`, `cnf` or `nsd` +All these commands take a `--definition-type` argument of `vnf` or `cnf` Create an example config file for building a definition -`az aosm definition generate-config` +`az aosm nfd generate-config` This will output a file called `input.json` which must be filled in. Once the config file has been filled in the following commands can be run. -Build a definition locally +Build an nfd definition locally -`az aosm definition build --config-file input.json` +`az aosm nfd build --config-file input.json` Build and publish a definition -`az aosm definition build --config-file input.json --publish` +`az aosm nfd build --config-file input.json --publish` Publish a pre-built definition -`az aosm definition publish --config-file input.json` +`az aosm nfd publish --config-file input.json` Delete a published definition -`az aosm definition delete --config-file input.json` +`az aosm nfd delete --config-file input.json` Delete a published definition and the publisher, artifact stores and NFD group -`az aosm definition delete --config-file input.json --clean` +`az aosm nfd delete --config-file input.json --clean` +Coming soon: +`az aosm nsd build` and further nsd commands. diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index 1b9bcf60651..2098f52876e 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -17,11 +17,11 @@ def load_arguments(self: AzCommandsLoader, _): get_three_state_flag, ) - definition_type = get_enum_type([VNF, CNF, NSD]) + definition_type = get_enum_type([VNF, CNF]) # Set the argument context so these options are only available when this specific command # is called. - with self.argument_context("aosm definition") as c: + with self.argument_context("aosm nfd") as c: c.argument( "definition_type", arg_type=definition_type, help="Type of AOSM definition." ) @@ -32,11 +32,6 @@ def load_arguments(self: AzCommandsLoader, _): completer=FilesCompleter(allowednames="*.json"), help="The path to the configuration file.", ) - c.argument( - "publish", - arg_type=get_three_state_flag(), - help="Publishes generated AOSM definition.", - ) c.argument( "clean", arg_type=get_three_state_flag(), @@ -71,9 +66,16 @@ def load_arguments(self: AzCommandsLoader, _): help="Optional path to a parameters file for the manifest definition file. Use to override publish of the built definition and config with alternative parameters.", ) - with self.argument_context("aosm generate-config") as c: + with self.argument_context("aosm nsd") as c: c.argument( - "definition_type", - arg_type=definition_type, - help="Type of AOSM definition config to generate.", + "config_file", + options_list=["--config-file", "-f"], + type=file_type, + completer=FilesCompleter(allowednames="*.json"), + help="The path to the configuration file.", + ) + c.argument( + "clean", + arg_type=get_three_state_flag(), + help="Also delete artifact stores, NFD Group and Publisher. Use with care.", ) diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index a25fcf9d2c4..8fd99d31c23 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -10,13 +10,18 @@ def load_command_table(self: AzCommandsLoader, _): - with self.command_group("aosm definition", client_factory=cf_aosm) as g: + with self.command_group("aosm nfd", client_factory=cf_aosm) as g: # Add each command and bind it to a function in custom.py g.custom_command("generate-config", "generate_definition_config") g.custom_command("build", "build_definition") g.custom_command("delete", "delete_published_definition") - g.custom_command("show", "show_publisher") g.custom_command("publish", "publish_definition") + with self.command_group("aosm nsd", client_factory=cf_aosm) as g: + # Add each command and bind it to a function in custom.py + g.custom_command("generate-config", "generate_design_config") + g.custom_command("build", "build_design") + g.custom_command("delete", "delete_published_design") + g.custom_command("publish", "publish_design") with self.command_group("aosm", is_preview=True): pass diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index b7d7bce7097..3e0731b571d 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -14,7 +14,7 @@ from azext_aosm.generate_nfd.vnf_bicep_nfd_generator import VnfBicepNfdGenerator from azext_aosm.delete.delete import ResourceDeleter from azext_aosm.deploy.deploy_with_arm import DeployerViaArm -from azext_aosm.util.constants import VNF, CNF # , NSD +from azext_aosm.util.constants import VNF, CNF, NSD from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks import HybridNetworkManagementClient from azext_aosm._client_factory import cf_resources @@ -28,43 +28,20 @@ logger = get_logger(__name__) -def build_definition( - cmd, - client: HybridNetworkManagementClient, - definition_type: str, - config_file: str, - publish=False, -): +def build_definition(cmd, definition_type: str, config_file: str): """ Build and optionally publish a definition. :param cmd: - :type cmd: _type_ - :param client: - :type client: HybridNetworkManagementClient :param config_file: path to the file - :param definition_type: VNF, CNF or NSD - :param publish: _description_, defaults to False - :type publish: bool, optional + :param definition_type: VNF or CNF """ - api_clients = ApiClients( - aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) - ) - # Read the config from the given file config = _get_config_from_file(config_file, definition_type) - # Generate the NFD/NSD and the artifact manifest. + # Generate the NFD and the artifact manifest. _generate_nfd(definition_type=definition_type, config=config) - # Publish the definition if publish is true - if publish: - if definition_type == VNF: - deployer = DeployerViaArm(api_clients, config=config) - deployer.deploy_vnfd_from_bicep() - else: - print("TODO - cannot publish CNF or NSD yet.") - def generate_definition_config(definition_type: str, output_file: str = "input.json"): """ @@ -74,13 +51,7 @@ def generate_definition_config(definition_type: str, output_file: str = "input.j :param output_file: path to output config file, defaults to "input.json" :type output_file: str, optional """ - config = get_configuration(definition_type) - config_as_dict = json.dumps(asdict(config), indent=4) - - with open(output_file, "w", encoding="utf-8") as f: - f.write(config_as_dict) - print(f"Empty definition configuration has been written to {output_file}") - logger.info(f"Empty definition configuration has been written to {output_file}") + _generate_config(definition_type, output_file) def _get_config_from_file(config_file: str, definition_type: str) -> NFConfiguration: @@ -160,6 +131,10 @@ def publish_definition( manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, ) + else: + raise NotImplementedError( + "Publishing of CNF definitions is not yet implemented." + ) def delete_published_definition( @@ -187,7 +162,86 @@ def delete_published_definition( delly = ResourceDeleter(api_clients, config) if definition_type == VNF: delly.delete_vnf(clean=clean) + else: + raise NotImplementedError( + "Deleting of published CNF definitions is not yet implemented." + ) + + +def generate_design_config(output_file: str = "input.json"): + """ + Generate an example config file for building a NSD. + + :param output_file: path to output config file, defaults to "input.json" + :type output_file: str, optional + """ + _generate_config(NSD, output_file) + +def _generate_config(definition_type: str, output_file: str = "input.json"): + """ + Generic generate config function for NFDs and NSDs. + + :param definition_type: CNF, VNF or NSD + :param output_file: path to output config file, defaults to "input.json" + :type output_file: str, optional + """ + config = get_configuration(definition_type) + config_as_dict = json.dumps(asdict(config), indent=4) -def show_publisher(): - pass + with open(output_file, "w", encoding="utf-8") as f: + f.write(config_as_dict) + if definition_type == CNF or definition_type == VNF: + prtName = "definition" + else: + prtName = "design" + print(f"Empty {prtName} configuration has been written to {output_file}") + logger.info(f"Empty {prtName} configuration has been written to {output_file}") + + +def build_design(cmd, client: HybridNetworkManagementClient, config_file: str): + """ + Build and optionally publish a Network Service Design. + + :param cmd: + :type cmd: _type_ + :param client: + :type client: HybridNetworkManagementClient + :param config_file: path to the file + """ + raise NotImplementedError("Build design is not yet implented for NSD") + + +def delete_published_design( + cmd, + client: HybridNetworkManagementClient, + config_file, + clean=False, +): + """ + Delete a published NSD. + + :param definition_type: CNF or VNF + :param config_file: Path to the config file + :param clean: if True, will delete the NFDG, artifact stores and publisher too. + Defaults to False. Only works if no resources have those as a parent. + Use with care. + """ + raise NotImplementedError("Delete published design is not yet implented for NSD") + + +def publish_design( + cmd, + client: HybridNetworkManagementClient, + config_file, +): + """ + Publish a generated design. + + :param cmd: + :param client: + :type client: HybridNetworkManagementClient + :param definition_type: VNF or CNF + :param config_file: Path to the config file for the NFDV + """ + raise NotImplementedError("Publishing design is not yet implemented for NSD") diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index 482a50b3c73..d3bab0a6a95 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -50,6 +50,7 @@ def __init__(self, config: VNFConfiguration): ) def generate_nfd(self) -> None: + """Create a bicep template for an NFD from the ARM template for the VNF.""" """ Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. Create a bicep template for an NFD from the ARM template for the VNF. @@ -60,7 +61,11 @@ def generate_nfd(self) -> None: self._create_nfd_folder() self.create_parameter_files() self.copy_bicep() - print(f"Generated NFD bicep template created in {self.folder_name}") + print(f"Generated NFD bicep templates created in {self.folder_name}") + print( + "Please review these templates. When you are happy with them run " + "`az aosm nfd publish` with the same arguments." + ) @property def bicep_path(self) -> Optional[str]: diff --git a/src/aosm/setup.py b/src/aosm/setup.py index 873894c392d..9cd195a21b2 100644 --- a/src/aosm/setup.py +++ b/src/aosm/setup.py @@ -18,7 +18,7 @@ # TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. -VERSION = "0.1.0" +VERSION = "0.2.0" # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers From 13c27cc87699006edcfaad61376aaa1f6e2e18f0 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 24 May 2023 12:24:55 +0100 Subject: [PATCH 070/145] fixed most style errors; ran static checks and azdev style --- src/aosm/azext_aosm/_configuration.py | 28 ++++++---- src/aosm/azext_aosm/custom.py | 55 +++++++++++++------ src/aosm/azext_aosm/delete/delete.py | 12 ++-- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 19 ++++--- src/aosm/azext_aosm/deploy/pre_deploy.py | 12 ++-- .../generate_nfd/cnf_nfd_generator.py | 52 ++++++++++-------- .../generate_nfd/vnf_bicep_nfd_generator.py | 4 +- src/aosm/azext_aosm/util/constants.py | 4 +- 8 files changed, 112 insertions(+), 74 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 79a0ecfc96b..29e7ef03e7a 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -9,8 +9,9 @@ "Resource group for the Publisher resource. Will be " "created if it does not exist." ), - "publisher_name": ("Name of the Publisher resource you want your definition " - "published to. Will be created if it does not exist." + "publisher_name": ( + "Name of the Publisher resource you want your definition " + "published to. Will be created if it does not exist." ), "nf_name": "Name of NF definition", "version": "Version of the NF definition", @@ -114,7 +115,7 @@ def validate(self) -> None: raise ValidationError( "Config validation error. VHD config must have either a local filepath or a blob SAS URL" ) - + if filepath_set: # Explicitly set the blob SAS URL to None to avoid other code having to # check if the value is the default description @@ -126,6 +127,7 @@ def validate(self) -> None: def sa_manifest_name(self) -> str: """Return the Storage account manifest name from the NFD name.""" return f"{self.nf_name}-sa-manifest-{self.version.replace('.', '-')}" + @property def build_output_folder_name(self) -> str: """Return the local folder for generating the bicep template to.""" @@ -134,11 +136,19 @@ def build_output_folder_name(self) -> str: f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" ) + @dataclass class HelmPackageConfig: name: str = "Name of the Helm package" - path_to_chart: str = "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz" - depends_on: List[str] = field(default_factory=lambda: ["Names of the Helm packages this package depends on. Leave as an empty string if no dependencies"]) + path_to_chart: str = ( + "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz" + ) + depends_on: List[str] = field( + default_factory=lambda: [ + "Names of the Helm packages this package depends on. Leave as an empty string if no dependencies" + ] + ) + @dataclass class CNFConfiguration(NFConfiguration): @@ -147,7 +157,7 @@ class CNFConfiguration(NFConfiguration): def __post_init__(self): """ Cope with deserializing subclasses from dicts to HelmPackageConfig. - + Used when creating CNFConfiguration object from a loaded json config file. """ for package in self.helm_packages: @@ -157,9 +167,8 @@ def __post_init__(self): @property def build_output_folder_name(self) -> str: """Return the local folder for generating the bicep template to.""" - return ( - f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}" - ) + return f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}" + def get_configuration( definition_type: str, config_as_dict: Optional[Dict[Any, Any]] = None @@ -179,4 +188,3 @@ def get_configuration( ) return config - diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 1dc63d65b63..40ff560ded0 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -9,6 +9,7 @@ from dataclasses import asdict from typing import Optional from knack.log import get_logger +from azure.cli.core.azclierror import CLIInternalError from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator @@ -23,7 +24,7 @@ get_configuration, NFConfiguration, ) -from azure.cli.core.azclierror import InvalidTemplateError, CLIInternalError + logger = get_logger(__name__) @@ -39,9 +40,12 @@ def build_definition( """ Build and optionally publish a definition. - :param cmd: + :param cmd: :type cmd: _type_ :param client: :type client: + HybridNetworkManagementClient :param config_ + file: + :param cmd: :type cmd: _type_ - :param client: + :param client: :type client: HybridNetworkManagementClient :param config_file: path to the file :param definition_type: VNF, CNF or NSD @@ -71,6 +75,9 @@ def generate_definition_config(definition_type: str, output_file: str = "input.j """ Generate an example config file for building a definition. + :param definition_type: CNF, VNF or NSD :param output_file: path to output config + file, defaults to "input.json" :type output_ + file: :param definition_type: CNF, VNF or NSD :param output_file: path to output config file, defaults to "input.json" :type output_file: str, optional @@ -81,7 +88,7 @@ def generate_definition_config(definition_type: str, output_file: str = "input.j with open(output_file, "w", encoding="utf-8") as f: f.write(config_as_dict) print(f"Empty definition configuration has been written to {output_file}") - logger.info(f"Empty definition configuration has been written to {output_file}") + logger.info("Empty definition configuration has been written to %s", output_file) def _get_config_from_file(config_file: str, definition_type: str) -> NFConfiguration: @@ -120,6 +127,7 @@ def _generate_nfd(definition_type, config): shutil.rmtree(os.path.dirname(nfd_generator.bicep_path)) nfd_generator.generate_nfd() + def publish_definition( cmd, client: HybridNetworkManagementClient, @@ -133,22 +141,37 @@ def publish_definition( """ Publish a generated definition. - :param cmd: - :param client: + :param cmd: :param client: :type client: HybridNetworkManagementClient :param + definition_type: VNF or CNF :param config_ + file: + Path to the config file for the NFDV :param definition_file: Optional path to a + bicep template to deploy, in case the user wants to edit the + built NFDV template. If omitted, the default built NFDV + template will be used. :param parameters_json_ + file: + Optional path to a parameters file for the bicep file, in case + the user wants to edit the built NFDV template. If omitted, + parameters from config will be turned into parameters for the + bicep file :param manifest_ + file: + Optional path to an override bicep template to deploy + manifests :param manifest_parameters_json_ + file: + :param cmd: + :param client: :type client: HybridNetworkManagementClient :param definition_type: VNF or CNF :param config_file: Path to the config file for the NFDV - :param definition_file: Optional path to a bicep template to deploy, in case the user - wants to edit the built NFDV template. If omitted, the default - built NFDV template will be used. + :param definition_file: Optional path to a bicep template to deploy, in case the + user wants to edit the built NFDV template. If omitted, the default + built NFDV template will be used. :param parameters_json_file: Optional path to a parameters file for the bicep file, - in case the user wants to edit the built NFDV template. If - omitted, parameters from config will be turned into parameters - for the bicep file + in case the user wants to edit the built NFDV template. If omitted, + parameters from config will be turned into parameters for the bicep file :param manifest_file: Optional path to an override bicep template to deploy - manifests + manifests :param manifest_parameters_json_file: Optional path to an override bicep parameters - file for manifest parameters + file for manifest parameters """ print("Publishing definition.") api_clients = ApiClients( @@ -178,8 +201,8 @@ def delete_published_definition( :param definition_type: CNF or VNF :param config_file: Path to the config file :param clean: if True, will delete the NFDG, artifact stores and publisher too. - Defaults to False. Only works if no resources have those as a parent. - Use with care. + Defaults to False. Only works if no resources have those as a parent. Use + with care. """ config = _get_config_from_file(config_file, definition_type) diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 5e0de9be3d9..2bb3b77ab00 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -36,9 +36,8 @@ def delete_vnf(self, clean: bool = False): Delete the NFDV and manifests. If they don't exist it still reports them as deleted. - :param clean: Delete the NFDG, artifact stores and publisher too. - defaults to False - Use with care. + :param clean: Delete the NFDG, artifact stores and publisher too. defaults + to False Use with care. """ assert isinstance(self.config, VNFConfiguration) if clean: @@ -99,8 +98,8 @@ def delete_artifact_manifest(self, store_type: str) -> None: _summary_ :param store_type: "sa" or "acr" - :raises CLIInternalError: If called with any other store type - :raises Exception if delete throws an exception + :raises CLIInternalError: If called with any other store type :raises + Exception if delete throws an exception """ if store_type == "sa": assert isinstance(self.config, VNFConfiguration) @@ -156,8 +155,7 @@ def delete_artifact_store(self, store_type: str) -> None: """Delete an artifact store :param store_type: "sa" or "acr" :raises CLIInternalError: If called with any other store type - :raises Exception if delete throws an exception - """ + :raises Exception if delete throws an exception.""" if store_type == "sa": assert isinstance(self.config, VNFConfiguration) store_name = self.config.blob_artifact_store_name diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index a712f2eed42..79c6b3ade44 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -62,12 +62,19 @@ def deploy_vnfd_from_bicep( Also ensure that all required predeploy resources are deployed. + :param bicep_template_path: The path to the bicep template of the nfdv :type + bicep_template_path: str :parameters_json_ + file: + path to an override file of set parameters for the nfdv :param + manifest_bicep_path: The path to the bicep template of the manifest + :manifest_parameters_json_ + file: :param bicep_template_path: The path to the bicep template of the nfdv :type bicep_template_path: str :parameters_json_file: path to an override file of set parameters for the nfdv :param manifest_bicep_path: The path to the bicep template of the manifest :manifest_parameters_json_file: path to an override file of set parameters for - the manifest + the manifest """ assert isinstance(self.config, VNFConfiguration) @@ -207,8 +214,8 @@ def deploy_bicep_template( Deploy a bicep template. :param bicep_template_path: Path to the bicep template - :param parameters: Parameters for the bicep template - :return Any output that the template produces + :param parameters: Parameters for the bicep template :return Any output + that the template produces """ logger.info("Deploy %s", bicep_template_path) arm_template_json = self.convert_bicep_to_arm(bicep_template_path) @@ -248,8 +255,7 @@ def validate_and_deploy_arm_template( :param template: The JSON contents of the template to deploy :param parameters: The JSON contents of the parameters file :param resource_group: The name of the resource group that has been deployed - - :raise RuntimeError if validation or deploy fails + :raise RuntimeError if validation or deploy fails :return: Output dictionary from the bicep template. """ deployment_name = f"nfd_into_{resource_group}" @@ -327,8 +333,7 @@ def convert_bicep_to_arm(self, bicep_template_path: str) -> Any: Convert a bicep template into an ARM template. :param bicep_template_path: The path to the bicep template to be converted - - :raise RuntimeError if az CLI is not installed. + :raise RuntimeError if az CLI is not installed. :return: Output dictionary from the bicep template. """ if not shutil.which("az"): diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index affb6d30fdb..eefad144c59 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -51,10 +51,10 @@ def ensure_resource_group_exists(self, resource_group_name: str) -> None: Checks whether a particular resource group exists on the subscription. Copied from virtutils. - :param resource_group_name: The name of the resource group - - Raises a NotFoundError exception if the resource group does not exist. - Raises a PermissionsError exception if we don't have permissions to check resource group existence. + :param resource_group_name: The name of the resource group Raises a + NotFoundError exception if the resource group does not exist. + Raises a PermissionsError exception if we don't have permissions to + check resource group existence. """ if not self.api_clients.resource_client.resource_groups.check_existence( resource_group_name @@ -67,9 +67,7 @@ def ensure_resource_group_exists(self, resource_group_name: str) -> None: ) else: print(f"Resource group {resource_group_name} exists.") - self.api_clients.resource_client.resource_groups.get( - resource_group_name - ) + self.api_clients.resource_client.resource_groups.get(resource_group_name) def ensure_config_resource_group_exists(self) -> None: """ diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 2d482ee53ca..942855d4d66 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -12,9 +12,11 @@ import tempfile import yaml -from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from jinja2 import Template, StrictUndefined +from azure.cli.core.azclierror import InvalidTemplateError from knack.log import get_logger + +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig from azext_aosm.util.constants import ( CNF_DEFINITION_BICEP_TEMPLATE, @@ -25,7 +27,7 @@ IMAGE_LINE_REGEX, IMAGE_PULL_SECRET_LINE_REGEX, ) -from azure.cli.core.azclierror import InvalidTemplateError + logger = get_logger(__name__) @@ -71,20 +73,20 @@ def generate_nfd(self) -> None: """Generate a CNF NFD which comprises a group, an Artifact Manifest and an NFDV.""" # Create output folder self._create_nfd_folder() - + # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: self.tmp_folder_name = tmpdirname try: for helm_package in self.config.helm_packages: - helm_package = HelmPackageConfig(**helm_package) # Unpack the chart into the tmp folder self._extract_chart(helm_package.path_to_chart) # TODO: Validate charts - # Get schema for each chart (extract mappings and take the schema bits we need from values.schema.json) + # Get schema for each chart + # (extract mappings and take the schema bits we need from values.schema.json) # + Add that schema to the big schema. self.deployment_parameter_schema["properties"].update( self.get_chart_mapping_schema(helm_package) @@ -118,7 +120,9 @@ def generate_nfd(self) -> None: self.write_schema_to_file() self.write_manifest_bicep_file() self.copy_to_output_folder() - print(f"Generated NFD bicep template created in {self.output_folder_name}") + print( + f"Generated NFD bicep template created in {self.output_folder_name}" + ) except InvalidTemplateError as e: raise e @@ -135,7 +139,6 @@ def _extract_chart(self, fname: str) -> None: Extract the chart into the tmp folder. :param fname: The path to helm package - """ if fname.endswith("tar.gz") or fname.endswith("tgz"): tar = tarfile.open(fname, "r:gz") @@ -146,7 +149,9 @@ def _extract_chart(self, fname: str) -> None: tar.extractall(path=self.tmp_folder_name) tar.close() else: - raise InvalidTemplateError(f"ERROR: The helm package '{fname}' is not a .tgz, .tar or .tar.gz file. Please fix this and run the command again.") + raise InvalidTemplateError( + f"ERROR: The helm package '{fname}' is not a .tgz, .tar or .tar.gz file. Please fix this and run the command again." + ) def _create_nfd_folder(self) -> None: """ @@ -239,10 +244,11 @@ def generate_nf_application_config( image_line_matches: List[Tuple[str, ...]], image_pull_secret_line_matches: List[Tuple[str, ...]], ) -> Dict[str, Any]: + """Generate NF application config.""" (name, version) = self.get_chart_name_and_version(helm_package) registryValuesPaths = set([m[0] for m in image_line_matches]) imagePullSecretsValuesPaths = set(image_pull_secret_line_matches) - """Generate NF application config""" + return { "name": helm_package.name, "chartName": name, @@ -267,8 +273,9 @@ def _find_yaml_files(self, directory) -> Iterator[str]: def find_pattern_matches_in_chart( self, helm_package: HelmPackageConfig, pattern: str ) -> List[Tuple[str, ...]]: - """ + """ Find pattern matches in Helm chart, using provided REGEX pattern. + param helm_package: The helm package config. param pattern: The regex pattern to match. """ @@ -289,6 +296,7 @@ def get_artifact_list( ) -> List[Any]: """ Get the list of artifacts for the chart. + param helm_package: The helm package config. param image_line_matches: The list of image line matches. """ @@ -325,19 +333,19 @@ def get_chart_mapping_schema( values_schema = os.path.join( self.tmp_folder_name, helm_package.name, "values.schema.json" ) - + if not os.path.exists(non_def_values) or not os.path.exists(values_schema): raise InvalidTemplateError( f"ERROR: The helm package '{helm_package.name}' is missing either values.mappings.yaml or values.schema.json. Please fix this and run the command again." ) - else: - with open(non_def_values, "r", encoding="utf-8") as stream: - values_data = yaml.load(stream, Loader=yaml.SafeLoader) - with open(values_schema, "r", encoding="utf-8") as f: - data = json.load(f) - schema_data = data["properties"] - + with open(non_def_values, "r", encoding="utf-8") as stream: + values_data = yaml.load(stream, Loader=yaml.SafeLoader) + + with open(values_schema, "r", encoding="utf-8") as f: + data = json.load(f) + schema_data = data["properties"] + try: final_schema = self.find_deploy_params(values_data, schema_data, {}) except KeyError as e: @@ -350,9 +358,7 @@ def get_chart_mapping_schema( def find_deploy_params( self, nested_dict, schema_nested_dict, final_schema ) -> Dict[Any, Any]: - """ - Find the deploy parameters in the values.mappings.yaml file and add them to the schema. - """ + """Find the deploy parameters in the values.mappings.yaml file and add them to the schema.""" original_schema_nested_dict = schema_nested_dict for k, v in nested_dict.items(): # if value is a string and contains deployParameters. @@ -394,11 +400,11 @@ def get_chart_name_and_version( return (chart_name, chart_version) def generate_parameter_mappings(self, helm_package: HelmPackageConfig) -> str: - """ Generate parameter mappings for the given helm package.""" + """Generate parameter mappings for the given helm package.""" values = os.path.join( self.tmp_folder_name, helm_package.name, "values.mappings.yaml" ) - + mappings_folder_path = os.path.join(self.tmp_folder_name, "configMappings") mappings_filename = f"{helm_package.name}-mappings.json" diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index d4e53714be2..ec3fbbd27b5 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -50,9 +50,7 @@ def __init__(self, config: VNFConfiguration): ) def generate_nfd(self) -> None: - """ - Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. - """ + """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" logger.info(f"Generate NFD bicep template for {self.arm_template_path}") print(f"Generate NFD bicep template for {self.arm_template_path}") diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 641fd252fbb..74a7867972d 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -18,6 +18,8 @@ CNF_DEFINITION_BICEP_TEMPLATE = "cnfdefinition.bicep" CNF_MANIFEST_BICEP_TEMPLATE = "cnfartifactmanifest.bicep" -IMAGE_LINE_REGEX = r"image: \{\{ .Values.(.+?) \}\}/(.+?):(\d+\.\d+\.\d+(-\w+)?(\.\d+)?)" +IMAGE_LINE_REGEX = ( + r"image: \{\{ .Values.(.+?) \}\}/(.+?):(\d+\.\d+\.\d+(-\w+)?(\.\d+)?)" +) IMAGE_PULL_SECRET_LINE_REGEX = r"imagePullSecrets: \[name: \{\{ .Values.(.+?) \}\}\]" DEPLOYMENT_PARAMETER_MAPPING_REGEX = r"\{deployParameters.(.+?)\}" From ff1793cf45b5344f29b6af6746a7b43d27a17c4c Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 24 May 2023 13:48:43 +0100 Subject: [PATCH 071/145] pre merge commit --- .../azext_aosm/generate_nfd/cnf_nfd_generator.py | 15 +-------------- .../generate_nfd/vnf_bicep_nfd_generator.py | 16 +--------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 942855d4d66..a892fca69de 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -154,20 +154,7 @@ def _extract_chart(self, fname: str) -> None: ) def _create_nfd_folder(self) -> None: - """ - Create the folder for the NFD bicep files. - - :raises RuntimeError: If the user aborts. - """ - # if os.path.exists(self.output_folder_name): - # carry_on = input( - # f"The folder {self.output_folder_name} already exists - delete it and continue? (y/n)" - # ) - # if carry_on != "y": - # raise RuntimeError("User aborted!") - - # shutil.rmtree(self.output_folder_name) - + """Create the folder for the NFD bicep files.""" logger.info("Create NFD bicep %s", self.output_folder_name) os.mkdir(self.output_folder_name) diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py index ec3fbbd27b5..7befe6ea928 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py @@ -52,7 +52,6 @@ def __init__(self, config: VNFConfiguration): def generate_nfd(self) -> None: """Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV.""" logger.info(f"Generate NFD bicep template for {self.arm_template_path}") - print(f"Generate NFD bicep template for {self.arm_template_path}") self._create_nfd_folder() self.create_parameter_files() @@ -76,20 +75,7 @@ def manifest_path(self) -> Optional[str]: return None def _create_nfd_folder(self) -> None: - """ - Create the folder for the NFD bicep files. - - :raises RuntimeError: If the user aborts. - """ - if os.path.exists(self.folder_name): - carry_on = input( - f"The folder {self.folder_name} already exists - delete it and continue? (y/n)" - ) - if carry_on != "y": - raise RuntimeError("User aborted!") - - shutil.rmtree(self.folder_name) - + """Create the folder for the NFD bicep files.""" logger.info("Create NFD bicep %s", self.folder_name) os.mkdir(self.folder_name) From 5bde597a03f8dc82eeeb2bd279d2cb940968017b Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 24 May 2023 14:18:24 +0100 Subject: [PATCH 072/145] more style changes; renamed vnfbicepnfd to vnfnfd --- src/aosm/azext_aosm/custom.py | 35 ++++++++++++------- src/aosm/azext_aosm/deploy/pre_deploy.py | 6 ++-- .../generate_nfd/cnf_nfd_generator.py | 4 +-- .../generate_nfd/nfd_generator_base.py | 3 +- ..._nfd_generator.py => vnf_nfd_generator.py} | 8 +++-- 5 files changed, 34 insertions(+), 22 deletions(-) rename src/aosm/azext_aosm/generate_nfd/{vnf_bicep_nfd_generator.py => vnf_nfd_generator.py} (99%) diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 10219892345..b365767bcc0 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -13,7 +13,7 @@ from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator -from azext_aosm.generate_nfd.vnf_bicep_nfd_generator import VnfBicepNfdGenerator +from src.aosm.azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator from azext_aosm.delete.delete import ResourceDeleter from azext_aosm.deploy.deploy_with_arm import DeployerViaArm from azext_aosm.util.constants import VNF, CNF, NSD @@ -26,7 +26,6 @@ ) - logger = get_logger(__name__) @@ -34,7 +33,7 @@ def build_definition(cmd, definition_type: str, config_file: str): """ Build and optionally publish a definition. - :param cmd: + :param cmd: :param config_file: path to the file :param definition_type: VNF or CNF """ @@ -78,7 +77,7 @@ def _generate_nfd(definition_type, config): """Generate a Network Function Definition for the given type and config.""" nfd_generator: NFDGenerator if definition_type == VNF: - nfd_generator = VnfBicepNfdGenerator(config) + nfd_generator = VnfNfdGenerator(config) elif definition_type == CNF: nfd_generator = CnfNfdGenerator(config) else: @@ -125,8 +124,8 @@ def publish_definition( Optional path to an override bicep template to deploy manifests :param manifest_parameters_json_ file: - :param cmd: - :param client: + :param cmd: + :param client: :type client: HybridNetworkManagementClient :param definition_type: VNF or CNF :param config_file: Path to the config file for the NFDV @@ -195,6 +194,9 @@ def generate_design_config(output_file: str = "input.json"): """ Generate an example config file for building a NSD. + :param output_file: path to output config file, defaults to "input.json" :type + output_ + file: :param output_file: path to output config file, defaults to "input.json" :type output_file: str, optional """ @@ -205,6 +207,9 @@ def _generate_config(definition_type: str, output_file: str = "input.json"): """ Generic generate config function for NFDs and NSDs. + :param definition_type: CNF, VNF or NSD :param output_file: path to output config + file, defaults to "input.json" :type output_ + file: :param definition_type: CNF, VNF or NSD :param output_file: path to output config file, defaults to "input.json" :type output_file: str, optional @@ -226,9 +231,12 @@ def build_design(cmd, client: HybridNetworkManagementClient, config_file: str): """ Build and optionally publish a Network Service Design. - :param cmd: + :param cmd: :type cmd: _type_ :param client: :type client: + HybridNetworkManagementClient :param config_ + file: + :param cmd: :type cmd: _type_ - :param client: + :param client: :type client: HybridNetworkManagementClient :param config_file: path to the file """ @@ -247,8 +255,8 @@ def delete_published_design( :param definition_type: CNF or VNF :param config_file: Path to the config file :param clean: if True, will delete the NFDG, artifact stores and publisher too. - Defaults to False. Only works if no resources have those as a parent. - Use with care. + Defaults to False. Only works if no resources have those as a parent. Use + with care. """ raise NotImplementedError("Delete published design is not yet implented for NSD") @@ -261,8 +269,11 @@ def publish_design( """ Publish a generated design. - :param cmd: - :param client: + :param cmd: :param client: :type client: HybridNetworkManagementClient :param + definition_type: VNF or CNF :param config_ + file: + :param cmd: + :param client: :type client: HybridNetworkManagementClient :param definition_type: VNF or CNF :param config_file: Path to the config file for the NFDV diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index eefad144c59..6e01a0bd7f5 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -52,9 +52,9 @@ def ensure_resource_group_exists(self, resource_group_name: str) -> None: Copied from virtutils. :param resource_group_name: The name of the resource group Raises a - NotFoundError exception if the resource group does not exist. - Raises a PermissionsError exception if we don't have permissions to - check resource group existence. + NotFoundError exception if the resource group does not exist. Raises a + PermissionsError exception if we don't have permissions to check + resource group existence. """ if not self.api_clients.resource_client.resource_groups.check_existence( resource_group_name diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index a892fca69de..80bff78ae24 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -32,7 +32,7 @@ logger = get_logger(__name__) -class CnfNfdGenerator(NFDGenerator): +class CnfNfdGenerator(NFDGenerator): # pylint: disable=too-many-instance-attributes """ _summary_ @@ -252,7 +252,7 @@ def _find_yaml_files(self, directory) -> Iterator[str]: :param directory: The directory to search. """ - for root, dirs, files in os.walk(directory): + for root, _, files in os.walk(directory): for file in files: if file.endswith(".yaml") or file.endswith(".yml"): yield os.path.join(root, file) diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index 81afb4db802..591e56e2200 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -20,9 +20,8 @@ def __init__( The sub-classes do the actual work """ - pass def generate_nfd(self) -> None: """No-op on base class.""" logger.error("Generate NFD called on base class. No-op") - return + diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py similarity index 99% rename from src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py rename to src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index 8601ba7f1f2..9c0d751ca24 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_bicep_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -3,14 +3,15 @@ # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- """Contains a class for generating VNF NFDs and associated resources.""" -from knack.log import get_logger -import json + import logging +import json import os import shutil from functools import cached_property from pathlib import Path from typing import Any, Dict, Optional +from knack.log import get_logger from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator @@ -24,7 +25,7 @@ logger = get_logger(__name__) -class VnfBicepNfdGenerator(NFDGenerator): +class VnfNfdGenerator(NFDGenerator): """ VNF NFD Generator. @@ -53,6 +54,7 @@ def generate_nfd(self) -> None: """Create a bicep template for an NFD from the ARM template for the VNF.""" """ Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. + Create a bicep template for an NFD from the ARM template for the VNF. """ logger.info(f"Generate NFD bicep template for {self.arm_template_path}") From a79ef57b1be4ff90e6d8c4923d5344a44475dceb Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 24 May 2023 14:27:45 +0100 Subject: [PATCH 073/145] Update readme with workflow --- src/aosm/README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/aosm/README.md b/src/aosm/README.md index 7cc02dce08f..34f32cfbf36 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -40,11 +40,23 @@ https://eng.ms/docs/strategic-missions-and-technologies/strategic-missions-and-t CLI issues should be tagged and triaged as UX bugs. -## Definitions +## nfd and nsd commands These commands help with the publishing of Network Function Definition and Network Service Design resources. +## Overview of function +A generic workflow of using the tool would be: +- Find the pre-requisite items you require for your use-case +- Run a `generate-config` command to output an example JSON config file for subsequent commands +- Fill in the config file +- Run a `build` command to output one or more bicep templates for your Network Function Definition or Network Service Design +- Review the output of the build command, edit the output as necessary for your requirements +- Run a `publish` command to: + * Create all pre-requisite resources such as Resource Group, Publisher, Artifact Stores, Groups + * Deploy those bicep templates + * Upload artifacts to the artifact stores + ### Pre-requisites #### VNFs From 168c2656d131350e8cb57c0974bdcd8e29f6cece Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 24 May 2023 15:01:02 +0100 Subject: [PATCH 074/145] added configfile validation --- src/aosm/azext_aosm/custom.py | 11 ++++++++--- .../azext_aosm/generate_nfd/cnf_nfd_generator.py | 12 +++++++++++- src/aosm/azext_aosm/util/constants.py | 4 +++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index b365767bcc0..3ddb3a91fde 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -9,11 +9,11 @@ from dataclasses import asdict from typing import Optional from knack.log import get_logger -from azure.cli.core.azclierror import CLIInternalError +from azure.cli.core.azclierror import CLIInternalError, InvalidArgumentValueError from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator -from src.aosm.azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator +from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator from azext_aosm.delete.delete import ResourceDeleter from azext_aosm.deploy.deploy_with_arm import DeployerViaArm from azext_aosm.util.constants import VNF, CNF, NSD @@ -66,6 +66,10 @@ def _get_config_from_file(config_file: str, definition_type: str) -> NFConfigura :param definition_type: VNF, CNF or NSD :rtype: Configuration """ + + if not os.path.exists(config_file): + raise InvalidArgumentValueError(f"Config file {config_file} not found. Please specify a valid config file path.") + with open(config_file, "r", encoding="utf-8") as f: config_as_dict = json.loads(f.read()) @@ -155,7 +159,8 @@ def publish_definition( ) else: raise NotImplementedError( - "Publishing of CNF definitions is not yet implemented." + "Publishing of CNF definitions is not yet implemented. \ + You should manually deploy your bicep file and upload charts and images to your artifact store. " ) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 80bff78ae24..4749397a980 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -34,7 +34,13 @@ class CnfNfdGenerator(NFDGenerator): # pylint: disable=too-many-instance-attributes """ - _summary_ + CNF NFD Generator. + + This takes a config file, and outputs: + - A bicep file for the NFDV + - Parameters files that are used by the NFDV bicep file, these are the + deployParameters and the mapping profiles of those deploy parameters + - A bicep file for the Artifact manifests :param NFDGenerator: _description_ :type NFDGenerator: _type_ @@ -123,6 +129,10 @@ def generate_nfd(self) -> None: print( f"Generated NFD bicep template created in {self.output_folder_name}" ) + print( + "Please review these templates." + "If you are happy with them, you should manually deploy your bicep templates and upoad your charts and images to your artifact store." + ) except InvalidTemplateError as e: raise e diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 74a7867972d..67150882426 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -10,9 +10,11 @@ NSD = "nsd" # Names of files used in the repo +DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" + VNF_DEFINITION_BICEP_SOURCE_TEMPLATE = "vnfdefinition.bicep" VNF_MANIFEST_BICEP_SOURCE_TEMPLATE = "vnfartifactmanifests.bicep" -VNF_DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" + CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE = "cnfdefinition.bicep.j2" CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE = "cnfartifactmanifest.bicep.j2" CNF_DEFINITION_BICEP_TEMPLATE = "cnfdefinition.bicep" From e43cb92926aba4cd5aa3392de46817c3baa8e3ff Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 25 May 2023 09:45:15 +0100 Subject: [PATCH 075/145] added temp dir to vnf; renamed shared constants --- src/aosm/azext_aosm/_configuration.py | 6 +- src/aosm/azext_aosm/custom.py | 4 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 8 +- .../generate_nfd/vnf_nfd_generator.py | 75 ++++++++++++------- src/aosm/azext_aosm/util/constants.py | 4 +- 5 files changed, 58 insertions(+), 39 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 29e7ef03e7a..510d18db771 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -2,7 +2,7 @@ from typing import Dict, Optional, Any, List from pathlib import Path from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError -from azext_aosm.util.constants import VNF_DEFINITION_OUTPUT_BICEP_PREFIX, VNF, CNF, NSD +from azext_aosm.util.constants import DEFINITION_OUTPUT_BICEP_PREFIX, VNF, CNF, NSD DESCRIPTION_MAP: Dict[str, str] = { "publisher_resource_group_name": ( @@ -133,7 +133,7 @@ def build_output_folder_name(self) -> str: """Return the local folder for generating the bicep template to.""" arm_template_path = self.arm_template.file_path return ( - f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" + f"{DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" ) @@ -167,7 +167,7 @@ def __post_init__(self): @property def build_output_folder_name(self) -> str: """Return the local folder for generating the bicep template to.""" - return f"{VNF_DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}" + return f"{DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}" def get_configuration( diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 3ddb3a91fde..12bf872bae6 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -9,7 +9,7 @@ from dataclasses import asdict from typing import Optional from knack.log import get_logger -from azure.cli.core.azclierror import CLIInternalError, InvalidArgumentValueError +from azure.cli.core.azclierror import CLIInternalError, InvalidArgumentValueError, UnclassifiedUserFault from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator @@ -93,7 +93,7 @@ def _generate_nfd(definition_type, config): f"The folder {os.path.dirname(nfd_generator.bicep_path)} already exists - delete it and continue? (y/n)" ) if carry_on != "y": - raise RuntimeError("User aborted!") + raise UnclassifiedUserFault("User aborted! ") shutil.rmtree(os.path.dirname(nfd_generator.bicep_path)) nfd_generator.generate_nfd() diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 79c6b3ade44..fa7e9877c83 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -18,8 +18,8 @@ from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK from azext_aosm._configuration import NFConfiguration, VNFConfiguration from azext_aosm.util.constants import ( - VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, - VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, + VNF_DEFINITION_BICEP_TEMPLATE, + VNF_MANIFEST_BICEP_TEMPLATE, ) @@ -83,7 +83,7 @@ def deploy_vnfd_from_bicep( # one produced from building the NFDV using this CLI bicep_path = os.path.join( self.config.build_output_folder_name, - VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, + VNF_DEFINITION_BICEP_TEMPLATE, ) if parameters_json_file: @@ -110,7 +110,7 @@ def deploy_vnfd_from_bicep( if not manifest_bicep_path: manifest_bicep_path = os.path.join( self.config.build_output_folder_name, - VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, + VNF_MANIFEST_BICEP_TEMPLATE, ) if not manifest_parameters_json_file: manifest_params = self.construct_manifest_parameters() diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index 9c0d751ca24..bcb1a3c736b 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -8,6 +8,8 @@ import json import os import shutil +import tempfile + from functools import cached_property from pathlib import Path from typing import Any, Dict, Optional @@ -17,8 +19,8 @@ from azext_aosm._configuration import VNFConfiguration from azext_aosm.util.constants import ( - VNF_DEFINITION_BICEP_SOURCE_TEMPLATE, - VNF_MANIFEST_BICEP_SOURCE_TEMPLATE, + VNF_DEFINITION_BICEP_TEMPLATE, + VNF_MANIFEST_BICEP_TEMPLATE, ) @@ -39,15 +41,15 @@ class VnfNfdGenerator(NFDGenerator): def __init__(self, config: VNFConfiguration): super(NFDGenerator, self).__init__() self.config = config - self.bicep_template_name = VNF_DEFINITION_BICEP_SOURCE_TEMPLATE - self.manifest_template_name = VNF_MANIFEST_BICEP_SOURCE_TEMPLATE + self.bicep_template_name = VNF_DEFINITION_BICEP_TEMPLATE + self.manifest_template_name = VNF_MANIFEST_BICEP_TEMPLATE self.arm_template_path = self.config.arm_template.file_path - self.folder_name = self.config.build_output_folder_name + self.output_folder_name = self.config.build_output_folder_name - self._bicep_path = os.path.join(self.folder_name, self.bicep_template_name) + self._bicep_path = os.path.join(self.output_folder_name, self.bicep_template_name) self._manifest_path = os.path.join( - self.folder_name, self.manifest_template_name + self.output_folder_name, self.manifest_template_name ) def generate_nfd(self) -> None: @@ -57,16 +59,20 @@ def generate_nfd(self) -> None: Create a bicep template for an NFD from the ARM template for the VNF. """ - logger.info(f"Generate NFD bicep template for {self.arm_template_path}") - + # Create output folder self._create_nfd_folder() - self.create_parameter_files() - self.copy_bicep() - print(f"Generated NFD bicep templates created in {self.folder_name}") - print( - "Please review these templates. When you are happy with them run " - "`az aosm nfd publish` with the same arguments." - ) + + # Create temporary folder. + with tempfile.TemporaryDirectory() as tmpdirname: + self.tmp_folder_name = tmpdirname + + self.create_parameter_files() + self.copy_to_output_folder() + print(f"Generated NFD bicep templates created in {self.output_folder_name}") + print( + "Please review these templates. When you are happy with them run " + "`az aosm nfd publish` with the same arguments." + ) @property def bicep_path(self) -> Optional[str]: @@ -86,8 +92,8 @@ def manifest_path(self) -> Optional[str]: def _create_nfd_folder(self) -> None: """Create the folder for the NFD bicep files.""" - logger.info("Create NFD bicep %s", self.folder_name) - os.mkdir(self.folder_name) + logger.info("Create NFD bicep %s", self.output_folder_name) + os.mkdir(self.output_folder_name) @cached_property def vm_parameters(self) -> Dict[str, Any]: @@ -99,11 +105,11 @@ def vm_parameters(self) -> Dict[str, Any]: def create_parameter_files(self) -> None: """Create the Deployment and Template json parameter files.""" - schemas_folder_path = os.path.join(self.folder_name, "schemas") + schemas_folder_path = os.path.join(self.tmp_folder_name, "schemas") os.mkdir(schemas_folder_path) self.write_deployment_parameters(schemas_folder_path) - mappings_folder_path = os.path.join(self.folder_name, "configMappings") + mappings_folder_path = os.path.join(self.tmp_folder_name, "configMappings") os.mkdir(mappings_folder_path) self.write_template_parameters(mappings_folder_path) self.write_vhd_parameters(mappings_folder_path) @@ -119,7 +125,7 @@ def write_deployment_parameters(self, folder_path: str) -> None: nfd_parameters: Dict[str, Any] = { key: {"type": self.vm_parameters[key]["type"]} for key in self.vm_parameters } - + deployment_parameters_path = os.path.join( folder_path, "deploymentParameters.json" ) @@ -176,18 +182,31 @@ def write_vhd_parameters(self, folder_path: str) -> None: } vhd_parameters_path = os.path.join(folder_path, "vhdParameters.json") - with open(vhd_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(vhd_parameters, indent=4)) logger.debug(f"{vhd_parameters_path} created") - def copy_bicep(self) -> None: - """Copy the bicep templates into the build output folder.""" + def copy_to_output_folder(self) -> None: + """Copy the bicep templates, config mappings and schema into the build output folder.""" code_dir = os.path.dirname(__file__) - + bicep_path = os.path.join(code_dir, "templates", self.bicep_template_name) + shutil.copy(bicep_path, self.output_folder_name) + manifest_path = os.path.join(code_dir, "templates", self.manifest_template_name) - - shutil.copy(bicep_path, self.folder_name) - shutil.copy(manifest_path, self.folder_name) + shutil.copy(manifest_path, self.output_folder_name) + + os.mkdir(self.output_folder_name + "/schemas") + full_schema = os.path.join(self.tmp_folder_name, "schemas", "deploymentParameters.json") + shutil.copy( + full_schema, + self.output_folder_name + "/schemas" + "/deploymentParameters.json", + ) + + config_mappings_path = os.path.join(self.tmp_folder_name, "configMappings") + shutil.copytree( + config_mappings_path, + self.output_folder_name + "/configMappings", + dirs_exist_ok=True, + ) \ No newline at end of file diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 67150882426..9bc8294e101 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -12,8 +12,8 @@ # Names of files used in the repo DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" -VNF_DEFINITION_BICEP_SOURCE_TEMPLATE = "vnfdefinition.bicep" -VNF_MANIFEST_BICEP_SOURCE_TEMPLATE = "vnfartifactmanifests.bicep" +VNF_DEFINITION_BICEP_TEMPLATE = "vnfdefinition.bicep" +VNF_MANIFEST_BICEP_TEMPLATE = "vnfartifactmanifests.bicep" CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE = "cnfdefinition.bicep.j2" CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE = "cnfartifactmanifest.bicep.j2" From 9694c9b0cfe03eff440389c4f9e4865b37c7eef2 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Thu, 25 May 2023 11:54:56 +0100 Subject: [PATCH 076/145] sunny markups --- src/aosm/azext_aosm/_configuration.py | 18 ++++---- .../generate_nfd/cnf_nfd_generator.py | 42 +++++++++---------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 510d18db771..a4f69ae8a1c 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -31,6 +31,14 @@ "Version of the artifact. For VHDs this must be in format A-B-C. " "For ARM templates this must be in format A.B.C" ), + "helm_package_name": "Name of the Helm package", + "path_to_chart": ( + "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz" + ), + "helm_depends_on": ( + "Names of the Helm packages this package depends on. " + "Leave as an empty array if no dependencies" + ) } @@ -139,14 +147,10 @@ def build_output_folder_name(self) -> str: @dataclass class HelmPackageConfig: - name: str = "Name of the Helm package" - path_to_chart: str = ( - "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz" - ) + name: str = DESCRIPTION_MAP["helm_package_name"] + path_to_chart: str = DESCRIPTION_MAP["path_to_chart"] depends_on: List[str] = field( - default_factory=lambda: [ - "Names of the Helm packages this package depends on. Leave as an empty string if no dependencies" - ] + default_factory=lambda: [DESCRIPTION_MAP["helm_depends_on"]] ) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 4749397a980..6bc2f8dd214 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -41,9 +41,6 @@ class CnfNfdGenerator(NFDGenerator): # pylint: disable=too-many-instance-attribu - Parameters files that are used by the NFDV bicep file, these are the deployParameters and the mapping profiles of those deploy parameters - A bicep file for the Artifact manifests - - :param NFDGenerator: _description_ - :type NFDGenerator: _type_ """ def __init__(self, config: CNFConfiguration): @@ -82,7 +79,7 @@ def generate_nfd(self) -> None: # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: - self.tmp_folder_name = tmpdirname + self._tmp_folder_name = tmpdirname try: for helm_package in self.config.helm_packages: helm_package = HelmPackageConfig(**helm_package) @@ -131,7 +128,9 @@ def generate_nfd(self) -> None: ) print( "Please review these templates." - "If you are happy with them, you should manually deploy your bicep templates and upoad your charts and images to your artifact store." + "If you are happy with them, you should manually deploy your bicep " + "templates and upload your charts and images to your " + "artifact store." ) except InvalidTemplateError as e: raise e @@ -152,15 +151,16 @@ def _extract_chart(self, fname: str) -> None: """ if fname.endswith("tar.gz") or fname.endswith("tgz"): tar = tarfile.open(fname, "r:gz") - tar.extractall(path=self.tmp_folder_name) + tar.extractall(path=self._tmp_folder_name) tar.close() elif fname.endswith("tar"): tar = tarfile.open(fname, "r:") - tar.extractall(path=self.tmp_folder_name) + tar.extractall(path=self._tmp_folder_name) tar.close() else: raise InvalidTemplateError( - f"ERROR: The helm package '{fname}' is not a .tgz, .tar or .tar.gz file. Please fix this and run the command again." + f"ERROR: The helm package '{fname}' is not a .tgz, .tar or .tar.gz " + "file. Please fix this and run the command again." ) def _create_nfd_folder(self) -> None: @@ -180,7 +180,7 @@ def write_manifest_bicep_file(self) -> None: artifacts=self.artifacts, ) - path = os.path.join(self.tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE) + path = os.path.join(self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE) with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) @@ -197,13 +197,13 @@ def write_nfd_bicep_file(self) -> None: nf_application_configurations=self.nf_application_configurations, ) - path = os.path.join(self.tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE) + path = os.path.join(self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE) with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) def write_schema_to_file(self) -> None: """Write the schema to file deploymentParameters.json.""" - full_schema = os.path.join(self.tmp_folder_name, "deploymentParameters.json") + full_schema = os.path.join(self._tmp_folder_name, "deploymentParameters.json") with open(full_schema, "w", encoding="UTF-8") as f: json.dump(self.deployment_parameter_schema, f, indent=4) @@ -213,23 +213,23 @@ def copy_to_output_folder(self) -> None: os.mkdir(self.output_folder_name + "/schemas") nfd_bicep_path = os.path.join( - self.tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE + self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE ) shutil.copy(nfd_bicep_path, self.output_folder_name) manifest_bicep_path = os.path.join( - self.tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE + self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE ) shutil.copy(manifest_bicep_path, self.output_folder_name) - config_mappings_path = os.path.join(self.tmp_folder_name, "configMappings") + config_mappings_path = os.path.join(self._tmp_folder_name, "configMappings") shutil.copytree( config_mappings_path, self.output_folder_name + "/configMappings", dirs_exist_ok=True, ) - full_schema = os.path.join(self.tmp_folder_name, "deploymentParameters.json") + full_schema = os.path.join(self._tmp_folder_name, "deploymentParameters.json") shutil.copy( full_schema, self.output_folder_name + "/schemas" + "/deploymentParameters.json", @@ -276,7 +276,7 @@ def find_pattern_matches_in_chart( param helm_package: The helm package config. param pattern: The regex pattern to match. """ - chart_dir = os.path.join(self.tmp_folder_name, helm_package.name) + chart_dir = os.path.join(self._tmp_folder_name, helm_package.name) matches = [] for file in self._find_yaml_files(chart_dir): @@ -325,10 +325,10 @@ def get_chart_mapping_schema( param helm_package: The helm package config. """ non_def_values = os.path.join( - self.tmp_folder_name, helm_package.name, "values.mappings.yaml" + self._tmp_folder_name, helm_package.name, "values.mappings.yaml" ) values_schema = os.path.join( - self.tmp_folder_name, helm_package.name, "values.schema.json" + self._tmp_folder_name, helm_package.name, "values.schema.json" ) if not os.path.exists(non_def_values) or not os.path.exists(values_schema): @@ -387,7 +387,7 @@ def get_chart_name_and_version( self, helm_package: HelmPackageConfig ) -> Tuple[str, str]: """Get the name and version of the chart.""" - chart = os.path.join(self.tmp_folder_name, helm_package.name, "Chart.yaml") + chart = os.path.join(self._tmp_folder_name, helm_package.name, "Chart.yaml") with open(chart, "r", encoding="utf-8") as f: data = yaml.load(f, Loader=yaml.FullLoader) @@ -399,10 +399,10 @@ def get_chart_name_and_version( def generate_parameter_mappings(self, helm_package: HelmPackageConfig) -> str: """Generate parameter mappings for the given helm package.""" values = os.path.join( - self.tmp_folder_name, helm_package.name, "values.mappings.yaml" + self._tmp_folder_name, helm_package.name, "values.mappings.yaml" ) - mappings_folder_path = os.path.join(self.tmp_folder_name, "configMappings") + mappings_folder_path = os.path.join(self._tmp_folder_name, "configMappings") mappings_filename = f"{helm_package.name}-mappings.json" if not os.path.exists(mappings_folder_path): From 9efa2967619c9b8816c33bfed7d4b0fb76db6f69 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 25 May 2023 12:33:09 +0100 Subject: [PATCH 077/145] removed create_nfd_folder; added schema prefix to constant --- .../generate_nfd/cnf_nfd_generator.py | 51 +++++++++---------- .../generate_nfd/vnf_nfd_generator.py | 40 +++++++-------- src/aosm/azext_aosm/util/constants.py | 12 +++++ 3 files changed, 54 insertions(+), 49 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 4749397a980..631d46cffc7 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -26,6 +26,9 @@ DEPLOYMENT_PARAMETER_MAPPING_REGEX, IMAGE_LINE_REGEX, IMAGE_PULL_SECRET_LINE_REGEX, + CONFIG_MAPPINGS, + SCHEMAS, + SCHEMA_PREFIX ) @@ -64,12 +67,7 @@ def __init__(self, config: CNFConfiguration): self.artifacts = [] self.nf_application_configurations = [] - self.deployment_parameter_schema = { - "$schema": "https://json-schema.org/draft-07/schema#", - "title": "DeployParametersSchema", - "type": "object", - "properties": {}, - } + self.deployment_parameter_schema = SCHEMA_PREFIX self._bicep_path = os.path.join( self.output_folder_name, CNF_DEFINITION_BICEP_TEMPLATE @@ -77,8 +75,6 @@ def __init__(self, config: CNFConfiguration): def generate_nfd(self) -> None: """Generate a CNF NFD which comprises a group, an Artifact Manifest and an NFDV.""" - # Create output folder - self._create_nfd_folder() # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: @@ -105,6 +101,7 @@ def generate_nfd(self) -> None: ) # Generate the NF application configuration for the chart + # passed to jinja2 renderer to render bicep template self.nf_application_configurations.append( self.generate_nf_application_config( helm_package, @@ -144,30 +141,27 @@ def bicep_path(self) -> Optional[str]: return None - def _extract_chart(self, fname: str) -> None: + def _extract_chart(self, path: str) -> None: """ Extract the chart into the tmp folder. - :param fname: The path to helm package + :param path: The path to helm package """ - if fname.endswith("tar.gz") or fname.endswith("tgz"): - tar = tarfile.open(fname, "r:gz") + (_, ext) = os.path.splitext(path) + if ext == ".gz" or ext == ".tgz": + tar = tarfile.open(path, "r:gz") tar.extractall(path=self.tmp_folder_name) tar.close() - elif fname.endswith("tar"): - tar = tarfile.open(fname, "r:") + elif ext == ".tar": + tar = tarfile.open(path, "r:") tar.extractall(path=self.tmp_folder_name) tar.close() else: raise InvalidTemplateError( - f"ERROR: The helm package '{fname}' is not a .tgz, .tar or .tar.gz file. Please fix this and run the command again." + f"ERROR: The helm package '{path}' is not a .tgz, .tar or .tar.gz file.\ + Please fix this and run the command again." ) - def _create_nfd_folder(self) -> None: - """Create the folder for the NFD bicep files.""" - logger.info("Create NFD bicep %s", self.output_folder_name) - os.mkdir(self.output_folder_name) - def write_manifest_bicep_file(self) -> None: """Write the bicep file for the Artifact Manifest.""" with open(self.manifest_jinja2_template_path, "r", encoding="UTF-8") as f: @@ -209,8 +203,11 @@ def write_schema_to_file(self) -> None: def copy_to_output_folder(self) -> None: """Copy the config mappings, schema and bicep templates (artifact manifest and NFDV) to the output folder.""" - - os.mkdir(self.output_folder_name + "/schemas") + + logger.info("Create NFD bicep %s", self.output_folder_name) + os.mkdir(self.output_folder_name) + + os.mkdir(self.output_folder_name + "/" + SCHEMAS) nfd_bicep_path = os.path.join( self.tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE @@ -222,17 +219,17 @@ def copy_to_output_folder(self) -> None: ) shutil.copy(manifest_bicep_path, self.output_folder_name) - config_mappings_path = os.path.join(self.tmp_folder_name, "configMappings") + config_mappings_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) shutil.copytree( config_mappings_path, - self.output_folder_name + "/configMappings", + self.output_folder_name + "/" + CONFIG_MAPPINGS, dirs_exist_ok=True, ) full_schema = os.path.join(self.tmp_folder_name, "deploymentParameters.json") shutil.copy( full_schema, - self.output_folder_name + "/schemas" + "/deploymentParameters.json", + self.output_folder_name + "/" + SCHEMAS + "/deploymentParameters.json", ) def generate_nf_application_config( @@ -402,7 +399,7 @@ def generate_parameter_mappings(self, helm_package: HelmPackageConfig) -> str: self.tmp_folder_name, helm_package.name, "values.mappings.yaml" ) - mappings_folder_path = os.path.join(self.tmp_folder_name, "configMappings") + mappings_folder_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) mappings_filename = f"{helm_package.name}-mappings.json" if not os.path.exists(mappings_folder_path): @@ -416,4 +413,4 @@ def generate_parameter_mappings(self, helm_package: HelmPackageConfig) -> str: with open(mapping_file_path, "w", encoding="utf-8") as file: json.dump(data, file, indent=4) - return os.path.join("configMappings", mappings_filename) + return os.path.join(CONFIG_MAPPINGS, mappings_filename) diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index bcb1a3c736b..90133fe95a0 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -21,6 +21,9 @@ from azext_aosm.util.constants import ( VNF_DEFINITION_BICEP_TEMPLATE, VNF_MANIFEST_BICEP_TEMPLATE, + CONFIG_MAPPINGS, + SCHEMAS, + SCHEMA_PREFIX ) @@ -59,8 +62,7 @@ def generate_nfd(self) -> None: Create a bicep template for an NFD from the ARM template for the VNF. """ - # Create output folder - self._create_nfd_folder() + # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: @@ -90,11 +92,6 @@ def manifest_path(self) -> Optional[str]: return None - def _create_nfd_folder(self) -> None: - """Create the folder for the NFD bicep files.""" - logger.info("Create NFD bicep %s", self.output_folder_name) - os.mkdir(self.output_folder_name) - @cached_property def vm_parameters(self) -> Dict[str, Any]: """The parameters from the VM ARM template.""" @@ -105,11 +102,11 @@ def vm_parameters(self) -> Dict[str, Any]: def create_parameter_files(self) -> None: """Create the Deployment and Template json parameter files.""" - schemas_folder_path = os.path.join(self.tmp_folder_name, "schemas") + schemas_folder_path = os.path.join(self.tmp_folder_name, SCHEMAS) os.mkdir(schemas_folder_path) self.write_deployment_parameters(schemas_folder_path) - mappings_folder_path = os.path.join(self.tmp_folder_name, "configMappings") + mappings_folder_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) os.mkdir(mappings_folder_path) self.write_template_parameters(mappings_folder_path) self.write_vhd_parameters(mappings_folder_path) @@ -131,13 +128,9 @@ def write_deployment_parameters(self, folder_path: str) -> None: ) # Heading for the deployParameters schema - deploy_parameters_full: Dict[str, Any] = { - "$schema": "https://json-schema.org/draft-07/schema#", - "title": "DeployParametersSchema", - "type": "object", - "properties": nfd_parameters, - } - + deploy_parameters_full: Dict[str, Any] = SCHEMA_PREFIX + deploy_parameters_full["properties"].update(nfd_parameters) + with open(deployment_parameters_path, "w") as _file: _file.write(json.dumps(deploy_parameters_full, indent=4)) @@ -190,23 +183,26 @@ def write_vhd_parameters(self, folder_path: str) -> None: def copy_to_output_folder(self) -> None: """Copy the bicep templates, config mappings and schema into the build output folder.""" code_dir = os.path.dirname(__file__) - + + logger.info("Create NFD bicep %s", self.output_folder_name) + os.mkdir(self.output_folder_name) + bicep_path = os.path.join(code_dir, "templates", self.bicep_template_name) shutil.copy(bicep_path, self.output_folder_name) manifest_path = os.path.join(code_dir, "templates", self.manifest_template_name) shutil.copy(manifest_path, self.output_folder_name) - os.mkdir(self.output_folder_name + "/schemas") - full_schema = os.path.join(self.tmp_folder_name, "schemas", "deploymentParameters.json") + os.mkdir(self.output_folder_name + "/" + SCHEMAS) + full_schema = os.path.join(self.tmp_folder_name, SCHEMAS, "deploymentParameters.json") shutil.copy( full_schema, - self.output_folder_name + "/schemas" + "/deploymentParameters.json", + self.output_folder_name + "/" + SCHEMAS + "/deploymentParameters.json", ) - config_mappings_path = os.path.join(self.tmp_folder_name, "configMappings") + config_mappings_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) shutil.copytree( config_mappings_path, - self.output_folder_name + "/configMappings", + self.output_folder_name + "/" + CONFIG_MAPPINGS, dirs_exist_ok=True, ) \ No newline at end of file diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 9bc8294e101..f196d32a7ae 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -20,6 +20,18 @@ CNF_DEFINITION_BICEP_TEMPLATE = "cnfdefinition.bicep" CNF_MANIFEST_BICEP_TEMPLATE = "cnfartifactmanifest.bicep" +# Names of folder used in the repo +CONFIG_MAPPINGS = "configMappings" +SCHEMAS = "schemas" + +# Deployment Schema + +SCHEMA_PREFIX = { + "$schema": "https://json-schema.org/draft-07/schema#", + "title": "DeployParametersSchema", + "type": "object", + "properties": {}, + } IMAGE_LINE_REGEX = ( r"image: \{\{ .Values.(.+?) \}\}/(.+?):(\d+\.\d+\.\d+(-\w+)?(\.\d+)?)" ) From a40cc3dba7f34b4306c19c67d85bc39093852735 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 25 May 2023 12:50:43 +0100 Subject: [PATCH 078/145] added deploymentparams to constants.py --- .../generate_nfd/cnf_nfd_generator.py | 31 ++++++++++--------- .../generate_nfd/vnf_nfd_generator.py | 21 +++++++------ src/aosm/azext_aosm/util/constants.py | 1 + 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index cd96cd865bb..8d55a44ff3e 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -28,7 +28,8 @@ IMAGE_PULL_SECRET_LINE_REGEX, CONFIG_MAPPINGS, SCHEMAS, - SCHEMA_PREFIX + SCHEMA_PREFIX, + DEPLOYMENT_PARAMETERS ) @@ -186,7 +187,7 @@ def write_nfd_bicep_file(self) -> None: ) bicep_contents: str = template.render( - deployParametersPath="schemas/deploymentParameters.json", + deployParametersPath = os.path.join(SCHEMAS,DEPLOYMENT_PARAMETERS), nf_application_configurations=self.nf_application_configurations, ) @@ -196,7 +197,7 @@ def write_nfd_bicep_file(self) -> None: def write_schema_to_file(self) -> None: """Write the schema to file deploymentParameters.json.""" - full_schema = os.path.join(self._tmp_folder_name, "deploymentParameters.json") + full_schema = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS) with open(full_schema, "w", encoding="UTF-8") as f: json.dump(self.deployment_parameter_schema, f, indent=4) @@ -206,29 +207,31 @@ def copy_to_output_folder(self) -> None: logger.info("Create NFD bicep %s", self.output_folder_name) os.mkdir(self.output_folder_name) - os.mkdir(self.output_folder_name + "/" + SCHEMAS) + os.mkdir(os.path.join(self.output_folder_name, SCHEMAS)) - nfd_bicep_path = os.path.join( + tmp_nfd_bicep_path = os.path.join( self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE ) - shutil.copy(nfd_bicep_path, self.output_folder_name) + shutil.copy(tmp_nfd_bicep_path, self.output_folder_name) - manifest_bicep_path = os.path.join( + tmp_manifest_bicep_path = os.path.join( self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE ) - shutil.copy(manifest_bicep_path, self.output_folder_name) + shutil.copy(tmp_manifest_bicep_path, self.output_folder_name) - config_mappings_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS) + tmp_config_mappings_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS) + output_config_mappings_path = os.path.join(self.output_folder_name, CONFIG_MAPPINGS) shutil.copytree( - config_mappings_path, - self.output_folder_name + "/" + CONFIG_MAPPINGS, + tmp_config_mappings_path, + output_config_mappings_path, dirs_exist_ok=True, ) - full_schema = os.path.join(self._tmp_folder_name, "deploymentParameters.json") + tmp_schema_path = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS) + output_schema_path = os.path.join(self.output_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS) shutil.copy( - full_schema, - self.output_folder_name + "/" + SCHEMAS + "/deploymentParameters.json", + tmp_schema_path, + output_schema_path, ) def generate_nf_application_config( diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index 90133fe95a0..cc9c43117bf 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -23,7 +23,8 @@ VNF_MANIFEST_BICEP_TEMPLATE, CONFIG_MAPPINGS, SCHEMAS, - SCHEMA_PREFIX + SCHEMA_PREFIX, + DEPLOYMENT_PARAMETERS ) @@ -124,7 +125,7 @@ def write_deployment_parameters(self, folder_path: str) -> None: } deployment_parameters_path = os.path.join( - folder_path, "deploymentParameters.json" + folder_path, DEPLOYMENT_PARAMETERS ) # Heading for the deployParameters schema @@ -193,16 +194,18 @@ def copy_to_output_folder(self) -> None: manifest_path = os.path.join(code_dir, "templates", self.manifest_template_name) shutil.copy(manifest_path, self.output_folder_name) - os.mkdir(self.output_folder_name + "/" + SCHEMAS) - full_schema = os.path.join(self.tmp_folder_name, SCHEMAS, "deploymentParameters.json") + os.mkdir(os.path.join(self.output_folder_name, SCHEMAS)) + tmp_schema_path = os.path.join(self.tmp_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS) + output_schema_path = os.path.join(self.output_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS) shutil.copy( - full_schema, - self.output_folder_name + "/" + SCHEMAS + "/deploymentParameters.json", + tmp_schema_path, + output_schema_path, ) - config_mappings_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) + tmp_config_mappings_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) + output_config_mappings_path = os.path.join(self.output_folder_name, CONFIG_MAPPINGS) shutil.copytree( - config_mappings_path, - self.output_folder_name + "/" + CONFIG_MAPPINGS, + tmp_config_mappings_path, + output_config_mappings_path, dirs_exist_ok=True, ) \ No newline at end of file diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index f196d32a7ae..844815342c6 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -20,6 +20,7 @@ CNF_DEFINITION_BICEP_TEMPLATE = "cnfdefinition.bicep" CNF_MANIFEST_BICEP_TEMPLATE = "cnfartifactmanifest.bicep" +DEPLOYMENT_PARAMETERS = "deploymentParameters.json" # Names of folder used in the repo CONFIG_MAPPINGS = "configMappings" SCHEMAS = "schemas" From e63f1996c1282eb01b5d6e9b2677ac45dcc81426 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 25 May 2023 13:37:38 +0100 Subject: [PATCH 079/145] added error catching for get chart name and version --- .../azext_aosm/generate_nfd/cnf_nfd_generator.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 8d55a44ff3e..e4a76c5e59d 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -13,7 +13,7 @@ import tempfile import yaml from jinja2 import Template, StrictUndefined -from azure.cli.core.azclierror import InvalidTemplateError +from azure.cli.core.azclierror import InvalidTemplateError, FileOperationError from knack.log import get_logger from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator @@ -387,11 +387,18 @@ def get_chart_name_and_version( ) -> Tuple[str, str]: """Get the name and version of the chart.""" chart = os.path.join(self._tmp_folder_name, helm_package.name, "Chart.yaml") - + + if not os.path.exists(chart): + raise InvalidTemplateError(f"There is no Chart.yaml file in the helm package '{helm_package.name}'. Please fix this and run the command again.") + + with open(chart, "r", encoding="utf-8") as f: data = yaml.load(f, Loader=yaml.FullLoader) - chart_name = data["name"] - chart_version = data["version"] + if 'name' in data and 'version' in data: + chart_name = data["name"] + chart_version = data["version"] + else: + raise FileOperationError(f"A name or version is missing from Chart.yaml in the helm package '{helm_package.name}'. Please fix this and run the command again.") return (chart_name, chart_version) From 2dee8c40072eb9a278e0dfcaaa35232e0c273f41 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 25 May 2023 17:07:21 +0100 Subject: [PATCH 080/145] added meaningful logs; prevent auto overwriting input.json --- src/aosm/azext_aosm/_configuration.py | 4 ++-- src/aosm/azext_aosm/custom.py | 9 +++++++- .../generate_nfd/cnf_nfd_generator.py | 21 ++++++++++++++++++- .../generate_nfd/vnf_nfd_generator.py | 13 +++++++++--- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index a4f69ae8a1c..b5bb1974277 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -15,9 +15,9 @@ ), "nf_name": "Name of NF definition", "version": "Version of the NF definition", - "acr_artifact_store_name": "Name of the ACR Artifact Store resource", + "acr_artifact_store_name": "Name of the ACR Artifact Store resource. Will be created if it does not exist.", "location": "Azure location to use when creating resources", - "blob_artifact_store_name": "Name of the storage account Artifact Store resource", + "blob_artifact_store_name": "Name of the storage account Artifact Store resource. Will be created if it does not exist.", "artifact_name": "Name of the artifact", "file_path": ( "Optional. File path of the artifact you wish to upload from your " diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 12bf872bae6..ca905a509b7 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -221,7 +221,14 @@ def _generate_config(definition_type: str, output_file: str = "input.json"): """ config = get_configuration(definition_type) config_as_dict = json.dumps(asdict(config), indent=4) - + + if os.path.exists(output_file): + carry_on = input( + f"The file {output_file} already exists - do you want to overwrite it? (y/n)" + ) + if carry_on != "y": + raise UnclassifiedUserFault("User aborted!") + with open(output_file, "w", encoding="utf-8") as f: f.write(config_as_dict) if definition_type == CNF or definition_type == VNF: diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index e4a76c5e59d..d1b0721da2a 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -147,6 +147,9 @@ def _extract_chart(self, path: str) -> None: :param path: The path to helm package """ + + logger.debug("Extracting helm package %s", path) + (_, ext) = os.path.splitext(path) if ext == ".gz" or ext == ".tgz": tar = tarfile.open(path, "r:gz") @@ -177,6 +180,8 @@ def write_manifest_bicep_file(self) -> None: path = os.path.join(self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE) with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) + + logger.info("Created artifact manifest bicep template: %s", path) def write_nfd_bicep_file(self) -> None: """Write the bicep file for the NFD.""" @@ -194,19 +199,26 @@ def write_nfd_bicep_file(self) -> None: path = os.path.join(self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE) with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) + + logger.info("Created NFD bicep template: %s", path) def write_schema_to_file(self) -> None: """Write the schema to file deploymentParameters.json.""" + + logger.debug("Create deploymentParameters.json") + full_schema = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS) with open(full_schema, "w", encoding="UTF-8") as f: json.dump(self.deployment_parameter_schema, f, indent=4) + + logger.debug(f"{full_schema} created") def copy_to_output_folder(self) -> None: """Copy the config mappings, schema and bicep templates (artifact manifest and NFDV) to the output folder.""" logger.info("Create NFD bicep %s", self.output_folder_name) - os.mkdir(self.output_folder_name) + os.mkdir(self.output_folder_name) os.mkdir(os.path.join(self.output_folder_name, SCHEMAS)) tmp_nfd_bicep_path = os.path.join( @@ -233,6 +245,8 @@ def copy_to_output_folder(self) -> None: tmp_schema_path, output_schema_path, ) + + logger.info("Copied files to %s", self.output_folder_name) def generate_nf_application_config( self, @@ -323,6 +337,9 @@ def get_chart_mapping_schema( param helm_package: The helm package config. """ + + logger.debug("Get chart mapping schema for %s", helm_package.name) + non_def_values = os.path.join( self._tmp_folder_name, helm_package.name, "values.mappings.yaml" ) @@ -349,6 +366,7 @@ def get_chart_mapping_schema( f"ERROR: Your schema and values for the helm package '{helm_package.name}' do not match. Please fix this and run the command again." ) from e + logger.debug("Generated chart mapping schema for %s", helm_package.name) return final_schema def find_deploy_params( @@ -422,4 +440,5 @@ def generate_parameter_mappings(self, helm_package: HelmPackageConfig) -> str: with open(mapping_file_path, "w", encoding="utf-8") as file: json.dump(data, file, indent=4) + logger.debug("Generated parameter mappings for %s", helm_package.name) return os.path.join(CONFIG_MAPPINGS, mappings_filename) diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index cc9c43117bf..271b21f8e8b 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -97,8 +97,13 @@ def manifest_path(self) -> Optional[str]: def vm_parameters(self) -> Dict[str, Any]: """The parameters from the VM ARM template.""" with open(self.arm_template_path, "r") as _file: - parameters: Dict[str, Any] = json.load(_file)["parameters"] - + data = json.load(_file) + if "parameters" in data: + parameters: Dict[str, Any] = data["parameters"] + else: + print("No parameters found in the template provided. Your schema will have no properties") + parameters = {} + return parameters def create_parameter_files(self) -> None: @@ -208,4 +213,6 @@ def copy_to_output_folder(self) -> None: tmp_config_mappings_path, output_config_mappings_path, dirs_exist_ok=True, - ) \ No newline at end of file + ) + + logger.info("Copied files to %s", self.output_folder_name) \ No newline at end of file From bb6302aac9fcba48a7dfda7ef9d011e0f80a3d2e Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 26 May 2023 12:40:54 +0100 Subject: [PATCH 081/145] edited vnf schema to have accepted types --- .../azext_aosm/generate_nfd/cnf_nfd_generator.py | 3 +++ .../azext_aosm/generate_nfd/vnf_nfd_generator.py | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index d1b0721da2a..ce71213c971 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -79,7 +79,10 @@ def generate_nfd(self) -> None: self._tmp_folder_name = tmpdirname try: for helm_package in self.config.helm_packages: + + # Turn Any type into HelmPackageConfig, to access properties on the object helm_package = HelmPackageConfig(**helm_package) + # Unpack the chart into the tmp folder self._extract_chart(helm_package.path_to_chart) diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index 271b21f8e8b..c00083aff35 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -125,9 +125,18 @@ def write_deployment_parameters(self, folder_path: str) -> None: """ logger.debug("Create deploymentParameters.json") - nfd_parameters: Dict[str, Any] = { - key: {"type": self.vm_parameters[key]["type"]} for key in self.vm_parameters - } + nfd_parameters = {} + + for key in self.vm_parameters: + # ARM templates allow int and secureString but we do not currently accept them in AOSM + # This may change, but for now we should change them to accepted types integer and string + if self.vm_parameters[key]["type"] == "int": + nfd_parameters[key] = {"type": "integer"} + elif self.vm_parameters[key]["type"] == "secureString": + nfd_parameters[key] = {"type": "string"} + else: + nfd_parameters[key] = {"type": self.vm_parameters[key]["type"]} + deployment_parameters_path = os.path.join( folder_path, DEPLOYMENT_PARAMETERS From d5b03c67c22e3ef4d15bbc1ef1416bd401df8ee4 Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 26 May 2023 12:46:03 +0100 Subject: [PATCH 082/145] added templates to setup.py --- src/aosm/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aosm/setup.py b/src/aosm/setup.py index 9cd195a21b2..7eafe07b30b 100644 --- a/src/aosm/setup.py +++ b/src/aosm/setup.py @@ -56,5 +56,5 @@ classifiers=CLASSIFIERS, packages=find_packages(), install_requires=DEPENDENCIES, - package_data={"azext_aosm": ["azext_metadata.json"]}, + package_data={"azext_aosm": ["azext_metadata.json", "generate_nfd/templates/*"]}, ) From d7f1b7af1b2411096e783368533632a43e66f2cf Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 26 May 2023 17:26:47 +0100 Subject: [PATCH 083/145] added location from input file not resourceGroup().location --- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 2 ++ .../generate_nfd/templates/cnfartifactmanifest.bicep.j2 | 2 +- .../azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 | 2 +- .../generate_nfd/templates/vnfartifactmanifests.bicep | 2 +- src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index fa7e9877c83..5a3cf59caa1 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -178,6 +178,7 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: """ assert isinstance(self.config, VNFConfiguration) return { + "location" : {"value": self.config.location}, "publisherName": {"value": self.config.publisher_name}, "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, @@ -196,6 +197,7 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: """ assert isinstance(self.config, VNFConfiguration) return { + "location" : {"value": self.config.location}, "publisherName": {"value": self.config.publisher_name}, "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 b/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 index 3027b2c25cf..c9c475cf010 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfartifactmanifest.bicep.j2 @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // This file creates an Artifact Manifest for a CNF -param location string = resourceGroup().location +param location string @description('Name of an existing publisher, expected to be in the resource group where you deploy the template') param publisherName string @description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 index 0f57950481e..307f0903c32 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // This file creates an NF definition for a CNF -param location string = resourceGroup().location +param location string @description('Name of an existing publisher, expected to be in the resource group where you deploy the template') param publisherName string @description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep index 20e7d5e2e2b..611b5d79184 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // This file creates an NF definition for a VNF -param location string = resourceGroup().location +param location string @description('Name of an existing publisher, expected to be in the resource group where you deploy the template') param publisherName string @description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep index 87f3b93e15f..7f98fcf55be 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // This file creates an NF definition for a VNF -param location string = resourceGroup().location +param location string @description('Name of an existing publisher, expected to be in the resource group where you deploy the template') param publisherName string @description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') From ab95a7ca79478f13169b502c1de233d244179ccd Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 2 Jun 2023 13:24:01 +0100 Subject: [PATCH 084/145] added path_to_mappings to input.json; added logic to take mappings from file outside of helm package --- src/aosm/README.md | 2 ++ src/aosm/azext_aosm/_configuration.py | 4 ++++ .../azext_aosm/generate_nfd/cnf_nfd_generator.py | 12 +++++++----- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/aosm/README.md b/src/aosm/README.md index 34f32cfbf36..6ef13b0a53c 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -73,6 +73,7 @@ For CNFs, you must provide helm packages with an associated schema. When filling { "name": "A", "path_to_chart": "Path to package A", + "path_to_mappings": "Path to package A mappings", "depends_on": [ "Names of the Helm packages this package depends on" ] @@ -80,6 +81,7 @@ For CNFs, you must provide helm packages with an associated schema. When filling { "name": "B", "path_to_chart": "Path to package B", + "path_to_mappings": "Path to package B mappings", "depends_on": [ "Names of the Helm packages this package depends on" ] diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index b5bb1974277..aabdcfdde6a 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -35,6 +35,9 @@ "path_to_chart": ( "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz" ), + "path_to_mappings": ( + "File path of value mappings on local disk. Accepts .yaml or .yml" + ), "helm_depends_on": ( "Names of the Helm packages this package depends on. " "Leave as an empty array if no dependencies" @@ -149,6 +152,7 @@ def build_output_folder_name(self) -> str: class HelmPackageConfig: name: str = DESCRIPTION_MAP["helm_package_name"] path_to_chart: str = DESCRIPTION_MAP["path_to_chart"] + path_to_mappings: str = DESCRIPTION_MAP["path_to_mappings"] depends_on: List[str] = field( default_factory=lambda: [DESCRIPTION_MAP["helm_depends_on"]] ) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index ce71213c971..55d0cc58311 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -343,16 +343,18 @@ def get_chart_mapping_schema( logger.debug("Get chart mapping schema for %s", helm_package.name) - non_def_values = os.path.join( - self._tmp_folder_name, helm_package.name, "values.mappings.yaml" - ) + non_def_values = helm_package.path_to_mappings values_schema = os.path.join( self._tmp_folder_name, helm_package.name, "values.schema.json" ) - if not os.path.exists(non_def_values) or not os.path.exists(values_schema): + if not os.path.exists(non_def_values): + raise InvalidTemplateError( + f"ERROR: The helm package '{helm_package.name}' does not have a valid values mappings file. The file at '{helm_package.path_to_mappings}' does not exist.\nPlease fix this and run the command again." + ) + if not os.path.exists(values_schema): raise InvalidTemplateError( - f"ERROR: The helm package '{helm_package.name}' is missing either values.mappings.yaml or values.schema.json. Please fix this and run the command again." + f"ERROR: The helm package '{helm_package.name}' is missing values.schema.json. Please fix this and run the command again." ) with open(non_def_values, "r", encoding="utf-8") as stream: From 65ac401c290b6a72ee1da5dc193213d312dc72f8 Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 2 Jun 2023 14:04:08 +0100 Subject: [PATCH 085/145] renamed non_def_values to mappings_path --- src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 55d0cc58311..bb7f889e35e 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -343,12 +343,12 @@ def get_chart_mapping_schema( logger.debug("Get chart mapping schema for %s", helm_package.name) - non_def_values = helm_package.path_to_mappings + mappings_path = helm_package.path_to_mappings values_schema = os.path.join( self._tmp_folder_name, helm_package.name, "values.schema.json" ) - if not os.path.exists(non_def_values): + if not os.path.exists(mappings_path): raise InvalidTemplateError( f"ERROR: The helm package '{helm_package.name}' does not have a valid values mappings file. The file at '{helm_package.path_to_mappings}' does not exist.\nPlease fix this and run the command again." ) @@ -357,7 +357,7 @@ def get_chart_mapping_schema( f"ERROR: The helm package '{helm_package.name}' is missing values.schema.json. Please fix this and run the command again." ) - with open(non_def_values, "r", encoding="utf-8") as stream: + with open(mappings_path, "r", encoding="utf-8") as stream: values_data = yaml.load(stream, Loader=yaml.SafeLoader) with open(values_schema, "r", encoding="utf-8") as f: From dda595788592b135850f29dfa662293bd23c3fee Mon Sep 17 00:00:00 2001 From: patrykkulik-microsoft <116072282+patrykkulik-microsoft@users.noreply.github.com> Date: Fri, 2 Jun 2023 18:20:50 +0100 Subject: [PATCH 086/145] Pk5/add nsd cli (#15) * First working version of the CLI NSD create * Fully working version of the NSD CLI * minor change to nsd_generate * Sunny's refactor * First round of cleanup * Secound Round of cleanup * fix the 2023 api NSDV * description updates * deleted comment * Fix SNS creation * Fix SNS creation try 2 * markups * delete unnecessary file * Testing markups * Fix the SNS attempt 3 * minor fixes * Fix config validation --- src/aosm/README.md | 42 +++- src/aosm/azext_aosm/_configuration.py | 159 ++++++++++++- src/aosm/azext_aosm/_params.py | 13 +- src/aosm/azext_aosm/custom.py | 197 +++++++++++----- src/aosm/azext_aosm/delete/delete.py | 83 ++++++- src/aosm/azext_aosm/deploy/artifact.py | 3 +- .../azext_aosm/deploy/artifact_manifest.py | 4 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 213 ++++++++++++++--- src/aosm/azext_aosm/deploy/pre_deploy.py | 38 ++- .../generate_nfd/vnf_nfd_generator.py | 54 +++-- .../azext_aosm/generate_nsd/nsd_generator.py | 222 ++++++++++++++++++ .../artifact_manifest_template.bicep | 39 +++ .../generate_nsd/templates/nf_template.bicep | 42 ++++ .../generate_nsd/templates/nsd_template.bicep | 117 +++++++++ src/aosm/azext_aosm/util/constants.py | 24 +- src/aosm/setup.py | 8 +- 16 files changed, 1108 insertions(+), 150 deletions(-) create mode 100644 src/aosm/azext_aosm/generate_nsd/nsd_generator.py create mode 100644 src/aosm/azext_aosm/generate_nsd/templates/artifact_manifest_template.bicep create mode 100644 src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep create mode 100644 src/aosm/azext_aosm/generate_nsd/templates/nsd_template.bicep diff --git a/src/aosm/README.md b/src/aosm/README.md index 6ef13b0a53c..a4df5c59b07 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -87,8 +87,14 @@ For CNFs, you must provide helm packages with an associated schema. When filling ] }, +#### NSDs +For NSDs, you will need to have a Resource Group with a deployed Publisher, Artifact Store, Network Function Definition and Network Function Definition Version. You can use the `az aosm nfd` commands to create all of these resources. + + ### Command examples +#### NFDs + Get help on command arguments `az aosm -h` @@ -109,10 +115,6 @@ Build an nfd definition locally `az aosm nfd build --config-file input.json` -Build and publish a definition - -`az aosm nfd build --config-file input.json --publish` - Publish a pre-built definition `az aosm nfd publish --config-file input.json` @@ -125,6 +127,34 @@ Delete a published definition and the publisher, artifact stores and NFD group `az aosm nfd delete --config-file input.json --clean` -Coming soon: +#### NSDs + +Get help on command arguments + +`az aosm -h` +`az aosm nsd -h` +`az aosm nsd build -h` +etc... + +Create an example config file for building a definition + +`az aosm nsd generate-config` + +This will output a file called `input.json` which must be filled in. +Once the config file has been filled in the following commands can be run. + +Build an nsd locally + +`az aosm nsd build --config-file input.json` + +Publish a pre-built design + +`az aosm nsd publish --config-file input.json` + +Delete a published design + +`az aosm nsd delete --config-file input.json` + +Delete a published design and the publisher, artifact stores and NSD group -`az aosm nsd build` and further nsd commands. +`az aosm nsd delete --config-file input.json --clean` \ No newline at end of file diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index aabdcfdde6a..4778f925bf7 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -2,7 +2,16 @@ from typing import Dict, Optional, Any, List from pathlib import Path from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError -from azext_aosm.util.constants import DEFINITION_OUTPUT_BICEP_PREFIX, VNF, CNF, NSD +from azext_aosm.util.constants import ( + DEFINITION_OUTPUT_BICEP_PREFIX, + VNF, + CNF, + NSD, + SCHEMA, + NSD_DEFINITION_OUTPUT_BICEP_PREFIX, + NF_DEFINITION_JSON_FILE, +) +import os DESCRIPTION_MAP: Dict[str, str] = { "publisher_resource_group_name": ( @@ -13,10 +22,14 @@ "Name of the Publisher resource you want your definition " "published to. Will be created if it does not exist." ), + "publisher_name_nsd": ( + "Name of the Publisher resource you want your design published to. This published should be the same as the publisher used for your NFDVs" + ), + "publisher_resource_group_name_nsd": ("Resource group for the Publisher resource."), "nf_name": "Name of NF definition", "version": "Version of the NF definition", "acr_artifact_store_name": "Name of the ACR Artifact Store resource. Will be created if it does not exist.", - "location": "Azure location to use when creating resources", + "location": "Azure location to use when creating resources.", "blob_artifact_store_name": "Name of the storage account Artifact Store resource. Will be created if it does not exist.", "artifact_name": "Name of the artifact", "file_path": ( @@ -31,6 +44,13 @@ "Version of the artifact. For VHDs this must be in format A-B-C. " "For ARM templates this must be in format A.B.C" ), + "nsdv_description": "Description of the NSDV", + "nsdg_name": "Network Service Design Group Name. This is the collection of Network Service Design Versions. Will be " + "created if it does not exist.", + "nsd_version": "Version of the NSD to be created. This should be in the format A.B.C", + "network_function_definition_group_name": "Exising Network Function Definition Group Name. This can be created using the 'az aosm nfd' commands.", + "network_function_definition_version_name": "Exising Network Function Definition Version Name. This can be created using the 'az aosm nfd' commands.", + "network_function_definition_offering_location": "Offering location of the Network Function Definition", "helm_package_name": "Name of the Helm package", "path_to_chart": ( "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz" @@ -41,7 +61,7 @@ "helm_depends_on": ( "Names of the Helm packages this package depends on. " "Leave as an empty array if no dependencies" - ) + ), } @@ -77,6 +97,123 @@ def acr_manifest_name(self) -> str: return f"{self.nf_name}-acr-manifest-{self.version.replace('.', '-')}" +@dataclass +class NSConfiguration: + location: str = DESCRIPTION_MAP["location"] + publisher_name: str = DESCRIPTION_MAP["publisher_name_nsd"] + publisher_resource_group_name: str = DESCRIPTION_MAP[ + "publisher_resource_group_name_nsd" + ] + acr_artifact_store_name: str = DESCRIPTION_MAP["acr_artifact_store_name"] + network_function_definition_group_name: str = DESCRIPTION_MAP[ + "network_function_definition_group_name" + ] + network_function_definition_version_name: str = DESCRIPTION_MAP[ + "network_function_definition_version_name" + ] + network_function_definition_offering_location: str = DESCRIPTION_MAP[ + "network_function_definition_offering_location" + ] + nsdg_name: str = DESCRIPTION_MAP["nsdg_name"] + nsd_version: str = DESCRIPTION_MAP["nsd_version"] + nsdv_description: str = DESCRIPTION_MAP["nsdv_description"] + + def __post_init__(self): + """ + Cope with deserializing subclasses from dicts to ArtifactConfig. + + Used when creating VNFConfiguration object from a loaded json config file. + """ + if isinstance(self.arm_template, dict): + self.arm_template = ArtifactConfig(**self.arm_template) + + def validate(self): + ## validate that all of the configuration parameters are set + + if self.location == DESCRIPTION_MAP["location"] or "": + raise ValueError("Location must be set") + if self.publisher_name == DESCRIPTION_MAP["publisher_name_nsd"] or "": + raise ValueError("Publisher name must be set") + if ( + self.publisher_resource_group_name + == DESCRIPTION_MAP["publisher_resource_group_name_nsd"] + or "" + ): + raise ValueError("Publisher resource group name must be set") + if ( + self.acr_artifact_store_name == DESCRIPTION_MAP["acr_artifact_store_name"] + or "" + ): + raise ValueError("ACR Artifact Store name must be set") + if ( + self.network_function_definition_group_name + == DESCRIPTION_MAP["network_function_definition_group_name"] + or "" + ): + raise ValueError("Network Function Definition Group name must be set") + if ( + self.network_function_definition_version_name + == DESCRIPTION_MAP["network_function_definition_version_name"] + or "" + ): + raise ValueError("Network Function Definition Version name must be set") + if ( + self.network_function_definition_offering_location + == DESCRIPTION_MAP["network_function_definition_offering_location"] + or "" + ): + raise ValueError( + "Network Function Definition Offering Location must be set" + ) + if self.nsdg_name == DESCRIPTION_MAP["nsdg_name"] or "": + raise ValueError("NSDG name must be set") + if self.nsd_version == DESCRIPTION_MAP["nsd_version"] or "": + raise ValueError("NSD Version must be set") + + @property + def build_output_folder_name(self) -> str: + """Return the local folder for generating the bicep template to.""" + current_working_directory = os.getcwd() + return f"{current_working_directory}/{NSD_DEFINITION_OUTPUT_BICEP_PREFIX}" + + @property + def resource_element_name(self) -> str: + """Return the name of the resource element.""" + artifact_name = self.arm_template.artifact_name + return f"{artifact_name}-resource-element" + + @property + def network_function_name(self) -> str: + """Return the name of the NFVI used for the NSDV.""" + return f"{self.nsdg_name}_NF" + + @property + def acr_manifest_name(self) -> str: + """Return the ACR manifest name from the NFD name.""" + return f"{self.network_function_name.lower().replace('_', '-')}-acr-manifest-{self.nsd_version.replace('.', '-')}" + + @property + def nfvi_site_name(self) -> str: + """Return the name of the NFVI used for the NSDV.""" + return f"{self.nsdg_name}_NFVI" + + @property + def cg_schema_name(self) -> str: + """Return the name of the Configuration Schema used for the NSDV.""" + return f"{self.nsdg_name.replace('-', '_')}_ConfigGroupSchema" + + @property + def arm_template(self) -> ArtifactConfig: + """Return the parameters of the ARM template to be uploaded as part of the NSDV.""" + artifact = ArtifactConfig() + artifact.artifact_name = f"{self.nsdg_name.lower()}_nf_artifact" + artifact.version = self.nsd_version + artifact.file_path = os.path.join( + self.build_output_folder_name, NF_DEFINITION_JSON_FILE + ) + return artifact + + @dataclass class VNFConfiguration(NFConfiguration): blob_artifact_store_name: str = DESCRIPTION_MAP["blob_artifact_store_name"] @@ -143,9 +280,7 @@ def sa_manifest_name(self) -> str: def build_output_folder_name(self) -> str: """Return the local folder for generating the bicep template to.""" arm_template_path = self.arm_template.file_path - return ( - f"{DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" - ) + return f"{DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" @dataclass @@ -179,17 +314,17 @@ def build_output_folder_name(self) -> str: def get_configuration( - definition_type: str, config_as_dict: Optional[Dict[Any, Any]] = None -) -> NFConfiguration: + configuration_type: str, config_as_dict: Optional[Dict[Any, Any]] = None +) -> NFConfiguration or NSConfiguration: if config_as_dict is None: config_as_dict = {} - if definition_type == VNF: + if configuration_type == VNF: config = VNFConfiguration(**config_as_dict) - elif definition_type == CNF: + elif configuration_type == CNF: config = CNFConfiguration(**config_as_dict) - elif definition_type == NSD: - config = NFConfiguration(**config_as_dict) + elif configuration_type == NSD: + config = NSConfiguration(**config_as_dict) else: raise InvalidArgumentValueError( "Definition type not recognized, options are: vnf, cnf or nsd" diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index 2098f52876e..840dda18b6e 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -21,6 +21,7 @@ def load_arguments(self: AzCommandsLoader, _): # Set the argument context so these options are only available when this specific command # is called. + with self.argument_context("aosm nfd") as c: c.argument( "definition_type", arg_type=definition_type, help="Type of AOSM definition." @@ -44,6 +45,13 @@ def load_arguments(self: AzCommandsLoader, _): completer=FilesCompleter(allowednames="*.json"), help="Optional path to a bicep file to publish. Use to override publish of the built definition with an alternative file.", ) + c.argument( + "design_file", + options_list=["--design-file", "-b"], + type=file_type, + completer=FilesCompleter(allowednames="*.bicep"), + help="Optional path to a bicep file to publish. Use to override publish of the built design with an alternative file.", + ) c.argument( "parameters_json_file", options_list=["--parameters-file", "-p"], @@ -74,8 +82,3 @@ def load_arguments(self: AzCommandsLoader, _): completer=FilesCompleter(allowednames="*.json"), help="The path to the configuration file.", ) - c.argument( - "clean", - arg_type=get_three_state_flag(), - help="Also delete artifact stores, NFD Group and Publisher. Use with care.", - ) diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index ca905a509b7..ed8e708e9d6 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -9,10 +9,15 @@ from dataclasses import asdict from typing import Optional from knack.log import get_logger -from azure.cli.core.azclierror import CLIInternalError, InvalidArgumentValueError, UnclassifiedUserFault +from azure.cli.core.azclierror import ( + CLIInternalError, + InvalidArgumentValueError, + UnclassifiedUserFault, +) from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator +from azext_aosm.generate_nsd.nsd_generator import NSDGenerator from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator from azext_aosm.delete.delete import ResourceDeleter from azext_aosm.deploy.deploy_with_arm import DeployerViaArm @@ -23,22 +28,30 @@ from azext_aosm._configuration import ( get_configuration, NFConfiguration, + NSConfiguration, ) logger = get_logger(__name__) -def build_definition(cmd, definition_type: str, config_file: str): +def build_definition( + definition_type: str, + config_file: str, +): """ - Build and optionally publish a definition. + Build a definition. - :param cmd: + :param cmd: + :type cmd: _type_ :param config_file: path to the file - :param definition_type: VNF or CNF + :param definition_type: VNF, CNF """ + # Read the config from the given file - config = _get_config_from_file(config_file, definition_type) + config = _get_config_from_file( + config_file=config_file, configuration_type=definition_type + ) # Generate the NFD and the artifact manifest. _generate_nfd(definition_type=definition_type, config=config) @@ -48,17 +61,16 @@ def generate_definition_config(definition_type: str, output_file: str = "input.j """ Generate an example config file for building a definition. - :param definition_type: CNF, VNF or NSD :param output_file: path to output config - file, defaults to "input.json" :type output_ - file: - :param definition_type: CNF, VNF or NSD + :param definition_type: CNF, VNF :param output_file: path to output config file, defaults to "input.json" :type output_file: str, optional """ - _generate_config(definition_type, output_file) + _generate_config(configuration_type=definition_type, output_file=output_file) -def _get_config_from_file(config_file: str, definition_type: str) -> NFConfiguration: +def _get_config_from_file( + config_file: str, configuration_type: str +) -> NFConfiguration or NSConfiguration: """ Read input config file JSON and turn it into a Configuration object. @@ -66,14 +78,15 @@ def _get_config_from_file(config_file: str, definition_type: str) -> NFConfigura :param definition_type: VNF, CNF or NSD :rtype: Configuration """ - + if not os.path.exists(config_file): - raise InvalidArgumentValueError(f"Config file {config_file} not found. Please specify a valid config file path.") - + raise InvalidArgumentValueError( + f"Config file {config_file} not found. Please specify a valid config file path." + ) + with open(config_file, "r", encoding="utf-8") as f: config_as_dict = json.loads(f.read()) - - config = get_configuration(definition_type, config_as_dict) + config = get_configuration(configuration_type, config_as_dict) return config @@ -148,7 +161,9 @@ def publish_definition( api_clients = ApiClients( aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) ) - config = _get_config_from_file(config_file, definition_type) + config = _get_config_from_file( + config_file=config_file, configuration_type=definition_type + ) if definition_type == VNF: deployer = DeployerViaArm(api_clients, config=config) deployer.deploy_vnfd_from_bicep( @@ -180,7 +195,9 @@ def delete_published_definition( Defaults to False. Only works if no resources have those as a parent. Use with care. """ - config = _get_config_from_file(config_file, definition_type) + config = _get_config_from_file( + config_file=config_file, configuration_type=definition_type + ) api_clients = ApiClients( aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) @@ -198,40 +215,32 @@ def delete_published_definition( def generate_design_config(output_file: str = "input.json"): """ Generate an example config file for building a NSD. - - :param output_file: path to output config file, defaults to "input.json" :type - output_ - file: :param output_file: path to output config file, defaults to "input.json" :type output_file: str, optional """ _generate_config(NSD, output_file) -def _generate_config(definition_type: str, output_file: str = "input.json"): +def _generate_config(configuration_type: str, output_file: str = "input.json"): """ Generic generate config function for NFDs and NSDs. - - :param definition_type: CNF, VNF or NSD :param output_file: path to output config - file, defaults to "input.json" :type output_ - file: - :param definition_type: CNF, VNF or NSD + :param configuration_type: CNF, VNF or NSD :param output_file: path to output config file, defaults to "input.json" :type output_file: str, optional """ - config = get_configuration(definition_type) + config = get_configuration(configuration_type) config_as_dict = json.dumps(asdict(config), indent=4) - + if os.path.exists(output_file): carry_on = input( f"The file {output_file} already exists - do you want to overwrite it? (y/n)" ) if carry_on != "y": raise UnclassifiedUserFault("User aborted!") - + with open(output_file, "w", encoding="utf-8") as f: f.write(config_as_dict) - if definition_type == CNF or definition_type == VNF: + if configuration_type == CNF or configuration_type == VNF: prtName = "definition" else: prtName = "design" @@ -241,53 +250,127 @@ def _generate_config(definition_type: str, output_file: str = "input.json"): def build_design(cmd, client: HybridNetworkManagementClient, config_file: str): """ - Build and optionally publish a Network Service Design. - - :param cmd: :type cmd: _type_ :param client: :type client: - HybridNetworkManagementClient :param config_ - file: - :param cmd: + Build a Network Service Design. + :param cmd: :type cmd: _type_ - :param client: + :param client: :type client: HybridNetworkManagementClient :param config_file: path to the file """ - raise NotImplementedError("Build design is not yet implented for NSD") + + api_clients = ApiClients( + aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) + ) + + # Read the config from the given file + config = _get_config_from_file(config_file=config_file, configuration_type=NSD) + + config.validate() + + # Generate the NSD and the artifact manifest. + # This function should not be taking deploy parameters + _generate_nsd( + config=config, + api_clients=api_clients, + ) def delete_published_design( cmd, client: HybridNetworkManagementClient, config_file, - clean=False, ): """ Delete a published NSD. - - :param definition_type: CNF or VNF :param config_file: Path to the config file - :param clean: if True, will delete the NFDG, artifact stores and publisher too. - Defaults to False. Only works if no resources have those as a parent. Use - with care. + :param clean: if True, will delete the NSDG, artifact stores and publisher too. + Defaults to False. Only works if no resources have those as a parent. + Use with care. """ - raise NotImplementedError("Delete published design is not yet implented for NSD") + config = _get_config_from_file(config_file=config_file, configuration_type=NSD) + + api_clients = ApiClients( + aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) + ) + + destroyer = ResourceDeleter(api_clients, config) + destroyer.delete_nsd() def publish_design( cmd, client: HybridNetworkManagementClient, config_file, + design_file: Optional[str] = None, + parameters_json_file: Optional[str] = None, + manifest_file: Optional[str] = None, + manifest_parameters_json_file: Optional[str] = None, ): """ Publish a generated design. - - :param cmd: :param client: :type client: HybridNetworkManagementClient :param - definition_type: VNF or CNF :param config_ - file: - :param cmd: - :param client: + :param cmd: + :param client: :type client: HybridNetworkManagementClient - :param definition_type: VNF or CNF - :param config_file: Path to the config file for the NFDV + :param config_file: Path to the config file for the NSDV + :param design_file: Optional path to an override bicep template to deploy the NSDV. + :param parameters_json_file: Optional path to a parameters file for the bicep file, + in case the user wants to edit the built NSDV template. If + omitted, parameters from config will be turned into parameters + for the bicep file + :param manifest_file: Optional path to an override bicep template to deploy + manifests + :param manifest_parameters_json_file: Optional path to an override bicep parameters + file for manifest parameters """ - raise NotImplementedError("Publishing design is not yet implemented for NSD") + + print("Publishing design.") + api_clients = ApiClients( + aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) + ) + + config = _get_config_from_file(config_file=config_file, configuration_type=NSD) + + config.validate() + + deployer = DeployerViaArm(api_clients, config=config) + + deployer.deploy_nsd_from_bicep( + bicep_path=design_file, + parameters_json_file=parameters_json_file, + manifest_bicep_path=manifest_file, + manifest_parameters_json_file=manifest_parameters_json_file, + ) + + +def _generate_nsd(config: NSDGenerator, api_clients): + """Generate a Network Service Design for the given type and config.""" + if config: + nsd_generator = NSDGenerator(config) + else: + from azure.cli.core.azclierror import CLIInternalError + + raise CLIInternalError("Generate NSD called without a config file") + deploy_parameters = _get_nfdv_deployment_parameters(config, api_clients) + + if os.path.exists(config.build_output_folder_name): + carry_on = input( + f"The folder {config.build_output_folder_name} already exists - delete it and continue? (y/n)" + ) + if carry_on != "y": + raise UnclassifiedUserFault("User aborted! ") + + shutil.rmtree(config.build_output_folder_name) + + nsd_generator.generate_nsd(deploy_parameters) + + +def _get_nfdv_deployment_parameters(config: NSConfiguration, api_clients): + """Get the properties of the existing NFDV.""" + NFDV_object = api_clients.aosm_client.network_function_definition_versions.get( + resource_group_name=config.publisher_resource_group_name, + publisher_name=config.publisher_name, + network_function_definition_group_name=config.network_function_definition_group_name, + network_function_definition_version_name=config.network_function_definition_version_name, + ) + + return NFDV_object.deploy_parameters diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 2bb3b77ab00..6a1515b2c77 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -6,7 +6,7 @@ from knack.log import get_logger from azext_aosm.util.management_clients import ApiClients -from azext_aosm._configuration import NFConfiguration, VNFConfiguration +from azext_aosm._configuration import NFConfiguration, VNFConfiguration, NSConfiguration from azext_aosm.util.utils import input_ack @@ -17,7 +17,7 @@ class ResourceDeleter: def __init__( self, api_clients: ApiClients, - config: NFConfiguration, + config: NFConfiguration or NSConfiguration, ) -> None: """ Initializes a new instance of the Deployer class. @@ -74,6 +74,25 @@ def delete_vnf(self, clean: bool = False): self.delete_artifact_store("sa") self.delete_publisher() + def delete_nsd(self): + """ + Delete the NSDV and manifests. If they don't exist it still reports them as + deleted. + """ + assert isinstance(self.config, NSConfiguration) + + print( + f"Are you sure you want to delete the NSD Version {self.config.nsd_version}, the associated manifest {self.config.acr_manifest_name} and configuration group schema {self.config.cg_schema_name}?" + ) + print("There is no undo. Type 'delete' to confirm") + if not input_ack("delete", "Confirm delete:"): + print("Not proceeding with delete") + return + + self.delete_nsdv() + self.delete_artifact_manifest("acr") + self.delete_config_group_schema() + def delete_nfdv(self): message = f"Delete NFDV {self.config.version} from group {self.config.nfdg_name} and publisher {self.config.publisher_name}" logger.debug(message) @@ -93,6 +112,26 @@ def delete_nfdv(self): ) raise + def delete_nsdv(self): + assert isinstance(self.config, NSConfiguration) + message = f"Delete NSDV {self.config.nsd_version} from group {self.config.nsdg_name} and publisher {self.config.publisher_name}" + logger.debug(message) + print(message) + try: + poller = self.api_clients.aosm_client.network_service_design_versions.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + network_service_design_group_name=self.config.nsdg_name, + network_service_design_version_name=self.config.nsd_version, + ) + poller.result() + print("Deleted NSDV.") + except Exception: + logger.error( + f"Failed to delete NSDV {self.config.nsd_version} from group {self.config.nsdg_name}" + ) + raise + def delete_artifact_manifest(self, store_type: str) -> None: """ _summary_ @@ -134,6 +173,25 @@ def delete_artifact_manifest(self, store_type: str) -> None: ) raise + def delete_nsdg(self) -> None: + """Delete the NSDG.""" + message = f"Delete NSD Group {self.config.nsdg_name}" + logger.debug(message) + print(message) + try: + poller = ( + self.api_clients.aosm_client.network_service_design_groups.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + network_service_design_group_name=self.config.nsdg_name, + ) + ) + poller.result() + print("Deleted NSD Group") + except Exception: + logger.error("Failed to delete NFDG.") + raise + def delete_nfdg(self) -> None: """Delete the NFDG.""" message = f"Delete NFD Group {self.config.nfdg_name}" @@ -201,3 +259,24 @@ def delete_publisher(self) -> None: except Exception: logger.error("Failed to delete publisher") raise + + def delete_config_group_schema(self) -> None: + """ + Delete the Configuration Group Schema. + """ + message = f"Delete Configuration Group Schema {self.config.cg_schema_name}" + logger.debug(message) + print(message) + try: + poller = ( + self.api_clients.aosm_client.configuration_group_schemas.begin_delete( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + configuration_group_schema_name=self.config.cg_schema_name, + ) + ) + poller.result() + print("Deleted Configuration Group Schema") + except Exception: + logger.error("Failed to delete the Configuration Group Schema") + raise diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 1d3f1ff095b..e533905e6b1 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -43,11 +43,12 @@ def _upload_to_acr(self, artifact_config: ArtifactConfig) -> None: # If not included in config, the file path value will be the description of # the field. + if artifact_config.file_path: target = f"{self.artifact_client.remote.hostname.replace('https://', '')}/{self.artifact_name}:{self.artifact_version}" logger.debug(f"Uploading {artifact_config.file_path} to {target}") self.artifact_client.push( - file=artifact_config.file_path, + files=[artifact_config.file_path], target=target, ) else: diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 8fa31fb30f4..58f2ea3e893 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -9,7 +9,7 @@ from azext_aosm.deploy.artifact import Artifact from azure.storage.blob import BlobClient from oras.client import OrasClient -from azext_aosm._configuration import NFConfiguration +from azext_aosm._configuration import NFConfiguration, NSConfiguration from azext_aosm.vendored_sdks.models import ( ArtifactManifest, ManifestArtifactFormat, @@ -27,7 +27,7 @@ class ArtifactManifestOperator: def __init__( self, - config: NFConfiguration, + config: NFConfiguration or NSConfiguration, api_clients: ApiClients, store_name: str, manifest_name: str, diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 5a3cf59caa1..47edd96d82b 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -16,11 +16,18 @@ from azure.mgmt.resource.resources.models import DeploymentExtended from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK -from azext_aosm._configuration import NFConfiguration, VNFConfiguration +from azext_aosm._configuration import NFConfiguration, NSConfiguration, VNFConfiguration from azext_aosm.util.constants import ( + NSD_DEFINITION_BICEP_FILE, + NSD_ARTIFACT_MANIFEST_BICEP_FILE, + NF_DEFINITION_BICEP_FILE, + NF_DEFINITION_JSON_FILE, VNF_DEFINITION_BICEP_TEMPLATE, VNF_MANIFEST_BICEP_TEMPLATE, + NSD, + VNF, ) +import time logger = get_logger(__name__) @@ -37,7 +44,7 @@ class DeployerViaArm: def __init__( self, api_clients: ApiClients, - config: NFConfiguration, + config: NFConfiguration or NSConfiguration, ) -> None: """ Initializes a new instance of the Deployer class. @@ -105,20 +112,9 @@ def deploy_vnfd_from_bicep( # Create or check required resources deploy_manifest_template = not self.vnfd_predeploy() if deploy_manifest_template: - print(f"Deploy bicep template for Artifact manifests") - logger.debug("Deploy manifest bicep") - if not manifest_bicep_path: - manifest_bicep_path = os.path.join( - self.config.build_output_folder_name, - VNF_MANIFEST_BICEP_TEMPLATE, - ) - if not manifest_parameters_json_file: - manifest_params = self.construct_manifest_parameters() - else: - logger.info("Use provided manifest parameters") - with open(manifest_parameters_json_file, "r", encoding="utf-8") as f: - manifest_params = json.loads(f.read()) - self.deploy_bicep_template(manifest_bicep_path, manifest_params) + self.deploy_manifest_template( + manifest_parameters_json_file, manifest_bicep_path, VNF + ) else: print( f"Artifact manifests exist for NFD {self.config.nf_name} " @@ -178,7 +174,7 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: """ assert isinstance(self.config, VNFConfiguration) return { - "location" : {"value": self.config.location}, + "location": {"value": self.config.location}, "publisherName": {"value": self.config.publisher_name}, "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, @@ -191,21 +187,178 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: def construct_manifest_parameters(self) -> Dict[str, Any]: """ - Create the parmeters dictionary for vnfdefinitions.bicep. VNF specific. + Create the parmeters dictionary for VNF or NSD. + """ + if isinstance(self.config, VNFConfiguration): + return { + "location": {"value": self.config.location}, + "publisherName": {"value": self.config.publisher_name}, + "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, + "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, + "acrManifestName": {"value": self.config.acr_manifest_name}, + "saManifestName": {"value": self.config.sa_manifest_name}, + "vhdName": {"value": self.config.vhd.artifact_name}, + "vhdVersion": {"value": self.config.vhd.version}, + "armTemplateName": {"value": self.config.arm_template.artifact_name}, + "armTemplateVersion": {"value": self.config.arm_template.version}, + } + elif isinstance(self.config, NSConfiguration): + return { + "location": {"value": self.config.location}, + "publisherName": {"value": self.config.publisher_name}, + "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, + "acrManifestName": {"value": self.config.acr_manifest_name}, + "armTemplateName": {"value": self.config.arm_template.artifact_name}, + "armTemplateVersion": {"value": self.config.arm_template.version}, + } + else: + raise ValueError("Unknown configuration type") - :param config: The contents of the configuration file. + def deploy_nsd_from_bicep( + self, + bicep_path: Optional[str] = None, + parameters_json_file: Optional[str] = None, + manifest_bicep_path: Optional[str] = None, + manifest_parameters_json_file: Optional[str] = None, + ) -> None: """ - assert isinstance(self.config, VNFConfiguration) + Deploy the bicep template defining the VNFD. + + Also ensure that all required predeploy resources are deployed. + + :param bicep_template_path: The path to the bicep template of the nfdv + :type bicep_template_path: str + :parameters_json_file: path to an override file of set parameters for the nfdv + :param manifest_bicep_path: The path to the bicep template of the manifest + :param manifest_parameters_json_file: path to an override file of set parameters for + the manifest + """ + assert isinstance(self.config, NSConfiguration) + + if not bicep_path: + # User has not passed in a bicep template, so we are deploying the default + # one produced from building the NSDV using this CLI + bicep_path = os.path.join( + self.config.build_output_folder_name, + NSD_DEFINITION_BICEP_FILE, + ) + + if parameters_json_file: + message = f"Use parameters from file {parameters_json_file}" + logger.info(message) + print(message) + with open(parameters_json_file, "r", encoding="utf-8") as f: + parameters = json.loads(f.read()) + + else: + # User has not passed in parameters file, so we use the parameters required + # from config for the default bicep template produced from building the + # NSDV using this CLI + logger.debug("Create parameters for default NSDV template.") + parameters = self.construct_nsd_parameters() + + logger.debug(parameters) + + # Create or check required resources + deploy_manifest_template = not self.nsd_predeploy() + + if deploy_manifest_template: + self.deploy_manifest_template( + manifest_parameters_json_file, manifest_bicep_path, NSD + ) + else: + print(f"Artifact manifests {self.config.acr_manifest_name} already exists") + + message = ( + f"Deploy bicep template for NSDV {self.config.nsd_version} " + f"into {self.config.publisher_resource_group_name} under publisher " + f"{self.config.publisher_name}" + ) + print(message) + logger.info(message) + self.deploy_bicep_template(bicep_path, parameters) + print( + f"Deployed NSD {self.config.acr_manifest_name} version {self.config.nsd_version}." + ) + acr_manifest = ArtifactManifestOperator( + self.config, + self.api_clients, + self.config.acr_artifact_store_name, + self.config.acr_manifest_name, + ) + + arm_template_artifact = acr_manifest.artifacts[0] + + ## Convert the NF bicep to ARM + arm_template_artifact_json = self.convert_bicep_to_arm( + os.path.join(self.config.build_output_folder_name, NF_DEFINITION_BICEP_FILE) + ) + + with open(self.config.arm_template.file_path, "w") as file: + file.write(json.dumps(arm_template_artifact_json, indent=4)) + + print("Uploading ARM template artifact") + arm_template_artifact.upload(self.config.arm_template) + print("Done") + + def deploy_manifest_template( + self, manifest_parameters_json_file, manifest_bicep_path, configuration_type + ) -> None: + """ + Deploy the bicep template defining the manifest. + + :param manifest_parameters_json_file: path to an override file of set parameters + for the manifest + :param manifest_bicep_path: The path to the bicep template of the manifest + :param configuration_type: The type of configuration to deploy + """ + print(f"Deploy bicep template for Artifact manifests") + logger.debug("Deploy manifest bicep") + + if not manifest_bicep_path: + if configuration_type == NSD: + file_name = NSD_ARTIFACT_MANIFEST_BICEP_FILE + elif configuration_type == VNF: + file_name = VNF_MANIFEST_BICEP_TEMPLATE + + manifest_bicep_path = os.path.join( + self.config.build_output_folder_name, + file_name, + ) + if not manifest_parameters_json_file: + manifest_params = self.construct_manifest_parameters() + else: + logger.info("Use provided manifest parameters") + with open(manifest_parameters_json_file, "r", encoding="utf-8") as f: + manifest_params = json.loads(f.read()) + self.deploy_bicep_template(manifest_bicep_path, manifest_params) + + def nsd_predeploy(self) -> bool: + """ + All the predeploy steps for a NSD. Check if the RG, publisher, ACR, NSDG and + artifact manifest exist. + + Return True if artifact manifest already exists, False otherwise + """ + logger.debug("Ensure all required resources exist") + self.pre_deployer.ensure_config_resource_group_exists() + self.pre_deployer.ensure_config_publisher_exists() + self.pre_deployer.ensure_acr_artifact_store_exists() + self.pre_deployer.ensure_config_nsdg_exists() + return self.pre_deployer.do_config_artifact_manifests_exist() + + def construct_nsd_parameters(self) -> Dict[str, Any]: + """ + Create the parmeters dictionary for nsd_definition.bicep. + """ + assert isinstance(self.config, NSConfiguration) return { - "location" : {"value": self.config.location}, + "location": {"value": self.config.location}, "publisherName": {"value": self.config.publisher_name}, "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, - "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, - "acrManifestName": {"value": self.config.acr_manifest_name}, - "saManifestName": {"value": self.config.sa_manifest_name}, - "vhdName": {"value": self.config.vhd.artifact_name}, - "vhdVersion": {"value": self.config.vhd.version}, - "armTemplateName": {"value": self.config.arm_template.artifact_name}, + "nsDesignGroup": {"value": self.config.nsdg_name}, + "nsDesignVersion": {"value": self.config.nsd_version}, + "nfviSiteName": {"value": self.config.nfvi_site_name}, "armTemplateVersion": {"value": self.config.arm_template.version}, } @@ -260,7 +413,11 @@ def validate_and_deploy_arm_template( :raise RuntimeError if validation or deploy fails :return: Output dictionary from the bicep template. """ - deployment_name = f"nfd_into_{resource_group}" + # Get current time from the time module and remove all digits after the decimal point + current_time = str(time.time()).split(".")[0] + + # Add a timestamp to the deployment name to ensure it is unique + deployment_name = f"AOSM_CLI_deployment_into_{resource_group}_{current_time}" validation = self.api_clients.resource_client.deployments.begin_validate( resource_group_name=resource_group, diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 6e01a0bd7f5..47e83ff4e81 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -19,7 +19,7 @@ Publisher, ProvisioningState, ) -from azext_aosm._configuration import NFConfiguration, VNFConfiguration +from azext_aosm._configuration import NFConfiguration, VNFConfiguration, NSConfiguration logger = get_logger(__name__) @@ -34,7 +34,7 @@ class PreDeployerViaSDK: def __init__( self, api_clients: ApiClients, - config: NFConfiguration, + config: NFConfiguration or NSConfiguration, ) -> None: """ Initializes a new instance of the Deployer class. @@ -59,6 +59,10 @@ def ensure_resource_group_exists(self, resource_group_name: str) -> None: if not self.api_clients.resource_client.resource_groups.check_existence( resource_group_name ): + if isinstance(self.config, NSConfiguration): + raise AzCLIError( + f"Resource Group {resource_group_name} does not exist. Please create it before running this command." + ) logger.info(f"RG {resource_group_name} not found. Create it.") print(f"Creating resource group {resource_group_name}.") rg_params: ResourceGroup = ResourceGroup(location=self.config.location) @@ -71,7 +75,7 @@ def ensure_resource_group_exists(self, resource_group_name: str) -> None: def ensure_config_resource_group_exists(self) -> None: """ - Ensures that the publisher exists in the resource group. + Ensures that the resource group exists. Finds the parameters from self.config """ @@ -90,16 +94,21 @@ def ensure_publisher_exists( :param location: The location of the publisher. :type location: str """ - logger.info("Creating publisher %s if it does not exist", publisher_name) + try: - pubby = self.api_clients.aosm_client.publishers.get( + publisher = self.api_clients.aosm_client.publishers.get( resource_group_name, publisher_name ) print( - f"Publisher {pubby.name} exists in resource group {resource_group_name}" + f"Publisher {publisher.name} exists in resource group {resource_group_name}" ) except azure_exceptions.ResourceNotFoundError: + if isinstance(self.config, NSConfiguration): + raise AzCLIError( + f"Publisher {publisher_name} does not exist. Please create it before running this command." + ) # Create the publisher + logger.info("Creating publisher %s if it does not exist", publisher_name) print( f"Creating publisher {publisher_name} in resource group {resource_group_name}" ) @@ -269,6 +278,21 @@ def ensure_config_nfdg_exists( self.config.location, ) + def ensure_config_nsdg_exists( + self, + ): + """ + Ensures that the Network Function Definition Group exists. + + Finds the parameters from self.config + """ + self.ensure_nsdg_exists( + self.config.publisher_resource_group_name, + self.config.publisher_name, + self.config.nsdg_name, + self.config.location, + ) + def does_artifact_manifest_exist( self, rg_name: str, publisher_name: str, store_name: str, manifest_name: str ) -> bool: @@ -307,7 +331,7 @@ def do_config_artifact_manifests_exist( return True elif acr_manny_exists or sa_manny_exists: raise AzCLIError( - "Only one artifact manifest exists. Cannot proceed. Please delete the NFDV using `az aosm definition delete` and start the publish again from scratch." + "Only one artifact manifest exists. Cannot proceed. Please delete the NFDV using `az aosm nfd delete` and start the publish again from scratch." ) else: return False diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index c00083aff35..e9a2c85f424 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -24,7 +24,7 @@ CONFIG_MAPPINGS, SCHEMAS, SCHEMA_PREFIX, - DEPLOYMENT_PARAMETERS + DEPLOYMENT_PARAMETERS, ) @@ -51,7 +51,9 @@ def __init__(self, config: VNFConfiguration): self.arm_template_path = self.config.arm_template.file_path self.output_folder_name = self.config.build_output_folder_name - self._bicep_path = os.path.join(self.output_folder_name, self.bicep_template_name) + self._bicep_path = os.path.join( + self.output_folder_name, self.bicep_template_name + ) self._manifest_path = os.path.join( self.output_folder_name, self.manifest_template_name ) @@ -64,7 +66,6 @@ def generate_nfd(self) -> None: Create a bicep template for an NFD from the ARM template for the VNF. """ - # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: self.tmp_folder_name = tmpdirname @@ -101,9 +102,11 @@ def vm_parameters(self) -> Dict[str, Any]: if "parameters" in data: parameters: Dict[str, Any] = data["parameters"] else: - print("No parameters found in the template provided. Your schema will have no properties") + print( + "No parameters found in the template provided. Your schema will have no properties" + ) parameters = {} - + return parameters def create_parameter_files(self) -> None: @@ -134,18 +137,15 @@ def write_deployment_parameters(self, folder_path: str) -> None: nfd_parameters[key] = {"type": "integer"} elif self.vm_parameters[key]["type"] == "secureString": nfd_parameters[key] = {"type": "string"} - else: - nfd_parameters[key] = {"type": self.vm_parameters[key]["type"]} + else: + nfd_parameters[key] = {"type": self.vm_parameters[key]["type"]} - - deployment_parameters_path = os.path.join( - folder_path, DEPLOYMENT_PARAMETERS - ) + deployment_parameters_path = os.path.join(folder_path, DEPLOYMENT_PARAMETERS) # Heading for the deployParameters schema deploy_parameters_full: Dict[str, Any] = SCHEMA_PREFIX deploy_parameters_full["properties"].update(nfd_parameters) - + with open(deployment_parameters_path, "w") as _file: _file.write(json.dumps(deploy_parameters_full, indent=4)) @@ -198,30 +198,36 @@ def write_vhd_parameters(self, folder_path: str) -> None: def copy_to_output_folder(self) -> None: """Copy the bicep templates, config mappings and schema into the build output folder.""" code_dir = os.path.dirname(__file__) - + logger.info("Create NFD bicep %s", self.output_folder_name) - os.mkdir(self.output_folder_name) - + os.mkdir(self.output_folder_name) + bicep_path = os.path.join(code_dir, "templates", self.bicep_template_name) shutil.copy(bicep_path, self.output_folder_name) - + manifest_path = os.path.join(code_dir, "templates", self.manifest_template_name) shutil.copy(manifest_path, self.output_folder_name) - - os.mkdir(os.path.join(self.output_folder_name, SCHEMAS)) - tmp_schema_path = os.path.join(self.tmp_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS) - output_schema_path = os.path.join(self.output_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS) + + os.mkdir(os.path.join(self.output_folder_name, SCHEMAS)) + tmp_schema_path = os.path.join( + self.tmp_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS + ) + output_schema_path = os.path.join( + self.output_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS + ) shutil.copy( tmp_schema_path, output_schema_path, ) - + tmp_config_mappings_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) - output_config_mappings_path = os.path.join(self.output_folder_name, CONFIG_MAPPINGS) + output_config_mappings_path = os.path.join( + self.output_folder_name, CONFIG_MAPPINGS + ) shutil.copytree( tmp_config_mappings_path, output_config_mappings_path, dirs_exist_ok=True, ) - - logger.info("Copied files to %s", self.output_folder_name) \ No newline at end of file + + logger.info("Copied files to %s", self.output_folder_name) diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py new file mode 100644 index 00000000000..430954fcab3 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -0,0 +1,222 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Contains a class for generating VNF NFDs and associated resources.""" +from knack.log import get_logger +import json +import logging +import os +import shutil +from functools import cached_property +from pathlib import Path +from typing import Any, Dict, Optional +import tempfile + +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator + +from azext_aosm._configuration import NSConfiguration +from azext_aosm.util.constants import ( + NSD_DEFINITION_BICEP_SOURCE_TEMPLATE, + NSD_DEFINITION_BICEP_FILE, + NF_TEMPLATE_BICEP_FILE, + NF_DEFINITION_BICEP_FILE, + NSD_ARTIFACT_MANIFEST_BICEP_FILE, + NSD_CONFIG_MAPPING_FILE, + SCHEMAS, + CONFIG_MAPPINGS, + NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE, + TEMPLATES, +) + +from jinja2 import Template + + +logger = get_logger(__name__) + + +class NSDGenerator: + """ + NSD Generator. + + This takes a config file and a set of NFDV deploy_parameters and outputs: + - A bicep file for the NSDV + - Parameters files that are used by the NSDV bicep file, these are the + schemas and the mapping profiles of those schemas parameters + - A bicep file for the Artifact manifest + - A bicep and JSON file defining the Network Function that will + be deployed by the NSDV + """ + + def __init__(self, config: NSConfiguration): + self.config = config + self.nsd_bicep_template_name = NSD_DEFINITION_BICEP_SOURCE_TEMPLATE + self.nf_bicep_template_name = NF_TEMPLATE_BICEP_FILE + self.nsd_bicep_output_name = NSD_DEFINITION_BICEP_FILE + + self.build_folder_name = self.config.build_output_folder_name + + def generate_nsd(self, deploy_parameters) -> None: + """Generate a NSD templates which includes an Artifact Manifest, NFDV and NF templates.""" + logger.info(f"Generate NSD bicep templates") + + self.deploy_parameters = deploy_parameters + + # Create temporary folder. + with tempfile.TemporaryDirectory() as tmpdirname: + self.tmp_folder_name = tmpdirname + + self.create_parameter_files() + self.write_nsd_manifest() + self.write_nf_bicep() + self.write_nsd_bicep() + + self.copy_to_output_folder() + print(f"Generated NSD bicep templates created in {self.build_folder_name}") + print( + "Please review these templates. When you are happy with them run " + "`az aosm nsd publish` with the same arguments." + ) + + def create_parameter_files(self) -> None: + """Create the Schema and configMappings json files.""" + temp_schemas_folder_path = os.path.join(self.tmp_folder_name, SCHEMAS) + os.mkdir(temp_schemas_folder_path) + self.write_schema(temp_schemas_folder_path) + + temp_mappings_folder_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) + os.mkdir(temp_mappings_folder_path) + self.write_config_mappings(temp_mappings_folder_path) + + def write_schema(self, folder_path: str) -> None: + """ + Write out the NSD Config Group Schema JSON file. + + :param folder_path: The folder to put this file in. + """ + logger.debug(f"Create {self.config.cg_schema_name}.json") + + schema_path = os.path.join(folder_path, f"{self.config.cg_schema_name}.json") + + with open(schema_path, "w") as _file: + _file.write(json.dumps(json.loads(self.deploy_parameters), indent=4)) + + logger.debug(f"{schema_path} created") + + def write_config_mappings(self, folder_path: str) -> None: + """ + Write out the NSD configMappings.json file. + + :param folder_path: The folder to put this file in. + """ + + deploy_parameters_dict = json.loads(self.deploy_parameters) + deploy_properties = deploy_parameters_dict["properties"] + + logger.debug("Create configMappings.json") + config_mappings = { + key: f"{{configurationparameters('{self.config.cg_schema_name}').{key}}}" + for key in deploy_properties + } + + config_mappings_path = os.path.join(folder_path, NSD_CONFIG_MAPPING_FILE) + + with open(config_mappings_path, "w") as _file: + _file.write(json.dumps(config_mappings, indent=4)) + + logger.debug(f"{config_mappings_path} created") + + def write_nf_bicep(self) -> None: + """Write out the Network Function bicep file.""" + bicep_params = "" + + bicep_deploymentValues = "" + + deploy_parameters_dict = json.loads(self.deploy_parameters) + deploy_properties = deploy_parameters_dict["properties"] + + for key, value in deploy_properties.items(): + # location is sometimes part of deploy_properties. + # We want to avoid having duplicate params in the bicep template + if key != "location": + bicep_params += f"param {key} {value['type']}\n" + bicep_deploymentValues += f"{key}: {key}\n " + + self.generate_bicep( + self.nf_bicep_template_name, + NF_DEFINITION_BICEP_FILE, + { + "bicep_params": bicep_params, + "deploymentValues": bicep_deploymentValues, + "network_function_name": self.config.network_function_name, + "publisher_name": self.config.publisher_name, + "network_function_definition_group_name": self.config.network_function_definition_group_name, + "network_function_definition_version_name": self.config.network_function_definition_version_name, + "network_function_definition_offering_location": self.config.network_function_definition_offering_location, + "location": self.config.location, + }, + ) + + def write_nsd_bicep(self) -> None: + """Write out the NSD bicep file.""" + params = { + "nfvi_site_name": self.config.nfvi_site_name, + "armTemplateName": self.config.arm_template.artifact_name, + "armTemplateVersion": self.config.arm_template.version, + "cg_schema_name": self.config.cg_schema_name, + "nsdv_description": self.config.nsdv_description, + "ResourceElementName": self.config.resource_element_name, + } + + self.generate_bicep( + self.nsd_bicep_template_name, self.nsd_bicep_output_name, params + ) + + def write_nsd_manifest(self) -> None: + """Write out the NSD manifest bicep file.""" + logger.debug("Create NSD manifest") + + self.generate_bicep( + NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE, NSD_ARTIFACT_MANIFEST_BICEP_FILE, {} + ) + + def generate_bicep(self, template_name, output_file_name, params) -> None: + """ + Render the bicep templates with the correct parameters and copy them into the build output folder. + + :param template_name: The name of the template to render + :param output_file_name: The name of the output file + :param params: The parameters to render the template with + """ + + code_dir = os.path.dirname(__file__) + + bicep_template_path = os.path.join(code_dir, TEMPLATES, template_name) + + with open(bicep_template_path, "r") as file: + bicep_contents = file.read() + + bicep_template = Template(bicep_contents) + + # Render all the relevant parameters in the bicep template + rendered_template = bicep_template.render(**params) + + bicep_file_build_path = os.path.join(self.tmp_folder_name, output_file_name) + + with open(bicep_file_build_path, "w") as file: + file.write(rendered_template) + + def copy_to_output_folder(self) -> None: + """Copy the bicep templates, config mappings and schema into the build output folder.""" + code_dir = os.path.dirname(__file__) + + logger.info("Create NSD bicep %s", self.build_folder_name) + os.mkdir(self.build_folder_name) + + shutil.copytree( + self.tmp_folder_name, + self.build_folder_name, + dirs_exist_ok=True, + ) + + logger.info("Copied files to %s", self.build_folder_name) diff --git a/src/aosm/azext_aosm/generate_nsd/templates/artifact_manifest_template.bicep b/src/aosm/azext_aosm/generate_nsd/templates/artifact_manifest_template.bicep new file mode 100644 index 00000000000..1d6f28c1d83 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nsd/templates/artifact_manifest_template.bicep @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an Artifact Manifest for a NSD +param location string +@description('Name of an existing publisher, expected to be in the resource group where you deploy the template') +param publisherName string +@description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') +param acrArtifactStoreName string +@description('Name of the manifest to deploy for the ACR-backed Artifact Store') +param acrManifestName string +@description('The name under which to store the ARM template') +param armTemplateName string +@description('The version that you want to name the NFM template artifact, in format A.B.C. e.g. 6.13.0. If testing for development, you can use any numbers you like.') +param armTemplateVersion string + +resource publisher 'Microsoft.HybridNetwork/publishers@2023-04-01-preview' existing = { + name: publisherName + scope: resourceGroup() +} + +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-04-01-preview' existing = { + parent: publisher + name: acrArtifactStoreName +} + +resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2023-04-01-preview' = { + parent: acrArtifactStore + name: acrManifestName + location: location + properties: { + artifacts: [ + { + artifactName: armTemplateName + artifactType: 'OCIArtifact' + artifactVersion: armTemplateVersion + } + ] + } +} diff --git a/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep b/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep new file mode 100644 index 00000000000..d558ef3f316 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Highly Confidential Material +// +// The template that the NSD invokes to create the Network Function from a published NFDV. + +@description('Publisher where the NFD is published') +param publisherName string = '{{publisher_name}}' + +@description('NFD Group name for the Network Function') +param networkFunctionDefinitionGroupName string = '{{network_function_definition_group_name}}' + +@description('NFD version') +param networkFunctionDefinitionVersion string = '{{network_function_definition_version_name}}' + +@description('Offering location for the Network Function') +param networkFunctionDefinitionOfferingLocation string = '{{network_function_definition_offering_location}}' + +param location string = '{{location}}' + +param resourceGroupId string = resourceGroup().id + +{{bicep_params}} + +var deploymentValues = { + {{deploymentValues}} +} + +resource nf_resource 'Microsoft.HybridNetwork/networkFunctions@2023-04-01-preview' = { + name: '{{network_function_name}}' + location: location + properties: { + publisherName: publisherName + publisherScope: 'Private' + networkFunctionDefinitionGroupName: networkFunctionDefinitionGroupName + networkFunctionDefinitionVersion: networkFunctionDefinitionVersion + networkFunctionDefinitionOfferingLocation: networkFunctionDefinitionOfferingLocation + nfviType: 'AzureCore' + nfviId: resourceGroupId + allowSoftwareUpdate: true + deploymentValues: string(deploymentValues) + } +} diff --git a/src/aosm/azext_aosm/generate_nsd/templates/nsd_template.bicep b/src/aosm/azext_aosm/generate_nsd/templates/nsd_template.bicep new file mode 100644 index 00000000000..0f777e01780 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nsd/templates/nsd_template.bicep @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Highly Confidential Material +// +// Bicep template to create an Artifact Manifest, Config Group Schema and NSDV. +// +// Requires an existing NFDV from which the values will be populated. + +param location string +@description('Name of an existing publisher, expected to be in the resource group where you deploy the template') +param publisherName string +@description('Name of an existing ACR-backed Artifact Store, deployed under the publisher.') +param acrArtifactStoreName string +@description('Name of an existing Network Service Design Group') +param nsDesignGroup string +@description('The version of the NSDV you want to create, in format A-B-C') +param nsDesignVersion string +@description('Name of the nfvi site') +param nfviSiteName string = '{{nfvi_site_name}}' +@description('The version that you want to name the NF template artifact, in format A-B-C. e.g. 6-13-0. Suggestion that this matches as best possible the SIMPL released version. If testing for development, you can use any numbers you like.') +param armTemplateVersion string = '{{armTemplateVersion}}' +@description('Name of the NF template artifact') +var armTemplateName = '{{armTemplateName}}' + +// The publisher resource is the top level AOSM resource under which all other designer resources +// are created. +resource publisher 'Microsoft.HybridNetwork/publishers@2023-04-01-preview' existing = { + name: publisherName + scope: resourceGroup() +} + +// The artifact store is the resource in which all the artifacts required to deploy the NF are stored. +// You can either create one especially for SIMPL or share a manifest with other NSDs. In this example +// the artifact store is expected to be shared and should be created upfront. +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-04-01-preview' existing = { + parent: publisher + name: acrArtifactStoreName +} + +// Created up-front, the NSD Group is the parent resource under which all NSD versions will be created. +resource nsdGroup 'Microsoft.Hybridnetwork/publishers/networkservicedesigngroups@2023-04-01-preview' existing = { + parent: publisher + name: nsDesignGroup +} + +// The configuration group schema defines the configuration required to deploy the NSD. The NSD references this object in the +// `configurationgroupsSchemaReferences` and references the values in the schema in the `parameterValues`. +// The operator will create a config group values object that will satisfy this schema. +resource cgSchema 'Microsoft.Hybridnetwork/publishers/configurationGroupSchemas@2023-04-01-preview' = { + parent: publisher + name: '{{cg_schema_name}}' + location: location + properties: { + schemaDefinition: string(loadJsonContent('schemas/{{cg_schema_name}}.json')) + } +} + +// The NSD version +resource nsdVersion 'Microsoft.Hybridnetwork/publishers/networkservicedesigngroups/networkservicedesignversions@2023-04-01-preview' = { + parent: nsdGroup + name: nsDesignVersion + location: location + properties: { + description: '{{nsdv_description}}' + // The version state can be Preview, Active or Deprecated. + // Once in an Active state, the NSDV becomes immutable. + versionState: 'Preview' + // The `configurationgroupsSchemaReferences` field contains references to the schemas required to + // be filled out to configure this NSD. + configurationGroupSchemaReferences: { + {{cg_schema_name}}: { + id: cgSchema.id + } + } + // This details the NFVIs that should be available in the Site object created by the operator. + nfvisFromSite: { + nfvi1: { + name: nfviSiteName + type: 'AzureCore' + } + } + // This field lists the templates that will be deployed by AOSM and the config mappings + // to the values in the CG schemas. + resourceElementTemplates: [ + { + name: '{{ResourceElementName}}' + // The type of resource element can be ArmResourceDefinition, ConfigurationDefinition or NetworkFunctionDefinition. + type: 'NetworkFunctionDefinition' + // The configuration object may be different for different types of resource element. + configuration: { + // This field points AOSM at the artifact in the artifact store. + artifactProfile: { + artifactStoreReference: { + id: acrArtifactStore.id + } + artifactName: armTemplateName + artifactVersion: armTemplateVersion + } + templateType: 'ArmTemplate' + // The parameter values map values from the CG schema, to values required by the template + // deployed by this resource element. + // outputParameters from the disk RET are used in these parameterValues + // This NSD does not support the NF-Agent as it has no Configuration Resource Elements. + // If Configuration resource elements (SDFs, Perimeta config) are added, the simplNfConfigMapping + // must be edited to have these lines (instead of blank values. SNSSelf is null if there are no Configuration elements) + // "nfAgentServiceBusNamespace": "{configurationparameters('SNSSelf').nfAgentConfiguration.resourceNamespace}", + // "nfAgentUserAssignedIdentityResourceId": "{configurationparameters('SNSSelf').nfAgentConfiguration.userAssignedIdentityResourceId}", + parameterValues: string(loadJsonContent('configMappings/configMappings.json')) + } + dependsOnProfile: { + installDependsOn: [] + uninstallDependsOn: [] + updateDependsOn: [] + } + } + ] + } +} diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 844815342c6..3ea1f7c25fe 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -8,9 +8,22 @@ VNF = "vnf" CNF = "cnf" NSD = "nsd" +SCHEMA = "schema" + +## TODO pk5: clean up these names # Names of files used in the repo +NSD_DEFINITION_BICEP_SOURCE_TEMPLATE = "nsd_template.bicep" +NSD_DEFINITION_BICEP_FILE = "nsd_definition.bicep" +NF_TEMPLATE_BICEP_FILE = "nf_template.bicep" +NF_DEFINITION_BICEP_FILE = "nf_definition.bicep" +NF_DEFINITION_JSON_FILE = "nf_definition.json" +NSD_DEFINITION_OUTPUT_BICEP_PREFIX = "nsd-bicep-templates" +NSD_ARTIFACT_MANIFEST_BICEP_FILE = "artifact_manifest.bicep" +NSD_ARTIFACT_MANIFEST_JSON_FILE = "artifact_manifest.json" DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" +NSD_CONFIG_MAPPING_FILE = "configMappings.json" +NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE = "artifact_manifest_template.bicep" VNF_DEFINITION_BICEP_TEMPLATE = "vnfdefinition.bicep" VNF_MANIFEST_BICEP_TEMPLATE = "vnfartifactmanifests.bicep" @@ -24,15 +37,16 @@ # Names of folder used in the repo CONFIG_MAPPINGS = "configMappings" SCHEMAS = "schemas" +TEMPLATES = "templates" # Deployment Schema SCHEMA_PREFIX = { - "$schema": "https://json-schema.org/draft-07/schema#", - "title": "DeployParametersSchema", - "type": "object", - "properties": {}, - } + "$schema": "https://json-schema.org/draft-07/schema#", + "title": "DeployParametersSchema", + "type": "object", + "properties": {}, +} IMAGE_LINE_REGEX = ( r"image: \{\{ .Values.(.+?) \}\}/(.+?):(\d+\.\d+\.\d+(-\w+)?(\.\d+)?)" ) diff --git a/src/aosm/setup.py b/src/aosm/setup.py index 7eafe07b30b..47149f957cb 100644 --- a/src/aosm/setup.py +++ b/src/aosm/setup.py @@ -56,5 +56,11 @@ classifiers=CLASSIFIERS, packages=find_packages(), install_requires=DEPENDENCIES, - package_data={"azext_aosm": ["azext_metadata.json", "generate_nfd/templates/*"]}, + package_data={ + "azext_aosm": [ + "azext_metadata.json", + "generate_nfd/templates/*", + "generate_nsd/templates/*", + ] + }, ) From cdfde0f4f0b50ea7a3f00c31dbee618eec0baf8d Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Tue, 6 Jun 2023 09:27:38 +0100 Subject: [PATCH 087/145] fix CNF depends on --- .../azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 index 307f0903c32..7c12e53c320 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 +++ b/src/aosm/azext_aosm/generate_nfd/templates/cnfdefinition.bicep.j2 @@ -45,7 +45,9 @@ resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroup { artifactType: 'HelmPackage' name: '{{ configuration.name }}' - dependsOnProfile: {{ configuration.dependsOnProfile }} + dependsOnProfile: { + installDependsOn: {{ configuration.dependsOnProfile }} + } artifactProfile: { artifactStore: { id: acrArtifactStore.id From 5b1e3aa0e58082ed0420c63a80dc309784ecd38d Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jun 2023 12:43:18 +0100 Subject: [PATCH 088/145] initial commit; ran python static checks fmt (except on vendored sdks), fixed styling on _configuration.py --- src/aosm/azext_aosm/_configuration.py | 75 ++++++++++--------- src/aosm/azext_aosm/delete/delete.py | 9 +-- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 14 +--- .../generate_nfd/cnf_nfd_generator.py | 60 ++++++++------- .../generate_nfd/nfd_generator_base.py | 1 - src/aosm/azext_aosm/vendored_sdks/__init__.py | 3 +- .../vendored_sdks/_configuration.py | 61 ++++++++++----- 7 files changed, 125 insertions(+), 98 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 4778f925bf7..ea96ecf7faa 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -14,54 +14,59 @@ import os DESCRIPTION_MAP: Dict[str, str] = { - "publisher_resource_group_name": ( - "Resource group for the Publisher resource. Will be " - "created if it does not exist." - ), - "publisher_name": ( - "Name of the Publisher resource you want your definition " - "published to. Will be created if it does not exist." - ), - "publisher_name_nsd": ( - "Name of the Publisher resource you want your design published to. This published should be the same as the publisher used for your NFDVs" - ), - "publisher_resource_group_name_nsd": ("Resource group for the Publisher resource."), + "publisher_resource_group_name": + "Resource group for the Publisher resource. Will be created if it does not exist." + , + "publisher_name": + "Name of the Publisher resource you want your definition published to. Will be created if it does not exist." + , + "publisher_name_nsd": + "Name of the Publisher resource you want your design published to. " + "This should be the same as the publisher used for your NFDVs" + , + "publisher_resource_group_name_nsd": "Resource group for the Publisher resource.", "nf_name": "Name of NF definition", "version": "Version of the NF definition", "acr_artifact_store_name": "Name of the ACR Artifact Store resource. Will be created if it does not exist.", "location": "Azure location to use when creating resources.", - "blob_artifact_store_name": "Name of the storage account Artifact Store resource. Will be created if it does not exist.", + "blob_artifact_store_name": + "Name of the storage account Artifact Store resource. Will be created if it does not exist.", "artifact_name": "Name of the artifact", - "file_path": ( - "Optional. File path of the artifact you wish to upload from your " - "local disk. Delete if not required." - ), - "blob_sas_url": ( - "Optional. SAS URL of the blob artifact you wish to copy to your " - "Artifact Store. Delete if not required." - ), - "artifact_version": ( + "file_path": + "Optional. File path of the artifact you wish to upload from your local disk. " + "Delete if not required." + , + "blob_sas_url": + "Optional. SAS URL of the blob artifact you wish to copy to your Artifact Store. " + "Delete if not required." + , + "artifact_version": "Version of the artifact. For VHDs this must be in format A-B-C. " "For ARM templates this must be in format A.B.C" - ), + , "nsdv_description": "Description of the NSDV", - "nsdg_name": "Network Service Design Group Name. This is the collection of Network Service Design Versions. Will be " - "created if it does not exist.", + "nsdg_name": + "Network Service Design Group Name. This is the collection of Network Service Design Versions. " + "Will be created if it does not exist.", "nsd_version": "Version of the NSD to be created. This should be in the format A.B.C", - "network_function_definition_group_name": "Exising Network Function Definition Group Name. This can be created using the 'az aosm nfd' commands.", - "network_function_definition_version_name": "Exising Network Function Definition Version Name. This can be created using the 'az aosm nfd' commands.", + "network_function_definition_group_name": + "Exising Network Function Definition Group Name. " + "This can be created using the 'az aosm nfd' commands.", + "network_function_definition_version_name": + "Exising Network Function Definition Version Name. " + "This can be created using the 'az aosm nfd' commands.", "network_function_definition_offering_location": "Offering location of the Network Function Definition", "helm_package_name": "Name of the Helm package", - "path_to_chart": ( + "path_to_chart": "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz" - ), - "path_to_mappings": ( + , + "path_to_mappings": "File path of value mappings on local disk. Accepts .yaml or .yml" - ), - "helm_depends_on": ( + , + "helm_depends_on": "Names of the Helm packages this package depends on. " "Leave as an empty array if no dependencies" - ), + , } @@ -99,6 +104,7 @@ def acr_manifest_name(self) -> str: @dataclass class NSConfiguration: + # pylint: disable=too-many-instance-attributes location: str = DESCRIPTION_MAP["location"] publisher_name: str = DESCRIPTION_MAP["publisher_name_nsd"] publisher_resource_group_name: str = DESCRIPTION_MAP[ @@ -190,7 +196,8 @@ def network_function_name(self) -> str: @property def acr_manifest_name(self) -> str: """Return the ACR manifest name from the NFD name.""" - return f"{self.network_function_name.lower().replace('_', '-')}-acr-manifest-{self.nsd_version.replace('.', '-')}" + return \ + f"{self.network_function_name.lower().replace('_', '-')}-acr-manifest-{self.nsd_version.replace('.', '-')}" @property def nfvi_site_name(self) -> str: diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 6a1515b2c77..5952a164d0e 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -76,8 +76,9 @@ def delete_vnf(self, clean: bool = False): def delete_nsd(self): """ - Delete the NSDV and manifests. If they don't exist it still reports them as - deleted. + Delete the NSDV and manifests. + + If they don't exist it still reports them as deleted. """ assert isinstance(self.config, NSConfiguration) @@ -261,9 +262,7 @@ def delete_publisher(self) -> None: raise def delete_config_group_schema(self) -> None: - """ - Delete the Configuration Group Schema. - """ + """Delete the Configuration Group Schema.""" message = f"Delete Configuration Group Schema {self.config.cg_schema_name}" logger.debug(message) print(message) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 47edd96d82b..90347469f6d 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -186,9 +186,7 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: } def construct_manifest_parameters(self) -> Dict[str, Any]: - """ - Create the parmeters dictionary for VNF or NSD. - """ + """Create the parmeters dictionary for VNF or NSD.""" if isinstance(self.config, VNFConfiguration): return { "location": {"value": self.config.location}, @@ -230,8 +228,7 @@ def deploy_nsd_from_bicep( :type bicep_template_path: str :parameters_json_file: path to an override file of set parameters for the nfdv :param manifest_bicep_path: The path to the bicep template of the manifest - :param manifest_parameters_json_file: path to an override file of set parameters for - the manifest + :param manifest_parameters_json_file: path to an override file of set parameters for the manifest """ assert isinstance(self.config, NSConfiguration) @@ -307,8 +304,7 @@ def deploy_manifest_template( """ Deploy the bicep template defining the manifest. - :param manifest_parameters_json_file: path to an override file of set parameters - for the manifest + :param manifest_parameters_json_file: path to an override file of set parameters for the manifest :param manifest_bicep_path: The path to the bicep template of the manifest :param configuration_type: The type of configuration to deploy """ @@ -348,9 +344,7 @@ def nsd_predeploy(self) -> bool: return self.pre_deployer.do_config_artifact_manifests_exist() def construct_nsd_parameters(self) -> Dict[str, Any]: - """ - Create the parmeters dictionary for nsd_definition.bicep. - """ + """Create the parmeters dictionary for nsd_definition.bicep.""" assert isinstance(self.config, NSConfiguration) return { "location": {"value": self.config.location}, diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index bb7f889e35e..e7dfb67fa59 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -29,14 +29,14 @@ CONFIG_MAPPINGS, SCHEMAS, SCHEMA_PREFIX, - DEPLOYMENT_PARAMETERS + DEPLOYMENT_PARAMETERS, ) logger = get_logger(__name__) -class CnfNfdGenerator(NFDGenerator): # pylint: disable=too-many-instance-attributes +class CnfNfdGenerator(NFDGenerator): # pylint: disable=too-many-instance-attributes """ CNF NFD Generator. @@ -79,10 +79,9 @@ def generate_nfd(self) -> None: self._tmp_folder_name = tmpdirname try: for helm_package in self.config.helm_packages: - # Turn Any type into HelmPackageConfig, to access properties on the object helm_package = HelmPackageConfig(**helm_package) - + # Unpack the chart into the tmp folder self._extract_chart(helm_package.path_to_chart) @@ -132,7 +131,7 @@ def generate_nfd(self) -> None: "If you are happy with them, you should manually deploy your bicep " "templates and upload your charts and images to your " "artifact store." - ) + ) except InvalidTemplateError as e: raise e @@ -150,9 +149,9 @@ def _extract_chart(self, path: str) -> None: :param path: The path to helm package """ - + logger.debug("Extracting helm package %s", path) - + (_, ext) = os.path.splitext(path) if ext == ".gz" or ext == ".tgz": tar = tarfile.open(path, "r:gz") @@ -183,7 +182,7 @@ def write_manifest_bicep_file(self) -> None: path = os.path.join(self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE) with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) - + logger.info("Created artifact manifest bicep template: %s", path) def write_nfd_bicep_file(self) -> None: @@ -195,32 +194,32 @@ def write_nfd_bicep_file(self) -> None: ) bicep_contents: str = template.render( - deployParametersPath = os.path.join(SCHEMAS,DEPLOYMENT_PARAMETERS), + deployParametersPath=os.path.join(SCHEMAS, DEPLOYMENT_PARAMETERS), nf_application_configurations=self.nf_application_configurations, ) path = os.path.join(self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE) with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) - + logger.info("Created NFD bicep template: %s", path) def write_schema_to_file(self) -> None: """Write the schema to file deploymentParameters.json.""" - + logger.debug("Create deploymentParameters.json") - + full_schema = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS) with open(full_schema, "w", encoding="UTF-8") as f: json.dump(self.deployment_parameter_schema, f, indent=4) - + logger.debug(f"{full_schema} created") def copy_to_output_folder(self) -> None: """Copy the config mappings, schema and bicep templates (artifact manifest and NFDV) to the output folder.""" - + logger.info("Create NFD bicep %s", self.output_folder_name) - + os.mkdir(self.output_folder_name) os.mkdir(os.path.join(self.output_folder_name, SCHEMAS)) @@ -235,7 +234,9 @@ def copy_to_output_folder(self) -> None: shutil.copy(tmp_manifest_bicep_path, self.output_folder_name) tmp_config_mappings_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS) - output_config_mappings_path = os.path.join(self.output_folder_name, CONFIG_MAPPINGS) + output_config_mappings_path = os.path.join( + self.output_folder_name, CONFIG_MAPPINGS + ) shutil.copytree( tmp_config_mappings_path, output_config_mappings_path, @@ -243,12 +244,14 @@ def copy_to_output_folder(self) -> None: ) tmp_schema_path = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS) - output_schema_path = os.path.join(self.output_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS) + output_schema_path = os.path.join( + self.output_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS + ) shutil.copy( tmp_schema_path, output_schema_path, ) - + logger.info("Copied files to %s", self.output_folder_name) def generate_nf_application_config( @@ -340,9 +343,9 @@ def get_chart_mapping_schema( param helm_package: The helm package config. """ - + logger.debug("Get chart mapping schema for %s", helm_package.name) - + mappings_path = helm_package.path_to_mappings values_schema = os.path.join( self._tmp_folder_name, helm_package.name, "values.schema.json" @@ -351,7 +354,7 @@ def get_chart_mapping_schema( if not os.path.exists(mappings_path): raise InvalidTemplateError( f"ERROR: The helm package '{helm_package.name}' does not have a valid values mappings file. The file at '{helm_package.path_to_mappings}' does not exist.\nPlease fix this and run the command again." - ) + ) if not os.path.exists(values_schema): raise InvalidTemplateError( f"ERROR: The helm package '{helm_package.name}' is missing values.schema.json. Please fix this and run the command again." @@ -410,18 +413,21 @@ def get_chart_name_and_version( ) -> Tuple[str, str]: """Get the name and version of the chart.""" chart = os.path.join(self._tmp_folder_name, helm_package.name, "Chart.yaml") - + if not os.path.exists(chart): - raise InvalidTemplateError(f"There is no Chart.yaml file in the helm package '{helm_package.name}'. Please fix this and run the command again.") - - + raise InvalidTemplateError( + f"There is no Chart.yaml file in the helm package '{helm_package.name}'. Please fix this and run the command again." + ) + with open(chart, "r", encoding="utf-8") as f: data = yaml.load(f, Loader=yaml.FullLoader) - if 'name' in data and 'version' in data: + if "name" in data and "version" in data: chart_name = data["name"] chart_version = data["version"] else: - raise FileOperationError(f"A name or version is missing from Chart.yaml in the helm package '{helm_package.name}'. Please fix this and run the command again.") + raise FileOperationError( + f"A name or version is missing from Chart.yaml in the helm package '{helm_package.name}'. Please fix this and run the command again." + ) return (chart_name, chart_version) diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index 591e56e2200..f03e1bd892c 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -24,4 +24,3 @@ def __init__( def generate_nfd(self) -> None: """No-op on base class.""" logger.error("Generate NFD called on base class. No-op") - diff --git a/src/aosm/azext_aosm/vendored_sdks/__init__.py b/src/aosm/azext_aosm/vendored_sdks/__init__.py index 37494f5f33e..9226444c2b5 100644 --- a/src/aosm/azext_aosm/vendored_sdks/__init__.py +++ b/src/aosm/azext_aosm/vendored_sdks/__init__.py @@ -10,9 +10,10 @@ from ._version import VERSION __version__ = VERSION -__all__ = ['HybridNetworkManagementClient'] +__all__ = ["HybridNetworkManagementClient"] # `._patch.py` is used for handwritten extensions to the generated code # Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md from ._patch import patch_sdk + patch_sdk() diff --git a/src/aosm/azext_aosm/vendored_sdks/_configuration.py b/src/aosm/azext_aosm/vendored_sdks/_configuration.py index 881c6609513..326f02605ad 100644 --- a/src/aosm/azext_aosm/vendored_sdks/_configuration.py +++ b/src/aosm/azext_aosm/vendored_sdks/_configuration.py @@ -10,7 +10,10 @@ from azure.core.configuration import Configuration from azure.core.pipeline import policies -from azure.mgmt.core.policies import ARMChallengeAuthenticationPolicy, ARMHttpLoggingPolicy +from azure.mgmt.core.policies import ( + ARMChallengeAuthenticationPolicy, + ARMHttpLoggingPolicy, +) from ._version import VERSION @@ -21,8 +24,11 @@ from azure.core.credentials import TokenCredential -class HybridNetworkManagementClientConfiguration(Configuration): # pylint: disable=too-many-instance-attributes - """Configuration for HybridNetworkManagementClient. +class HybridNetworkManagementClientConfiguration( + Configuration +): # pylint: disable=too-many-instance-attributes + """ + Configuration for HybridNetworkManagementClient. Note that all parameters used to create this instance are saved as instance attributes. @@ -31,8 +37,8 @@ class HybridNetworkManagementClientConfiguration(Configuration): # pylint: disa :type credential: ~azure.core.credentials.TokenCredential :param subscription_id: The ID of the target subscription. :type subscription_id: str - :keyword api_version: Api Version. The default value is "2023-04-01-preview". Note that - overriding this default value may result in unsupported behavior. + :keyword api_version: Api Version. The default value is "2023-04-01-preview". Note + that overriding this default value may result in unsupported behavior. :paramtype api_version: str """ @@ -44,7 +50,7 @@ def __init__( ): # type: (...) -> None super(HybridNetworkManagementClientConfiguration, self).__init__(**kwargs) - api_version = kwargs.pop('api_version', "2023-04-01-preview") # type: str + api_version = kwargs.pop("api_version", "2023-04-01-preview") # type: str if credential is None: raise ValueError("Parameter 'credential' must not be None.") @@ -54,23 +60,38 @@ def __init__( self.credential = credential self.subscription_id = subscription_id self.api_version = api_version - self.credential_scopes = kwargs.pop('credential_scopes', ['https://management.azure.com/.default']) - kwargs.setdefault('sdk_moniker', 'hybridnetwork/{}'.format(VERSION)) + self.credential_scopes = kwargs.pop( + "credential_scopes", ["https://management.azure.com/.default"] + ) + kwargs.setdefault("sdk_moniker", "hybridnetwork/{}".format(VERSION)) self._configure(**kwargs) def _configure( - self, - **kwargs # type: Any + self, **kwargs # type: Any ): # type: (...) -> None - self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs) - self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs) - self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs) - self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs) - self.http_logging_policy = kwargs.get('http_logging_policy') or ARMHttpLoggingPolicy(**kwargs) - self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs) - self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs) - self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs) - self.authentication_policy = kwargs.get('authentication_policy') + self.user_agent_policy = kwargs.get( + "user_agent_policy" + ) or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy( + **kwargs + ) + self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get( + "logging_policy" + ) or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get( + "http_logging_policy" + ) or ARMHttpLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get( + "custom_hook_policy" + ) or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy( + **kwargs + ) + self.authentication_policy = kwargs.get("authentication_policy") if self.credential and not self.authentication_policy: - self.authentication_policy = ARMChallengeAuthenticationPolicy(self.credential, *self.credential_scopes, **kwargs) + self.authentication_policy = ARMChallengeAuthenticationPolicy( + self.credential, *self.credential_scopes, **kwargs + ) From a1035f72a216dbe030696ba29d3620b9e95f72ac Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Tue, 6 Jun 2023 13:37:29 +0100 Subject: [PATCH 089/145] Name uploaded VHD correctly --- src/aosm/azext_aosm/_configuration.py | 6 +---- src/aosm/azext_aosm/deploy/artifact.py | 4 ++-- .../azext_aosm/deploy/artifact_manifest.py | 24 ++++++++++++++----- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 5 ++-- .../templates/vnfartifactmanifests.bicep | 10 ++++---- .../azext_aosm/generate_nsd/nsd_generator.py | 2 +- 6 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 4778f925bf7..9cea625b0f6 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -31,7 +31,6 @@ "acr_artifact_store_name": "Name of the ACR Artifact Store resource. Will be created if it does not exist.", "location": "Azure location to use when creating resources.", "blob_artifact_store_name": "Name of the storage account Artifact Store resource. Will be created if it does not exist.", - "artifact_name": "Name of the artifact", "file_path": ( "Optional. File path of the artifact you wish to upload from your " "local disk. Delete if not required." @@ -67,7 +66,6 @@ @dataclass class ArtifactConfig: - artifact_name: str = DESCRIPTION_MAP["artifact_name"] # artifact.py checks for the presence of the default descriptions, change there if # you change the descriptions. file_path: Optional[str] = DESCRIPTION_MAP["file_path"] @@ -179,8 +177,7 @@ def build_output_folder_name(self) -> str: @property def resource_element_name(self) -> str: """Return the name of the resource element.""" - artifact_name = self.arm_template.artifact_name - return f"{artifact_name}-resource-element" + return f"{self.nsdg_name.lower()}-resource-element" @property def network_function_name(self) -> str: @@ -206,7 +203,6 @@ def cg_schema_name(self) -> str: def arm_template(self) -> ArtifactConfig: """Return the parameters of the ARM template to be uploaded as part of the NSDV.""" artifact = ArtifactConfig() - artifact.artifact_name = f"{self.nsdg_name.lower()}_nf_artifact" artifact.version = self.nsd_version artifact.file_path = os.path.join( self.build_output_folder_name, NF_DEFINITION_JSON_FILE diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index e533905e6b1..48b37953f1f 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -6,7 +6,7 @@ from dataclasses import dataclass from typing import Union -from azure.storage.blob import BlobClient +from azure.storage.blob import BlobClient, BlobType from azext_aosm._configuration import ArtifactConfig from oras.client import OrasClient @@ -68,7 +68,7 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: if artifact_config.file_path: logger.info("Upload to blob store") with open(artifact_config.file_path, "rb") as artifact: - self.artifact_client.upload_blob(artifact, overwrite=True) + self.artifact_client.upload_blob(artifact, overwrite=True, blob_type=BlobType.PAGEBLOB) logger.info( f"Successfully uploaded {artifact_config.file_path} to {self.artifact_client.account_name}" ) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 58f2ea3e893..5eec5b0486f 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -131,16 +131,24 @@ def _get_artifact_client( f"{CredentialType.AZURE_STORAGE_ACCOUNT_TOKEN} are not expected " f"for Artifacts of type {artifact.artifact_type}" ) - + container_basename = artifact.artifact_name.replace("-", "") - blob_url = self._get_blob_url( - f"{container_basename}-{artifact.artifact_version}" - ) + container_name = f"{container_basename}-{artifact.artifact_version}" + + # For AOSM to work VHD blobs must have the suffix .vhd + if artifact.artifact_name.endswith("-vhd"): + blob_name = f"{artifact.artifact_name[:-4].replace('-', '')}-{artifact.artifact_version}.vhd" + else: + blob_name = container_name + + logger.debug("container name: %s, blob name: %s", container_name, blob_name) + + blob_url = self._get_blob_url(container_name, blob_name) return BlobClient.from_blob_url(blob_url) else: return self._oras_client(self._manifest_credentials["acr_server_url"]) - def _get_blob_url(self, container_name: str) -> str: + def _get_blob_url(self, container_name: str, blob_name: str) -> str: """ Get the URL for the blob to be uploaded to the storage account artifact store. @@ -151,6 +159,10 @@ def _get_blob_url(self, container_name: str) -> str: sas_uri = str(container_credential["container_sas_uri"]) sas_uri_prefix = sas_uri.split("?")[0] sas_uri_token = sas_uri.split("?")[1] + + blob_url = f"{sas_uri_prefix}/{blob_name}?{sas_uri_token}" + + logger.debug("Blob URL: %s", blob_url) - return f"{sas_uri_prefix}/{container_name}?{sas_uri_token}" + return blob_url raise KeyError(f"Manifest does not include a credential for {container_name}.") diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 47edd96d82b..565bb746670 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -197,9 +197,8 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, "acrManifestName": {"value": self.config.acr_manifest_name}, "saManifestName": {"value": self.config.sa_manifest_name}, - "vhdName": {"value": self.config.vhd.artifact_name}, + 'nfName': {"value": self.config.nf_name}, "vhdVersion": {"value": self.config.vhd.version}, - "armTemplateName": {"value": self.config.arm_template.artifact_name}, "armTemplateVersion": {"value": self.config.arm_template.version}, } elif isinstance(self.config, NSConfiguration): @@ -208,7 +207,7 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: "publisherName": {"value": self.config.publisher_name}, "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, "acrManifestName": {"value": self.config.acr_manifest_name}, - "armTemplateName": {"value": self.config.arm_template.artifact_name}, + "armTemplateName": {"value": f"{self.config.network_function_definition_group_name}_nfd_artifact"}, "armTemplateVersion": {"value": self.config.arm_template.version}, } else: diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep index 611b5d79184..554e3bfa28d 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep @@ -12,13 +12,11 @@ param saArtifactStoreName string param acrManifestName string @description('Name of the manifest to deploy for the Storage Account-backed Artifact Store') param saManifestName string -@description('The name under which to store the VHD') -param vhdName string +@description('Name of Network Function. Used predominantly as a prefix for other variable names') +param nfName string @description('The version that you want to name the NFM VHD artifact, in format A-B-C. e.g. 6-13-0') param vhdVersion string @description('The name under which to store the ARM template') -param armTemplateName string -@description('The version that you want to name the NFM template artifact, in format A.B.C. e.g. 6.13.0. If testing for development, you can use any numbers you like.') param armTemplateVersion string // Created by the az aosm definition publish command before the template is deployed @@ -46,7 +44,7 @@ resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/a properties: { artifacts: [ { - artifactName: '${vhdName}' + artifactName: '${nfName}-vhd' artifactType: 'VhdImageFile' artifactVersion: vhdVersion } @@ -61,7 +59,7 @@ resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/ properties: { artifacts: [ { - artifactName: '${armTemplateName}' + artifactName: '${nfName}-arm-template' artifactType: 'ArmTemplate' artifactVersion: armTemplateVersion } diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index 430954fcab3..401b66b7296 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -161,7 +161,7 @@ def write_nsd_bicep(self) -> None: """Write out the NSD bicep file.""" params = { "nfvi_site_name": self.config.nfvi_site_name, - "armTemplateName": self.config.arm_template.artifact_name, + "armTemplateName": f"{self.config.network_function_definition_group_name}_nfd_artifact", "armTemplateVersion": self.config.arm_template.version, "cg_schema_name": self.config.cg_schema_name, "nsdv_description": self.config.nsdv_description, From 77e2e95efa41ab60f5e0c8d928481e63481094d2 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Tue, 6 Jun 2023 13:55:37 +0100 Subject: [PATCH 090/145] Self review markups --- src/aosm/azext_aosm/deploy/artifact_manifest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 5eec5b0486f..4365e3fa182 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -131,7 +131,7 @@ def _get_artifact_client( f"{CredentialType.AZURE_STORAGE_ACCOUNT_TOKEN} are not expected " f"for Artifacts of type {artifact.artifact_type}" ) - + container_basename = artifact.artifact_name.replace("-", "") container_name = f"{container_basename}-{artifact.artifact_version}" @@ -153,6 +153,7 @@ def _get_blob_url(self, container_name: str, blob_name: str) -> str: Get the URL for the blob to be uploaded to the storage account artifact store. :param container_name: name of the container + :param blob_name: the name that the blob will get uploaded with """ for container_credential in self._manifest_credentials["container_credentials"]: if container_credential["container_name"] == container_name: From b557b7f0c38982695b73fb10f3a4172d468e686d Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jun 2023 15:02:47 +0100 Subject: [PATCH 091/145] fixed up configuration.py --- src/aosm/azext_aosm/_configuration.py | 29 +++++++++++---------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index ea96ecf7faa..896d38e322d 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,17 +1,20 @@ +## Disabling as every if statement in validate in NSConfig class has this condition +# pylint: disable=simplifiable-condition + from dataclasses import dataclass, field from typing import Dict, Optional, Any, List from pathlib import Path +import os from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError from azext_aosm.util.constants import ( DEFINITION_OUTPUT_BICEP_PREFIX, VNF, CNF, NSD, - SCHEMA, NSD_DEFINITION_OUTPUT_BICEP_PREFIX, NF_DEFINITION_JSON_FILE, ) -import os + DESCRIPTION_MAP: Dict[str, str] = { "publisher_resource_group_name": @@ -134,33 +137,24 @@ def __post_init__(self): self.arm_template = ArtifactConfig(**self.arm_template) def validate(self): - ## validate that all of the configuration parameters are set + """ Validate that all of the configuration parameters are set """ if self.location == DESCRIPTION_MAP["location"] or "": raise ValueError("Location must be set") if self.publisher_name == DESCRIPTION_MAP["publisher_name_nsd"] or "": raise ValueError("Publisher name must be set") - if ( - self.publisher_resource_group_name - == DESCRIPTION_MAP["publisher_resource_group_name_nsd"] - or "" - ): + if self.publisher_resource_group_name == DESCRIPTION_MAP["publisher_resource_group_name_nsd"] or "": raise ValueError("Publisher resource group name must be set") - if ( - self.acr_artifact_store_name == DESCRIPTION_MAP["acr_artifact_store_name"] - or "" - ): + if self.acr_artifact_store_name == DESCRIPTION_MAP["acr_artifact_store_name"] or "": raise ValueError("ACR Artifact Store name must be set") if ( self.network_function_definition_group_name - == DESCRIPTION_MAP["network_function_definition_group_name"] - or "" + == DESCRIPTION_MAP["network_function_definition_group_name"] or "" ): raise ValueError("Network Function Definition Group name must be set") if ( - self.network_function_definition_version_name - == DESCRIPTION_MAP["network_function_definition_version_name"] - or "" + self.network_function_definition_version_name == + DESCRIPTION_MAP["network_function_definition_version_name"] or "" ): raise ValueError("Network Function Definition Version name must be set") if ( @@ -246,6 +240,7 @@ def validate(self) -> None: :raises ValidationError for any invalid config """ + if self.vhd.version == DESCRIPTION_MAP["version"]: # Config has not been filled in. Don't validate. return From a7d75749042e1e80cfc10c747df3fca1a8c2c3a8 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jun 2023 15:14:50 +0100 Subject: [PATCH 092/145] fixed cnf generator styling --- .../generate_nfd/vnf_nfd_generator.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index e9a2c85f424..37e81e009b2 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -4,14 +4,12 @@ # -------------------------------------------------------------------------------------- """Contains a class for generating VNF NFDs and associated resources.""" -import logging import json import os import shutil import tempfile from functools import cached_property -from pathlib import Path from typing import Any, Dict, Optional from knack.log import get_logger @@ -32,6 +30,7 @@ class VnfNfdGenerator(NFDGenerator): + # pylint: disable=too-many-instance-attributes """ VNF NFD Generator. @@ -57,15 +56,13 @@ def __init__(self, config: VNFConfiguration): self._manifest_path = os.path.join( self.output_folder_name, self.manifest_template_name ) + self.tmp_folder_name = '' def generate_nfd(self) -> None: - """Create a bicep template for an NFD from the ARM template for the VNF.""" """ Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. - Create a bicep template for an NFD from the ARM template for the VNF. """ - # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: self.tmp_folder_name = tmpdirname @@ -97,7 +94,7 @@ def manifest_path(self) -> Optional[str]: @cached_property def vm_parameters(self) -> Dict[str, Any]: """The parameters from the VM ARM template.""" - with open(self.arm_template_path, "r") as _file: + with open(self.arm_template_path, "r", encoding="utf-8") as _file: data = json.load(_file) if "parameters" in data: parameters: Dict[str, Any] = data["parameters"] @@ -146,10 +143,10 @@ def write_deployment_parameters(self, folder_path: str) -> None: deploy_parameters_full: Dict[str, Any] = SCHEMA_PREFIX deploy_parameters_full["properties"].update(nfd_parameters) - with open(deployment_parameters_path, "w") as _file: + with open(deployment_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(deploy_parameters_full, indent=4)) - logger.debug(f"{deployment_parameters_path} created") + logger.debug("%s created", deployment_parameters_path) def write_template_parameters(self, folder_path: str) -> None: """ @@ -164,10 +161,10 @@ def write_template_parameters(self, folder_path: str) -> None: template_parameters_path = os.path.join(folder_path, "templateParameters.json") - with open(template_parameters_path, "w") as _file: + with open(template_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(template_parameters, indent=4)) - logger.debug(f"{template_parameters_path} created") + logger.debug("%s created", template_parameters_path) def write_vhd_parameters(self, folder_path: str) -> None: """ @@ -193,7 +190,7 @@ def write_vhd_parameters(self, folder_path: str) -> None: with open(vhd_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(vhd_parameters, indent=4)) - logger.debug(f"{vhd_parameters_path} created") + logger.debug("%s created", vhd_parameters_path) def copy_to_output_folder(self) -> None: """Copy the bicep templates, config mappings and schema into the build output folder.""" From 6d0520dcaaf0f2f94e5505245c91a01b647fa862 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jun 2023 16:09:13 +0100 Subject: [PATCH 093/145] fixed styling for cnf generator --- .../generate_nfd/cnf_nfd_generator.py | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index e7dfb67fa59..deb06343879 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -70,6 +70,7 @@ def __init__(self, config: CNFConfiguration): self._bicep_path = os.path.join( self.output_folder_name, CNF_DEFINITION_BICEP_TEMPLATE ) + self._tmp_folder_name = '' def generate_nfd(self) -> None: """Generate a CNF NFD which comprises a group, an Artifact Manifest and an NFDV.""" @@ -153,14 +154,14 @@ def _extract_chart(self, path: str) -> None: logger.debug("Extracting helm package %s", path) (_, ext) = os.path.splitext(path) - if ext == ".gz" or ext == ".tgz": - tar = tarfile.open(path, "r:gz") - tar.extractall(path=self._tmp_folder_name) - tar.close() + if ext in ('.gz', '.tgz'): + with tarfile.open(path, "r:gz") as tar: + tar.extractall(path=self._tmp_folder_name) + elif ext == ".tar": - tar = tarfile.open(path, "r:") - tar.extractall(path=self._tmp_folder_name) - tar.close() + with tarfile.open(path, "r:") as tar: + tar.extractall(path=self._tmp_folder_name) + else: raise InvalidTemplateError( f"ERROR: The helm package '{path}' is not a .tgz, .tar or .tar.gz file.\ @@ -213,7 +214,7 @@ def write_schema_to_file(self) -> None: with open(full_schema, "w", encoding="UTF-8") as f: json.dump(self.deployment_parameter_schema, f, indent=4) - logger.debug(f"{full_schema} created") + logger.debug("%s created", full_schema) def copy_to_output_folder(self) -> None: """Copy the config mappings, schema and bicep templates (artifact manifest and NFDV) to the output folder.""" @@ -262,7 +263,7 @@ def generate_nf_application_config( ) -> Dict[str, Any]: """Generate NF application config.""" (name, version) = self.get_chart_name_and_version(helm_package) - registryValuesPaths = set([m[0] for m in image_line_matches]) + registryValuesPaths = set({m[0] for m in image_line_matches}) imagePullSecretsValuesPaths = set(image_pull_secret_line_matches) return { @@ -353,11 +354,14 @@ def get_chart_mapping_schema( if not os.path.exists(mappings_path): raise InvalidTemplateError( - f"ERROR: The helm package '{helm_package.name}' does not have a valid values mappings file. The file at '{helm_package.path_to_mappings}' does not exist.\nPlease fix this and run the command again." + f"ERROR: The helm package '{helm_package.name}' does not have a valid values mappings file. \ + The file at '{helm_package.path_to_mappings}' does not exist. \ + Please fix this and run the command again." ) if not os.path.exists(values_schema): raise InvalidTemplateError( - f"ERROR: The helm package '{helm_package.name}' is missing values.schema.json. Please fix this and run the command again." + f"ERROR: The helm package '{helm_package.name}' is missing values.schema.json. \ + Please fix this and run the command again." ) with open(mappings_path, "r", encoding="utf-8") as stream: @@ -371,7 +375,8 @@ def get_chart_mapping_schema( final_schema = self.find_deploy_params(values_data, schema_data, {}) except KeyError as e: raise InvalidTemplateError( - f"ERROR: Your schema and values for the helm package '{helm_package.name}' do not match. Please fix this and run the command again." + f"ERROR: Your schema and values for the helm package '{helm_package.name}' do not match. \ + Please fix this and run the command again." ) from e logger.debug("Generated chart mapping schema for %s", helm_package.name) @@ -416,7 +421,8 @@ def get_chart_name_and_version( if not os.path.exists(chart): raise InvalidTemplateError( - f"There is no Chart.yaml file in the helm package '{helm_package.name}'. Please fix this and run the command again." + f"There is no Chart.yaml file in the helm package '{helm_package.name}'. \ + Please fix this and run the command again." ) with open(chart, "r", encoding="utf-8") as f: @@ -426,7 +432,8 @@ def get_chart_name_and_version( chart_version = data["version"] else: raise FileOperationError( - f"A name or version is missing from Chart.yaml in the helm package '{helm_package.name}'. Please fix this and run the command again." + f"A name or version is missing from Chart.yaml in the helm package '{helm_package.name}'. \ + Please fix this and run the command again." ) return (chart_name, chart_version) From 4c1a2eea1af324fd4c2ca0487bc911064555d066 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jun 2023 16:22:33 +0100 Subject: [PATCH 094/145] fixed up nfd generator base and deploy with arm --- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 41 +++++++++---------- .../generate_nfd/nfd_generator_base.py | 2 +- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 90347469f6d..e84fad9a549 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -9,25 +9,25 @@ import subprocess # noqa from typing import Any, Dict, Optional import tempfile +import time from knack.log import get_logger -from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator -from azext_aosm.util.management_clients import ApiClients from azure.mgmt.resource.resources.models import DeploymentExtended +from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator +from azext_aosm.util.management_clients import ApiClients from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK from azext_aosm._configuration import NFConfiguration, NSConfiguration, VNFConfiguration from azext_aosm.util.constants import ( NSD_DEFINITION_BICEP_FILE, NSD_ARTIFACT_MANIFEST_BICEP_FILE, NF_DEFINITION_BICEP_FILE, - NF_DEFINITION_JSON_FILE, VNF_DEFINITION_BICEP_TEMPLATE, VNF_MANIFEST_BICEP_TEMPLATE, NSD, VNF, ) -import time + logger = get_logger(__name__) @@ -200,7 +200,7 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: "armTemplateName": {"value": self.config.arm_template.artifact_name}, "armTemplateVersion": {"value": self.config.arm_template.version}, } - elif isinstance(self.config, NSConfiguration): + if isinstance(self.config, NSConfiguration): return { "location": {"value": self.config.location}, "publisherName": {"value": self.config.publisher_name}, @@ -209,8 +209,7 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: "armTemplateName": {"value": self.config.arm_template.artifact_name}, "armTemplateVersion": {"value": self.config.arm_template.version}, } - else: - raise ValueError("Unknown configuration type") + raise ValueError("Unknown configuration type") def deploy_nsd_from_bicep( self, @@ -291,7 +290,7 @@ def deploy_nsd_from_bicep( os.path.join(self.config.build_output_folder_name, NF_DEFINITION_BICEP_FILE) ) - with open(self.config.arm_template.file_path, "w") as file: + with open(self.config.arm_template.file_path, "w", encoding="utf-8") as file: file.write(json.dumps(arm_template_artifact_json, indent=4)) print("Uploading ARM template artifact") @@ -308,7 +307,7 @@ def deploy_manifest_template( :param manifest_bicep_path: The path to the bicep template of the manifest :param configuration_type: The type of configuration to deploy """ - print(f"Deploy bicep template for Artifact manifests") + print("Deploy bicep template for Artifact manifests") logger.debug("Deploy manifest bicep") if not manifest_bicep_path: @@ -408,7 +407,7 @@ def validate_and_deploy_arm_template( :return: Output dictionary from the bicep template. """ # Get current time from the time module and remove all digits after the decimal point - current_time = str(time.time()).split(".")[0] + current_time = str(time.time()).split(".")[0] # pylint: disable=use-maxsplit-arg # Add a timestamp to the deployment name to ensure it is unique deployment_name = f"AOSM_CLI_deployment_into_{resource_group}_{current_time}" @@ -426,22 +425,21 @@ def validate_and_deploy_arm_template( ) validation_res = validation.result() - logger.debug(f"Validation Result {validation_res}") + logger.debug("Validation Result %s", validation_res) if validation_res.error: # Validation failed so don't even try to deploy logger.error( - f"Template for resource group {resource_group} " - f"has failed validation. The message was: " - f"{validation_res.error.message}. See logs for additional details." + "Template for resource group %s has failed validation. The message was: %s.\ + See logs for additional details.", resource_group, validation_res.error.message ) logger.debug( - f"Template for resource group {resource_group} " - f"failed validation. Full error details: {validation_res.error}." + "Template for resource group %s failed validation. \ + Full error details: %s",resource_group,validation_res.error ) raise RuntimeError("Azure template validation failed.") # Validation succeeded so proceed with deployment - logger.debug(f"Successfully validated resources for {resource_group}") + logger.debug("Successfully validated resources for %s", resource_group) poller = self.api_clients.resource_client.deployments.begin_create_or_update( resource_group_name=resource_group, @@ -464,10 +462,10 @@ def validate_and_deploy_arm_template( depl_props = deployment.properties else: raise RuntimeError("The deployment has no properties.\nAborting") - logger.debug(f"Deployed: {deployment.name} {deployment.id} {depl_props}") + logger.debug("Deployed: %s %s %s", deployment.name, deployment.id, depl_props) if depl_props.provisioning_state != "Succeeded": - logger.debug(f"Failed to provision: {depl_props}") + logger.debug("Failed to provision: %s", depl_props) raise RuntimeError( f"Deploy of template to resource group" f" {resource_group} proceeded but the provisioning" @@ -475,8 +473,7 @@ def validate_and_deploy_arm_template( f"\nAborting" ) logger.debug( - f"Provisioning state of {resource_group}" - f": {depl_props.provisioning_state}" + "Provisioning state of deployment %s : %s", resource_group, depl_props.provisioning_state ) return depl_props.outputs @@ -497,7 +494,7 @@ def convert_bicep_to_arm(self, bicep_template_path: str) -> Any: raise RuntimeError( "The Azure CLI is not installed - cannot render ARM templates." ) - logger.debug(f"Converting {bicep_template_path} to ARM template") + logger.debug("Converting %s to ARM template", bicep_template_path) with tempfile.TemporaryDirectory() as tmpdir: bicep_filename = os.path.basename(bicep_template_path) diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index f03e1bd892c..4428bdf45d1 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -11,7 +11,7 @@ class NFDGenerator: """A class for generating an NFD from a config file.""" - + # pylint: disable=too-few-public-methods def __init__( self, ) -> None: From 8e8db34649e8f64384d837362703f0c4cc48c921 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jun 2023 17:03:56 +0100 Subject: [PATCH 095/145] fixed styling for artifact.py --- src/aosm/azext_aosm/deploy/artifact.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index e533905e6b1..d258366c41c 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -1,14 +1,16 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Highly Confidential Material -"""A module to handle interacting with artifacts.""" -from knack.log import get_logger -from dataclasses import dataclass +# pylint: disable=unidiomatic-typecheck +"""A module to handle interacting with artifacts.""" from typing import Union +from dataclasses import dataclass +from knack.log import get_logger from azure.storage.blob import BlobClient -from azext_aosm._configuration import ArtifactConfig from oras.client import OrasClient +from azext_aosm._configuration import ArtifactConfig + logger = get_logger(__name__) @@ -45,8 +47,9 @@ def _upload_to_acr(self, artifact_config: ArtifactConfig) -> None: # the field. if artifact_config.file_path: - target = f"{self.artifact_client.remote.hostname.replace('https://', '')}/{self.artifact_name}:{self.artifact_version}" - logger.debug(f"Uploading {artifact_config.file_path} to {target}") + target = f"{self.artifact_client.remote.hostname.replace('https://', '')}\ + /{self.artifact_name}:{self.artifact_version}" + logger.debug("Uploading %s to %s", artifact_config.file_path, target) self.artifact_client.push( files=[artifact_config.file_path], target=target, @@ -70,7 +73,7 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: with open(artifact_config.file_path, "rb") as artifact: self.artifact_client.upload_blob(artifact, overwrite=True) logger.info( - f"Successfully uploaded {artifact_config.file_path} to {self.artifact_client.account_name}" + "Successfully uploaded %s to %s", artifact_config.file_path, self.artifact_client.account_name ) else: logger.info("Copy from SAS URL to blob store") @@ -80,7 +83,8 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: logger.debug(source_blob.url) self.artifact_client.start_copy_from_url(source_blob.url) logger.info( - f"Successfully copied {source_blob.blob_name} from {source_blob.account_name} to {self.artifact_client.account_name}" + "Successfully copied %s from %s to %s", + source_blob.blob_name, source_blob.account_name, self.artifact_client.account_name ) else: raise RuntimeError( From 44299e6e292b387c01d109442092d0794e4d57df Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 6 Jun 2023 17:18:40 +0100 Subject: [PATCH 096/145] fixed styling for atrifact manifest .py --- .../azext_aosm/deploy/artifact_manifest.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 58f2ea3e893..7e865e42d02 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -2,13 +2,15 @@ # Highly Confidential Material """A module to handle interacting with artifact manifests.""" -from knack.log import get_logger from functools import cached_property, lru_cache from typing import Any, List, Union +from knack.log import get_logger +from oras.client import OrasClient + from azure.cli.core.azclierror import AzCLIError -from azext_aosm.deploy.artifact import Artifact from azure.storage.blob import BlobClient -from oras.client import OrasClient + +from azext_aosm.deploy.artifact import Artifact from azext_aosm._configuration import NFConfiguration, NSConfiguration from azext_aosm.vendored_sdks.models import ( ArtifactManifest, @@ -16,7 +18,6 @@ CredentialType, ArtifactType, ) - from azext_aosm.util.management_clients import ApiClients logger = get_logger(__name__) @@ -24,7 +25,7 @@ class ArtifactManifestOperator: """ArtifactManifest class.""" - + # pylint: disable=too-few-public-methods def __init__( self, config: NFConfiguration or NSConfiguration, @@ -122,8 +123,7 @@ def _get_artifact_client( # Check we have the required artifact types for this credential. Indicates # a coding error if we hit this but worth checking. if not ( - artifact.artifact_type == ArtifactType.IMAGE_FILE - or artifact.artifact_type == ArtifactType.VHD_IMAGE_FILE + artifact.artifact_type in (ArtifactType.IMAGE_FILE, ArtifactType.VHD_IMAGE_FILE) ): raise AzCLIError( f"Cannot upload artifact {artifact.artifact_name}." @@ -137,8 +137,7 @@ def _get_artifact_client( f"{container_basename}-{artifact.artifact_version}" ) return BlobClient.from_blob_url(blob_url) - else: - return self._oras_client(self._manifest_credentials["acr_server_url"]) + return self._oras_client(self._manifest_credentials["acr_server_url"]) def _get_blob_url(self, container_name: str) -> str: """ @@ -149,7 +148,7 @@ def _get_blob_url(self, container_name: str) -> str: for container_credential in self._manifest_credentials["container_credentials"]: if container_credential["container_name"] == container_name: sas_uri = str(container_credential["container_sas_uri"]) - sas_uri_prefix = sas_uri.split("?")[0] + sas_uri_prefix = sas_uri.split("?")[0] # pylint: disable=use-maxsplit-arg sas_uri_token = sas_uri.split("?")[1] return f"{sas_uri_prefix}/{container_name}?{sas_uri_token}" From e38d4256287d846b04e750ec696da8eeeb1b9500 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Tue, 6 Jun 2023 18:51:29 +0100 Subject: [PATCH 097/145] Code review markups --- src/aosm/azext_aosm/_configuration.py | 14 +++++--------- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 2 +- src/aosm/azext_aosm/generate_nsd/nsd_generator.py | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 9cea625b0f6..d4fd1f3d632 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -116,15 +116,6 @@ class NSConfiguration: nsd_version: str = DESCRIPTION_MAP["nsd_version"] nsdv_description: str = DESCRIPTION_MAP["nsdv_description"] - def __post_init__(self): - """ - Cope with deserializing subclasses from dicts to ArtifactConfig. - - Used when creating VNFConfiguration object from a loaded json config file. - """ - if isinstance(self.arm_template, dict): - self.arm_template = ArtifactConfig(**self.arm_template) - def validate(self): ## validate that all of the configuration parameters are set @@ -208,6 +199,11 @@ def arm_template(self) -> ArtifactConfig: self.build_output_folder_name, NF_DEFINITION_JSON_FILE ) return artifact + + @property + def arm_template_artifact_name(self) -> str: + """Return the artifact name for the ARM template""" + return f"{self.network_function_definition_group_name}_nfd_artifact" @dataclass diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 565bb746670..c7feb2802ed 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -207,7 +207,7 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: "publisherName": {"value": self.config.publisher_name}, "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, "acrManifestName": {"value": self.config.acr_manifest_name}, - "armTemplateName": {"value": f"{self.config.network_function_definition_group_name}_nfd_artifact"}, + "armTemplateName": {"value": self.config.arm_template_artifact_name}, "armTemplateVersion": {"value": self.config.arm_template.version}, } else: diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index 401b66b7296..a4318752a10 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -161,7 +161,7 @@ def write_nsd_bicep(self) -> None: """Write out the NSD bicep file.""" params = { "nfvi_site_name": self.config.nfvi_site_name, - "armTemplateName": f"{self.config.network_function_definition_group_name}_nfd_artifact", + "armTemplateName": self.config.arm_template_artifact_name, "armTemplateVersion": self.config.arm_template.version, "cg_schema_name": self.config.cg_schema_name, "nsdv_description": self.config.nsdv_description, From d0f1276ec05eb311f78d6262f47d0bae7ebfa012 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 7 Jun 2023 09:46:47 +0100 Subject: [PATCH 098/145] fixed more linting --- src/aosm/azext_aosm/_configuration.py | 4 ++-- src/aosm/azext_aosm/deploy/artifact_manifest.py | 2 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 8 +++----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 896d38e322d..09f06282d00 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -20,10 +20,10 @@ "publisher_resource_group_name": "Resource group for the Publisher resource. Will be created if it does not exist." , - "publisher_name": + "publisher_name": "Name of the Publisher resource you want your definition published to. Will be created if it does not exist." , - "publisher_name_nsd": + "publisher_name_nsd": "Name of the Publisher resource you want your design published to. " "This should be the same as the publisher used for your NFDVs" , diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 7e865e42d02..ddfafcd1e48 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -148,7 +148,7 @@ def _get_blob_url(self, container_name: str) -> str: for container_credential in self._manifest_credentials["container_credentials"]: if container_credential["container_name"] == container_name: sas_uri = str(container_credential["container_sas_uri"]) - sas_uri_prefix = sas_uri.split("?")[0] # pylint: disable=use-maxsplit-arg + sas_uri_prefix = sas_uri.split("?")[0] # pylint: disable=use-maxsplit-arg sas_uri_token = sas_uri.split("?")[1] return f"{sas_uri_prefix}/{container_name}?{sas_uri_token}" diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index e84fad9a549..c0f4005649c 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -28,8 +28,6 @@ VNF, ) - - logger = get_logger(__name__) @@ -285,7 +283,7 @@ def deploy_nsd_from_bicep( arm_template_artifact = acr_manifest.artifacts[0] - ## Convert the NF bicep to ARM + # Convert the NF bicep to ARM arm_template_artifact_json = self.convert_bicep_to_arm( os.path.join(self.config.build_output_folder_name, NF_DEFINITION_BICEP_FILE) ) @@ -407,7 +405,7 @@ def validate_and_deploy_arm_template( :return: Output dictionary from the bicep template. """ # Get current time from the time module and remove all digits after the decimal point - current_time = str(time.time()).split(".")[0] # pylint: disable=use-maxsplit-arg + current_time = str(time.time()).split(".")[0] # pylint: disable=use-maxsplit-arg # Add a timestamp to the deployment name to ensure it is unique deployment_name = f"AOSM_CLI_deployment_into_{resource_group}_{current_time}" @@ -434,7 +432,7 @@ def validate_and_deploy_arm_template( ) logger.debug( "Template for resource group %s failed validation. \ - Full error details: %s",resource_group,validation_res.error + Full error details: %s", resource_group, validation_res.error ) raise RuntimeError("Azure template validation failed.") From 5f7b6089b5bb43375d3a462d8841bca4e51ca76c Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 9 Jun 2023 16:58:48 +0100 Subject: [PATCH 099/145] first attempt at regex --- src/aosm/azext_aosm/custom.py | 24 ++----- .../generate_nfd/cnf_nfd_generator.py | 67 ++++++++++++++----- src/aosm/azext_aosm/util/constants.py | 13 ++-- 3 files changed, 64 insertions(+), 40 deletions(-) diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index ed8e708e9d6..a237180e3e7 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -125,33 +125,17 @@ def publish_definition( """ Publish a generated definition. - :param cmd: :param client: :type client: HybridNetworkManagementClient :param - definition_type: VNF or CNF :param config_ - file: - Path to the config file for the NFDV :param definition_file: Optional path to a - bicep template to deploy, in case the user wants to edit the - built NFDV template. If omitted, the default built NFDV - template will be used. :param parameters_json_ - file: - Optional path to a parameters file for the bicep file, in case - the user wants to edit the built NFDV template. If omitted, - parameters from config will be turned into parameters for the - bicep file :param manifest_ - file: - Optional path to an override bicep template to deploy - manifests :param manifest_parameters_json_ - file: :param cmd: :param client: :type client: HybridNetworkManagementClient :param definition_type: VNF or CNF :param config_file: Path to the config file for the NFDV :param definition_file: Optional path to a bicep template to deploy, in case the - user wants to edit the built NFDV template. If omitted, the default - built NFDV template will be used. + user wants to edit the built NFDV template. + If omitted, the default built NFDV template will be used. :param parameters_json_file: Optional path to a parameters file for the bicep file, - in case the user wants to edit the built NFDV template. If omitted, - parameters from config will be turned into parameters for the bicep file + in case the user wants to edit the built NFDV template. If omitted, + parameters from config will be turned into parameters for the bicep file :param manifest_file: Optional path to an override bicep template to deploy manifests :param manifest_parameters_json_file: Optional path to an override bicep parameters diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index deb06343879..f7730256026 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -97,18 +97,24 @@ def generate_nfd(self) -> None: # Get all image line matches for files in the chart. # Do this here so we don't have to do it multiple times. + # image_line_matches = self.find_pattern_matches_in_chart( + # helm_package, IMAGE_LINE_REGEX + # ) image_line_matches = self.find_pattern_matches_in_chart( - helm_package, IMAGE_LINE_REGEX + helm_package, IMAGE_LINE_REGEX, "image:" ) - + print("first", image_line_matches) # Generate the NF application configuration for the chart # passed to jinja2 renderer to render bicep template self.nf_application_configurations.append( self.generate_nf_application_config( helm_package, image_line_matches, + # self.find_pattern_matches_in_chart( + # helm_package, IMAGE_PULL_SECRET_LINE_REGEX + # ), self.find_pattern_matches_in_chart( - helm_package, IMAGE_PULL_SECRET_LINE_REGEX + helm_package, IMAGE_PULL_SECRET_LINE_REGEX, "imagePullSecrets:" ), ) ) @@ -288,7 +294,7 @@ def _find_yaml_files(self, directory) -> Iterator[str]: yield os.path.join(root, file) def find_pattern_matches_in_chart( - self, helm_package: HelmPackageConfig, pattern: str + self, helm_package: HelmPackageConfig, pattern: str, start_string: str ) -> List[Tuple[str, ...]]: """ Find pattern matches in Helm chart, using provided REGEX pattern. @@ -298,12 +304,38 @@ def find_pattern_matches_in_chart( """ chart_dir = os.path.join(self._tmp_folder_name, helm_package.name) matches = [] - + path = [] + # name_and_version = () + # for file in self._find_yaml_files(chart_dir): + # with open(file, "r", encoding="UTF-8") as f: + # contents = f.read() + # print(re.findall(pattern, contents)) + # matches += re.findall(pattern, contents) for file in self._find_yaml_files(chart_dir): with open(file, "r", encoding="UTF-8") as f: - contents = f.read() - matches += re.findall(pattern, contents) - + for line in f: + if start_string in line: + print("LINE", start_string, line) + path = re.findall(pattern, line) + # testing splitting regex to get version and name + if start_string == "image:": + # re.findall(r"\/(.*)\:(.*)", line) + + # name_and_version = re.search(r"\/([^\s\/:]+):([^\s\/]+)", line) + name_and_version = re.search(r"\/([^\/]+):([^\/]+)", line) + # name_and_version = re.search(r'/(.+?):[\s"]*([^/)\s"]+)', line) + print("name_and_version", name_and_version) + print("n", name_and_version.group(1)) + print("v", name_and_version.group(2)) + # name = name_and_version[0][0] + # version = name_and_version[0][1] + # print("name", name) + # ( ['image1', 'image2'], 'name', 'version' ) + matches += (path, name_and_version.group(1), name_and_version.group(2)) + print("path", path) + else: + matches += path + print("MATCHES", matches) return matches def get_artifact_list( @@ -351,7 +383,8 @@ def get_chart_mapping_schema( values_schema = os.path.join( self._tmp_folder_name, helm_package.name, "values.schema.json" ) - + print("helm", helm_package.name) + if not os.path.exists(mappings_path): raise InvalidTemplateError( f"ERROR: The helm package '{helm_package.name}' does not have a valid values mappings file. \ @@ -360,8 +393,8 @@ def get_chart_mapping_schema( ) if not os.path.exists(values_schema): raise InvalidTemplateError( - f"ERROR: The helm package '{helm_package.name}' is missing values.schema.json. \ - Please fix this and run the command again." + f"ERROR: The helm package '{helm_package.name}' is missing values.schema.json.\n\ + Please fix this and run the command again." ) with open(mappings_path, "r", encoding="utf-8") as stream: @@ -387,7 +420,11 @@ def find_deploy_params( ) -> Dict[Any, Any]: """Find the deploy parameters in the values.mappings.yaml file and add them to the schema.""" original_schema_nested_dict = schema_nested_dict + # if given a blank mapping file, return empty schema + if nested_dict is None: + return {} for k, v in nested_dict.items(): + # print("k", k) # if value is a string and contains deployParameters. if isinstance(v, str) and re.search(DEPLOYMENT_PARAMETER_MAPPING_REGEX, v): # only add the parameter name (e.g. from {deployParameter.zone} only param = zone) @@ -440,10 +477,10 @@ def get_chart_name_and_version( def generate_parameter_mappings(self, helm_package: HelmPackageConfig) -> str: """Generate parameter mappings for the given helm package.""" - values = os.path.join( - self._tmp_folder_name, helm_package.name, "values.mappings.yaml" - ) - + # values = os.path.join( + # self._tmp_folder_name, helm_package.name, "values.mappings.yaml" + # ) + values = helm_package.path_to_mappings mappings_folder_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS) mappings_filename = f"{helm_package.name}-mappings.json" diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 3ea1f7c25fe..4f036dbe58e 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -10,7 +10,7 @@ NSD = "nsd" SCHEMA = "schema" -## TODO pk5: clean up these names +# TODO pk5: clean up these names # Names of files used in the repo NSD_DEFINITION_BICEP_SOURCE_TEMPLATE = "nsd_template.bicep" @@ -47,8 +47,11 @@ "type": "object", "properties": {}, } -IMAGE_LINE_REGEX = ( - r"image: \{\{ .Values.(.+?) \}\}/(.+?):(\d+\.\d+\.\d+(-\w+)?(\.\d+)?)" -) -IMAGE_PULL_SECRET_LINE_REGEX = r"imagePullSecrets: \[name: \{\{ .Values.(.+?) \}\}\]" +# IMAGE_LINE_REGEX = ( +# r"image: \{\{ .Values.(.+?) \}\}/(.+?):(\d+\.\d+\.\d+(-\w+)?(\.\d+)?)" +# ) +IMAGE_LINE_REGEX = r".Values\.([^\s})]*)" +# IMAGE_PULL_SECRET_LINE_REGEX = r"imagePullSecrets: \[name: \{\{ .Values.(.+?) \}\}\]" +IMAGE_PULL_SECRET_LINE_REGEX = r".Values\.([^\s})]*)" + DEPLOYMENT_PARAMETER_MAPPING_REGEX = r"\{deployParameters.(.+?)\}" From 09be2487089b2a5a3bc3e2ba5f2a155f2019f596 Mon Sep 17 00:00:00 2001 From: sunnycarter <36891339+sunnycarter@users.noreply.github.com> Date: Fri, 9 Jun 2023 17:38:11 +0100 Subject: [PATCH 100/145] Sunny/choose deploy parameters (#23) * choose-deploy-parameters * optioned deployParameters for CNF * lint * lint2 * docs * docs * lint * 9.82 score * Fix bugs * more useful debug logs * Fix bugs and logging * lint * markups --- src/aosm/HISTORY.rst | 4 + src/aosm/README.md | 18 +- src/aosm/azext_aosm/_client_factory.py | 1 + src/aosm/azext_aosm/_configuration.py | 61 +++-- src/aosm/azext_aosm/_help.py | 1 - src/aosm/azext_aosm/_params.py | 18 +- src/aosm/azext_aosm/custom.py | 54 ++-- src/aosm/azext_aosm/delete/delete.py | 3 +- src/aosm/azext_aosm/deploy/artifact.py | 21 +- .../azext_aosm/deploy/artifact_manifest.py | 21 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 30 ++- src/aosm/azext_aosm/deploy/pre_deploy.py | 9 +- .../generate_nfd/cnf_nfd_generator.py | 253 +++++++++++++++--- .../generate_nfd/nfd_generator_base.py | 2 +- .../generate_nfd/vnf_nfd_generator.py | 166 +++++++++--- .../azext_aosm/generate_nsd/nsd_generator.py | 20 +- .../tests/latest/test_aosm_scenario.py | 3 +- src/aosm/azext_aosm/util/constants.py | 18 +- .../azext_aosm/util/management_clients.py | 3 +- 19 files changed, 530 insertions(+), 176 deletions(-) diff --git a/src/aosm/HISTORY.rst b/src/aosm/HISTORY.rst index e5bcecabf4b..93107646473 100644 --- a/src/aosm/HISTORY.rst +++ b/src/aosm/HISTORY.rst @@ -3,6 +3,10 @@ Release History =============== +unreleased +++++++++++ +* `az aosm nfd build` options `--order-params` and `--interactive` to help users choose which NF parameters to expose as deployParameters. Feature added that allows CNF value mappings file to be generated if none is supplied. + 0.2.0 ++++++ Breaking change to commands - now use `nfd` instead of `definition`. Publish option removed from build. diff --git a/src/aosm/README.md b/src/aosm/README.md index a4df5c59b07..2ebeb4d1680 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -67,7 +67,10 @@ image that would be used for the VNF Virtual Machine. #### CNFs -For CNFs, you must provide helm packages with an associated schema. When filling in the input.json file, you must list helm packages in the order they are to be deployed. For example, if A must be deployed before B, your input.json should look something like this: +For CNFs, you must provide helm packages with an associated schema. +Optionally, you can provide a file path_to_mappings which is a copy of values.yaml with your chosen values replaced by deployment parameters, thus exposing them as parameters to the CNF. You can get this file auto-generated by leaving the value as a blank string, either having every value as +a deployment parameter, or using --interactive to interactively choose. +When filling in the input.json file, you must list helm packages in the order they are to be deployed. For example, if A must be deployed before B, your input.json should look something like this: "helm_packages": [ { @@ -115,6 +118,17 @@ Build an nfd definition locally `az aosm nfd build --config-file input.json` +More options on building an nfd definition locally: + +Choose which of the VNF ARM template parameters you want to expose as NFD deploymentParameters, with the option of interactively choosing each one. + +`az aosm nfd build --config-file input.json --definition_type vnf --order_params` +`az aosm nfd build --config-file input.json --definition_type vnf --order_params --interactive` + +Choose which of the CNF Helm values parameters you want to expose as NFD deploymentParameters. + +`az aosm nfd build --config-file input.json --definition_type cnf [--interactive]` + Publish a pre-built definition `az aosm nfd publish --config-file input.json` @@ -157,4 +171,4 @@ Delete a published design Delete a published design and the publisher, artifact stores and NSD group -`az aosm nsd delete --config-file input.json --clean` \ No newline at end of file +`az aosm nsd delete --config-file input.json --clean` diff --git a/src/aosm/azext_aosm/_client_factory.py b/src/aosm/azext_aosm/_client_factory.py index e55e6142d25..939880b240f 100644 --- a/src/aosm/azext_aosm/_client_factory.py +++ b/src/aosm/azext_aosm/_client_factory.py @@ -5,6 +5,7 @@ from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.cli.core.profiles import ResourceType + from .vendored_sdks import HybridNetworkManagementClient diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index f63e8001aa4..a26a3af3a77 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,28 +1,29 @@ ## Disabling as every if statement in validate in NSConfig class has this condition # pylint: disable=simplifiable-condition +import os from dataclasses import dataclass, field -from typing import Dict, Optional, Any, List from pathlib import Path -import os -from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError +from typing import Any, Dict, List, Optional + +from azure.cli.core.azclierror import InvalidArgumentValueError, ValidationError + from azext_aosm.util.constants import ( - DEFINITION_OUTPUT_BICEP_PREFIX, - VNF, CNF, + DEFINITION_OUTPUT_BICEP_PREFIX, + NF_DEFINITION_JSON_FILE, NSD, NSD_DEFINITION_OUTPUT_BICEP_PREFIX, - NF_DEFINITION_JSON_FILE, + VNF, ) - DESCRIPTION_MAP: Dict[str, str] = { "publisher_resource_group_name": - "Resource group for the Publisher resource. Will be created if it does not exist." - , + "Resource group for the Publisher resource. " + "Will be created if it does not exist.", "publisher_name": - "Name of the Publisher resource you want your definition published to. Will be created if it does not exist." - , + "Name of the Publisher resource you want your definition published to. " + "Will be created if it does not exist.", "publisher_name_nsd": "Name of the Publisher resource you want your design published to. " "This should be the same as the publisher used for your NFDVs" @@ -33,7 +34,8 @@ "acr_artifact_store_name": "Name of the ACR Artifact Store resource. Will be created if it does not exist.", "location": "Azure location to use when creating resources.", "blob_artifact_store_name": - "Name of the storage account Artifact Store resource. Will be created if it does not exist.", + "Name of the storage account Artifact Store resource. Will be created if it " + "does not exist.", "artifact_name": "Name of the artifact", "file_path": "Optional. File path of the artifact you wish to upload from your local disk. " @@ -60,7 +62,12 @@ "path_to_chart": "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz", "path_to_mappings": - "File path of value mappings on local disk. Accepts .yaml or .yml", + "File path of value mappings on local disk where chosen values are replaced " + "with deploymentParameter placeholders. Accepts .yaml or .yml. If left as a " + "blank string, a value mappings file will be generated with every value " + "mapped to a deployment parameter. Use a blank string and --interactive on " + "the build command to interactively choose which values to map." + , "helm_depends_on": "Names of the Helm packages this package depends on. " "Leave as an empty array if no dependencies", @@ -121,24 +128,33 @@ class NSConfiguration: nsdv_description: str = DESCRIPTION_MAP["nsdv_description"] def validate(self): - """ Validate that all of the configuration parameters are set """ + """Validate that all of the configuration parameters are set.""" if self.location == DESCRIPTION_MAP["location"] or "": raise ValueError("Location must be set") if self.publisher_name == DESCRIPTION_MAP["publisher_name_nsd"] or "": raise ValueError("Publisher name must be set") - if self.publisher_resource_group_name == DESCRIPTION_MAP["publisher_resource_group_name_nsd"] or "": + if ( + self.publisher_resource_group_name + == DESCRIPTION_MAP["publisher_resource_group_name_nsd"] + or "" + ): raise ValueError("Publisher resource group name must be set") - if self.acr_artifact_store_name == DESCRIPTION_MAP["acr_artifact_store_name"] or "": + if ( + self.acr_artifact_store_name == DESCRIPTION_MAP["acr_artifact_store_name"] + or "" + ): raise ValueError("ACR Artifact Store name must be set") if ( self.network_function_definition_group_name - == DESCRIPTION_MAP["network_function_definition_group_name"] or "" + == DESCRIPTION_MAP["network_function_definition_group_name"] + or "" ): raise ValueError("Network Function Definition Group name must be set") if ( - self.network_function_definition_version_name == - DESCRIPTION_MAP["network_function_definition_version_name"] or "" + self.network_function_definition_version_name + == DESCRIPTION_MAP["network_function_definition_version_name"] + or "" ): raise ValueError("Network Function Definition Version name must be set") if ( @@ -173,8 +189,7 @@ def network_function_name(self) -> str: @property def acr_manifest_name(self) -> str: """Return the ACR manifest name from the NFD name.""" - return \ - f"{self.network_function_name.lower().replace('_', '-')}-acr-manifest-{self.nsd_version.replace('.', '-')}" + return f"{self.network_function_name.lower().replace('_', '-')}-acr-manifest-{self.nsd_version.replace('.', '-')}" @property def nfvi_site_name(self) -> str: @@ -195,10 +210,10 @@ def arm_template(self) -> ArtifactConfig: self.build_output_folder_name, NF_DEFINITION_JSON_FILE ) return artifact - + @property def arm_template_artifact_name(self) -> str: - """Return the artifact name for the ARM template""" + """Return the artifact name for the ARM template.""" return f"{self.network_function_definition_group_name}_nfd_artifact" diff --git a/src/aosm/azext_aosm/_help.py b/src/aosm/azext_aosm/_help.py index 2a9a3013fd9..b11bedb4b53 100644 --- a/src/aosm/azext_aosm/_help.py +++ b/src/aosm/azext_aosm/_help.py @@ -6,7 +6,6 @@ from knack.help_files import helps # pylint: disable=unused-import - helps[ "aosm" ] = """ diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index 840dda18b6e..b7e15796e0f 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -7,7 +7,7 @@ from argcomplete.completers import FilesCompleter from azure.cli.core import AzCommandsLoader -from .util.constants import VNF, CNF, NSD +from .util.constants import CNF, VNF def load_arguments(self: AzCommandsLoader, _): @@ -52,6 +52,22 @@ def load_arguments(self: AzCommandsLoader, _): completer=FilesCompleter(allowednames="*.bicep"), help="Optional path to a bicep file to publish. Use to override publish of the built design with an alternative file.", ) + c.argument( + "order_params", + arg_type=get_three_state_flag(), + help="VNF definition_type only - ignored for CNF." + " Order deploymentParameters schema and configMappings to have the " + "parameters without default values at the top and those with default " + "values at the bottom. Can make it easier to remove those with defaults " + "which you do not want to expose as NFD parameters.", + ) + c.argument( + "interactive", + options_list=["--interactive", "-i"], + arg_type=get_three_state_flag(), + help="Prompt user to choose every parameter to expose as an NFD parameter." + " Those without defaults are automatically included.", + ) c.argument( "parameters_json_file", options_list=["--parameters-file", "-p"], diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index ed8e708e9d6..06c454235c4 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -8,29 +8,31 @@ import shutil from dataclasses import asdict from typing import Optional -from knack.log import get_logger + from azure.cli.core.azclierror import ( CLIInternalError, InvalidArgumentValueError, UnclassifiedUserFault, ) +from knack.log import get_logger -from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator -from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator -from azext_aosm.generate_nsd.nsd_generator import NSDGenerator -from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator -from azext_aosm.delete.delete import ResourceDeleter -from azext_aosm.deploy.deploy_with_arm import DeployerViaArm -from azext_aosm.util.constants import VNF, CNF, NSD -from azext_aosm.util.management_clients import ApiClients -from azext_aosm.vendored_sdks import HybridNetworkManagementClient from azext_aosm._client_factory import cf_resources from azext_aosm._configuration import ( - get_configuration, + CNFConfiguration, NFConfiguration, NSConfiguration, + VNFConfiguration, + get_configuration, ) - +from azext_aosm.delete.delete import ResourceDeleter +from azext_aosm.deploy.deploy_with_arm import DeployerViaArm +from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator +from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator +from azext_aosm.generate_nsd.nsd_generator import NSDGenerator +from azext_aosm.util.constants import CNF, NSD, VNF +from azext_aosm.util.management_clients import ApiClients +from azext_aosm.vendored_sdks import HybridNetworkManagementClient logger = get_logger(__name__) @@ -38,6 +40,8 @@ def build_definition( definition_type: str, config_file: str, + order_params: bool = False, + interactive: bool = False, ): """ Build a definition. @@ -54,7 +58,12 @@ def build_definition( ) # Generate the NFD and the artifact manifest. - _generate_nfd(definition_type=definition_type, config=config) + _generate_nfd( + definition_type=definition_type, + config=config, + order_params=order_params, + interactive=interactive, + ) def generate_definition_config(definition_type: str, output_file: str = "input.json"): @@ -90,13 +99,17 @@ def _get_config_from_file( return config -def _generate_nfd(definition_type, config): +def _generate_nfd( + definition_type: str, config: NFConfiguration, order_params: bool, interactive: bool +): """Generate a Network Function Definition for the given type and config.""" nfd_generator: NFDGenerator if definition_type == VNF: - nfd_generator = VnfNfdGenerator(config) + assert isinstance(config, VNFConfiguration) + nfd_generator = VnfNfdGenerator(config, order_params, interactive) elif definition_type == CNF: - nfd_generator = CnfNfdGenerator(config) + assert isinstance(config, CNFConfiguration) + nfd_generator = CnfNfdGenerator(config, interactive) else: raise CLIInternalError( "Generate NFD called for unrecognised definition_type. Only VNF and CNF have been implemented." @@ -215,6 +228,7 @@ def delete_published_definition( def generate_design_config(output_file: str = "input.json"): """ Generate an example config file for building a NSD. + :param output_file: path to output config file, defaults to "input.json" :type output_file: str, optional """ @@ -224,6 +238,7 @@ def generate_design_config(output_file: str = "input.json"): def _generate_config(configuration_type: str, output_file: str = "input.json"): """ Generic generate config function for NFDs and NSDs. + :param configuration_type: CNF, VNF or NSD :param output_file: path to output config file, defaults to "input.json" :type output_file: str, optional @@ -240,7 +255,7 @@ def _generate_config(configuration_type: str, output_file: str = "input.json"): with open(output_file, "w", encoding="utf-8") as f: f.write(config_as_dict) - if configuration_type == CNF or configuration_type == VNF: + if configuration_type in (CNF,VNF): prtName = "definition" else: prtName = "design" @@ -251,6 +266,7 @@ def _generate_config(configuration_type: str, output_file: str = "input.json"): def build_design(cmd, client: HybridNetworkManagementClient, config_file: str): """ Build a Network Service Design. + :param cmd: :type cmd: _type_ :param client: @@ -282,6 +298,7 @@ def delete_published_design( ): """ Delete a published NSD. + :param config_file: Path to the config file :param clean: if True, will delete the NSDG, artifact stores and publisher too. Defaults to False. Only works if no resources have those as a parent. @@ -308,6 +325,7 @@ def publish_design( ): """ Publish a generated design. + :param cmd: :param client: :type client: HybridNetworkManagementClient @@ -347,8 +365,6 @@ def _generate_nsd(config: NSDGenerator, api_clients): if config: nsd_generator = NSDGenerator(config) else: - from azure.cli.core.azclierror import CLIInternalError - raise CLIInternalError("Generate NSD called without a config file") deploy_parameters = _get_nfdv_deployment_parameters(config, api_clients) diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 5952a164d0e..7cb01d8ce9e 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -5,11 +5,10 @@ """Contains class for deploying generated definitions using the Python SDK.""" from knack.log import get_logger +from azext_aosm._configuration import NFConfiguration, NSConfiguration, VNFConfiguration from azext_aosm.util.management_clients import ApiClients -from azext_aosm._configuration import NFConfiguration, VNFConfiguration, NSConfiguration from azext_aosm.util.utils import input_ack - logger = get_logger(__name__) diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 8ee00fc9b7f..b1d8a17857a 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -3,15 +3,14 @@ # pylint: disable=unidiomatic-typecheck """A module to handle interacting with artifacts.""" -from typing import Union from dataclasses import dataclass -from knack.log import get_logger +from typing import Union from azure.storage.blob import BlobClient, BlobType -from azext_aosm._configuration import ArtifactConfig +from knack.log import get_logger from oras.client import OrasClient -from azext_aosm._configuration import ArtifactConfig +from azext_aosm._configuration import ArtifactConfig logger = get_logger(__name__) @@ -72,9 +71,13 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: if artifact_config.file_path: logger.info("Upload to blob store") with open(artifact_config.file_path, "rb") as artifact: - self.artifact_client.upload_blob(artifact, overwrite=True, blob_type=BlobType.PAGEBLOB) + self.artifact_client.upload_blob( + artifact, overwrite=True, blob_type=BlobType.PAGEBLOB + ) logger.info( - "Successfully uploaded %s to %s", artifact_config.file_path, self.artifact_client.account_name + "Successfully uploaded %s to %s", + artifact_config.file_path, + self.artifact_client.account_name, ) else: logger.info("Copy from SAS URL to blob store") @@ -84,8 +87,10 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: logger.debug(source_blob.url) self.artifact_client.start_copy_from_url(source_blob.url) logger.info( - "Successfully copied %s from %s to %s", - source_blob.blob_name, source_blob.account_name, self.artifact_client.account_name + "Successfully copied %s from %s to %s", + source_blob.blob_name, + source_blob.account_name, + self.artifact_client.account_name, ) else: raise RuntimeError( diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 13ba5824c2d..168021e8519 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -4,27 +4,28 @@ from functools import cached_property, lru_cache from typing import Any, List, Union -from knack.log import get_logger -from oras.client import OrasClient from azure.cli.core.azclierror import AzCLIError from azure.storage.blob import BlobClient +from knack.log import get_logger +from oras.client import OrasClient -from azext_aosm.deploy.artifact import Artifact from azext_aosm._configuration import NFConfiguration, NSConfiguration +from azext_aosm.deploy.artifact import Artifact +from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks.models import ( ArtifactManifest, - ManifestArtifactFormat, - CredentialType, ArtifactType, + CredentialType, + ManifestArtifactFormat, ) -from azext_aosm.util.management_clients import ApiClients logger = get_logger(__name__) class ArtifactManifestOperator: """ArtifactManifest class.""" + # pylint: disable=too-few-public-methods def __init__( self, @@ -123,7 +124,8 @@ def _get_artifact_client( # Check we have the required artifact types for this credential. Indicates # a coding error if we hit this but worth checking. if not ( - artifact.artifact_type in (ArtifactType.IMAGE_FILE, ArtifactType.VHD_IMAGE_FILE) + artifact.artifact_type + in (ArtifactType.IMAGE_FILE, ArtifactType.VHD_IMAGE_FILE) ): raise AzCLIError( f"Cannot upload artifact {artifact.artifact_name}." @@ -142,7 +144,7 @@ def _get_artifact_client( blob_name = container_name logger.debug("container name: %s, blob name: %s", container_name, blob_name) - + blob_url = self._get_blob_url(container_name, blob_name) return BlobClient.from_blob_url(blob_url) return self._oras_client(self._manifest_credentials["acr_server_url"]) @@ -159,9 +161,8 @@ def _get_blob_url(self, container_name: str, blob_name: str) -> str: sas_uri = str(container_credential["container_sas_uri"]) sas_uri_prefix = sas_uri.split("?")[0] # pylint: disable=use-maxsplit-arg sas_uri_token = sas_uri.split("?")[1] - + blob_url = f"{sas_uri_prefix}/{blob_name}?{sas_uri_token}" - logger.debug("Blob URL: %s", blob_url) return blob_url diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index f8a3de1e1b9..8ecdcb6c293 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -7,26 +7,26 @@ import os import shutil import subprocess # noqa -from typing import Any, Dict, Optional import tempfile import time +from typing import Any, Dict, Optional -from knack.log import get_logger from azure.mgmt.resource.resources.models import DeploymentExtended +from knack.log import get_logger +from azext_aosm._configuration import NFConfiguration, NSConfiguration, VNFConfiguration from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator -from azext_aosm.util.management_clients import ApiClients from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK -from azext_aosm._configuration import NFConfiguration, NSConfiguration, VNFConfiguration from azext_aosm.util.constants import ( - NSD_DEFINITION_BICEP_FILE, - NSD_ARTIFACT_MANIFEST_BICEP_FILE, NF_DEFINITION_BICEP_FILE, - VNF_DEFINITION_BICEP_TEMPLATE, - VNF_MANIFEST_BICEP_TEMPLATE, NSD, + NSD_ARTIFACT_MANIFEST_BICEP_FILE, + NSD_DEFINITION_BICEP_FILE, VNF, + VNF_DEFINITION_BICEP_TEMPLATE, + VNF_MANIFEST_BICEP_TEMPLATE, ) +from azext_aosm.util.management_clients import ApiClients logger = get_logger(__name__) @@ -193,7 +193,7 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: "saArtifactStoreName": {"value": self.config.blob_artifact_store_name}, "acrManifestName": {"value": self.config.acr_manifest_name}, "saManifestName": {"value": self.config.sa_manifest_name}, - 'nfName': {"value": self.config.nf_name}, + "nfName": {"value": self.config.nf_name}, "vhdVersion": {"value": self.config.vhd.version}, "armTemplateVersion": {"value": self.config.arm_template.version}, } @@ -427,11 +427,15 @@ def validate_and_deploy_arm_template( # Validation failed so don't even try to deploy logger.error( "Template for resource group %s has failed validation. The message was: %s.\ - See logs for additional details.", resource_group, validation_res.error.message + See logs for additional details.", + resource_group, + validation_res.error.message, ) logger.debug( "Template for resource group %s failed validation. \ - Full error details: %s", resource_group, validation_res.error + Full error details: %s", + resource_group, + validation_res.error, ) raise RuntimeError("Azure template validation failed.") @@ -470,7 +474,9 @@ def validate_and_deploy_arm_template( f"\nAborting" ) logger.debug( - "Provisioning state of deployment %s : %s", resource_group, depl_props.provisioning_state + "Provisioning state of deployment %s : %s", + resource_group, + depl_props.provisioning_state, ) return depl_props.outputs diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 47e83ff4e81..59ae3e8f2b3 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -4,22 +4,21 @@ # -------------------------------------------------------------------------------------- """Contains class for deploying resources required by NFDs/NSDs via the SDK.""" -from knack.log import get_logger - -from azure.core import exceptions as azure_exceptions from azure.cli.core.azclierror import AzCLIError +from azure.core import exceptions as azure_exceptions from azure.mgmt.resource.resources.models import ResourceGroup +from knack.log import get_logger +from azext_aosm._configuration import NFConfiguration, NSConfiguration, VNFConfiguration from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks.models import ( ArtifactStore, ArtifactStoreType, NetworkFunctionDefinitionGroup, NetworkServiceDesignGroup, - Publisher, ProvisioningState, + Publisher, ) -from azext_aosm._configuration import NFConfiguration, VNFConfiguration, NSConfiguration logger = get_logger(__name__) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index deb06343879..8d8ce10f1d0 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -8,30 +8,31 @@ import re import shutil import tarfile -from typing import Dict, List, Any, Tuple, Optional, Iterator - import tempfile +from typing import Any, Dict, Iterator, List, Optional, Tuple + import yaml -from jinja2 import Template, StrictUndefined -from azure.cli.core.azclierror import InvalidTemplateError, FileOperationError +from azure.cli.core.azclierror import FileOperationError, InvalidTemplateError +from jinja2 import StrictUndefined, Template from knack.log import get_logger -from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.util.constants import ( CNF_DEFINITION_BICEP_TEMPLATE, CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE, CNF_MANIFEST_BICEP_TEMPLATE, CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE, + CONFIG_MAPPINGS, DEPLOYMENT_PARAMETER_MAPPING_REGEX, + DEPLOYMENT_PARAMETERS, + GENERATED_VALUES_MAPPINGS, IMAGE_LINE_REGEX, IMAGE_PULL_SECRET_LINE_REGEX, - CONFIG_MAPPINGS, - SCHEMAS, SCHEMA_PREFIX, - DEPLOYMENT_PARAMETERS, + SCHEMAS, ) - +from azext_aosm.util.utils import input_ack logger = get_logger(__name__) @@ -47,8 +48,14 @@ class CnfNfdGenerator(NFDGenerator): # pylint: disable=too-many-instance-attrib - A bicep file for the Artifact manifests """ - def __init__(self, config: CNFConfiguration): - """Create a new CNF NFD Generator.""" + def __init__(self, config: CNFConfiguration, interactive: bool = False): + """ + Create a new CNF NFD Generator. + + Interactive parameter is only used if the user wants to generate the values + mapping file from the values.yaml in the helm package, and also requires the + mapping file in config to be blank. + """ super(NFDGenerator, self).__init__() self.config = config self.nfd_jinja2_template_path = os.path.join( @@ -70,7 +77,8 @@ def __init__(self, config: CNFConfiguration): self._bicep_path = os.path.join( self.output_folder_name, CNF_DEFINITION_BICEP_TEMPLATE ) - self._tmp_folder_name = '' + self.interactive = interactive + self._tmp_folder_name = "" def generate_nfd(self) -> None: """Generate a CNF NFD which comprises a group, an Artifact Manifest and an NFDV.""" @@ -88,6 +96,10 @@ def generate_nfd(self) -> None: # TODO: Validate charts + # Create a chart mapping schema if none has been passed in. + if not helm_package.path_to_mappings: + self._generate_chart_value_mappings(helm_package) + # Get schema for each chart # (extract mappings and take the schema bits we need from values.schema.json) # + Add that schema to the big schema. @@ -154,7 +166,7 @@ def _extract_chart(self, path: str) -> None: logger.debug("Extracting helm package %s", path) (_, ext) = os.path.splitext(path) - if ext in ('.gz', '.tgz'): + if ext in (".gz", ".tgz"): with tarfile.open(path, "r:gz") as tar: tar.extractall(path=self._tmp_folder_name) @@ -168,6 +180,64 @@ def _extract_chart(self, path: str) -> None: Please fix this and run the command again." ) + def _generate_chart_value_mappings(self, helm_package: HelmPackageConfig) -> None: + """ + Optional function to create a chart value mappings file with every value being a deployParameter. + + Expected use when a helm chart is very simple and user wants every value to be a + deployment parameter. + """ + logger.debug( + "Creating chart value mappings file for %s", helm_package.path_to_chart + ) + print("Creating chart value mappings file for %s", helm_package.path_to_chart) + + # Get all the values files in the chart + top_level_values_yaml = self._read_top_level_values_yaml(helm_package) + + mapping_to_write = self._replace_values_with_deploy_params( + top_level_values_yaml, {} + ) + + # Write the mapping to a file + folder_name = os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS) + os.makedirs(folder_name, exist_ok=True) + mapping_filepath = os.path.join( + self._tmp_folder_name, + GENERATED_VALUES_MAPPINGS, + f"{helm_package.name}-generated-mapping.yaml", + ) + with open(mapping_filepath, "w", encoding="UTF-8") as mapping_file: + yaml.dump(mapping_to_write, mapping_file) + + # Update the config that points to the mapping file + helm_package.path_to_mappings = mapping_filepath + + def _read_top_level_values_yaml( + self, helm_package: HelmPackageConfig + ) -> Dict[str, Any]: + """Return a dictionary of the values.yaml|yml read from the root of the helm package. + + :param helm_package: The helm package to look in + :type helm_package: HelmPackageConfig + :raises FileOperationError: if no values.yaml|yml found + :return: A dictionary of the yaml read from the file + :rtype: Dict[str, Any] + """ + for file in os.listdir(os.path.join(self._tmp_folder_name, helm_package.name)): + if file in ("values.yaml", "values.yml"): + with open( + os.path.join(self._tmp_folder_name, helm_package.name, file), + "r", + encoding="UTF-8", + ) as values_file: + values_yaml = yaml.safe_load(values_file) + return values_yaml + + raise FileOperationError( + "Cannot find top level values.yaml/.yml file in Helm package." + ) + def write_manifest_bicep_file(self) -> None: """Write the bicep file for the Artifact Manifest.""" with open(self.manifest_jinja2_template_path, "r", encoding="UTF-8") as f: @@ -224,6 +294,7 @@ def copy_to_output_folder(self) -> None: os.mkdir(self.output_folder_name) os.mkdir(os.path.join(self.output_folder_name, SCHEMAS)) + # Copy the nfd and the manifest bicep files to the output folder tmp_nfd_bicep_path = os.path.join( self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE ) @@ -233,7 +304,23 @@ def copy_to_output_folder(self) -> None: self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE ) shutil.copy(tmp_manifest_bicep_path, self.output_folder_name) + + # Copy any generated values mappings YAML files to the corresponding folder in + # the output directory so that the user can edit them and re-run the build if + # required + if os.path.exists( + os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS) + ): + generated_mappings_path = os.path.join( + self.output_folder_name, GENERATED_VALUES_MAPPINGS + ) + shutil.copytree( + os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS), + generated_mappings_path, + ) + # Copy the JSON config mappings and deploymentParameters schema that are used + # for the NFD to the output folder tmp_config_mappings_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS) output_config_mappings_path = os.path.join( self.output_folder_name, CONFIG_MAPPINGS @@ -273,7 +360,7 @@ def generate_nf_application_config( "dependsOnProfile": helm_package.depends_on, "registryValuesPaths": list(registryValuesPaths), "imagePullSecretsValuesPaths": list(imagePullSecretsValuesPaths), - "valueMappingsPath": self.generate_parameter_mappings(helm_package), + "valueMappingsPath": self.jsonify_value_mappings(helm_package), } def _find_yaml_files(self, directory) -> Iterator[str]: @@ -293,8 +380,8 @@ def find_pattern_matches_in_chart( """ Find pattern matches in Helm chart, using provided REGEX pattern. - param helm_package: The helm package config. - param pattern: The regex pattern to match. + param helm_package: The helm package config. param pattern: The regex pattern to + match. """ chart_dir = os.path.join(self._tmp_folder_name, helm_package.name) matches = [] @@ -314,8 +401,8 @@ def get_artifact_list( """ Get the list of artifacts for the chart. - param helm_package: The helm package config. - param image_line_matches: The list of image line matches. + param helm_package: The helm package config. param image_line_matches: The list + of image line matches. """ artifact_list = [] (chart_name, chart_version) = self.get_chart_name_and_version(helm_package) @@ -355,7 +442,7 @@ def get_chart_mapping_schema( if not os.path.exists(mappings_path): raise InvalidTemplateError( f"ERROR: The helm package '{helm_package.name}' does not have a valid values mappings file. \ - The file at '{helm_package.path_to_mappings}' does not exist. \ + The file at '{helm_package.path_to_mappings}' does not exist.\n\ Please fix this and run the command again." ) if not os.path.exists(values_schema): @@ -385,34 +472,134 @@ def get_chart_mapping_schema( def find_deploy_params( self, nested_dict, schema_nested_dict, final_schema ) -> Dict[Any, Any]: - """Find the deploy parameters in the values.mappings.yaml file and add them to the schema.""" + """ + Create a schema of types of only those values in the values.mappings.yaml file which have a deployParameters mapping. + + Finds the relevant part of the full schema of the values file and finds the + type of the parameter name, then adds that to the final schema, with no nesting. + + Returns a schema of form: + { + "$schema": "https://json-schema.org/draft-07/schema#", + "title": "DeployParametersSchema", + "type": "object", + "properties": { + "": { + "type": "" + }, + "": { + "type": "" + }, + + nested_dict: the dictionary of the values mappings yaml which contains + deployParameters mapping placeholders + schema_nested_dict: the properties section of the full schema (or sub-object in + schema) + final_schema: Blank dictionary if this is the top level starting point, + otherwise the final_schema as far as we have got. + """ original_schema_nested_dict = schema_nested_dict for k, v in nested_dict.items(): # if value is a string and contains deployParameters. if isinstance(v, str) and re.search(DEPLOYMENT_PARAMETER_MAPPING_REGEX, v): - # only add the parameter name (e.g. from {deployParameter.zone} only param = zone) + logger.debug( + "Found string deploy parameter for key %s, value %s. Find schema type", + k, + v, + ) + # only add the parameter name (e.g. from {deployParameter.zone} only + # param = zone) param = v.split(".", 1)[1] param = param.split("}", 1)[0] - # add the schema for k (from the big schema) to the (smaller) schema - final_schema.update( - {param: {"type": schema_nested_dict["properties"][k]["type"]}} - ) - + # add the schema for k (from the full schema) to the (new) schema + if "properties" in schema_nested_dict.keys(): + # Occurs if top level item in schema properties is an object with + # properties itself + final_schema.update( + {param: {"type": schema_nested_dict["properties"][k]["type"]}} + ) + else: + # Occurs if top level schema item in schema properties are objects + # with no "properties" - but can have "type". + final_schema.update( + {param: {"type": schema_nested_dict[k]["type"]}} + ) # else if value is a (non-empty) dictionary (i.e another layer of nesting) elif hasattr(v, "items") and v.items(): - # handling schema having properties which doesn't map directly to the values file nesting + logger.debug("Found dict value for key %s. Find schema type", k) + # handling schema having properties which doesn't map directly to the + # values file nesting if "properties" in schema_nested_dict.keys(): schema_nested_dict = schema_nested_dict["properties"][k] else: schema_nested_dict = schema_nested_dict[k] # recursively call function with values (i.e the nested dictionary) self.find_deploy_params(v, schema_nested_dict, final_schema) - # reset the schema dict to its original value (once finished with that level of recursion) + # reset the schema dict to its original value (once finished with that + # level of recursion) schema_nested_dict = original_schema_nested_dict return final_schema + def _replace_values_with_deploy_params( + self, + values_yaml_dict, + param_prefix: Optional[str] = None, + ) -> Dict[Any, Any]: + """ + Given the yaml dictionary read from values.yaml, replace all the values with {deploymentParameter.keyname}. + + Thus creating a values mapping file if the user has not provided one in config. + """ + logger.debug("Replacing values with deploy parameters") + final_values_mapping_dict: Dict[Any, Any] = {} + for k, v in values_yaml_dict.items(): + # if value is a string and contains deployParameters. + logger.debug("Processing key %s", k) + param_name = k if param_prefix is None else f"{param_prefix}_{k}" + if isinstance(v, (str, int, bool)): + # Replace the parameter with {deploymentParameter.keyname} + if self.interactive: + # Interactive mode. Prompt user to include or exclude parameters + # This requires the enter key after the y/n input which isn't ideal + if not input_ack("y", f"Expose parameter {param_name}? y/n "): + logger.debug("Excluding parameter %s", param_name) + final_values_mapping_dict.update({k: v}) + continue + replacement_value = f"{{deployParameters.{param_name}}}" + + # add the schema for k (from the big schema) to the (smaller) schema + final_values_mapping_dict.update({k: replacement_value}) + elif isinstance(v, dict): + + final_values_mapping_dict[k] = self._replace_values_with_deploy_params( + v, param_name + ) + elif isinstance(v, list): + final_values_mapping_dict[k] = [] + for index, item in enumerate(v): + param_name = f"{param_prefix}_{k}_{index}" if param_prefix else f"{k})_{index}" + if isinstance(item, dict): + final_values_mapping_dict[k].append( + self._replace_values_with_deploy_params( + item, param_name + ) + ) + elif isinstance(v, (str, int, bool)): + replacement_value = f"{{deployParameters.{param_name}}}" + final_values_mapping_dict[k].append(replacement_value) + else: + raise ValueError( + f"Found an unexpected type {type(v)} of key {k} in " + "values.yaml, cannot generate values mapping file.") + else: + raise ValueError( + f"Found an unexpected type {type(v)} of key {k} in values.yaml, " + "cannot generate values mapping file.") + + return final_values_mapping_dict + def get_chart_name_and_version( self, helm_package: HelmPackageConfig ) -> Tuple[str, str]: @@ -438,11 +625,9 @@ def get_chart_name_and_version( return (chart_name, chart_version) - def generate_parameter_mappings(self, helm_package: HelmPackageConfig) -> str: - """Generate parameter mappings for the given helm package.""" - values = os.path.join( - self._tmp_folder_name, helm_package.name, "values.mappings.yaml" - ) + def jsonify_value_mappings(self, helm_package: HelmPackageConfig) -> str: + """Yaml->JSON values mapping file, then return path to it.""" + mappings_yaml = helm_package.path_to_mappings mappings_folder_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS) mappings_filename = f"{helm_package.name}-mappings.json" @@ -452,7 +637,7 @@ def generate_parameter_mappings(self, helm_package: HelmPackageConfig) -> str: mapping_file_path = os.path.join(mappings_folder_path, mappings_filename) - with open(values, "r", encoding="utf-8") as f: + with open(mappings_yaml, "r", encoding="utf-8") as f: data = yaml.load(f, Loader=yaml.FullLoader) with open(mapping_file_path, "w", encoding="utf-8") as file: diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index 4428bdf45d1..3072f62394e 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -5,12 +5,12 @@ """Contains a base class for generating NFDs.""" from knack.log import get_logger - logger = get_logger(__name__) class NFDGenerator: """A class for generating an NFD from a config file.""" + # pylint: disable=too-few-public-methods def __init__( self, diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index 37e81e009b2..7d33fab1016 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -8,26 +8,38 @@ import os import shutil import tempfile - from functools import cached_property from typing import Any, Dict, Optional -from knack.log import get_logger -from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator +from knack.log import get_logger from azext_aosm._configuration import VNFConfiguration +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.util.constants import ( - VNF_DEFINITION_BICEP_TEMPLATE, - VNF_MANIFEST_BICEP_TEMPLATE, CONFIG_MAPPINGS, - SCHEMAS, - SCHEMA_PREFIX, DEPLOYMENT_PARAMETERS, + OPTIONAL_DEPLOYMENT_PARAMETERS_FILE, + OPTIONAL_DEPLOYMENT_PARAMETERS_HEADING, + SCHEMA_PREFIX, + SCHEMAS, + TEMPLATE_PARAMETERS, + VHD_PARAMETERS, + VNF_DEFINITION_BICEP_TEMPLATE, + VNF_MANIFEST_BICEP_TEMPLATE, ) - +from azext_aosm.util.utils import input_ack logger = get_logger(__name__) +# Different types are used in ARM templates and NFDs. The list accepted by NFDs is +# documented in the AOSM meta-schema. This will be published in the future but for now +# can be found in +# https://microsoft.sharepoint.com/:w:/t/NSODevTeam/Ec7ovdKroSRIv5tumQnWIE0BE-B2LykRcll2Qb9JwfVFMQ +ARM_TO_JSON_PARAM_TYPES: Dict[str, str] = { + "int": "integer", + "secureString": "string", +} + class VnfNfdGenerator(NFDGenerator): # pylint: disable=too-many-instance-attributes @@ -39,9 +51,16 @@ class VnfNfdGenerator(NFDGenerator): - Parameters files that are used by the NFDV bicep file, these are the deployParameters and the mapping profiles of those deploy parameters - A bicep file for the Artifact manifests + + @param order_params: whether to order the deployment and template output parameters + with those without a default first, then those with a default. + Those without a default will definitely be required to be + exposed, those with a default may not be. + @param interactive: whether to prompt the user to confirm the parameters to be + exposed. """ - def __init__(self, config: VNFConfiguration): + def __init__(self, config: VNFConfiguration, order_params: bool, interactive: bool): super(NFDGenerator, self).__init__() self.config = config self.bicep_template_name = VNF_DEFINITION_BICEP_TEMPLATE @@ -56,11 +75,14 @@ def __init__(self, config: VNFConfiguration): self._manifest_path = os.path.join( self.output_folder_name, self.manifest_template_name ) - self.tmp_folder_name = '' + self.order_params = order_params + self.interactive = interactive + self.tmp_folder_name = "" def generate_nfd(self) -> None: """ Generate a VNF NFD which comprises an group, an Artifact Manifest and a NFDV. + Create a bicep template for an NFD from the ARM template for the VNF. """ # Create temporary folder. @@ -100,12 +122,35 @@ def vm_parameters(self) -> Dict[str, Any]: parameters: Dict[str, Any] = data["parameters"] else: print( - "No parameters found in the template provided. Your schema will have no properties" + "No parameters found in the template provided. " + "Your NFD will have no deployParameters" ) parameters = {} return parameters + @property + def vm_parameters_ordered(self) -> Dict[str, Any]: + """The parameters from the VM ARM template, ordered as those without defaults then those with.""" + vm_parameters_no_default: Dict[str, Any] = {} + vm_parameters_with_default: Dict[str, Any] = {} + has_default_field: bool = False + has_default: bool = False + + for key in self.vm_parameters: + # Order parameters into those with and without defaults + has_default_field = "defaultValue" in self.vm_parameters[key] + has_default = ( + has_default_field and not self.vm_parameters[key]["defaultValue"] == "" + ) + + if has_default: + vm_parameters_with_default[key] = self.vm_parameters[key] + else: + vm_parameters_no_default[key] = self.vm_parameters[key] + + return {**vm_parameters_no_default, **vm_parameters_with_default} + def create_parameter_files(self) -> None: """Create the Deployment and Template json parameter files.""" schemas_folder_path = os.path.join(self.tmp_folder_name, SCHEMAS) @@ -126,16 +171,42 @@ def write_deployment_parameters(self, folder_path: str) -> None: logger.debug("Create deploymentParameters.json") nfd_parameters = {} + nfd_parameters_with_default = {} + vm_parameters_to_exclude = [] - for key in self.vm_parameters: - # ARM templates allow int and secureString but we do not currently accept them in AOSM - # This may change, but for now we should change them to accepted types integer and string - if self.vm_parameters[key]["type"] == "int": - nfd_parameters[key] = {"type": "integer"} - elif self.vm_parameters[key]["type"] == "secureString": - nfd_parameters[key] = {"type": "string"} - else: - nfd_parameters[key] = {"type": self.vm_parameters[key]["type"]} + vm_parameters = ( + self.vm_parameters_ordered if self.order_params else self.vm_parameters + ) + + for key in vm_parameters: + # Order parameters into those without and then with defaults + has_default_field = "defaultValue" in self.vm_parameters[key] + has_default = ( + has_default_field and not self.vm_parameters[key]["defaultValue"] == "" + ) + + if self.interactive and has_default: + # Interactive mode. Prompt user to include or exclude parameters + # This requires the enter key after the y/n input which isn't ideal + if not input_ack("y", f"Expose parameter {key}? y/n "): + logger.debug("Excluding parameter %s", key) + vm_parameters_to_exclude.append(key) + continue + + # Map ARM parameter types to JSON parameter types accepted by AOSM + arm_type = self.vm_parameters[key]["type"] + json_type = ARM_TO_JSON_PARAM_TYPES.get(arm_type, arm_type) + + if has_default: + nfd_parameters_with_default[key] = {"type": json_type} + + nfd_parameters[key] = {"type": json_type} + + # Now we are out of the vm_parameters loop, we can remove the excluded + # parameters so they don't get included in templateParameters.json + # Remove from both ordered and unordered dicts + for key in vm_parameters_to_exclude: + self.vm_parameters.pop(key, None) deployment_parameters_path = os.path.join(folder_path, DEPLOYMENT_PARAMETERS) @@ -147,6 +218,28 @@ def write_deployment_parameters(self, folder_path: str) -> None: _file.write(json.dumps(deploy_parameters_full, indent=4)) logger.debug("%s created", deployment_parameters_path) + if self.order_params: + print( + "Deployment parameters for the generated NFDV are ordered by those " + "without defaults first to make it easier to choose which to expose." + ) + + # Extra output file to help the user know which parameters are optional + if not self.interactive: + if nfd_parameters_with_default: + optional_deployment_parameters_path = os.path.join( + folder_path, OPTIONAL_DEPLOYMENT_PARAMETERS_FILE + ) + with open( + optional_deployment_parameters_path, "w", encoding="utf-8" + ) as _file: + _file.write(OPTIONAL_DEPLOYMENT_PARAMETERS_HEADING) + _file.write(json.dumps(nfd_parameters_with_default, indent=4)) + print( + "Optional ARM parameters detected. Created " + f"{OPTIONAL_DEPLOYMENT_PARAMETERS_FILE} to help you choose which " + "to expose." + ) def write_template_parameters(self, folder_path: str) -> None: """ @@ -154,12 +247,15 @@ def write_template_parameters(self, folder_path: str) -> None: :param folder_path: The folder to put this file in. """ - logger.debug("Create templateParameters.json") + logger.debug("Create %s", TEMPLATE_PARAMETERS) + vm_parameters = ( + self.vm_parameters_ordered if self.order_params else self.vm_parameters + ) template_parameters = { - key: f"{{deployParameters.{key}}}" for key in self.vm_parameters + key: f"{{deployParameters.{key}}}" for key in vm_parameters } - template_parameters_path = os.path.join(folder_path, "templateParameters.json") + template_parameters_path = os.path.join(folder_path, TEMPLATE_PARAMETERS) with open(template_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(template_parameters, indent=4)) @@ -186,7 +282,7 @@ def write_vhd_parameters(self, folder_path: str) -> None: "azureDeployLocation": azureDeployLocation, } - vhd_parameters_path = os.path.join(folder_path, "vhdParameters.json") + vhd_parameters_path = os.path.join(folder_path, VHD_PARAMETERS) with open(vhd_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(vhd_parameters, indent=4)) @@ -204,26 +300,10 @@ def copy_to_output_folder(self) -> None: manifest_path = os.path.join(code_dir, "templates", self.manifest_template_name) shutil.copy(manifest_path, self.output_folder_name) - - os.mkdir(os.path.join(self.output_folder_name, SCHEMAS)) - tmp_schema_path = os.path.join( - self.tmp_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS - ) - output_schema_path = os.path.join( - self.output_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS - ) - shutil.copy( - tmp_schema_path, - output_schema_path, - ) - - tmp_config_mappings_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) - output_config_mappings_path = os.path.join( - self.output_folder_name, CONFIG_MAPPINGS - ) + # Copy everything in the temp folder to the output folder shutil.copytree( - tmp_config_mappings_path, - output_config_mappings_path, + self.tmp_folder_name, + self.output_folder_name, dirs_exist_ok=True, ) diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index a4318752a10..5651072eb84 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -3,35 +3,33 @@ # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- """Contains a class for generating VNF NFDs and associated resources.""" -from knack.log import get_logger import json import logging import os import shutil +import tempfile from functools import cached_property from pathlib import Path from typing import Any, Dict, Optional -import tempfile -from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator +from jinja2 import Template +from knack.log import get_logger from azext_aosm._configuration import NSConfiguration +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.util.constants import ( - NSD_DEFINITION_BICEP_SOURCE_TEMPLATE, - NSD_DEFINITION_BICEP_FILE, - NF_TEMPLATE_BICEP_FILE, + CONFIG_MAPPINGS, NF_DEFINITION_BICEP_FILE, + NF_TEMPLATE_BICEP_FILE, NSD_ARTIFACT_MANIFEST_BICEP_FILE, + NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE, NSD_CONFIG_MAPPING_FILE, + NSD_DEFINITION_BICEP_FILE, + NSD_DEFINITION_BICEP_SOURCE_TEMPLATE, SCHEMAS, - CONFIG_MAPPINGS, - NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE, TEMPLATES, ) -from jinja2 import Template - - logger = get_logger(__name__) diff --git a/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py b/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py index 0bc37d2e16e..e1ff05f0ff8 100644 --- a/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py +++ b/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py @@ -7,8 +7,7 @@ import unittest # from azure_devtools.scenario_tests import AllowLargeResponse -from azure.cli.testsdk import ScenarioTest, ResourceGroupPreparer - +from azure.cli.testsdk import ResourceGroupPreparer, ScenarioTest TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), "..")) diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 3ea1f7c25fe..2fcdb0e6cca 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -33,11 +33,27 @@ CNF_DEFINITION_BICEP_TEMPLATE = "cnfdefinition.bicep" CNF_MANIFEST_BICEP_TEMPLATE = "cnfartifactmanifest.bicep" -DEPLOYMENT_PARAMETERS = "deploymentParameters.json" + # Names of folder used in the repo CONFIG_MAPPINGS = "configMappings" SCHEMAS = "schemas" TEMPLATES = "templates" +GENERATED_VALUES_MAPPINGS = "generatedValuesMappings" + +# Names of files when building NFDs/NSDs +DEPLOYMENT_PARAMETERS = "deploymentParameters.json" +OPTIONAL_DEPLOYMENT_PARAMETERS_FILE = "optionalDeploymentParameters.txt" +TEMPLATE_PARAMETERS = "templateParameters.json" +VHD_PARAMETERS = "vhdParameters.json" +OPTIONAL_DEPLOYMENT_PARAMETERS_HEADING = ( + "# The following parameters are optional as they have default values.\n" + "# If you do not wish to expose them in the NFD, find and remove them from both\n" + f"# {DEPLOYMENT_PARAMETERS} and {TEMPLATE_PARAMETERS} (and {VHD_PARAMETERS} if\n" + "they are there)\n" + "# You can re-run the build command with the --order-params flag to order those\n" + "# files with the optional parameters at the end of the file, and with the \n" + "# --interactive flag to interactively choose y/n for each parameter to expose.\n\n" +) # Deployment Schema diff --git a/src/aosm/azext_aosm/util/management_clients.py b/src/aosm/azext_aosm/util/management_clients.py index 65ea9aa4afb..11712b4e894 100644 --- a/src/aosm/azext_aosm/util/management_clients.py +++ b/src/aosm/azext_aosm/util/management_clients.py @@ -4,8 +4,9 @@ # -------------------------------------------------------------------------------------------- """Clients for the python SDK along with useful caches.""" -from knack.log import get_logger from azure.mgmt.resource import ResourceManagementClient +from knack.log import get_logger + from azext_aosm.vendored_sdks import HybridNetworkManagementClient logger = get_logger(__name__) From e68093182715f03d35707e31c1942e09474184a1 Mon Sep 17 00:00:00 2001 From: Andy Churchard Date: Wed, 14 Jun 2023 16:18:10 +0100 Subject: [PATCH 101/145] Fix for oras target string with erroneous spaces --- src/aosm/azext_aosm/deploy/artifact.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index b1d8a17857a..f7bd4084def 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -47,8 +47,10 @@ def _upload_to_acr(self, artifact_config: ArtifactConfig) -> None: # the field. if artifact_config.file_path: - target = f"{self.artifact_client.remote.hostname.replace('https://', '')}\ - /{self.artifact_name}:{self.artifact_version}" + target = ( + f"{self.artifact_client.remote.hostname.replace('https://', '')}" + f"/{self.artifact_name}:{self.artifact_version}" + ) logger.debug("Uploading %s to %s", artifact_config.file_path, target) self.artifact_client.push( files=[artifact_config.file_path], From 4c543678d98fb6fc9be3a9ba68dd9acbd81772f0 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 15 Jun 2023 16:22:59 +0100 Subject: [PATCH 102/145] fixed regex; tested on existing charts and sas charts; committing to not lose prints for testing --- .../generate_nfd/cnf_nfd_generator.py | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index f7730256026..95bbef47a64 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -97,22 +97,21 @@ def generate_nfd(self) -> None: # Get all image line matches for files in the chart. # Do this here so we don't have to do it multiple times. - # image_line_matches = self.find_pattern_matches_in_chart( - # helm_package, IMAGE_LINE_REGEX - # ) image_line_matches = self.find_pattern_matches_in_chart( helm_package, IMAGE_LINE_REGEX, "image:" ) - print("first", image_line_matches) + + # Creates a flattened list to prevent set error + image_registry_paths = [] + for m in image_line_matches: + image_registry_paths += m[0] + # Generate the NF application configuration for the chart # passed to jinja2 renderer to render bicep template self.nf_application_configurations.append( self.generate_nf_application_config( helm_package, - image_line_matches, - # self.find_pattern_matches_in_chart( - # helm_package, IMAGE_PULL_SECRET_LINE_REGEX - # ), + image_registry_paths, self.find_pattern_matches_in_chart( helm_package, IMAGE_PULL_SECRET_LINE_REGEX, "imagePullSecrets:" ), @@ -121,7 +120,7 @@ def generate_nfd(self) -> None: # Workout the list of artifacts for the chart and # update the list for the NFD with any unique artifacts. chart_artifacts = self.get_artifact_list( - helm_package, set(image_line_matches) + helm_package, image_line_matches ) self.artifacts += [ a for a in chart_artifacts if a not in self.artifacts @@ -264,12 +263,14 @@ def copy_to_output_folder(self) -> None: def generate_nf_application_config( self, helm_package: HelmPackageConfig, - image_line_matches: List[Tuple[str, ...]], + # image_line_matches: List[Tuple[str, ...]], + image_registry_path: List[str], image_pull_secret_line_matches: List[Tuple[str, ...]], ) -> Dict[str, Any]: """Generate NF application config.""" (name, version) = self.get_chart_name_and_version(helm_package) - registryValuesPaths = set({m[0] for m in image_line_matches}) + + registryValuesPaths = set(image_registry_path) imagePullSecretsValuesPaths = set(image_pull_secret_line_matches) return { @@ -318,21 +319,14 @@ def find_pattern_matches_in_chart( print("LINE", start_string, line) path = re.findall(pattern, line) # testing splitting regex to get version and name - if start_string == "image:": - # re.findall(r"\/(.*)\:(.*)", line) - - # name_and_version = re.search(r"\/([^\s\/:]+):([^\s\/]+)", line) - name_and_version = re.search(r"\/([^\/]+):([^\/]+)", line) - # name_and_version = re.search(r'/(.+?):[\s"]*([^/)\s"]+)', line) + if start_string == "image:": + name_and_version = re.search(r"\/([^\s]*):([^\s)\"}]*)", line) print("name_and_version", name_and_version) print("n", name_and_version.group(1)) print("v", name_and_version.group(2)) - # name = name_and_version[0][0] - # version = name_and_version[0][1] - # print("name", name) # ( ['image1', 'image2'], 'name', 'version' ) - matches += (path, name_and_version.group(1), name_and_version.group(2)) - print("path", path) + match = (path, name_and_version.group(1), name_and_version.group(2)) + matches.append(match) else: matches += path print("MATCHES", matches) @@ -356,7 +350,6 @@ def get_artifact_list( "version": chart_version, } artifact_list.append(helm_artifact) - for match in image_line_matches: artifact_list.append( { @@ -383,7 +376,6 @@ def get_chart_mapping_schema( values_schema = os.path.join( self._tmp_folder_name, helm_package.name, "values.schema.json" ) - print("helm", helm_package.name) if not os.path.exists(mappings_path): raise InvalidTemplateError( @@ -424,7 +416,6 @@ def find_deploy_params( if nested_dict is None: return {} for k, v in nested_dict.items(): - # print("k", k) # if value is a string and contains deployParameters. if isinstance(v, str) and re.search(DEPLOYMENT_PARAMETER_MAPPING_REGEX, v): # only add the parameter name (e.g. from {deployParameter.zone} only param = zone) From 70c73460c47b806629942e55be95774f21590bad Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 15 Jun 2023 16:40:04 +0100 Subject: [PATCH 103/145] changed regex constants + tidied --- .../generate_nfd/cnf_nfd_generator.py | 52 +++++++------------ src/aosm/azext_aosm/util/constants.py | 8 +-- 2 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 95bbef47a64..70cba2ec698 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -24,15 +24,14 @@ CNF_MANIFEST_BICEP_TEMPLATE, CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE, DEPLOYMENT_PARAMETER_MAPPING_REGEX, - IMAGE_LINE_REGEX, - IMAGE_PULL_SECRET_LINE_REGEX, + IMAGE_NAME_AND_VERSION_REGEX, + IMAGE_PATH_REGEX, CONFIG_MAPPINGS, SCHEMAS, SCHEMA_PREFIX, DEPLOYMENT_PARAMETERS, ) - logger = get_logger(__name__) @@ -98,13 +97,13 @@ def generate_nfd(self) -> None: # Get all image line matches for files in the chart. # Do this here so we don't have to do it multiple times. image_line_matches = self.find_pattern_matches_in_chart( - helm_package, IMAGE_LINE_REGEX, "image:" + helm_package, "image:" ) - # Creates a flattened list to prevent set error + # Creates a flattened list of image registry paths to prevent set error image_registry_paths = [] - for m in image_line_matches: - image_registry_paths += m[0] + for registry_path in image_line_matches: + image_registry_paths += registry_path[0] # Generate the NF application configuration for the chart # passed to jinja2 renderer to render bicep template @@ -113,7 +112,7 @@ def generate_nfd(self) -> None: helm_package, image_registry_paths, self.find_pattern_matches_in_chart( - helm_package, IMAGE_PULL_SECRET_LINE_REGEX, "imagePullSecrets:" + helm_package, "imagePullSecrets:" ), ) ) @@ -263,23 +262,22 @@ def copy_to_output_folder(self) -> None: def generate_nf_application_config( self, helm_package: HelmPackageConfig, - # image_line_matches: List[Tuple[str, ...]], image_registry_path: List[str], image_pull_secret_line_matches: List[Tuple[str, ...]], ) -> Dict[str, Any]: """Generate NF application config.""" (name, version) = self.get_chart_name_and_version(helm_package) - registryValuesPaths = set(image_registry_path) - imagePullSecretsValuesPaths = set(image_pull_secret_line_matches) + registry_values_paths = set(image_registry_path) + image_pull_secrets_values_paths = set(image_pull_secret_line_matches) return { "name": helm_package.name, "chartName": name, "chartVersion": version, "dependsOnProfile": helm_package.depends_on, - "registryValuesPaths": list(registryValuesPaths), - "imagePullSecretsValuesPaths": list(imagePullSecretsValuesPaths), + "registryValuesPaths": list(registry_values_paths), + "imagePullSecretsValuesPaths": list(image_pull_secrets_values_paths), "valueMappingsPath": self.generate_parameter_mappings(helm_package), } @@ -295,41 +293,29 @@ def _find_yaml_files(self, directory) -> Iterator[str]: yield os.path.join(root, file) def find_pattern_matches_in_chart( - self, helm_package: HelmPackageConfig, pattern: str, start_string: str + self, helm_package: HelmPackageConfig, start_string: str ) -> List[Tuple[str, ...]]: """ Find pattern matches in Helm chart, using provided REGEX pattern. param helm_package: The helm package config. - param pattern: The regex pattern to match. + param start_string: The string to search for, either imagePullSecrets: or image: """ chart_dir = os.path.join(self._tmp_folder_name, helm_package.name) matches = [] path = [] - # name_and_version = () - # for file in self._find_yaml_files(chart_dir): - # with open(file, "r", encoding="UTF-8") as f: - # contents = f.read() - # print(re.findall(pattern, contents)) - # matches += re.findall(pattern, contents) + for file in self._find_yaml_files(chart_dir): with open(file, "r", encoding="UTF-8") as f: for line in f: if start_string in line: - print("LINE", start_string, line) - path = re.findall(pattern, line) - # testing splitting regex to get version and name - if start_string == "image:": - name_and_version = re.search(r"\/([^\s]*):([^\s)\"}]*)", line) - print("name_and_version", name_and_version) - print("n", name_and_version.group(1)) - print("v", name_and_version.group(2)) - # ( ['image1', 'image2'], 'name', 'version' ) - match = (path, name_and_version.group(1), name_and_version.group(2)) - matches.append(match) + path = re.findall(IMAGE_PATH_REGEX, line) + # If "image:", search for chart name and version + if start_string == "image:": + name_and_version = re.search(IMAGE_NAME_AND_VERSION_REGEX, line) + matches.append((path, name_and_version.group(1), name_and_version.group(2))) else: matches += path - print("MATCHES", matches) return matches def get_artifact_list( diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 4f036dbe58e..f760ee3a345 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -47,11 +47,7 @@ "type": "object", "properties": {}, } -# IMAGE_LINE_REGEX = ( -# r"image: \{\{ .Values.(.+?) \}\}/(.+?):(\d+\.\d+\.\d+(-\w+)?(\.\d+)?)" -# ) -IMAGE_LINE_REGEX = r".Values\.([^\s})]*)" -# IMAGE_PULL_SECRET_LINE_REGEX = r"imagePullSecrets: \[name: \{\{ .Values.(.+?) \}\}\]" -IMAGE_PULL_SECRET_LINE_REGEX = r".Values\.([^\s})]*)" +IMAGE_PATH_REGEX = r".Values\.([^\s})]*)" +IMAGE_NAME_AND_VERSION_REGEX = r"\/([^\s]*):([^\s)\"}]*)" DEPLOYMENT_PARAMETER_MAPPING_REGEX = r"\{deployParameters.(.+?)\}" From 126c68c206e3f5521ec898518854b028580d4e48 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 15 Jun 2023 16:48:02 +0100 Subject: [PATCH 104/145] fixed blankspace --- src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 70cba2ec698..cbb51508f58 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -99,7 +99,6 @@ def generate_nfd(self) -> None: image_line_matches = self.find_pattern_matches_in_chart( helm_package, "image:" ) - # Creates a flattened list of image registry paths to prevent set error image_registry_paths = [] for registry_path in image_line_matches: @@ -362,7 +361,6 @@ def get_chart_mapping_schema( values_schema = os.path.join( self._tmp_folder_name, helm_package.name, "values.schema.json" ) - if not os.path.exists(mappings_path): raise InvalidTemplateError( f"ERROR: The helm package '{helm_package.name}' does not have a valid values mappings file. \ From 93fb6afd797c615f96ce89b843316c68bcdf6166 Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 15 Jun 2023 17:59:35 +0100 Subject: [PATCH 105/145] markups --- .../generate_nfd/cnf_nfd_generator.py | 18 +++++++++++++----- src/aosm/azext_aosm/util/constants.py | 7 +++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 4f300d2763b..f77acd637bf 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -27,12 +27,12 @@ DEPLOYMENT_PARAMETER_MAPPING_REGEX, IMAGE_NAME_AND_VERSION_REGEX, IMAGE_PATH_REGEX, - CONFIG_MAPPINGS, - SCHEMAS, DEPLOYMENT_PARAMETERS, GENERATED_VALUES_MAPPINGS, SCHEMA_PREFIX, SCHEMAS, + IMAGE_PULL_SECRETS_START_STRING, + IMAGE_START_STRING ) from azext_aosm.util.utils import input_ack @@ -112,7 +112,7 @@ def generate_nfd(self) -> None: # Get all image line matches for files in the chart. # Do this here so we don't have to do it multiple times. image_line_matches = self.find_pattern_matches_in_chart( - helm_package, "image:" + helm_package, IMAGE_START_STRING ) # Creates a flattened list of image registry paths to prevent set error image_registry_paths = [] @@ -126,7 +126,7 @@ def generate_nfd(self) -> None: helm_package, image_registry_paths, self.find_pattern_matches_in_chart( - helm_package, "imagePullSecrets:" + helm_package, IMAGE_PULL_SECRETS_START_STRING ), ) ) @@ -389,6 +389,14 @@ def find_pattern_matches_in_chart( param helm_package: The helm package config. param start_string: The string to search for, either imagePullSecrets: or image: + + If searching for imagePullSecrets, + returns list of lists containing image pull secrets paths, + e.g. Values.foo.bar.imagePullSecret + + If searching for image, + returns list of tuples containing the list of image paths and the name and version of the image. + e.g. (Values.foo.bar.repoPath, foo, 1.2.3) """ chart_dir = os.path.join(self._tmp_folder_name, helm_package.name) matches = [] @@ -400,7 +408,7 @@ def find_pattern_matches_in_chart( if start_string in line: path = re.findall(IMAGE_PATH_REGEX, line) # If "image:", search for chart name and version - if start_string == "image:": + if start_string == IMAGE_START_STRING: name_and_version = re.search(IMAGE_NAME_AND_VERSION_REGEX, line) matches.append((path, name_and_version.group(1), name_and_version.group(2))) else: diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 15ac55d35a9..c5274b8ee93 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -64,6 +64,13 @@ "properties": {}, } +# For CNF NFD Generator +# To match the image path if image: is present in the yaml file +IMAGE_START_STRING = "image:" IMAGE_PATH_REGEX = r".Values\.([^\s})]*)" + +# To match the image name and version if imagePullSecrets: is present in the yaml file +IMAGE_PULL_SECRETS_START_STRING = "imagePullSecrets:" IMAGE_NAME_AND_VERSION_REGEX = r"\/([^\s]*):([^\s)\"}]*)" + DEPLOYMENT_PARAMETER_MAPPING_REGEX = r"\{deployParameters.(.+?)\}" From c57e4c53ba0e8a9f4c05c545f12aa4e143479bc7 Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 16 Jun 2023 17:42:24 +0100 Subject: [PATCH 106/145] initial commit --- .../generate_nfd/cnf_nfd_generator.py | 192 +++++++++++------- 1 file changed, 117 insertions(+), 75 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index f77acd637bf..3923ca0d255 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -476,10 +476,13 @@ def get_chart_mapping_schema( with open(values_schema, "r", encoding="utf-8") as f: data = json.load(f) - schema_data = data["properties"] + schema_data = data try: - final_schema = self.find_deploy_params(values_data, schema_data, {}) + # self.find_deploy_params(values_data) + deploy_params_dict = self.traverse_dict(values_data, DEPLOYMENT_PARAMETER_MAPPING_REGEX) + new_schema = self.search_schema(deploy_params_dict, schema_data) + print("here", new_schema) except KeyError as e: raise InvalidTemplateError( f"ERROR: Your schema and values for the helm package '{helm_package.name}' do not match. \ @@ -487,83 +490,122 @@ def get_chart_mapping_schema( ) from e logger.debug("Generated chart mapping schema for %s", helm_package.name) - return final_schema - - def find_deploy_params( - self, nested_dict, schema_nested_dict, final_schema - ) -> Dict[Any, Any]: + return new_schema + + def traverse_dict(self, d, target): + stack = [(d, [])] + result = {} + while stack: + (node, path) = stack.pop() + for k, v in node.items(): + if isinstance(v, dict): + stack.append((v, path + [k])) + elif isinstance(v, str) and re.search(target, v): + match = re.search(target, v) + result[match.group(1)] = path + [k] + if isinstance(node, list): + for i in node: + if isinstance(i, dict): + stack.append((i, path)) + print(result) + return result + + def search_schema(self, result, full_schema): """ - Create a schema of types of only those values in the values.mappings.yaml file which have a deployParameters mapping. - - Finds the relevant part of the full schema of the values file and finds the - type of the parameter name, then adds that to the final schema, with no nesting. + Search through provided schema for the types of the deployment parameters. + This assumes that the type of the key will be the type of the deployment parameter. + e.g. if foo: {deployParameter.bar} and foo is type string, then bar is type string. - Returns a schema of form: - { - "$schema": "https://json-schema.org/draft-07/schema#", - "title": "DeployParametersSchema", - "type": "object", - "properties": { - "": { - "type": "" - }, - "": { - "type": "" - }, - - nested_dict: the dictionary of the values mappings yaml which contains - deployParameters mapping placeholders - schema_nested_dict: the properties section of the full schema (or sub-object in - schema) - final_schema: Blank dictionary if this is the top level starting point, - otherwise the final_schema as far as we have got. + param result: The result of the traverse_dict function. + param full_schema: The schema to search through. """ - original_schema_nested_dict = schema_nested_dict - # if given a blank mapping file, return empty schema - if nested_dict is None: - return {} - for k, v in nested_dict.items(): - # if value is a string and contains deployParameters. - if isinstance(v, str) and re.search(DEPLOYMENT_PARAMETER_MAPPING_REGEX, v): - logger.debug( - "Found string deploy parameter for key %s, value %s. Find schema type", - k, - v, - ) - # only add the parameter name (e.g. from {deployParameter.zone} only - # param = zone) - param = v.split(".", 1)[1] - param = param.split("}", 1)[0] - - # add the schema for k (from the full schema) to the (new) schema - if "properties" in schema_nested_dict.keys(): - # Occurs if top level item in schema properties is an object with - # properties itself - final_schema.update( - {param: {"type": schema_nested_dict["properties"][k]["type"]}} - ) - else: - # Occurs if top level schema item in schema properties are objects - # with no "properties" - but can have "type". - final_schema.update( - {param: {"type": schema_nested_dict[k]["type"]}} - ) - # else if value is a (non-empty) dictionary (i.e another layer of nesting) - elif hasattr(v, "items") and v.items(): - logger.debug("Found dict value for key %s. Find schema type", k) - # handling schema having properties which doesn't map directly to the - # values file nesting - if "properties" in schema_nested_dict.keys(): - schema_nested_dict = schema_nested_dict["properties"][k] + # result = {'oam_paas_1': ['global', 'grafana', 'url']} + # node = schema + new_schema = {} + for deploy_param in result: + node = full_schema + for path_list in result[deploy_param]: + if "properties" in node.keys(): + node = node["properties"][path_list] else: - schema_nested_dict = schema_nested_dict[k] - # recursively call function with values (i.e the nested dictionary) - self.find_deploy_params(v, schema_nested_dict, final_schema) - # reset the schema dict to its original value (once finished with that - # level of recursion) - schema_nested_dict = original_schema_nested_dict - - return final_schema + print("No schema found for deployment parameter: ", deploy_param, " - assuming it is of type string") + new_schema.update({deploy_param: {"type": "string"}}) + if deploy_param not in new_schema: + new_schema.update({deploy_param: {"type": node.get('type', None)}}) + return new_schema + + # def find_deploy_params( + # self, nested_dict, schema_nested_dict, final_schema + # ) -> Dict[Any, Any]: + # """ + # Create a schema of types of only those values in the values.mappings.yaml file which have a deployParameters mapping. + # Finds the relevant part of the full schema of the values file and finds the + # type of the parameter name, then adds that to the final schema, with no nesting. + # Returns a schema of form: + # { + # "$schema": "https://json-schema.org/draft-07/schema#", + # "title": "DeployParametersSchema", + # "type": "object", + # "properties": { + # "": { + # "type": "" + # }, + # "": { + # "type": "" + # }, + # nested_dict: the dictionary of the values mappings yaml which contains + # deployParameters mapping placeholders + # schema_nested_dict: the properties section of the full schema (or sub-object in + # schema) + # final_schema: Blank dictionary if this is the top level starting point, + # otherwise the final_schema as far as we have got. + # """ + # original_schema_nested_dict = schema_nested_dict + # # if given a blank mapping file, return empty schema + # if nested_dict is None: + # return {} + # for k, v in nested_dict.items(): + # # if value is a string and contains deployParameters. + # if isinstance(v, str) and re.search(DEPLOYMENT_PARAMETER_MAPPING_REGEX, v): + # logger.debug( + # "Found string deploy parameter for key %s, value %s. Find schema type", + # k, + # v, + # ) + # # only add the parameter name (e.g. from {deployParameter.zone} only + # # param = zone) + # param = v.split(".", 1)[1] + # param = param.split("}", 1)[0] + + # # add the schema for k (from the full schema) to the (new) schema + # if "properties" in schema_nested_dict.keys(): + # # Occurs if top level item in schema properties is an object with + # # properties itself + # final_schema.update( + # {param: {"type": schema_nested_dict["properties"][k]["type"]}} + # ) + # else: + # # Occurs if top level schema item in schema properties are objects + # # with no "properties" - but can have "type". + # final_schema.update( + # {param: {"type": schema_nested_dict[k]["type"]}} + # ) + # # else if value is a (non-empty) dictionary (i.e another layer of nesting) + # elif hasattr(v, "items") and v.items(): + # logger.debug("Found dict value for key %s. Find schema type", k) + # # handling schema having properties which doesn't map directly to the + # # values file nesting + # if "properties" in schema_nested_dict.keys(): + # schema_nested_dict = schema_nested_dict["properties"][k] + # else: + # schema_nested_dict = schema_nested_dict[k] + # # recursively call function with values (i.e the nested dictionary) + # self.find_deploy_params(v, schema_nested_dict, final_schema) + # # reset the schema dict to its original value (once finished with that + # # level of recursion) + # schema_nested_dict = original_schema_nested_dict + + # return final_schema def _replace_values_with_deploy_params( self, From 63b4346382d5653294bd8ea1d378902ced975d41 Mon Sep 17 00:00:00 2001 From: Jordan Date: Fri, 16 Jun 2023 18:24:36 +0100 Subject: [PATCH 107/145] tidied code and added comments --- .../generate_nfd/cnf_nfd_generator.py | 126 +++++------------- 1 file changed, 30 insertions(+), 96 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 3923ca0d255..6f7fbf8f72e 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -310,7 +310,7 @@ def copy_to_output_folder(self) -> None: self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE ) shutil.copy(tmp_manifest_bicep_path, self.output_folder_name) - + # Copy any generated values mappings YAML files to the corresponding folder in # the output directory so that the user can edit them and re-run the build if # required @@ -479,13 +479,11 @@ def get_chart_mapping_schema( schema_data = data try: - # self.find_deploy_params(values_data) deploy_params_dict = self.traverse_dict(values_data, DEPLOYMENT_PARAMETER_MAPPING_REGEX) new_schema = self.search_schema(deploy_params_dict, schema_data) - print("here", new_schema) except KeyError as e: raise InvalidTemplateError( - f"ERROR: Your schema and values for the helm package '{helm_package.name}' do not match. \ + f"ERROR: There is a problem with your schema or values for the helm package '{helm_package.name}'. \ Please fix this and run the command again." ) from e @@ -493,34 +491,44 @@ def get_chart_mapping_schema( return new_schema def traverse_dict(self, d, target): - stack = [(d, [])] - result = {} - while stack: + """ + Traverse the dictionary that is loaded from the file provided by path_to_mappings in the input.json. + Returns a dictionary of all the values that match the target regex, + with the key being the deploy parameter and the value being the path to the value. + e.g. {"foo": ["global", "foo", "bar"]} + + param d: The dictionary to traverse. + param target: The regex to search for. + """ + stack = [(d, [])] # Initialize the stack with the dictionary and an empty path + result = {} # Initialize empty dictionary to store the results + while stack: # While there are still items in the stack + # Pop the last item from the stack and unpack it into node (the dictionary) and path (node, path) = stack.pop() - for k, v in node.items(): - if isinstance(v, dict): - stack.append((v, path + [k])) - elif isinstance(v, str) and re.search(target, v): - match = re.search(target, v) - result[match.group(1)] = path + [k] - if isinstance(node, list): + for k, v in node.items(): # For each key-value pair in the popped item + if isinstance(v, dict): # If the value is a dictionary + stack.append((v, path + [k])) # Add the dictionary to the stack with the path + elif isinstance(v, str) and re.search(target, v): # If the value is a string + matches target regex + match = re.search(target, v) # Take the match i.e, foo from {deployParameter.foo} + result[match.group(1)] = path + [k] # Add it to the result dictionary with its path as the value + if isinstance(node, list): # If the popped item is a list for i in node: if isinstance(i, dict): - stack.append((i, path)) - print(result) + stack.append((i, path)) # Add it to the stack with its path return result def search_schema(self, result, full_schema): """ - Search through provided schema for the types of the deployment parameters. + Search through provided schema for the types of the deployment parameters. This assumes that the type of the key will be the type of the deployment parameter. e.g. if foo: {deployParameter.bar} and foo is type string, then bar is type string. - + + Returns a dictionary of the deployment parameters in the format: + {"foo": {"type": "string"}, "bar": {"type": "string"}} + param result: The result of the traverse_dict function. param full_schema: The schema to search through. """ - # result = {'oam_paas_1': ['global', 'grafana', 'url']} - # node = schema new_schema = {} for deploy_param in result: node = full_schema @@ -528,85 +536,12 @@ def search_schema(self, result, full_schema): if "properties" in node.keys(): node = node["properties"][path_list] else: - print("No schema found for deployment parameter: ", deploy_param, " - assuming it is of type string") + print("No schema found for deployment parameter: ", deploy_param, ", we default to type string.") new_schema.update({deploy_param: {"type": "string"}}) if deploy_param not in new_schema: new_schema.update({deploy_param: {"type": node.get('type', None)}}) return new_schema - # def find_deploy_params( - # self, nested_dict, schema_nested_dict, final_schema - # ) -> Dict[Any, Any]: - # """ - # Create a schema of types of only those values in the values.mappings.yaml file which have a deployParameters mapping. - # Finds the relevant part of the full schema of the values file and finds the - # type of the parameter name, then adds that to the final schema, with no nesting. - # Returns a schema of form: - # { - # "$schema": "https://json-schema.org/draft-07/schema#", - # "title": "DeployParametersSchema", - # "type": "object", - # "properties": { - # "": { - # "type": "" - # }, - # "": { - # "type": "" - # }, - # nested_dict: the dictionary of the values mappings yaml which contains - # deployParameters mapping placeholders - # schema_nested_dict: the properties section of the full schema (or sub-object in - # schema) - # final_schema: Blank dictionary if this is the top level starting point, - # otherwise the final_schema as far as we have got. - # """ - # original_schema_nested_dict = schema_nested_dict - # # if given a blank mapping file, return empty schema - # if nested_dict is None: - # return {} - # for k, v in nested_dict.items(): - # # if value is a string and contains deployParameters. - # if isinstance(v, str) and re.search(DEPLOYMENT_PARAMETER_MAPPING_REGEX, v): - # logger.debug( - # "Found string deploy parameter for key %s, value %s. Find schema type", - # k, - # v, - # ) - # # only add the parameter name (e.g. from {deployParameter.zone} only - # # param = zone) - # param = v.split(".", 1)[1] - # param = param.split("}", 1)[0] - - # # add the schema for k (from the full schema) to the (new) schema - # if "properties" in schema_nested_dict.keys(): - # # Occurs if top level item in schema properties is an object with - # # properties itself - # final_schema.update( - # {param: {"type": schema_nested_dict["properties"][k]["type"]}} - # ) - # else: - # # Occurs if top level schema item in schema properties are objects - # # with no "properties" - but can have "type". - # final_schema.update( - # {param: {"type": schema_nested_dict[k]["type"]}} - # ) - # # else if value is a (non-empty) dictionary (i.e another layer of nesting) - # elif hasattr(v, "items") and v.items(): - # logger.debug("Found dict value for key %s. Find schema type", k) - # # handling schema having properties which doesn't map directly to the - # # values file nesting - # if "properties" in schema_nested_dict.keys(): - # schema_nested_dict = schema_nested_dict["properties"][k] - # else: - # schema_nested_dict = schema_nested_dict[k] - # # recursively call function with values (i.e the nested dictionary) - # self.find_deploy_params(v, schema_nested_dict, final_schema) - # # reset the schema dict to its original value (once finished with that - # # level of recursion) - # schema_nested_dict = original_schema_nested_dict - - # return final_schema - def _replace_values_with_deploy_params( self, values_yaml_dict, @@ -637,14 +572,13 @@ def _replace_values_with_deploy_params( # add the schema for k (from the big schema) to the (smaller) schema final_values_mapping_dict.update({k: replacement_value}) elif isinstance(v, dict): - final_values_mapping_dict[k] = self._replace_values_with_deploy_params( v, param_name ) elif isinstance(v, list): final_values_mapping_dict[k] = [] for index, item in enumerate(v): - param_name = f"{param_prefix}_{k}_{index}" if param_prefix else f"{k})_{index}" + param_name = f"{param_prefix}_{k}_{index}" if param_prefix else f"{k})_{index}" if isinstance(item, dict): final_values_mapping_dict[k].append( self._replace_values_with_deploy_params( From 93840e87d70fa98607ed95142d4eb1ca1cf1941e Mon Sep 17 00:00:00 2001 From: Jacob Darby Date: Sat, 17 Jun 2023 21:12:46 +0100 Subject: [PATCH 108/145] Add style and lint check --- .github/workflows/CheckStyleAndLinting.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/CheckStyleAndLinting.yml diff --git a/.github/workflows/CheckStyleAndLinting.yml b/.github/workflows/CheckStyleAndLinting.yml new file mode 100644 index 00000000000..0c8382649d8 --- /dev/null +++ b/.github/workflows/CheckStyleAndLinting.yml @@ -0,0 +1,18 @@ +name: Style and Lint Check + +on: + pull_request: + types: [opened] + +jobs: + build_aosm: + runs-on: ubuntu-latest + container: mcr.microsoft.com/azure-cli/tools:latest + permissions: write-all + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Check Style + run: azdev style aosm + - name: Check Linting + run: azdev linter aosm From 6c9a4788688f8c3233207d3fdc039ae1d5d3afba Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 19 Jun 2023 16:36:05 +0100 Subject: [PATCH 109/145] added logic for handling deployparams within lists --- .../azext_aosm/generate_nfd/cnf_nfd_generator.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 6f7fbf8f72e..6f461a93b0d 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -511,10 +511,11 @@ def traverse_dict(self, d, target): elif isinstance(v, str) and re.search(target, v): # If the value is a string + matches target regex match = re.search(target, v) # Take the match i.e, foo from {deployParameter.foo} result[match.group(1)] = path + [k] # Add it to the result dictionary with its path as the value - if isinstance(node, list): # If the popped item is a list - for i in node: - if isinstance(i, dict): - stack.append((i, path)) # Add it to the stack with its path + elif isinstance(v, list): + for i in v: + if isinstance(i, str) and re.search(target, i): + match = re.search(target, i) + result[match.group(1)] = path + [k] return result def search_schema(self, result, full_schema): @@ -530,16 +531,21 @@ def search_schema(self, result, full_schema): param full_schema: The schema to search through. """ new_schema = {} + no_schema_list = [] + print(result) for deploy_param in result: node = full_schema for path_list in result[deploy_param]: if "properties" in node.keys(): node = node["properties"][path_list] else: - print("No schema found for deployment parameter: ", deploy_param, ", we default to type string.") + no_schema_list.append(deploy_param) new_schema.update({deploy_param: {"type": "string"}}) if deploy_param not in new_schema: new_schema.update({deploy_param: {"type": node.get('type', None)}}) + if no_schema_list: + print("No schema found for deployment parameter(s):", no_schema_list) + print("We default these parameters to type string") return new_schema def _replace_values_with_deploy_params( From 3adcb8098d8b2f2e0a7b9e36bb31a0d898808e21 Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 19 Jun 2023 16:38:24 +0100 Subject: [PATCH 110/145] one line fix from review --- src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 6f461a93b0d..1db706accc6 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -475,8 +475,7 @@ def get_chart_mapping_schema( values_data = yaml.load(stream, Loader=yaml.SafeLoader) with open(values_schema, "r", encoding="utf-8") as f: - data = json.load(f) - schema_data = data + schema_data = json.load(f) try: deploy_params_dict = self.traverse_dict(values_data, DEPLOYMENT_PARAMETER_MAPPING_REGEX) From 85ae2474e36d52dc197858fbd684fc6943aac13e Mon Sep 17 00:00:00 2001 From: Jordan Date: Mon, 19 Jun 2023 16:39:54 +0100 Subject: [PATCH 111/145] removing print statement --- src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 1db706accc6..44be7a00e68 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -531,7 +531,6 @@ def search_schema(self, result, full_schema): """ new_schema = {} no_schema_list = [] - print(result) for deploy_param in result: node = full_schema for path_list in result[deploy_param]: From 7719df284612ea070911705f73fd23a45eae8cd5 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 20 Jun 2023 11:19:23 +0100 Subject: [PATCH 112/145] added new test file and one unit test --- src/aosm/azext_aosm/tests/latest/test_cnf.py | 53 ++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/aosm/azext_aosm/tests/latest/test_cnf.py diff --git a/src/aosm/azext_aosm/tests/latest/test_cnf.py b/src/aosm/azext_aosm/tests/latest/test_cnf.py new file mode 100644 index 00000000000..553dc11e2dd --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/test_cnf.py @@ -0,0 +1,53 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import os +import unittest +from unittest.mock import Mock, patch + +from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator + +# from azure_devtools.scenario_tests import AllowLargeResponse +# from azure.cli.testsdk import ResourceGroupPreparer, ScenarioTest +from azure.cli.core.azclierror import ( + BadRequestError, + InvalidArgumentValueError, + ResourceNotFoundError, + InvalidTemplateError +) + +class TestErrorMessages(unittest.TestCase): + def test_invalid_chart(self): + with self.assertRaises(InvalidTemplateError): + CnfNfdGenerator._extract_chart(self, "test/helmChart") + # def test_invalid_values(self): + # with self.assertRaises(InvalidTemplateError): + # CnfNfdGenerator.get_chart_mapping_schema(self, "test") + +# class AosmScenarioTest(ScenarioTest): +# @ResourceGroupPreparer(name_prefix="cli_test_aosm") +# def test__aosm(self, resource_group): +# self.kwargs.update({"name": "test1"}) + +# self.cmd( +# "aosm create -g {rg} -n {name} --tags foo=doo", +# checks=[self.check("tags.foo", "doo"), self.check("name", "{name}")], +# ) +# self.cmd( +# "aosm update -g {rg} -n {name} --tags foo=boo", +# checks=[self.check("tags.foo", "boo")], +# ) +# count = len(self.cmd("aosm list").get_output_in_json()) +# self.cmd( +# "aosm show - {rg} -n {name}", +# checks=[ +# self.check("name", "{name}"), +# self.check("resourceGroup", "{rg}"), +# self.check("tags.foo", "boo"), +# ], +# ) +# self.cmd("aosm delete -g {rg} -n {name}") +# final_count = len(self.cmd("aosm list").get_output_in_json()) +# self.assertTrue(final_count, count - 1) \ No newline at end of file From 077531d460773a4df47968539d1916a03962b0ca Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 20 Jun 2023 16:17:45 +0100 Subject: [PATCH 113/145] added workflow for unit tests in pipeline + set up rough structure of unit testing --- .github/workflows/RunUnitTests.yml | 22 ++++++++++++++++++++ src/aosm/azext_aosm/tests/latest/test_cnf.py | 19 ++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/RunUnitTests.yml diff --git a/.github/workflows/RunUnitTests.yml b/.github/workflows/RunUnitTests.yml new file mode 100644 index 00000000000..b9f4e99cdb8 --- /dev/null +++ b/.github/workflows/RunUnitTests.yml @@ -0,0 +1,22 @@ +name: Run Unit + Integration Tests + +on: + push: + branches: [add-aosm-extension] + pull_request: + branches: [add-aosm-extension] + +jobs: + check_tests: + runs-on: ubuntu-latest + container: mcr.microsoft.com/azure-cli/tools:latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + - name: Setup azdev + run: | + # Pretend we have a valid git repo to satisfy azdev. + mkdir .git + azdev setup -c EDGE -r . -e aosm + - name: Check Test + run: azdev test aosm \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/test_cnf.py b/src/aosm/azext_aosm/tests/latest/test_cnf.py index 553dc11e2dd..9df4193b8c0 100644 --- a/src/aosm/azext_aosm/tests/latest/test_cnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_cnf.py @@ -17,7 +17,7 @@ ResourceNotFoundError, InvalidTemplateError ) - +# this should probably be incorporated into each other class, not be on its own class TestErrorMessages(unittest.TestCase): def test_invalid_chart(self): with self.assertRaises(InvalidTemplateError): @@ -26,6 +26,23 @@ def test_invalid_chart(self): # with self.assertRaises(InvalidTemplateError): # CnfNfdGenerator.get_chart_mapping_schema(self, "test") +class TestExtractChart(unittest.TestCase): + pass +class TestGenerateChartValueMappings(unittest.TestCase): + pass +class TestGetChartMappingSchema(unittest.TestCase): + pass +class TestFindPatternMatchesInChart(unittest.TestCase): + pass + +class TestGenerateNFApplicationConfig(unittest.TestCase): + pass + +class TestGetArtifactList(unittest.TestCase): + pass +class TestWriteFilesToOutput(unittest.TestCase): + pass + # class AosmScenarioTest(ScenarioTest): # @ResourceGroupPreparer(name_prefix="cli_test_aosm") # def test__aosm(self, resource_group): From d7a4abfee53168928c4684428abfee8e6d1775e4 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 21 Jun 2023 15:17:32 +0100 Subject: [PATCH 114/145] instantiated cnf class; added fake invalid helm package; added new files to use for testing --- .../tests/latest/mock_cnf/config_file.json | 19 +++++ .../tests/latest/mock_cnf/invalid_chart.yaml | 0 .../latest/mock_cnf/invalid_mappings.yaml | 0 .../tests/latest/mock_cnf/valid_chart.tgz | 0 .../tests/latest/test_aosm_scenario.py | 50 ++++++------ src/aosm/azext_aosm/tests/latest/test_cnf.py | 79 +++++++++---------- src/aosm/azext_aosm/tests/latest/test_nsd.py | 10 +++ src/aosm/azext_aosm/tests/latest/test_vnf.py | 10 +++ 8 files changed, 103 insertions(+), 65 deletions(-) create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/config_file.json create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_chart.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_mappings.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/valid_chart.tgz create mode 100644 src/aosm/azext_aosm/tests/latest/test_nsd.py create mode 100644 src/aosm/azext_aosm/tests/latest/test_vnf.py diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/config_file.json b/src/aosm/azext_aosm/tests/latest/mock_cnf/config_file.json new file mode 100644 index 00000000000..60f54478c5d --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/config_file.json @@ -0,0 +1,19 @@ +{ + "publisher_name": "test_cnf_publisher", + "publisher_resource_group_name": "test_cnf_publisher_rg", + "nf_name": "test_cnf_nf", + "version": "1.0.0", + "acr_artifact_store_name": "test_cnf_acr", + "location": "uksouth", + "helm_packages": [ + { + "name": "invalid-package", + "path_to_chart": "src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_chart.yaml", + "path_to_mappings":"src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_mappings.yaml", + "depends_on": [] + }, + { + + } + ] +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_chart.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_chart.yaml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_mappings.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_mappings.yaml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/valid_chart.tgz b/src/aosm/azext_aosm/tests/latest/mock_cnf/valid_chart.tgz new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py b/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py index e1ff05f0ff8..fe10ce0d1de 100644 --- a/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py +++ b/src/aosm/azext_aosm/tests/latest/test_aosm_scenario.py @@ -11,29 +11,29 @@ TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), "..")) +## Note: keeping this only as an example for what we could do +# class AosmScenarioTest(ScenarioTest): +# @ResourceGroupPreparer(name_prefix="cli_test_aosm") +# def test_aosm(self, resource_group): +# self.kwargs.update({"name": "test1"}) -class AosmScenarioTest(ScenarioTest): - @ResourceGroupPreparer(name_prefix="cli_test_aosm") - def test_aosm(self, resource_group): - self.kwargs.update({"name": "test1"}) - - self.cmd( - "aosm create -g {rg} -n {name} --tags foo=doo", - checks=[self.check("tags.foo", "doo"), self.check("name", "{name}")], - ) - self.cmd( - "aosm update -g {rg} -n {name} --tags foo=boo", - checks=[self.check("tags.foo", "boo")], - ) - count = len(self.cmd("aosm list").get_output_in_json()) - self.cmd( - "aosm show - {rg} -n {name}", - checks=[ - self.check("name", "{name}"), - self.check("resourceGroup", "{rg}"), - self.check("tags.foo", "boo"), - ], - ) - self.cmd("aosm delete -g {rg} -n {name}") - final_count = len(self.cmd("aosm list").get_output_in_json()) - self.assertTrue(final_count, count - 1) +# self.cmd( +# "aosm create -g {rg} -n {name} --tags foo=doo", +# checks=[self.check("tags.foo", "doo"), self.check("name", "{name}")], +# ) +# self.cmd( +# "aosm update -g {rg} -n {name} --tags foo=boo", +# checks=[self.check("tags.foo", "boo")], +# ) +# count = len(self.cmd("aosm list").get_output_in_json()) +# self.cmd( +# "aosm show - {rg} -n {name}", +# checks=[ +# self.check("name", "{name}"), +# self.check("resourceGroup", "{rg}"), +# self.check("tags.foo", "boo"), +# ], +# ) +# self.cmd("aosm delete -g {rg} -n {name}") +# final_count = len(self.cmd("aosm list").get_output_in_json()) +# self.assertTrue(final_count, count - 1) diff --git a/src/aosm/azext_aosm/tests/latest/test_cnf.py b/src/aosm/azext_aosm/tests/latest/test_cnf.py index 9df4193b8c0..b2bb8c97d71 100644 --- a/src/aosm/azext_aosm/tests/latest/test_cnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_cnf.py @@ -3,68 +3,67 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -import os +# import os import unittest -from unittest.mock import Mock, patch +import json +import logging +# from unittest.mock import Mock, patch from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator +from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig -# from azure_devtools.scenario_tests import AllowLargeResponse -# from azure.cli.testsdk import ResourceGroupPreparer, ScenarioTest from azure.cli.core.azclierror import ( BadRequestError, InvalidArgumentValueError, ResourceNotFoundError, InvalidTemplateError ) -# this should probably be incorporated into each other class, not be on its own -class TestErrorMessages(unittest.TestCase): + +# Instantiate CNF with faked config file +with open("azext_aosm/tests/latest/mock_cnf/config_file.json", "r", encoding="utf-8") as f: + config_as_dict = json.loads(f.read()) +config = CNFConfiguration(**config_as_dict) +test_cnf = CnfNfdGenerator(config) +invalid_helm_package = test_cnf.config.helm_packages[0] +invalid_helm_package = HelmPackageConfig(**invalid_helm_package) + + +# pylint: disable=protected-access +class TestExtractChart(unittest.TestCase): + # Jordan: can we test whether this has extracted correctly in a unit test? def test_invalid_chart(self): with self.assertRaises(InvalidTemplateError): - CnfNfdGenerator._extract_chart(self, "test/helmChart") - # def test_invalid_values(self): - # with self.assertRaises(InvalidTemplateError): - # CnfNfdGenerator.get_chart_mapping_schema(self, "test") - -class TestExtractChart(unittest.TestCase): - pass + print("TEST", invalid_helm_package) + test_cnf._extract_chart(invalid_helm_package.path_to_chart) + + class TestGenerateChartValueMappings(unittest.TestCase): - pass + # Test for _read_top_level_values_yaml + # Test for _replace_values_with_deploy_params + def test_write_mappings_to_file(self): + pass + + def test_update_path_to_mappings(self): + pass + + class TestGetChartMappingSchema(unittest.TestCase): + # Test for traverse_dict + # Test for search_schema pass + + class TestFindPatternMatchesInChart(unittest.TestCase): pass + class TestGenerateNFApplicationConfig(unittest.TestCase): pass + class TestGetArtifactList(unittest.TestCase): pass + + class TestWriteFilesToOutput(unittest.TestCase): pass - -# class AosmScenarioTest(ScenarioTest): -# @ResourceGroupPreparer(name_prefix="cli_test_aosm") -# def test__aosm(self, resource_group): -# self.kwargs.update({"name": "test1"}) - -# self.cmd( -# "aosm create -g {rg} -n {name} --tags foo=doo", -# checks=[self.check("tags.foo", "doo"), self.check("name", "{name}")], -# ) -# self.cmd( -# "aosm update -g {rg} -n {name} --tags foo=boo", -# checks=[self.check("tags.foo", "boo")], -# ) -# count = len(self.cmd("aosm list").get_output_in_json()) -# self.cmd( -# "aosm show - {rg} -n {name}", -# checks=[ -# self.check("name", "{name}"), -# self.check("resourceGroup", "{rg}"), -# self.check("tags.foo", "boo"), -# ], -# ) -# self.cmd("aosm delete -g {rg} -n {name}") -# final_count = len(self.cmd("aosm list").get_output_in_json()) -# self.assertTrue(final_count, count - 1) \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/test_nsd.py b/src/aosm/azext_aosm/tests/latest/test_nsd.py new file mode 100644 index 00000000000..e5f0885cfce --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/test_nsd.py @@ -0,0 +1,10 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import os +import unittest +from unittest.mock import Mock, patch + +from azext_aosm.generate_nsd.nsd_generator import NSDGenerator diff --git a/src/aosm/azext_aosm/tests/latest/test_vnf.py b/src/aosm/azext_aosm/tests/latest/test_vnf.py new file mode 100644 index 00000000000..653978e8b8e --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/test_vnf.py @@ -0,0 +1,10 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import os +import unittest +from unittest.mock import Mock, patch + +from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator From 401389500b06e6672959de43ed376daca09ebdaf Mon Sep 17 00:00:00 2001 From: sunnycarter <36891339+sunnycarter@users.noreply.github.com> Date: Thu, 22 Jun 2023 15:44:15 +0100 Subject: [PATCH 115/145] Nsd for cnfs (#33) * NSD building for CNFs * linting --- src/aosm/azext_aosm/_configuration.py | 4 + src/aosm/azext_aosm/custom.py | 30 ++----- .../generate_nfd/cnf_nfd_generator.py | 89 ++++++++++++------- .../azext_aosm/generate_nsd/nsd_generator.py | 68 +++++++++++--- .../artifact_manifest_template.bicep | 2 +- .../generate_nsd/templates/nf_template.bicep | 4 +- 6 files changed, 130 insertions(+), 67 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index a26a3af3a77..0d9b368eaeb 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -58,6 +58,7 @@ "Exising Network Function Definition Version Name. " "This can be created using the 'az aosm nfd' commands.", "network_function_definition_offering_location": "Offering location of the Network Function Definition", + "network_function_type": "Type of nf in the definition. Valid values are 'cnf' or 'vnf'", "helm_package_name": "Name of the Helm package", "path_to_chart": "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz", @@ -123,6 +124,7 @@ class NSConfiguration: network_function_definition_offering_location: str = DESCRIPTION_MAP[ "network_function_definition_offering_location" ] + network_function_type: str = DESCRIPTION_MAP["network_function_type"] nsdg_name: str = DESCRIPTION_MAP["nsdg_name"] nsd_version: str = DESCRIPTION_MAP["nsd_version"] nsdv_description: str = DESCRIPTION_MAP["nsdv_description"] @@ -165,6 +167,8 @@ def validate(self): raise ValueError( "Network Function Definition Offering Location must be set" ) + if self.network_function_type not in [CNF, VNF]: + raise ValueError("Network Function Type must be cnf or vnf") if self.nsdg_name == DESCRIPTION_MAP["nsdg_name"] or "": raise ValueError("NSDG name must be set") if self.nsd_version == DESCRIPTION_MAP["nsd_version"] or "": diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 0d9fbe6ff2d..7c84eb17125 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -239,7 +239,7 @@ def _generate_config(configuration_type: str, output_file: str = "input.json"): with open(output_file, "w", encoding="utf-8") as f: f.write(config_as_dict) - if configuration_type in (CNF,VNF): + if configuration_type in (CNF, VNF): prtName = "definition" else: prtName = "design" @@ -264,7 +264,7 @@ def build_design(cmd, client: HybridNetworkManagementClient, config_file: str): # Read the config from the given file config = _get_config_from_file(config_file=config_file, configuration_type=NSD) - + assert isinstance(config, NSConfiguration) config.validate() # Generate the NSD and the artifact manifest. @@ -344,14 +344,8 @@ def publish_design( ) -def _generate_nsd(config: NSDGenerator, api_clients): - """Generate a Network Service Design for the given type and config.""" - if config: - nsd_generator = NSDGenerator(config) - else: - raise CLIInternalError("Generate NSD called without a config file") - deploy_parameters = _get_nfdv_deployment_parameters(config, api_clients) - +def _generate_nsd(config: NSConfiguration, api_clients: ApiClients): + """Generate a Network Service Design for the given config.""" if os.path.exists(config.build_output_folder_name): carry_on = input( f"The folder {config.build_output_folder_name} already exists - delete it and continue? (y/n)" @@ -360,17 +354,5 @@ def _generate_nsd(config: NSDGenerator, api_clients): raise UnclassifiedUserFault("User aborted! ") shutil.rmtree(config.build_output_folder_name) - - nsd_generator.generate_nsd(deploy_parameters) - - -def _get_nfdv_deployment_parameters(config: NSConfiguration, api_clients): - """Get the properties of the existing NFDV.""" - NFDV_object = api_clients.aosm_client.network_function_definition_versions.get( - resource_group_name=config.publisher_resource_group_name, - publisher_name=config.publisher_name, - network_function_definition_group_name=config.network_function_definition_group_name, - network_function_definition_version_name=config.network_function_definition_version_name, - ) - - return NFDV_object.deploy_parameters + nsd_generator = NSDGenerator(api_clients, config) + nsd_generator.generate_nsd() diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 44be7a00e68..b79873486e6 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -32,7 +32,7 @@ SCHEMA_PREFIX, SCHEMAS, IMAGE_PULL_SECRETS_START_STRING, - IMAGE_START_STRING + IMAGE_START_STRING, ) from azext_aosm.util.utils import input_ack @@ -222,7 +222,8 @@ def _generate_chart_value_mappings(self, helm_package: HelmPackageConfig) -> Non def _read_top_level_values_yaml( self, helm_package: HelmPackageConfig ) -> Dict[str, Any]: - """Return a dictionary of the values.yaml|yml read from the root of the helm package. + """ + Return a dictionary of the values.yaml|yml read from the root of the helm package. :param helm_package: The helm package to look in :type helm_package: HelmPackageConfig @@ -387,16 +388,15 @@ def find_pattern_matches_in_chart( """ Find pattern matches in Helm chart, using provided REGEX pattern. - param helm_package: The helm package config. - param start_string: The string to search for, either imagePullSecrets: or image: + :param helm_package: The helm package config. + :param start_string: The string to search for, either imagePullSecrets: or image: - If searching for imagePullSecrets, - returns list of lists containing image pull secrets paths, - e.g. Values.foo.bar.imagePullSecret + If searching for imagePullSecrets, returns list of lists containing image pull + secrets paths, e.g. Values.foo.bar.imagePullSecret - If searching for image, - returns list of tuples containing the list of image paths and the name and version of the image. - e.g. (Values.foo.bar.repoPath, foo, 1.2.3) + If searching for image, returns list of tuples containing the list of image + paths and the name and version of the image. e.g. (Values.foo.bar.repoPath, foo, + 1.2.3) """ chart_dir = os.path.join(self._tmp_folder_name, helm_package.name) matches = [] @@ -409,8 +409,16 @@ def find_pattern_matches_in_chart( path = re.findall(IMAGE_PATH_REGEX, line) # If "image:", search for chart name and version if start_string == IMAGE_START_STRING: - name_and_version = re.search(IMAGE_NAME_AND_VERSION_REGEX, line) - matches.append((path, name_and_version.group(1), name_and_version.group(2))) + name_and_version = re.search( + IMAGE_NAME_AND_VERSION_REGEX, line + ) + matches.append( + ( + path, + name_and_version.group(1), + name_and_version.group(2), + ) + ) else: matches += path return matches @@ -423,8 +431,8 @@ def get_artifact_list( """ Get the list of artifacts for the chart. - param helm_package: The helm package config. param image_line_matches: The list - of image line matches. + :param helm_package: The helm package config. + :param image_line_matches: The list of image line matches. """ artifact_list = [] (chart_name, chart_version) = self.get_chart_name_and_version(helm_package) @@ -478,7 +486,9 @@ def get_chart_mapping_schema( schema_data = json.load(f) try: - deploy_params_dict = self.traverse_dict(values_data, DEPLOYMENT_PARAMETER_MAPPING_REGEX) + deploy_params_dict = self.traverse_dict( + values_data, DEPLOYMENT_PARAMETER_MAPPING_REGEX + ) new_schema = self.search_schema(deploy_params_dict, schema_data) except KeyError as e: raise InvalidTemplateError( @@ -492,24 +502,39 @@ def get_chart_mapping_schema( def traverse_dict(self, d, target): """ Traverse the dictionary that is loaded from the file provided by path_to_mappings in the input.json. + Returns a dictionary of all the values that match the target regex, with the key being the deploy parameter and the value being the path to the value. e.g. {"foo": ["global", "foo", "bar"]} - param d: The dictionary to traverse. - param target: The regex to search for. + :param d: The dictionary to traverse. + :param target: The regex to search for. """ stack = [(d, [])] # Initialize the stack with the dictionary and an empty path result = {} # Initialize empty dictionary to store the results while stack: # While there are still items in the stack # Pop the last item from the stack and unpack it into node (the dictionary) and path (node, path) = stack.pop() - for k, v in node.items(): # For each key-value pair in the popped item - if isinstance(v, dict): # If the value is a dictionary - stack.append((v, path + [k])) # Add the dictionary to the stack with the path - elif isinstance(v, str) and re.search(target, v): # If the value is a string + matches target regex - match = re.search(target, v) # Take the match i.e, foo from {deployParameter.foo} - result[match.group(1)] = path + [k] # Add it to the result dictionary with its path as the value + # For each key-value pair in the popped item + for k, v in node.items(): + # If the value is a dictionary + if isinstance(v, dict): + # Add the dictionary to the stack with the path + stack.append( + (v, path + [k]) + ) + # If the value is a string + matches target regex + elif isinstance(v, str) and re.search( + target, v + ): + # Take the match i.e, foo from {deployParameter.foo} + match = re.search( + target, v + ) + # Add it to the result dictionary with its path as the value + result[match.group(1)] = path + [ + k + ] elif isinstance(v, list): for i in v: if isinstance(i, str) and re.search(target, i): @@ -540,7 +565,7 @@ def search_schema(self, result, full_schema): no_schema_list.append(deploy_param) new_schema.update({deploy_param: {"type": "string"}}) if deploy_param not in new_schema: - new_schema.update({deploy_param: {"type": node.get('type', None)}}) + new_schema.update({deploy_param: {"type": node.get("type", None)}}) if no_schema_list: print("No schema found for deployment parameter(s):", no_schema_list) print("We default these parameters to type string") @@ -582,12 +607,14 @@ def _replace_values_with_deploy_params( elif isinstance(v, list): final_values_mapping_dict[k] = [] for index, item in enumerate(v): - param_name = f"{param_prefix}_{k}_{index}" if param_prefix else f"{k})_{index}" + param_name = ( + f"{param_prefix}_{k}_{index}" + if param_prefix + else f"{k})_{index}" + ) if isinstance(item, dict): final_values_mapping_dict[k].append( - self._replace_values_with_deploy_params( - item, param_name - ) + self._replace_values_with_deploy_params(item, param_name) ) elif isinstance(v, (str, int, bool)): replacement_value = f"{{deployParameters.{param_name}}}" @@ -595,11 +622,13 @@ def _replace_values_with_deploy_params( else: raise ValueError( f"Found an unexpected type {type(v)} of key {k} in " - "values.yaml, cannot generate values mapping file.") + "values.yaml, cannot generate values mapping file." + ) else: raise ValueError( f"Found an unexpected type {type(v)} of key {k} in values.yaml, " - "cannot generate values mapping file.") + "cannot generate values mapping file." + ) return final_values_mapping_dict diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index 5651072eb84..9d4f3b1b8dc 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -2,21 +2,18 @@ # Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- -"""Contains a class for generating VNF NFDs and associated resources.""" +"""Contains a class for generating NSDs and associated resources.""" import json -import logging import os import shutil import tempfile -from functools import cached_property -from pathlib import Path -from typing import Any, Dict, Optional +from typing import Dict from jinja2 import Template from knack.log import get_logger +from azext_aosm.vendored_sdks.models import NFVIType from azext_aosm._configuration import NSConfiguration -from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.util.constants import ( CONFIG_MAPPINGS, NF_DEFINITION_BICEP_FILE, @@ -28,10 +25,22 @@ NSD_DEFINITION_BICEP_SOURCE_TEMPLATE, SCHEMAS, TEMPLATES, + VNF, ) +from azext_aosm.util.management_clients import ApiClients +from azext_aosm.vendored_sdks.models import NetworkFunctionDefinitionVersion logger = get_logger(__name__) +# Different types are used in Bicep templates and NFDs. The list accepted by NFDs is +# documented in the AOSM meta-schema. This will be published in the future but for now +# can be found in +# https://microsoft.sharepoint.com/:w:/t/NSODevTeam/Ec7ovdKroSRIv5tumQnWIE0BE-B2LykRcll2Qb9JwfVFMQ +NFV_TO_BICEP_PARAM_TYPES: Dict[str, str] = { + "integer": "int", + "boolean": "bool", +} + class NSDGenerator: """ @@ -46,20 +55,42 @@ class NSDGenerator: be deployed by the NSDV """ - def __init__(self, config: NSConfiguration): + def __init__(self, api_clients: ApiClients, config: NSConfiguration): self.config = config self.nsd_bicep_template_name = NSD_DEFINITION_BICEP_SOURCE_TEMPLATE self.nf_bicep_template_name = NF_TEMPLATE_BICEP_FILE self.nsd_bicep_output_name = NSD_DEFINITION_BICEP_FILE self.build_folder_name = self.config.build_output_folder_name + nfdv = self._get_nfdv(config, api_clients) + print("Finding the deploy parameters of the NFDV resource") + if not nfdv.deploy_parameters: + raise NotImplementedError( + "NFDV has no deploy parameters, cannot generate NSD." + ) + self.deploy_parameters: str = nfdv.deploy_parameters + + def _get_nfdv( + self, config: NSConfiguration, api_clients + ) -> NetworkFunctionDefinitionVersion: + """Get the existing NFDV resource object.""" + print( + "Reading existing NFDV resource object " + f"{config.network_function_definition_version_name} from group " + f"{config.network_function_definition_group_name}" + ) + nfdv_object = api_clients.aosm_client.network_function_definition_versions.get( + resource_group_name=config.publisher_resource_group_name, + publisher_name=config.publisher_name, + network_function_definition_group_name=config.network_function_definition_group_name, + network_function_definition_version_name=config.network_function_definition_version_name, + ) + return nfdv_object - def generate_nsd(self, deploy_parameters) -> None: + def generate_nsd(self) -> None: """Generate a NSD templates which includes an Artifact Manifest, NFDV and NF templates.""" logger.info(f"Generate NSD bicep templates") - self.deploy_parameters = deploy_parameters - # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: self.tmp_folder_name = tmpdirname @@ -131,13 +162,22 @@ def write_nf_bicep(self) -> None: bicep_deploymentValues = "" deploy_parameters_dict = json.loads(self.deploy_parameters) + if "properties" not in deploy_parameters_dict: + raise ValueError( + f"NFDV in {self.config.network_function_definition_group_name} has " + "no properties within deployParameters" + ) + deploy_properties = deploy_parameters_dict["properties"] for key, value in deploy_properties.items(): # location is sometimes part of deploy_properties. # We want to avoid having duplicate params in the bicep template if key != "location": - bicep_params += f"param {key} {value['type']}\n" + bicep_type = ( + NFV_TO_BICEP_PARAM_TYPES.get(value["type"]) or value["type"] + ) + bicep_params += f"param {key} {bicep_type}\n" bicep_deploymentValues += f"{key}: {key}\n " self.generate_bicep( @@ -152,6 +192,12 @@ def write_nf_bicep(self) -> None: "network_function_definition_version_name": self.config.network_function_definition_version_name, "network_function_definition_offering_location": self.config.network_function_definition_offering_location, "location": self.config.location, + # Ideally we would use the network_function_type from reading the actual + # NF, as we do for deployParameters, but the SDK currently doesn't + # support this and needs to be rebuilt to do so. + "nfvi_type": NFVIType.AZURE_CORE + if self.config.network_function_type == VNF + else NFVIType.AZURE_ARC_KUBERNETES.value, }, ) diff --git a/src/aosm/azext_aosm/generate_nsd/templates/artifact_manifest_template.bicep b/src/aosm/azext_aosm/generate_nsd/templates/artifact_manifest_template.bicep index 1d6f28c1d83..4dcdcf18114 100644 --- a/src/aosm/azext_aosm/generate_nsd/templates/artifact_manifest_template.bicep +++ b/src/aosm/azext_aosm/generate_nsd/templates/artifact_manifest_template.bicep @@ -31,7 +31,7 @@ resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/ artifacts: [ { artifactName: armTemplateName - artifactType: 'OCIArtifact' + artifactType: 'ArmTemplate' artifactVersion: armTemplateVersion } ] diff --git a/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep b/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep index d558ef3f316..a32d583e772 100644 --- a/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep +++ b/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep @@ -17,6 +17,8 @@ param networkFunctionDefinitionOfferingLocation string = '{{network_function_def param location string = '{{location}}' +param nfviType string = '{{nfvi_type}}' + param resourceGroupId string = resourceGroup().id {{bicep_params}} @@ -34,7 +36,7 @@ resource nf_resource 'Microsoft.HybridNetwork/networkFunctions@2023-04-01-previe networkFunctionDefinitionGroupName: networkFunctionDefinitionGroupName networkFunctionDefinitionVersion: networkFunctionDefinitionVersion networkFunctionDefinitionOfferingLocation: networkFunctionDefinitionOfferingLocation - nfviType: 'AzureCore' + nfviType: nfviType nfviId: resourceGroupId allowSoftwareUpdate: true deploymentValues: string(deploymentValues) From 689acf4ceefa1556ec70b520e165b9d12ecae02f Mon Sep 17 00:00:00 2001 From: patrykkulik-microsoft <116072282+patrykkulik-microsoft@users.noreply.github.com> Date: Fri, 23 Jun 2023 10:12:30 +0100 Subject: [PATCH 116/145] Add Publish command to the CNF azure CLI (#24) * Working publish * Fix the artifact upload * Working image copy * minor fix * Minor fixes * sunny merge add-aosm-extension into patryk's branch (#25) * Sunny/choose deploy parameters (#23) * choose-deploy-parameters * optioned deployParameters for CNF * lint * lint2 * docs * docs * lint * 9.82 score * Fix bugs * more useful debug logs * Fix bugs and logging * lint * markups * comment out breaking line * minor TODOs * deleted comment * fix bring your own parameters * Markups * Fix the helm upload * Minor markups * Change error message --------- Co-authored-by: sunnycarter <36891339+sunnycarter@users.noreply.github.com> Co-authored-by: Sunny Carter --- src/aosm/HISTORY.rst | 1 + src/aosm/README.md | 43 ++-- src/aosm/azext_aosm/_client_factory.py | 13 ++ src/aosm/azext_aosm/_configuration.py | 43 ++-- src/aosm/azext_aosm/custom.py | 30 ++- src/aosm/azext_aosm/delete/delete.py | 15 +- src/aosm/azext_aosm/deploy/artifact.py | 101 ++++++++- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 210 ++++++++++++++++-- src/aosm/azext_aosm/deploy/pre_deploy.py | 64 +++++- .../generate_nfd/cnf_nfd_generator.py | 64 +++++- .../azext_aosm/generate_nsd/nsd_generator.py | 1 + src/aosm/azext_aosm/util/constants.py | 2 - .../azext_aosm/util/management_clients.py | 5 + 13 files changed, 496 insertions(+), 96 deletions(-) diff --git a/src/aosm/HISTORY.rst b/src/aosm/HISTORY.rst index 93107646473..8a3d7b2d91a 100644 --- a/src/aosm/HISTORY.rst +++ b/src/aosm/HISTORY.rst @@ -6,6 +6,7 @@ Release History unreleased ++++++++++ * `az aosm nfd build` options `--order-params` and `--interactive` to help users choose which NF parameters to expose as deployParameters. Feature added that allows CNF value mappings file to be generated if none is supplied. +* `az aosm nfd publish` option added for `--definition-type cnf` to publish the CNF bicep templates, upload helm charts from disk to the ACR and copy the images from a source ACR to the target ACR. 0.2.0 ++++++ diff --git a/src/aosm/README.md b/src/aosm/README.md index 2ebeb4d1680..f1cc088e5d6 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -67,28 +67,31 @@ image that would be used for the VNF Virtual Machine. #### CNFs -For CNFs, you must provide helm packages with an associated schema. -Optionally, you can provide a file path_to_mappings which is a copy of values.yaml with your chosen values replaced by deployment parameters, thus exposing them as parameters to the CNF. You can get this file auto-generated by leaving the value as a blank string, either having every value as -a deployment parameter, or using --interactive to interactively choose. +For CNFs you must have the `helm` package installed on the machine you are running the CLI from. Instructions on how to do this can be found [here](https://helm.sh/docs/intro/install/). + +For CNFs, you must provide: +* helm packages with an associated schema. These files must be on your disk and will be referenced in the `input.json` config file. +* a reference to an existing Azure Container Registry which contains the images for your CNF. Currently, only one ACR is supported per CNF. The images to be copied from this ACR are populated automatically based on the helm package schema. +* optionally, you can provide a file (on disk) path_to_mappings which is a copy of values.yaml with your chosen values replaced by deployment parameters, thus exposing them as parameters to the CNF. You can get this file auto-generated by leaving the value as a blank string, either having every value as a deployment parameter, or using `--interactive` to interactively choose. When filling in the input.json file, you must list helm packages in the order they are to be deployed. For example, if A must be deployed before B, your input.json should look something like this: - "helm_packages": [ - { - "name": "A", - "path_to_chart": "Path to package A", - "path_to_mappings": "Path to package A mappings", - "depends_on": [ - "Names of the Helm packages this package depends on" - ] - }, - { - "name": "B", - "path_to_chart": "Path to package B", - "path_to_mappings": "Path to package B mappings", - "depends_on": [ - "Names of the Helm packages this package depends on" - ] - }, + "helm_packages": [ + { + "name": "A", + "path_to_chart": "Path to package A", + "path_to_mappings": "Path to package A mappings", + "depends_on": [ + "Names of the Helm packages this package depends on" + ] + }, + { + "name": "B", + "path_to_chart": "Path to package B", + "path_to_mappings": "Path to package B mappings", + "depends_on": [ + "Names of the Helm packages this package depends on" + ] + }, #### NSDs For NSDs, you will need to have a Resource Group with a deployed Publisher, Artifact Store, Network Function Definition and Network Function Definition Version. You can use the `az aosm nfd` commands to create all of these resources. diff --git a/src/aosm/azext_aosm/_client_factory.py b/src/aosm/azext_aosm/_client_factory.py index 939880b240f..66c3bea2ab8 100644 --- a/src/aosm/azext_aosm/_client_factory.py +++ b/src/aosm/azext_aosm/_client_factory.py @@ -7,6 +7,7 @@ from azure.cli.core.profiles import ResourceType from .vendored_sdks import HybridNetworkManagementClient +from azure.mgmt.containerregistry import ContainerRegistryManagementClient def cf_aosm(cli_ctx, *_) -> HybridNetworkManagementClient: @@ -17,3 +18,15 @@ def cf_resources(cli_ctx, subscription_id=None): return get_mgmt_service_client( cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id ) + + +def cf_acr_registries(cli_ctx, *_) -> ContainerRegistryManagementClient: + """ + Returns the client for managing container registries. + + :param cli_ctx: CLI context + :return: ContainerRegistryManagementClient object + """ + return get_mgmt_service_client( + cli_ctx, ResourceType.MGMT_CONTAINERREGISTRY + ).registries diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 0d9b368eaeb..253104e4e85 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -37,26 +37,20 @@ "Name of the storage account Artifact Store resource. Will be created if it " "does not exist.", "artifact_name": "Name of the artifact", - "file_path": - "Optional. File path of the artifact you wish to upload from your local disk. " - "Delete if not required.", - "blob_sas_url": - "Optional. SAS URL of the blob artifact you wish to copy to your Artifact Store. " - "Delete if not required.", - "artifact_version": - "Version of the artifact. For VHDs this must be in format A-B-C. " - "For ARM templates this must be in format A.B.C", + "file_path": "Optional. File path of the artifact you wish to upload from your local disk. " + "Delete if not required.", + "blob_sas_url": "Optional. SAS URL of the blob artifact you wish to copy to your Artifact Store. " + "Delete if not required.", + "artifact_version": "Version of the artifact. For VHDs this must be in format A-B-C. " + "For ARM templates this must be in format A.B.C", "nsdv_description": "Description of the NSDV", - "nsdg_name": - "Network Service Design Group Name. This is the collection of Network Service Design Versions. " - "Will be created if it does not exist.", + "nsdg_name": "Network Service Design Group Name. This is the collection of Network Service Design Versions. " + "Will be created if it does not exist.", "nsd_version": "Version of the NSD to be created. This should be in the format A.B.C", - "network_function_definition_group_name": - "Exising Network Function Definition Group Name. " - "This can be created using the 'az aosm nfd' commands.", - "network_function_definition_version_name": - "Exising Network Function Definition Version Name. " - "This can be created using the 'az aosm nfd' commands.", + "network_function_definition_group_name": "Exising Network Function Definition Group Name. " + "This can be created using the 'az aosm nfd' commands.", + "network_function_definition_version_name": "Exising Network Function Definition Version Name. " + "This can be created using the 'az aosm nfd' commands.", "network_function_definition_offering_location": "Offering location of the Network Function Definition", "network_function_type": "Type of nf in the definition. Valid values are 'cnf' or 'vnf'", "helm_package_name": "Name of the Helm package", @@ -72,6 +66,7 @@ "helm_depends_on": "Names of the Helm packages this package depends on. " "Leave as an empty array if no dependencies", + "source_registry_id": "Resource ID of the source acr registry from which to pull the image", } @@ -303,6 +298,7 @@ class HelmPackageConfig: @dataclass class CNFConfiguration(NFConfiguration): + source_registry_id: str = DESCRIPTION_MAP["source_registry_id"] helm_packages: List[Any] = field(default_factory=lambda: [HelmPackageConfig()]) def __post_init__(self): @@ -311,9 +307,9 @@ def __post_init__(self): Used when creating CNFConfiguration object from a loaded json config file. """ - for package in self.helm_packages: + for package_index, package in enumerate(self.helm_packages): if isinstance(package, dict): - package = HelmPackageConfig(**dict(package)) + self.helm_packages[package_index] = HelmPackageConfig(**dict(package)) @property def build_output_folder_name(self) -> str: @@ -324,6 +320,13 @@ def build_output_folder_name(self) -> str: def get_configuration( configuration_type: str, config_as_dict: Optional[Dict[Any, Any]] = None ) -> NFConfiguration or NSConfiguration: + """ + Return the correct configuration object based on the type. + + :param configuration_type: The type of configuration to return + :param config_as_dict: The configuration as a dictionary + :return: The configuration object + """ if config_as_dict is None: config_as_dict = {} diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 7c84eb17125..6885a31276d 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -16,7 +16,7 @@ ) from knack.log import get_logger -from azext_aosm._client_factory import cf_resources +from azext_aosm._client_factory import cf_resources, cf_acr_registries from azext_aosm._configuration import ( CNFConfiguration, NFConfiguration, @@ -156,11 +156,15 @@ def publish_definition( """ print("Publishing definition.") api_clients = ApiClients( - aosm_client=client, resource_client=cf_resources(cmd.cli_ctx) + aosm_client=client, + resource_client=cf_resources(cmd.cli_ctx), + container_registry_client=cf_acr_registries(cmd.cli_ctx), ) + config = _get_config_from_file( config_file=config_file, configuration_type=definition_type ) + if definition_type == VNF: deployer = DeployerViaArm(api_clients, config=config) deployer.deploy_vnfd_from_bicep( @@ -169,10 +173,18 @@ def publish_definition( manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, ) + elif definition_type == CNF: + deployer = DeployerViaArm(api_clients, config=config) + deployer.deploy_cnfd_from_bicep( + cli_ctx=cmd.cli_ctx, + bicep_path=definition_file, + parameters_json_file=parameters_json_file, + manifest_bicep_path=manifest_file, + manifest_parameters_json_file=manifest_parameters_json_file, + ) else: - raise NotImplementedError( - "Publishing of CNF definitions is not yet implemented. \ - You should manually deploy your bicep file and upload charts and images to your artifact store. " + raise ValueError( + f"Definition type must be either 'vnf' or 'cnf'. Definition type {definition_type} is not recognised." ) @@ -202,10 +214,12 @@ def delete_published_definition( delly = ResourceDeleter(api_clients, config) if definition_type == VNF: - delly.delete_vnf(clean=clean) + delly.delete_nfd(clean=clean) + elif definition_type == CNF: + delly.delete_nfd(clean=clean) else: - raise NotImplementedError( - "Deleting of published CNF definitions is not yet implemented." + raise ValueError( + f"Definition type must be either 'vnf' or 'cnf'. Definition type {definition_type} is not recognised." ) diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 7cb01d8ce9e..aeedaaf4543 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -30,15 +30,15 @@ def __init__( self.api_clients = api_clients self.config = config - def delete_vnf(self, clean: bool = False): + def delete_nfd(self, clean: bool = False): """ Delete the NFDV and manifests. If they don't exist it still reports them as deleted. - :param clean: Delete the NFDG, artifact stores and publisher too. defaults - to False Use with care. + :param clean: Delete the NFDG, artifact stores and publisher too. Defaults to False. + Use with care. """ - assert isinstance(self.config, VNFConfiguration) + if clean: print( f"Are you sure you want to delete all resources associated with NFD {self.config.nf_name} including the artifact stores and publisher {self.config.publisher_name}?" @@ -63,14 +63,17 @@ def delete_vnf(self, clean: bool = False): return self.delete_nfdv() - self.delete_artifact_manifest("sa") + + if isinstance(self.config, VNFConfiguration): + self.delete_artifact_manifest("sa") self.delete_artifact_manifest("acr") if clean: logger.info("Delete called for all resources.") self.delete_nfdg() self.delete_artifact_store("acr") - self.delete_artifact_store("sa") + if isinstance(self.config, VNFConfiguration): + self.delete_artifact_store("sa") self.delete_publisher() def delete_nsd(self): diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index f7bd4084def..905e715693c 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -5,12 +5,18 @@ """A module to handle interacting with artifacts.""" from dataclasses import dataclass from typing import Union - -from azure.storage.blob import BlobClient, BlobType +import subprocess from knack.log import get_logger from oras.client import OrasClient -from azext_aosm._configuration import ArtifactConfig +from azure.storage.blob import BlobClient, BlobType +from azext_aosm._configuration import ArtifactConfig, HelmPackageConfig +from azure.mgmt.containerregistry.models import ( + ImportImageParameters, + ImportSource, +) + +from azure.cli.core.commands import LongRunningOperation logger = get_logger(__name__) @@ -24,28 +30,30 @@ class Artifact: artifact_version: str artifact_client: Union[BlobClient, OrasClient] - def upload(self, artifact_config: ArtifactConfig) -> None: + def upload(self, artifact_config: ArtifactConfig or HelmPackageConfig) -> None: """ Upload aritfact. :param artifact_config: configuration for the artifact being uploaded """ if type(self.artifact_client) == OrasClient: - self._upload_to_acr(artifact_config) + if type(artifact_config) == HelmPackageConfig: + self._upload_helm_to_acr(artifact_config) + elif type(artifact_config) == ArtifactConfig: + self._upload_arm_to_acr(artifact_config) + else: + raise ValueError(f"Unsupported artifact type: {type(artifact_config)}.") else: self._upload_to_storage_account(artifact_config) - def _upload_to_acr(self, artifact_config: ArtifactConfig) -> None: + def _upload_arm_to_acr(self, artifact_config: ArtifactConfig) -> None: """ - Upload artifact to ACR. + Upload ARM artifact to ACR. :param artifact_config: configuration for the artifact being uploaded """ assert type(self.artifact_client) == OrasClient - # If not included in config, the file path value will be the description of - # the field. - if artifact_config.file_path: target = ( f"{self.artifact_client.remote.hostname.replace('https://', '')}" @@ -61,6 +69,27 @@ def _upload_to_acr(self, artifact_config: ArtifactConfig) -> None: "Copying artifacts is not implemented for ACR artifacts stores." ) + def _upload_helm_to_acr(self, artifact_config: HelmPackageConfig) -> None: + """ + Upload artifact to ACR. + + :param artifact_config: configuration for the artifact being uploaded + """ + chart_path = artifact_config.path_to_chart + registry = self.artifact_client.remote.hostname.replace("https://", "") + target_registry = f"oci://{registry}" + registry_name = registry.replace(".azurecr.io", "") + + # az acr login --name "registry_name" + login_command = ["az", "acr", "login", "--name", registry_name] + subprocess.run(login_command, check=True) + + logger.debug(f"Uploading {chart_path} to {target_registry}") + + # helm push "$chart_path" "$target_registry" + push_command = ["helm", "push", chart_path, target_registry] + subprocess.run(push_command, check=True) + def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: """ Upload artifact to storage account. @@ -68,6 +97,7 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: :param artifact_config: configuration for the artifact being uploaded """ assert type(self.artifact_client) == BlobClient + assert type(artifact_config) == ArtifactConfig # If the file path is given, upload the artifact, else, copy it from an existing blob. if artifact_config.file_path: @@ -98,3 +128,54 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: raise RuntimeError( f"{source_blob.blob_name} does not exist in {source_blob.account_name}." ) + + def copy_image( + self, + cli_ctx, + container_registry_client, + source_registry_id, + source_image, + target_registry_resource_group_name, + target_registry_name, + mode="NoForce", + ): + """ + Copy image from one ACR to another. + + :param cli_ctx: CLI context + :param container_registry_client: container registry client + :param source_registry_id: source registry ID + :param source_image: source image + :param target_registry_resource_group_name: target registry resource group name + :param target_registry_name: target registry name + :param mode: mode for import + """ + target_tags = [source_image] + + source = ImportSource(resource_id=source_registry_id, source_image=source_image) + + import_parameters = ImportImageParameters( + source=source, + target_tags=target_tags, + untagged_target_repositories=[], + mode=mode, + ) + try: + result_poller = container_registry_client.begin_import_image( + resource_group_name=target_registry_resource_group_name, + registry_name=target_registry_name, + parameters=import_parameters, + ) + + LongRunningOperation(cli_ctx, "Importing image...")(result_poller) + + logger.info( + "Successfully imported %s to %s", source_image, target_registry_name + ) + except Exception as error: + logger.error( + "Failed to import %s to %s. Check if this image exists in the source registry or is already present in the target registry.", + source_image, + target_registry_name, + ) + logger.debug(error, exc_info=True) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 8ecdcb6c293..3c7dfa95eb9 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -14,14 +14,24 @@ from azure.mgmt.resource.resources.models import DeploymentExtended from knack.log import get_logger -from azext_aosm._configuration import NFConfiguration, NSConfiguration, VNFConfiguration +from azext_aosm._configuration import ( + NFConfiguration, + NSConfiguration, + VNFConfiguration, + CNFConfiguration, +) from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator +from azext_aosm.deploy.artifact import Artifact +from azext_aosm.util.management_clients import ApiClients from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK from azext_aosm.util.constants import ( NF_DEFINITION_BICEP_FILE, NSD, NSD_ARTIFACT_MANIFEST_BICEP_FILE, NSD_DEFINITION_BICEP_FILE, + CNF_DEFINITION_BICEP_TEMPLATE, + CNF_MANIFEST_BICEP_TEMPLATE, + CNF, VNF, VNF_DEFINITION_BICEP_TEMPLATE, VNF_MANIFEST_BICEP_TEMPLATE, @@ -55,6 +65,22 @@ def __init__( self.config = config self.pre_deployer = PreDeployerViaSDK(api_clients, self.config) + def read_parameters_from_file(self, parameters_json_file: str) -> Dict[str, Any]: + """ + Read parameters from a file. + + :param parameters_json_file: path to the parameters file + :return: parameters + """ + message = f"Use parameters from file {parameters_json_file}" + logger.info(message) + print(message) + with open(parameters_json_file, "r", encoding="utf-8") as f: + parameters_json = json.loads(f.read()) + parameters = parameters_json["parameters"] + + return parameters + def deploy_vnfd_from_bicep( self, bicep_path: Optional[str] = None, @@ -92,11 +118,7 @@ def deploy_vnfd_from_bicep( ) if parameters_json_file: - message = f"Use parameters from file {parameters_json_file}" - logger.info(message) - print(message) - with open(parameters_json_file, "r", encoding="utf-8") as f: - parameters = json.loads(f.read()) + parameters = self.read_parameters_from_file(parameters_json_file) else: # User has not passed in parameters file, so we use the parameters required @@ -108,7 +130,7 @@ def deploy_vnfd_from_bicep( logger.debug(parameters) # Create or check required resources - deploy_manifest_template = not self.vnfd_predeploy() + deploy_manifest_template = not self.nfd_predeploy(definition_type=VNF) if deploy_manifest_template: self.deploy_manifest_template( manifest_parameters_json_file, manifest_bicep_path, VNF @@ -150,17 +172,22 @@ def deploy_vnfd_from_bicep( arm_template_artifact.upload(self.config.arm_template) print("Done") - def vnfd_predeploy(self) -> bool: + def nfd_predeploy(self, definition_type) -> bool: """ - All the predeploy steps for a VNF. Create publisher, artifact stores and NFDG. + All the predeploy steps for a NFD. Create publisher, artifact stores and NFDG. - VNF specific return True if artifact manifest already exists, False otherwise + Return True if artifact manifest already exists, False otherwise """ + logger.debug("Ensure all required resources exist") self.pre_deployer.ensure_config_resource_group_exists() self.pre_deployer.ensure_config_publisher_exists() self.pre_deployer.ensure_acr_artifact_store_exists() - self.pre_deployer.ensure_sa_artifact_store_exists() + if definition_type == VNF: + self.pre_deployer.ensure_sa_artifact_store_exists() + if definition_type == CNF: + self.pre_deployer.ensure_config_source_registry_exists() + self.pre_deployer.ensure_config_nfdg_exists() return self.pre_deployer.do_config_artifact_manifests_exist() @@ -183,8 +210,21 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: "armTemplateVersion": {"value": self.config.arm_template.version}, } + def construct_cnfd_parameters(self) -> Dict[str, Any]: + """ + Create the parmeters dictionary for cnfdefinition.bicep. CNF specific. + """ + assert isinstance(self.config, CNFConfiguration) + return { + "location": {"value": self.config.location}, + "publisherName": {"value": self.config.publisher_name}, + "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, + "nfDefinitionGroup": {"value": self.config.nfdg_name}, + "nfDefinitionVersion": {"value": self.config.version}, + } + def construct_manifest_parameters(self) -> Dict[str, Any]: - """Create the parmeters dictionary for VNF or NSD.""" + """Create the parmeters dictionary for VNF, CNF or NSD.""" if isinstance(self.config, VNFConfiguration): return { "location": {"value": self.config.location}, @@ -197,7 +237,14 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: "vhdVersion": {"value": self.config.vhd.version}, "armTemplateVersion": {"value": self.config.arm_template.version}, } - if isinstance(self.config, NSConfiguration): + elif isinstance(self.config, CNFConfiguration): + return { + "location": {"value": self.config.location}, + "publisherName": {"value": self.config.publisher_name}, + "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, + "acrManifestName": {"value": self.config.acr_manifest_name}, + } + elif isinstance(self.config, NSConfiguration): return { "location": {"value": self.config.location}, "publisherName": {"value": self.config.publisher_name}, @@ -208,6 +255,127 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: } raise ValueError("Unknown configuration type") + def deploy_cnfd_from_bicep( + self, + cli_ctx, + bicep_path: Optional[str] = None, + parameters_json_file: Optional[str] = None, + manifest_bicep_path: Optional[str] = None, + manifest_parameters_json_file: Optional[str] = None, + ) -> None: + """ + Deploy the bicep template defining the CNFD. + + Also ensure that all required predeploy resources are deployed. + + :param cli_ctx: The CLI context + :param management_client: The container registry management client + :param bicep_path: The path to the bicep template of the nfdv + :param parameters_json_file: path to an override file of set parameters for the nfdv + :param manifest_bicep_path: The path to the bicep template of the manifest + :param manifest_parameters_json_file: path to an override file of set parameters for + the manifest + """ + assert isinstance(self.config, CNFConfiguration) + + if not bicep_path: + # User has not passed in a bicep template, so we are deploying the default + # one produced from building the NFDV using this CLI + bicep_path = os.path.join( + self.config.build_output_folder_name, + CNF_DEFINITION_BICEP_TEMPLATE, + ) + + if parameters_json_file: + parameters = self.read_parameters_from_file(parameters_json_file) + else: + # User has not passed in parameters file, so we use the parameters required + # from config for the default bicep template produced from building the + # NFDV using this CLI + logger.debug("Create parameters for default NFDV template.") + parameters = self.construct_cnfd_parameters() + + logger.debug( + f"Parameters used for CNF definition bicep deployment: {parameters}" + ) + + # Create or check required resources + deploy_manifest_template = not self.nfd_predeploy(definition_type=CNF) + if deploy_manifest_template: + self.deploy_manifest_template( + manifest_parameters_json_file, manifest_bicep_path, CNF + ) + else: + print( + f"Artifact manifests exist for NFD {self.config.nf_name} " + f"version {self.config.version}" + ) + message = ( + f"Deploy bicep template for NFD {self.config.nf_name} version {self.config.version} " + f"into {self.config.publisher_resource_group_name} under publisher " + f"{self.config.publisher_name}" + ) + print(message) + logger.info(message) + self.deploy_bicep_template(bicep_path, parameters) + print(f"Deployed NFD {self.config.nf_name} version {self.config.version}.") + + acr_properties = self.api_clients.aosm_client.artifact_stores.get( + resource_group_name=self.config.publisher_resource_group_name, + publisher_name=self.config.publisher_name, + artifact_store_name=self.config.acr_artifact_store_name, + ) + target_registry_name = acr_properties.storage_resource_id.split("/")[-1] + target_registry_resource_group_name = acr_properties.storage_resource_id.split( + "/" + )[-5] + + acr_manifest = ArtifactManifestOperator( + self.config, + self.api_clients, + self.config.acr_artifact_store_name, + self.config.acr_manifest_name, + ) + + artifact_dictionary = {} + + for artifact in acr_manifest.artifacts: + artifact_dictionary[artifact.artifact_name] = artifact + + for helm_package in self.config.helm_packages: + helm_package_name = helm_package.name + + if helm_package_name not in artifact_dictionary: + raise ValueError( + f"Artifact {helm_package_name} not found in the artifact manifest" + ) + + manifest_artifact = artifact_dictionary[helm_package_name] + + print(f"Uploading Helm package: {helm_package_name}") + + manifest_artifact.upload(helm_package) + + print(f"Finished uploading Helm package: {helm_package_name}") + + artifact_dictionary.pop(helm_package_name) + + # All the remaining artifacts are not in the helm_packages list. We assume that they are images that need to be copied from another ACR. + for artifact in artifact_dictionary.values(): + assert isinstance(artifact, Artifact) + + print(f"Copying artifact: {artifact.artifact_name}") + artifact.copy_image( + cli_ctx=cli_ctx, + container_registry_client=self.api_clients.container_registry_client, + source_registry_id=self.config.source_registry_id, + source_image=f"{artifact.artifact_name}:{artifact.artifact_version}", + target_registry_resource_group_name=target_registry_resource_group_name, + target_registry_name=target_registry_name, + ) + + print("Done") + def deploy_nsd_from_bicep( self, bicep_path: Optional[str] = None, @@ -237,12 +405,7 @@ def deploy_nsd_from_bicep( ) if parameters_json_file: - message = f"Use parameters from file {parameters_json_file}" - logger.info(message) - print(message) - with open(parameters_json_file, "r", encoding="utf-8") as f: - parameters = json.loads(f.read()) - + parameters = self.read_parameters_from_file(parameters_json_file) else: # User has not passed in parameters file, so we use the parameters required # from config for the default bicep template produced from building the @@ -312,6 +475,8 @@ def deploy_manifest_template( file_name = NSD_ARTIFACT_MANIFEST_BICEP_FILE elif configuration_type == VNF: file_name = VNF_MANIFEST_BICEP_TEMPLATE + elif configuration_type == CNF: + file_name = CNF_MANIFEST_BICEP_TEMPLATE manifest_bicep_path = os.path.join( self.config.build_output_folder_name, @@ -322,7 +487,8 @@ def deploy_manifest_template( else: logger.info("Use provided manifest parameters") with open(manifest_parameters_json_file, "r", encoding="utf-8") as f: - manifest_params = json.loads(f.read()) + manifest_json = json.loads(f.read()) + manifest_params = manifest_json["parameters"] self.deploy_bicep_template(manifest_bicep_path, manifest_params) def nsd_predeploy(self) -> bool: @@ -404,7 +570,9 @@ def validate_and_deploy_arm_template( :return: Output dictionary from the bicep template. """ # Get current time from the time module and remove all digits after the decimal point - current_time = str(time.time()).split(".")[0] # pylint: disable=use-maxsplit-arg + current_time = str(time.time()).split(".")[ + 0 + ] # pylint: disable=use-maxsplit-arg # Add a timestamp to the deployment name to ensure it is unique deployment_name = f"AOSM_CLI_deployment_into_{resource_group}_{current_time}" diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 59ae3e8f2b3..b83ed1b3b52 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -130,6 +130,29 @@ def ensure_config_publisher_exists(self) -> None: location=self.config.location, ) + def ensure_config_source_registry_exists(self) -> None: + """ + Ensures that the source registry exists + + Finds the parameters from self.config + """ + logger.info( + "Check if the source registry %s exists", + self.config.source_registry_id, + ) + + # Assume that the registry id is of the form: /subscriptions//resourceGroups//providers/Microsoft.ContainerRegistry/registries/ + source_registry_name = self.config.source_registry_id.split("/")[-1] + source_registry_resource_group_name = self.config.source_registry_id.split("/")[ + -5 + ] + + # This will raise an error if the registry does not exist + self.api_clients.container_registry_client.get( + resource_group_name=source_registry_resource_group_name, + registry_name=source_registry_name, + ) + def ensure_artifact_store_exists( self, resource_group_name: str, @@ -255,12 +278,41 @@ def ensure_nfdg_exists( "Creating network function definition group %s if it does not exist", nfdg_name, ) - self.api_clients.aosm_client.network_function_definition_groups.begin_create_or_update( - resource_group_name=resource_group_name, - publisher_name=publisher_name, - network_function_definition_group_name=nfdg_name, - parameters=NetworkFunctionDefinitionGroup(location=location), - ) + + try: + self.api_clients.aosm_client.network_function_definition_groups.get( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=nfdg_name, + ) + print( + f"Network function definition group {nfdg_name} exists in resource group {resource_group_name}" + ) + except azure_exceptions.ResourceNotFoundError: + print(f"Create Network Function Definition Group {nfdg_name}") + poller = self.api_clients.aosm_client.network_function_definition_groups.begin_create_or_update( + resource_group_name=resource_group_name, + publisher_name=publisher_name, + network_function_definition_group_name=nfdg_name, + parameters=NetworkFunctionDefinitionGroup(location=location), + ) + + # Asking for result waits for provisioning state Succeeded before carrying + # on + nfdg: NetworkFunctionDefinitionGroup = poller.result() + + if nfdg.provisioning_state != ProvisioningState.SUCCEEDED: + logger.debug( + f"Failed to provision Network Function Definition Group: {nfdg.name}" + ) + raise RuntimeError( + f"Creation of Network Function Definition Group proceeded, but the provisioning" + f" state returned is {nfdg.provisioning_state}. " + f"\nAborting" + ) + logger.debug( + f"Provisioning state of {nfdg_name}" f": {nfdg.provisioning_state}" + ) def ensure_config_nfdg_exists( self, diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index b79873486e6..5af6014d87c 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -90,9 +90,6 @@ def generate_nfd(self) -> None: self._tmp_folder_name = tmpdirname try: for helm_package in self.config.helm_packages: - # Turn Any type into HelmPackageConfig, to access properties on the object - helm_package = HelmPackageConfig(**helm_package) - # Unpack the chart into the tmp folder self._extract_chart(helm_package.path_to_chart) @@ -632,6 +629,67 @@ def _replace_values_with_deploy_params( return final_values_mapping_dict + def _replace_values_with_deploy_params( + self, + values_yaml_dict, + param_prefix: Optional[str] = None, + ) -> Dict[Any, Any]: + """ + Given the yaml dictionary read from values.yaml, replace all the values with {deploymentParameter.keyname}. + + Thus creating a values mapping file if the user has not provided one in config. + """ + logger.debug("Replacing values with deploy parameters") + final_values_mapping_dict: Dict[Any, Any] = {} + for k, v in values_yaml_dict.items(): + # if value is a string and contains deployParameters. + logger.debug("Processing key %s", k) + param_name = k if param_prefix is None else f"{param_prefix}_{k}" + if isinstance(v, (str, int, bool)): + # Replace the parameter with {deploymentParameter.keyname} + if self.interactive: + # Interactive mode. Prompt user to include or exclude parameters + # This requires the enter key after the y/n input which isn't ideal + if not input_ack("y", f"Expose parameter {param_name}? y/n "): + logger.debug("Excluding parameter %s", param_name) + final_values_mapping_dict.update({k: v}) + continue + replacement_value = f"{{deployParameters.{param_name}}}" + + # add the schema for k (from the big schema) to the (smaller) schema + final_values_mapping_dict.update({k: replacement_value}) + elif isinstance(v, dict): + final_values_mapping_dict[k] = self._replace_values_with_deploy_params( + v, param_name + ) + elif isinstance(v, list): + final_values_mapping_dict[k] = [] + for index, item in enumerate(v): + param_name = ( + f"{param_prefix}_{k}_{index}" + if param_prefix + else f"{k})_{index}" + ) + if isinstance(item, dict): + final_values_mapping_dict[k].append( + self._replace_values_with_deploy_params(item, param_name) + ) + elif isinstance(v, (str, int, bool)): + replacement_value = f"{{deployParameters.{param_name}}}" + final_values_mapping_dict[k].append(replacement_value) + else: + raise ValueError( + f"Found an unexpected type {type(v)} of key {k} in " + "values.yaml, cannot generate values mapping file." + ) + else: + raise ValueError( + f"Found an unexpected type {type(v)} of key {k} in values.yaml, " + "cannot generate values mapping file." + ) + + return final_values_mapping_dict + def get_chart_name_and_version( self, helm_package: HelmPackageConfig ) -> Tuple[str, str]: diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index 9d4f3b1b8dc..b71bd8206b2 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -14,6 +14,7 @@ from azext_aosm.vendored_sdks.models import NFVIType from azext_aosm._configuration import NSConfiguration +from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.util.constants import ( CONFIG_MAPPINGS, NF_DEFINITION_BICEP_FILE, diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index c5274b8ee93..7b3087f870e 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -10,8 +10,6 @@ NSD = "nsd" SCHEMA = "schema" -# TODO pk5: clean up these names - # Names of files used in the repo NSD_DEFINITION_BICEP_SOURCE_TEMPLATE = "nsd_template.bicep" NSD_DEFINITION_BICEP_FILE = "nsd_definition.bicep" diff --git a/src/aosm/azext_aosm/util/management_clients.py b/src/aosm/azext_aosm/util/management_clients.py index 11712b4e894..132f6feed69 100644 --- a/src/aosm/azext_aosm/util/management_clients.py +++ b/src/aosm/azext_aosm/util/management_clients.py @@ -8,6 +8,9 @@ from knack.log import get_logger from azext_aosm.vendored_sdks import HybridNetworkManagementClient +from azure.mgmt.containerregistry import ContainerRegistryManagementClient +from typing import Optional + logger = get_logger(__name__) @@ -19,7 +22,9 @@ def __init__( self, aosm_client: HybridNetworkManagementClient, resource_client: ResourceManagementClient, + container_registry_client: Optional[ContainerRegistryManagementClient] = None, ): """Initialise with clients.""" self.aosm_client = aosm_client self.resource_client = resource_client + self.container_registry_client = container_registry_client From a403856ee6999d91e6a167e99856fdf11c39ed39 Mon Sep 17 00:00:00 2001 From: jamiedparsons <111778988+jamiedparsons@users.noreply.github.com> Date: Tue, 27 Jun 2023 19:31:24 +0100 Subject: [PATCH 117/145] Expose NFD version and managed identities (#34) * NFDV version exposed as a CGV on an SNS * Managed identities support on NFs * Fix identiy, fix API versions * history --------- Co-authored-by: Jamie Parsons Co-authored-by: Sunny Carter --- src/aosm/HISTORY.rst | 2 + src/aosm/azext_aosm/_configuration.py | 27 +++++--- .../templates/vnfartifactmanifests.bicep | 10 +-- .../templates/vnfdefinition.bicep | 10 +-- .../generate_nfd/vnf_nfd_generator.py | 22 ++++-- .../azext_aosm/generate_nsd/nsd_generator.py | 68 +++++++++++++++---- .../generate_nsd/templates/nf_template.bicep | 13 +++- 7 files changed, 112 insertions(+), 40 deletions(-) diff --git a/src/aosm/HISTORY.rst b/src/aosm/HISTORY.rst index 8a3d7b2d91a..836fcf03607 100644 --- a/src/aosm/HISTORY.rst +++ b/src/aosm/HISTORY.rst @@ -6,7 +6,9 @@ Release History unreleased ++++++++++ * `az aosm nfd build` options `--order-params` and `--interactive` to help users choose which NF parameters to expose as deployParameters. Feature added that allows CNF value mappings file to be generated if none is supplied. +* NFDV version exposed as a CGV on an SNS. * `az aosm nfd publish` option added for `--definition-type cnf` to publish the CNF bicep templates, upload helm charts from disk to the ACR and copy the images from a source ACR to the target ACR. +* Managed Identity added to VNF NF templates - requires subscription to be registered for the feature flag. 0.2.0 ++++++ diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 253104e4e85..23de58ce64d 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -47,10 +47,12 @@ "nsdg_name": "Network Service Design Group Name. This is the collection of Network Service Design Versions. " "Will be created if it does not exist.", "nsd_version": "Version of the NSD to be created. This should be in the format A.B.C", - "network_function_definition_group_name": "Exising Network Function Definition Group Name. " - "This can be created using the 'az aosm nfd' commands.", - "network_function_definition_version_name": "Exising Network Function Definition Version Name. " - "This can be created using the 'az aosm nfd' commands.", + "network_function_definition_group_name": + "Existing Network Function Definition Group Name. " + "This can be created using the 'az aosm nfd' commands.", + "network_function_definition_version_name": + "Existing Network Function Definition Version Name. " + "This can be created using the 'az aosm nfd' commands.", "network_function_definition_offering_location": "Offering location of the Network Function Definition", "network_function_type": "Type of nf in the definition. Valid values are 'cnf' or 'vnf'", "helm_package_name": "Name of the Helm package", @@ -66,7 +68,12 @@ "helm_depends_on": "Names of the Helm packages this package depends on. " "Leave as an empty array if no dependencies", - "source_registry_id": "Resource ID of the source acr registry from which to pull the image", + "image_name_parameter": + "The parameter name in the VM ARM template which specifies the name of the " + "image to use for the VM.", + "source_registry_id": + "Resource ID of the source acr registry from which to pull " + "the image", } @@ -98,7 +105,8 @@ def nfdg_name(self) -> str: @property def acr_manifest_name(self) -> str: """Return the ACR manifest name from the NFD name.""" - return f"{self.nf_name}-acr-manifest-{self.version.replace('.', '-')}" + sanitized_nf_name = self.nf_name.lower().replace("_", "-") + return f"{sanitized_nf_name}-acr-manifest-{self.version.replace('.', '-')}" @dataclass @@ -188,7 +196,8 @@ def network_function_name(self) -> str: @property def acr_manifest_name(self) -> str: """Return the ACR manifest name from the NFD name.""" - return f"{self.network_function_name.lower().replace('_', '-')}-acr-manifest-{self.nsd_version.replace('.', '-')}" + sanitised_nf_name = self.network_function_name.lower().replace('_', '-') + return f"{sanitised_nf_name}-acr-manifest-{self.nsd_version.replace('.', '-')}" @property def nfvi_site_name(self) -> str: @@ -219,6 +228,7 @@ def arm_template_artifact_name(self) -> str: @dataclass class VNFConfiguration(NFConfiguration): blob_artifact_store_name: str = DESCRIPTION_MAP["blob_artifact_store_name"] + image_name_parameter: str = DESCRIPTION_MAP["image_name_parameter"] arm_template: Any = ArtifactConfig() vhd: Any = ArtifactConfig() @@ -277,7 +287,8 @@ def validate(self) -> None: @property def sa_manifest_name(self) -> str: """Return the Storage account manifest name from the NFD name.""" - return f"{self.nf_name}-sa-manifest-{self.version.replace('.', '-')}" + sanitized_nf_name = self.nf_name.lower().replace("_", "-") + return f"{sanitized_nf_name}-sa-manifest-{self.version.replace('.', '-')}" @property def build_output_folder_name(self) -> str: diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep index 554e3bfa28d..bc884941987 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfartifactmanifests.bicep @@ -20,24 +20,24 @@ param vhdVersion string param armTemplateVersion string // Created by the az aosm definition publish command before the template is deployed -resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { +resource publisher 'Microsoft.HybridNetwork/publishers@2023-04-01-preview' existing = { name: publisherName scope: resourceGroup() } // Created by the az aosm definition publish command before the template is deployed -resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-04-01-preview' existing = { parent: publisher name: acrArtifactStoreName } // Created by the az aosm definition publish command before the template is deployed -resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { +resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-04-01-preview' existing = { parent: publisher name: saArtifactStoreName } -resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { +resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2023-04-01-preview' = { parent: saArtifactStore name: saManifestName location: location @@ -52,7 +52,7 @@ resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/a } } -resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2022-09-01-preview' = { +resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2023-04-01-preview' = { parent: acrArtifactStore name: acrManifestName location: location diff --git a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep index 7f98fcf55be..0439097e8d0 100644 --- a/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep +++ b/src/aosm/azext_aosm/generate_nfd/templates/vnfdefinition.bicep @@ -20,30 +20,30 @@ param vhdVersion string param armTemplateVersion string // Created by the az aosm definition publish command before the template is deployed -resource publisher 'Microsoft.HybridNetwork/publishers@2022-09-01-preview' existing = { +resource publisher 'Microsoft.HybridNetwork/publishers@2023-04-01-preview' existing = { name: publisherName scope: resourceGroup() } // Created by the az aosm definition publish command before the template is deployed -resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-04-01-preview' existing = { parent: publisher name: acrArtifactStoreName } // Created by the az aosm definition publish command before the template is deployed -resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2022-09-01-preview' existing = { +resource saArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-04-01-preview' existing = { parent: publisher name: saArtifactStoreName } // Created by the az aosm definition publish command before the template is deployed -resource nfdg 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups@2022-09-01-preview' existing = { +resource nfdg 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups@2023-04-01-preview' existing = { parent: publisher name: nfDefinitionGroup } -resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups/networkfunctiondefinitionversions@2022-09-01-preview' = { +resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups/networkfunctiondefinitionversions@2023-04-01-preview' = { parent: nfdg name: nfDefinitionVersion location: location diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index 7d33fab1016..e9581a6b9a1 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -78,6 +78,7 @@ def __init__(self, config: VNFConfiguration, order_params: bool, interactive: bo self.order_params = order_params self.interactive = interactive self.tmp_folder_name = "" + self.image_name = f"{self.config.nf_name}Image" def generate_nfd(self) -> None: """ @@ -179,6 +180,11 @@ def write_deployment_parameters(self, folder_path: str) -> None: ) for key in vm_parameters: + if key == self.config.image_name_parameter: + # There is only one correct answer for the image name, so don't ask the + # user, instead it is hardcoded in config mappings. + continue + # Order parameters into those without and then with defaults has_default_field = "defaultValue" in self.vm_parameters[key] has_default = ( @@ -240,7 +246,7 @@ def write_deployment_parameters(self, folder_path: str) -> None: f"{OPTIONAL_DEPLOYMENT_PARAMETERS_FILE} to help you choose which " "to expose." ) - + def write_template_parameters(self, folder_path: str) -> None: """ Write out the NFD templateParameters.json file. @@ -251,9 +257,15 @@ def write_template_parameters(self, folder_path: str) -> None: vm_parameters = ( self.vm_parameters_ordered if self.order_params else self.vm_parameters ) - template_parameters = { - key: f"{{deployParameters.{key}}}" for key in vm_parameters - } + + template_parameters = {} + + for key in vm_parameters: + if key == self.config.image_name_parameter: + template_parameters[key] = self.image_name + continue + + template_parameters[key] = f"{{deployParameters.{key}}}" template_parameters_path = os.path.join(folder_path, TEMPLATE_PARAMETERS) @@ -278,7 +290,7 @@ def write_vhd_parameters(self, folder_path: str) -> None: azureDeployLocation = self.config.location vhd_parameters = { - "imageName": f"{self.config.nf_name}Image", + "imageName": self.image_name, "azureDeployLocation": azureDeployLocation, } diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index b71bd8206b2..3f365d4cbb6 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -4,17 +4,18 @@ # -------------------------------------------------------------------------------------- """Contains a class for generating NSDs and associated resources.""" import json +import copy import os import shutil import tempfile -from typing import Dict +from functools import cached_property +from typing import Any, Dict, Optional from jinja2 import Template from knack.log import get_logger from azext_aosm.vendored_sdks.models import NFVIType from azext_aosm._configuration import NSConfiguration -from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.util.constants import ( CONFIG_MAPPINGS, NF_DEFINITION_BICEP_FILE, @@ -61,6 +62,8 @@ def __init__(self, api_clients: ApiClients, config: NSConfiguration): self.nsd_bicep_template_name = NSD_DEFINITION_BICEP_SOURCE_TEMPLATE self.nf_bicep_template_name = NF_TEMPLATE_BICEP_FILE self.nsd_bicep_output_name = NSD_DEFINITION_BICEP_FILE + self.nfdv_parameter_name = \ + f"{self.config.network_function_definition_group_name.replace('-', '_')}_nfd_version" self.build_folder_name = self.config.build_output_folder_name nfdv = self._get_nfdv(config, api_clients) @@ -69,7 +72,7 @@ def __init__(self, api_clients: ApiClients, config: NSConfiguration): raise NotImplementedError( "NFDV has no deploy parameters, cannot generate NSD." ) - self.deploy_parameters: str = nfdv.deploy_parameters + self.deploy_parameters: Optional[Dict[str, Any]] = json.loads(nfdv.deploy_parameters) def _get_nfdv( self, config: NSConfiguration, api_clients @@ -90,13 +93,13 @@ def _get_nfdv( def generate_nsd(self) -> None: """Generate a NSD templates which includes an Artifact Manifest, NFDV and NF templates.""" - logger.info(f"Generate NSD bicep templates") + logger.info("Generate NSD bicep templates") # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: self.tmp_folder_name = tmpdirname - self.create_parameter_files() + self.create_config_group_schema_files() self.write_nsd_manifest() self.write_nf_bicep() self.write_nsd_bicep() @@ -108,7 +111,45 @@ def generate_nsd(self) -> None: "`az aosm nsd publish` with the same arguments." ) - def create_parameter_files(self) -> None: + @cached_property + def config_group_schema_dict(self) -> Dict[str, Any]: + """ + :return: The Config Group Schema as a dictionary. + """ + # This function cannot be called before deployment parameters have been + # supplied. + assert self.deploy_parameters + + # Take a copy of the deploy parameters. + cgs_dict = copy.deepcopy(self.deploy_parameters) + + # Re-title it. + cgs_dict["title"] = self.config.cg_schema_name + + # Add in the NFDV version as a parameter. + description_string = ( + f"The version of the {self.config.network_function_definition_group_name} " + f"NFD to use. This version must be compatable with (have the same " + f"parameters exposed as) " + f"{self.config.network_function_definition_version_name}." + ) + cgs_dict["properties"][self.nfdv_parameter_name] = \ + {"type": "string", "description": description_string} + + managed_identity_description_string = ( + "The managed identity to use to deploy NFs within this SNS. This should " + "of the form '/subscriptions/{subscriptionId}/resourceGroups/" + "{resourceGroupName}/providers/Microsoft.ManagedIdentity/" + "userAssignedIdentities/{identityName}. " + "The az aosm tool only supports user assigned identities at present, " + "you cannot use a System Assigned identity." + ) + cgs_dict["properties"]["managedIdentity"] = \ + {"type": "string", "description": managed_identity_description_string} + + return cgs_dict + + def create_config_group_schema_files(self) -> None: """Create the Schema and configMappings json files.""" temp_schemas_folder_path = os.path.join(self.tmp_folder_name, SCHEMAS) os.mkdir(temp_schemas_folder_path) @@ -129,7 +170,7 @@ def write_schema(self, folder_path: str) -> None: schema_path = os.path.join(folder_path, f"{self.config.cg_schema_name}.json") with open(schema_path, "w") as _file: - _file.write(json.dumps(json.loads(self.deploy_parameters), indent=4)) + _file.write(json.dumps(self.config_group_schema_dict, indent=4)) logger.debug(f"{schema_path} created") @@ -139,9 +180,7 @@ def write_config_mappings(self, folder_path: str) -> None: :param folder_path: The folder to put this file in. """ - - deploy_parameters_dict = json.loads(self.deploy_parameters) - deploy_properties = deploy_parameters_dict["properties"] + deploy_properties = self.config_group_schema_dict["properties"] logger.debug("Create configMappings.json") config_mappings = { @@ -162,14 +201,13 @@ def write_nf_bicep(self) -> None: bicep_deploymentValues = "" - deploy_parameters_dict = json.loads(self.deploy_parameters) - if "properties" not in deploy_parameters_dict: + + if "properties" not in self.deploy_parameters: raise ValueError( f"NFDV in {self.config.network_function_definition_group_name} has " "no properties within deployParameters" ) - - deploy_properties = deploy_parameters_dict["properties"] + deploy_properties = self.deploy_parameters["properties"] for key, value in deploy_properties.items(): # location is sometimes part of deploy_properties. @@ -190,7 +228,7 @@ def write_nf_bicep(self) -> None: "network_function_name": self.config.network_function_name, "publisher_name": self.config.publisher_name, "network_function_definition_group_name": self.config.network_function_definition_group_name, - "network_function_definition_version_name": self.config.network_function_definition_version_name, + "network_function_definition_version_parameter": self.nfdv_parameter_name, "network_function_definition_offering_location": self.config.network_function_definition_offering_location, "location": self.config.location, # Ideally we would use the network_function_type from reading the actual diff --git a/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep b/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep index a32d583e772..89a2362e8ec 100644 --- a/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep +++ b/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep @@ -10,11 +10,14 @@ param publisherName string = '{{publisher_name}}' param networkFunctionDefinitionGroupName string = '{{network_function_definition_group_name}}' @description('NFD version') -param networkFunctionDefinitionVersion string = '{{network_function_definition_version_name}}' +param {{network_function_definition_version_parameter}} string @description('Offering location for the Network Function') param networkFunctionDefinitionOfferingLocation string = '{{network_function_definition_offering_location}}' +@description('The managed identity that should be used to create the NF.') +param managedIdentity string + param location string = '{{location}}' param nfviType string = '{{nfvi_type}}' @@ -30,11 +33,17 @@ var deploymentValues = { resource nf_resource 'Microsoft.HybridNetwork/networkFunctions@2023-04-01-preview' = { name: '{{network_function_name}}' location: location + identity: { + type: 'UserAssigned' + userAssignedIdentities: { + '${managedIdentity}': {} + } + } properties: { publisherName: publisherName publisherScope: 'Private' networkFunctionDefinitionGroupName: networkFunctionDefinitionGroupName - networkFunctionDefinitionVersion: networkFunctionDefinitionVersion + networkFunctionDefinitionVersion: {{network_function_definition_version_parameter}} networkFunctionDefinitionOfferingLocation: networkFunctionDefinitionOfferingLocation nfviType: nfviType nfviId: resourceGroupId From aad112f7fdf315116c0d899a6e82c49cf142f032 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Wed, 28 Jun 2023 19:04:43 +0100 Subject: [PATCH 118/145] Add a first VNF test --- src/aosm/azext_aosm/_configuration.py | 48 +++++-- src/aosm/azext_aosm/custom.py | 13 +- .../tests/latest/mock_cnf/config_file.json | 3 - .../tests/latest/mock_vnf/input.json | 18 +++ .../latest/mock_vnf/ubuntu-template.json | 118 ++++++++++++++++++ src/aosm/azext_aosm/tests/latest/test_cnf.py | 9 +- src/aosm/azext_aosm/tests/latest/test_nsd.py | 4 + src/aosm/azext_aosm/tests/latest/test_vnf.py | 17 ++- 8 files changed, 210 insertions(+), 20 deletions(-) create mode 100644 src/aosm/azext_aosm/tests/latest/mock_vnf/input.json create mode 100644 src/aosm/azext_aosm/tests/latest/mock_vnf/ubuntu-template.json diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 23de58ce64d..e3a3e0af8bf 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,6 +1,7 @@ ## Disabling as every if statement in validate in NSConfig class has this condition # pylint: disable=simplifiable-condition +import json import os from dataclasses import dataclass, field from pathlib import Path @@ -84,10 +85,31 @@ class ArtifactConfig: file_path: Optional[str] = DESCRIPTION_MAP["file_path"] blob_sas_url: Optional[str] = DESCRIPTION_MAP["blob_sas_url"] version: str = DESCRIPTION_MAP["artifact_version"] + + +@dataclass +class Configuration: + config_file: Optional[str] = None + + def path_from_cli(self, path: str) -> str: + """ + Convert path from config file to path from current directory. + + We assume that the path supplied in the config file is relative to the + configuration file. That isn't the same as the path relative to where ever the + CLI is being run from. This function fixes that up. + + :param path: The path relative to the config file. + """ + # If no path has been supplied we shouldn't try to update it. + if path == "": + return "" + + return os.path.join(os.path.dirname(self.config_file), path) @dataclass -class NFConfiguration: +class NFConfiguration(Configuration): publisher_name: str = DESCRIPTION_MAP["publisher_name"] publisher_resource_group_name: str = DESCRIPTION_MAP[ "publisher_resource_group_name" @@ -110,7 +132,7 @@ def acr_manifest_name(self) -> str: @dataclass -class NSConfiguration: +class NSConfiguration(Configuration): # pylint: disable=too-many-instance-attributes location: str = DESCRIPTION_MAP["location"] publisher_name: str = DESCRIPTION_MAP["publisher_name_nsd"] @@ -239,9 +261,13 @@ def __post_init__(self): Used when creating VNFConfiguration object from a loaded json config file. """ if isinstance(self.arm_template, dict): + self.arm_template["file_path"] = \ + self.path_from_cli(self.arm_template["file_path"]) self.arm_template = ArtifactConfig(**self.arm_template) if isinstance(self.vhd, dict): + self.vhd["file_path"] = \ + self.path_from_cli(self.vhd["file_path"]) self.vhd = ArtifactConfig(**self.vhd) self.validate() @@ -320,6 +346,9 @@ def __post_init__(self): """ for package_index, package in enumerate(self.helm_packages): if isinstance(package, dict): + package["path_to_chart"] = self.path_from_cli(package["path_to_chart"]) + package["path_to_mappings"] = \ + self.path_from_cli(package["path_to_mappings"]) self.helm_packages[package_index] = HelmPackageConfig(**dict(package)) @property @@ -329,24 +358,27 @@ def build_output_folder_name(self) -> str: def get_configuration( - configuration_type: str, config_as_dict: Optional[Dict[Any, Any]] = None + configuration_type: str, config_file: str = None ) -> NFConfiguration or NSConfiguration: """ Return the correct configuration object based on the type. :param configuration_type: The type of configuration to return - :param config_as_dict: The configuration as a dictionary + :param config_file: The path to the config file :return: The configuration object """ - if config_as_dict is None: + if config_file: + with open(config_file, "r", encoding="utf-8") as f: + config_as_dict = json.loads(f.read()) + else: config_as_dict = {} if configuration_type == VNF: - config = VNFConfiguration(**config_as_dict) + config = VNFConfiguration(config_file=config_file, **config_as_dict) elif configuration_type == CNF: - config = CNFConfiguration(**config_as_dict) + config = CNFConfiguration(config_file=config_file, **config_as_dict) elif configuration_type == NSD: - config = NSConfiguration(**config_as_dict) + config = NSConfiguration(config_file=config_file, **config_as_dict) else: raise InvalidArgumentValueError( "Definition type not recognized, options are: vnf, cnf or nsd" diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 6885a31276d..4d244a2ebf3 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -93,9 +93,7 @@ def _get_config_from_file( f"Config file {config_file} not found. Please specify a valid config file path." ) - with open(config_file, "r", encoding="utf-8") as f: - config_as_dict = json.loads(f.read()) - config = get_configuration(configuration_type, config_as_dict) + config = get_configuration(configuration_type, config_file) return config @@ -241,8 +239,13 @@ def _generate_config(configuration_type: str, output_file: str = "input.json"): :param output_file: path to output config file, defaults to "input.json" :type output_file: str, optional """ - config = get_configuration(configuration_type) - config_as_dict = json.dumps(asdict(config), indent=4) + # Config file is a special parameter on the configuration objects. It is the path + # to the configuration file, rather than an input parameter. It therefore shouldn't + # be included here. + config = asdict(get_configuration(configuration_type)) + config.pop("config_file") + + config_as_dict = json.dumps(config, indent=4) if os.path.exists(output_file): carry_on = input( diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/config_file.json b/src/aosm/azext_aosm/tests/latest/mock_cnf/config_file.json index 60f54478c5d..6f2372284bc 100644 --- a/src/aosm/azext_aosm/tests/latest/mock_cnf/config_file.json +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/config_file.json @@ -11,9 +11,6 @@ "path_to_chart": "src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_chart.yaml", "path_to_mappings":"src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_mappings.yaml", "depends_on": [] - }, - { - } ] } \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/mock_vnf/input.json b/src/aosm/azext_aosm/tests/latest/mock_vnf/input.json new file mode 100644 index 00000000000..b3a3b991a1d --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_vnf/input.json @@ -0,0 +1,18 @@ +{ + "publisher_name": "jamie-mobile-publisher", + "publisher_resource_group_name": "Jamie-publisher", + "nf_name": "ubuntu-vm", + "version": "1.0.0", + "acr_artifact_store_name": "ubuntu-acr", + "location": "eastus", + "blob_artifact_store_name": "ubuntu-blob-store", + "image_name_parameter": "imageName", + "arm_template": { + "file_path": "ubuntu-template.json", + "version": "1.0.0" + }, + "vhd": { + "file_path": "livecd.ubuntu-cpc.azure.vhd", + "version": "1-0-0" + } +} diff --git a/src/aosm/azext_aosm/tests/latest/mock_vnf/ubuntu-template.json b/src/aosm/azext_aosm/tests/latest/mock_vnf/ubuntu-template.json new file mode 100644 index 00000000000..378927a3fe5 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_vnf/ubuntu-template.json @@ -0,0 +1,118 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.15.31.15270", + "templateHash": "1656082395923655778" + } + }, + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "subnetName": { + "type": "string" + }, + "ubuntuVmName": { + "type": "string", + "defaultValue": "ubuntu-vm" + }, + "virtualNetworkId": { + "type": "string" + }, + "sshPublicKeyAdmin": { + "type": "string" + }, + "imageName": { + "type": "string" + } + }, + "variables": { + "imageResourceGroup": "[resourceGroup().name]", + "subscriptionId": "[subscription().subscriptionId]", + "vmSizeSku": "Standard_D2s_v3" + }, + "resources": [ + { + "type": "Microsoft.Network/networkInterfaces", + "apiVersion": "2021-05-01", + "name": "[format('{0}_nic', parameters('ubuntuVmName'))]", + "location": "[parameters('location')]", + "properties": { + "ipConfigurations": [ + { + "name": "ipconfig1", + "properties": { + "subnet": { + "id": "[format('{0}/subnets/{1}', parameters('virtualNetworkId'), parameters('subnetName'))]" + }, + "primary": true, + "privateIPAddressVersion": "IPv4" + } + } + ] + } + }, + { + "type": "Microsoft.Compute/virtualMachines", + "apiVersion": "2021-07-01", + "name": "[parameters('ubuntuVmName')]", + "location": "[parameters('location')]", + "properties": { + "hardwareProfile": { + "vmSize": "[variables('vmSizeSku')]" + }, + "storageProfile": { + "imageReference": { + "id": "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', variables('subscriptionId'), variables('imageResourceGroup')), 'Microsoft.Compute/images', parameters('imageName'))]" + }, + "osDisk": { + "osType": "Linux", + "name": "[format('{0}_disk', parameters('ubuntuVmName'))]", + "createOption": "FromImage", + "caching": "ReadWrite", + "writeAcceleratorEnabled": false, + "managedDisk": "[json('{\"storageAccountType\": \"Premium_LRS\"}')]", + "deleteOption": "Delete", + "diskSizeGB": 30 + } + }, + "osProfile": { + "computerName": "[parameters('ubuntuVmName')]", + "adminUsername": "azureuser", + "linuxConfiguration": { + "disablePasswordAuthentication": true, + "ssh": { + "publicKeys": [ + { + "path": "/home/azureuser/.ssh/authorized_keys", + "keyData": "[parameters('sshPublicKeyAdmin')]" + } + ] + }, + "provisionVMAgent": true, + "patchSettings": { + "patchMode": "ImageDefault", + "assessmentMode": "ImageDefault" + } + }, + "secrets": [], + "allowExtensionOperations": true + }, + "networkProfile": { + "networkInterfaces": [ + { + "id": "[resourceId('Microsoft.Network/networkInterfaces', format('{0}_nic', parameters('ubuntuVmName')))]" + } + ] + } + }, + "dependsOn": [ + "[resourceId('Microsoft.Network/networkInterfaces', format('{0}_nic', parameters('ubuntuVmName')))]" + ] + } + ] +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/test_cnf.py b/src/aosm/azext_aosm/tests/latest/test_cnf.py index b2bb8c97d71..85601d1d7a0 100644 --- a/src/aosm/azext_aosm/tests/latest/test_cnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_cnf.py @@ -7,6 +7,7 @@ import unittest import json import logging +import os # from unittest.mock import Mock, patch from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator @@ -19,13 +20,15 @@ InvalidTemplateError ) +mock_cnf_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_cnf") +cnf_config_file = os.path.join(mock_cnf_folder, "config_file.json") + # Instantiate CNF with faked config file -with open("azext_aosm/tests/latest/mock_cnf/config_file.json", "r", encoding="utf-8") as f: +with open(cnf_config_file, "r", encoding="utf-8") as f: config_as_dict = json.loads(f.read()) -config = CNFConfiguration(**config_as_dict) +config = CNFConfiguration(config_file=cnf_config_file, **config_as_dict) test_cnf = CnfNfdGenerator(config) invalid_helm_package = test_cnf.config.helm_packages[0] -invalid_helm_package = HelmPackageConfig(**invalid_helm_package) # pylint: disable=protected-access diff --git a/src/aosm/azext_aosm/tests/latest/test_nsd.py b/src/aosm/azext_aosm/tests/latest/test_nsd.py index e5f0885cfce..da13e3fa3e2 100644 --- a/src/aosm/azext_aosm/tests/latest/test_nsd.py +++ b/src/aosm/azext_aosm/tests/latest/test_nsd.py @@ -8,3 +8,7 @@ from unittest.mock import Mock, patch from azext_aosm.generate_nsd.nsd_generator import NSDGenerator + +class TestNSDGenerator(): + def test_create(self): + pass \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/test_vnf.py b/src/aosm/azext_aosm/tests/latest/test_vnf.py index 653978e8b8e..2b2e7ecb491 100644 --- a/src/aosm/azext_aosm/tests/latest/test_vnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_vnf.py @@ -6,5 +6,20 @@ import os import unittest from unittest.mock import Mock, patch +from tempfile import TemporaryDirectory -from azext_aosm.generate_nfd.vnf_nfd_generator import VnfNfdGenerator +from azext_aosm.custom import build_definition + +mock_vnf_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_vnf") + +class TestVNF(): + def test_build(self): + starting_directory = os.getcwd() + with TemporaryDirectory() as test_dir: + os.chdir(test_dir) + + try: + build_definition("vnf", os.path.join(mock_vnf_folder, "input.json")) + assert os.path.exists("nfd-bicep-ubuntu-template") + except: + os.chdir(starting_directory) From f06efc3ae25f0b0b332099fb1da59e6df6f53f41 Mon Sep 17 00:00:00 2001 From: Cyclam <95434717+Cyclam@users.noreply.github.com> Date: Thu, 29 Jun 2023 16:29:07 +0100 Subject: [PATCH 119/145] achurchard/style fixes (#35) Fix style issues raised by `azdev style` --- .github/workflows/CheckStyleAndLinting.yml | 2 +- src/aosm/azext_aosm/_client_factory.py | 2 +- src/aosm/azext_aosm/_configuration.py | 125 +++++++++++------- src/aosm/azext_aosm/_params.py | 46 +++++-- src/aosm/azext_aosm/commands.py | 1 - src/aosm/azext_aosm/custom.py | 27 ++-- src/aosm/azext_aosm/delete/delete.py | 46 +++++-- src/aosm/azext_aosm/deploy/artifact.py | 28 ++-- .../azext_aosm/deploy/artifact_manifest.py | 7 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 95 +++++++------ src/aosm/azext_aosm/deploy/pre_deploy.py | 73 +++++----- .../generate_nfd/cnf_nfd_generator.py | 116 ++++++++-------- .../generate_nfd/nfd_generator_base.py | 14 +- .../generate_nfd/vnf_nfd_generator.py | 37 +++--- .../azext_aosm/generate_nsd/nsd_generator.py | 97 ++++++++------ src/aosm/azext_aosm/util/constants.py | 59 ++++----- .../azext_aosm/util/management_clients.py | 21 ++- src/aosm/setup.md | 2 + src/aosm/setup.py | 3 +- 19 files changed, 449 insertions(+), 352 deletions(-) diff --git a/.github/workflows/CheckStyleAndLinting.yml b/.github/workflows/CheckStyleAndLinting.yml index 0c8382649d8..82e39b86e0b 100644 --- a/.github/workflows/CheckStyleAndLinting.yml +++ b/.github/workflows/CheckStyleAndLinting.yml @@ -15,4 +15,4 @@ jobs: - name: Check Style run: azdev style aosm - name: Check Linting - run: azdev linter aosm + run: azdev linter aosm \ No newline at end of file diff --git a/src/aosm/azext_aosm/_client_factory.py b/src/aosm/azext_aosm/_client_factory.py index 66c3bea2ab8..61fe56814a4 100644 --- a/src/aosm/azext_aosm/_client_factory.py +++ b/src/aosm/azext_aosm/_client_factory.py @@ -5,9 +5,9 @@ from azure.cli.core.commands.client_factory import get_mgmt_service_client from azure.cli.core.profiles import ResourceType +from azure.mgmt.containerregistry import ContainerRegistryManagementClient from .vendored_sdks import HybridNetworkManagementClient -from azure.mgmt.containerregistry import ContainerRegistryManagementClient def cf_aosm(cli_ctx, *_) -> HybridNetworkManagementClient: diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 23de58ce64d..4f40ad21917 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,6 +1,3 @@ -## Disabling as every if statement in validate in NSConfig class has this condition -# pylint: disable=simplifiable-condition - import os from dataclasses import dataclass, field from pathlib import Path @@ -10,70 +7,94 @@ from azext_aosm.util.constants import ( CNF, - DEFINITION_OUTPUT_BICEP_PREFIX, - NF_DEFINITION_JSON_FILE, + NF_DEFINITION_OUTPUT_BICEP_PREFIX, + NF_DEFINITION_JSON_FILENAME, NSD, - NSD_DEFINITION_OUTPUT_BICEP_PREFIX, + NSD_OUTPUT_BICEP_PREFIX, VNF, ) DESCRIPTION_MAP: Dict[str, str] = { - "publisher_resource_group_name": + "publisher_resource_group_name": ( "Resource group for the Publisher resource. " - "Will be created if it does not exist.", - "publisher_name": + "Will be created if it does not exist." + ), + "publisher_name": ( "Name of the Publisher resource you want your definition published to. " - "Will be created if it does not exist.", - "publisher_name_nsd": + "Will be created if it does not exist." + ), + "publisher_name_nsd": ( "Name of the Publisher resource you want your design published to. " "This should be the same as the publisher used for your NFDVs" - , + ), "publisher_resource_group_name_nsd": "Resource group for the Publisher resource.", "nf_name": "Name of NF definition", "version": "Version of the NF definition", - "acr_artifact_store_name": "Name of the ACR Artifact Store resource. Will be created if it does not exist.", + "acr_artifact_store_name": ( + "Name of the ACR Artifact Store resource. Will be created if it does not exist." + ), "location": "Azure location to use when creating resources.", - "blob_artifact_store_name": + "blob_artifact_store_name": ( "Name of the storage account Artifact Store resource. Will be created if it " - "does not exist.", + "does not exist." + ), "artifact_name": "Name of the artifact", - "file_path": "Optional. File path of the artifact you wish to upload from your local disk. " - "Delete if not required.", - "blob_sas_url": "Optional. SAS URL of the blob artifact you wish to copy to your Artifact Store. " - "Delete if not required.", - "artifact_version": "Version of the artifact. For VHDs this must be in format A-B-C. " - "For ARM templates this must be in format A.B.C", + "file_path": ( + "Optional. File path of the artifact you wish to upload from your local disk. " + "Delete if not required." + ), + "blob_sas_url": ( + "Optional. SAS URL of the blob artifact you wish to copy to your Artifact" + " Store. Delete if not required." + ), + "artifact_version": ( + "Version of the artifact. For VHDs this must be in format A-B-C. " + "For ARM templates this must be in format A.B.C" + ), "nsdv_description": "Description of the NSDV", - "nsdg_name": "Network Service Design Group Name. This is the collection of Network Service Design Versions. " - "Will be created if it does not exist.", - "nsd_version": "Version of the NSD to be created. This should be in the format A.B.C", - "network_function_definition_group_name": + "nsdg_name": ( + "Network Service Design Group Name. This is the collection of Network Service" + " Design Versions. Will be created if it does not exist." + ), + "nsd_version": ( + "Version of the NSD to be created. This should be in the format A.B.C" + ), + "network_function_definition_group_name": ( "Existing Network Function Definition Group Name. " - "This can be created using the 'az aosm nfd' commands.", - "network_function_definition_version_name": + "This can be created using the 'az aosm nfd' commands." + ), + "network_function_definition_version_name": ( "Existing Network Function Definition Version Name. " - "This can be created using the 'az aosm nfd' commands.", - "network_function_definition_offering_location": "Offering location of the Network Function Definition", - "network_function_type": "Type of nf in the definition. Valid values are 'cnf' or 'vnf'", + "This can be created using the 'az aosm nfd' commands." + ), + "network_function_definition_offering_location": ( + "Offering location of the Network Function Definition" + ), + "network_function_type": ( + "Type of nf in the definition. Valid values are 'cnf' or 'vnf'" + ), "helm_package_name": "Name of the Helm package", - "path_to_chart": - "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz", - "path_to_mappings": + "path_to_chart": ( + "File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz" + ), + "path_to_mappings": ( "File path of value mappings on local disk where chosen values are replaced " "with deploymentParameter placeholders. Accepts .yaml or .yml. If left as a " "blank string, a value mappings file will be generated with every value " "mapped to a deployment parameter. Use a blank string and --interactive on " "the build command to interactively choose which values to map." - , - "helm_depends_on": + ), + "helm_depends_on": ( "Names of the Helm packages this package depends on. " - "Leave as an empty array if no dependencies", - "image_name_parameter": + "Leave as an empty array if no dependencies" + ), + "image_name_parameter": ( "The parameter name in the VM ARM template which specifies the name of the " - "image to use for the VM.", - "source_registry_id": - "Resource ID of the source acr registry from which to pull " - "the image", + "image to use for the VM." + ), + "source_registry_id": ( + "Resource ID of the source acr registry from which to pull the image" + ), } @@ -135,6 +156,9 @@ class NSConfiguration: def validate(self): """Validate that all of the configuration parameters are set.""" + # Exemption for pylint as explicitly including the empty string makes the code clearer + # pylint: disable=simplifiable-condition + if self.location == DESCRIPTION_MAP["location"] or "": raise ValueError("Location must be set") if self.publisher_name == DESCRIPTION_MAP["publisher_name_nsd"] or "": @@ -181,7 +205,7 @@ def validate(self): def build_output_folder_name(self) -> str: """Return the local folder for generating the bicep template to.""" current_working_directory = os.getcwd() - return f"{current_working_directory}/{NSD_DEFINITION_OUTPUT_BICEP_PREFIX}" + return f"{current_working_directory}/{NSD_OUTPUT_BICEP_PREFIX}" @property def resource_element_name(self) -> str: @@ -196,7 +220,7 @@ def network_function_name(self) -> str: @property def acr_manifest_name(self) -> str: """Return the ACR manifest name from the NFD name.""" - sanitised_nf_name = self.network_function_name.lower().replace('_', '-') + sanitised_nf_name = self.network_function_name.lower().replace("_", "-") return f"{sanitised_nf_name}-acr-manifest-{self.nsd_version.replace('.', '-')}" @property @@ -215,7 +239,7 @@ def arm_template(self) -> ArtifactConfig: artifact = ArtifactConfig() artifact.version = self.nsd_version artifact.file_path = os.path.join( - self.build_output_folder_name, NF_DEFINITION_JSON_FILE + self.build_output_folder_name, NF_DEFINITION_JSON_FILENAME ) return artifact @@ -258,11 +282,13 @@ def validate(self) -> None: if "." in self.vhd.version or "-" not in self.vhd.version: raise ValidationError( - "Config validation error. VHD artifact version should be in format A-B-C" + "Config validation error. VHD artifact version should be in format" + " A-B-C" ) if "." not in self.arm_template.version or "-" in self.arm_template.version: raise ValidationError( - "Config validation error. ARM template artifact version should be in format A.B.C" + "Config validation error. ARM template artifact version should be in" + " format A.B.C" ) filepath_set = ( self.vhd.file_path and self.vhd.file_path != DESCRIPTION_MAP["file_path"] @@ -274,7 +300,8 @@ def validate(self) -> None: # If these are the same, either neither is set or both are, both of which are errors if filepath_set == sas_set: raise ValidationError( - "Config validation error. VHD config must have either a local filepath or a blob SAS URL" + "Config validation error. VHD config must have either a local filepath" + " or a blob SAS URL" ) if filepath_set: @@ -294,7 +321,7 @@ def sa_manifest_name(self) -> str: def build_output_folder_name(self) -> str: """Return the local folder for generating the bicep template to.""" arm_template_path = self.arm_template.file_path - return f"{DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" + return f"{NF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" @dataclass @@ -325,7 +352,7 @@ def __post_init__(self): @property def build_output_folder_name(self) -> str: """Return the local folder for generating the bicep template to.""" - return f"{DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}" + return f"{NF_DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}" def get_configuration( diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index b7e15796e0f..c7a8602bd76 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -2,7 +2,6 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -# pylint: disable=line-too-long from argcomplete.completers import FilesCompleter from azure.cli.core import AzCommandsLoader @@ -43,51 +42,72 @@ def load_arguments(self: AzCommandsLoader, _): options_list=["--definition-file", "-b"], type=file_type, completer=FilesCompleter(allowednames="*.json"), - help="Optional path to a bicep file to publish. Use to override publish of the built definition with an alternative file.", + help=( + "Optional path to a bicep file to publish. Use to override publish of" + " the built definition with an alternative file." + ), ) c.argument( "design_file", options_list=["--design-file", "-b"], type=file_type, completer=FilesCompleter(allowednames="*.bicep"), - help="Optional path to a bicep file to publish. Use to override publish of the built design with an alternative file.", + help=( + "Optional path to a bicep file to publish. Use to override publish of" + " the built design with an alternative file." + ), ) c.argument( "order_params", arg_type=get_three_state_flag(), - help="VNF definition_type only - ignored for CNF." - " Order deploymentParameters schema and configMappings to have the " - "parameters without default values at the top and those with default " - "values at the bottom. Can make it easier to remove those with defaults " - "which you do not want to expose as NFD parameters.", + help=( + "VNF definition_type only - ignored for CNF. Order deploymentParameters" + " schema and configMappings to have the parameters without default" + " values at the top and those with default values at the bottom. Can" + " make it easier to remove those with defaults which you do not want to" + " expose as NFD parameters." + ), ) c.argument( "interactive", options_list=["--interactive", "-i"], arg_type=get_three_state_flag(), - help="Prompt user to choose every parameter to expose as an NFD parameter." - " Those without defaults are automatically included.", + help=( + "Prompt user to choose every parameter to expose as an NFD parameter." + " Those without defaults are automatically included." + ), ) c.argument( "parameters_json_file", options_list=["--parameters-file", "-p"], type=file_type, completer=FilesCompleter(allowednames="*.json"), - help="Optional path to a parameters file for the bicep definition file. Use to override publish of the built definition and config with alternative parameters.", + help=( + "Optional path to a parameters file for the bicep definition file. Use" + " to override publish of the built definition and config with" + " alternative parameters." + ), ) c.argument( "manifest_file", options_list=["--manifest-file", "-m"], type=file_type, completer=FilesCompleter(allowednames="*.json"), - help="Optional path to a bicep file to publish manifests. Use to override publish of the built definition with an alternative file.", + help=( + "Optional path to a bicep file to publish manifests. Use to override" + " publish of the built definition with an alternative file." + ), ) c.argument( "manifest_parameters_json_file", options_list=["--manifest-parameters-file", "-mp"], type=file_type, completer=FilesCompleter(allowednames="*.json"), - help="Optional path to a parameters file for the manifest definition file. Use to override publish of the built definition and config with alternative parameters.", + help=( + "Optional path to a parameters file for the manifest definition file." + " Use to override publish of the built definition and config with" + " alternative parameters." + ), ) with self.argument_context("aosm nsd") as c: diff --git a/src/aosm/azext_aosm/commands.py b/src/aosm/azext_aosm/commands.py index 8fd99d31c23..abc33f8444b 100644 --- a/src/aosm/azext_aosm/commands.py +++ b/src/aosm/azext_aosm/commands.py @@ -3,7 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -# pylint: disable=line-too-long from azure.cli.core import AzCommandsLoader from azext_aosm._client_factory import cf_aosm diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 6885a31276d..78b058c8859 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -16,7 +16,7 @@ ) from knack.log import get_logger -from azext_aosm._client_factory import cf_resources, cf_acr_registries +from azext_aosm._client_factory import cf_acr_registries, cf_resources from azext_aosm._configuration import ( CNFConfiguration, NFConfiguration, @@ -90,7 +90,8 @@ def _get_config_from_file( if not os.path.exists(config_file): raise InvalidArgumentValueError( - f"Config file {config_file} not found. Please specify a valid config file path." + f"Config file {config_file} not found. Please specify a valid config file" + " path." ) with open(config_file, "r", encoding="utf-8") as f: @@ -112,11 +113,13 @@ def _generate_nfd( nfd_generator = CnfNfdGenerator(config, interactive) else: raise CLIInternalError( - "Generate NFD called for unrecognised definition_type. Only VNF and CNF have been implemented." + "Generate NFD called for unrecognised definition_type. Only VNF and CNF" + " have been implemented." ) if nfd_generator.bicep_path: carry_on = input( - f"The folder {os.path.dirname(nfd_generator.bicep_path)} already exists - delete it and continue? (y/n)" + f"The folder {os.path.dirname(nfd_generator.bicep_path)} already exists -" + " delete it and continue? (y/n)" ) if carry_on != "y": raise UnclassifiedUserFault("User aborted! ") @@ -184,7 +187,8 @@ def publish_definition( ) else: raise ValueError( - f"Definition type must be either 'vnf' or 'cnf'. Definition type {definition_type} is not recognised." + "Definition type must be either 'vnf' or 'cnf'. Definition type" + f" {definition_type} is not recognised." ) @@ -219,7 +223,8 @@ def delete_published_definition( delly.delete_nfd(clean=clean) else: raise ValueError( - f"Definition type must be either 'vnf' or 'cnf'. Definition type {definition_type} is not recognised." + "Definition type must be either 'vnf' or 'cnf'. Definition type" + f" {definition_type} is not recognised." ) @@ -246,7 +251,8 @@ def _generate_config(configuration_type: str, output_file: str = "input.json"): if os.path.exists(output_file): carry_on = input( - f"The file {output_file} already exists - do you want to overwrite it? (y/n)" + f"The file {output_file} already exists - do you want to overwrite it?" + " (y/n)" ) if carry_on != "y": raise UnclassifiedUserFault("User aborted!") @@ -258,7 +264,9 @@ def _generate_config(configuration_type: str, output_file: str = "input.json"): else: prtName = "design" print(f"Empty {prtName} configuration has been written to {output_file}") - logger.info(f"Empty {prtName} configuration has been written to {output_file}") + logger.info( + "Empty %s configuration has been written to %s", prtName, output_file + ) def build_design(cmd, client: HybridNetworkManagementClient, config_file: str): @@ -362,7 +370,8 @@ def _generate_nsd(config: NSConfiguration, api_clients: ApiClients): """Generate a Network Service Design for the given config.""" if os.path.exists(config.build_output_folder_name): carry_on = input( - f"The folder {config.build_output_folder_name} already exists - delete it and continue? (y/n)" + f"The folder {config.build_output_folder_name} already exists - delete it" + " and continue? (y/n)" ) if carry_on != "y": raise UnclassifiedUserFault("User aborted! ") diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index aeedaaf4543..6894f6f3544 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -41,13 +41,16 @@ def delete_nfd(self, clean: bool = False): if clean: print( - f"Are you sure you want to delete all resources associated with NFD {self.config.nf_name} including the artifact stores and publisher {self.config.publisher_name}?" + "Are you sure you want to delete all resources associated with NFD" + f" {self.config.nf_name} including the artifact stores and publisher" + f" {self.config.publisher_name}?" ) logger.warning( "This command will fail if other NFD versions exist in the NFD group." ) logger.warning( - "Only do this if you are SURE you are not sharing the publisher and artifact stores with other NFDs" + "Only do this if you are SURE you are not sharing the publisher and" + " artifact stores with other NFDs" ) print("There is no undo. Type the publisher name to confirm.") if not input_ack(self.config.publisher_name.lower(), "Confirm delete:"): @@ -55,7 +58,9 @@ def delete_nfd(self, clean: bool = False): return else: print( - f"Are you sure you want to delete the NFD Version {self.config.version} and associated manifests from group {self.config.nfdg_name} and publisher {self.config.publisher_name}?" + "Are you sure you want to delete the NFD Version" + f" {self.config.version} and associated manifests from group" + f" {self.config.nfdg_name} and publisher {self.config.publisher_name}?" ) print("There is no undo. Type 'delete' to confirm") if not input_ack("delete", "Confirm delete:"): @@ -85,7 +90,10 @@ def delete_nsd(self): assert isinstance(self.config, NSConfiguration) print( - f"Are you sure you want to delete the NSD Version {self.config.nsd_version}, the associated manifest {self.config.acr_manifest_name} and configuration group schema {self.config.cg_schema_name}?" + "Are you sure you want to delete the NSD Version" + f" {self.config.nsd_version}, the associated manifest" + f" {self.config.acr_manifest_name} and configuration group schema" + f" {self.config.cg_schema_name}?" ) print("There is no undo. Type 'delete' to confirm") if not input_ack("delete", "Confirm delete:"): @@ -97,7 +105,10 @@ def delete_nsd(self): self.delete_config_group_schema() def delete_nfdv(self): - message = f"Delete NFDV {self.config.version} from group {self.config.nfdg_name} and publisher {self.config.publisher_name}" + message = ( + f"Delete NFDV {self.config.version} from group {self.config.nfdg_name} and" + f" publisher {self.config.publisher_name}" + ) logger.debug(message) print(message) try: @@ -111,13 +122,18 @@ def delete_nfdv(self): print("Deleted NFDV.") except Exception: logger.error( - f"Failed to delete NFDV {self.config.version} from group {self.config.nfdg_name}" + "Failed to delete NFDV %s from group %s", + self.config.version, + self.config.nfdg_name, ) raise def delete_nsdv(self): assert isinstance(self.config, NSConfiguration) - message = f"Delete NSDV {self.config.nsd_version} from group {self.config.nsdg_name} and publisher {self.config.publisher_name}" + message = ( + f"Delete NSDV {self.config.nsd_version} from group" + f" {self.config.nsdg_name} and publisher {self.config.publisher_name}" + ) logger.debug(message) print(message) try: @@ -131,7 +147,9 @@ def delete_nsdv(self): print("Deleted NSDV.") except Exception: logger.error( - f"Failed to delete NSDV {self.config.nsd_version} from group {self.config.nsdg_name}" + "Failed to delete NSDV %s from group %s", + self.config.nsd_version, + self.config.nsdg_name, ) raise @@ -154,7 +172,8 @@ def delete_artifact_manifest(self, store_type: str) -> None: from azure.cli.core.azclierror import CLIInternalError raise CLIInternalError( - "Delete artifact manifest called for invalid store type. Valid types are sa and acr." + "Delete artifact manifest called for invalid store type. Valid types" + " are sa and acr." ) message = ( f"Delete Artifact manifest {manifest_name} from artifact store {store_name}" @@ -172,7 +191,9 @@ def delete_artifact_manifest(self, store_type: str) -> None: print("Deleted Artifact Manifest") except Exception: logger.error( - f"Failed to delete Artifact manifest {manifest_name} from artifact store {store_name}" + "Failed to delete Artifact manifest %s from artifact store %s", + manifest_name, + store_name, ) raise @@ -226,7 +247,8 @@ def delete_artifact_store(self, store_type: str) -> None: from azure.cli.core.azclierror import CLIInternalError raise CLIInternalError( - "Delete artifact store called for invalid store type. Valid types are sa and acr." + "Delete artifact store called for invalid store type. Valid types are" + " sa and acr." ) message = f"Delete Artifact store {store_name}" logger.debug(message) @@ -240,7 +262,7 @@ def delete_artifact_store(self, store_type: str) -> None: poller.result() print("Deleted Artifact Store") except Exception: - logger.error(f"Failed to delete Artifact store {store_name}") + logger.error("Failed to delete Artifact store %s", store_name) raise def delete_publisher(self) -> None: diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 905e715693c..ee37c50bebe 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -3,20 +3,18 @@ # pylint: disable=unidiomatic-typecheck """A module to handle interacting with artifacts.""" +import subprocess from dataclasses import dataclass from typing import Union -import subprocess + +from azure.cli.core.commands import LongRunningOperation +from azure.mgmt.containerregistry.models import ImportImageParameters, ImportSource +from azure.storage.blob import BlobClient, BlobType from knack.log import get_logger +from knack.util import CLIError from oras.client import OrasClient -from azure.storage.blob import BlobClient, BlobType from azext_aosm._configuration import ArtifactConfig, HelmPackageConfig -from azure.mgmt.containerregistry.models import ( - ImportImageParameters, - ImportSource, -) - -from azure.cli.core.commands import LongRunningOperation logger = get_logger(__name__) @@ -84,7 +82,7 @@ def _upload_helm_to_acr(self, artifact_config: HelmPackageConfig) -> None: login_command = ["az", "acr", "login", "--name", registry_name] subprocess.run(login_command, check=True) - logger.debug(f"Uploading {chart_path} to {target_registry}") + logger.debug("Uploading %s to %s", chart_path, target_registry) # helm push "$chart_path" "$target_registry" push_command = ["helm", "push", chart_path, target_registry] @@ -126,11 +124,12 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: ) else: raise RuntimeError( - f"{source_blob.blob_name} does not exist in {source_blob.account_name}." + f"{source_blob.blob_name} does not exist in" + f" {source_blob.account_name}." ) + @staticmethod def copy_image( - self, cli_ctx, container_registry_client, source_registry_id, @@ -172,9 +171,12 @@ def copy_image( logger.info( "Successfully imported %s to %s", source_image, target_registry_name ) - except Exception as error: + except CLIError as error: logger.error( - "Failed to import %s to %s. Check if this image exists in the source registry or is already present in the target registry.", + ( + "Failed to import %s to %s. Check if this image exists in the" + " source registry or is already present in the target registry." + ), source_image, target_registry_name, ) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 168021e8519..55b55fd95e6 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -139,7 +139,9 @@ def _get_artifact_client( # For AOSM to work VHD blobs must have the suffix .vhd if artifact.artifact_name.endswith("-vhd"): - blob_name = f"{artifact.artifact_name[:-4].replace('-', '')}-{artifact.artifact_version}.vhd" + blob_name = ( + f"{artifact.artifact_name[:-4].replace('-', '')}-{artifact.artifact_version}.vhd" + ) else: blob_name = container_name @@ -159,8 +161,7 @@ def _get_blob_url(self, container_name: str, blob_name: str) -> str: for container_credential in self._manifest_credentials["container_credentials"]: if container_credential["container_name"] == container_name: sas_uri = str(container_credential["container_sas_uri"]) - sas_uri_prefix = sas_uri.split("?")[0] # pylint: disable=use-maxsplit-arg - sas_uri_token = sas_uri.split("?")[1] + sas_uri_prefix, sas_uri_token = sas_uri.split("?", maxsplit=1) blob_url = f"{sas_uri_prefix}/{blob_name}?{sas_uri_token}" logger.debug("Blob URL: %s", blob_url) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 3c7dfa95eb9..36d0b76979e 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -15,26 +15,25 @@ from knack.log import get_logger from azext_aosm._configuration import ( + CNFConfiguration, NFConfiguration, NSConfiguration, VNFConfiguration, - CNFConfiguration, ) -from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator from azext_aosm.deploy.artifact import Artifact -from azext_aosm.util.management_clients import ApiClients +from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK from azext_aosm.util.constants import ( - NF_DEFINITION_BICEP_FILE, - NSD, - NSD_ARTIFACT_MANIFEST_BICEP_FILE, - NSD_DEFINITION_BICEP_FILE, - CNF_DEFINITION_BICEP_TEMPLATE, - CNF_MANIFEST_BICEP_TEMPLATE, CNF, + CNF_DEFINITION_BICEP_TEMPLATE_FILENAME, + CNF_MANIFEST_BICEP_TEMPLATE_FILENAME, + NF_DEFINITION_BICEP_FILENAME, + NSD, + NSD_ARTIFACT_MANIFEST_BICEP_FILENAME, + NSD_BICEP_FILENAME, VNF, - VNF_DEFINITION_BICEP_TEMPLATE, - VNF_MANIFEST_BICEP_TEMPLATE, + VNF_DEFINITION_BICEP_TEMPLATE_FILENAME, + VNF_MANIFEST_BICEP_TEMPLATE_FILENAME, ) from azext_aosm.util.management_clients import ApiClients @@ -65,7 +64,8 @@ def __init__( self.config = config self.pre_deployer = PreDeployerViaSDK(api_clients, self.config) - def read_parameters_from_file(self, parameters_json_file: str) -> Dict[str, Any]: + @staticmethod + def read_parameters_from_file(parameters_json_file: str) -> Dict[str, Any]: """ Read parameters from a file. @@ -114,7 +114,7 @@ def deploy_vnfd_from_bicep( # one produced from building the NFDV using this CLI bicep_path = os.path.join( self.config.build_output_folder_name, - VNF_DEFINITION_BICEP_TEMPLATE, + VNF_DEFINITION_BICEP_TEMPLATE_FILENAME, ) if parameters_json_file: @@ -141,9 +141,10 @@ def deploy_vnfd_from_bicep( f"version {self.config.version}" ) message = ( - f"Deploy bicep template for NFD {self.config.nf_name} version {self.config.version} " - f"into {self.config.publisher_resource_group_name} under publisher " - f"{self.config.publisher_name}" + f"Deploy bicep template for NFD {self.config.nf_name} version" + f" {self.config.version} into" + f" {self.config.publisher_resource_group_name} under publisher" + f" {self.config.publisher_name}" ) print(message) logger.info(message) @@ -237,14 +238,14 @@ def construct_manifest_parameters(self) -> Dict[str, Any]: "vhdVersion": {"value": self.config.vhd.version}, "armTemplateVersion": {"value": self.config.arm_template.version}, } - elif isinstance(self.config, CNFConfiguration): + if isinstance(self.config, CNFConfiguration): return { "location": {"value": self.config.location}, "publisherName": {"value": self.config.publisher_name}, "acrArtifactStoreName": {"value": self.config.acr_artifact_store_name}, "acrManifestName": {"value": self.config.acr_manifest_name}, } - elif isinstance(self.config, NSConfiguration): + if isinstance(self.config, NSConfiguration): return { "location": {"value": self.config.location}, "publisherName": {"value": self.config.publisher_name}, @@ -283,7 +284,7 @@ def deploy_cnfd_from_bicep( # one produced from building the NFDV using this CLI bicep_path = os.path.join( self.config.build_output_folder_name, - CNF_DEFINITION_BICEP_TEMPLATE, + CNF_DEFINITION_BICEP_TEMPLATE_FILENAME, ) if parameters_json_file: @@ -296,7 +297,7 @@ def deploy_cnfd_from_bicep( parameters = self.construct_cnfd_parameters() logger.debug( - f"Parameters used for CNF definition bicep deployment: {parameters}" + "Parameters used for CNF definition bicep deployment: %s", parameters ) # Create or check required resources @@ -311,9 +312,10 @@ def deploy_cnfd_from_bicep( f"version {self.config.version}" ) message = ( - f"Deploy bicep template for NFD {self.config.nf_name} version {self.config.version} " - f"into {self.config.publisher_resource_group_name} under publisher " - f"{self.config.publisher_name}" + f"Deploy bicep template for NFD {self.config.nf_name} version" + f" {self.config.version} into" + f" {self.config.publisher_resource_group_name} under publisher" + f" {self.config.publisher_name}" ) print(message) logger.info(message) @@ -360,7 +362,8 @@ def deploy_cnfd_from_bicep( artifact_dictionary.pop(helm_package_name) - # All the remaining artifacts are not in the helm_packages list. We assume that they are images that need to be copied from another ACR. + # All the remaining artifacts are not in the helm_packages list. We assume that they + # are images that need to be copied from another ACR. for artifact in artifact_dictionary.values(): assert isinstance(artifact, Artifact) @@ -401,7 +404,7 @@ def deploy_nsd_from_bicep( # one produced from building the NSDV using this CLI bicep_path = os.path.join( self.config.build_output_folder_name, - NSD_DEFINITION_BICEP_FILE, + NSD_BICEP_FILENAME, ) if parameters_json_file: @@ -434,7 +437,8 @@ def deploy_nsd_from_bicep( logger.info(message) self.deploy_bicep_template(bicep_path, parameters) print( - f"Deployed NSD {self.config.acr_manifest_name} version {self.config.nsd_version}." + f"Deployed NSD {self.config.acr_manifest_name} version" + f" {self.config.nsd_version}." ) acr_manifest = ArtifactManifestOperator( self.config, @@ -447,7 +451,7 @@ def deploy_nsd_from_bicep( # Convert the NF bicep to ARM arm_template_artifact_json = self.convert_bicep_to_arm( - os.path.join(self.config.build_output_folder_name, NF_DEFINITION_BICEP_FILE) + os.path.join(self.config.build_output_folder_name, NF_DEFINITION_BICEP_FILENAME) ) with open(self.config.arm_template.file_path, "w", encoding="utf-8") as file: @@ -472,11 +476,11 @@ def deploy_manifest_template( if not manifest_bicep_path: if configuration_type == NSD: - file_name = NSD_ARTIFACT_MANIFEST_BICEP_FILE + file_name = NSD_ARTIFACT_MANIFEST_BICEP_FILENAME elif configuration_type == VNF: - file_name = VNF_MANIFEST_BICEP_TEMPLATE + file_name = VNF_MANIFEST_BICEP_TEMPLATE_FILENAME elif configuration_type == CNF: - file_name = CNF_MANIFEST_BICEP_TEMPLATE + file_name = CNF_MANIFEST_BICEP_TEMPLATE_FILENAME manifest_bicep_path = os.path.join( self.config.build_output_folder_name, @@ -570,9 +574,7 @@ def validate_and_deploy_arm_template( :return: Output dictionary from the bicep template. """ # Get current time from the time module and remove all digits after the decimal point - current_time = str(time.time()).split(".")[ - 0 - ] # pylint: disable=use-maxsplit-arg + current_time = str(time.time()).split(".", maxsplit=1)[0] # Add a timestamp to the deployment name to ensure it is unique deployment_name = f"AOSM_CLI_deployment_into_{resource_group}_{current_time}" @@ -594,14 +596,18 @@ def validate_and_deploy_arm_template( if validation_res.error: # Validation failed so don't even try to deploy logger.error( - "Template for resource group %s has failed validation. The message was: %s.\ - See logs for additional details.", + ( + "Template for resource group %s has failed validation. The message" + " was: %s. See logs for additional details." + ), resource_group, validation_res.error.message, ) logger.debug( - "Template for resource group %s failed validation. \ - Full error details: %s", + ( + "Template for resource group %s failed validation." + " Full error details: %s" + ), resource_group, validation_res.error, ) @@ -636,10 +642,10 @@ def validate_and_deploy_arm_template( if depl_props.provisioning_state != "Succeeded": logger.debug("Failed to provision: %s", depl_props) raise RuntimeError( - f"Deploy of template to resource group" + "Deploy of template to resource group" f" {resource_group} proceeded but the provisioning" - f" state returned is {depl_props.provisioning_state}. " - f"\nAborting" + f" state returned is {depl_props.provisioning_state}." + "\nAborting" ) logger.debug( "Provisioning state of deployment %s : %s", @@ -649,7 +655,8 @@ def validate_and_deploy_arm_template( return depl_props.outputs - def convert_bicep_to_arm(self, bicep_template_path: str) -> Any: + @staticmethod + def convert_bicep_to_arm(bicep_template_path: str) -> Any: """ Convert a bicep template into an ARM template. @@ -689,8 +696,10 @@ def convert_bicep_to_arm(self, bicep_template_path: str) -> Any: logger.debug("az bicep output: %s", str(bicep_output)) except subprocess.CalledProcessError as e: logger.error( - "ARM template compilation failed! See logs for full " - "output. The failing command was %s", + ( + "ARM template compilation failed! See logs for full " + "output. The failing command was %s" + ), e.cmd, ) logger.debug("bicep build stdout: %s", e.stdout) diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index b83ed1b3b52..2c26cac4850 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -60,9 +60,10 @@ def ensure_resource_group_exists(self, resource_group_name: str) -> None: ): if isinstance(self.config, NSConfiguration): raise AzCLIError( - f"Resource Group {resource_group_name} does not exist. Please create it before running this command." + f"Resource Group {resource_group_name} does not exist. Please" + " create it before running this command." ) - logger.info(f"RG {resource_group_name} not found. Create it.") + logger.info("RG %s not found. Create it.", resource_group_name) print(f"Creating resource group {resource_group_name}.") rg_params: ResourceGroup = ResourceGroup(location=self.config.location) self.api_clients.resource_client.resource_groups.create_or_update( @@ -99,17 +100,20 @@ def ensure_publisher_exists( resource_group_name, publisher_name ) print( - f"Publisher {publisher.name} exists in resource group {resource_group_name}" + f"Publisher {publisher.name} exists in resource group" + f" {resource_group_name}" ) - except azure_exceptions.ResourceNotFoundError: + except azure_exceptions.ResourceNotFoundError as ex: if isinstance(self.config, NSConfiguration): raise AzCLIError( - f"Publisher {publisher_name} does not exist. Please create it before running this command." - ) + f"Publisher {publisher_name} does not exist. Please create it" + " before running this command." + ) from ex # Create the publisher logger.info("Creating publisher %s if it does not exist", publisher_name) print( - f"Creating publisher {publisher_name} in resource group {resource_group_name}" + f"Creating publisher {publisher_name} in resource group" + f" {resource_group_name}" ) pub = self.api_clients.aosm_client.publishers.begin_create_or_update( resource_group_name=resource_group_name, @@ -141,7 +145,8 @@ def ensure_config_source_registry_exists(self) -> None: self.config.source_registry_id, ) - # Assume that the registry id is of the form: /subscriptions//resourceGroups//providers/Microsoft.ContainerRegistry/registries/ + # Assume that the registry id is of the form: /subscriptions/ + # /resourceGroups//providers/Microsoft.ContainerRegistry/registries/ source_registry_name = self.config.source_registry_id.split("/")[-1] source_registry_resource_group_name = self.config.source_registry_id.split("/")[ -5 @@ -186,11 +191,13 @@ def ensure_artifact_store_exists( artifact_store_name=artifact_store_name, ) print( - f"Artifact store {artifact_store_name} exists in resource group {resource_group_name}" + f"Artifact store {artifact_store_name} exists in resource group" + f" {resource_group_name}" ) - except azure_exceptions.ResourceNotFoundError: + except azure_exceptions.ResourceNotFoundError as ex: print( - f"Create Artifact Store {artifact_store_name} of type {artifact_store_type}" + f"Create Artifact Store {artifact_store_name} of type" + f" {artifact_store_type}" ) poller = ( self.api_clients.aosm_client.artifact_stores.begin_create_or_update( @@ -208,15 +215,16 @@ def ensure_artifact_store_exists( arty: ArtifactStore = poller.result() if arty.provisioning_state != ProvisioningState.SUCCEEDED: - logger.debug(f"Failed to provision artifact store: {arty.name}") + logger.debug("Failed to provision artifact store: %s", arty.name) raise RuntimeError( - f"Creation of artifact store proceeded, but the provisioning" + "Creation of artifact store proceeded, but the provisioning" f" state returned is {arty.provisioning_state}. " - f"\nAborting" - ) + "\nAborting" + ) from ex logger.debug( - f"Provisioning state of {artifact_store_name}" - f": {arty.provisioning_state}" + "Provisioning state of %s: %s", + artifact_store_name, + arty.provisioning_state, ) def ensure_acr_artifact_store_exists(self) -> None: @@ -286,9 +294,10 @@ def ensure_nfdg_exists( network_function_definition_group_name=nfdg_name, ) print( - f"Network function definition group {nfdg_name} exists in resource group {resource_group_name}" + f"Network function definition group {nfdg_name} exists in resource" + f" group {resource_group_name}" ) - except azure_exceptions.ResourceNotFoundError: + except azure_exceptions.ResourceNotFoundError as ex: print(f"Create Network Function Definition Group {nfdg_name}") poller = self.api_clients.aosm_client.network_function_definition_groups.begin_create_or_update( resource_group_name=resource_group_name, @@ -303,15 +312,16 @@ def ensure_nfdg_exists( if nfdg.provisioning_state != ProvisioningState.SUCCEEDED: logger.debug( - f"Failed to provision Network Function Definition Group: {nfdg.name}" + "Failed to provision Network Function Definition Group: %s", + nfdg.name, ) raise RuntimeError( - f"Creation of Network Function Definition Group proceeded, but the provisioning" - f" state returned is {nfdg.provisioning_state}. " - f"\nAborting" - ) + "Creation of Network Function Definition Group proceeded, but the" + f" provisioning state returned is {nfdg.provisioning_state}." + " \nAborting" + ) from ex logger.debug( - f"Provisioning state of {nfdg_name}" f": {nfdg.provisioning_state}" + "Provisioning state of %s: %s", nfdg_name, nfdg.provisioning_state ) def ensure_config_nfdg_exists( @@ -354,10 +364,10 @@ def does_artifact_manifest_exist( artifact_store_name=store_name, artifact_manifest_name=manifest_name, ) - logger.debug(f"Artifact manifest {manifest_name} exists") + logger.debug("Artifact manifest %s exists", manifest_name) return True except azure_exceptions.ResourceNotFoundError: - logger.debug(f"Artifact manifest {manifest_name} does not exist") + logger.debug("Artifact manifest %s does not exist", manifest_name) return False def do_config_artifact_manifests_exist( @@ -380,12 +390,13 @@ def do_config_artifact_manifests_exist( ) if acr_manny_exists and sa_manny_exists: return True - elif acr_manny_exists or sa_manny_exists: + if acr_manny_exists or sa_manny_exists: raise AzCLIError( - "Only one artifact manifest exists. Cannot proceed. Please delete the NFDV using `az aosm nfd delete` and start the publish again from scratch." + "Only one artifact manifest exists. Cannot proceed. Please delete" + " the NFDV using `az aosm nfd delete` and start the publish again" + " from scratch." ) - else: - return False + return False return acr_manny_exists diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 5af6014d87c..febb9d70818 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -19,20 +19,20 @@ from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.util.constants import ( - CNF_DEFINITION_BICEP_TEMPLATE, - CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE, - CNF_MANIFEST_BICEP_TEMPLATE, - CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE, - CONFIG_MAPPINGS, + CNF_DEFINITION_BICEP_TEMPLATE_FILENAME, + CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE_FILENAME, + CNF_MANIFEST_BICEP_TEMPLATE_FILENAME, + CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE_FILENAME, + CONFIG_MAPPINGS_DIR_NAME, DEPLOYMENT_PARAMETER_MAPPING_REGEX, + DEPLOYMENT_PARAMETERS_FILENAME, + GENERATED_VALUES_MAPPINGS_DIR_NAME, IMAGE_NAME_AND_VERSION_REGEX, IMAGE_PATH_REGEX, - DEPLOYMENT_PARAMETERS, - GENERATED_VALUES_MAPPINGS, - SCHEMA_PREFIX, - SCHEMAS, IMAGE_PULL_SECRETS_START_STRING, IMAGE_START_STRING, + SCHEMA_PREFIX, + SCHEMAS_DIR_NAME, ) from azext_aosm.util.utils import input_ack @@ -58,17 +58,16 @@ def __init__(self, config: CNFConfiguration, interactive: bool = False): mapping file from the values.yaml in the helm package, and also requires the mapping file in config to be blank. """ - super(NFDGenerator, self).__init__() self.config = config self.nfd_jinja2_template_path = os.path.join( os.path.dirname(__file__), "templates", - CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE, + CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE_FILENAME, ) self.manifest_jinja2_template_path = os.path.join( os.path.dirname(__file__), "templates", - CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE, + CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE_FILENAME, ) self.output_folder_name = self.config.build_output_folder_name @@ -77,7 +76,7 @@ def __init__(self, config: CNFConfiguration, interactive: bool = False): self.deployment_parameter_schema = SCHEMA_PREFIX self._bicep_path = os.path.join( - self.output_folder_name, CNF_DEFINITION_BICEP_TEMPLATE + self.output_folder_name, CNF_DEFINITION_BICEP_TEMPLATE_FILENAME ) self.interactive = interactive self._tmp_folder_name = "" @@ -179,8 +178,8 @@ def _extract_chart(self, path: str) -> None: else: raise InvalidTemplateError( - f"ERROR: The helm package '{path}' is not a .tgz, .tar or .tar.gz file.\ - Please fix this and run the command again." + f"ERROR: The helm package '{path}' is not a .tgz, .tar or .tar.gz file." + " Please fix this and run the command again." ) def _generate_chart_value_mappings(self, helm_package: HelmPackageConfig) -> None: @@ -203,11 +202,11 @@ def _generate_chart_value_mappings(self, helm_package: HelmPackageConfig) -> Non ) # Write the mapping to a file - folder_name = os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS) + folder_name = os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS_DIR_NAME) os.makedirs(folder_name, exist_ok=True) mapping_filepath = os.path.join( self._tmp_folder_name, - GENERATED_VALUES_MAPPINGS, + GENERATED_VALUES_MAPPINGS_DIR_NAME, f"{helm_package.name}-generated-mapping.yaml", ) with open(mapping_filepath, "w", encoding="UTF-8") as mapping_file: @@ -254,7 +253,7 @@ def write_manifest_bicep_file(self) -> None: artifacts=self.artifacts, ) - path = os.path.join(self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE) + path = os.path.join(self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE_FILENAME) with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) @@ -269,11 +268,11 @@ def write_nfd_bicep_file(self) -> None: ) bicep_contents: str = template.render( - deployParametersPath=os.path.join(SCHEMAS, DEPLOYMENT_PARAMETERS), + deployParametersPath=os.path.join(SCHEMAS_DIR_NAME, DEPLOYMENT_PARAMETERS_FILENAME), nf_application_configurations=self.nf_application_configurations, ) - path = os.path.join(self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE) + path = os.path.join(self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE_FILENAME) with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) @@ -284,7 +283,7 @@ def write_schema_to_file(self) -> None: logger.debug("Create deploymentParameters.json") - full_schema = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS) + full_schema = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS_FILENAME) with open(full_schema, "w", encoding="UTF-8") as f: json.dump(self.deployment_parameter_schema, f, indent=4) @@ -296,16 +295,16 @@ def copy_to_output_folder(self) -> None: logger.info("Create NFD bicep %s", self.output_folder_name) os.mkdir(self.output_folder_name) - os.mkdir(os.path.join(self.output_folder_name, SCHEMAS)) + os.mkdir(os.path.join(self.output_folder_name, SCHEMAS_DIR_NAME)) # Copy the nfd and the manifest bicep files to the output folder tmp_nfd_bicep_path = os.path.join( - self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE + self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE_FILENAME ) shutil.copy(tmp_nfd_bicep_path, self.output_folder_name) tmp_manifest_bicep_path = os.path.join( - self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE + self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE_FILENAME ) shutil.copy(tmp_manifest_bicep_path, self.output_folder_name) @@ -313,21 +312,21 @@ def copy_to_output_folder(self) -> None: # the output directory so that the user can edit them and re-run the build if # required if os.path.exists( - os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS) + os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS_DIR_NAME) ): generated_mappings_path = os.path.join( - self.output_folder_name, GENERATED_VALUES_MAPPINGS + self.output_folder_name, GENERATED_VALUES_MAPPINGS_DIR_NAME ) shutil.copytree( - os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS), + os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS_DIR_NAME), generated_mappings_path, ) # Copy the JSON config mappings and deploymentParameters schema that are used # for the NFD to the output folder - tmp_config_mappings_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS) + tmp_config_mappings_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME) output_config_mappings_path = os.path.join( - self.output_folder_name, CONFIG_MAPPINGS + self.output_folder_name, CONFIG_MAPPINGS_DIR_NAME ) shutil.copytree( tmp_config_mappings_path, @@ -335,9 +334,9 @@ def copy_to_output_folder(self) -> None: dirs_exist_ok=True, ) - tmp_schema_path = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS) + tmp_schema_path = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS_FILENAME) output_schema_path = os.path.join( - self.output_folder_name, SCHEMAS, DEPLOYMENT_PARAMETERS + self.output_folder_name, SCHEMAS_DIR_NAME, DEPLOYMENT_PARAMETERS_FILENAME ) shutil.copy( tmp_schema_path, @@ -368,7 +367,8 @@ def generate_nf_application_config( "valueMappingsPath": self.jsonify_value_mappings(helm_package), } - def _find_yaml_files(self, directory) -> Iterator[str]: + @staticmethod + def _find_yaml_files(directory) -> Iterator[str]: """ Find all yaml files in given directory. @@ -428,7 +428,7 @@ def get_artifact_list( """ Get the list of artifacts for the chart. - :param helm_package: The helm package config. + :param helm_package: The helm package config. :param image_line_matches: The list of image line matches. """ artifact_list = [] @@ -466,14 +466,14 @@ def get_chart_mapping_schema( ) if not os.path.exists(mappings_path): raise InvalidTemplateError( - f"ERROR: The helm package '{helm_package.name}' does not have a valid values mappings file. \ - The file at '{helm_package.path_to_mappings}' does not exist.\n\ - Please fix this and run the command again." + f"ERROR: The helm package '{helm_package.name}' does not have a valid values" + " mappings file. The file at '{helm_package.path_to_mappings}' does not exist." + "\nPlease fix this and run the command again." ) if not os.path.exists(values_schema): raise InvalidTemplateError( - f"ERROR: The helm package '{helm_package.name}' is missing values.schema.json.\n\ - Please fix this and run the command again." + f"ERROR: The helm package '{helm_package.name}' is missing values.schema.json." + "\nPlease fix this and run the command again." ) with open(mappings_path, "r", encoding="utf-8") as stream: @@ -489,14 +489,16 @@ def get_chart_mapping_schema( new_schema = self.search_schema(deploy_params_dict, schema_data) except KeyError as e: raise InvalidTemplateError( - f"ERROR: There is a problem with your schema or values for the helm package '{helm_package.name}'. \ - Please fix this and run the command again." + "ERROR: There is a problem with your schema or values for the helm" + f" package '{helm_package.name}'." + "\nPlease fix this and run the command again." ) from e logger.debug("Generated chart mapping schema for %s", helm_package.name) return new_schema - def traverse_dict(self, d, target): + @staticmethod + def traverse_dict(d, target): """ Traverse the dictionary that is loaded from the file provided by path_to_mappings in the input.json. @@ -517,21 +519,13 @@ def traverse_dict(self, d, target): # If the value is a dictionary if isinstance(v, dict): # Add the dictionary to the stack with the path - stack.append( - (v, path + [k]) - ) + stack.append((v, path + [k])) # If the value is a string + matches target regex - elif isinstance(v, str) and re.search( - target, v - ): + elif isinstance(v, str) and re.search(target, v): # Take the match i.e, foo from {deployParameter.foo} - match = re.search( - target, v - ) + match = re.search(target, v) # Add it to the result dictionary with its path as the value - result[match.group(1)] = path + [ - k - ] + result[match.group(1)] = path + [k] elif isinstance(v, list): for i in v: if isinstance(i, str) and re.search(target, i): @@ -539,7 +533,8 @@ def traverse_dict(self, d, target): result[match.group(1)] = path + [k] return result - def search_schema(self, result, full_schema): + @staticmethod + def search_schema(result, full_schema): """ Search through provided schema for the types of the deployment parameters. This assumes that the type of the key will be the type of the deployment parameter. @@ -698,8 +693,8 @@ def get_chart_name_and_version( if not os.path.exists(chart): raise InvalidTemplateError( - f"There is no Chart.yaml file in the helm package '{helm_package.name}'. \ - Please fix this and run the command again." + f"There is no Chart.yaml file in the helm package '{helm_package.name}'. " + "\nPlease fix this and run the command again." ) with open(chart, "r", encoding="utf-8") as f: @@ -709,8 +704,9 @@ def get_chart_name_and_version( chart_version = data["version"] else: raise FileOperationError( - f"A name or version is missing from Chart.yaml in the helm package '{helm_package.name}'. \ - Please fix this and run the command again." + "A name or version is missing from Chart.yaml in the helm package" + f" '{helm_package.name}'." + "\nPlease fix this and run the command again." ) return (chart_name, chart_version) @@ -719,7 +715,7 @@ def jsonify_value_mappings(self, helm_package: HelmPackageConfig) -> str: """Yaml->JSON values mapping file, then return path to it.""" mappings_yaml = helm_package.path_to_mappings - mappings_folder_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS) + mappings_folder_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME) mappings_filename = f"{helm_package.name}-mappings.json" if not os.path.exists(mappings_folder_path): @@ -734,4 +730,4 @@ def jsonify_value_mappings(self, helm_package: HelmPackageConfig) -> str: json.dump(data, file, indent=4) logger.debug("Generated parameter mappings for %s", helm_package.name) - return os.path.join(CONFIG_MAPPINGS, mappings_filename) + return os.path.join(CONFIG_MAPPINGS_DIR_NAME, mappings_filename) diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index 3072f62394e..a57604f3009 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -3,24 +3,16 @@ # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- """Contains a base class for generating NFDs.""" +from abc import ABC from knack.log import get_logger logger = get_logger(__name__) -class NFDGenerator: +class NFDGenerator(ABC): """A class for generating an NFD from a config file.""" # pylint: disable=too-few-public-methods - def __init__( - self, - ) -> None: - """ - Superclass for NFD generators. - - The sub-classes do the actual work - """ - def generate_nfd(self) -> None: """No-op on base class.""" - logger.error("Generate NFD called on base class. No-op") + raise NotImplementedError diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index e9581a6b9a1..ec2d44a1214 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -16,16 +16,16 @@ from azext_aosm._configuration import VNFConfiguration from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator from azext_aosm.util.constants import ( - CONFIG_MAPPINGS, - DEPLOYMENT_PARAMETERS, - OPTIONAL_DEPLOYMENT_PARAMETERS_FILE, + CONFIG_MAPPINGS_DIR_NAME, + DEPLOYMENT_PARAMETERS_FILENAME, + OPTIONAL_DEPLOYMENT_PARAMETERS_FILENAME, OPTIONAL_DEPLOYMENT_PARAMETERS_HEADING, SCHEMA_PREFIX, - SCHEMAS, - TEMPLATE_PARAMETERS, - VHD_PARAMETERS, - VNF_DEFINITION_BICEP_TEMPLATE, - VNF_MANIFEST_BICEP_TEMPLATE, + SCHEMAS_DIR_NAME, + TEMPLATE_PARAMETERS_FILENAME, + VHD_PARAMETERS_FILENAME, + VNF_DEFINITION_BICEP_TEMPLATE_FILENAME, + VNF_MANIFEST_BICEP_TEMPLATE_FILENAME, ) from azext_aosm.util.utils import input_ack @@ -61,10 +61,9 @@ class VnfNfdGenerator(NFDGenerator): """ def __init__(self, config: VNFConfiguration, order_params: bool, interactive: bool): - super(NFDGenerator, self).__init__() self.config = config - self.bicep_template_name = VNF_DEFINITION_BICEP_TEMPLATE - self.manifest_template_name = VNF_MANIFEST_BICEP_TEMPLATE + self.bicep_template_name = VNF_DEFINITION_BICEP_TEMPLATE_FILENAME + self.manifest_template_name = VNF_MANIFEST_BICEP_TEMPLATE_FILENAME self.arm_template_path = self.config.arm_template.file_path self.output_folder_name = self.config.build_output_folder_name @@ -154,11 +153,11 @@ def vm_parameters_ordered(self) -> Dict[str, Any]: def create_parameter_files(self) -> None: """Create the Deployment and Template json parameter files.""" - schemas_folder_path = os.path.join(self.tmp_folder_name, SCHEMAS) + schemas_folder_path = os.path.join(self.tmp_folder_name, SCHEMAS_DIR_NAME) os.mkdir(schemas_folder_path) self.write_deployment_parameters(schemas_folder_path) - mappings_folder_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) + mappings_folder_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME) os.mkdir(mappings_folder_path) self.write_template_parameters(mappings_folder_path) self.write_vhd_parameters(mappings_folder_path) @@ -214,7 +213,7 @@ def write_deployment_parameters(self, folder_path: str) -> None: for key in vm_parameters_to_exclude: self.vm_parameters.pop(key, None) - deployment_parameters_path = os.path.join(folder_path, DEPLOYMENT_PARAMETERS) + deployment_parameters_path = os.path.join(folder_path, DEPLOYMENT_PARAMETERS_FILENAME) # Heading for the deployParameters schema deploy_parameters_full: Dict[str, Any] = SCHEMA_PREFIX @@ -234,7 +233,7 @@ def write_deployment_parameters(self, folder_path: str) -> None: if not self.interactive: if nfd_parameters_with_default: optional_deployment_parameters_path = os.path.join( - folder_path, OPTIONAL_DEPLOYMENT_PARAMETERS_FILE + folder_path, OPTIONAL_DEPLOYMENT_PARAMETERS_FILENAME ) with open( optional_deployment_parameters_path, "w", encoding="utf-8" @@ -243,7 +242,7 @@ def write_deployment_parameters(self, folder_path: str) -> None: _file.write(json.dumps(nfd_parameters_with_default, indent=4)) print( "Optional ARM parameters detected. Created " - f"{OPTIONAL_DEPLOYMENT_PARAMETERS_FILE} to help you choose which " + f"{OPTIONAL_DEPLOYMENT_PARAMETERS_FILENAME} to help you choose which " "to expose." ) @@ -253,7 +252,7 @@ def write_template_parameters(self, folder_path: str) -> None: :param folder_path: The folder to put this file in. """ - logger.debug("Create %s", TEMPLATE_PARAMETERS) + logger.debug("Create %s", TEMPLATE_PARAMETERS_FILENAME) vm_parameters = ( self.vm_parameters_ordered if self.order_params else self.vm_parameters ) @@ -267,7 +266,7 @@ def write_template_parameters(self, folder_path: str) -> None: template_parameters[key] = f"{{deployParameters.{key}}}" - template_parameters_path = os.path.join(folder_path, TEMPLATE_PARAMETERS) + template_parameters_path = os.path.join(folder_path, TEMPLATE_PARAMETERS_FILENAME) with open(template_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(template_parameters, indent=4)) @@ -294,7 +293,7 @@ def write_vhd_parameters(self, folder_path: str) -> None: "azureDeployLocation": azureDeployLocation, } - vhd_parameters_path = os.path.join(folder_path, VHD_PARAMETERS) + vhd_parameters_path = os.path.join(folder_path, VHD_PARAMETERS_FILENAME) with open(vhd_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(vhd_parameters, indent=4)) diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index 3f365d4cbb6..a6f4dd62006 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -13,24 +13,23 @@ from jinja2 import Template from knack.log import get_logger -from azext_aosm.vendored_sdks.models import NFVIType from azext_aosm._configuration import NSConfiguration from azext_aosm.util.constants import ( - CONFIG_MAPPINGS, - NF_DEFINITION_BICEP_FILE, - NF_TEMPLATE_BICEP_FILE, - NSD_ARTIFACT_MANIFEST_BICEP_FILE, - NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE, - NSD_CONFIG_MAPPING_FILE, - NSD_DEFINITION_BICEP_FILE, - NSD_DEFINITION_BICEP_SOURCE_TEMPLATE, - SCHEMAS, - TEMPLATES, + CONFIG_MAPPINGS_DIR_NAME, + NF_DEFINITION_BICEP_FILENAME, + NF_TEMPLATE_BICEP_FILENAME, + NSD_ARTIFACT_MANIFEST_BICEP_FILENAME, + NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE_FILENAME, + NSD_CONFIG_MAPPING_FILENAME, + NSD_BICEP_FILENAME, + NSD_SOURCE_TEMPLATE_BICEP_FILENAME, + SCHEMAS_DIR_NAME, + TEMPLATES_DIR_NAME, VNF, ) from azext_aosm.util.management_clients import ApiClients -from azext_aosm.vendored_sdks.models import NetworkFunctionDefinitionVersion +from azext_aosm.vendored_sdks.models import NetworkFunctionDefinitionVersion, NFVIType logger = get_logger(__name__) @@ -59,12 +58,12 @@ class NSDGenerator: def __init__(self, api_clients: ApiClients, config: NSConfiguration): self.config = config - self.nsd_bicep_template_name = NSD_DEFINITION_BICEP_SOURCE_TEMPLATE - self.nf_bicep_template_name = NF_TEMPLATE_BICEP_FILE - self.nsd_bicep_output_name = NSD_DEFINITION_BICEP_FILE - self.nfdv_parameter_name = \ + self.nsd_bicep_template_name = NSD_SOURCE_TEMPLATE_BICEP_FILENAME + self.nf_bicep_template_name = NF_TEMPLATE_BICEP_FILENAME + self.nsd_bicep_output_name = NSD_BICEP_FILENAME + self.nfdv_parameter_name = ( f"{self.config.network_function_definition_group_name.replace('-', '_')}_nfd_version" - + ) self.build_folder_name = self.config.build_output_folder_name nfdv = self._get_nfdv(config, api_clients) print("Finding the deploy parameters of the NFDV resource") @@ -72,7 +71,9 @@ def __init__(self, api_clients: ApiClients, config: NSConfiguration): raise NotImplementedError( "NFDV has no deploy parameters, cannot generate NSD." ) - self.deploy_parameters: Optional[Dict[str, Any]] = json.loads(nfdv.deploy_parameters) + self.deploy_parameters: Optional[Dict[str, Any]] = json.loads( + nfdv.deploy_parameters + ) def _get_nfdv( self, config: NSConfiguration, api_clients @@ -129,12 +130,14 @@ def config_group_schema_dict(self) -> Dict[str, Any]: # Add in the NFDV version as a parameter. description_string = ( f"The version of the {self.config.network_function_definition_group_name} " - f"NFD to use. This version must be compatable with (have the same " - f"parameters exposed as) " + "NFD to use. This version must be compatable with (have the same " + "parameters exposed as) " f"{self.config.network_function_definition_version_name}." ) - cgs_dict["properties"][self.nfdv_parameter_name] = \ - {"type": "string", "description": description_string} + cgs_dict["properties"][self.nfdv_parameter_name] = { + "type": "string", + "description": description_string, + } managed_identity_description_string = ( "The managed identity to use to deploy NFs within this SNS. This should " @@ -144,18 +147,22 @@ def config_group_schema_dict(self) -> Dict[str, Any]: "The az aosm tool only supports user assigned identities at present, " "you cannot use a System Assigned identity." ) - cgs_dict["properties"]["managedIdentity"] = \ - {"type": "string", "description": managed_identity_description_string} + cgs_dict["properties"]["managedIdentity"] = { + "type": "string", + "description": managed_identity_description_string, + } return cgs_dict def create_config_group_schema_files(self) -> None: """Create the Schema and configMappings json files.""" - temp_schemas_folder_path = os.path.join(self.tmp_folder_name, SCHEMAS) + temp_schemas_folder_path = os.path.join(self.tmp_folder_name, SCHEMAS_DIR_NAME) os.mkdir(temp_schemas_folder_path) self.write_schema(temp_schemas_folder_path) - temp_mappings_folder_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS) + temp_mappings_folder_path = os.path.join( + self.tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME + ) os.mkdir(temp_mappings_folder_path) self.write_config_mappings(temp_mappings_folder_path) @@ -165,14 +172,14 @@ def write_schema(self, folder_path: str) -> None: :param folder_path: The folder to put this file in. """ - logger.debug(f"Create {self.config.cg_schema_name}.json") + logger.debug("Create %s.json", self.config.cg_schema_name) schema_path = os.path.join(folder_path, f"{self.config.cg_schema_name}.json") with open(schema_path, "w") as _file: _file.write(json.dumps(self.config_group_schema_dict, indent=4)) - logger.debug(f"{schema_path} created") + logger.debug("%s created", schema_path) def write_config_mappings(self, folder_path: str) -> None: """ @@ -188,12 +195,12 @@ def write_config_mappings(self, folder_path: str) -> None: for key in deploy_properties } - config_mappings_path = os.path.join(folder_path, NSD_CONFIG_MAPPING_FILE) + config_mappings_path = os.path.join(folder_path, NSD_CONFIG_MAPPING_FILENAME) with open(config_mappings_path, "w") as _file: _file.write(json.dumps(config_mappings, indent=4)) - logger.debug(f"{config_mappings_path} created") + logger.debug("%s created", config_mappings_path) def write_nf_bicep(self) -> None: """Write out the Network Function bicep file.""" @@ -201,7 +208,6 @@ def write_nf_bicep(self) -> None: bicep_deploymentValues = "" - if "properties" not in self.deploy_parameters: raise ValueError( f"NFDV in {self.config.network_function_definition_group_name} has " @@ -221,22 +227,30 @@ def write_nf_bicep(self) -> None: self.generate_bicep( self.nf_bicep_template_name, - NF_DEFINITION_BICEP_FILE, + NF_DEFINITION_BICEP_FILENAME, { "bicep_params": bicep_params, "deploymentValues": bicep_deploymentValues, "network_function_name": self.config.network_function_name, "publisher_name": self.config.publisher_name, - "network_function_definition_group_name": self.config.network_function_definition_group_name, - "network_function_definition_version_parameter": self.nfdv_parameter_name, - "network_function_definition_offering_location": self.config.network_function_definition_offering_location, + "network_function_definition_group_name": ( + self.config.network_function_definition_group_name + ), + "network_function_definition_version_parameter": ( + self.nfdv_parameter_name + ), + "network_function_definition_offering_location": ( + self.config.network_function_definition_offering_location + ), "location": self.config.location, # Ideally we would use the network_function_type from reading the actual # NF, as we do for deployParameters, but the SDK currently doesn't # support this and needs to be rebuilt to do so. - "nfvi_type": NFVIType.AZURE_CORE - if self.config.network_function_type == VNF - else NFVIType.AZURE_ARC_KUBERNETES.value, + "nfvi_type": ( + NFVIType.AZURE_CORE + if self.config.network_function_type == VNF + else NFVIType.AZURE_ARC_KUBERNETES.value + ), }, ) @@ -260,7 +274,9 @@ def write_nsd_manifest(self) -> None: logger.debug("Create NSD manifest") self.generate_bicep( - NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE, NSD_ARTIFACT_MANIFEST_BICEP_FILE, {} + NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE_FILENAME, + NSD_ARTIFACT_MANIFEST_BICEP_FILENAME, + {}, ) def generate_bicep(self, template_name, output_file_name, params) -> None: @@ -274,7 +290,7 @@ def generate_bicep(self, template_name, output_file_name, params) -> None: code_dir = os.path.dirname(__file__) - bicep_template_path = os.path.join(code_dir, TEMPLATES, template_name) + bicep_template_path = os.path.join(code_dir, TEMPLATES_DIR_NAME, template_name) with open(bicep_template_path, "r") as file: bicep_contents = file.read() @@ -291,7 +307,6 @@ def generate_bicep(self, template_name, output_file_name, params) -> None: def copy_to_output_folder(self) -> None: """Copy the bicep templates, config mappings and schema into the build output folder.""" - code_dir = os.path.dirname(__file__) logger.info("Create NSD bicep %s", self.build_folder_name) os.mkdir(self.build_folder_name) diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 7b3087f870e..960463db610 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -11,42 +11,42 @@ SCHEMA = "schema" # Names of files used in the repo -NSD_DEFINITION_BICEP_SOURCE_TEMPLATE = "nsd_template.bicep" -NSD_DEFINITION_BICEP_FILE = "nsd_definition.bicep" -NF_TEMPLATE_BICEP_FILE = "nf_template.bicep" -NF_DEFINITION_BICEP_FILE = "nf_definition.bicep" -NF_DEFINITION_JSON_FILE = "nf_definition.json" -NSD_DEFINITION_OUTPUT_BICEP_PREFIX = "nsd-bicep-templates" -NSD_ARTIFACT_MANIFEST_BICEP_FILE = "artifact_manifest.bicep" -NSD_ARTIFACT_MANIFEST_JSON_FILE = "artifact_manifest.json" -DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" -NSD_CONFIG_MAPPING_FILE = "configMappings.json" -NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE = "artifact_manifest_template.bicep" +NF_TEMPLATE_BICEP_FILENAME = "nf_template.bicep" +NF_DEFINITION_BICEP_FILENAME = "nf_definition.bicep" +NF_DEFINITION_JSON_FILENAME = "nf_definition.json" +NF_DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" +NSD_SOURCE_TEMPLATE_BICEP_FILENAME = "nsd_template.bicep" +NSD_BICEP_FILENAME = "nsd_definition.bicep" +NSD_OUTPUT_BICEP_PREFIX = "nsd-bicep-templates" +NSD_ARTIFACT_MANIFEST_BICEP_FILENAME = "artifact_manifest.bicep" +NSD_ARTIFACT_MANIFEST_JSON_FILENAME = "artifact_manifest.json" +NSD_CONFIG_MAPPING_FILENAME = "configMappings.json" +NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE_FILENAME = "artifact_manifest_template.bicep" -VNF_DEFINITION_BICEP_TEMPLATE = "vnfdefinition.bicep" -VNF_MANIFEST_BICEP_TEMPLATE = "vnfartifactmanifests.bicep" +VNF_DEFINITION_BICEP_TEMPLATE_FILENAME = "vnfdefinition.bicep" +VNF_MANIFEST_BICEP_TEMPLATE_FILENAME = "vnfartifactmanifests.bicep" -CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE = "cnfdefinition.bicep.j2" -CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE = "cnfartifactmanifest.bicep.j2" -CNF_DEFINITION_BICEP_TEMPLATE = "cnfdefinition.bicep" -CNF_MANIFEST_BICEP_TEMPLATE = "cnfartifactmanifest.bicep" +CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE_FILENAME = "cnfdefinition.bicep.j2" +CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE_FILENAME = "cnfartifactmanifest.bicep.j2" +CNF_DEFINITION_BICEP_TEMPLATE_FILENAME = "cnfdefinition.bicep" +CNF_MANIFEST_BICEP_TEMPLATE_FILENAME = "cnfartifactmanifest.bicep" -# Names of folder used in the repo -CONFIG_MAPPINGS = "configMappings" -SCHEMAS = "schemas" -TEMPLATES = "templates" -GENERATED_VALUES_MAPPINGS = "generatedValuesMappings" +# Names of directories used in the repo +CONFIG_MAPPINGS_DIR_NAME = "configMappings" +SCHEMAS_DIR_NAME = "schemas" +TEMPLATES_DIR_NAME = "templates" +GENERATED_VALUES_MAPPINGS_DIR_NAME = "generatedValuesMappings" -# Names of files when building NFDs/NSDs -DEPLOYMENT_PARAMETERS = "deploymentParameters.json" -OPTIONAL_DEPLOYMENT_PARAMETERS_FILE = "optionalDeploymentParameters.txt" -TEMPLATE_PARAMETERS = "templateParameters.json" -VHD_PARAMETERS = "vhdParameters.json" +# Items used when building NFDs/NSDs +DEPLOYMENT_PARAMETERS_FILENAME = "deploymentParameters.json" +OPTIONAL_DEPLOYMENT_PARAMETERS_FILENAME = "optionalDeploymentParameters.txt" +TEMPLATE_PARAMETERS_FILENAME = "templateParameters.json" +VHD_PARAMETERS_FILENAME = "vhdParameters.json" OPTIONAL_DEPLOYMENT_PARAMETERS_HEADING = ( "# The following parameters are optional as they have default values.\n" "# If you do not wish to expose them in the NFD, find and remove them from both\n" - f"# {DEPLOYMENT_PARAMETERS} and {TEMPLATE_PARAMETERS} (and {VHD_PARAMETERS} if\n" + f"# {DEPLOYMENT_PARAMETERS_FILENAME} and {TEMPLATE_PARAMETERS_FILENAME} (and {VHD_PARAMETERS_FILENAME} if\n" "they are there)\n" "# You can re-run the build command with the --order-params flag to order those\n" "# files with the optional parameters at the end of the file, and with the \n" @@ -54,7 +54,6 @@ ) # Deployment Schema - SCHEMA_PREFIX = { "$schema": "https://json-schema.org/draft-07/schema#", "title": "DeployParametersSchema", @@ -67,7 +66,7 @@ IMAGE_START_STRING = "image:" IMAGE_PATH_REGEX = r".Values\.([^\s})]*)" -# To match the image name and version if imagePullSecrets: is present in the yaml file +# To match the image name and version if 'imagePullSecrets:' is present in the yaml file IMAGE_PULL_SECRETS_START_STRING = "imagePullSecrets:" IMAGE_NAME_AND_VERSION_REGEX = r"\/([^\s]*):([^\s)\"}]*)" diff --git a/src/aosm/azext_aosm/util/management_clients.py b/src/aosm/azext_aosm/util/management_clients.py index 132f6feed69..fff9aa5c0a9 100644 --- a/src/aosm/azext_aosm/util/management_clients.py +++ b/src/aosm/azext_aosm/util/management_clients.py @@ -4,27 +4,22 @@ # -------------------------------------------------------------------------------------------- """Clients for the python SDK along with useful caches.""" +from dataclasses import dataclass +from typing import Optional + +from azure.mgmt.containerregistry import ContainerRegistryManagementClient from azure.mgmt.resource import ResourceManagementClient from knack.log import get_logger from azext_aosm.vendored_sdks import HybridNetworkManagementClient -from azure.mgmt.containerregistry import ContainerRegistryManagementClient -from typing import Optional - logger = get_logger(__name__) +@dataclass class ApiClients: """A class for API Clients needed throughout.""" - def __init__( - self, - aosm_client: HybridNetworkManagementClient, - resource_client: ResourceManagementClient, - container_registry_client: Optional[ContainerRegistryManagementClient] = None, - ): - """Initialise with clients.""" - self.aosm_client = aosm_client - self.resource_client = resource_client - self.container_registry_client = container_registry_client + aosm_client: HybridNetworkManagementClient + resource_client: ResourceManagementClient + container_registry_client: Optional[ContainerRegistryManagementClient] = None diff --git a/src/aosm/setup.md b/src/aosm/setup.md index 8e73437afa1..b38bd52d039 100644 --- a/src/aosm/setup.md +++ b/src/aosm/setup.md @@ -44,6 +44,8 @@ azdev linter --include-whl-extensions aosm (Not written any tests yet) azdev test aosm ``` +The standard Python tool, `black`, is useful for automatically formatting your code. + You can use python-static-checks in your dev environment if you want, to help you: ```bash pip3 install -U --index-url https://pkgs.dev.azure.com/msazuredev/AzureForOperators/_packaging/python/pypi/simple/ python-static-checks==4.0.0 diff --git a/src/aosm/setup.py b/src/aosm/setup.py index 47149f957cb..807c81eb801 100644 --- a/src/aosm/setup.py +++ b/src/aosm/setup.py @@ -6,8 +6,7 @@ # -------------------------------------------------------------------------------------------- -from codecs import open -from setuptools import setup, find_packages +from setuptools import find_packages, setup try: from azure_bdist_wheel import cmdclass From 31672ae3ee7c9966b452eb5a5c95566c76be677c Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Fri, 30 Jun 2023 10:44:41 +0100 Subject: [PATCH 120/145] Add CNF UTs that will fail at the moment --- .../helm-charts/nf-agent-cnf-0.1.0.tgz | Bin 0 -> 5234 bytes .../helm-charts/nf-agent-cnf/.helmignore | 23 +++ .../helm-charts/nf-agent-cnf/Chart.yaml | 24 +++ .../nf-agent-cnf/templates/NOTES.txt | 22 ++ .../nf-agent-cnf/templates/_helpers.tpl | 62 ++++++ .../nf-agent-cnf/templates/deployment.yaml | 71 +++++++ .../nf-agent-cnf/templates/hpa.yaml | 28 +++ .../nf-agent-cnf/templates/ingress.yaml | 61 ++++++ .../templates/nf-agent-config-map.yaml | 27 +++ .../nf-agent-cnf/templates/service.yaml | 15 ++ .../templates/serviceaccount.yaml | 12 ++ .../templates/tests/test-connection.yaml | 15 ++ .../nf-agent-cnf/values.mappings.yaml | 89 ++++++++ .../nf-agent-cnf/values.schema.json | 193 ++++++++++++++++++ .../helm-charts/nf-agent-cnf/values.yaml | 92 +++++++++ .../helm-charts/nfconfigchart-0.1.0.tgz | Bin 0 -> 4630 bytes .../helm-charts/nfconfigchart/.helmignore | 22 ++ .../helm-charts/nfconfigchart/Chart.yaml | 6 + .../nfconfigchart/configmap/default.conf | 38 ++++ .../nfconfigchartvalues.mappings.yaml | 69 +++++++ .../nfconfigchart/templates/NOTES.txt | 21 ++ .../nfconfigchart/templates/_helpers.tpl | 56 +++++ .../nfconfigchart/templates/deployment.yaml | 68 ++++++ .../nfconfigchart/templates/ingress.yaml | 41 ++++ .../templates/nginx_config_map.yaml | 56 +++++ .../nfconfigchart/templates/service.yaml | 16 ++ .../templates/serviceaccount.yaml | 8 + .../templates/tests/test-connection.yaml | 15 ++ .../nfconfigchart/values.schema.json | 134 ++++++++++++ .../helm-charts/nfconfigchart/values.yaml | 70 +++++++ .../latest/mock_cnf/input-nfconfigchart.json | 18 ++ ...fig_file.json => invalid_config_file.json} | 0 32 files changed, 1372 insertions(+) create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf-0.1.0.tgz create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/.helmignore create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/Chart.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/NOTES.txt create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/_helpers.tpl create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/deployment.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/hpa.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/ingress.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/nf-agent-config-map.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/service.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/serviceaccount.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/tests/test-connection.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.mappings.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.schema.json create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart-0.1.0.tgz create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/.helmignore create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/Chart.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/configmap/default.conf create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/nfconfigchartvalues.mappings.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/NOTES.txt create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/_helpers.tpl create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/deployment.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/ingress.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/nginx_config_map.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/service.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/serviceaccount.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/tests/test-connection.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/values.schema.json create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/values.yaml create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/input-nfconfigchart.json rename src/aosm/azext_aosm/tests/latest/mock_cnf/{config_file.json => invalid_config_file.json} (100%) diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf-0.1.0.tgz b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf-0.1.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..679c20fddcf4562cdc8396fe0d6f3c5be2092d4d GIT binary patch literal 5234 zcmV-&6pia2iwG0|00000|0w_~VMtOiV@ORlOnEsqVl!4SWK%V1T2nbTPgYhoO;>Dc zVQyr3R8em|NM&qo0PH<~bK5ws`?o#?p3|GQd$lYlZratGzMEXq+s(T+%{1M;x!Kw2 z&=PF3kw_g$IrVz;KKmPz`fVw86E|(|%s&!a0s#;tK@bFJHtCZoGSv^*WNJQQW(O7MyLT!Fo=jim=i(C zI6?`E!x$kUQep^{DGm#s3Q!m)5m6{z#}R1M!ZA;o@?q#WG$vE@9RPs|msD}F@Ij`G zErN(9>DYW^6T=z_#C{k)JtP?JA0E2o_f%jYT*@7QB#okT9?@Xo!|CLVt8;-8nQ{R3 z;LRL`prK}QhG0m7B2&1UafuLS!l3rG)pMm%bRE#ZKJ=bH`{8hZ)XSJYPowAp1A$8V z@au0z73PF|==GdQ8bvD)9f@L213U@>BLl<7$J%jp8&ClsDvpp6q;j5C1q2CIG0T^I2-`GmS`CzJUnV}r=MM5 zkP506$DAqrs0ywp@<+kb#D{&)^R$H9!2*(yF^#CAD6QN9Lcx>#b03agy)vH#lJE_S z7H>IMf1?q~g;W?<*=EPsUGF2MB!RZN+QXD zGCfNqO3f+@?0=!89yq`mAe&RcnU;`*E2?G?QKh16aOJE#0htCfP5w1yRClMVC*y*r z5OTO8tk#lBwUpV`Dmw*v6!9y{rUrXNnFb-@hg6#Pu_nMUKq-k>JTdJT7<1Elgdi2s z0>*+E*-R7)cvy=1p_?I%Y1v0XlA3uDXWwItjkX`|KYvZLCjKi$xoHiDq>9UcM3hZi zCr(V+Tf5#!z19H41rwWWBZm7krgzy9VpWHOt!#d#{$xS|^g)jMDZiS3n9zB$Ncoim zKtp88RP#o|aJ-M>{=p%7{n369_DL{2=z9kQpW_cdJPShIR>cz<_#kPVM5YP3UQc*f zV1vFH__dcZf$j62551XEi9ZgKy%nfN>rAD}Dz+XoWeTS#HpE;mm|Mnt^D=uEV$Kbu zHyRAhZQAOH$gxNz^oVK2Vzz{zbug7X-1XvWa@rvuQ>WZ`Zx^p3tCMSUgm>=N<{o{u zZ>Yk!L)L^X-b{MgmSjC2L>fr1NHLr`L3HUxP$K%|POMd5Gmu*A=+~FE4Yoj;nUbz z-#@L@HtVyt@@a%hf_LiMR+P8s?{+*y&F+K&ZaXg8%7$a5m51CH^%b?|RyA)agSEsHr}#(Uw-L?Q(i&i|+15dgg8W ztj1XGTHCH=Q#c2=Y@_pp24B)juR2V>uv4IZ==9~8X`FU_VTP&)x80L(Wt(0{ksS|w z;iky1O0d}x;pcT7aM5kU-_oITlM!_filcsvzS~~c>e#dREpLO_-L~s@?(xb=+I{+R zoC@#?pV!~yVOZ__r-;rOoV|JX^1@Xg)i!9XiT^q{7&YU+o(@O*yYrv>C_@*1L>mN9 z3Dbn1-@bzJ0z}GK7N#Q+0v^YNh0=GH%RbNvxWCu~!#u(y^SQzGwSf?XO%Wcm(qxA^d*UP$5W&B@F6=WpJ=d-34WWje+{MKDDL z{eEGkgJ$F{Mo1*OXT{U&Yv^wK_2UMAr{@jsG;Vn-9*u6*>`6sbDqRwWxvJ*=xJ;q*L< zOeAwcBRyK(s_OqIPaz--u80a|HtNl^6ZoV$9UgviSIc<-{i{to@L}137cbxba(dj- zhX&&&q&K7q{eG_gp|@Q2mdk8LKB6qdkC69xR1s%B9l?8SCY)<#ot;~~>y~j)w#L`| zHoDg|xN}w(;c^>H%kwuU@6V22zih}X;o+vkK7t-e61N^8rz^hblxHc+C#zK{lS<3% zMU$i!Rp%^=QIU`+VsK~jv@JY-bN24&^z7x^Htmz}aI!o?L4VTFB7!+%g0 zN>$N+>1Fn-EgkmX`x!V0ZODSfWrgxk;WJ4WI{heuitCf zXpUj=*oKsof`VSX7Vxi>M07$i)JnxL?>hfLi`&2}O+hzA!WaXhb&%vSR`Ql?lP46T zPy!KXBULermZuUPjTc57CubKLRvQ3XJwA4w(+LQxq%4wRv9fssHt1c!6^$ZobEH!9 zDYc!FMp4G?&C)H`=v=}Tv%49sk_)c${U$=!>u&b>foXvMV)I@tc`QU>ku;Y)%V+K3 zCo-1^%G3mUf0F$_$zB7OCA#?-YyVgqd6h2Jb0y1T)7@#hH5(%qDk5Wy)^)7`E&H|E zo~o$r=PU;W{s4hVq}RjVpL@`I-~05*#N(JV%cfkzrUkNm&M=ByIU5+({cg)LYnp3` zcL2%E)&D9Z;8sRY*5acg@kYN}HL8kaLTxUrRQUt`m2!m*39Mp?2_sVs`{RXQvpX)b zgqJo6=I0cf$*|efek&g~=Vb%)vZZcrUivGR(@kT#sqouVeAYIu>U}-yQdV^^H%k#} zEE|v3?o=LkA!OCIR`f)Ux|e-e**&x(SkVPvdY%4UrNjOUF^TvhMz)P~@OAm0`_J~9 z_TST|2Rr-kK1wzJn}q|E~~k=%O%9ARPXq? zK&2M{D>;Kl3I!u#0goao6_hJRvpPJ|BmGoDkFq(5XxQrnef+p=?COGd!+dC49o;If zdVXqaua={t5eLxT8Kv8%nu}S?+p1-GT|J8Hp_CQ_wyvUJioeu@N*c$6HTPDHO4CnSua^j}c)%kc z-W{J;-t9p|=g3gXbHT^x*IwB}jvrAqA45y>>|W8D6~=9zGX2a{%B0S9W24NK?H(0# z9;Gq9*7KsHce26I4>+69Y2Q|8h&|Tz&uuGE1%rI{4QwT2zBH=HbZjfEf>;tQ6K5SO z_W5g))LYV4xl8L;6&s=|;0jDusd^_tSEUjrtAt9>pemyF z?z}neGFP$v>~fN~*#hp=SN>90TY&^gT0F4?j^-%H6e~nJo3a^4jRj_H3valX;g*fG zS54ftog47=1zb-Z`ah4e*~%KQ_WrM@!t`jM*aW4?#4xRM^ti2OS)R_In7EzrB+Hl`GE`SwTx#ug`P`nh3~O;YZRAEZ5SFY`<}M$H;^lCypDa(XvI(2@P@9LGIyITmUxEtxV(3)>ULS7x$0Q$P%t)t zGrR7q5JDCM+69|mLe|(aX0>o&@+8czOqS~4M68jn%f`uRGzQoVXy*~-<~ z20Ub-g~M_Uxu(2ZEbRZB1JM8Q(qaFXkFCEmCduvh0&DF5eXn``yYCIX(a!$Ak5aq; zJ9p$9=g#aF%c&%JD%8+-HW4( zcl;9Bj~wMsDDXvowb5BI$v_IC!szeVX-|8pnJefa;pr_Wa7{||Qlzk4aI>wgyc`ZXNfsA3D*ne$Z% z@91Z73u}WmtV{m98RXCw!%+(qsfUT(E^cb{HEpMEp8r`O@Ez5_+W9|h#(zH3|912L z9?C{h+D+eUQ&D8#pQ0~rh>P34C$`b5Ejnbsc?U_y{8uQI{i`>649#}rwrXJA{6B2Y z|9$Upw2S|~m(n_|&w1D~mwOv7{{61|_9uT0Tio{Ti({IchRCR$hx%@Ei;itlQQ zsv1k|!#I_TG5=VE&YBx8eE9XD27Q=c6GOyQ>W3Rj;D+ROgHoU#bSe*IJ;OPQFQh+e z^WW7nwfnqn(pbCxA3R<8{jc5q|Mye&;G8Ih!up!BJ^s}U8H`gJg(ftg1eaurviK!1 znI^{O206nhf@#FZHe{&IW)Ar;bbr&JBhU(3GZj(-;e^EZDmn-27! z{HvU^L5XNgg3B~9PD$x}@5-yh`Q9CqOXqu6#riWBbn1Nnf6gBKLImZhgwvCk(s2{P zKVYC7mxf3N7F_TTjysnD4{`7Z< s*r9zzBzveJCSm1%Ju?J%KRmcAyRs|0^0k%!4*&rF|D$UPvjBtu0FxAJdjJ3c literal 0 HcmV?d00001 diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/.helmignore b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/.helmignore new file mode 100644 index 00000000000..0e8a0eb36f4 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/Chart.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/Chart.yaml new file mode 100644 index 00000000000..275ab10e2e2 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: nf-agent-cnf +description: A Helm chart for Kubernetes + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/NOTES.txt b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/NOTES.txt new file mode 100644 index 00000000000..238eb9aa2f6 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "nf-agent-cnf.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "nf-agent-cnf.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "nf-agent-cnf.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "nf-agent-cnf.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/_helpers.tpl b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/_helpers.tpl new file mode 100644 index 00000000000..1a8d7653757 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "nf-agent-cnf.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "nf-agent-cnf.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "nf-agent-cnf.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "nf-agent-cnf.labels" -}} +helm.sh/chart: {{ include "nf-agent-cnf.chart" . }} +{{ include "nf-agent-cnf.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "nf-agent-cnf.selectorLabels" -}} +app.kubernetes.io/name: {{ include "nf-agent-cnf.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "nf-agent-cnf.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "nf-agent-cnf.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/deployment.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/deployment.yaml new file mode 100644 index 00000000000..90bae35f548 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/deployment.yaml @@ -0,0 +1,71 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "nf-agent-cnf.fullname" . }} + labels: + {{- include "nf-agent-cnf.labels" . | nindent 4 }} +spec: + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} + selector: + matchLabels: + {{- include "nf-agent-cnf.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "nf-agent-cnf.selectorLabels" . | nindent 8 }} + #aadpodidbinding: {{ .Values.nfagent.podIdentity }} - not using podidentity any more + spec: + # Copied imagePullSecrets from how afosas-aosm repo does it + imagePullSecrets: {{ mustToPrettyJson (ternary (list ) .Values.imagePullSecrets (kindIs "invalid" .Values.imagePullSecrets)) }} + serviceAccountName: {{ include "nf-agent-cnf.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + # Edited the image to point to the nf-agent image in the Artifact Store ACR + image: "{{ .Values.image.repository }}/pez-nfagent:879624" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + # Commented out otherwise kubernetes keeps restarting the pod thinking the probes have failed + # livenessProbe: + # httpGet: + # path: / + # port: http + # readinessProbe: + # httpGet: + # path: / + # port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + # Gets the NF Agent config from the configMap - see nf-agent-config-map.yaml + volumeMounts: + - name: nfagent-config-volume + mountPath: /etc/nf-agent/config.yaml + subPath: config.yaml + volumes: + - name: nfagent-config-volume + configMap: + name: nfagent-config + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/hpa.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/hpa.yaml new file mode 100644 index 00000000000..ae24cfc1704 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "nf-agent-cnf.fullname" . }} + labels: + {{- include "nf-agent-cnf.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "nf-agent-cnf.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/ingress.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/ingress.yaml new file mode 100644 index 00000000000..9fc4d315aed --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/ingress.yaml @@ -0,0 +1,61 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "nf-agent-cnf.fullname" . -}} +{{- $svcPort := .Values.service.port -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "nf-agent-cnf.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/nf-agent-config-map.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/nf-agent-config-map.yaml new file mode 100644 index 00000000000..8c2f5e6f823 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/nf-agent-config-map.yaml @@ -0,0 +1,27 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: nfagent-config +data: + config.yaml: | + # Example NF Agent config file. + # Config is read from /etc/nf-agent/config.yaml. + log_level: debug + service_bus: + # Using a namespace and Managed Identity (specified by client ID) for auth. + namespace: {{ .Values.nfagent.namespace }} + # Helm uses sprig for templating, so we can use sprig functions to find just the UID from the full Managed Identity ID path. + identity: {{ (splitList "/" .Values.nfagent.identity) | last }} + # Alternatively can use a connstring instead of namespace + managed identity: + # connstring: "Endpoint=sb://contoso.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=TopSecretSASTokenGoesHere=" + subscriptions: + - topic: {{ .Values.nfagent.topic }} + subscription: {{ .Values.nfagent.topic }}-subscription + # Handler-specific config + handler_config: + simpl: + # The endpoint is constructed from the namespace and service name of the receiving thing. + # We couldn't get AOSM to install the service to listen on anything but port 80 + # Doh - that was because we changed values.yaml in the chart but didn't change values.mappings.yaml in the NFDV + # Changing values.mappings.yaml should make this work on port 5222 as expected. + endpoint: http://nfconfigchart.nfconfigchart.svc.cluster.local:80 # DevSkim: ignore DS162092 diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/service.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/service.yaml new file mode 100644 index 00000000000..ed537a4e61c --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "nf-agent-cnf.fullname" . }} + labels: + {{- include "nf-agent-cnf.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "nf-agent-cnf.selectorLabels" . | nindent 4 }} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/serviceaccount.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/serviceaccount.yaml new file mode 100644 index 00000000000..e19c3c09fbc --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "nf-agent-cnf.serviceAccountName" . }} + labels: + {{- include "nf-agent-cnf.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/tests/test-connection.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/tests/test-connection.yaml new file mode 100644 index 00000000000..309ea5078a2 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "nf-agent-cnf.fullname" . }}-test-connection" + labels: + {{- include "nf-agent-cnf.labels" . | nindent 4 }} + annotations: + "helm.sh/hook": test +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "nf-agent-cnf.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.mappings.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.mappings.yaml new file mode 100644 index 00000000000..eef4e074f8b --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.mappings.yaml @@ -0,0 +1,89 @@ +# Default values for nf-agent-cnf. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: sunnyclipubsunnynfagentacre00abc1832.azurecr.io + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "879624" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 80 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +nfagent: + namespace: "{deployParameters.nfAgentServiceBusNamespace}" + identity: "{deployParameters.nfAgentUserAssignedIdentityResourceId}" + topic: "{deployParameters.nfagent_topic}" # ??? This wasn't made available to simpl + # name of pod identity - not using this any more + # podIdentity: mypeapod diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.schema.json b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.schema.json new file mode 100644 index 00000000000..5207b19a8df --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.schema.json @@ -0,0 +1,193 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "additionalProperties": true, + "properties": { + "affinity": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "autoscaling": { + "additionalProperties": false, + "properties": { + "enabled": { + "type": "boolean" + }, + "maxReplicas": { + "type": "integer" + }, + "minReplicas": { + "type": "integer" + }, + "targetCPUUtilizationPercentage": { + "type": "integer" + } + }, + "type": "object" + }, + "fullnameOverride": { + "type": "string" + }, + "image": { + "additionalProperties": false, + "properties": { + "pullPolicy": { + "type": "string" + }, + "repository": { + "type": "string" + }, + "tag": { + "type": "string" + } + }, + "type": "object" + }, + "imagePullSecrets": { + "items": { + "anyOf": [] + }, + "type": "array" + }, + "ingress": { + "additionalProperties": false, + "properties": { + "annotations": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "className": { + "type": "string" + }, + "enabled": { + "type": "boolean" + }, + "hosts": { + "items": { + "anyOf": [ + { + "additionalProperties": false, + "properties": { + "host": { + "type": "string" + }, + "paths": { + "items": { + "anyOf": [ + { + "additionalProperties": false, + "properties": { + "path": { + "type": "string" + }, + "pathType": { + "type": "string" + } + }, + "type": "object" + } + ] + }, + "type": "array" + } + }, + "type": "object" + } + ] + }, + "type": "array" + }, + "tls": { + "items": { + "anyOf": [] + }, + "type": "array" + } + }, + "type": "object" + }, + "nameOverride": { + "type": "string" + }, + "nfagent": { + "additionalProperties": false, + "properties": { + "identity": { + "type": "string" + }, + "namespace": { + "type": "string" + }, + "topic": { + "type": "string" + } + }, + "type": "object" + }, + "nodeSelector": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "podAnnotations": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "podSecurityContext": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "replicaCount": { + "type": "integer" + }, + "resources": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "securityContext": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "service": { + "additionalProperties": false, + "properties": { + "port": { + "type": "integer" + }, + "type": { + "type": "string" + } + }, + "type": "object" + }, + "serviceAccount": { + "additionalProperties": false, + "properties": { + "annotations": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "create": { + "type": "boolean" + }, + "name": { + "type": "string" + } + }, + "type": "object" + }, + "tolerations": { + "items": { + "anyOf": [] + }, + "type": "array" + } + }, + "type": "object" +} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.yaml new file mode 100644 index 00000000000..3d9aeb6c9cb --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nf-agent-cnf/values.yaml @@ -0,0 +1,92 @@ +# Default values for nf-agent-cnf. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + # NFDV defines that AOSM overwrites image.repository with the Articfact Store ACR + repository: sunnyclipubsunnynfagentacr2dd56aed266.azurecr.io + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "879624" + +# NFDV defines that AOSM overwrites imagePullSecrets with whatever is needed for the Artifact Store ACR +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + # I forgot to change values.mappings.yaml in NFDV to match the service port in the Helm chart when testing this + port: 8123 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +nfagent: + namespace: sb-uowvjfivpyuow + identity: 041db2eb-36e0-42cd-ac13-03ae8e997cd1 + topic: simpl + # name of pod identity - not using this any more + # podIdentity: mypeapod diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart-0.1.0.tgz b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart-0.1.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..db24d31925a98013991b078915dafa0910d8faff GIT binary patch literal 4630 zcmV+x66x(9iwG0|00000|0w_~VMtOiV@ORlOnEsqVl!4SWK%V1T2nbTPgYhoO;>Dc zVQyr3R8em|NM&qo0PK8ibK5$u@cFD?fk(+ceYv$PJ1_01(>v3fcF*nIHqD%LyR*|d zlc6QpW9brBZQ17g$You1pt? zd>zM@d=Fp;PBV<@n4*G%=O)QaUOgt!_A{Y~<&|>;DMKFDW z7=xbT8Wt@eR~T5>cVpl}gF+32Cj~MiEiH3=2E-wv3MR-=nl2$%lus<;a&Sw*cwpfp z&&xz|ig7Nfo*xOW@lr>yxUyZ2)vr?ISp>r{3=J>Z!D5n;5oJ_URE|Rci4BkM{5K)=pD9B%R~pmE4#5HB{Ixn3+yFFR|5c%kU{H`^8D)CV^9&<6V!6^N z-<_D5Af%4qU^pCl9_15>%94fL%#>usf5N%Y#4LHL7>nuaJRhOtXyz^z{i1ykGon-k zd_wtUE1+hoM`E-1`G#!Y1DFb>ZO?`U=11gK&>mirG-DVr5ff(X0WzYeZf2S>G52Ws z*8^qe?Xg{2YZ!W(se;L?-gX?qUTbHbL?v<=qgsmZZwR@{31f4!jEgiyp4h3T1t>e! z=a3ZEW7*oyK`nqGnIULnIEXPEvEVAEB6noPQ(>mFF*arv<_cxttPEjF0Oe*DD^!M5 z9=rciD6T4lv5*>z$nXH%m9D1+Gp4}J za5J^YcuYCfb6fqh7o~@CZ>81$Q}Gm25`0yH-$frA{J-aWd&7qRcW^K~c<}%3qb%$y zV3CB7Z6$X z{i0aZOv}RJ)ZSi))2`0X>Y#PxSB+ZZ0hl3)(N~PMzpSjl`AzR`otzSj(vtE?I~MCn z-r-1Ub*_Ht#kSU8OKA(m%Qh=l`)=`SGPwmp?;7-5iM8q4ugivNOgnf@`26G8FC4AS zbPy@Yyn_tqCH~NvQSny0Ilg^=9sRb*7_JjW2h(hu!r|ULKSn|@Bz!xp*3a$6*)8uS z$Wrc|Af|L9SRuMGw`RyCapmTS{-ee%#(AsBXG`vX8TVlJk=Zs-FCH zbC+_B6O>&jiaqpC9*X*xVr+5z^X?T2gUKZCu8 z^Pl@Dg8+U-cg{^RyC@qyhQI#y9!7JJIp;;BNFl@`O$kp__7Eu_~V0o?!WQyiXbgzB_46u~a8!n>0qDotjDGBZ_!>Pqu>kwZ*4To4^kUDVZ%6U4Zx3y*FrYc-3Zcd@ku zAFU*K`u4Za?~Yo8Xi;v{_qLrvuU8s>@D~ezu_zSsG35zfLMd}rVQ8t15I(W`7FeZo z>g8Xx%!Ji&B13RPz;?u)in)yAZlRecAK#oEzy9#H!L&>y+fIB2KFPA69?3NgUv)Ed z#mr~xZ7EmUFzr>dPs6KDMN3hWglJ-MR~YJlri$v4uY=+9APmA_5WNUrghg(EOSh=l zbmKXd+%R0~jfK1*GJ)NaU0|9=FT$#o{MqZ%L;10#%l|u@BFj*!Kxem31>5BR?HxRC z_vTj(3mnb*7Q|s*b+}Mf~S3JlKW4+x0jjC?P#PX6-i9*^dhBX5pR4Xkk%j9>R8@ZOC6(V^hWbKO{Yb&=XEoy zX@%PpL^sK(e(rhPWj^X)L6KqFD>h?`#Zu=VZ{BM>>B7n@l2|Hk1HWH9tnC3>k+f*% z&t7i-z5T+=G7NeRXAx1s}Xo7Bz_N(041-%X0RWL%(%*9DN;~G z74O%tODq;(b_$=wiA1gE|Dyzl#~LLkat@CfRT@_IzS$fen~C;Lflv92Fq-(CpiiEx z#<#v^SvppySDTl(po*=2bz#XwvubGZcapLtRqJ7N_y)X~u`gCQ3vU)>MXy8R3|ZmVIA`h{LN;&n_Y?)fHT5!>qQ74v9u>*l^ZmDdzm3}7ii$IkVTF> zjY|*qNey=*;&YUs$pmUGH=%ArlI3c8lZNif5cn0#U|$8RyhgaXs1VrF|MI2F|1Sfr zcX1VXga1Da*Y5ux?hhaQ|9dGLBKgbHJ>%9N7bkpMc>c?FY8IO%uNwca#rrC!4GPm4 z$|I3xL?ZbA`Dzdh_IsfZ!BOQNY4DePgvFL6_?7DN(8V1ytu`|p^@Wh3~(71#g)@~ibfY?d7E`|E&*t=IYK;lHJA;*cAUA9yIQM4#VN$!}@uC_TTtEwBL2)@Jn1i>=r3pyCadz&qi~N>P#70 zmfe{O@OO=EKa)5{iPG=trT{bap4pF(_+`t>vm%=Y6Z7Ohdg+yh8D%B+nNg*Y7e8Kv zFWV~)hQr}{)t4yxJ*u{G*w1Xt1MJw%y7kgq9R$WPDs{%h1fV}7vd_e%*!9{>Nmn1( zdMBewV}sD8 zSHm!b-CWX_m2B_j<4y${_QU5(>RXDhEkx)ei=k?sAi+p@MTh5 z&d)NUR7>L8V7O-n;?&g)M55{L=F_BnYGqX>jDeX_K4}PG2Xrnui1FC4XJP=RDBS_+ zOwa@pk&hUbm9@4N){61?78AQus0lLE*d+PiN~90o>5nO0{$IICzlZam@UZFs4G#AQ z`w#x#eUw)JuSh`o*>PX@0k4)!@m0ciB?{9k!VuSFmOF!@iJYK5X~rztLNK*>PCdSS z>qzZQqqILp{u}haNGH0T8Q7%%dwYA${Ez2{58wZ}m$G%H*L8-X0B^S!-w~Mqe$(-g z>vhA@rT-e0c7Kf@$}u*M>35oejqCrgasP8T7(RUe>wZeBTAzrdMVI|;7yn*k+W5DO zg{(z5{4ynYD#W=Tf$dM_cJH(F9-3J=Wnlhdg1VZ}6u~H0^O3k*X7AWrt`U5BWI!L4 zm(z)ys0iT8qixx6%^f$3RHB)By39N|#u>_cH(GW54-8}JgbRsx*vBUQKNudaegAp* z;Q!xC*?|+HHA-&J!JO#fVu~C_Ib{ju6Uaz>P9~_9AA(kSX8mqZQ)CP#OpIK*CFPT6 zAdwMGXJ{i{mG^`v-VSh_xHFE&nZz-@#KeU;|KF1UK5{k(!EH-J5@aat_f`WhcyoGo zs)a;v2Z~z=pN~!&W+l(LZJ1{w-fjCw=p${HbQVzd|%3@p+!vyHCn{ z8mNoRdm4<$x%V{CY34osUvCFK6G=s`;N6?I$_p|nzGAGsfF?-#4o-@%UNBR!NU;A0 zay{z$@19eV)zYDE+s6j|9}Wgh|Nn4r`0)Mrdnxx6rMZU)&CQ}Swa83sRHilTa&5@v zyTdK5p_c7p0$YVxu0LcgPM~iVR=H(J#f4LD6iV3;M%m1+D{l=?CX}Anf+aUSRlmy< z^=nSkE0K$r;H{3uTSv4O;rQO@MptA5(@f9LCUpD~N@5;9xb#pS%0qc5f2{I<0RRC1 M|BT)1UI1=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: +{{ include "nfconfigchart.labels" . | indent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: +{{- if .Values.ingress.tls }} + tls: + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} +{{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + backend: + serviceName: {{ $fullName }} + servicePort: {{ $svcPort }} + {{- end }} + {{- end }} +{{- end }} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/nginx_config_map.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/nginx_config_map.yaml new file mode 100644 index 00000000000..3174b9eef3c --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/nginx_config_map.yaml @@ -0,0 +1,56 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: nginx-config +# This writes the nginx config file to the ConfigMap and deployment.yaml mounts it as a volume +# to the right place. +data: + default.conf: | + log_format client '$remote_addr - $remote_user $request_time $upstream_response_time ' + '[$time_local] "$request" $status $body_bytes_sent $request_body "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + server { + listen 80; + listen 5222; + listen [::]:80; + server_name localhost; + + access_log /var/log/nginx/host.access.log client; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + error_page 405 =200 $uri; + } + + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + location = /nf-config/v1/config { + #access_log logs/uaa_access.log client; + # add the proper port or IP address if Nginx is not on 127.0.0.1:80 + # This results in a Bad Gateway. We could pass it back to the nf-agent + # but haven't worked out how to put a body in it here. + proxy_pass http://127.0.0.1:8123/nf-status/v1/report; + error_page 405 =200 $uri; + } + + location = /post_thing { + # turn off logging here to avoid double logging + access_log off; + error_page 405 =200 $uri; + } + + location = /nf-config/v1/delete { + #access_log logs/uaa_access.log client; + # add the proper port or IP address if Nginx is not on 127.0.0.1:80 + proxy_pass http://127.0.0.1:8123/nf-status/v1/report; + error_page 405 =200 $uri; + } + } diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/service.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/service.yaml new file mode 100644 index 00000000000..a9f1a14e49c --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "nfconfigchart.fullname" . }} + labels: +{{ include "nfconfigchart.labels" . | indent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/name: {{ include "nfconfigchart.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/serviceaccount.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/serviceaccount.yaml new file mode 100644 index 00000000000..cab132a5c75 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/serviceaccount.yaml @@ -0,0 +1,8 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "nfconfigchart.serviceAccountName" . }} + labels: +{{ include "nfconfigchart.labels" . | indent 4 }} +{{- end -}} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/tests/test-connection.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/tests/test-connection.yaml new file mode 100644 index 00000000000..db6b909125f --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/templates/tests/test-connection.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Pod +metadata: + name: "{{ include "nfconfigchart.fullname" . }}-test-connection" + labels: +{{ include "nfconfigchart.labels" . | indent 4 }} + annotations: + "helm.sh/hook": test-success +spec: + containers: + - name: wget + image: busybox + command: ['wget'] + args: ['{{ include "nfconfigchart.fullname" . }}:{{ .Values.service.port }}'] + restartPolicy: Never diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/values.schema.json b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/values.schema.json new file mode 100644 index 00000000000..4972d65822b --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/values.schema.json @@ -0,0 +1,134 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema", + "additionalProperties": true, + "properties": { + "affinity": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "fullnameOverride": { + "type": "string" + }, + "image": { + "additionalProperties": false, + "properties": { + "pullPolicy": { + "type": "string" + }, + "repository": { + "type": "string" + }, + "tag": { + "type": "string" + } + }, + "type": "object" + }, + "imagePullSecrets": { + "items": { + "anyOf": [] + }, + "type": "array" + }, + "ingress": { + "additionalProperties": false, + "properties": { + "annotations": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "enabled": { + "type": "boolean" + }, + "hosts": { + "items": { + "anyOf": [ + { + "additionalProperties": false, + "properties": { + "host": { + "type": "string" + }, + "paths": { + "items": { + "anyOf": [] + }, + "type": "array" + } + }, + "type": "object" + } + ] + }, + "type": "array" + }, + "tls": { + "items": { + "anyOf": [] + }, + "type": "array" + } + }, + "type": "object" + }, + "nameOverride": { + "type": "string" + }, + "nodeSelector": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "podSecurityContext": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "replicaCount": { + "type": "integer" + }, + "resources": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "securityContext": { + "additionalProperties": false, + "properties": {}, + "type": "object" + }, + "service": { + "additionalProperties": false, + "properties": { + "port": { + "type": "integer" + }, + "type": { + "type": "string" + } + }, + "type": "object" + }, + "serviceAccount": { + "additionalProperties": false, + "properties": { + "create": { + "type": "boolean" + }, + "name": { + "type": "null" + } + }, + "type": "object" + }, + "tolerations": { + "items": { + "anyOf": [] + }, + "type": "array" + } + }, + "type": "object" +} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/values.yaml b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/values.yaml new file mode 100644 index 00000000000..de470d42f3c --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/helm-charts/nfconfigchart/values.yaml @@ -0,0 +1,70 @@ +# Default values for nfconfigchart. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + # Repository gets overwritten by AOSM to the Artifact Store ACR, however we've hard-coded the image name and tag in deployment.yaml + repository: sunnyclipubsunnynfagentacr2dd56aed266.azurecr.io + tag: stable + pullPolicy: IfNotPresent + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: false + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + # I forgot to change values.mappings.yaml in NFDV to match the service port in the Helm chart when testing this + port: 5222 + +ingress: + enabled: false + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/input-nfconfigchart.json b/src/aosm/azext_aosm/tests/latest/mock_cnf/input-nfconfigchart.json new file mode 100644 index 00000000000..f1869fe5cb1 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/input-nfconfigchart.json @@ -0,0 +1,18 @@ +{ + "publisher_name": "sunnyclipub", + "publisher_resource_group_name": "sunny-uksouth", + "nf_name": "nginx-basic-test", + "version": "0.1.0", + "acr_artifact_store_name": "sunny-nfagent-acr-2", + "location": "uksouth", + "source_registry_id": "this was nonsense just put something in to stop CLI complaining. The image was manually uploaded. /subscriptions/c7bd9d96-70dd-4f61-af56-6e0abd8d80b5/resourceGroups/SIMPLVM-team-CI/providers/Microsoft.ContainerRegistry/registries/a4oSIMPL", + "helm_packages": [ + { + "name": "nfconfigchart", + "path_to_chart": "helm-charts/nfconfigchart-0.1.0.tgz", + "path_to_mappings": "helm-charts/nfconfigchart/nfconfigchartvalues.mappings.yaml", + "depends_on": [ + ] + } + ] +} diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/config_file.json b/src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_config_file.json similarity index 100% rename from src/aosm/azext_aosm/tests/latest/mock_cnf/config_file.json rename to src/aosm/azext_aosm/tests/latest/mock_cnf/invalid_config_file.json From f8b317f81391d53648a37ba8be740605773a4c00 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Fri, 30 Jun 2023 10:49:44 +0100 Subject: [PATCH 121/145] Actually include all files. --- .github/workflows/RunUnitTests.yml | 2 +- src/aosm/azext_aosm/_configuration.py | 10 +++++++--- src/aosm/azext_aosm/tests/latest/test_cnf.py | 20 +++++++++++++++++++- src/aosm/azext_aosm/tests/latest/test_vnf.py | 7 ++++--- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/.github/workflows/RunUnitTests.yml b/.github/workflows/RunUnitTests.yml index b9f4e99cdb8..9796a77bc69 100644 --- a/.github/workflows/RunUnitTests.yml +++ b/.github/workflows/RunUnitTests.yml @@ -17,6 +17,6 @@ jobs: run: | # Pretend we have a valid git repo to satisfy azdev. mkdir .git - azdev setup -c EDGE -r . -e aosm + azdev setup -r . - name: Check Test run: azdev test aosm \ No newline at end of file diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index e3a3e0af8bf..fad119a0e9c 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -90,11 +90,11 @@ class ArtifactConfig: @dataclass class Configuration: config_file: Optional[str] = None - + def path_from_cli(self, path: str) -> str: """ Convert path from config file to path from current directory. - + We assume that the path supplied in the config file is relative to the configuration file. That isn't the same as the path relative to where ever the CLI is being run from. This function fixes that up. @@ -104,7 +104,11 @@ def path_from_cli(self, path: str) -> str: # If no path has been supplied we shouldn't try to update it. if path == "": return "" - + + # If it is an absolute path then we don't need to monkey around with it. + if os.path.isabs(path): + return path + return os.path.join(os.path.dirname(self.config_file), path) diff --git a/src/aosm/azext_aosm/tests/latest/test_cnf.py b/src/aosm/azext_aosm/tests/latest/test_cnf.py index 85601d1d7a0..99af75bd02c 100644 --- a/src/aosm/azext_aosm/tests/latest/test_cnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_cnf.py @@ -8,10 +8,12 @@ import json import logging import os +from tempfile import TemporaryDirectory # from unittest.mock import Mock, patch from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig +from azext_aosm.custom import build_definition from azure.cli.core.azclierror import ( BadRequestError, @@ -21,7 +23,7 @@ ) mock_cnf_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_cnf") -cnf_config_file = os.path.join(mock_cnf_folder, "config_file.json") +cnf_config_file = os.path.join(mock_cnf_folder, "invalid_config_file.json") # Instantiate CNF with faked config file with open(cnf_config_file, "r", encoding="utf-8") as f: @@ -40,6 +42,22 @@ def test_invalid_chart(self): test_cnf._extract_chart(invalid_helm_package.path_to_chart) +class TestCNF(unittest.TestCase): + def test_build(self): + starting_directory = os.getcwd() + with TemporaryDirectory() as test_dir: + os.chdir(test_dir) + + try: + build_definition( + "cnf", + os.path.join(mock_cnf_folder, "input-nfconfigchart.json") + ) + assert os.path.exists("nfd-bicep-ubuntu-template") + finally: + os.chdir(starting_directory) + + class TestGenerateChartValueMappings(unittest.TestCase): # Test for _read_top_level_values_yaml # Test for _replace_values_with_deploy_params diff --git a/src/aosm/azext_aosm/tests/latest/test_vnf.py b/src/aosm/azext_aosm/tests/latest/test_vnf.py index 2b2e7ecb491..8aae15f2e1c 100644 --- a/src/aosm/azext_aosm/tests/latest/test_vnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_vnf.py @@ -12,14 +12,15 @@ mock_vnf_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_vnf") -class TestVNF(): + +class TestVNF(unittest.TestCase): def test_build(self): starting_directory = os.getcwd() with TemporaryDirectory() as test_dir: os.chdir(test_dir) - + try: build_definition("vnf", os.path.join(mock_vnf_folder, "input.json")) assert os.path.exists("nfd-bicep-ubuntu-template") - except: + finally: os.chdir(starting_directory) From 53e7729d0b1668a13d9598ef0471563940afcbe4 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Fri, 30 Jun 2023 10:51:01 +0100 Subject: [PATCH 122/145] Always run tests --- .github/workflows/RunUnitTests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/RunUnitTests.yml b/.github/workflows/RunUnitTests.yml index 9796a77bc69..8e16e29c13b 100644 --- a/.github/workflows/RunUnitTests.yml +++ b/.github/workflows/RunUnitTests.yml @@ -2,7 +2,6 @@ name: Run Unit + Integration Tests on: push: - branches: [add-aosm-extension] pull_request: branches: [add-aosm-extension] From 9d219001d1225f126d59b9297a9fd8bd6ae43f9f Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Fri, 30 Jun 2023 14:02:47 +0100 Subject: [PATCH 123/145] Add another test that won't pass yet --- .../latest/mock_cnf/input-nf-agent-cnf.json | 17 +++++++++++++ src/aosm/azext_aosm/tests/latest/test_cnf.py | 25 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/aosm/azext_aosm/tests/latest/mock_cnf/input-nf-agent-cnf.json diff --git a/src/aosm/azext_aosm/tests/latest/mock_cnf/input-nf-agent-cnf.json b/src/aosm/azext_aosm/tests/latest/mock_cnf/input-nf-agent-cnf.json new file mode 100644 index 00000000000..e260384ff23 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_cnf/input-nf-agent-cnf.json @@ -0,0 +1,17 @@ +{ + "publisher_name": "sunnyclipub", + "publisher_resource_group_name": "sunny-uksouth", + "nf_name": "nf-agent-cnf", + "version": "0.1.0", + "acr_artifact_store_name": "sunny-nfagent-acr-2", + "location": "uksouth", + "source_registry_id": "--this was copied here and renamed from https://ms.portal.azure.com/#@microsoft.onmicrosoft.com/resource/subscriptions/4a0479c0-b795-4d0f-96fd-c7edd2a2928f/resourceGroups/pez-nfagent-pipelines/providers/Microsoft.ContainerRegistry/registries/peznfagenttemp/overview new one was /subscriptions/c7bd9d96-70dd-4f61-af56-6e0abd8d80b5/resourceGroups/sunny-nfagent-acr-HostedResources-4CDE264A/providers/Microsoft.ContainerRegistry/registries/SunnyclipubSunnyNfagentAcre00abc1832", + "helm_packages": [ + { + "name": "nf-agent-cnf", + "path_to_chart": "helm-charts/nf-agent-cnf-0.1.0.tgz", + "path_to_mappings": "", + "depends_on": [] + } + ] +} diff --git a/src/aosm/azext_aosm/tests/latest/test_cnf.py b/src/aosm/azext_aosm/tests/latest/test_cnf.py index 99af75bd02c..491f20dcd42 100644 --- a/src/aosm/azext_aosm/tests/latest/test_cnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_cnf.py @@ -44,18 +44,41 @@ def test_invalid_chart(self): class TestCNF(unittest.TestCase): def test_build(self): + """ + Test the build command for CNFs. + """ starting_directory = os.getcwd() with TemporaryDirectory() as test_dir: os.chdir(test_dir) try: build_definition( - "cnf", + "cnf", os.path.join(mock_cnf_folder, "input-nfconfigchart.json") ) assert os.path.exists("nfd-bicep-ubuntu-template") finally: os.chdir(starting_directory) + + def test_no_mapping(self): + """ + Test the build command for CNFs where no mapping file is supplied. + + Also reorder the parameters. + """ + starting_directory = os.getcwd() + with TemporaryDirectory() as test_dir: + os.chdir(test_dir) + + try: + build_definition( + "cnf", + os.path.join(mock_cnf_folder, "input-nf-agent-cnf.json"), + order_params=True + ) + assert os.path.exists("nfd-bicep-ubuntu-template") + finally: + os.chdir(starting_directory) class TestGenerateChartValueMappings(unittest.TestCase): From 716737eccd8d133d464db5c6f3f6901666039c46 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Fri, 30 Jun 2023 14:06:51 +0100 Subject: [PATCH 124/145] remove github pipeline tests - they should run in Azure --- .github/workflows/RunUnitTests.yml | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 .github/workflows/RunUnitTests.yml diff --git a/.github/workflows/RunUnitTests.yml b/.github/workflows/RunUnitTests.yml deleted file mode 100644 index 8e16e29c13b..00000000000 --- a/.github/workflows/RunUnitTests.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Run Unit + Integration Tests - -on: - push: - pull_request: - branches: [add-aosm-extension] - -jobs: - check_tests: - runs-on: ubuntu-latest - container: mcr.microsoft.com/azure-cli/tools:latest - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - name: Setup azdev - run: | - # Pretend we have a valid git repo to satisfy azdev. - mkdir .git - azdev setup -r . - - name: Check Test - run: azdev test aosm \ No newline at end of file From 0f86392c9ae8e3346acad45dbb3094caea0385d5 Mon Sep 17 00:00:00 2001 From: sunnycarter <36891339+sunnycarter@users.noreply.github.com> Date: Tue, 4 Jul 2023 12:00:53 +0100 Subject: [PATCH 125/145] Sundry fixes for CNF quickstart (#38) * Sundry fixes for CNF quickstart * merge add-aosm-ext in (#37) * markups --- src/aosm/HISTORY.rst | 7 + src/aosm/azext_aosm/_configuration.py | 32 ++- src/aosm/azext_aosm/_params.py | 9 +- src/aosm/azext_aosm/custom.py | 7 + src/aosm/azext_aosm/deploy/artifact.py | 37 ++- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 272 ++++++++++-------- src/aosm/azext_aosm/deploy/pre_deploy.py | 35 ++- .../generate_nfd/cnf_nfd_generator.py | 148 +++++----- src/aosm/azext_aosm/generate_nsd/__init__.py | 5 + .../azext_aosm/generate_nsd/nsd_generator.py | 46 ++- ...nf_template.bicep => nf_template.bicep.j2} | 25 +- ...d_template.bicep => nsd_template.bicep.j2} | 7 +- src/aosm/azext_aosm/util/constants.py | 20 +- 13 files changed, 408 insertions(+), 242 deletions(-) create mode 100644 src/aosm/azext_aosm/generate_nsd/__init__.py rename src/aosm/azext_aosm/generate_nsd/templates/{nf_template.bicep => nf_template.bicep.j2} (79%) rename src/aosm/azext_aosm/generate_nsd/templates/{nsd_template.bicep => nsd_template.bicep.j2} (92%) diff --git a/src/aosm/HISTORY.rst b/src/aosm/HISTORY.rst index 836fcf03607..ae1c3842448 100644 --- a/src/aosm/HISTORY.rst +++ b/src/aosm/HISTORY.rst @@ -9,6 +9,13 @@ unreleased * NFDV version exposed as a CGV on an SNS. * `az aosm nfd publish` option added for `--definition-type cnf` to publish the CNF bicep templates, upload helm charts from disk to the ACR and copy the images from a source ACR to the target ACR. * Managed Identity added to VNF NF templates - requires subscription to be registered for the feature flag. +* Various fixes to NFD build of deployParameters schema and interactive mode create of deployParameters mappings file. +* Fix CNF NFD publish so that it doesn't render the ACR unuseable for future Artifact publishing. +* Allow CNF NFD image copy from a source ACR using a namespace. +* Fix - Add new CGSchema parameters not from the NFD to the `required` section of the schema. +* Add the ability to skip bicep publish or artifact upload during publish commands. +* Fix Manifest name for NSDs so it isn't the same as that for NFDs +* Add validation of source_registry_id format for CNF configuration 0.2.0 ++++++ diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 4f40ad21917..f933e3bd524 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,4 +1,5 @@ import os +import re from dataclasses import dataclass, field from pathlib import Path from typing import Any, Dict, List, Optional @@ -12,6 +13,7 @@ NSD, NSD_OUTPUT_BICEP_PREFIX, VNF, + SOURCE_ACR_REGEX ) DESCRIPTION_MAP: Dict[str, str] = { @@ -95,6 +97,13 @@ "source_registry_id": ( "Resource ID of the source acr registry from which to pull the image" ), + "source_registry_namespace": ( + "Optional. Namespace of the repository of the source acr registry from which " + "to pull. For example if your repository is samples/prod/nginx then set this to" + " samples/prod . Leave blank if the image is in the root namespace." + "See https://learn.microsoft.com/en-us/azure/container-registry/" + "container-registry-best-practices#repository-namespaces for further details." + ), } @@ -220,8 +229,10 @@ def network_function_name(self) -> str: @property def acr_manifest_name(self) -> str: """Return the ACR manifest name from the NFD name.""" - sanitised_nf_name = self.network_function_name.lower().replace("_", "-") - return f"{sanitised_nf_name}-acr-manifest-{self.nsd_version.replace('.', '-')}" + sanitised_nf_name = self.network_function_name.lower().replace('_', '-') + return ( + f"{sanitised_nf_name}-nsd-acr-manifest-{self.nsd_version.replace('.', '-')}" + ) @property def nfvi_site_name(self) -> str: @@ -246,7 +257,7 @@ def arm_template(self) -> ArtifactConfig: @property def arm_template_artifact_name(self) -> str: """Return the artifact name for the ARM template.""" - return f"{self.network_function_definition_group_name}_nfd_artifact" + return f"{self.network_function_definition_group_name}-nfd-artifact" @dataclass @@ -337,6 +348,7 @@ class HelmPackageConfig: @dataclass class CNFConfiguration(NFConfiguration): source_registry_id: str = DESCRIPTION_MAP["source_registry_id"] + source_registry_namespace: str = DESCRIPTION_MAP["source_registry_namespace"] helm_packages: List[Any] = field(default_factory=lambda: [HelmPackageConfig()]) def __post_init__(self): @@ -354,6 +366,20 @@ def build_output_folder_name(self) -> str: """Return the local folder for generating the bicep template to.""" return f"{NF_DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}" + def validate(self): + """Validate the CNF config + + :raises ValidationError: If source registry ID doesn't match the regex + """ + if self.source_registry_id == DESCRIPTION_MAP["source_registry_id"]: + # Config has not been filled in. Don't validate. + return + + source_registry_match = re.search(SOURCE_ACR_REGEX, self.source_registry_id) + if not source_registry_match or len(source_registry_match.groups()) < 2: + raise ValidationError( + "CNF config has an invalid source registry ID. Please run `az aosm " + "nfd generate-config` to see the valid formats.") def get_configuration( configuration_type: str, config_as_dict: Optional[Dict[Any, Any]] = None diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index c7a8602bd76..2c379a3494a 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -6,7 +6,7 @@ from argcomplete.completers import FilesCompleter from azure.cli.core import AzCommandsLoader -from .util.constants import CNF, VNF +from .util.constants import CNF, VNF, BICEP_PUBLISH, ARTIFACT_UPLOAD def load_arguments(self: AzCommandsLoader, _): @@ -17,6 +17,7 @@ def load_arguments(self: AzCommandsLoader, _): ) definition_type = get_enum_type([VNF, CNF]) + skip_steps = get_enum_type([BICEP_PUBLISH, ARTIFACT_UPLOAD]) # Set the argument context so these options are only available when this specific command # is called. @@ -109,6 +110,9 @@ def load_arguments(self: AzCommandsLoader, _): " alternative parameters." ), ) + c.argument( + "skip", arg_type=skip_steps, help="Optional skip steps" + ) with self.argument_context("aosm nsd") as c: c.argument( @@ -118,3 +122,6 @@ def load_arguments(self: AzCommandsLoader, _): completer=FilesCompleter(allowednames="*.json"), help="The path to the configuration file.", ) + c.argument( + "skip", arg_type=skip_steps, help="Optional skip steps" + ) diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 78b058c8859..bbe7ed00abd 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -137,6 +137,7 @@ def publish_definition( parameters_json_file: Optional[str] = None, manifest_file: Optional[str] = None, manifest_parameters_json_file: Optional[str] = None, + skip: Optional[str] = None, ): """ Publish a generated definition. @@ -156,6 +157,7 @@ def publish_definition( manifests :param manifest_parameters_json_file: Optional path to an override bicep parameters file for manifest parameters + :param skip: options to skip, either publish bicep or upload artifacts """ print("Publishing definition.") api_clients = ApiClients( @@ -175,6 +177,7 @@ def publish_definition( parameters_json_file=parameters_json_file, manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, + skip=skip ) elif definition_type == CNF: deployer = DeployerViaArm(api_clients, config=config) @@ -184,6 +187,7 @@ def publish_definition( parameters_json_file=parameters_json_file, manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, + skip=skip ) else: raise ValueError( @@ -328,6 +332,7 @@ def publish_design( parameters_json_file: Optional[str] = None, manifest_file: Optional[str] = None, manifest_parameters_json_file: Optional[str] = None, + skip: Optional[str] = None, ): """ Publish a generated design. @@ -345,6 +350,7 @@ def publish_design( manifests :param manifest_parameters_json_file: Optional path to an override bicep parameters file for manifest parameters + :param skip: options to skip, either publish bicep or upload artifacts """ print("Publishing design.") @@ -363,6 +369,7 @@ def publish_design( parameters_json_file=parameters_json_file, manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, + skip=skip ) diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index ee37c50bebe..7e5d03bd532 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -5,7 +5,7 @@ """A module to handle interacting with artifacts.""" import subprocess from dataclasses import dataclass -from typing import Union +from typing import Union, List from azure.cli.core.commands import LongRunningOperation from azure.mgmt.containerregistry.models import ImportImageParameters, ImportSource @@ -13,6 +13,8 @@ from knack.log import get_logger from knack.util import CLIError from oras.client import OrasClient +from azure.cli.core.commands import LongRunningOperation +from azure.mgmt.containerregistry import ContainerRegistryManagementClient from azext_aosm._configuration import ArtifactConfig, HelmPackageConfig @@ -82,11 +84,18 @@ def _upload_helm_to_acr(self, artifact_config: HelmPackageConfig) -> None: login_command = ["az", "acr", "login", "--name", registry_name] subprocess.run(login_command, check=True) - logger.debug("Uploading %s to %s", chart_path, target_registry) - - # helm push "$chart_path" "$target_registry" - push_command = ["helm", "push", chart_path, target_registry] - subprocess.run(push_command, check=True) + try: + logger.debug("Uploading %s to %s", chart_path, target_registry) + + # helm push "$chart_path" "$target_registry" + push_command = ["helm", "push", chart_path, target_registry] + subprocess.run(push_command, check=True) + finally: + # If we don't logout from the registry, future Artifact uploads to this ACR + # will fail with an UNAUTHORIZED error. There is no az acr logout command, + # but it is a wrapper around docker, so a call to docker logout will work. + logout_command = ["docker", "logout", registry] + subprocess.run(logout_command, check=True) def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: """ @@ -131,12 +140,13 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: @staticmethod def copy_image( cli_ctx, - container_registry_client, - source_registry_id, - source_image, - target_registry_resource_group_name, - target_registry_name, - mode="NoForce", + container_registry_client: ContainerRegistryManagementClient, + source_registry_id: str, + source_image: str, + target_registry_resource_group_name: str, + target_registry_name: str, + target_tags: List[str], + mode: str = "NoForce", ): """ Copy image from one ACR to another. @@ -147,9 +157,10 @@ def copy_image( :param source_image: source image :param target_registry_resource_group_name: target registry resource group name :param target_registry_name: target registry name + :param target_tags: the list of tags to be applied to the imported image + should be of form: namepace/name:tag or name:tag :param mode: mode for import """ - target_tags = [source_image] source = ImportSource(resource_id=source_registry_id, source_image=source_image) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 36d0b76979e..e0251be0351 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -5,6 +5,7 @@ """Contains class for deploying generated definitions using ARM.""" import json import os +import re import shutil import subprocess # noqa import tempfile @@ -24,6 +25,8 @@ from azext_aosm.deploy.artifact_manifest import ArtifactManifestOperator from azext_aosm.deploy.pre_deploy import PreDeployerViaSDK from azext_aosm.util.constants import ( + ARTIFACT_UPLOAD, + BICEP_PUBLISH, CNF, CNF_DEFINITION_BICEP_TEMPLATE_FILENAME, CNF_MANIFEST_BICEP_TEMPLATE_FILENAME, @@ -34,6 +37,7 @@ VNF, VNF_DEFINITION_BICEP_TEMPLATE_FILENAME, VNF_MANIFEST_BICEP_TEMPLATE_FILENAME, + SOURCE_ACR_REGEX, ) from azext_aosm.util.management_clients import ApiClients @@ -87,6 +91,7 @@ def deploy_vnfd_from_bicep( parameters_json_file: Optional[str] = None, manifest_bicep_path: Optional[str] = None, manifest_parameters_json_file: Optional[str] = None, + skip: Optional[str] = None ) -> None: """ Deploy the bicep template defining the VNFD. @@ -106,50 +111,59 @@ def deploy_vnfd_from_bicep( :param manifest_bicep_path: The path to the bicep template of the manifest :manifest_parameters_json_file: path to an override file of set parameters for the manifest + :param skip: options to skip, either publish bicep or upload artifacts """ assert isinstance(self.config, VNFConfiguration) - if not bicep_path: - # User has not passed in a bicep template, so we are deploying the default - # one produced from building the NFDV using this CLI - bicep_path = os.path.join( - self.config.build_output_folder_name, - VNF_DEFINITION_BICEP_TEMPLATE_FILENAME, - ) + if not skip == BICEP_PUBLISH: + if not bicep_path: + # User has not passed in a bicep template, so we are deploying the default + # one produced from building the NFDV using this CLI + bicep_path = os.path.join( + self.config.build_output_folder_name, + VNF_DEFINITION_BICEP_TEMPLATE_FILENAME, + ) - if parameters_json_file: - parameters = self.read_parameters_from_file(parameters_json_file) + if parameters_json_file: + parameters = self.read_parameters_from_file(parameters_json_file) - else: - # User has not passed in parameters file, so we use the parameters required - # from config for the default bicep template produced from building the - # NFDV using this CLI - logger.debug("Create parameters for default NFDV template.") - parameters = self.construct_vnfd_parameters() - - logger.debug(parameters) - - # Create or check required resources - deploy_manifest_template = not self.nfd_predeploy(definition_type=VNF) - if deploy_manifest_template: - self.deploy_manifest_template( - manifest_parameters_json_file, manifest_bicep_path, VNF + else: + # User has not passed in parameters file, so we use the parameters + # required from config for the default bicep template produced from + # building the NFDV using this CLI + logger.debug("Create parameters for default NFDV template.") + parameters = self.construct_vnfd_parameters() + + logger.debug(parameters) + + # Create or check required resources + deploy_manifest_template = not self.nfd_predeploy(definition_type=VNF) + if deploy_manifest_template: + self.deploy_manifest_template( + manifest_parameters_json_file, manifest_bicep_path, VNF + ) + else: + print( + f"Artifact manifests exist for NFD {self.config.nf_name} " + f"version {self.config.version}" + ) + message = ( + f"Deploy bicep template for NFD {self.config.nf_name} version" + f" {self.config.version} into" + f" {self.config.publisher_resource_group_name} under publisher" + f" {self.config.publisher_name}" ) + print(message) + logger.info(message) + self.deploy_bicep_template(bicep_path, parameters) + print(f"Deployed NFD {self.config.nf_name} version {self.config.version}.") else: - print( - f"Artifact manifests exist for NFD {self.config.nf_name} " - f"version {self.config.version}" - ) - message = ( - f"Deploy bicep template for NFD {self.config.nf_name} version" - f" {self.config.version} into" - f" {self.config.publisher_resource_group_name} under publisher" - f" {self.config.publisher_name}" - ) - print(message) - logger.info(message) - self.deploy_bicep_template(bicep_path, parameters) - print(f"Deployed NFD {self.config.nf_name} version {self.config.version}.") + print("Skipping bicep publish") + + if skip == ARTIFACT_UPLOAD: + print("Skipping artifact upload") + print("Done") + return storage_account_manifest = ArtifactManifestOperator( self.config, @@ -179,7 +193,6 @@ def nfd_predeploy(self, definition_type) -> bool: Return True if artifact manifest already exists, False otherwise """ - logger.debug("Ensure all required resources exist") self.pre_deployer.ensure_config_resource_group_exists() self.pre_deployer.ensure_config_publisher_exists() @@ -263,6 +276,7 @@ def deploy_cnfd_from_bicep( parameters_json_file: Optional[str] = None, manifest_bicep_path: Optional[str] = None, manifest_parameters_json_file: Optional[str] = None, + skip: Optional[str] = None ) -> None: """ Deploy the bicep template defining the CNFD. @@ -276,51 +290,60 @@ def deploy_cnfd_from_bicep( :param manifest_bicep_path: The path to the bicep template of the manifest :param manifest_parameters_json_file: path to an override file of set parameters for the manifest + :param skip: options to skip, either publish bicep or upload artifacts """ assert isinstance(self.config, CNFConfiguration) - if not bicep_path: - # User has not passed in a bicep template, so we are deploying the default - # one produced from building the NFDV using this CLI - bicep_path = os.path.join( - self.config.build_output_folder_name, - CNF_DEFINITION_BICEP_TEMPLATE_FILENAME, - ) + if not skip == BICEP_PUBLISH: + if not bicep_path: + # User has not passed in a bicep template, so we are deploying the + # default one produced from building the NFDV using this CLI + bicep_path = os.path.join( + self.config.build_output_folder_name, + CNF_DEFINITION_BICEP_TEMPLATE_FILENAME, + ) - if parameters_json_file: - parameters = self.read_parameters_from_file(parameters_json_file) - else: - # User has not passed in parameters file, so we use the parameters required - # from config for the default bicep template produced from building the - # NFDV using this CLI - logger.debug("Create parameters for default NFDV template.") - parameters = self.construct_cnfd_parameters() + if parameters_json_file: + parameters = self.read_parameters_from_file(parameters_json_file) + else: + # User has not passed in parameters file, so we use the parameters + # required from config for the default bicep template produced from + # building the NFDV using this CLI + logger.debug("Create parameters for default NFDV template.") + parameters = self.construct_cnfd_parameters() - logger.debug( - "Parameters used for CNF definition bicep deployment: %s", parameters - ) + logger.debug( + "Parameters used for CNF definition bicep deployment: %s", parameters + ) - # Create or check required resources - deploy_manifest_template = not self.nfd_predeploy(definition_type=CNF) - if deploy_manifest_template: - self.deploy_manifest_template( - manifest_parameters_json_file, manifest_bicep_path, CNF + # Create or check required resources + deploy_manifest_template = not self.nfd_predeploy(definition_type=CNF) + if deploy_manifest_template: + self.deploy_manifest_template( + manifest_parameters_json_file, manifest_bicep_path, CNF + ) + else: + print( + f"Artifact manifests exist for NFD {self.config.nf_name} " + f"version {self.config.version}" + ) + message = ( + f"Deploy bicep template for NFD {self.config.nf_name} version" + f" {self.config.version} into" + f" {self.config.publisher_resource_group_name} under publisher" + f" {self.config.publisher_name}" ) + print(message) + logger.info(message) + self.deploy_bicep_template(bicep_path, parameters) + print(f"Deployed NFD {self.config.nf_name} version {self.config.version}.") else: - print( - f"Artifact manifests exist for NFD {self.config.nf_name} " - f"version {self.config.version}" - ) - message = ( - f"Deploy bicep template for NFD {self.config.nf_name} version" - f" {self.config.version} into" - f" {self.config.publisher_resource_group_name} under publisher" - f" {self.config.publisher_name}" - ) - print(message) - logger.info(message) - self.deploy_bicep_template(bicep_path, parameters) - print(f"Deployed NFD {self.config.nf_name} version {self.config.version}.") + print("Skipping bicep publish") + + if skip == ARTIFACT_UPLOAD: + print("Skipping artifact upload") + print("Done") + return acr_properties = self.api_clients.aosm_client.artifact_stores.get( resource_group_name=self.config.publisher_resource_group_name, @@ -331,6 +354,10 @@ def deploy_cnfd_from_bicep( target_registry_resource_group_name = acr_properties.storage_resource_id.split( "/" )[-5] + # Check whether the source registry has a namespace in the repository path + source_registry_namespace: str = "" + if self.config.source_registry_namespace: + source_registry_namespace = f"{self.config.source_registry_namespace}/" acr_manifest = ArtifactManifestOperator( self.config, @@ -362,8 +389,8 @@ def deploy_cnfd_from_bicep( artifact_dictionary.pop(helm_package_name) - # All the remaining artifacts are not in the helm_packages list. We assume that they - # are images that need to be copied from another ACR. + # All the remaining artifacts are not in the helm_packages list. We assume that + # they are images that need to be copied from another ACR. for artifact in artifact_dictionary.values(): assert isinstance(artifact, Artifact) @@ -372,9 +399,13 @@ def deploy_cnfd_from_bicep( cli_ctx=cli_ctx, container_registry_client=self.api_clients.container_registry_client, source_registry_id=self.config.source_registry_id, - source_image=f"{artifact.artifact_name}:{artifact.artifact_version}", + source_image=( + f"{source_registry_namespace}{artifact.artifact_name}" + f":{artifact.artifact_version}" + ), target_registry_resource_group_name=target_registry_resource_group_name, target_registry_name=target_registry_name, + target_tags=[f"{artifact.artifact_name}:{artifact.artifact_version}"], ) print("Done") @@ -385,6 +416,7 @@ def deploy_nsd_from_bicep( parameters_json_file: Optional[str] = None, manifest_bicep_path: Optional[str] = None, manifest_parameters_json_file: Optional[str] = None, + skip: Optional[str] = None, ) -> None: """ Deploy the bicep template defining the VNFD. @@ -396,50 +428,56 @@ def deploy_nsd_from_bicep( :parameters_json_file: path to an override file of set parameters for the nfdv :param manifest_bicep_path: The path to the bicep template of the manifest :param manifest_parameters_json_file: path to an override file of set parameters for the manifest + :param skip: options to skip, either publish bicep or upload artifacts """ assert isinstance(self.config, NSConfiguration) + if not skip == BICEP_PUBLISH: + if not bicep_path: + # User has not passed in a bicep template, so we are deploying the default + # one produced from building the NSDV using this CLI + bicep_path = os.path.join( + self.config.build_output_folder_name, + NSD_BICEP_FILENAME, + ) - if not bicep_path: - # User has not passed in a bicep template, so we are deploying the default - # one produced from building the NSDV using this CLI - bicep_path = os.path.join( - self.config.build_output_folder_name, - NSD_BICEP_FILENAME, - ) + if parameters_json_file: + parameters = self.read_parameters_from_file(parameters_json_file) + else: + # User has not passed in parameters file, so we use the parameters required + # from config for the default bicep template produced from building the + # NSDV using this CLI + logger.debug("Create parameters for default NSDV template.") + parameters = self.construct_nsd_parameters() - if parameters_json_file: - parameters = self.read_parameters_from_file(parameters_json_file) - else: - # User has not passed in parameters file, so we use the parameters required - # from config for the default bicep template produced from building the - # NSDV using this CLI - logger.debug("Create parameters for default NSDV template.") - parameters = self.construct_nsd_parameters() + logger.debug(parameters) - logger.debug(parameters) + # Create or check required resources + deploy_manifest_template = not self.nsd_predeploy() - # Create or check required resources - deploy_manifest_template = not self.nsd_predeploy() + if deploy_manifest_template: + self.deploy_manifest_template( + manifest_parameters_json_file, manifest_bicep_path, NSD + ) + else: + print(f"Artifact manifests {self.config.acr_manifest_name} already exists") - if deploy_manifest_template: - self.deploy_manifest_template( - manifest_parameters_json_file, manifest_bicep_path, NSD + message = ( + f"Deploy bicep template for NSDV {self.config.nsd_version} " + f"into {self.config.publisher_resource_group_name} under publisher " + f"{self.config.publisher_name}" ) - else: - print(f"Artifact manifests {self.config.acr_manifest_name} already exists") + print(message) + logger.info(message) + self.deploy_bicep_template(bicep_path, parameters) + print( + f"Deployed NSD {self.config.nsdg_name} " + f"version {self.config.nsd_version}." + ) + if skip == ARTIFACT_UPLOAD: + print("Skipping artifact upload") + print("Done") + return - message = ( - f"Deploy bicep template for NSDV {self.config.nsd_version} " - f"into {self.config.publisher_resource_group_name} under publisher " - f"{self.config.publisher_name}" - ) - print(message) - logger.info(message) - self.deploy_bicep_template(bicep_path, parameters) - print( - f"Deployed NSD {self.config.acr_manifest_name} version" - f" {self.config.nsd_version}." - ) acr_manifest = ArtifactManifestOperator( self.config, self.api_clients, @@ -694,16 +732,16 @@ def convert_bicep_to_arm(bicep_template_path: str) -> Any: stderr=subprocess.PIPE, ) logger.debug("az bicep output: %s", str(bicep_output)) - except subprocess.CalledProcessError as e: + except subprocess.CalledProcessError as err: logger.error( ( "ARM template compilation failed! See logs for full " "output. The failing command was %s" ), - e.cmd, + err.cmd, ) - logger.debug("bicep build stdout: %s", e.stdout) - logger.debug("bicep build stderr: %s", e.stderr) + logger.debug("bicep build stdout: %s", err.stdout) + logger.debug("bicep build stderr: %s", err.stderr) raise with open( diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 2c26cac4850..1fd21dfcb4f 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -4,12 +4,19 @@ # -------------------------------------------------------------------------------------- """Contains class for deploying resources required by NFDs/NSDs via the SDK.""" +import re from azure.cli.core.azclierror import AzCLIError from azure.core import exceptions as azure_exceptions from azure.mgmt.resource.resources.models import ResourceGroup from knack.log import get_logger -from azext_aosm._configuration import NFConfiguration, NSConfiguration, VNFConfiguration +from azext_aosm._configuration import ( + NFConfiguration, + NSConfiguration, + VNFConfiguration, + CNFConfiguration +) +from azext_aosm.util.constants import SOURCE_ACR_REGEX from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks.models import ( ArtifactStore, @@ -140,23 +147,25 @@ def ensure_config_source_registry_exists(self) -> None: Finds the parameters from self.config """ + assert isinstance(self.config, CNFConfiguration) logger.info( "Check if the source registry %s exists", self.config.source_registry_id, ) - # Assume that the registry id is of the form: /subscriptions/ - # /resourceGroups//providers/Microsoft.ContainerRegistry/registries/ - source_registry_name = self.config.source_registry_id.split("/")[-1] - source_registry_resource_group_name = self.config.source_registry_id.split("/")[ - -5 - ] - - # This will raise an error if the registry does not exist - self.api_clients.container_registry_client.get( - resource_group_name=source_registry_resource_group_name, - registry_name=source_registry_name, - ) + # Match the source registry format + source_registry_match = re.search(SOURCE_ACR_REGEX, self.config.source_registry_id) + # Config validation has already checked and raised an error if the regex doesn't + # match + if source_registry_match and len(source_registry_match.groups()) > 1: + source_registry_resource_group_name = source_registry_match.group('resource_group') + source_registry_name = source_registry_match.group('registry_name') + + # This will raise an error if the registry does not exist + self.api_clients.container_registry_client.get( + resource_group_name=source_registry_resource_group_name, + registry_name=source_registry_name, + ) def ensure_artifact_store_exists( self, diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index febb9d70818..9eef0c0db51 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -198,7 +198,7 @@ def _generate_chart_value_mappings(self, helm_package: HelmPackageConfig) -> Non top_level_values_yaml = self._read_top_level_values_yaml(helm_package) mapping_to_write = self._replace_values_with_deploy_params( - top_level_values_yaml, {} + top_level_values_yaml, None ) # Write the mapping to a file @@ -401,21 +401,36 @@ def find_pattern_matches_in_chart( for file in self._find_yaml_files(chart_dir): with open(file, "r", encoding="UTF-8") as f: + logger.debug("Searching for %s in %s", start_string, file) for line in f: if start_string in line: + logger.debug("Found %s in %s", start_string, line) path = re.findall(IMAGE_PATH_REGEX, line) # If "image:", search for chart name and version if start_string == IMAGE_START_STRING: name_and_version = re.search( IMAGE_NAME_AND_VERSION_REGEX, line ) - matches.append( - ( - path, - name_and_version.group(1), - name_and_version.group(2), + logger.debug( + "Regex match for name and version is %s", + name_and_version ) - ) + + if name_and_version and len(name_and_version.groups()) == 2: + logger.debug( + "Found image name and version %s %s", + name_and_version.group('name'), + name_and_version.group('version') + ) + matches.append( + ( + path, + name_and_version.group('name'), + name_and_version.group('version'), + ) + ) + else: + logger.debug("No image name and version found") else: matches += path return matches @@ -486,6 +501,7 @@ def get_chart_mapping_schema( deploy_params_dict = self.traverse_dict( values_data, DEPLOYMENT_PARAMETER_MAPPING_REGEX ) + logger.debug("Deploy params dict is %s", deploy_params_dict) new_schema = self.search_schema(deploy_params_dict, schema_data) except KeyError as e: raise InvalidTemplateError( @@ -498,7 +514,10 @@ def get_chart_mapping_schema( return new_schema @staticmethod - def traverse_dict(d, target): + def traverse_dict( + dict_to_search: Dict[Any, Any], + target_regex: str + ) -> Dict[str, List[str]]: """ Traverse the dictionary that is loaded from the file provided by path_to_mappings in the input.json. @@ -509,7 +528,8 @@ def traverse_dict(d, target): :param d: The dictionary to traverse. :param target: The regex to search for. """ - stack = [(d, [])] # Initialize the stack with the dictionary and an empty path + # Initialize the stack with the dictionary and an empty path + stack = [(dict_to_search, [])] result = {} # Initialize empty dictionary to store the results while stack: # While there are still items in the stack # Pop the last item from the stack and unpack it into node (the dictionary) and path @@ -521,20 +541,37 @@ def traverse_dict(d, target): # Add the dictionary to the stack with the path stack.append((v, path + [k])) # If the value is a string + matches target regex - elif isinstance(v, str) and re.search(target, v): + elif isinstance(v, str) and re.search(target_regex, v): # Take the match i.e, foo from {deployParameter.foo} - match = re.search(target, v) + match = re.search(target_regex, v) # Add it to the result dictionary with its path as the value result[match.group(1)] = path + [k] elif isinstance(v, list): + logger.debug("Found a list %s", v) for i in v: - if isinstance(i, str) and re.search(target, i): - match = re.search(target, i) + logger.debug("Found an item %s", i) + if isinstance(i, str) and re.search(target_regex, i): + match = re.search(target_regex, i) result[match.group(1)] = path + [k] + elif isinstance(i, dict): + stack.append((i, path + [k])) + elif isinstance(i, list): + # We should fix this but for now just log a warning and + # carry on + logger.warning( + "Values mapping file contains a list of lists " + "at path %s, which this tool cannot parse. " + "Please check the output configMappings and schemas " + "files and check that they are as required.", + path + [k] + ) return result @staticmethod - def search_schema(result, full_schema): + def search_schema( + deployParams_paths: Dict[str, List[str]], + full_schema + ) -> Dict[str, Dict[str, str]]: """ Search through provided schema for the types of the deployment parameters. This assumes that the type of the key will be the type of the deployment parameter. @@ -543,24 +580,41 @@ def search_schema(result, full_schema): Returns a dictionary of the deployment parameters in the format: {"foo": {"type": "string"}, "bar": {"type": "string"}} - param result: The result of the traverse_dict function. + param deployParams_paths: a dictionary of all the deploy parameters to search for, + with the key being the deploy parameter and the value being the + path to the value. + e.g. {"foo": ["global", "foo", "bar"]} param full_schema: The schema to search through. """ new_schema = {} no_schema_list = [] - for deploy_param in result: + for deploy_param, path_list in deployParams_paths.items(): + logger.debug( + "Searching for %s in schema at path %s", deploy_param, path_list + ) node = full_schema - for path_list in result[deploy_param]: + for path in path_list: if "properties" in node.keys(): - node = node["properties"][path_list] + logger.debug( + "Searching properties for %s in schema at path %s", + deploy_param, path + ) + node = node["properties"][path] else: + logger.debug("No schema node found for %s", deploy_param) no_schema_list.append(deploy_param) new_schema.update({deploy_param: {"type": "string"}}) if deploy_param not in new_schema: new_schema.update({deploy_param: {"type": node.get("type", None)}}) if no_schema_list: - print("No schema found for deployment parameter(s):", no_schema_list) - print("We default these parameters to type string") + logger.warning( + "No schema found for deployment parameter(s): %s", no_schema_list + ) + logger.warning( + "We default these parameters to type string. " + "Please edit schemas/%s in the output before publishing " + "if this is wrong", DEPLOYMENT_PARAMETERS_FILENAME + ) return new_schema def _replace_values_with_deploy_params( @@ -608,7 +662,7 @@ def _replace_values_with_deploy_params( final_values_mapping_dict[k].append( self._replace_values_with_deploy_params(item, param_name) ) - elif isinstance(v, (str, int, bool)): + elif isinstance(v, (str, int, bool)) or not v: replacement_value = f"{{deployParameters.{param_name}}}" final_values_mapping_dict[k].append(replacement_value) else: @@ -616,31 +670,9 @@ def _replace_values_with_deploy_params( f"Found an unexpected type {type(v)} of key {k} in " "values.yaml, cannot generate values mapping file." ) - else: - raise ValueError( - f"Found an unexpected type {type(v)} of key {k} in values.yaml, " - "cannot generate values mapping file." - ) - - return final_values_mapping_dict - - def _replace_values_with_deploy_params( - self, - values_yaml_dict, - param_prefix: Optional[str] = None, - ) -> Dict[Any, Any]: - """ - Given the yaml dictionary read from values.yaml, replace all the values with {deploymentParameter.keyname}. - - Thus creating a values mapping file if the user has not provided one in config. - """ - logger.debug("Replacing values with deploy parameters") - final_values_mapping_dict: Dict[Any, Any] = {} - for k, v in values_yaml_dict.items(): - # if value is a string and contains deployParameters. - logger.debug("Processing key %s", k) - param_name = k if param_prefix is None else f"{param_prefix}_{k}" - if isinstance(v, (str, int, bool)): + elif not v: + # V is blank so we don't know what type it is. Assuming it is an + # empty string (but do this after checking for dict and list) # Replace the parameter with {deploymentParameter.keyname} if self.interactive: # Interactive mode. Prompt user to include or exclude parameters @@ -653,30 +685,6 @@ def _replace_values_with_deploy_params( # add the schema for k (from the big schema) to the (smaller) schema final_values_mapping_dict.update({k: replacement_value}) - elif isinstance(v, dict): - final_values_mapping_dict[k] = self._replace_values_with_deploy_params( - v, param_name - ) - elif isinstance(v, list): - final_values_mapping_dict[k] = [] - for index, item in enumerate(v): - param_name = ( - f"{param_prefix}_{k}_{index}" - if param_prefix - else f"{k})_{index}" - ) - if isinstance(item, dict): - final_values_mapping_dict[k].append( - self._replace_values_with_deploy_params(item, param_name) - ) - elif isinstance(v, (str, int, bool)): - replacement_value = f"{{deployParameters.{param_name}}}" - final_values_mapping_dict[k].append(replacement_value) - else: - raise ValueError( - f"Found an unexpected type {type(v)} of key {k} in " - "values.yaml, cannot generate values mapping file." - ) else: raise ValueError( f"Found an unexpected type {type(v)} of key {k} in values.yaml, " diff --git a/src/aosm/azext_aosm/generate_nsd/__init__.py b/src/aosm/azext_aosm/generate_nsd/__init__.py new file mode 100644 index 00000000000..99c0f28cd71 --- /dev/null +++ b/src/aosm/azext_aosm/generate_nsd/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index a6f4dd62006..33dd6596bb0 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -16,17 +16,17 @@ from azext_aosm._configuration import NSConfiguration from azext_aosm.util.constants import ( + CNF, CONFIG_MAPPINGS_DIR_NAME, NF_DEFINITION_BICEP_FILENAME, - NF_TEMPLATE_BICEP_FILENAME, + NF_TEMPLATE_JINJA2_SOURCE_TEMPLATE, NSD_ARTIFACT_MANIFEST_BICEP_FILENAME, NSD_ARTIFACT_MANIFEST_SOURCE_TEMPLATE_FILENAME, NSD_CONFIG_MAPPING_FILENAME, NSD_BICEP_FILENAME, - NSD_SOURCE_TEMPLATE_BICEP_FILENAME, + NSD_DEFINITION_JINJA2_SOURCE_TEMPLATE, SCHEMAS_DIR_NAME, TEMPLATES_DIR_NAME, - VNF, ) from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks.models import NetworkFunctionDefinitionVersion, NFVIType @@ -58,8 +58,8 @@ class NSDGenerator: def __init__(self, api_clients: ApiClients, config: NSConfiguration): self.config = config - self.nsd_bicep_template_name = NSD_SOURCE_TEMPLATE_BICEP_FILENAME - self.nf_bicep_template_name = NF_TEMPLATE_BICEP_FILENAME + self.nsd_bicep_template_name = NSD_DEFINITION_JINJA2_SOURCE_TEMPLATE + self.nf_bicep_template_name = NF_TEMPLATE_JINJA2_SOURCE_TEMPLATE self.nsd_bicep_output_name = NSD_BICEP_FILENAME self.nfdv_parameter_name = ( f"{self.config.network_function_definition_group_name.replace('-', '_')}_nfd_version" @@ -130,7 +130,7 @@ def config_group_schema_dict(self) -> Dict[str, Any]: # Add in the NFDV version as a parameter. description_string = ( f"The version of the {self.config.network_function_definition_group_name} " - "NFD to use. This version must be compatable with (have the same " + "NFD to use. This version must be compatible with (have the same " "parameters exposed as) " f"{self.config.network_function_definition_version_name}." ) @@ -138,19 +138,32 @@ def config_group_schema_dict(self) -> Dict[str, Any]: "type": "string", "description": description_string, } + cgs_dict["required"].append(self.nfdv_parameter_name) managed_identity_description_string = ( "The managed identity to use to deploy NFs within this SNS. This should " - "of the form '/subscriptions/{subscriptionId}/resourceGroups/" + "be of the form '/subscriptions/{subscriptionId}/resourceGroups/" "{resourceGroupName}/providers/Microsoft.ManagedIdentity/" "userAssignedIdentities/{identityName}. " - "The az aosm tool only supports user assigned identities at present, " - "you cannot use a System Assigned identity." + "If you wish to use a system assigned identity, set this to a blank string." ) cgs_dict["properties"]["managedIdentity"] = { "type": "string", "description": managed_identity_description_string, } + cgs_dict["required"].append("managedIdentity") + + if self.config.network_function_type == CNF: + custom_location_description_string = ( + "The custom location ID of the ARC-Enabled AKS Cluster to deploy the CNF " + "to. Should be of the form " + "'/subscriptions/{subscriptionId}/resourcegroups" + "/{resourceGroupName}/providers/microsoft.extendedlocation/" + "customlocations/{customLocationName}'" + ) + cgs_dict["properties"]["customLocationId"] = \ + {"type": "string", "description": custom_location_description_string} + cgs_dict["required"].append("customLocationId") return cgs_dict @@ -208,16 +221,21 @@ def write_nf_bicep(self) -> None: bicep_deploymentValues = "" - if "properties" not in self.deploy_parameters: + if not self.deploy_parameters or not self.deploy_parameters.get("properties"): raise ValueError( f"NFDV in {self.config.network_function_definition_group_name} has " "no properties within deployParameters" ) deploy_properties = self.deploy_parameters["properties"] + logger.debug("Deploy properties: %s", deploy_properties) for key, value in deploy_properties.items(): # location is sometimes part of deploy_properties. # We want to avoid having duplicate params in the bicep template + logger.debug( + "Adding deploy parameter key: %s, value: %s to nf template", + key, + value) if key != "location": bicep_type = ( NFV_TO_BICEP_PARAM_TYPES.get(value["type"]) or value["type"] @@ -247,10 +265,11 @@ def write_nf_bicep(self) -> None: # NF, as we do for deployParameters, but the SDK currently doesn't # support this and needs to be rebuilt to do so. "nfvi_type": ( - NFVIType.AZURE_CORE + NFVIType.AZURE_CORE.value if self.config.network_function_type == VNF else NFVIType.AZURE_ARC_KUBERNETES.value ), + "CNF": True if self.config.network_function_type == CNF else False, }, ) @@ -279,7 +298,10 @@ def write_nsd_manifest(self) -> None: {}, ) - def generate_bicep(self, template_name, output_file_name, params) -> None: + def generate_bicep(self, + template_name: str, + output_file_name: str, + params: Dict[Any,Any]) -> None: """ Render the bicep templates with the correct parameters and copy them into the build output folder. diff --git a/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep b/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep.j2 similarity index 79% rename from src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep rename to src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep.j2 index 89a2362e8ec..8cf4a207a23 100644 --- a/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep +++ b/src/aosm/azext_aosm/generate_nsd/templates/nf_template.bicep.j2 @@ -18,6 +18,11 @@ param networkFunctionDefinitionOfferingLocation string = '{{network_function_def @description('The managed identity that should be used to create the NF.') param managedIdentity string +{%- if CNF %} +@description('The custom location of the ARC-enabled AKS cluster to create the NF.') +param customLocationId string +{%- endif %} + param location string = '{{location}}' param nfviType string = '{{nfvi_type}}' @@ -30,15 +35,19 @@ var deploymentValues = { {{deploymentValues}} } +var identityObject = (managedIdentity == '') ? { + type: 'SystemAssigned' +} : { + type: 'UserAssigned' + userAssignedIdentities: { + '${managedIdentity}': {} + } +} + resource nf_resource 'Microsoft.HybridNetwork/networkFunctions@2023-04-01-preview' = { name: '{{network_function_name}}' location: location - identity: { - type: 'UserAssigned' - userAssignedIdentities: { - '${managedIdentity}': {} - } - } + identity: identityObject properties: { publisherName: publisherName publisherScope: 'Private' @@ -46,7 +55,11 @@ resource nf_resource 'Microsoft.HybridNetwork/networkFunctions@2023-04-01-previe networkFunctionDefinitionVersion: {{network_function_definition_version_parameter}} networkFunctionDefinitionOfferingLocation: networkFunctionDefinitionOfferingLocation nfviType: nfviType +{%- if CNF %} + nfviId: customLocationId +{%- else %} nfviId: resourceGroupId +{%- endif %} allowSoftwareUpdate: true deploymentValues: string(deploymentValues) } diff --git a/src/aosm/azext_aosm/generate_nsd/templates/nsd_template.bicep b/src/aosm/azext_aosm/generate_nsd/templates/nsd_template.bicep.j2 similarity index 92% rename from src/aosm/azext_aosm/generate_nsd/templates/nsd_template.bicep rename to src/aosm/azext_aosm/generate_nsd/templates/nsd_template.bicep.j2 index 0f777e01780..3570adf0247 100644 --- a/src/aosm/azext_aosm/generate_nsd/templates/nsd_template.bicep +++ b/src/aosm/azext_aosm/generate_nsd/templates/nsd_template.bicep.j2 @@ -98,12 +98,11 @@ resource nsdVersion 'Microsoft.Hybridnetwork/publishers/networkservicedesigngrou templateType: 'ArmTemplate' // The parameter values map values from the CG schema, to values required by the template // deployed by this resource element. - // outputParameters from the disk RET are used in these parameterValues // This NSD does not support the NF-Agent as it has no Configuration Resource Elements. - // If Configuration resource elements (SDFs, Perimeta config) are added, the simplNfConfigMapping + // If Configuration resource elements (SDFs, Perimeta config) are added, the configMapping // must be edited to have these lines (instead of blank values. SNSSelf is null if there are no Configuration elements) - // "nfAgentServiceBusNamespace": "{configurationparameters('SNSSelf').nfAgentConfiguration.resourceNamespace}", - // "nfAgentUserAssignedIdentityResourceId": "{configurationparameters('SNSSelf').nfAgentConfiguration.userAssignedIdentityResourceId}", + // "": "{configurationparameters('SNSSelf').nfAgentConfiguration.resourceNamespace}", + // "": "{configurationparameters('SNSSelf').nfAgentConfiguration.userAssignedIdentityResourceId}", parameterValues: string(loadJsonContent('configMappings/configMappings.json')) } dependsOnProfile: { diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index 960463db610..cf76d00f895 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -10,12 +10,17 @@ NSD = "nsd" SCHEMA = "schema" +# Skip steps +BICEP_PUBLISH = "bicep-publish" +ARTIFACT_UPLOAD = "artifact-upload" + # Names of files used in the repo -NF_TEMPLATE_BICEP_FILENAME = "nf_template.bicep" + +NF_TEMPLATE_JINJA2_SOURCE_TEMPLATE = "nf_template.bicep.j2" NF_DEFINITION_BICEP_FILENAME = "nf_definition.bicep" NF_DEFINITION_JSON_FILENAME = "nf_definition.json" NF_DEFINITION_OUTPUT_BICEP_PREFIX = "nfd-bicep-" -NSD_SOURCE_TEMPLATE_BICEP_FILENAME = "nsd_template.bicep" +NSD_DEFINITION_JINJA2_SOURCE_TEMPLATE = "nsd_template.bicep.j2" NSD_BICEP_FILENAME = "nsd_definition.bicep" NSD_OUTPUT_BICEP_PREFIX = "nsd-bicep-templates" NSD_ARTIFACT_MANIFEST_BICEP_FILENAME = "artifact_manifest.bicep" @@ -68,6 +73,15 @@ # To match the image name and version if 'imagePullSecrets:' is present in the yaml file IMAGE_PULL_SECRETS_START_STRING = "imagePullSecrets:" -IMAGE_NAME_AND_VERSION_REGEX = r"\/([^\s]*):([^\s)\"}]*)" +IMAGE_NAME_AND_VERSION_REGEX = r"\/(?P[^\s]*):(?P[^\s)\"}]*)" DEPLOYMENT_PARAMETER_MAPPING_REGEX = r"\{deployParameters.(.+?)\}" + +# Assume that the registry id is of the form: +# /subscriptions//resourceGroups//providers/ +# Microsoft.ContainerRegistry/registries/ +# This returns groups for the resource group name and registry name +SOURCE_ACR_REGEX = ( + r".*\/resourceGroups\/(?P[^\/]*)\/providers\/Microsoft." + r"ContainerRegistry\/registries\/(?P[^\/]*)" + ) From ad88098f9cb83f0a840980df58d2cbfbf56482cc Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Tue, 4 Jul 2023 12:45:47 +0100 Subject: [PATCH 126/145] NSD UTs --- src/aosm/azext_aosm/custom.py | 2 +- .../tests/latest/mock_nsd/input.json | 13 +++ src/aosm/azext_aosm/tests/latest/test_cnf.py | 20 +++- src/aosm/azext_aosm/tests/latest/test_nsd.py | 93 ++++++++++++++++++- src/aosm/azext_aosm/tests/latest/test_vnf.py | 19 +++- 5 files changed, 137 insertions(+), 10 deletions(-) create mode 100644 src/aosm/azext_aosm/tests/latest/mock_nsd/input.json diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 76b61481efa..5843378c0b5 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -249,7 +249,7 @@ def _generate_config(configuration_type: str, output_file: str = "input.json"): # be included here. config = asdict(get_configuration(configuration_type)) config.pop("config_file") - + config_as_dict = json.dumps(config, indent=4) if os.path.exists(output_file): diff --git a/src/aosm/azext_aosm/tests/latest/mock_nsd/input.json b/src/aosm/azext_aosm/tests/latest/mock_nsd/input.json new file mode 100644 index 00000000000..8cccdaebfa8 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_nsd/input.json @@ -0,0 +1,13 @@ +{ + "location": "eastus", + "publisher_name": "jamie-mobile-publisher", + "publisher_resource_group_name": "Jamie-publisher", + "acr_artifact_store_name": "ubuntu-acr", + "network_function_definition_group_name": "ubuntu-vm-nfdg", + "network_function_definition_version_name": "1.0.0", + "network_function_definition_offering_location": "eastus", + "network_function_type": "vnf", + "nsdg_name": "ubuntu", + "nsd_version": "1.0.0", + "nsdv_description": "Plain ubuntu VM" +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/test_cnf.py b/src/aosm/azext_aosm/tests/latest/test_cnf.py index 491f20dcd42..51da54063ec 100644 --- a/src/aosm/azext_aosm/tests/latest/test_cnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_cnf.py @@ -13,7 +13,7 @@ from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig -from azext_aosm.custom import build_definition +from azext_aosm.custom import build_definition, generate_definition_config from azure.cli.core.azclierror import ( BadRequestError, @@ -43,6 +43,20 @@ def test_invalid_chart(self): class TestCNF(unittest.TestCase): + def test_generate_config(self): + """ + Test generating a config file for a VNF. + """ + starting_directory = os.getcwd() + with TemporaryDirectory() as test_dir: + os.chdir(test_dir) + + try: + generate_definition_config("cnf") + assert os.path.exists("input.json") + finally: + os.chdir(starting_directory) + def test_build(self): """ Test the build command for CNFs. @@ -59,8 +73,8 @@ def test_build(self): assert os.path.exists("nfd-bicep-ubuntu-template") finally: os.chdir(starting_directory) - - def test_no_mapping(self): + + def test_build_no_mapping(self): """ Test the build command for CNFs where no mapping file is supplied. diff --git a/src/aosm/azext_aosm/tests/latest/test_nsd.py b/src/aosm/azext_aosm/tests/latest/test_nsd.py index da13e3fa3e2..f3495054d9c 100644 --- a/src/aosm/azext_aosm/tests/latest/test_nsd.py +++ b/src/aosm/azext_aosm/tests/latest/test_nsd.py @@ -4,11 +4,94 @@ # -------------------------------------------------------------------------------------------- import os -import unittest -from unittest.mock import Mock, patch +from dataclasses import dataclass +import json +from unittest.mock import patch +from tempfile import TemporaryDirectory +from typing import Any, Dict + +from azext_aosm.custom import generate_design_config, build_design + +mock_nsd_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_nsd") -from azext_aosm.generate_nsd.nsd_generator import NSDGenerator class TestNSDGenerator(): - def test_create(self): - pass \ No newline at end of file + def test_generate_config(self): + """ + Test generating a config file for a VNF. + """ + starting_directory = os.getcwd() + with TemporaryDirectory() as test_dir: + os.chdir(test_dir) + + try: + generate_design_config() + assert os.path.exists("input.json") + finally: + os.chdir(starting_directory) + + @patch("azext_aosm.custom.cf_resources") + def test_build(self, cf_resources): + """ + Test building the NSD bicep templates. + """ + # We don't want to get details from a real NFD (calling out to Azure) in a UT. + # Therefore we pass in a fake client to supply the deployment parameters from + # the "NFD". + deploy_parameters = { + "$schema": "https://json-schema.org/draft-07/schema#", + "title": "DeployParametersSchema", + "type": "object", + "properties": { + "location": { + "type": "string" + }, + "subnetName": { + "type": "string" + }, + "virtualNetworkId": { + "type": "string" + }, + "sshPublicKeyAdmin": { + "type": "string" + } + } + } + + deploy_parameters_string = json.dumps(deploy_parameters) + + @dataclass + class NFDV: + deploy_parameters: Dict[str, Any] + + nfdv = NFDV(deploy_parameters_string) + + class NFDVs(): + def get(self, **_): + return nfdv + + class AOSMClient(): + def __init__(self) -> None: + self.network_function_definition_versions = NFDVs() + + mock_client = AOSMClient() + + class FakeCmd(): + def __init__(self) -> None: + self.cli_ctx = None + + cmd = FakeCmd() + + starting_directory = os.getcwd() + with TemporaryDirectory() as test_dir: + os.chdir(test_dir) + + try: + build_design( + cmd, + client=mock_client, + config_file=os.path.join(mock_nsd_folder, "input.json") + ) + assert os.path.exists("nsd-bicep-templates") + finally: + os.chdir(starting_directory) diff --git a/src/aosm/azext_aosm/tests/latest/test_vnf.py b/src/aosm/azext_aosm/tests/latest/test_vnf.py index 8aae15f2e1c..41bad660cd8 100644 --- a/src/aosm/azext_aosm/tests/latest/test_vnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_vnf.py @@ -8,13 +8,30 @@ from unittest.mock import Mock, patch from tempfile import TemporaryDirectory -from azext_aosm.custom import build_definition +from azext_aosm.custom import build_definition, generate_definition_config mock_vnf_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_vnf") class TestVNF(unittest.TestCase): + def test_generate_config(self): + """ + Test generating a config file for a VNF. + """ + starting_directory = os.getcwd() + with TemporaryDirectory() as test_dir: + os.chdir(test_dir) + + try: + generate_definition_config("vnf") + assert os.path.exists("input.json") + finally: + os.chdir(starting_directory) + def test_build(self): + """ + Test building an NFDV for a VNF. + """ starting_directory = os.getcwd() with TemporaryDirectory() as test_dir: os.chdir(test_dir) From de248c1d77545f14bf6902ad229118345ea9f453 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Tue, 4 Jul 2023 15:08:05 +0100 Subject: [PATCH 127/145] Update read me. --- src/aosm/README.md | 22 +++++++++ .../generate_nfd/cnf_nfd_generator.py | 10 ++--- .../azext_aosm/generate_nsd/nsd_generator.py | 5 ++- src/aosm/azext_aosm/tests/latest/test_cnf.py | 45 +------------------ src/aosm/azext_aosm/tests/latest/test_vnf.py | 20 ++++++++- src/aosm/azext_aosm/util/constants.py | 2 +- 6 files changed, 51 insertions(+), 53 deletions(-) diff --git a/src/aosm/README.md b/src/aosm/README.md index f1cc088e5d6..d28dd58d2bd 100644 --- a/src/aosm/README.md +++ b/src/aosm/README.md @@ -175,3 +175,25 @@ Delete a published design Delete a published design and the publisher, artifact stores and NSD group `az aosm nsd delete --config-file input.json --clean` + +# Development + +## Unit tests +To run unit tests run `azdev test aosm`. + +To get code coverage run: +```bash +pip install coverage +cd src/aosm +coverage erase +coverage run -m pytest . +coverage report --include="*/src/aosm/*" --omit="*/src/aosm/azext_aosm/vendored_sdks/*","*/src/aosm/azext_aosm/tests/*" -m +``` + +## Pipelines +The pipelines for the Azure CLI run in ADO, not in github. +To trigger a pipeline you need to create a PR against main. +Until we do the initial merge to main we don't want to have a PR to main for every code review. +Instead we have a single PR for the `add-aosm-extension` branch: https://github.com/Azure/azure-cli-extensions/pull/6426 +Once you have merged your changes to `add-aosm-extension` then look at the Azure Pipelines under https://github.com/Azure/azure-cli-extensions/pull/6426/checks, click on the link that says ` errors / warnings`. + diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 9eef0c0db51..9c53a5f74a6 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -192,7 +192,7 @@ def _generate_chart_value_mappings(self, helm_package: HelmPackageConfig) -> Non logger.debug( "Creating chart value mappings file for %s", helm_package.path_to_chart ) - print("Creating chart value mappings file for %s", helm_package.path_to_chart) + print(f"Creating chart value mappings file for {helm_package.path_to_chart}.") # Get all the values files in the chart top_level_values_yaml = self._read_top_level_values_yaml(helm_package) @@ -414,7 +414,7 @@ def find_pattern_matches_in_chart( logger.debug( "Regex match for name and version is %s", name_and_version - ) + ) if name_and_version and len(name_and_version.groups()) == 2: logger.debug( @@ -517,7 +517,7 @@ def get_chart_mapping_schema( def traverse_dict( dict_to_search: Dict[Any, Any], target_regex: str - ) -> Dict[str, List[str]]: + ) -> Dict[str, List[str]]: """ Traverse the dictionary that is loaded from the file provided by path_to_mappings in the input.json. @@ -571,7 +571,7 @@ def traverse_dict( def search_schema( deployParams_paths: Dict[str, List[str]], full_schema - ) -> Dict[str, Dict[str, str]]: + ) -> Dict[str, Dict[str, str]]: """ Search through provided schema for the types of the deployment parameters. This assumes that the type of the key will be the type of the deployment parameter. @@ -591,7 +591,7 @@ def search_schema( for deploy_param, path_list in deployParams_paths.items(): logger.debug( "Searching for %s in schema at path %s", deploy_param, path_list - ) + ) node = full_schema for path in path_list: if "properties" in node.keys(): diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index 33dd6596bb0..b0fc198878e 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -27,6 +27,7 @@ NSD_DEFINITION_JINJA2_SOURCE_TEMPLATE, SCHEMAS_DIR_NAME, TEMPLATES_DIR_NAME, + VNF ) from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks.models import NetworkFunctionDefinitionVersion, NFVIType @@ -138,7 +139,7 @@ def config_group_schema_dict(self) -> Dict[str, Any]: "type": "string", "description": description_string, } - cgs_dict["required"].append(self.nfdv_parameter_name) + cgs_dict.setdefault("required", []).append(self.nfdv_parameter_name) managed_identity_description_string = ( "The managed identity to use to deploy NFs within this SNS. This should " @@ -301,7 +302,7 @@ def write_nsd_manifest(self) -> None: def generate_bicep(self, template_name: str, output_file_name: str, - params: Dict[Any,Any]) -> None: + params: Dict[Any, Any]) -> None: """ Render the bicep templates with the correct parameters and copy them into the build output folder. diff --git a/src/aosm/azext_aosm/tests/latest/test_cnf.py b/src/aosm/azext_aosm/tests/latest/test_cnf.py index 51da54063ec..ea877ef57ab 100644 --- a/src/aosm/azext_aosm/tests/latest/test_cnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_cnf.py @@ -33,15 +33,6 @@ invalid_helm_package = test_cnf.config.helm_packages[0] -# pylint: disable=protected-access -class TestExtractChart(unittest.TestCase): - # Jordan: can we test whether this has extracted correctly in a unit test? - def test_invalid_chart(self): - with self.assertRaises(InvalidTemplateError): - print("TEST", invalid_helm_package) - test_cnf._extract_chart(invalid_helm_package.path_to_chart) - - class TestCNF(unittest.TestCase): def test_generate_config(self): """ @@ -70,7 +61,7 @@ def test_build(self): "cnf", os.path.join(mock_cnf_folder, "input-nfconfigchart.json") ) - assert os.path.exists("nfd-bicep-ubuntu-template") + assert os.path.exists("nfd-bicep-nginx-basic-test") finally: os.chdir(starting_directory) @@ -90,38 +81,6 @@ def test_build_no_mapping(self): os.path.join(mock_cnf_folder, "input-nf-agent-cnf.json"), order_params=True ) - assert os.path.exists("nfd-bicep-ubuntu-template") + assert os.path.exists("nfd-bicep-nf-agent-cnf") finally: os.chdir(starting_directory) - - -class TestGenerateChartValueMappings(unittest.TestCase): - # Test for _read_top_level_values_yaml - # Test for _replace_values_with_deploy_params - def test_write_mappings_to_file(self): - pass - - def test_update_path_to_mappings(self): - pass - - -class TestGetChartMappingSchema(unittest.TestCase): - # Test for traverse_dict - # Test for search_schema - pass - - -class TestFindPatternMatchesInChart(unittest.TestCase): - pass - - -class TestGenerateNFApplicationConfig(unittest.TestCase): - pass - - -class TestGetArtifactList(unittest.TestCase): - pass - - -class TestWriteFilesToOutput(unittest.TestCase): - pass diff --git a/src/aosm/azext_aosm/tests/latest/test_vnf.py b/src/aosm/azext_aosm/tests/latest/test_vnf.py index 41bad660cd8..008c3c29e63 100644 --- a/src/aosm/azext_aosm/tests/latest/test_vnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_vnf.py @@ -5,7 +5,6 @@ import os import unittest -from unittest.mock import Mock, patch from tempfile import TemporaryDirectory from azext_aosm.custom import build_definition, generate_definition_config @@ -27,7 +26,7 @@ def test_generate_config(self): assert os.path.exists("input.json") finally: os.chdir(starting_directory) - + def test_build(self): """ Test building an NFDV for a VNF. @@ -41,3 +40,20 @@ def test_build(self): assert os.path.exists("nfd-bicep-ubuntu-template") finally: os.chdir(starting_directory) + + def test_build_with_ordered_params(self): + """ + Test building an NFDV for a VNF. + """ + starting_directory = os.getcwd() + with TemporaryDirectory() as test_dir: + os.chdir(test_dir) + + try: + build_definition( + "vnf", + os.path.join(mock_vnf_folder, "input.json"), + order_params=True) + assert os.path.exists("nfd-bicep-ubuntu-template") + finally: + os.chdir(starting_directory) diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index cf76d00f895..2c42de41a3e 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -84,4 +84,4 @@ SOURCE_ACR_REGEX = ( r".*\/resourceGroups\/(?P[^\/]*)\/providers\/Microsoft." r"ContainerRegistry\/registries\/(?P[^\/]*)" - ) +) From 0497ec755b9e37f6084fd7af88362c9030409261 Mon Sep 17 00:00:00 2001 From: Cyclam <95434717+Cyclam@users.noreply.github.com> Date: Tue, 4 Jul 2023 16:45:51 +0100 Subject: [PATCH 128/145] Improve path handling, other small refactorings (#39) # Main changes ## Make methods relying on self._tmp_dir private - `self._tmp_dir` is only available in the context of calling `generate_nfd()`, so methods relying on `self._tmp_dir` should be private ## Use pathlib.Path rather than os file operations - Provides clearer and stronger typing than passing `str`s around - Adds some handy utility functions ## Variable renaming for clarity - E.g. consistently use 'directory' / 'dir' (rather than mix with 'folder') - Obvs somewhat subjective, but as someone new to most of this code, the changes made sense to me ## Add nfd_bicep_path as abstract property on NFDGenerator - We rely on it when calling the concrete implementations - Also use ABC rather than raise NotImplementedError ## Miscellaneous style updates to keep `azdev style aosm` happy - isort - black --- src/aosm/azext_aosm/_configuration.py | 20 +- src/aosm/azext_aosm/custom.py | 17 +- src/aosm/azext_aosm/deploy/artifact.py | 8 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 4 +- .../generate_nfd/cnf_nfd_generator.py | 288 ++++++++---------- .../generate_nfd/nfd_generator_base.py | 15 +- .../generate_nfd/vnf_nfd_generator.py | 124 ++++---- .../azext_aosm/generate_nsd/nsd_generator.py | 2 +- src/aosm/azext_aosm/util/constants.py | 3 +- 9 files changed, 230 insertions(+), 251 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index f933e3bd524..a36cca1bba5 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -13,7 +13,7 @@ NSD, NSD_OUTPUT_BICEP_PREFIX, VNF, - SOURCE_ACR_REGEX + SOURCE_ACR_REGEX, ) DESCRIPTION_MAP: Dict[str, str] = { @@ -229,7 +229,7 @@ def network_function_name(self) -> str: @property def acr_manifest_name(self) -> str: """Return the ACR manifest name from the NFD name.""" - sanitised_nf_name = self.network_function_name.lower().replace('_', '-') + sanitised_nf_name = self.network_function_name.lower().replace("_", "-") return ( f"{sanitised_nf_name}-nsd-acr-manifest-{self.nsd_version.replace('.', '-')}" ) @@ -329,10 +329,10 @@ def sa_manifest_name(self) -> str: return f"{sanitized_nf_name}-sa-manifest-{self.version.replace('.', '-')}" @property - def build_output_folder_name(self) -> str: + def output_directory_for_build(self) -> Path: """Return the local folder for generating the bicep template to.""" - arm_template_path = self.arm_template.file_path - return f"{NF_DEFINITION_OUTPUT_BICEP_PREFIX}{Path(str(arm_template_path)).stem}" + arm_template_name = Path(self.arm_template.file_path).stem + return Path(f"{NF_DEFINITION_OUTPUT_BICEP_PREFIX}{arm_template_name}") @dataclass @@ -362,9 +362,9 @@ def __post_init__(self): self.helm_packages[package_index] = HelmPackageConfig(**dict(package)) @property - def build_output_folder_name(self) -> str: - """Return the local folder for generating the bicep template to.""" - return f"{NF_DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}" + def output_directory_for_build(self) -> Path: + """Return the directory the build command will writes its output to""" + return Path(f"{NF_DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}") def validate(self): """Validate the CNF config @@ -379,7 +379,9 @@ def validate(self): if not source_registry_match or len(source_registry_match.groups()) < 2: raise ValidationError( "CNF config has an invalid source registry ID. Please run `az aosm " - "nfd generate-config` to see the valid formats.") + "nfd generate-config` to see the valid formats." + ) + def get_configuration( configuration_type: str, config_as_dict: Optional[Dict[Any, Any]] = None diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index bbe7ed00abd..e69d35e8780 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -7,6 +7,7 @@ import os import shutil from dataclasses import asdict +from pathlib import Path from typing import Optional from azure.cli.core.azclierror import ( @@ -116,15 +117,15 @@ def _generate_nfd( "Generate NFD called for unrecognised definition_type. Only VNF and CNF" " have been implemented." ) - if nfd_generator.bicep_path: + if nfd_generator.nfd_bicep_path: carry_on = input( - f"The folder {os.path.dirname(nfd_generator.bicep_path)} already exists -" + f"The {nfd_generator.nfd_bicep_path.parent} directory already exists -" " delete it and continue? (y/n)" ) if carry_on != "y": - raise UnclassifiedUserFault("User aborted! ") + raise UnclassifiedUserFault("User aborted!") - shutil.rmtree(os.path.dirname(nfd_generator.bicep_path)) + shutil.rmtree(nfd_generator.nfd_bicep_path.parent) nfd_generator.generate_nfd() @@ -177,7 +178,7 @@ def publish_definition( parameters_json_file=parameters_json_file, manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, - skip=skip + skip=skip, ) elif definition_type == CNF: deployer = DeployerViaArm(api_clients, config=config) @@ -187,7 +188,7 @@ def publish_definition( parameters_json_file=parameters_json_file, manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, - skip=skip + skip=skip, ) else: raise ValueError( @@ -253,7 +254,7 @@ def _generate_config(configuration_type: str, output_file: str = "input.json"): config = get_configuration(configuration_type) config_as_dict = json.dumps(asdict(config), indent=4) - if os.path.exists(output_file): + if Path(output_file).exists(): carry_on = input( f"The file {output_file} already exists - do you want to overwrite it?" " (y/n)" @@ -369,7 +370,7 @@ def publish_design( parameters_json_file=parameters_json_file, manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, - skip=skip + skip=skip, ) diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 7e5d03bd532..614b38d5784 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -5,10 +5,12 @@ """A module to handle interacting with artifacts.""" import subprocess from dataclasses import dataclass -from typing import Union, List +from typing import List, Union from azure.cli.core.commands import LongRunningOperation -from azure.mgmt.containerregistry.models import ImportImageParameters, ImportSource +from azure.mgmt.containerregistry import ContainerRegistryManagementClient +from azure.mgmt.containerregistry.models import (ImportImageParameters, + ImportSource) from azure.storage.blob import BlobClient, BlobType from knack.log import get_logger from knack.util import CLIError @@ -157,7 +159,7 @@ def copy_image( :param source_image: source image :param target_registry_resource_group_name: target registry resource group name :param target_registry_name: target registry name - :param target_tags: the list of tags to be applied to the imported image + :param target_tags: the list of tags to be applied to the imported image should be of form: namepace/name:tag or name:tag :param mode: mode for import """ diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index e0251be0351..a0746a2045e 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -5,7 +5,6 @@ """Contains class for deploying generated definitions using ARM.""" import json import os -import re import shutil import subprocess # noqa import tempfile @@ -37,7 +36,6 @@ VNF, VNF_DEFINITION_BICEP_TEMPLATE_FILENAME, VNF_MANIFEST_BICEP_TEMPLATE_FILENAME, - SOURCE_ACR_REGEX, ) from azext_aosm.util.management_clients import ApiClients @@ -120,7 +118,7 @@ def deploy_vnfd_from_bicep( # User has not passed in a bicep template, so we are deploying the default # one produced from building the NFDV using this CLI bicep_path = os.path.join( - self.config.build_output_folder_name, + self.config.output_directory_for_build, VNF_DEFINITION_BICEP_TEMPLATE_FILENAME, ) diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 9eef0c0db51..deec27f7306 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -4,11 +4,11 @@ # -------------------------------------------------------------------------------------- """Contains a class for generating CNF NFDs and associated resources.""" import json -import os import re import shutil import tarfile import tempfile +from pathlib import Path from typing import Any, Dict, Iterator, List, Optional, Tuple import yaml @@ -23,6 +23,7 @@ CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE_FILENAME, CNF_MANIFEST_BICEP_TEMPLATE_FILENAME, CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE_FILENAME, + CNF_VALUES_SCHEMA_FILENAME, CONFIG_MAPPINGS_DIR_NAME, DEPLOYMENT_PARAMETER_MAPPING_REGEX, DEPLOYMENT_PARAMETERS_FILENAME, @@ -59,38 +60,37 @@ def __init__(self, config: CNFConfiguration, interactive: bool = False): mapping file in config to be blank. """ self.config = config - self.nfd_jinja2_template_path = os.path.join( - os.path.dirname(__file__), - "templates", - CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE_FILENAME, + self.nfd_jinja2_template_path = ( + Path(__file__).parent + / "templates" + / CNF_DEFINITION_JINJA2_SOURCE_TEMPLATE_FILENAME ) - self.manifest_jinja2_template_path = os.path.join( - os.path.dirname(__file__), - "templates", - CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE_FILENAME, + self.manifest_jinja2_template_path = ( + Path(__file__).parent + / "templates" + / CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE_FILENAME ) - self.output_folder_name = self.config.build_output_folder_name + self.output_directory: Path = self.config.output_directory_for_build + self._cnfd_bicep_path = ( + self.output_directory / CNF_DEFINITION_BICEP_TEMPLATE_FILENAME + ) + self._tmp_dir: Optional[Path] = None self.artifacts = [] self.nf_application_configurations = [] self.deployment_parameter_schema = SCHEMA_PREFIX - - self._bicep_path = os.path.join( - self.output_folder_name, CNF_DEFINITION_BICEP_TEMPLATE_FILENAME - ) self.interactive = interactive - self._tmp_folder_name = "" def generate_nfd(self) -> None: """Generate a CNF NFD which comprises a group, an Artifact Manifest and an NFDV.""" - # Create temporary folder. + # Create temporary directory. with tempfile.TemporaryDirectory() as tmpdirname: - self._tmp_folder_name = tmpdirname + self._tmp_dir = Path(tmpdirname) try: for helm_package in self.config.helm_packages: - # Unpack the chart into the tmp folder - self._extract_chart(helm_package.path_to_chart) + # Unpack the chart into the tmp directory + self._extract_chart(Path(helm_package.path_to_chart)) # TODO: Validate charts @@ -99,15 +99,15 @@ def generate_nfd(self) -> None: self._generate_chart_value_mappings(helm_package) # Get schema for each chart - # (extract mappings and take the schema bits we need from values.schema.json) + # (extract mappings and relevant parts of the schema) # + Add that schema to the big schema. self.deployment_parameter_schema["properties"].update( - self.get_chart_mapping_schema(helm_package) + self._get_chart_mapping_schema(helm_package) ) # Get all image line matches for files in the chart. # Do this here so we don't have to do it multiple times. - image_line_matches = self.find_pattern_matches_in_chart( + image_line_matches = self._find_pattern_matches_in_chart( helm_package, IMAGE_START_STRING ) # Creates a flattened list of image registry paths to prevent set error @@ -118,28 +118,28 @@ def generate_nfd(self) -> None: # Generate the NF application configuration for the chart # passed to jinja2 renderer to render bicep template self.nf_application_configurations.append( - self.generate_nf_application_config( + self._generate_nf_application_config( helm_package, image_registry_paths, - self.find_pattern_matches_in_chart( + self._find_pattern_matches_in_chart( helm_package, IMAGE_PULL_SECRETS_START_STRING ), ) ) # Workout the list of artifacts for the chart and # update the list for the NFD with any unique artifacts. - chart_artifacts = self.get_artifact_list( + chart_artifacts = self._get_artifact_list( helm_package, image_line_matches ) self.artifacts += [ a for a in chart_artifacts if a not in self.artifacts ] - self.write_nfd_bicep_file() - self.write_schema_to_file() - self.write_manifest_bicep_file() - self.copy_to_output_folder() + self._write_nfd_bicep_file() + self._write_schema_to_file() + self._write_manifest_bicep_file() + self._copy_to_output_directory() print( - f"Generated NFD bicep template created in {self.output_folder_name}" + f"Generated NFD bicep template created in {self.output_directory}" ) print( "Please review these templates." @@ -151,30 +151,29 @@ def generate_nfd(self) -> None: raise e @property - def bicep_path(self) -> Optional[str]: + def nfd_bicep_path(self) -> Optional[Path]: """Returns the path to the bicep file for the NFD if it has been created.""" - if os.path.exists(self._bicep_path): - return self._bicep_path - + if self._cnfd_bicep_path.exists(): + return self._cnfd_bicep_path return None - def _extract_chart(self, path: str) -> None: + def _extract_chart(self, path: Path) -> None: """ - Extract the chart into the tmp folder. + Extract the chart into the tmp directory. :param path: The path to helm package """ logger.debug("Extracting helm package %s", path) - (_, ext) = os.path.splitext(path) - if ext in (".gz", ".tgz"): + file_extension = path.suffix + if file_extension in (".gz", ".tgz"): with tarfile.open(path, "r:gz") as tar: - tar.extractall(path=self._tmp_folder_name) + tar.extractall(path=self._tmp_dir) - elif ext == ".tar": + elif file_extension == ".tar": with tarfile.open(path, "r:") as tar: - tar.extractall(path=self._tmp_folder_name) + tar.extractall(path=self._tmp_dir) else: raise InvalidTemplateError( @@ -202,12 +201,10 @@ def _generate_chart_value_mappings(self, helm_package: HelmPackageConfig) -> Non ) # Write the mapping to a file - folder_name = os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS_DIR_NAME) - os.makedirs(folder_name, exist_ok=True) - mapping_filepath = os.path.join( - self._tmp_folder_name, - GENERATED_VALUES_MAPPINGS_DIR_NAME, - f"{helm_package.name}-generated-mapping.yaml", + mapping_directory: Path = self._tmp_dir / GENERATED_VALUES_MAPPINGS_DIR_NAME + mapping_directory.mkdir(exist_ok=True) + mapping_filepath = ( + mapping_directory / f"{helm_package.name}-generated-mapping.yaml" ) with open(mapping_filepath, "w", encoding="UTF-8") as mapping_file: yaml.dump(mapping_to_write, mapping_file) @@ -227,13 +224,9 @@ def _read_top_level_values_yaml( :return: A dictionary of the yaml read from the file :rtype: Dict[str, Any] """ - for file in os.listdir(os.path.join(self._tmp_folder_name, helm_package.name)): - if file in ("values.yaml", "values.yml"): - with open( - os.path.join(self._tmp_folder_name, helm_package.name, file), - "r", - encoding="UTF-8", - ) as values_file: + for file in Path(self._tmp_dir / helm_package.name).iterdir(): + if file.name in ("values.yaml", "values.yml"): + with file.open(encoding="UTF-8") as values_file: values_yaml = yaml.safe_load(values_file) return values_yaml @@ -241,8 +234,8 @@ def _read_top_level_values_yaml( "Cannot find top level values.yaml/.yml file in Helm package." ) - def write_manifest_bicep_file(self) -> None: - """Write the bicep file for the Artifact Manifest.""" + def _write_manifest_bicep_file(self) -> None: + """Write the bicep file for the Artifact Manifest to the temp directory.""" with open(self.manifest_jinja2_template_path, "r", encoding="UTF-8") as f: template: Template = Template( f.read(), @@ -253,14 +246,14 @@ def write_manifest_bicep_file(self) -> None: artifacts=self.artifacts, ) - path = os.path.join(self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE_FILENAME) + path = self._tmp_dir / CNF_MANIFEST_BICEP_TEMPLATE_FILENAME with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) logger.info("Created artifact manifest bicep template: %s", path) - def write_nfd_bicep_file(self) -> None: - """Write the bicep file for the NFD.""" + def _write_nfd_bicep_file(self) -> None: + """Write the bicep file for the NFD to the temp directory.""" with open(self.nfd_jinja2_template_path, "r", encoding="UTF-8") as f: template: Template = Template( f.read(), @@ -268,91 +261,76 @@ def write_nfd_bicep_file(self) -> None: ) bicep_contents: str = template.render( - deployParametersPath=os.path.join(SCHEMAS_DIR_NAME, DEPLOYMENT_PARAMETERS_FILENAME), + deployParametersPath=Path(SCHEMAS_DIR_NAME, DEPLOYMENT_PARAMETERS_FILENAME), nf_application_configurations=self.nf_application_configurations, ) - path = os.path.join(self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE_FILENAME) + path = self._tmp_dir / CNF_DEFINITION_BICEP_TEMPLATE_FILENAME with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) logger.info("Created NFD bicep template: %s", path) - def write_schema_to_file(self) -> None: - """Write the schema to file deploymentParameters.json.""" + def _write_schema_to_file(self) -> None: + """Write the schema to file deploymentParameters.json to the temp directory.""" logger.debug("Create deploymentParameters.json") - full_schema = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS_FILENAME) + full_schema = self._tmp_dir / DEPLOYMENT_PARAMETERS_FILENAME with open(full_schema, "w", encoding="UTF-8") as f: json.dump(self.deployment_parameter_schema, f, indent=4) logger.debug("%s created", full_schema) - def copy_to_output_folder(self) -> None: - """Copy the config mappings, schema and bicep templates (artifact manifest and NFDV) to the output folder.""" - - logger.info("Create NFD bicep %s", self.output_folder_name) + def _copy_to_output_directory(self) -> None: + """Copy the config mappings, schema and bicep templates (artifact manifest and NFDV) from the temp directory to the output directory.""" - os.mkdir(self.output_folder_name) - os.mkdir(os.path.join(self.output_folder_name, SCHEMAS_DIR_NAME)) + logger.info("Create NFD bicep %s", self.output_directory) - # Copy the nfd and the manifest bicep files to the output folder - tmp_nfd_bicep_path = os.path.join( - self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE_FILENAME + Path(self.output_directory / SCHEMAS_DIR_NAME).mkdir( + parents=True, exist_ok=True ) - shutil.copy(tmp_nfd_bicep_path, self.output_folder_name) - tmp_manifest_bicep_path = os.path.join( - self._tmp_folder_name, CNF_MANIFEST_BICEP_TEMPLATE_FILENAME + # Copy the nfd and the manifest bicep files to the output directory + shutil.copy( + self._tmp_dir / CNF_DEFINITION_BICEP_TEMPLATE_FILENAME, + self.output_directory, + ) + shutil.copy( + self._tmp_dir / CNF_MANIFEST_BICEP_TEMPLATE_FILENAME, self.output_directory ) - shutil.copy(tmp_manifest_bicep_path, self.output_folder_name) - # Copy any generated values mappings YAML files to the corresponding folder in + # Copy any generated values mappings YAML files to the corresponding directory in # the output directory so that the user can edit them and re-run the build if # required - if os.path.exists( - os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS_DIR_NAME) - ): - generated_mappings_path = os.path.join( - self.output_folder_name, GENERATED_VALUES_MAPPINGS_DIR_NAME - ) + if Path(self._tmp_dir / GENERATED_VALUES_MAPPINGS_DIR_NAME).exists(): shutil.copytree( - os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS_DIR_NAME), - generated_mappings_path, + self._tmp_dir / GENERATED_VALUES_MAPPINGS_DIR_NAME, + self.output_directory / GENERATED_VALUES_MAPPINGS_DIR_NAME, ) # Copy the JSON config mappings and deploymentParameters schema that are used - # for the NFD to the output folder - tmp_config_mappings_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME) - output_config_mappings_path = os.path.join( - self.output_folder_name, CONFIG_MAPPINGS_DIR_NAME - ) + # for the NFD to the output directory shutil.copytree( - tmp_config_mappings_path, - output_config_mappings_path, + self._tmp_dir / CONFIG_MAPPINGS_DIR_NAME, + self.output_directory / CONFIG_MAPPINGS_DIR_NAME, dirs_exist_ok=True, ) - - tmp_schema_path = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS_FILENAME) - output_schema_path = os.path.join( - self.output_folder_name, SCHEMAS_DIR_NAME, DEPLOYMENT_PARAMETERS_FILENAME - ) shutil.copy( - tmp_schema_path, - output_schema_path, + self._tmp_dir / DEPLOYMENT_PARAMETERS_FILENAME, + self.output_directory / SCHEMAS_DIR_NAME / DEPLOYMENT_PARAMETERS_FILENAME, ) - logger.info("Copied files to %s", self.output_folder_name) + logger.info("Copied files to %s", self.output_directory) - def generate_nf_application_config( + def _generate_nf_application_config( self, helm_package: HelmPackageConfig, image_registry_path: List[str], image_pull_secret_line_matches: List[Tuple[str, ...]], ) -> Dict[str, Any]: """Generate NF application config.""" - (name, version) = self.get_chart_name_and_version(helm_package) + (name, version) = self._get_chart_name_and_version(helm_package) registry_values_paths = set(image_registry_path) image_pull_secrets_values_paths = set(image_pull_secret_line_matches) @@ -364,22 +342,20 @@ def generate_nf_application_config( "dependsOnProfile": helm_package.depends_on, "registryValuesPaths": list(registry_values_paths), "imagePullSecretsValuesPaths": list(image_pull_secrets_values_paths), - "valueMappingsPath": self.jsonify_value_mappings(helm_package), + "valueMappingsPath": self._jsonify_value_mappings(helm_package), } @staticmethod - def _find_yaml_files(directory) -> Iterator[str]: + def _find_yaml_files(directory: Path) -> Iterator[str]: """ - Find all yaml files in given directory. + Find all yaml files recursively in given directory. :param directory: The directory to search. """ - for root, _, files in os.walk(directory): - for file in files: - if file.endswith(".yaml") or file.endswith(".yml"): - yield os.path.join(root, file) + yield from directory.glob("**/*.yaml") + yield from directory.glob("**/*.yml") - def find_pattern_matches_in_chart( + def _find_pattern_matches_in_chart( self, helm_package: HelmPackageConfig, start_string: str ) -> List[Tuple[str, ...]]: """ @@ -395,7 +371,7 @@ def find_pattern_matches_in_chart( paths and the name and version of the image. e.g. (Values.foo.bar.repoPath, foo, 1.2.3) """ - chart_dir = os.path.join(self._tmp_folder_name, helm_package.name) + chart_dir = self._tmp_dir / helm_package.name matches = [] path = [] @@ -413,20 +389,20 @@ def find_pattern_matches_in_chart( ) logger.debug( "Regex match for name and version is %s", - name_and_version - ) + name_and_version, + ) if name_and_version and len(name_and_version.groups()) == 2: logger.debug( "Found image name and version %s %s", - name_and_version.group('name'), - name_and_version.group('version') + name_and_version.group("name"), + name_and_version.group("version"), ) matches.append( ( path, - name_and_version.group('name'), - name_and_version.group('version'), + name_and_version.group("name"), + name_and_version.group("version"), ) ) else: @@ -435,7 +411,7 @@ def find_pattern_matches_in_chart( matches += path return matches - def get_artifact_list( + def _get_artifact_list( self, helm_package: HelmPackageConfig, image_line_matches: List[Tuple[str, ...]], @@ -447,7 +423,7 @@ def get_artifact_list( :param image_line_matches: The list of image line matches. """ artifact_list = [] - (chart_name, chart_version) = self.get_chart_name_and_version(helm_package) + (chart_name, chart_version) = self._get_chart_name_and_version(helm_package) helm_artifact = { "name": chart_name, "version": chart_version, @@ -463,12 +439,12 @@ def get_artifact_list( return artifact_list - def get_chart_mapping_schema( + def _get_chart_mapping_schema( self, helm_package: HelmPackageConfig ) -> Dict[Any, Any]: """ Get the schema for the non default values (those with {deploymentParameter...}). - Based on user provided values.schema.json. + Based on the user provided values schema. param helm_package: The helm package config. """ @@ -476,18 +452,16 @@ def get_chart_mapping_schema( logger.debug("Get chart mapping schema for %s", helm_package.name) mappings_path = helm_package.path_to_mappings - values_schema = os.path.join( - self._tmp_folder_name, helm_package.name, "values.schema.json" - ) - if not os.path.exists(mappings_path): + values_schema = self._tmp_dir / helm_package.name / CNF_VALUES_SCHEMA_FILENAME + if not Path(mappings_path).exists(): raise InvalidTemplateError( f"ERROR: The helm package '{helm_package.name}' does not have a valid values" " mappings file. The file at '{helm_package.path_to_mappings}' does not exist." "\nPlease fix this and run the command again." ) - if not os.path.exists(values_schema): + if not values_schema.exists(): raise InvalidTemplateError( - f"ERROR: The helm package '{helm_package.name}' is missing values.schema.json." + f"ERROR: The helm package '{helm_package.name}' is missing {CNF_VALUES_SCHEMA_FILENAME}." "\nPlease fix this and run the command again." ) @@ -515,14 +489,11 @@ def get_chart_mapping_schema( @staticmethod def traverse_dict( - dict_to_search: Dict[Any, Any], - target_regex: str - ) -> Dict[str, List[str]]: + dict_to_search: Dict[Any, Any], target_regex: str + ) -> Dict[str, List[str]]: """ - Traverse the dictionary that is loaded from the file provided by path_to_mappings in the input.json. - - Returns a dictionary of all the values that match the target regex, - with the key being the deploy parameter and the value being the path to the value. + Traverse the dictionary provided and return a dictionary of all the values that match the target regex, + with the key being the deploy parameter and the value being the path (as a list) to the value. e.g. {"foo": ["global", "foo", "bar"]} :param d: The dictionary to traverse. @@ -563,17 +534,16 @@ def traverse_dict( "at path %s, which this tool cannot parse. " "Please check the output configMappings and schemas " "files and check that they are as required.", - path + [k] + path + [k], ) return result @staticmethod def search_schema( - deployParams_paths: Dict[str, List[str]], - full_schema - ) -> Dict[str, Dict[str, str]]: + deployParams_paths: Dict[str, List[str]], full_schema + ) -> Dict[str, Dict[str, str]]: """ - Search through provided schema for the types of the deployment parameters. + Search through the provided schema for the types of the deployment parameters. This assumes that the type of the key will be the type of the deployment parameter. e.g. if foo: {deployParameter.bar} and foo is type string, then bar is type string. @@ -581,7 +551,7 @@ def search_schema( {"foo": {"type": "string"}, "bar": {"type": "string"}} param deployParams_paths: a dictionary of all the deploy parameters to search for, - with the key being the deploy parameter and the value being the + with the key being the deploy parameter and the value being the path to the value. e.g. {"foo": ["global", "foo", "bar"]} param full_schema: The schema to search through. @@ -591,13 +561,14 @@ def search_schema( for deploy_param, path_list in deployParams_paths.items(): logger.debug( "Searching for %s in schema at path %s", deploy_param, path_list - ) + ) node = full_schema for path in path_list: if "properties" in node.keys(): logger.debug( "Searching properties for %s in schema at path %s", - deploy_param, path + deploy_param, + path, ) node = node["properties"][path] else: @@ -613,7 +584,8 @@ def search_schema( logger.warning( "We default these parameters to type string. " "Please edit schemas/%s in the output before publishing " - "if this is wrong", DEPLOYMENT_PARAMETERS_FILENAME + "if this is wrong", + DEPLOYMENT_PARAMETERS_FILENAME, ) return new_schema @@ -693,19 +665,19 @@ def _replace_values_with_deploy_params( return final_values_mapping_dict - def get_chart_name_and_version( + def _get_chart_name_and_version( self, helm_package: HelmPackageConfig ) -> Tuple[str, str]: """Get the name and version of the chart.""" - chart = os.path.join(self._tmp_folder_name, helm_package.name, "Chart.yaml") + chart_path = self._tmp_dir / helm_package.name / "Chart.yaml" - if not os.path.exists(chart): + if not chart_path.exists(): raise InvalidTemplateError( f"There is no Chart.yaml file in the helm package '{helm_package.name}'. " "\nPlease fix this and run the command again." ) - with open(chart, "r", encoding="utf-8") as f: + with open(chart_path, "r", encoding="utf-8") as f: data = yaml.load(f, Loader=yaml.FullLoader) if "name" in data and "version" in data: chart_name = data["name"] @@ -719,23 +691,19 @@ def get_chart_name_and_version( return (chart_name, chart_version) - def jsonify_value_mappings(self, helm_package: HelmPackageConfig) -> str: + def _jsonify_value_mappings(self, helm_package: HelmPackageConfig) -> Path: """Yaml->JSON values mapping file, then return path to it.""" - mappings_yaml = helm_package.path_to_mappings - - mappings_folder_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME) - mappings_filename = f"{helm_package.name}-mappings.json" - - if not os.path.exists(mappings_folder_path): - os.mkdir(mappings_folder_path) + mappings_yaml_file = helm_package.path_to_mappings + mappings_dir = self._tmp_dir / CONFIG_MAPPINGS_DIR_NAME + mappings_output_file = mappings_dir / f"{helm_package.name}-mappings.json" - mapping_file_path = os.path.join(mappings_folder_path, mappings_filename) + mappings_dir.mkdir(exist_ok=True) - with open(mappings_yaml, "r", encoding="utf-8") as f: + with open(mappings_yaml_file, "r", encoding="utf-8") as f: data = yaml.load(f, Loader=yaml.FullLoader) - with open(mapping_file_path, "w", encoding="utf-8") as file: + with open(mappings_output_file, "w", encoding="utf-8") as file: json.dump(data, file, indent=4) logger.debug("Generated parameter mappings for %s", helm_package.name) - return os.path.join(CONFIG_MAPPINGS_DIR_NAME, mappings_filename) + return Path(CONFIG_MAPPINGS_DIR_NAME, f"{helm_package.name}-mappings.json") diff --git a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py index a57604f3009..e155950c03d 100644 --- a/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py +++ b/src/aosm/azext_aosm/generate_nfd/nfd_generator_base.py @@ -3,7 +3,10 @@ # License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------- """Contains a base class for generating NFDs.""" -from abc import ABC +from abc import ABC, abstractmethod +from pathlib import Path +from typing import Optional + from knack.log import get_logger logger = get_logger(__name__) @@ -12,7 +15,11 @@ class NFDGenerator(ABC): """A class for generating an NFD from a config file.""" - # pylint: disable=too-few-public-methods + @abstractmethod def generate_nfd(self) -> None: - """No-op on base class.""" - raise NotImplementedError + ... + + @property + @abstractmethod + def nfd_bicep_path(self) -> Optional[Path]: + ... diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index ec2d44a1214..98dd6a587e0 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -5,10 +5,10 @@ """Contains a class for generating VNF NFDs and associated resources.""" import json -import os import shutil import tempfile from functools import cached_property +from pathlib import Path from typing import Any, Dict, Optional from knack.log import get_logger @@ -62,21 +62,19 @@ class VnfNfdGenerator(NFDGenerator): def __init__(self, config: VNFConfiguration, order_params: bool, interactive: bool): self.config = config - self.bicep_template_name = VNF_DEFINITION_BICEP_TEMPLATE_FILENAME - self.manifest_template_name = VNF_MANIFEST_BICEP_TEMPLATE_FILENAME - self.arm_template_path = self.config.arm_template.file_path - self.output_folder_name = self.config.build_output_folder_name + self.arm_template_path = Path(self.config.arm_template.file_path) + self.output_directory: Path = self.config.output_directory_for_build - self._bicep_path = os.path.join( - self.output_folder_name, self.bicep_template_name + self._vnfd_bicep_path = Path( + self.output_directory, VNF_DEFINITION_BICEP_TEMPLATE_FILENAME ) - self._manifest_path = os.path.join( - self.output_folder_name, self.manifest_template_name + self._manifest_bicep_path = Path( + self.output_directory, VNF_MANIFEST_BICEP_TEMPLATE_FILENAME ) self.order_params = order_params self.interactive = interactive - self.tmp_folder_name = "" + self._tmp_dir: Optional[Path] = None self.image_name = f"{self.config.nf_name}Image" def generate_nfd(self) -> None: @@ -85,32 +83,30 @@ def generate_nfd(self) -> None: Create a bicep template for an NFD from the ARM template for the VNF. """ - # Create temporary folder. + # Create temporary directory. with tempfile.TemporaryDirectory() as tmpdirname: - self.tmp_folder_name = tmpdirname + self._tmp_dir = Path(tmpdirname) - self.create_parameter_files() - self.copy_to_output_folder() - print(f"Generated NFD bicep templates created in {self.output_folder_name}") + self._create_parameter_files() + self._copy_to_output_directory() + print(f"Generated NFD bicep templates created in {self.output_directory}") print( "Please review these templates. When you are happy with them run " "`az aosm nfd publish` with the same arguments." ) @property - def bicep_path(self) -> Optional[str]: + def nfd_bicep_path(self) -> Optional[Path]: """Returns the path to the bicep file for the NFD if it has been created.""" - if os.path.exists(self._bicep_path): - return self._bicep_path - + if self._vnfd_bicep_path.exists(): + return self._vnfd_bicep_path return None @property - def manifest_path(self) -> Optional[str]: + def manifest_bicep_path(self) -> Optional[str]: """Returns the path to the bicep file for the NFD if it has been created.""" - if os.path.exists(self._manifest_path): - return self._manifest_path - + if self._manifest_bicep_path.exists(): + return self._manifest_bicep_path return None @cached_property @@ -151,22 +147,22 @@ def vm_parameters_ordered(self) -> Dict[str, Any]: return {**vm_parameters_no_default, **vm_parameters_with_default} - def create_parameter_files(self) -> None: - """Create the Deployment and Template json parameter files.""" - schemas_folder_path = os.path.join(self.tmp_folder_name, SCHEMAS_DIR_NAME) - os.mkdir(schemas_folder_path) - self.write_deployment_parameters(schemas_folder_path) + def _create_parameter_files(self) -> None: + """Create the deployment, template and VHD parameter files.""" + tmp_schemas_directory: Path = self._tmp_dir / SCHEMAS_DIR_NAME + tmp_schemas_directory.mkdir() + self.write_deployment_parameters(tmp_schemas_directory) - mappings_folder_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME) - os.mkdir(mappings_folder_path) - self.write_template_parameters(mappings_folder_path) - self.write_vhd_parameters(mappings_folder_path) + tmp_mappings_directory: Path = self._tmp_dir / CONFIG_MAPPINGS_DIR_NAME + tmp_mappings_directory.mkdir() + self.write_template_parameters(tmp_mappings_directory) + self.write_vhd_parameters(tmp_mappings_directory) - def write_deployment_parameters(self, folder_path: str) -> None: + def write_deployment_parameters(self, directory: Path) -> None: """ - Write out the NFD deploymentParameters.json file. + Write out the NFD deploymentParameters.json file to `directory` - :param folder_path: The folder to put this file in. + :param directory: The directory to put this file in. """ logger.debug("Create deploymentParameters.json") @@ -180,10 +176,10 @@ def write_deployment_parameters(self, folder_path: str) -> None: for key in vm_parameters: if key == self.config.image_name_parameter: - # There is only one correct answer for the image name, so don't ask the + # There is only one correct answer for the image name, so don't ask the # user, instead it is hardcoded in config mappings. continue - + # Order parameters into those without and then with defaults has_default_field = "defaultValue" in self.vm_parameters[key] has_default = ( @@ -213,7 +209,7 @@ def write_deployment_parameters(self, folder_path: str) -> None: for key in vm_parameters_to_exclude: self.vm_parameters.pop(key, None) - deployment_parameters_path = os.path.join(folder_path, DEPLOYMENT_PARAMETERS_FILENAME) + deployment_parameters_path = directory / DEPLOYMENT_PARAMETERS_FILENAME # Heading for the deployParameters schema deploy_parameters_full: Dict[str, Any] = SCHEMA_PREFIX @@ -232,8 +228,8 @@ def write_deployment_parameters(self, folder_path: str) -> None: # Extra output file to help the user know which parameters are optional if not self.interactive: if nfd_parameters_with_default: - optional_deployment_parameters_path = os.path.join( - folder_path, OPTIONAL_DEPLOYMENT_PARAMETERS_FILENAME + optional_deployment_parameters_path = ( + directory / OPTIONAL_DEPLOYMENT_PARAMETERS_FILENAME ) with open( optional_deployment_parameters_path, "w", encoding="utf-8" @@ -245,12 +241,12 @@ def write_deployment_parameters(self, folder_path: str) -> None: f"{OPTIONAL_DEPLOYMENT_PARAMETERS_FILENAME} to help you choose which " "to expose." ) - - def write_template_parameters(self, folder_path: str) -> None: + + def write_template_parameters(self, directory: Path) -> None: """ - Write out the NFD templateParameters.json file. + Write out the NFD templateParameters.json file to `directory`. - :param folder_path: The folder to put this file in. + :param directory: The directory to put this file in. """ logger.debug("Create %s", TEMPLATE_PARAMETERS_FILENAME) vm_parameters = ( @@ -266,18 +262,18 @@ def write_template_parameters(self, folder_path: str) -> None: template_parameters[key] = f"{{deployParameters.{key}}}" - template_parameters_path = os.path.join(folder_path, TEMPLATE_PARAMETERS_FILENAME) + template_parameters_path = directory / TEMPLATE_PARAMETERS_FILENAME with open(template_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(template_parameters, indent=4)) logger.debug("%s created", template_parameters_path) - def write_vhd_parameters(self, folder_path: str) -> None: + def write_vhd_parameters(self, directory: Path) -> None: """ - Write out the NFD vhdParameters.json file. + Write out the NFD vhdParameters.json file to `directory`. - :param folder_path: The folder to put this file in. + :param directory: The directory to put this file in. """ azureDeployLocation: str if self.vm_parameters.get("location"): @@ -293,29 +289,33 @@ def write_vhd_parameters(self, folder_path: str) -> None: "azureDeployLocation": azureDeployLocation, } - vhd_parameters_path = os.path.join(folder_path, VHD_PARAMETERS_FILENAME) + vhd_parameters_path = directory / VHD_PARAMETERS_FILENAME with open(vhd_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(vhd_parameters, indent=4)) logger.debug("%s created", vhd_parameters_path) - def copy_to_output_folder(self) -> None: - """Copy the bicep templates, config mappings and schema into the build output folder.""" - code_dir = os.path.dirname(__file__) + def _copy_to_output_directory(self) -> None: + """Copy the static bicep templates and generated config mappings and schema into the build output directory.""" + logger.info("Create NFD bicep %s", self.output_directory) + Path(self.output_directory).mkdir(exist_ok=True) - logger.info("Create NFD bicep %s", self.output_folder_name) - os.mkdir(self.output_folder_name) + static_bicep_templates_dir = Path(__file__).parent / "templates" - bicep_path = os.path.join(code_dir, "templates", self.bicep_template_name) - shutil.copy(bicep_path, self.output_folder_name) + static_vnfd_bicep_path = ( + static_bicep_templates_dir / VNF_DEFINITION_BICEP_TEMPLATE_FILENAME + ) + shutil.copy(static_vnfd_bicep_path, self.output_directory) - manifest_path = os.path.join(code_dir, "templates", self.manifest_template_name) - shutil.copy(manifest_path, self.output_folder_name) - # Copy everything in the temp folder to the output folder + static_manifest_bicep_path = ( + static_bicep_templates_dir / VNF_MANIFEST_BICEP_TEMPLATE_FILENAME + ) + shutil.copy(static_manifest_bicep_path, self.output_directory) + # Copy everything in the temp directory to the output directory shutil.copytree( - self.tmp_folder_name, - self.output_folder_name, + self._tmp_dir, + self.output_directory, dirs_exist_ok=True, ) - logger.info("Copied files to %s", self.output_folder_name) + logger.info("Copied files to %s", self.output_directory) diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index 33dd6596bb0..836da37dc1d 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -298,7 +298,7 @@ def write_nsd_manifest(self) -> None: {}, ) - def generate_bicep(self, + def generate_bicep(self, template_name: str, output_file_name: str, params: Dict[Any,Any]) -> None: diff --git a/src/aosm/azext_aosm/util/constants.py b/src/aosm/azext_aosm/util/constants.py index cf76d00f895..d2f0f529f7c 100644 --- a/src/aosm/azext_aosm/util/constants.py +++ b/src/aosm/azext_aosm/util/constants.py @@ -35,6 +35,7 @@ CNF_MANIFEST_JINJA2_SOURCE_TEMPLATE_FILENAME = "cnfartifactmanifest.bicep.j2" CNF_DEFINITION_BICEP_TEMPLATE_FILENAME = "cnfdefinition.bicep" CNF_MANIFEST_BICEP_TEMPLATE_FILENAME = "cnfartifactmanifest.bicep" +CNF_VALUES_SCHEMA_FILENAME = "values.schema.json" # Names of directories used in the repo @@ -84,4 +85,4 @@ SOURCE_ACR_REGEX = ( r".*\/resourceGroups\/(?P[^\/]*)\/providers\/Microsoft." r"ContainerRegistry\/registries\/(?P[^\/]*)" - ) +) From 230bfa5c3d4b157b3bd7a640b60e891158e4781e Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Tue, 4 Jul 2023 23:39:12 +0100 Subject: [PATCH 129/145] Fix Artifact upload on Windows --- src/aosm/HISTORY.rst | 1 + src/aosm/azext_aosm/deploy/artifact.py | 34 +++++++++++++++++++------- src/aosm/setup.md | 4 ++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/aosm/HISTORY.rst b/src/aosm/HISTORY.rst index ae1c3842448..e733b20bcec 100644 --- a/src/aosm/HISTORY.rst +++ b/src/aosm/HISTORY.rst @@ -16,6 +16,7 @@ unreleased * Add the ability to skip bicep publish or artifact upload during publish commands. * Fix Manifest name for NSDs so it isn't the same as that for NFDs * Add validation of source_registry_id format for CNF configuration +* Workaround Oras client bug (#90) on Windows for Artifact upload to ACR 0.2.0 ++++++ diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 614b38d5784..8fc72f4d8ef 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -3,6 +3,7 @@ # pylint: disable=unidiomatic-typecheck """A module to handle interacting with artifacts.""" +import os import subprocess from dataclasses import dataclass from typing import List, Union @@ -57,15 +58,30 @@ def _upload_arm_to_acr(self, artifact_config: ArtifactConfig) -> None: assert type(self.artifact_client) == OrasClient if artifact_config.file_path: - target = ( - f"{self.artifact_client.remote.hostname.replace('https://', '')}" - f"/{self.artifact_name}:{self.artifact_version}" - ) - logger.debug("Uploading %s to %s", artifact_config.file_path, target) - self.artifact_client.push( - files=[artifact_config.file_path], - target=target, - ) + try: + # OrasClient 0.1.17 has a bug + # https://github.com/oras-project/oras-py/issues/90 which means on + # Windows we need a real blank file on disk, without a colon in the + # filepath (so tempfile can't be used and we just put it in the working + # directory), that can act as the manifest config file. So create one + # and then delete it after the upload. + with open("dummyManifestConfig.json", "w", encoding='utf-8') as f: + target = ( + f"{self.artifact_client.remote.hostname.replace('https://', '')}" + f"/{self.artifact_name}:{self.artifact_version}" + ) + logger.debug("Uploading %s to %s", artifact_config.file_path, target) + self.artifact_client.push( + files=[artifact_config.file_path], + target=target, + manifest_config=f.name, + ) + finally: + # Delete the dummy file + try: + os.remove("dummyManifestConfig.json") + except FileNotFoundError: + pass else: raise NotImplementedError( "Copying artifacts is not implemented for ACR artifacts stores." diff --git a/src/aosm/setup.md b/src/aosm/setup.md index b38bd52d039..0c2a9659cbe 100644 --- a/src/aosm/setup.md +++ b/src/aosm/setup.md @@ -12,7 +12,7 @@ Clone both azure-cli and azure-cli-extensions Note for azure-cli-extensions we are currently on a fork : https://github.com/jddarby/azure-cli-extensions ```bash # Go into your git clone of az-cli-extensions -cd az-cli-extensions +cd azure-cli-extensions # Create a virtual environment to run in python3.8 -m venv ~/.virtualenvs/az-cli-env @@ -24,6 +24,8 @@ python -m pip install -U pip # Install azdev pip install azdev +git checkout add-aosm-extension + # Install all the python dependencies you need azdev setup --cli /home/developer/code/azure-cli --repo . From 91b7f39409ddd6b8dcbfea77a200955d0f7abae1 Mon Sep 17 00:00:00 2001 From: sunnycarter <36891339+sunnycarter@users.noreply.github.com> Date: Tue, 4 Jul 2023 23:42:59 +0100 Subject: [PATCH 130/145] Fix Artifact upload on Windows (#40) --- src/aosm/HISTORY.rst | 1 + src/aosm/azext_aosm/deploy/artifact.py | 34 +++++++++++++++++++------- src/aosm/setup.md | 4 ++- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/aosm/HISTORY.rst b/src/aosm/HISTORY.rst index ae1c3842448..e733b20bcec 100644 --- a/src/aosm/HISTORY.rst +++ b/src/aosm/HISTORY.rst @@ -16,6 +16,7 @@ unreleased * Add the ability to skip bicep publish or artifact upload during publish commands. * Fix Manifest name for NSDs so it isn't the same as that for NFDs * Add validation of source_registry_id format for CNF configuration +* Workaround Oras client bug (#90) on Windows for Artifact upload to ACR 0.2.0 ++++++ diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 614b38d5784..8fc72f4d8ef 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -3,6 +3,7 @@ # pylint: disable=unidiomatic-typecheck """A module to handle interacting with artifacts.""" +import os import subprocess from dataclasses import dataclass from typing import List, Union @@ -57,15 +58,30 @@ def _upload_arm_to_acr(self, artifact_config: ArtifactConfig) -> None: assert type(self.artifact_client) == OrasClient if artifact_config.file_path: - target = ( - f"{self.artifact_client.remote.hostname.replace('https://', '')}" - f"/{self.artifact_name}:{self.artifact_version}" - ) - logger.debug("Uploading %s to %s", artifact_config.file_path, target) - self.artifact_client.push( - files=[artifact_config.file_path], - target=target, - ) + try: + # OrasClient 0.1.17 has a bug + # https://github.com/oras-project/oras-py/issues/90 which means on + # Windows we need a real blank file on disk, without a colon in the + # filepath (so tempfile can't be used and we just put it in the working + # directory), that can act as the manifest config file. So create one + # and then delete it after the upload. + with open("dummyManifestConfig.json", "w", encoding='utf-8') as f: + target = ( + f"{self.artifact_client.remote.hostname.replace('https://', '')}" + f"/{self.artifact_name}:{self.artifact_version}" + ) + logger.debug("Uploading %s to %s", artifact_config.file_path, target) + self.artifact_client.push( + files=[artifact_config.file_path], + target=target, + manifest_config=f.name, + ) + finally: + # Delete the dummy file + try: + os.remove("dummyManifestConfig.json") + except FileNotFoundError: + pass else: raise NotImplementedError( "Copying artifacts is not implemented for ACR artifacts stores." diff --git a/src/aosm/setup.md b/src/aosm/setup.md index b38bd52d039..0c2a9659cbe 100644 --- a/src/aosm/setup.md +++ b/src/aosm/setup.md @@ -12,7 +12,7 @@ Clone both azure-cli and azure-cli-extensions Note for azure-cli-extensions we are currently on a fork : https://github.com/jddarby/azure-cli-extensions ```bash # Go into your git clone of az-cli-extensions -cd az-cli-extensions +cd azure-cli-extensions # Create a virtual environment to run in python3.8 -m venv ~/.virtualenvs/az-cli-env @@ -24,6 +24,8 @@ python -m pip install -U pip # Install azdev pip install azdev +git checkout add-aosm-extension + # Install all the python dependencies you need azdev setup --cli /home/developer/code/azure-cli --repo . From ea3fd776d05376a648b74b2030f50cbcb2d40ecc Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Wed, 5 Jul 2023 10:52:33 +0100 Subject: [PATCH 131/145] Black --- src/aosm/azext_aosm/_configuration.py | 23 ++++---- src/aosm/azext_aosm/_help.py | 2 +- src/aosm/azext_aosm/_params.py | 8 +-- src/aosm/azext_aosm/custom.py | 6 +-- src/aosm/azext_aosm/deploy/artifact.py | 2 +- .../azext_aosm/deploy/artifact_manifest.py | 4 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 12 +++-- src/aosm/azext_aosm/deploy/pre_deploy.py | 12 +++-- .../generate_nfd/cnf_nfd_generator.py | 54 ++++++++++++------- .../generate_nfd/vnf_nfd_generator.py | 18 ++++--- .../azext_aosm/generate_nsd/nsd_generator.py | 24 ++++----- src/aosm/azext_aosm/tests/latest/test_cnf.py | 8 +-- src/aosm/azext_aosm/tests/latest/test_nsd.py | 30 ++++------- src/aosm/azext_aosm/tests/latest/test_vnf.py | 7 +-- 14 files changed, 113 insertions(+), 97 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index a679f63327c..179471ade4e 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -14,7 +14,7 @@ NSD, NSD_OUTPUT_BICEP_PREFIX, VNF, - SOURCE_ACR_REGEX + SOURCE_ACR_REGEX, ) DESCRIPTION_MAP: Dict[str, str] = { @@ -125,7 +125,7 @@ def path_from_cli(self, path: str) -> str: """ Convert path from config file to path from current directory. - We assume that the path supplied in the config file is relative to the + We assume that the path supplied in the config file is relative to the configuration file. That isn't the same as the path relative to where ever the CLI is being run from. This function fixes that up. @@ -255,7 +255,7 @@ def network_function_name(self) -> str: @property def acr_manifest_name(self) -> str: """Return the ACR manifest name from the NFD name.""" - sanitised_nf_name = self.network_function_name.lower().replace('_', '-') + sanitised_nf_name = self.network_function_name.lower().replace("_", "-") return ( f"{sanitised_nf_name}-nsd-acr-manifest-{self.nsd_version.replace('.', '-')}" ) @@ -300,13 +300,13 @@ def __post_init__(self): Used when creating VNFConfiguration object from a loaded json config file. """ if isinstance(self.arm_template, dict): - self.arm_template["file_path"] = \ - self.path_from_cli(self.arm_template["file_path"]) + self.arm_template["file_path"] = self.path_from_cli( + self.arm_template["file_path"] + ) self.arm_template = ArtifactConfig(**self.arm_template) if isinstance(self.vhd, dict): - self.vhd["file_path"] = \ - self.path_from_cli(self.vhd["file_path"]) + self.vhd["file_path"] = self.path_from_cli(self.vhd["file_path"]) self.vhd = ArtifactConfig(**self.vhd) self.validate() @@ -390,8 +390,9 @@ def __post_init__(self): for package_index, package in enumerate(self.helm_packages): if isinstance(package, dict): package["path_to_chart"] = self.path_from_cli(package["path_to_chart"]) - package["path_to_mappings"] = \ - self.path_from_cli(package["path_to_mappings"]) + package["path_to_mappings"] = self.path_from_cli( + package["path_to_mappings"] + ) self.helm_packages[package_index] = HelmPackageConfig(**dict(package)) @property @@ -412,7 +413,9 @@ def validate(self): if not source_registry_match or len(source_registry_match.groups()) < 2: raise ValidationError( "CNF config has an invalid source registry ID. Please run `az aosm " - "nfd generate-config` to see the valid formats.") + "nfd generate-config` to see the valid formats." + ) + def get_configuration( configuration_type: str, config_file: str = None diff --git a/src/aosm/azext_aosm/_help.py b/src/aosm/azext_aosm/_help.py index b11bedb4b53..afb4b08f19d 100644 --- a/src/aosm/azext_aosm/_help.py +++ b/src/aosm/azext_aosm/_help.py @@ -4,7 +4,7 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from knack.help_files import helps # pylint: disable=unused-import +from knack.help_files import helps helps[ "aosm" diff --git a/src/aosm/azext_aosm/_params.py b/src/aosm/azext_aosm/_params.py index 2c379a3494a..f0d5b1590f3 100644 --- a/src/aosm/azext_aosm/_params.py +++ b/src/aosm/azext_aosm/_params.py @@ -110,9 +110,7 @@ def load_arguments(self: AzCommandsLoader, _): " alternative parameters." ), ) - c.argument( - "skip", arg_type=skip_steps, help="Optional skip steps" - ) + c.argument("skip", arg_type=skip_steps, help="Optional skip steps") with self.argument_context("aosm nsd") as c: c.argument( @@ -122,6 +120,4 @@ def load_arguments(self: AzCommandsLoader, _): completer=FilesCompleter(allowednames="*.json"), help="The path to the configuration file.", ) - c.argument( - "skip", arg_type=skip_steps, help="Optional skip steps" - ) + c.argument("skip", arg_type=skip_steps, help="Optional skip steps") diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index ae521ad86d9..0b5f6acdccb 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -175,7 +175,7 @@ def publish_definition( parameters_json_file=parameters_json_file, manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, - skip=skip + skip=skip, ) elif definition_type == CNF: deployer = DeployerViaArm(api_clients, config=config) @@ -185,7 +185,7 @@ def publish_definition( parameters_json_file=parameters_json_file, manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, - skip=skip + skip=skip, ) else: raise ValueError( @@ -372,7 +372,7 @@ def publish_design( parameters_json_file=parameters_json_file, manifest_bicep_path=manifest_file, manifest_parameters_json_file=manifest_parameters_json_file, - skip=skip + skip=skip, ) diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 7e5d03bd532..20fb56390d4 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -157,7 +157,7 @@ def copy_image( :param source_image: source image :param target_registry_resource_group_name: target registry resource group name :param target_registry_name: target registry name - :param target_tags: the list of tags to be applied to the imported image + :param target_tags: the list of tags to be applied to the imported image should be of form: namepace/name:tag or name:tag :param mode: mode for import """ diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 55b55fd95e6..1ac303d4590 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -139,9 +139,7 @@ def _get_artifact_client( # For AOSM to work VHD blobs must have the suffix .vhd if artifact.artifact_name.endswith("-vhd"): - blob_name = ( - f"{artifact.artifact_name[:-4].replace('-', '')}-{artifact.artifact_version}.vhd" - ) + blob_name = f"{artifact.artifact_name[:-4].replace('-', '')}-{artifact.artifact_version}.vhd" else: blob_name = container_name diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index e0251be0351..036d6aa254a 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -91,7 +91,7 @@ def deploy_vnfd_from_bicep( parameters_json_file: Optional[str] = None, manifest_bicep_path: Optional[str] = None, manifest_parameters_json_file: Optional[str] = None, - skip: Optional[str] = None + skip: Optional[str] = None, ) -> None: """ Deploy the bicep template defining the VNFD. @@ -276,7 +276,7 @@ def deploy_cnfd_from_bicep( parameters_json_file: Optional[str] = None, manifest_bicep_path: Optional[str] = None, manifest_parameters_json_file: Optional[str] = None, - skip: Optional[str] = None + skip: Optional[str] = None, ) -> None: """ Deploy the bicep template defining the CNFD. @@ -459,7 +459,9 @@ def deploy_nsd_from_bicep( manifest_parameters_json_file, manifest_bicep_path, NSD ) else: - print(f"Artifact manifests {self.config.acr_manifest_name} already exists") + print( + f"Artifact manifests {self.config.acr_manifest_name} already exists" + ) message = ( f"Deploy bicep template for NSDV {self.config.nsd_version} " @@ -489,7 +491,9 @@ def deploy_nsd_from_bicep( # Convert the NF bicep to ARM arm_template_artifact_json = self.convert_bicep_to_arm( - os.path.join(self.config.build_output_folder_name, NF_DEFINITION_BICEP_FILENAME) + os.path.join( + self.config.build_output_folder_name, NF_DEFINITION_BICEP_FILENAME + ) ) with open(self.config.arm_template.file_path, "w", encoding="utf-8") as file: diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 1fd21dfcb4f..8c314a2872c 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -14,7 +14,7 @@ NFConfiguration, NSConfiguration, VNFConfiguration, - CNFConfiguration + CNFConfiguration, ) from azext_aosm.util.constants import SOURCE_ACR_REGEX from azext_aosm.util.management_clients import ApiClients @@ -154,12 +154,16 @@ def ensure_config_source_registry_exists(self) -> None: ) # Match the source registry format - source_registry_match = re.search(SOURCE_ACR_REGEX, self.config.source_registry_id) + source_registry_match = re.search( + SOURCE_ACR_REGEX, self.config.source_registry_id + ) # Config validation has already checked and raised an error if the regex doesn't # match if source_registry_match and len(source_registry_match.groups()) > 1: - source_registry_resource_group_name = source_registry_match.group('resource_group') - source_registry_name = source_registry_match.group('registry_name') + source_registry_resource_group_name = source_registry_match.group( + "resource_group" + ) + source_registry_name = source_registry_match.group("registry_name") # This will raise an error if the registry does not exist self.api_clients.container_registry_client.get( diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 9c53a5f74a6..ed8398e7f46 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -202,7 +202,9 @@ def _generate_chart_value_mappings(self, helm_package: HelmPackageConfig) -> Non ) # Write the mapping to a file - folder_name = os.path.join(self._tmp_folder_name, GENERATED_VALUES_MAPPINGS_DIR_NAME) + folder_name = os.path.join( + self._tmp_folder_name, GENERATED_VALUES_MAPPINGS_DIR_NAME + ) os.makedirs(folder_name, exist_ok=True) mapping_filepath = os.path.join( self._tmp_folder_name, @@ -268,11 +270,15 @@ def write_nfd_bicep_file(self) -> None: ) bicep_contents: str = template.render( - deployParametersPath=os.path.join(SCHEMAS_DIR_NAME, DEPLOYMENT_PARAMETERS_FILENAME), + deployParametersPath=os.path.join( + SCHEMAS_DIR_NAME, DEPLOYMENT_PARAMETERS_FILENAME + ), nf_application_configurations=self.nf_application_configurations, ) - path = os.path.join(self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE_FILENAME) + path = os.path.join( + self._tmp_folder_name, CNF_DEFINITION_BICEP_TEMPLATE_FILENAME + ) with open(path, "w", encoding="utf-8") as f: f.write(bicep_contents) @@ -283,7 +289,9 @@ def write_schema_to_file(self) -> None: logger.debug("Create deploymentParameters.json") - full_schema = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS_FILENAME) + full_schema = os.path.join( + self._tmp_folder_name, DEPLOYMENT_PARAMETERS_FILENAME + ) with open(full_schema, "w", encoding="UTF-8") as f: json.dump(self.deployment_parameter_schema, f, indent=4) @@ -324,7 +332,9 @@ def copy_to_output_folder(self) -> None: # Copy the JSON config mappings and deploymentParameters schema that are used # for the NFD to the output folder - tmp_config_mappings_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME) + tmp_config_mappings_path = os.path.join( + self._tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME + ) output_config_mappings_path = os.path.join( self.output_folder_name, CONFIG_MAPPINGS_DIR_NAME ) @@ -334,7 +344,9 @@ def copy_to_output_folder(self) -> None: dirs_exist_ok=True, ) - tmp_schema_path = os.path.join(self._tmp_folder_name, DEPLOYMENT_PARAMETERS_FILENAME) + tmp_schema_path = os.path.join( + self._tmp_folder_name, DEPLOYMENT_PARAMETERS_FILENAME + ) output_schema_path = os.path.join( self.output_folder_name, SCHEMAS_DIR_NAME, DEPLOYMENT_PARAMETERS_FILENAME ) @@ -413,20 +425,20 @@ def find_pattern_matches_in_chart( ) logger.debug( "Regex match for name and version is %s", - name_and_version + name_and_version, ) if name_and_version and len(name_and_version.groups()) == 2: logger.debug( "Found image name and version %s %s", - name_and_version.group('name'), - name_and_version.group('version') + name_and_version.group("name"), + name_and_version.group("version"), ) matches.append( ( path, - name_and_version.group('name'), - name_and_version.group('version'), + name_and_version.group("name"), + name_and_version.group("version"), ) ) else: @@ -515,8 +527,7 @@ def get_chart_mapping_schema( @staticmethod def traverse_dict( - dict_to_search: Dict[Any, Any], - target_regex: str + dict_to_search: Dict[Any, Any], target_regex: str ) -> Dict[str, List[str]]: """ Traverse the dictionary that is loaded from the file provided by path_to_mappings in the input.json. @@ -563,14 +574,13 @@ def traverse_dict( "at path %s, which this tool cannot parse. " "Please check the output configMappings and schemas " "files and check that they are as required.", - path + [k] + path + [k], ) return result @staticmethod def search_schema( - deployParams_paths: Dict[str, List[str]], - full_schema + deployParams_paths: Dict[str, List[str]], full_schema ) -> Dict[str, Dict[str, str]]: """ Search through provided schema for the types of the deployment parameters. @@ -581,7 +591,7 @@ def search_schema( {"foo": {"type": "string"}, "bar": {"type": "string"}} param deployParams_paths: a dictionary of all the deploy parameters to search for, - with the key being the deploy parameter and the value being the + with the key being the deploy parameter and the value being the path to the value. e.g. {"foo": ["global", "foo", "bar"]} param full_schema: The schema to search through. @@ -597,7 +607,8 @@ def search_schema( if "properties" in node.keys(): logger.debug( "Searching properties for %s in schema at path %s", - deploy_param, path + deploy_param, + path, ) node = node["properties"][path] else: @@ -613,7 +624,8 @@ def search_schema( logger.warning( "We default these parameters to type string. " "Please edit schemas/%s in the output before publishing " - "if this is wrong", DEPLOYMENT_PARAMETERS_FILENAME + "if this is wrong", + DEPLOYMENT_PARAMETERS_FILENAME, ) return new_schema @@ -723,7 +735,9 @@ def jsonify_value_mappings(self, helm_package: HelmPackageConfig) -> str: """Yaml->JSON values mapping file, then return path to it.""" mappings_yaml = helm_package.path_to_mappings - mappings_folder_path = os.path.join(self._tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME) + mappings_folder_path = os.path.join( + self._tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME + ) mappings_filename = f"{helm_package.name}-mappings.json" if not os.path.exists(mappings_folder_path): diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index ec2d44a1214..7438fbcd574 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -157,7 +157,9 @@ def create_parameter_files(self) -> None: os.mkdir(schemas_folder_path) self.write_deployment_parameters(schemas_folder_path) - mappings_folder_path = os.path.join(self.tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME) + mappings_folder_path = os.path.join( + self.tmp_folder_name, CONFIG_MAPPINGS_DIR_NAME + ) os.mkdir(mappings_folder_path) self.write_template_parameters(mappings_folder_path) self.write_vhd_parameters(mappings_folder_path) @@ -180,10 +182,10 @@ def write_deployment_parameters(self, folder_path: str) -> None: for key in vm_parameters: if key == self.config.image_name_parameter: - # There is only one correct answer for the image name, so don't ask the + # There is only one correct answer for the image name, so don't ask the # user, instead it is hardcoded in config mappings. continue - + # Order parameters into those without and then with defaults has_default_field = "defaultValue" in self.vm_parameters[key] has_default = ( @@ -213,7 +215,9 @@ def write_deployment_parameters(self, folder_path: str) -> None: for key in vm_parameters_to_exclude: self.vm_parameters.pop(key, None) - deployment_parameters_path = os.path.join(folder_path, DEPLOYMENT_PARAMETERS_FILENAME) + deployment_parameters_path = os.path.join( + folder_path, DEPLOYMENT_PARAMETERS_FILENAME + ) # Heading for the deployParameters schema deploy_parameters_full: Dict[str, Any] = SCHEMA_PREFIX @@ -245,7 +249,7 @@ def write_deployment_parameters(self, folder_path: str) -> None: f"{OPTIONAL_DEPLOYMENT_PARAMETERS_FILENAME} to help you choose which " "to expose." ) - + def write_template_parameters(self, folder_path: str) -> None: """ Write out the NFD templateParameters.json file. @@ -266,7 +270,9 @@ def write_template_parameters(self, folder_path: str) -> None: template_parameters[key] = f"{{deployParameters.{key}}}" - template_parameters_path = os.path.join(folder_path, TEMPLATE_PARAMETERS_FILENAME) + template_parameters_path = os.path.join( + folder_path, TEMPLATE_PARAMETERS_FILENAME + ) with open(template_parameters_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(template_parameters, indent=4)) diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index b0fc198878e..35814839eef 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -27,7 +27,7 @@ NSD_DEFINITION_JINJA2_SOURCE_TEMPLATE, SCHEMAS_DIR_NAME, TEMPLATES_DIR_NAME, - VNF + VNF, ) from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks.models import NetworkFunctionDefinitionVersion, NFVIType @@ -62,9 +62,7 @@ def __init__(self, api_clients: ApiClients, config: NSConfiguration): self.nsd_bicep_template_name = NSD_DEFINITION_JINJA2_SOURCE_TEMPLATE self.nf_bicep_template_name = NF_TEMPLATE_JINJA2_SOURCE_TEMPLATE self.nsd_bicep_output_name = NSD_BICEP_FILENAME - self.nfdv_parameter_name = ( - f"{self.config.network_function_definition_group_name.replace('-', '_')}_nfd_version" - ) + self.nfdv_parameter_name = f"{self.config.network_function_definition_group_name.replace('-', '_')}_nfd_version" self.build_folder_name = self.config.build_output_folder_name nfdv = self._get_nfdv(config, api_clients) print("Finding the deploy parameters of the NFDV resource") @@ -162,8 +160,10 @@ def config_group_schema_dict(self) -> Dict[str, Any]: "/{resourceGroupName}/providers/microsoft.extendedlocation/" "customlocations/{customLocationName}'" ) - cgs_dict["properties"]["customLocationId"] = \ - {"type": "string", "description": custom_location_description_string} + cgs_dict["properties"]["customLocationId"] = { + "type": "string", + "description": custom_location_description_string, + } cgs_dict["required"].append("customLocationId") return cgs_dict @@ -234,9 +234,8 @@ def write_nf_bicep(self) -> None: # location is sometimes part of deploy_properties. # We want to avoid having duplicate params in the bicep template logger.debug( - "Adding deploy parameter key: %s, value: %s to nf template", - key, - value) + "Adding deploy parameter key: %s, value: %s to nf template", key, value + ) if key != "location": bicep_type = ( NFV_TO_BICEP_PARAM_TYPES.get(value["type"]) or value["type"] @@ -299,10 +298,9 @@ def write_nsd_manifest(self) -> None: {}, ) - def generate_bicep(self, - template_name: str, - output_file_name: str, - params: Dict[Any, Any]) -> None: + def generate_bicep( + self, template_name: str, output_file_name: str, params: Dict[Any, Any] + ) -> None: """ Render the bicep templates with the correct parameters and copy them into the build output folder. diff --git a/src/aosm/azext_aosm/tests/latest/test_cnf.py b/src/aosm/azext_aosm/tests/latest/test_cnf.py index ea877ef57ab..6c27436e590 100644 --- a/src/aosm/azext_aosm/tests/latest/test_cnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_cnf.py @@ -9,6 +9,7 @@ import logging import os from tempfile import TemporaryDirectory + # from unittest.mock import Mock, patch from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator @@ -19,7 +20,7 @@ BadRequestError, InvalidArgumentValueError, ResourceNotFoundError, - InvalidTemplateError + InvalidTemplateError, ) mock_cnf_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_cnf") @@ -58,8 +59,7 @@ def test_build(self): try: build_definition( - "cnf", - os.path.join(mock_cnf_folder, "input-nfconfigchart.json") + "cnf", os.path.join(mock_cnf_folder, "input-nfconfigchart.json") ) assert os.path.exists("nfd-bicep-nginx-basic-test") finally: @@ -79,7 +79,7 @@ def test_build_no_mapping(self): build_definition( "cnf", os.path.join(mock_cnf_folder, "input-nf-agent-cnf.json"), - order_params=True + order_params=True, ) assert os.path.exists("nfd-bicep-nf-agent-cnf") finally: diff --git a/src/aosm/azext_aosm/tests/latest/test_nsd.py b/src/aosm/azext_aosm/tests/latest/test_nsd.py index f3495054d9c..cdb9534c4fd 100644 --- a/src/aosm/azext_aosm/tests/latest/test_nsd.py +++ b/src/aosm/azext_aosm/tests/latest/test_nsd.py @@ -15,7 +15,7 @@ mock_nsd_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_nsd") -class TestNSDGenerator(): +class TestNSDGenerator: def test_generate_config(self): """ Test generating a config file for a VNF. @@ -43,19 +43,11 @@ def test_build(self, cf_resources): "title": "DeployParametersSchema", "type": "object", "properties": { - "location": { - "type": "string" - }, - "subnetName": { - "type": "string" - }, - "virtualNetworkId": { - "type": "string" - }, - "sshPublicKeyAdmin": { - "type": "string" - } - } + "location": {"type": "string"}, + "subnetName": {"type": "string"}, + "virtualNetworkId": {"type": "string"}, + "sshPublicKeyAdmin": {"type": "string"}, + }, } deploy_parameters_string = json.dumps(deploy_parameters) @@ -66,17 +58,17 @@ class NFDV: nfdv = NFDV(deploy_parameters_string) - class NFDVs(): + class NFDVs: def get(self, **_): return nfdv - class AOSMClient(): + class AOSMClient: def __init__(self) -> None: self.network_function_definition_versions = NFDVs() mock_client = AOSMClient() - class FakeCmd(): + class FakeCmd: def __init__(self) -> None: self.cli_ctx = None @@ -89,8 +81,8 @@ def __init__(self) -> None: try: build_design( cmd, - client=mock_client, - config_file=os.path.join(mock_nsd_folder, "input.json") + client=mock_client, + config_file=os.path.join(mock_nsd_folder, "input.json"), ) assert os.path.exists("nsd-bicep-templates") finally: diff --git a/src/aosm/azext_aosm/tests/latest/test_vnf.py b/src/aosm/azext_aosm/tests/latest/test_vnf.py index 008c3c29e63..57fc466d929 100644 --- a/src/aosm/azext_aosm/tests/latest/test_vnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_vnf.py @@ -40,7 +40,7 @@ def test_build(self): assert os.path.exists("nfd-bicep-ubuntu-template") finally: os.chdir(starting_directory) - + def test_build_with_ordered_params(self): """ Test building an NFDV for a VNF. @@ -51,9 +51,10 @@ def test_build_with_ordered_params(self): try: build_definition( - "vnf", + "vnf", os.path.join(mock_vnf_folder, "input.json"), - order_params=True) + order_params=True, + ) assert os.path.exists("nfd-bicep-ubuntu-template") finally: os.chdir(starting_directory) From e994c606294aea621f781d3ee8d5aee698c273a3 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Wed, 5 Jul 2023 11:38:22 +0100 Subject: [PATCH 132/145] Mark ups --- src/aosm/azext_aosm/_configuration.py | 10 +++---- src/aosm/azext_aosm/tests/latest/test_cnf.py | 29 +++----------------- src/aosm/azext_aosm/tests/latest/test_nsd.py | 5 ++-- src/aosm/azext_aosm/tests/latest/test_vnf.py | 7 +++-- 4 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 179471ade4e..ebf76bf5347 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -121,7 +121,7 @@ class ArtifactConfig: class Configuration: config_file: Optional[str] = None - def path_from_cli(self, path: str) -> str: + def path_from_cli_dir(self, path: str) -> str: """ Convert path from config file to path from current directory. @@ -300,13 +300,13 @@ def __post_init__(self): Used when creating VNFConfiguration object from a loaded json config file. """ if isinstance(self.arm_template, dict): - self.arm_template["file_path"] = self.path_from_cli( + self.arm_template["file_path"] = self.path_from_cli_dir( self.arm_template["file_path"] ) self.arm_template = ArtifactConfig(**self.arm_template) if isinstance(self.vhd, dict): - self.vhd["file_path"] = self.path_from_cli(self.vhd["file_path"]) + self.vhd["file_path"] = self.path_from_cli_dir(self.vhd["file_path"]) self.vhd = ArtifactConfig(**self.vhd) self.validate() @@ -389,8 +389,8 @@ def __post_init__(self): """ for package_index, package in enumerate(self.helm_packages): if isinstance(package, dict): - package["path_to_chart"] = self.path_from_cli(package["path_to_chart"]) - package["path_to_mappings"] = self.path_from_cli( + package["path_to_chart"] = self.path_from_cli_dir(package["path_to_chart"]) + package["path_to_mappings"] = self.path_from_cli_dir( package["path_to_mappings"] ) self.helm_packages[package_index] = HelmPackageConfig(**dict(package)) diff --git a/src/aosm/azext_aosm/tests/latest/test_cnf.py b/src/aosm/azext_aosm/tests/latest/test_cnf.py index 6c27436e590..05f6ead7c5a 100644 --- a/src/aosm/azext_aosm/tests/latest/test_cnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_cnf.py @@ -2,36 +2,15 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- - -# import os import unittest -import json -import logging import os +from pathlib import Path from tempfile import TemporaryDirectory -# from unittest.mock import Mock, patch - -from azext_aosm.generate_nfd.cnf_nfd_generator import CnfNfdGenerator -from azext_aosm._configuration import CNFConfiguration, HelmPackageConfig from azext_aosm.custom import build_definition, generate_definition_config -from azure.cli.core.azclierror import ( - BadRequestError, - InvalidArgumentValueError, - ResourceNotFoundError, - InvalidTemplateError, -) - -mock_cnf_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_cnf") -cnf_config_file = os.path.join(mock_cnf_folder, "invalid_config_file.json") -# Instantiate CNF with faked config file -with open(cnf_config_file, "r", encoding="utf-8") as f: - config_as_dict = json.loads(f.read()) -config = CNFConfiguration(config_file=cnf_config_file, **config_as_dict) -test_cnf = CnfNfdGenerator(config) -invalid_helm_package = test_cnf.config.helm_packages[0] +mock_cnf_folder = ((Path(__file__).parent) / "mock_cnf").resolve() class TestCNF(unittest.TestCase): @@ -59,7 +38,7 @@ def test_build(self): try: build_definition( - "cnf", os.path.join(mock_cnf_folder, "input-nfconfigchart.json") + "cnf", str(mock_cnf_folder / "input-nfconfigchart.json") ) assert os.path.exists("nfd-bicep-nginx-basic-test") finally: @@ -78,7 +57,7 @@ def test_build_no_mapping(self): try: build_definition( "cnf", - os.path.join(mock_cnf_folder, "input-nf-agent-cnf.json"), + str(mock_cnf_folder / "input-nf-agent-cnf.json"), order_params=True, ) assert os.path.exists("nfd-bicep-nf-agent-cnf") diff --git a/src/aosm/azext_aosm/tests/latest/test_nsd.py b/src/aosm/azext_aosm/tests/latest/test_nsd.py index cdb9534c4fd..0046b2aaf95 100644 --- a/src/aosm/azext_aosm/tests/latest/test_nsd.py +++ b/src/aosm/azext_aosm/tests/latest/test_nsd.py @@ -6,13 +6,14 @@ import os from dataclasses import dataclass import json +from pathlib import Path from unittest.mock import patch from tempfile import TemporaryDirectory from typing import Any, Dict from azext_aosm.custom import generate_design_config, build_design -mock_nsd_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_nsd") +mock_nsd_folder = ((Path(__file__).parent) / "mock_nsd").resolve() class TestNSDGenerator: @@ -82,7 +83,7 @@ def __init__(self) -> None: build_design( cmd, client=mock_client, - config_file=os.path.join(mock_nsd_folder, "input.json"), + config_file=str(mock_nsd_folder / "input.json"), ) assert os.path.exists("nsd-bicep-templates") finally: diff --git a/src/aosm/azext_aosm/tests/latest/test_vnf.py b/src/aosm/azext_aosm/tests/latest/test_vnf.py index 57fc466d929..b44574ef6bb 100644 --- a/src/aosm/azext_aosm/tests/latest/test_vnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_vnf.py @@ -5,11 +5,12 @@ import os import unittest +from pathlib import Path from tempfile import TemporaryDirectory from azext_aosm.custom import build_definition, generate_definition_config -mock_vnf_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), "mock_vnf") +mock_vnf_folder = ((Path(__file__).parent) / "mock_vnf").resolve() class TestVNF(unittest.TestCase): @@ -36,7 +37,7 @@ def test_build(self): os.chdir(test_dir) try: - build_definition("vnf", os.path.join(mock_vnf_folder, "input.json")) + build_definition("vnf", str(mock_vnf_folder / "input.json")) assert os.path.exists("nfd-bicep-ubuntu-template") finally: os.chdir(starting_directory) @@ -52,7 +53,7 @@ def test_build_with_ordered_params(self): try: build_definition( "vnf", - os.path.join(mock_vnf_folder, "input.json"), + str(mock_vnf_folder / "input.json"), order_params=True, ) assert os.path.exists("nfd-bicep-ubuntu-template") From 2ab8cf6f3827f905d46b6c2042a10fd5a76e0927 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 5 Jul 2023 12:55:11 +0100 Subject: [PATCH 133/145] mypy fixups --- src/aosm/azext_aosm/_configuration.py | 12 +++++----- src/aosm/azext_aosm/custom.py | 13 ++++++----- src/aosm/azext_aosm/delete/delete.py | 3 ++- .../azext_aosm/deploy/artifact_manifest.py | 2 +- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 18 +++++++++------ src/aosm/azext_aosm/deploy/pre_deploy.py | 4 +++- .../azext_aosm/generate_nsd/nsd_generator.py | 23 +++++++++++-------- 7 files changed, 44 insertions(+), 31 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 0475350a592..83ea098102d 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -3,7 +3,7 @@ import re from dataclasses import dataclass, field from pathlib import Path -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional, Union from azure.cli.core.azclierror import InvalidArgumentValueError, ValidationError @@ -237,10 +237,10 @@ def validate(self): raise ValueError("NSD Version must be set") @property - def build_output_folder_name(self) -> str: + def output_directory_for_build(self) -> Path: """Return the local folder for generating the bicep template to.""" current_working_directory = os.getcwd() - return f"{current_working_directory}/{NSD_OUTPUT_BICEP_PREFIX}" + return Path(f"{current_working_directory}/{NSD_OUTPUT_BICEP_PREFIX}") @property def resource_element_name(self) -> str: @@ -276,7 +276,7 @@ def arm_template(self) -> ArtifactConfig: artifact = ArtifactConfig() artifact.version = self.nsd_version artifact.file_path = os.path.join( - self.build_output_folder_name, NF_DEFINITION_JSON_FILENAME + self.output_directory_for_build, NF_DEFINITION_JSON_FILENAME ) return artifact @@ -418,8 +418,8 @@ def validate(self): def get_configuration( - configuration_type: str, config_file: str = None -) -> NFConfiguration or NSConfiguration: + configuration_type: str, config_file: Optional[str] = None +) -> Union[NFConfiguration, NSConfiguration]: """ Return the correct configuration object based on the type. diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index e444909e806..9f9e0c94473 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -8,7 +8,7 @@ import shutil from dataclasses import asdict from pathlib import Path -from typing import Optional +from typing import Optional, Union from azure.cli.core.azclierror import ( CLIInternalError, @@ -57,6 +57,7 @@ def build_definition( config = _get_config_from_file( config_file=config_file, configuration_type=definition_type ) + assert isinstance(config, NFConfiguration) # Generate the NFD and the artifact manifest. _generate_nfd( @@ -80,7 +81,7 @@ def generate_definition_config(definition_type: str, output_file: str = "input.j def _get_config_from_file( config_file: str, configuration_type: str -) -> NFConfiguration or NSConfiguration: +) -> Union[NFConfiguration, NSConfiguration]: """ Read input config file JSON and turn it into a Configuration object. @@ -363,7 +364,7 @@ def publish_design( ) config = _get_config_from_file(config_file=config_file, configuration_type=NSD) - + assert isinstance(config, NSConfiguration) config.validate() deployer = DeployerViaArm(api_clients, config=config) @@ -379,14 +380,14 @@ def publish_design( def _generate_nsd(config: NSConfiguration, api_clients: ApiClients): """Generate a Network Service Design for the given config.""" - if os.path.exists(config.build_output_folder_name): + if os.path.exists(config.output_directory_for_build): carry_on = input( - f"The folder {config.build_output_folder_name} already exists - delete it" + f"The folder {config.output_directory_for_build} already exists - delete it" " and continue? (y/n)" ) if carry_on != "y": raise UnclassifiedUserFault("User aborted! ") - shutil.rmtree(config.build_output_folder_name) + shutil.rmtree(config.output_directory_for_build) nsd_generator = NSDGenerator(api_clients, config) nsd_generator.generate_nsd() diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 6894f6f3544..6e956de1244 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -4,6 +4,7 @@ # -------------------------------------------------------------------------------------- """Contains class for deploying generated definitions using the Python SDK.""" from knack.log import get_logger +from typing import Union from azext_aosm._configuration import NFConfiguration, NSConfiguration, VNFConfiguration from azext_aosm.util.management_clients import ApiClients @@ -16,7 +17,7 @@ class ResourceDeleter: def __init__( self, api_clients: ApiClients, - config: NFConfiguration or NSConfiguration, + config: Union[NFConfiguration, NSConfiguration], ) -> None: """ Initializes a new instance of the Deployer class. diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 1ac303d4590..0067a95cf50 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -29,7 +29,7 @@ class ArtifactManifestOperator: # pylint: disable=too-few-public-methods def __init__( self, - config: NFConfiguration or NSConfiguration, + config: Union[NFConfiguration, NSConfiguration], api_clients: ApiClients, store_name: str, manifest_name: str, diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index f66e1e0995a..bb1852245fb 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -9,7 +9,7 @@ import subprocess # noqa import tempfile import time -from typing import Any, Dict, Optional +from typing import Any, Dict, Optional, Union from azure.mgmt.resource.resources.models import DeploymentExtended from knack.log import get_logger @@ -53,7 +53,7 @@ class DeployerViaArm: def __init__( self, api_clients: ApiClients, - config: NFConfiguration or NSConfiguration, + config: Union[NFConfiguration,NSConfiguration], ) -> None: """ Initializes a new instance of the Deployer class. @@ -297,7 +297,7 @@ def deploy_cnfd_from_bicep( # User has not passed in a bicep template, so we are deploying the # default one produced from building the NFDV using this CLI bicep_path = os.path.join( - self.config.build_output_folder_name, + self.config.output_directory_for_build, CNF_DEFINITION_BICEP_TEMPLATE_FILENAME, ) @@ -434,7 +434,7 @@ def deploy_nsd_from_bicep( # User has not passed in a bicep template, so we are deploying the default # one produced from building the NSDV using this CLI bicep_path = os.path.join( - self.config.build_output_folder_name, + self.config.output_directory_for_build, NSD_BICEP_FILENAME, ) @@ -490,10 +490,14 @@ def deploy_nsd_from_bicep( # Convert the NF bicep to ARM arm_template_artifact_json = self.convert_bicep_to_arm( os.path.join( - self.config.build_output_folder_name, NF_DEFINITION_BICEP_FILENAME - ) + self.config.output_directory_for_build, + NF_DEFINITION_BICEP_FILENAME) ) + # appease mypy + assert self.config.arm_template.file_path, ( + "Config missing ARM template file path" + ) with open(self.config.arm_template.file_path, "w", encoding="utf-8") as file: file.write(json.dumps(arm_template_artifact_json, indent=4)) @@ -523,7 +527,7 @@ def deploy_manifest_template( file_name = CNF_MANIFEST_BICEP_TEMPLATE_FILENAME manifest_bicep_path = os.path.join( - self.config.build_output_folder_name, + self.config.output_directory_for_build, file_name, ) if not manifest_parameters_json_file: diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 8c314a2872c..e2ee0d7bf37 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -9,6 +9,7 @@ from azure.core import exceptions as azure_exceptions from azure.mgmt.resource.resources.models import ResourceGroup from knack.log import get_logger +from typing import Union from azext_aosm._configuration import ( NFConfiguration, @@ -40,7 +41,7 @@ class PreDeployerViaSDK: def __init__( self, api_clients: ApiClients, - config: NFConfiguration or NSConfiguration, + config: Union[NFConfiguration, NSConfiguration], ) -> None: """ Initializes a new instance of the Deployer class. @@ -166,6 +167,7 @@ def ensure_config_source_registry_exists(self) -> None: source_registry_name = source_registry_match.group("registry_name") # This will raise an error if the registry does not exist + assert self.api_clients.container_registry_client self.api_clients.container_registry_client.get( resource_group_name=source_registry_resource_group_name, registry_name=source_registry_name, diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index bf1bdc1b1f8..5a26d1f8dda 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -62,8 +62,10 @@ def __init__(self, api_clients: ApiClients, config: NSConfiguration): self.nsd_bicep_template_name = NSD_DEFINITION_JINJA2_SOURCE_TEMPLATE self.nf_bicep_template_name = NF_TEMPLATE_JINJA2_SOURCE_TEMPLATE self.nsd_bicep_output_name = NSD_BICEP_FILENAME - self.nfdv_parameter_name = f"{self.config.network_function_definition_group_name.replace('-', '_')}_nfd_version" - self.build_folder_name = self.config.build_output_folder_name + self.nfdv_parameter_name = ( + f"{self.config.network_function_definition_group_name.replace('-', '_')}" + "_nfd_version" + ) nfdv = self._get_nfdv(config, api_clients) print("Finding the deploy parameters of the NFDV resource") if not nfdv.deploy_parameters: @@ -105,7 +107,10 @@ def generate_nsd(self) -> None: self.write_nsd_bicep() self.copy_to_output_folder() - print(f"Generated NSD bicep templates created in {self.build_folder_name}") + print( + "Generated NSD bicep templates created in" + f" {self.config.output_directory_for_build}" + ) print( "Please review these templates. When you are happy with them run " "`az aosm nsd publish` with the same arguments." @@ -115,9 +120,9 @@ def generate_nsd(self) -> None: def config_group_schema_dict(self) -> Dict[str, Any]: """ :return: The Config Group Schema as a dictionary. + + This function cannot be called before deployment parameters have been supplied. """ - # This function cannot be called before deployment parameters have been - # supplied. assert self.deploy_parameters # Take a copy of the deploy parameters. @@ -330,13 +335,13 @@ def generate_bicep(self, def copy_to_output_folder(self) -> None: """Copy the bicep templates, config mappings and schema into the build output folder.""" - logger.info("Create NSD bicep %s", self.build_folder_name) - os.mkdir(self.build_folder_name) + logger.info("Create NSD bicep %s", self.config.output_directory_for_build) + os.mkdir(self.config.output_directory_for_build) shutil.copytree( self.tmp_folder_name, - self.build_folder_name, + self.config.output_directory_for_build, dirs_exist_ok=True, ) - logger.info("Copied files to %s", self.build_folder_name) + logger.info("Copied files to %s", self.config.output_directory_for_build) From 00268ef42b8021824c2601b6a50f4edb122a0d9d Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 5 Jul 2023 13:47:08 +0100 Subject: [PATCH 134/145] mypy fixes --- src/aosm/azext_aosm/_configuration.py | 9 ++++++++- src/aosm/azext_aosm/delete/delete.py | 8 ++++++-- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 3 ++- src/aosm/azext_aosm/deploy/pre_deploy.py | 4 ++-- src/aosm/azext_aosm/generate_nsd/nsd_generator.py | 4 ++-- src/aosm/pyproject.toml | 7 +++++++ 6 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 src/aosm/pyproject.toml diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 83ea098102d..95e9a65a9a7 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,3 +1,4 @@ +import abc import json import os import re @@ -118,7 +119,7 @@ class ArtifactConfig: @dataclass -class Configuration: +class Configuration(abc.ABC): config_file: Optional[str] = None def path_from_cli_dir(self, path: str) -> str: @@ -141,9 +142,15 @@ def path_from_cli_dir(self, path: str) -> str: return os.path.join(os.path.dirname(self.config_file), path) + @abc.abstractmethod + def output_directory_for_build(self) -> Path: + """Base class method to ensure subclasses implement this function.""" + + @dataclass class NFConfiguration(Configuration): + """Network Function configuration.""" publisher_name: str = DESCRIPTION_MAP["publisher_name"] publisher_resource_group_name: str = DESCRIPTION_MAP[ "publisher_resource_group_name" diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 6e956de1244..43cfded0842 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -33,12 +33,12 @@ def __init__( def delete_nfd(self, clean: bool = False): """ - Delete the NFDV and manifests. If they don't exist it still reports them as - deleted. + Delete the NFDV and manifests. If they don't exist it still reports them as deleted. :param clean: Delete the NFDG, artifact stores and publisher too. Defaults to False. Use with care. """ + assert isinstance(self.config, NFConfiguration) if clean: print( @@ -106,6 +106,7 @@ def delete_nsd(self): self.delete_config_group_schema() def delete_nfdv(self): + assert isinstance(self.config, NFConfiguration) message = ( f"Delete NFDV {self.config.version} from group {self.config.nfdg_name} and" f" publisher {self.config.publisher_name}" @@ -200,6 +201,7 @@ def delete_artifact_manifest(self, store_type: str) -> None: def delete_nsdg(self) -> None: """Delete the NSDG.""" + assert isinstance(self.config, NSConfiguration) message = f"Delete NSD Group {self.config.nsdg_name}" logger.debug(message) print(message) @@ -219,6 +221,7 @@ def delete_nsdg(self) -> None: def delete_nfdg(self) -> None: """Delete the NFDG.""" + assert isinstance(self.config, NFConfiguration) message = f"Delete NFD Group {self.config.nfdg_name}" logger.debug(message) print(message) @@ -288,6 +291,7 @@ def delete_publisher(self) -> None: def delete_config_group_schema(self) -> None: """Delete the Configuration Group Schema.""" + assert isinstance(self.config, NSConfiguration) message = f"Delete Configuration Group Schema {self.config.cg_schema_name}" logger.debug(message) print(message) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index bb1852245fb..150afd4e3e0 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -519,6 +519,7 @@ def deploy_manifest_template( logger.debug("Deploy manifest bicep") if not manifest_bicep_path: + file_name: str = "" if configuration_type == NSD: file_name = NSD_ARTIFACT_MANIFEST_BICEP_FILENAME elif configuration_type == VNF: @@ -527,7 +528,7 @@ def deploy_manifest_template( file_name = CNF_MANIFEST_BICEP_TEMPLATE_FILENAME manifest_bicep_path = os.path.join( - self.config.output_directory_for_build, + str(self.config.output_directory_for_build), file_name, ) if not manifest_parameters_json_file: diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index e2ee0d7bf37..9d12dcccef4 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -252,7 +252,7 @@ def ensure_acr_artifact_store_exists(self) -> None: self.config.publisher_resource_group_name, self.config.publisher_name, self.config.acr_artifact_store_name, - ArtifactStoreType.AZURE_CONTAINER_REGISTRY, + ArtifactStoreType.AZURE_CONTAINER_REGISTRY, # type: ignore self.config.location, ) @@ -273,7 +273,7 @@ def ensure_sa_artifact_store_exists(self) -> None: self.config.publisher_resource_group_name, self.config.publisher_name, self.config.blob_artifact_store_name, - ArtifactStoreType.AZURE_STORAGE_ACCOUNT, + ArtifactStoreType.AZURE_STORAGE_ACCOUNT, # type: ignore self.config.location, ) diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index 5a26d1f8dda..c825fbb372e 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -270,9 +270,9 @@ def write_nf_bicep(self) -> None: # NF, as we do for deployParameters, but the SDK currently doesn't # support this and needs to be rebuilt to do so. "nfvi_type": ( - NFVIType.AZURE_CORE.value + NFVIType.AZURE_CORE.value # type: ignore[attr-defined] if self.config.network_function_type == VNF - else NFVIType.AZURE_ARC_KUBERNETES.value + else NFVIType.AZURE_ARC_KUBERNETES.value # type: ignore[attr-defined] ), "CNF": True if self.config.network_function_type == CNF else False, }, diff --git a/src/aosm/pyproject.toml b/src/aosm/pyproject.toml new file mode 100644 index 00000000000..e4bbc5837c4 --- /dev/null +++ b/src/aosm/pyproject.toml @@ -0,0 +1,7 @@ +[tool.mypy] +ignore_missing_imports = true +no_namespace_packages = true + +[[tool.mypy.overrides]] +module = ["azext_aosm.vendored_sdks.*"] +ignore_errors = true From 4997d04ce26116f65a66a253c53ed3c955ee6ab1 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 5 Jul 2023 13:49:35 +0100 Subject: [PATCH 135/145] linting --- src/aosm/azext_aosm/_configuration.py | 11 +++++++---- src/aosm/azext_aosm/deploy/artifact.py | 9 +++++---- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 16 +++++++++------- src/aosm/azext_aosm/deploy/pre_deploy.py | 2 +- .../azext_aosm/generate_nsd/nsd_generator.py | 7 +++---- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 95e9a65a9a7..397b1977623 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -147,10 +147,10 @@ def output_directory_for_build(self) -> Path: """Base class method to ensure subclasses implement this function.""" - @dataclass class NFConfiguration(Configuration): """Network Function configuration.""" + publisher_name: str = DESCRIPTION_MAP["publisher_name"] publisher_resource_group_name: str = DESCRIPTION_MAP[ "publisher_resource_group_name" @@ -396,7 +396,9 @@ def __post_init__(self): """ for package_index, package in enumerate(self.helm_packages): if isinstance(package, dict): - package["path_to_chart"] = self.path_from_cli_dir(package["path_to_chart"]) + package["path_to_chart"] = self.path_from_cli_dir( + package["path_to_chart"] + ) package["path_to_mappings"] = self.path_from_cli_dir( package["path_to_mappings"] ) @@ -404,11 +406,12 @@ def __post_init__(self): @property def output_directory_for_build(self) -> Path: - """Return the directory the build command will writes its output to""" + """Return the directory the build command will writes its output to.""" return Path(f"{NF_DEFINITION_OUTPUT_BICEP_PREFIX}{self.nf_name}") def validate(self): - """Validate the CNF config + """ + Validate the CNF config. :raises ValidationError: If source registry ID doesn't match the regex """ diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 8fc72f4d8ef..8175278d29a 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -10,8 +10,7 @@ from azure.cli.core.commands import LongRunningOperation from azure.mgmt.containerregistry import ContainerRegistryManagementClient -from azure.mgmt.containerregistry.models import (ImportImageParameters, - ImportSource) +from azure.mgmt.containerregistry.models import ImportImageParameters, ImportSource from azure.storage.blob import BlobClient, BlobType from knack.log import get_logger from knack.util import CLIError @@ -65,12 +64,14 @@ def _upload_arm_to_acr(self, artifact_config: ArtifactConfig) -> None: # filepath (so tempfile can't be used and we just put it in the working # directory), that can act as the manifest config file. So create one # and then delete it after the upload. - with open("dummyManifestConfig.json", "w", encoding='utf-8') as f: + with open("dummyManifestConfig.json", "w", encoding="utf-8") as f: target = ( f"{self.artifact_client.remote.hostname.replace('https://', '')}" f"/{self.artifact_name}:{self.artifact_version}" ) - logger.debug("Uploading %s to %s", artifact_config.file_path, target) + logger.debug( + "Uploading %s to %s", artifact_config.file_path, target + ) self.artifact_client.push( files=[artifact_config.file_path], target=target, diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 150afd4e3e0..3962a83f82a 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -53,7 +53,7 @@ class DeployerViaArm: def __init__( self, api_clients: ApiClients, - config: Union[NFConfiguration,NSConfiguration], + config: Union[NFConfiguration, NSConfiguration] ) -> None: """ Initializes a new instance of the Deployer class. @@ -224,7 +224,9 @@ def construct_vnfd_parameters(self) -> Dict[str, Any]: def construct_cnfd_parameters(self) -> Dict[str, Any]: """ - Create the parmeters dictionary for cnfdefinition.bicep. CNF specific. + Create the parmeters dictionary for cnfdefinition.bicep. + + CNF specific. """ assert isinstance(self.config, CNFConfiguration) return { @@ -490,14 +492,14 @@ def deploy_nsd_from_bicep( # Convert the NF bicep to ARM arm_template_artifact_json = self.convert_bicep_to_arm( os.path.join( - self.config.output_directory_for_build, - NF_DEFINITION_BICEP_FILENAME) + self.config.output_directory_for_build, NF_DEFINITION_BICEP_FILENAME + ) ) # appease mypy - assert self.config.arm_template.file_path, ( - "Config missing ARM template file path" - ) + assert ( + self.config.arm_template.file_path + ), "Config missing ARM template file path" with open(self.config.arm_template.file_path, "w", encoding="utf-8") as file: file.write(json.dumps(arm_template_artifact_json, indent=4)) diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 9d12dcccef4..f58a9f33d2e 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -144,7 +144,7 @@ def ensure_config_publisher_exists(self) -> None: def ensure_config_source_registry_exists(self) -> None: """ - Ensures that the source registry exists + Ensures that the source registry exists. Finds the parameters from self.config """ diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index c825fbb372e..d2416324897 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -303,10 +303,9 @@ def write_nsd_manifest(self) -> None: {}, ) - def generate_bicep(self, - template_name: str, - output_file_name: str, - params: Dict[Any, Any]) -> None: + def generate_bicep( + self, template_name: str, output_file_name: str, params: Dict[Any, Any] + ) -> None: """ Render the bicep templates with the correct parameters and copy them into the build output folder. From ac4894454b06e02fb3a28762829a999f10fc4884 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 5 Jul 2023 13:53:14 +0100 Subject: [PATCH 136/145] mypy --- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 3962a83f82a..e6bcf713e87 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -350,6 +350,12 @@ def deploy_cnfd_from_bicep( publisher_name=self.config.publisher_name, artifact_store_name=self.config.acr_artifact_store_name, ) + if not acr_properties.storage_resource_id: + raise ValueError( + f"Artifact store {self.config.acr_artifact_store_name} " + "has no storage resource id linked" + ) + target_registry_name = acr_properties.storage_resource_id.split("/")[-1] target_registry_resource_group_name = acr_properties.storage_resource_id.split( "/" From a22c4ebb57eb5d4112d937004740af2ca718a374 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Wed, 5 Jul 2023 14:11:57 +0100 Subject: [PATCH 137/145] mypy for _configuration.py --- src/aosm/azext_aosm/_configuration.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 397b1977623..2fa1442e0b9 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,4 +1,5 @@ import abc +import logging import json import os import re @@ -18,6 +19,9 @@ SOURCE_ACR_REGEX, ) + +logger = logging.getLogger(__name__) + DESCRIPTION_MAP: Dict[str, str] = { "publisher_resource_group_name": ( "Resource group for the Publisher resource. " @@ -132,6 +136,8 @@ def path_from_cli_dir(self, path: str) -> str: :param path: The path relative to the config file. """ + assert self.config_file + # If no path has been supplied we shouldn't try to update it. if path == "": return "" @@ -140,9 +146,16 @@ def path_from_cli_dir(self, path: str) -> str: if os.path.isabs(path): return path - return os.path.join(os.path.dirname(self.config_file), path) + config_file_dir = Path(self.config_file).parent + + updated_path = str(config_file_dir / path) + + logger.debug("Updated path: %s", updated_path) + + return updated_path @abc.abstractmethod + @property def output_directory_for_build(self) -> Path: """Base class method to ensure subclasses implement this function.""" @@ -429,7 +442,7 @@ def validate(self): def get_configuration( configuration_type: str, config_file: Optional[str] = None -) -> Union[NFConfiguration, NSConfiguration]: +) -> Configuration: """ Return the correct configuration object based on the type. @@ -443,6 +456,8 @@ def get_configuration( else: config_as_dict = {} + config: Configuration + if configuration_type == VNF: config = VNFConfiguration(config_file=config_file, **config_as_dict) elif configuration_type == CNF: From aa0565b9776f85262bee57e860b0d87cdd128064 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Wed, 5 Jul 2023 14:15:01 +0100 Subject: [PATCH 138/145] mypy for vnf_nfd_generator.py --- src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py index 98dd6a587e0..3aaa6ca25d6 100644 --- a/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py @@ -103,7 +103,7 @@ def nfd_bicep_path(self) -> Optional[Path]: return None @property - def manifest_bicep_path(self) -> Optional[str]: + def manifest_bicep_path(self) -> Optional[Path]: """Returns the path to the bicep file for the NFD if it has been created.""" if self._manifest_bicep_path.exists(): return self._manifest_bicep_path @@ -149,6 +149,7 @@ def vm_parameters_ordered(self) -> Dict[str, Any]: def _create_parameter_files(self) -> None: """Create the deployment, template and VHD parameter files.""" + assert self._tmp_dir tmp_schemas_directory: Path = self._tmp_dir / SCHEMAS_DIR_NAME tmp_schemas_directory.mkdir() self.write_deployment_parameters(tmp_schemas_directory) @@ -298,6 +299,7 @@ def write_vhd_parameters(self, directory: Path) -> None: def _copy_to_output_directory(self) -> None: """Copy the static bicep templates and generated config mappings and schema into the build output directory.""" logger.info("Create NFD bicep %s", self.output_directory) + assert self._tmp_dir Path(self.output_directory).mkdir(exist_ok=True) static_bicep_templates_dir = Path(__file__).parent / "templates" From ef0a40ec348830ddfbefa8835b3e6ef2d221d08a Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 5 Jul 2023 15:24:01 +0100 Subject: [PATCH 139/145] mypy appeasement --- src/aosm/azext_aosm/_configuration.py | 17 ++++++++++++++--- src/aosm/azext_aosm/custom.py | 3 ++- src/aosm/azext_aosm/delete/delete.py | 4 ++-- src/aosm/azext_aosm/deploy/artifact.py | 10 +++++++++- src/aosm/azext_aosm/deploy/artifact_manifest.py | 4 ++-- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 4 ++-- src/aosm/azext_aosm/deploy/pre_deploy.py | 6 +++--- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 2fa1442e0b9..a3501f38908 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -125,7 +125,13 @@ class ArtifactConfig: @dataclass class Configuration(abc.ABC): config_file: Optional[str] = None - + publisher_name: str = DESCRIPTION_MAP["publisher_name"] + publisher_resource_group_name: str = DESCRIPTION_MAP[ + "publisher_resource_group_name" + ] + acr_artifact_store_name: str = DESCRIPTION_MAP["acr_artifact_store_name"] + location: str = DESCRIPTION_MAP["location"] + def path_from_cli_dir(self, path: str) -> str: """ Convert path from config file to path from current directory. @@ -154,10 +160,15 @@ def path_from_cli_dir(self, path: str) -> str: return updated_path - @abc.abstractmethod - @property + @abc.abstractproperty def output_directory_for_build(self) -> Path: """Base class method to ensure subclasses implement this function.""" + raise NotImplementedError("Subclass must define property") + + @abc.abstractproperty + def acr_manifest_name(self) -> str: + """Base class method to ensure subclasses implement this function.""" + raise NotImplementedError("Subclass must define property") @dataclass diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 9f9e0c94473..a124513d19b 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -20,6 +20,7 @@ from azext_aosm._client_factory import cf_acr_registries, cf_resources from azext_aosm._configuration import ( CNFConfiguration, + Configuration, NFConfiguration, NSConfiguration, VNFConfiguration, @@ -81,7 +82,7 @@ def generate_definition_config(definition_type: str, output_file: str = "input.j def _get_config_from_file( config_file: str, configuration_type: str -) -> Union[NFConfiguration, NSConfiguration]: +) -> Configuration: """ Read input config file JSON and turn it into a Configuration object. diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 43cfded0842..ec22aeda543 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -6,7 +6,7 @@ from knack.log import get_logger from typing import Union -from azext_aosm._configuration import NFConfiguration, NSConfiguration, VNFConfiguration +from azext_aosm._configuration import Configuration, NFConfiguration, NSConfiguration, VNFConfiguration from azext_aosm.util.management_clients import ApiClients from azext_aosm.util.utils import input_ack @@ -17,7 +17,7 @@ class ResourceDeleter: def __init__( self, api_clients: ApiClients, - config: Union[NFConfiguration, NSConfiguration], + config: Configuration, ) -> None: """ Initializes a new instance of the Deployer class. diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 8175278d29a..2ebe2ec6f0c 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -32,7 +32,7 @@ class Artifact: artifact_version: str artifact_client: Union[BlobClient, OrasClient] - def upload(self, artifact_config: ArtifactConfig or HelmPackageConfig) -> None: + def upload(self, artifact_config: Union[ArtifactConfig, HelmPackageConfig]) -> None: """ Upload aritfact. @@ -46,6 +46,7 @@ def upload(self, artifact_config: ArtifactConfig or HelmPackageConfig) -> None: else: raise ValueError(f"Unsupported artifact type: {type(artifact_config)}.") else: + assert isinstance(artifact_config, ArtifactConfig) self._upload_to_storage_account(artifact_config) def _upload_arm_to_acr(self, artifact_config: ArtifactConfig) -> None: @@ -94,7 +95,12 @@ def _upload_helm_to_acr(self, artifact_config: HelmPackageConfig) -> None: :param artifact_config: configuration for the artifact being uploaded """ + assert isinstance(self.artifact_client, OrasClient) chart_path = artifact_config.path_to_chart + if not self.artifact_client.remote.hostname: + raise ValueError( + "Cannot upload artifact. Oras client has no remote hostname." + ) registry = self.artifact_client.remote.hostname.replace("https://", "") target_registry = f"oci://{registry}" registry_name = registry.replace(".azurecr.io", "") @@ -138,6 +144,8 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None: self.artifact_client.account_name, ) else: + # Config Validation will raise error if not true + assert artifact_config.blob_sas_url logger.info("Copy from SAS URL to blob store") source_blob = BlobClient.from_blob_url(artifact_config.blob_sas_url) diff --git a/src/aosm/azext_aosm/deploy/artifact_manifest.py b/src/aosm/azext_aosm/deploy/artifact_manifest.py index 0067a95cf50..20cecf5c056 100644 --- a/src/aosm/azext_aosm/deploy/artifact_manifest.py +++ b/src/aosm/azext_aosm/deploy/artifact_manifest.py @@ -10,7 +10,7 @@ from knack.log import get_logger from oras.client import OrasClient -from azext_aosm._configuration import NFConfiguration, NSConfiguration +from azext_aosm._configuration import Configuration from azext_aosm.deploy.artifact import Artifact from azext_aosm.util.management_clients import ApiClients from azext_aosm.vendored_sdks.models import ( @@ -29,7 +29,7 @@ class ArtifactManifestOperator: # pylint: disable=too-few-public-methods def __init__( self, - config: Union[NFConfiguration, NSConfiguration], + config: Configuration, api_clients: ApiClients, store_name: str, manifest_name: str, diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index e6bcf713e87..5355c1a9023 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -16,7 +16,7 @@ from azext_aosm._configuration import ( CNFConfiguration, - NFConfiguration, + Configuration, NSConfiguration, VNFConfiguration, ) @@ -53,7 +53,7 @@ class DeployerViaArm: def __init__( self, api_clients: ApiClients, - config: Union[NFConfiguration, NSConfiguration] + config: Configuration ) -> None: """ Initializes a new instance of the Deployer class. diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index f58a9f33d2e..617889795b2 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -12,7 +12,7 @@ from typing import Union from azext_aosm._configuration import ( - NFConfiguration, + Configuration, NSConfiguration, VNFConfiguration, CNFConfiguration, @@ -41,7 +41,7 @@ class PreDeployerViaSDK: def __init__( self, api_clients: ApiClients, - config: Union[NFConfiguration, NSConfiguration], + config: Configuration, ) -> None: """ Initializes a new instance of the Deployer class. @@ -387,7 +387,7 @@ def does_artifact_manifest_exist( def do_config_artifact_manifests_exist( self, - ): + ) -> bool: """Returns True if all required manifests exist, False otherwise.""" acr_manny_exists: bool = self.does_artifact_manifest_exist( rg_name=self.config.publisher_resource_group_name, From 926930e78ad24fe532b68be80a0131742869d087 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 5 Jul 2023 15:26:51 +0100 Subject: [PATCH 140/145] python-static-checks fmt --- src/aosm/azext_aosm/_configuration.py | 2 +- src/aosm/azext_aosm/custom.py | 4 +--- src/aosm/azext_aosm/delete/delete.py | 7 ++++++- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 6 +----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index a3501f38908..92de3481c3d 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -131,7 +131,7 @@ class Configuration(abc.ABC): ] acr_artifact_store_name: str = DESCRIPTION_MAP["acr_artifact_store_name"] location: str = DESCRIPTION_MAP["location"] - + def path_from_cli_dir(self, path: str) -> str: """ Convert path from config file to path from current directory. diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index a124513d19b..3c816a41caa 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -80,9 +80,7 @@ def generate_definition_config(definition_type: str, output_file: str = "input.j _generate_config(configuration_type=definition_type, output_file=output_file) -def _get_config_from_file( - config_file: str, configuration_type: str -) -> Configuration: +def _get_config_from_file(config_file: str, configuration_type: str) -> Configuration: """ Read input config file JSON and turn it into a Configuration object. diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index ec22aeda543..7e7ca2dd7eb 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -6,7 +6,12 @@ from knack.log import get_logger from typing import Union -from azext_aosm._configuration import Configuration, NFConfiguration, NSConfiguration, VNFConfiguration +from azext_aosm._configuration import ( + Configuration, + NFConfiguration, + NSConfiguration, + VNFConfiguration, +) from azext_aosm.util.management_clients import ApiClients from azext_aosm.util.utils import input_ack diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index 5355c1a9023..ebb0942ec3c 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -50,11 +50,7 @@ class DeployerViaArm: templates. """ - def __init__( - self, - api_clients: ApiClients, - config: Configuration - ) -> None: + def __init__(self, api_clients: ApiClients, config: Configuration) -> None: """ Initializes a new instance of the Deployer class. From 90acb1acc4692798b59a5cf054c33b3c6e0afbe5 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 5 Jul 2023 15:52:55 +0100 Subject: [PATCH 141/145] az style happy --- src/aosm/azext_aosm/_configuration.py | 6 +++--- src/aosm/azext_aosm/custom.py | 2 +- src/aosm/azext_aosm/delete/delete.py | 1 - src/aosm/azext_aosm/deploy/artifact.py | 2 -- src/aosm/azext_aosm/deploy/deploy_with_arm.py | 2 +- src/aosm/azext_aosm/deploy/pre_deploy.py | 1 - src/aosm/azext_aosm/generate_nsd/nsd_generator.py | 14 ++++++++------ 7 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 92de3481c3d..0c3dd7acd97 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -5,7 +5,7 @@ import re from dataclasses import dataclass, field from pathlib import Path -from typing import Any, Dict, List, Optional, Union +from typing import Any, Dict, List, Optional from azure.cli.core.azclierror import InvalidArgumentValueError, ValidationError @@ -160,12 +160,12 @@ def path_from_cli_dir(self, path: str) -> str: return updated_path - @abc.abstractproperty + @property def output_directory_for_build(self) -> Path: """Base class method to ensure subclasses implement this function.""" raise NotImplementedError("Subclass must define property") - @abc.abstractproperty + @property def acr_manifest_name(self) -> str: """Base class method to ensure subclasses implement this function.""" raise NotImplementedError("Subclass must define property") diff --git a/src/aosm/azext_aosm/custom.py b/src/aosm/azext_aosm/custom.py index 3c816a41caa..e3e6d225ece 100644 --- a/src/aosm/azext_aosm/custom.py +++ b/src/aosm/azext_aosm/custom.py @@ -8,7 +8,7 @@ import shutil from dataclasses import asdict from pathlib import Path -from typing import Optional, Union +from typing import Optional from azure.cli.core.azclierror import ( CLIInternalError, diff --git a/src/aosm/azext_aosm/delete/delete.py b/src/aosm/azext_aosm/delete/delete.py index 7e7ca2dd7eb..3580a5d7737 100644 --- a/src/aosm/azext_aosm/delete/delete.py +++ b/src/aosm/azext_aosm/delete/delete.py @@ -4,7 +4,6 @@ # -------------------------------------------------------------------------------------- """Contains class for deploying generated definitions using the Python SDK.""" from knack.log import get_logger -from typing import Union from azext_aosm._configuration import ( Configuration, diff --git a/src/aosm/azext_aosm/deploy/artifact.py b/src/aosm/azext_aosm/deploy/artifact.py index 2ebe2ec6f0c..eada313c6bb 100644 --- a/src/aosm/azext_aosm/deploy/artifact.py +++ b/src/aosm/azext_aosm/deploy/artifact.py @@ -15,8 +15,6 @@ from knack.log import get_logger from knack.util import CLIError from oras.client import OrasClient -from azure.cli.core.commands import LongRunningOperation -from azure.mgmt.containerregistry import ContainerRegistryManagementClient from azext_aosm._configuration import ArtifactConfig, HelmPackageConfig diff --git a/src/aosm/azext_aosm/deploy/deploy_with_arm.py b/src/aosm/azext_aosm/deploy/deploy_with_arm.py index ebb0942ec3c..0d79fafcddd 100644 --- a/src/aosm/azext_aosm/deploy/deploy_with_arm.py +++ b/src/aosm/azext_aosm/deploy/deploy_with_arm.py @@ -9,7 +9,7 @@ import subprocess # noqa import tempfile import time -from typing import Any, Dict, Optional, Union +from typing import Any, Dict, Optional from azure.mgmt.resource.resources.models import DeploymentExtended from knack.log import get_logger diff --git a/src/aosm/azext_aosm/deploy/pre_deploy.py b/src/aosm/azext_aosm/deploy/pre_deploy.py index 617889795b2..ea5147fc44d 100644 --- a/src/aosm/azext_aosm/deploy/pre_deploy.py +++ b/src/aosm/azext_aosm/deploy/pre_deploy.py @@ -9,7 +9,6 @@ from azure.core import exceptions as azure_exceptions from azure.mgmt.resource.resources.models import ResourceGroup from knack.log import get_logger -from typing import Union from azext_aosm._configuration import ( Configuration, diff --git a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py index d2416324897..18c81f3731d 100644 --- a/src/aosm/azext_aosm/generate_nsd/nsd_generator.py +++ b/src/aosm/azext_aosm/generate_nsd/nsd_generator.py @@ -76,6 +76,7 @@ def __init__(self, api_clients: ApiClients, config: NSConfiguration): nfdv.deploy_parameters ) + # pylint: disable=no-self-use def _get_nfdv( self, config: NSConfiguration, api_clients ) -> NetworkFunctionDefinitionVersion: @@ -99,7 +100,7 @@ def generate_nsd(self) -> None: # Create temporary folder. with tempfile.TemporaryDirectory() as tmpdirname: - self.tmp_folder_name = tmpdirname + self.tmp_folder_name = tmpdirname # pylint: disable=attribute-defined-outside-init self.create_config_group_schema_files() self.write_nsd_manifest() @@ -195,7 +196,7 @@ def write_schema(self, folder_path: str) -> None: schema_path = os.path.join(folder_path, f"{self.config.cg_schema_name}.json") - with open(schema_path, "w") as _file: + with open(schema_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(self.config_group_schema_dict, indent=4)) logger.debug("%s created", schema_path) @@ -216,7 +217,7 @@ def write_config_mappings(self, folder_path: str) -> None: config_mappings_path = os.path.join(folder_path, NSD_CONFIG_MAPPING_FILENAME) - with open(config_mappings_path, "w") as _file: + with open(config_mappings_path, "w", encoding="utf-8") as _file: _file.write(json.dumps(config_mappings, indent=4)) logger.debug("%s created", config_mappings_path) @@ -248,6 +249,7 @@ def write_nf_bicep(self) -> None: bicep_params += f"param {key} {bicep_type}\n" bicep_deploymentValues += f"{key}: {key}\n " + # pylint: disable=no-member self.generate_bicep( self.nf_bicep_template_name, NF_DEFINITION_BICEP_FILENAME, @@ -274,7 +276,7 @@ def write_nf_bicep(self) -> None: if self.config.network_function_type == VNF else NFVIType.AZURE_ARC_KUBERNETES.value # type: ignore[attr-defined] ), - "CNF": True if self.config.network_function_type == CNF else False, + "CNF": self.config.network_function_type == CNF, }, ) @@ -318,7 +320,7 @@ def generate_bicep( bicep_template_path = os.path.join(code_dir, TEMPLATES_DIR_NAME, template_name) - with open(bicep_template_path, "r") as file: + with open(bicep_template_path, "r", encoding="utf-8") as file: bicep_contents = file.read() bicep_template = Template(bicep_contents) @@ -328,7 +330,7 @@ def generate_bicep( bicep_file_build_path = os.path.join(self.tmp_folder_name, output_file_name) - with open(bicep_file_build_path, "w") as file: + with open(bicep_file_build_path, "w", encoding="utf-8") as file: file.write(rendered_template) def copy_to_output_folder(self) -> None: From 859a12ff1bee4be657119c02441401f08879c8ac Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 5 Jul 2023 15:55:12 +0100 Subject: [PATCH 142/145] lint --- src/aosm/azext_aosm/_configuration.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 0c3dd7acd97..a74e8bcbff7 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -8,7 +8,6 @@ from typing import Any, Dict, List, Optional from azure.cli.core.azclierror import InvalidArgumentValueError, ValidationError - from azext_aosm.util.constants import ( CNF, NF_DEFINITION_OUTPUT_BICEP_PREFIX, @@ -19,7 +18,6 @@ SOURCE_ACR_REGEX, ) - logger = logging.getLogger(__name__) DESCRIPTION_MAP: Dict[str, str] = { From d668aba91f93f700cb97a9dabf1b843a389e7579 Mon Sep 17 00:00:00 2001 From: Jamie Parsons Date: Wed, 5 Jul 2023 15:55:54 +0100 Subject: [PATCH 143/145] mypy cnf_nfd_generator --- src/aosm/azext_aosm/_configuration.py | 5 +- .../generate_nfd/cnf_nfd_generator.py | 256 +++++++++++------- 2 files changed, 167 insertions(+), 94 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 2fa1442e0b9..b9bced2bf7a 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -5,7 +5,7 @@ import re from dataclasses import dataclass, field from pathlib import Path -from typing import Any, Dict, List, Optional, Union +from typing import Any, Dict, List, Optional from azure.cli.core.azclierror import InvalidArgumentValueError, ValidationError @@ -154,8 +154,7 @@ def path_from_cli_dir(self, path: str) -> str: return updated_path - @abc.abstractmethod - @property + @abc.abstractproperty def output_directory_for_build(self) -> Path: """Base class method to ensure subclasses implement this function.""" diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index 748cb14eccf..f55e2c58eda 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -8,6 +8,7 @@ import shutil import tarfile import tempfile +from dataclasses import dataclass from pathlib import Path from typing import Any, Dict, Iterator, List, Optional, Tuple @@ -40,6 +41,34 @@ logger = get_logger(__name__) +@dataclass +class Artifact: + """ + Information about an artifact. + """ + + name: str + version: str + + +@dataclass +class NFApplicationConfiguration: + name: str + chartName: str + chartVersion: str + dependsOnProfile: List[str] + registryValuesPaths: List[str] + imagePullSecretsValuesPaths: List[str] + valueMappingsPath: Path + + +@dataclass +class ImageInfo: + parameter: List[str] + name: str + version: str + + class CnfNfdGenerator(NFDGenerator): # pylint: disable=too-many-instance-attributes """ CNF NFD Generator. @@ -76,9 +105,9 @@ def __init__(self, config: CNFConfiguration, interactive: bool = False): ) self._tmp_dir: Optional[Path] = None - self.artifacts = [] - self.nf_application_configurations = [] - self.deployment_parameter_schema = SCHEMA_PREFIX + self.artifacts: List[Artifact] = [] + self.nf_application_configurations: List[NFApplicationConfiguration] = [] + self.deployment_parameter_schema: Dict[str, Any] = SCHEMA_PREFIX self.interactive = interactive def generate_nfd(self) -> None: @@ -107,13 +136,14 @@ def generate_nfd(self) -> None: # Get all image line matches for files in the chart. # Do this here so we don't have to do it multiple times. - image_line_matches = self._find_pattern_matches_in_chart( - helm_package, IMAGE_START_STRING + image_line_matches = self._find_image_parameter_from_chart( + helm_package ) + # Creates a flattened list of image registry paths to prevent set error - image_registry_paths = [] - for registry_path in image_line_matches: - image_registry_paths += registry_path[0] + image_registry_paths: List[str] = [] + for image_info in image_line_matches: + image_registry_paths += image_info.parameter # Generate the NF application configuration for the chart # passed to jinja2 renderer to render bicep template @@ -121,8 +151,8 @@ def generate_nfd(self) -> None: self._generate_nf_application_config( helm_package, image_registry_paths, - self._find_pattern_matches_in_chart( - helm_package, IMAGE_PULL_SECRETS_START_STRING + self._find_image_pull_secrets_parameter_from_chart( + helm_package ), ) ) @@ -163,6 +193,7 @@ def _extract_chart(self, path: Path) -> None: :param path: The path to helm package """ + assert self._tmp_dir logger.debug("Extracting helm package %s", path) @@ -188,6 +219,7 @@ def _generate_chart_value_mappings(self, helm_package: HelmPackageConfig) -> Non Expected use when a helm chart is very simple and user wants every value to be a deployment parameter. """ + assert self._tmp_dir logger.debug( "Creating chart value mappings file for %s", helm_package.path_to_chart ) @@ -210,7 +242,7 @@ def _generate_chart_value_mappings(self, helm_package: HelmPackageConfig) -> Non yaml.dump(mapping_to_write, mapping_file) # Update the config that points to the mapping file - helm_package.path_to_mappings = mapping_filepath + helm_package.path_to_mappings = str(mapping_filepath) def _read_top_level_values_yaml( self, helm_package: HelmPackageConfig @@ -224,6 +256,7 @@ def _read_top_level_values_yaml( :return: A dictionary of the yaml read from the file :rtype: Dict[str, Any] """ + assert self._tmp_dir for file in Path(self._tmp_dir / helm_package.name).iterdir(): if file.name in ("values.yaml", "values.yml"): with file.open(encoding="UTF-8") as values_file: @@ -236,6 +269,8 @@ def _read_top_level_values_yaml( def _write_manifest_bicep_file(self) -> None: """Write the bicep file for the Artifact Manifest to the temp directory.""" + assert self._tmp_dir + with open(self.manifest_jinja2_template_path, "r", encoding="UTF-8") as f: template: Template = Template( f.read(), @@ -254,6 +289,7 @@ def _write_manifest_bicep_file(self) -> None: def _write_nfd_bicep_file(self) -> None: """Write the bicep file for the NFD to the temp directory.""" + assert self._tmp_dir with open(self.nfd_jinja2_template_path, "r", encoding="UTF-8") as f: template: Template = Template( f.read(), @@ -273,8 +309,8 @@ def _write_nfd_bicep_file(self) -> None: def _write_schema_to_file(self) -> None: """Write the schema to file deploymentParameters.json to the temp directory.""" - logger.debug("Create deploymentParameters.json") + assert self._tmp_dir full_schema = self._tmp_dir / DEPLOYMENT_PARAMETERS_FILENAME with open(full_schema, "w", encoding="UTF-8") as f: @@ -284,6 +320,7 @@ def _write_schema_to_file(self) -> None: def _copy_to_output_directory(self) -> None: """Copy the config mappings, schema and bicep templates (artifact manifest and NFDV) from the temp directory to the output directory.""" + assert self._tmp_dir logger.info("Create NFD bicep %s", self.output_directory) @@ -327,26 +364,26 @@ def _generate_nf_application_config( self, helm_package: HelmPackageConfig, image_registry_path: List[str], - image_pull_secret_line_matches: List[Tuple[str, ...]], - ) -> Dict[str, Any]: + image_pull_secret_line_matches: List[str], + ) -> NFApplicationConfiguration: """Generate NF application config.""" (name, version) = self._get_chart_name_and_version(helm_package) registry_values_paths = set(image_registry_path) image_pull_secrets_values_paths = set(image_pull_secret_line_matches) - return { - "name": helm_package.name, - "chartName": name, - "chartVersion": version, - "dependsOnProfile": helm_package.depends_on, - "registryValuesPaths": list(registry_values_paths), - "imagePullSecretsValuesPaths": list(image_pull_secrets_values_paths), - "valueMappingsPath": self._jsonify_value_mappings(helm_package), - } + return NFApplicationConfiguration( + name=helm_package.name, + chartName=name, + chartVersion=version, + dependsOnProfile=helm_package.depends_on, + registryValuesPaths=list(registry_values_paths), + imagePullSecretsValuesPaths=list(image_pull_secrets_values_paths), + valueMappingsPath=self._jsonify_value_mappings(helm_package), + ) @staticmethod - def _find_yaml_files(directory: Path) -> Iterator[str]: + def _find_yaml_files(directory: Path) -> Iterator[Path]: """ Find all yaml files recursively in given directory. @@ -355,67 +392,90 @@ def _find_yaml_files(directory: Path) -> Iterator[str]: yield from directory.glob("**/*.yaml") yield from directory.glob("**/*.yml") - def _find_pattern_matches_in_chart( - self, helm_package: HelmPackageConfig, start_string: str - ) -> List[Tuple[str, ...]]: + def _find_image_parameter_from_chart( + self, helm_package_config: HelmPackageConfig + ) -> List[ImageInfo]: """ - Find pattern matches in Helm chart, using provided REGEX pattern. + Find pattern matches in Helm chart for the names of the image parameters. :param helm_package: The helm package config. - :param start_string: The string to search for, either imagePullSecrets: or image: - If searching for imagePullSecrets, returns list of lists containing image pull - secrets paths, e.g. Values.foo.bar.imagePullSecret - - If searching for image, returns list of tuples containing the list of image + Returns list of tuples containing the list of image paths and the name and version of the image. e.g. (Values.foo.bar.repoPath, foo, 1.2.3) """ - chart_dir = self._tmp_dir / helm_package.name + assert self._tmp_dir + chart_dir = self._tmp_dir / helm_package_config.name matches = [] path = [] for file in self._find_yaml_files(chart_dir): with open(file, "r", encoding="UTF-8") as f: - logger.debug("Searching for %s in %s", start_string, file) + logger.debug("Searching for %s in %s", IMAGE_START_STRING, file) for line in f: - if start_string in line: - logger.debug("Found %s in %s", start_string, line) + if IMAGE_START_STRING in line: + logger.debug("Found %s in %s", IMAGE_START_STRING, line) path = re.findall(IMAGE_PATH_REGEX, line) + # If "image:", search for chart name and version - if start_string == IMAGE_START_STRING: - name_and_version = re.search( - IMAGE_NAME_AND_VERSION_REGEX, line - ) + name_and_version = re.search(IMAGE_NAME_AND_VERSION_REGEX, line) + logger.debug( + "Regex match for name and version is %s", + name_and_version, + ) + + if name_and_version and len(name_and_version.groups()) == 2: logger.debug( - "Regex match for name and version is %s", - name_and_version, + "Found image name and version %s %s", + name_and_version.group("name"), + name_and_version.group("version"), ) - - if name_and_version and len(name_and_version.groups()) == 2: - logger.debug( - "Found image name and version %s %s", + matches.append( + ImageInfo( + path, name_and_version.group("name"), name_and_version.group("version"), ) - matches.append( - ( - path, - name_and_version.group("name"), - name_and_version.group("version"), - ) - ) - else: - logger.debug("No image name and version found") + ) else: - matches += path + logger.debug("No image name and version found") + return matches + + def _find_image_pull_secrets_parameter_from_chart( + self, helm_package_config: HelmPackageConfig + ) -> List[str]: + """ + Find pattern matches in Helm chart for the ImagePullSecrets parameter. + + :param helm_package: The helm package config. + + Returns list of lists containing image pull + secrets paths, e.g. Values.foo.bar.imagePullSecret + """ + assert self._tmp_dir + chart_dir = self._tmp_dir / helm_package_config.name + matches = [] + path = [] + + for file in self._find_yaml_files(chart_dir): + with open(file, "r", encoding="UTF-8") as f: + logger.debug( + "Searching for %s in %s", IMAGE_PULL_SECRETS_START_STRING, file + ) + for line in f: + if IMAGE_PULL_SECRETS_START_STRING in line: + logger.debug( + "Found %s in %s", IMAGE_PULL_SECRETS_START_STRING, line + ) + path = re.findall(IMAGE_PATH_REGEX, line) + matches += path return matches def _get_artifact_list( self, helm_package: HelmPackageConfig, - image_line_matches: List[Tuple[str, ...]], - ) -> List[Any]: + image_line_matches: List[ImageInfo], + ) -> List[Artifact]: """ Get the list of artifacts for the chart. @@ -423,19 +483,12 @@ def _get_artifact_list( :param image_line_matches: The list of image line matches. """ artifact_list = [] - (chart_name, chart_version) = self._get_chart_name_and_version(helm_package) - helm_artifact = { - "name": chart_name, - "version": chart_version, - } + (name, version) = self._get_chart_name_and_version(helm_package) + helm_artifact = Artifact(name, version) + artifact_list.append(helm_artifact) - for match in image_line_matches: - artifact_list.append( - { - "name": match[1], - "version": match[2], - } - ) + for image_info in image_line_matches: + artifact_list.append(Artifact(image_info.name, image_info.version)) return artifact_list @@ -448,7 +501,7 @@ def _get_chart_mapping_schema( param helm_package: The helm package config. """ - + assert self._tmp_dir logger.debug("Get chart mapping schema for %s", helm_package.name) mappings_path = helm_package.path_to_mappings @@ -499,34 +552,53 @@ def traverse_dict( :param d: The dictionary to traverse. :param target: The regex to search for. """ + @dataclass + class DictNode: + # The dictionary under this node + sub_dict: Dict[Any, Any] + + # The path to this node under the main dictionary + position_path: List[str] + # Initialize the stack with the dictionary and an empty path - stack = [(dict_to_search, [])] + stack: List[DictNode] = [DictNode(dict_to_search, [])] result = {} # Initialize empty dictionary to store the results while stack: # While there are still items in the stack # Pop the last item from the stack and unpack it into node (the dictionary) and path - (node, path) = stack.pop() + node = stack.pop() + # For each key-value pair in the popped item - for k, v in node.items(): + for key, value in node.sub_dict.items(): + # If the value is a dictionary - if isinstance(v, dict): + if isinstance(value, dict): # Add the dictionary to the stack with the path - stack.append((v, path + [k])) + stack.append(DictNode(value, node.position_path + [key])) + # If the value is a string + matches target regex - elif isinstance(v, str) and re.search(target_regex, v): + elif isinstance(value, str): # Take the match i.e, foo from {deployParameter.foo} - match = re.search(target_regex, v) + match = re.search(target_regex, value) + # Add it to the result dictionary with its path as the value - result[match.group(1)] = path + [k] - elif isinstance(v, list): - logger.debug("Found a list %s", v) - for i in v: - logger.debug("Found an item %s", i) - if isinstance(i, str) and re.search(target_regex, i): - match = re.search(target_regex, i) - result[match.group(1)] = path + [k] - elif isinstance(i, dict): - stack.append((i, path + [k])) - elif isinstance(i, list): + if match: + result[match.group(1)] = node.position_path + [key] + + elif isinstance(value, list): + logger.debug("Found a list %s", value) + for item in value: + logger.debug("Found an item %s", item) + + if isinstance(item, str): + match = re.search(target_regex, item) + + if match: + result[match.group(1)] = node.position_path + [key] + + elif isinstance(item, dict): + stack.append(DictNode(item, node.position_path + [key])) + + elif isinstance(item, list): # We should fix this but for now just log a warning and # carry on logger.warning( @@ -534,7 +606,7 @@ def traverse_dict( "at path %s, which this tool cannot parse. " "Please check the output configMappings and schemas " "files and check that they are as required.", - path + [k], + node.position_path + [key], ) return result @@ -669,6 +741,7 @@ def _get_chart_name_and_version( self, helm_package: HelmPackageConfig ) -> Tuple[str, str]: """Get the name and version of the chart.""" + assert self._tmp_dir chart_path = self._tmp_dir / helm_package.name / "Chart.yaml" if not chart_path.exists(): @@ -693,6 +766,7 @@ def _get_chart_name_and_version( def _jsonify_value_mappings(self, helm_package: HelmPackageConfig) -> Path: """Yaml->JSON values mapping file, then return path to it.""" + assert self._tmp_dir mappings_yaml_file = helm_package.path_to_mappings mappings_dir = self._tmp_dir / CONFIG_MAPPINGS_DIR_NAME mappings_output_file = mappings_dir / f"{helm_package.name}-mappings.json" From 0aabecac71950f29dd50fb1d8452ee340b487e62 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 5 Jul 2023 15:56:28 +0100 Subject: [PATCH 144/145] copyright --- src/aosm/azext_aosm/_configuration.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index a74e8bcbff7..221e972423b 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -1,3 +1,8 @@ +# -------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT +# License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------- +"""Configuration class for input config file parsing,""" import abc import logging import json From d2ef121d9d5c7c29bf9e6fb4fc8e31bcbaa02e67 Mon Sep 17 00:00:00 2001 From: Sunny Carter Date: Wed, 5 Jul 2023 16:06:23 +0100 Subject: [PATCH 145/145] more lint --- src/aosm/azext_aosm/_configuration.py | 2 +- src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py | 10 ++++++++-- src/aosm/setup.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/aosm/azext_aosm/_configuration.py b/src/aosm/azext_aosm/_configuration.py index 4d632f5cd80..221e972423b 100644 --- a/src/aosm/azext_aosm/_configuration.py +++ b/src/aosm/azext_aosm/_configuration.py @@ -163,7 +163,7 @@ def path_from_cli_dir(self, path: str) -> str: return updated_path - @abc.abstractproperty + @property def output_directory_for_build(self) -> Path: """Base class method to ensure subclasses implement this function.""" raise NotImplementedError("Subclass must define property") diff --git a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py index f55e2c58eda..dbf2bc7a314 100644 --- a/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py +++ b/src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py @@ -319,7 +319,12 @@ def _write_schema_to_file(self) -> None: logger.debug("%s created", full_schema) def _copy_to_output_directory(self) -> None: - """Copy the config mappings, schema and bicep templates (artifact manifest and NFDV) from the temp directory to the output directory.""" + """ + Copy files from the temp directory to the output directory. + + Files are the config mappings, schema and bicep templates (artifact manifest + and NFDV). + """ assert self._tmp_dir logger.info("Create NFD bicep %s", self.output_directory) @@ -552,6 +557,7 @@ def traverse_dict( :param d: The dictionary to traverse. :param target: The regex to search for. """ + # pylint: disable=too-many-nested-blocks @dataclass class DictNode: # The dictionary under this node @@ -591,7 +597,7 @@ class DictNode: if isinstance(item, str): match = re.search(target_regex, item) - + if match: result[match.group(1)] = node.position_path + [key] diff --git a/src/aosm/setup.py b/src/aosm/setup.py index 807c81eb801..c3af671b370 100644 --- a/src/aosm/setup.py +++ b/src/aosm/setup.py @@ -34,7 +34,7 @@ ] # TODO: Add any additional SDK dependencies here -DEPENDENCIES = ["oras~=0.1.17", "azure-storage-blob>=12.15.0", "jinja2>=3.1.2"] +DEPENDENCIES = ["oras~=0.1.18", "azure-storage-blob>=12.15.0", "jinja2>=3.1.2"] with open("README.md", "r", encoding="utf-8") as f: README = f.read()