From 2b6e17ccb90d53d6ba81c543519dc505be583b3c Mon Sep 17 00:00:00 2001 From: Jacob <53872686+jddarby@users.noreply.github.com> Date: Thu, 14 Dec 2023 13:37:27 +0000 Subject: [PATCH] Merge arm-processor code into Jacob's branch (#127) * Initial ArmInputTemplate class * Outline ArmBuildProcessor hierarchy * Update VNF tests to keep built output for comparison * Initial ArmInputTemplate class * Outline ArmBuildProcessor hierarchy * Update VNF tests to keep built output for comparison * WIP, for sharing with Jacob * Incremental update * Approximately complete ARM processor. No tests, no testing yet. * Fix artifact store reference --------- Co-authored-by: Andy Churchard --- .../build_processors/arm_processor.py | 136 ++++++++++++++++++ .../build_processors/base_processor.py | 2 +- .../azext_aosm/inputs/arm_template_input.py | 8 +- .../latest/mock_vnf/input_with_filepath.json | 18 +++ .../latest/mock_vnf/input_with_sas_token.json | 21 +++ .../tests/latest/test_arm_input_template.py | 12 ++ src/aosm/azext_aosm/tests/latest/test_vnf.py | 18 ++- .../configMappings/templateParameters.json | 8 ++ .../configMappings/vhdParameters.json | 3 + .../schemas/deploymentParameters.json | 22 +++ .../schemas/optionalDeploymentParameters.txt | 16 +++ .../vnfartifactmanifests.bicep | 68 +++++++++ .../vnfdefinition.bicep | 103 +++++++++++++ .../configMappings/templateParameters.json | 8 ++ .../configMappings/vhdParameters.json | 6 + .../schemas/deploymentParameters.json | 22 +++ .../schemas/optionalDeploymentParameters.txt | 16 +++ .../vnfartifactmanifests.bicep | 68 +++++++++ .../vnfdefinition.bicep | 103 +++++++++++++ 19 files changed, 646 insertions(+), 12 deletions(-) create mode 100644 src/aosm/azext_aosm/build_processors/arm_processor.py create mode 100644 src/aosm/azext_aosm/tests/latest/mock_vnf/input_with_filepath.json create mode 100644 src/aosm/azext_aosm/tests/latest/mock_vnf/input_with_sas_token.json create mode 100644 src/aosm/azext_aosm/tests/latest/test_arm_input_template.py create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/configMappings/templateParameters.json create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/configMappings/vhdParameters.json create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/schemas/deploymentParameters.json create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/schemas/optionalDeploymentParameters.txt create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/vnfartifactmanifests.bicep create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/vnfdefinition.bicep create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/configMappings/templateParameters.json create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/configMappings/vhdParameters.json create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/schemas/deploymentParameters.json create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/schemas/optionalDeploymentParameters.txt create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/vnfartifactmanifests.bicep create mode 100644 src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/vnfdefinition.bicep diff --git a/src/aosm/azext_aosm/build_processors/arm_processor.py b/src/aosm/azext_aosm/build_processors/arm_processor.py new file mode 100644 index 00000000000..d9635131087 --- /dev/null +++ b/src/aosm/azext_aosm/build_processors/arm_processor.py @@ -0,0 +1,136 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from abc import abstractmethod +from dataclasses import dataclass +from typing import Any, Dict, final, List, Tuple + +from azext_aosm.build_processors.base_processor import BaseBuildProcessor +from azext_aosm.common.artifact import LocalFileACRArtifact +from azext_aosm.common.local_file_builder import LocalFileBuilder +from azext_aosm.inputs.arm_template_input import ArmTemplateInput + +from ..vendored_sdks.models import ( + DependsOnProfile, + ResourceElementTemplate, + ReferencedResource, + ManifestArtifactFormat, + NetworkFunctionApplication, + ArmResourceDefinitionResourceElementTemplateDetails, + AzureCoreNetworkFunctionArmTemplateApplication, + AzureCoreArtifactType, + AzureCoreArmTemplateArtifactProfile, + ArmTemplateArtifactProfile, +) + + +@dataclass +class BaseArmBuildProcessor(BaseBuildProcessor): + """ + Base class for ARM template processors. + + This class loosely implements the Template Method pattern to define the steps required + to generate NF applications and RETs from a given ARM template. + + The steps are as follows: + - generate_schema + - generate_mappings + - generate_artifact_profile + - generate_nfvi_specific_nf_application + + """ + + name: str + input_artifact: ArmTemplateInput + + def get_artifact_manifest_list(self) -> List[ManifestArtifactFormat]: + """Get the artifact list.""" + return [ + ManifestArtifactFormat( + artifact_name=self.input_artifact.artifact_name, + artifact_type=AzureCoreArtifactType.ARM_TEMPLATE, + artifact_version=self.input_artifact.artifact_version, + ) + ] + + @abstractmethod + def get_artifact_details(self) -> Tuple[List[LocalFileACRArtifact], List[LocalFileBuilder]]: + """Get the artifact details.""" + return ( + [ + LocalFileACRArtifact( + artifact_manifest=ManifestArtifactFormat( + artifact_name=self.input_artifact.artifact_name, + artifact_type=AzureCoreArtifactType.ARM_TEMPLATE, + artifact_version=self.input_artifact.artifact_version, + ), + file_path=self.input_artifact.artifact_path, + ) + ], + [], + ) + + @final + def generate_nf_application(self) -> NetworkFunctionApplication: + return self.generate_nfvi_specific_nf_application() + + # TODO: Should this actually be a cached property? + def generate_schema(self) -> Dict[str, Any]: + return self.input_artifact.get_schema() + + def generate_mappings(self) -> Dict[str, str]: + template_parameters = {} + vm_parameters = self.generate_schema() + + # TODO: Document that this no longer appends "Image" to the image name supplied by user in input.jsonc + # TODO: Document that the parameters are no longer ordered, and create story to reimplement ordering + for key in vm_parameters: + template_parameters[key] = f"{{deployParameters.{key}}}" + + return template_parameters + + # @abstractmethod? + def generate_artifact_profile(self) -> AzureCoreArmTemplateArtifactProfile: + artifact_profile = ArmTemplateArtifactProfile( + template_name=self.input_artifact.artifact_name, + template_version=self.input_artifact.artifact_version, + ) + return AzureCoreArmTemplateArtifactProfile( + artifact_store=ReferencedResource(id=""), + template_artifact_profile=artifact_profile, + ) + + @abstractmethod + def generate_nfvi_specific_nf_application(self): + pass + + def generate_resource_element_template(self) -> ResourceElementTemplate: + return ArmResourceDefinitionResourceElementTemplateDetails() + + +class AzureCoreArmBuildProcessor(BaseArmBuildProcessor): + """ + This class represents an ARM template processor for Azure Core. + """ + + def generate_nfvi_specific_nf_application( + self, + ) -> AzureCoreNetworkFunctionArmTemplateApplication: + return AzureCoreNetworkFunctionArmTemplateApplication( + name=self.name, + depends_on_profile=DependsOnProfile(), + artifact_type=AzureCoreArtifactType.ARM_TEMPLATE, + artifact_profile=self.generate_artifact_profile(), + deploy_parameters_mapping_rule_profile=self.generate_mappings(), + ) + + +class NexusArmBuildProcessor(BaseArmBuildProcessor): + """ + Not implemented yet. This class represents a processor for generating ARM templates specific to Nexus. + """ + + def generate_nfvi_specific_nf_application(self): + return NotImplementedError diff --git a/src/aosm/azext_aosm/build_processors/base_processor.py b/src/aosm/azext_aosm/build_processors/base_processor.py index 0455c6eb8dc..b048df5d5fa 100644 --- a/src/aosm/azext_aosm/build_processors/base_processor.py +++ b/src/aosm/azext_aosm/build_processors/base_processor.py @@ -4,8 +4,8 @@ # -------------------------------------------------------------------------------------------- from abc import ABC, abstractmethod -from typing import List, Tuple from dataclasses import dataclass +from typing import List, Tuple from azext_aosm.inputs.base_input import BaseInput from azext_aosm.common.artifact import BaseArtifact from azext_aosm.common.local_file_builder import LocalFileBuilder diff --git a/src/aosm/azext_aosm/inputs/arm_template_input.py b/src/aosm/azext_aosm/inputs/arm_template_input.py index 0e646ca5aca..e770ae2aa20 100644 --- a/src/aosm/azext_aosm/inputs/arm_template_input.py +++ b/src/aosm/azext_aosm/inputs/arm_template_input.py @@ -1,21 +1,21 @@ from dataclasses import dataclass -from pathlib import Path import json +from pathlib import Path from typing import Any, Dict from azext_aosm.inputs.base_input import BaseInput + @dataclass class ArmTemplateInput(BaseInput): template_path: Path def get_defaults(self): - # TODO: Implement this - pass + return self.default_config def get_schema(self) -> Dict[str, Any]: # For ARM templates, the schema is defined by the parameters section - with open(self.template_path, "r", encoding="utf-8") as _file: + with open(self.artifact_path, "r", encoding="utf-8") as _file: data = json.load(_file) if "parameters" in data: parameters: Dict[str, Any] = data["parameters"] diff --git a/src/aosm/azext_aosm/tests/latest/mock_vnf/input_with_filepath.json b/src/aosm/azext_aosm/tests/latest/mock_vnf/input_with_filepath.json new file mode 100644 index 00000000000..b3a3b991a1d --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_vnf/input_with_filepath.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/input_with_sas_token.json b/src/aosm/azext_aosm/tests/latest/mock_vnf/input_with_sas_token.json new file mode 100644 index 00000000000..5222d940186 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/mock_vnf/input_with_sas_token.json @@ -0,0 +1,21 @@ +{ + "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": { + "blob_sas_url": "https://a/dummy/sas-url", + "version": "1-0-0", + "image_disk_size_GB": 30, + "image_hyper_v_generation": "V1", + "image_api_version": "2023-03-01" + } +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/test_arm_input_template.py b/src/aosm/azext_aosm/tests/latest/test_arm_input_template.py new file mode 100644 index 00000000000..320afaa5273 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/test_arm_input_template.py @@ -0,0 +1,12 @@ +from pathlib import Path +import unittest + +from azext_aosm.template_parsers.arm_parser import ArmParser + + +class ArmParserTest(unittest.TestCase): + here = Path(__file__).parent + arm_parser = ArmParser(here / "mock_vnf/ubuntu-template.json") + + assert arm_parser.get_defaults() == None + assert arm_parser.get_schema() == {'location': {'type': 'string', 'defaultValue': '[resourceGroup().location]'}, 'subnetName': {'type': 'string'}, 'ubuntuVmName': {'type': 'string', 'defaultValue': 'ubuntu-vm'}, 'virtualNetworkId': {'type': 'string'}, 'sshPublicKeyAdmin': {'type': 'string'}, 'imageName': {'type': 'string'}} diff --git a/src/aosm/azext_aosm/tests/latest/test_vnf.py b/src/aosm/azext_aosm/tests/latest/test_vnf.py index d6d178f56d0..57855514dcb 100644 --- a/src/aosm/azext_aosm/tests/latest/test_vnf.py +++ b/src/aosm/azext_aosm/tests/latest/test_vnf.py @@ -12,6 +12,7 @@ from azext_aosm.custom import build_definition, generate_definition_config mock_vnf_folder = ((Path(__file__).parent) / "mock_vnf").resolve() +vnf_output_directory = ((Path(__file__).parent) / "vnf_output").resolve() INPUT_WITH_SAS_VHD_PARAMS = { "imageName": "ubuntu-vmImage", @@ -42,26 +43,29 @@ def test_generate_config(self): finally: os.chdir(starting_directory) - def test_build(self): - """Test building an NFDV for a VNF.""" + def test_build_with_filepath(self): + """Test building an NFDV for a VNF using a filepath.""" starting_directory = os.getcwd() with TemporaryDirectory() as test_dir: - os.chdir(test_dir) + os.chdir(vnf_output_directory / "ubuntu_with_filepath") try: build_definition( - "vnf", str(mock_vnf_folder / "input_with_fp.json") + "vnf", str(mock_vnf_folder / "input_with_filepath.json") # TODO: add force to ensure we overwrite ) assert os.path.exists("nfd-bicep-ubuntu-template") finally: os.chdir(starting_directory) + def test_build_with_sas_token(self): + """Test building an NFDV for a VNF using a filepath.""" + starting_directory = os.getcwd() with TemporaryDirectory() as test_dir: - os.chdir(test_dir) + os.chdir(vnf_output_directory / "ubuntu_with_sas_token") try: build_definition( - "vnf", str(mock_vnf_folder / "input_with_sas.json") + "vnf", str(mock_vnf_folder / "input_with_sas_token.json") ) assert os.path.exists("nfd-bicep-ubuntu-template") print(os.listdir("nfd-bicep-ubuntu-template")) @@ -81,7 +85,7 @@ def test_build_with_ordered_params(self): try: build_definition( "vnf", - str(mock_vnf_folder / "input_with_fp.json"), + str(mock_vnf_folder / "input_with_filepath.json"), order_params=True, ) assert os.path.exists("nfd-bicep-ubuntu-template") diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/configMappings/templateParameters.json b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/configMappings/templateParameters.json new file mode 100644 index 00000000000..35398722d4a --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/configMappings/templateParameters.json @@ -0,0 +1,8 @@ +{ + "location": "{deployParameters.location}", + "subnetName": "{deployParameters.subnetName}", + "ubuntuVmName": "{deployParameters.ubuntuVmName}", + "virtualNetworkId": "{deployParameters.virtualNetworkId}", + "sshPublicKeyAdmin": "{deployParameters.sshPublicKeyAdmin}", + "imageName": "ubuntu-vmImage" +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/configMappings/vhdParameters.json b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/configMappings/vhdParameters.json new file mode 100644 index 00000000000..27c48c5e970 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/configMappings/vhdParameters.json @@ -0,0 +1,3 @@ +{ + "imageName": "ubuntu-vmImage" +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/schemas/deploymentParameters.json b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/schemas/deploymentParameters.json new file mode 100644 index 00000000000..0a9a1aecaf6 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/schemas/deploymentParameters.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft-07/schema#", + "title": "DeployParametersSchema", + "type": "object", + "properties": { + "location": { + "type": "string" + }, + "subnetName": { + "type": "string" + }, + "ubuntuVmName": { + "type": "string" + }, + "virtualNetworkId": { + "type": "string" + }, + "sshPublicKeyAdmin": { + "type": "string" + } + } +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/schemas/optionalDeploymentParameters.txt b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/schemas/optionalDeploymentParameters.txt new file mode 100644 index 00000000000..f3b7a1f23ad --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/schemas/optionalDeploymentParameters.txt @@ -0,0 +1,16 @@ +# The following parameters are optional as they have default values. +# If you do not wish to expose them in the NFD, find and remove them from both +# deploymentParameters.json and templateParameters.json (and vhdParameters.json if +they are there) +# You can re-run the build command with the --order-params flag to order those +# files with the optional parameters at the end of the file, and with the +# --interactive flag to interactively choose y/n for each parameter to expose. + +{ + "location": { + "type": "string" + }, + "ubuntuVmName": { + "type": "string" + } +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/vnfartifactmanifests.bicep b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/vnfartifactmanifests.bicep new file mode 100644 index 00000000000..109cca9c766 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/vnfartifactmanifests.bicep @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an NF definition for a VNF +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 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('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 armTemplateVersion string + +// Created by the az aosm definition publish command before the template is deployed +resource publisher 'Microsoft.HybridNetwork/publishers@2023-09-01' existing = { + name: publisherName + scope: resourceGroup() +} + +// Created by the az aosm definition publish command before the template is deployed +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-09-01' 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-09-01' existing = { + parent: publisher + name: saArtifactStoreName +} + +resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2023-09-01' = { + parent: saArtifactStore + name: saManifestName + location: location + properties: { + artifacts: [ + { + artifactName: '${nfName}-vhd' + artifactType: 'VhdImageFile' + artifactVersion: vhdVersion + } + ] + } +} + +resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2023-09-01' = { + parent: acrArtifactStore + name: acrManifestName + location: location + properties: { + artifacts: [ + { + artifactName: '${nfName}-arm-template' + artifactType: 'ArmTemplate' + artifactVersion: armTemplateVersion + } + ] + } +} diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/vnfdefinition.bicep b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/vnfdefinition.bicep new file mode 100644 index 00000000000..9deaeffd182 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_filepath/nfd-bicep-ubuntu-template/vnfdefinition.bicep @@ -0,0 +1,103 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an NF definition for a VNF +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 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@2023-09-01' existing = { + name: publisherName + scope: resourceGroup() +} + +// Created by the az aosm definition publish command before the template is deployed +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-09-01' 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-09-01' 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-09-01' existing = { + parent: publisher + name: nfDefinitionGroup +} + +resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups/networkfunctiondefinitionversions@2023-09-01' = { + 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/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/configMappings/templateParameters.json b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/configMappings/templateParameters.json new file mode 100644 index 00000000000..35398722d4a --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/configMappings/templateParameters.json @@ -0,0 +1,8 @@ +{ + "location": "{deployParameters.location}", + "subnetName": "{deployParameters.subnetName}", + "ubuntuVmName": "{deployParameters.ubuntuVmName}", + "virtualNetworkId": "{deployParameters.virtualNetworkId}", + "sshPublicKeyAdmin": "{deployParameters.sshPublicKeyAdmin}", + "imageName": "ubuntu-vmImage" +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/configMappings/vhdParameters.json b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/configMappings/vhdParameters.json new file mode 100644 index 00000000000..c633de114ad --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/configMappings/vhdParameters.json @@ -0,0 +1,6 @@ +{ + "imageName": "ubuntu-vmImage", + "imageDiskSizeGB": 30, + "imageHyperVGeneration": "V1", + "imageApiVersion": "2023-03-01" +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/schemas/deploymentParameters.json b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/schemas/deploymentParameters.json new file mode 100644 index 00000000000..0a9a1aecaf6 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/schemas/deploymentParameters.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft-07/schema#", + "title": "DeployParametersSchema", + "type": "object", + "properties": { + "location": { + "type": "string" + }, + "subnetName": { + "type": "string" + }, + "ubuntuVmName": { + "type": "string" + }, + "virtualNetworkId": { + "type": "string" + }, + "sshPublicKeyAdmin": { + "type": "string" + } + } +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/schemas/optionalDeploymentParameters.txt b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/schemas/optionalDeploymentParameters.txt new file mode 100644 index 00000000000..f3b7a1f23ad --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/schemas/optionalDeploymentParameters.txt @@ -0,0 +1,16 @@ +# The following parameters are optional as they have default values. +# If you do not wish to expose them in the NFD, find and remove them from both +# deploymentParameters.json and templateParameters.json (and vhdParameters.json if +they are there) +# You can re-run the build command with the --order-params flag to order those +# files with the optional parameters at the end of the file, and with the +# --interactive flag to interactively choose y/n for each parameter to expose. + +{ + "location": { + "type": "string" + }, + "ubuntuVmName": { + "type": "string" + } +} \ No newline at end of file diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/vnfartifactmanifests.bicep b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/vnfartifactmanifests.bicep new file mode 100644 index 00000000000..109cca9c766 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/vnfartifactmanifests.bicep @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an NF definition for a VNF +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 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('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 armTemplateVersion string + +// Created by the az aosm definition publish command before the template is deployed +resource publisher 'Microsoft.HybridNetwork/publishers@2023-09-01' existing = { + name: publisherName + scope: resourceGroup() +} + +// Created by the az aosm definition publish command before the template is deployed +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-09-01' 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-09-01' existing = { + parent: publisher + name: saArtifactStoreName +} + +resource saArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2023-09-01' = { + parent: saArtifactStore + name: saManifestName + location: location + properties: { + artifacts: [ + { + artifactName: '${nfName}-vhd' + artifactType: 'VhdImageFile' + artifactVersion: vhdVersion + } + ] + } +} + +resource acrArtifactManifest 'Microsoft.Hybridnetwork/publishers/artifactStores/artifactManifests@2023-09-01' = { + parent: acrArtifactStore + name: acrManifestName + location: location + properties: { + artifacts: [ + { + artifactName: '${nfName}-arm-template' + artifactType: 'ArmTemplate' + artifactVersion: armTemplateVersion + } + ] + } +} diff --git a/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/vnfdefinition.bicep b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/vnfdefinition.bicep new file mode 100644 index 00000000000..9deaeffd182 --- /dev/null +++ b/src/aosm/azext_aosm/tests/latest/vnf_output/ubuntu_with_sas_token/nfd-bicep-ubuntu-template/vnfdefinition.bicep @@ -0,0 +1,103 @@ +// Copyright (c) Microsoft Corporation. + +// This file creates an NF definition for a VNF +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 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@2023-09-01' existing = { + name: publisherName + scope: resourceGroup() +} + +// Created by the az aosm definition publish command before the template is deployed +resource acrArtifactStore 'Microsoft.HybridNetwork/publishers/artifactStores@2023-09-01' 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-09-01' 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-09-01' existing = { + parent: publisher + name: nfDefinitionGroup +} + +resource nfdv 'Microsoft.Hybridnetwork/publishers/networkfunctiondefinitiongroups/networkfunctiondefinitionversions@2023-09-01' = { + 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' + } + } + ] + } + } +}