Skip to content

Commit

Permalink
sunny merge add-aosm-extension into patryk's branch (#25)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sunnycarter authored Jun 12, 2023
1 parent de34077 commit 1e29dcf
Show file tree
Hide file tree
Showing 19 changed files with 505 additions and 158 deletions.
4 changes: 4 additions & 0 deletions src/aosm/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 16 additions & 2 deletions src/aosm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`
`az aosm nsd delete --config-file input.json --clean`
1 change: 1 addition & 0 deletions src/aosm/azext_aosm/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
from azure.mgmt.containerregistry import ContainerRegistryManagementClient

Expand Down
53 changes: 35 additions & 18 deletions src/aosm/azext_aosm/_configuration.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
## 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.",
"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":
"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.",
Expand All @@ -44,10 +53,18 @@
"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",
"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",
"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":
"Names of the Helm packages this package depends on. "
"Leave as an empty array if no dependencies",
"source_registry_id": "Name of the source acr registry from which to pull the image",
}

Expand Down Expand Up @@ -106,7 +123,7 @@ 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")
Expand Down Expand Up @@ -191,7 +208,7 @@ def arm_template(self) -> ArtifactConfig:

@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"


Expand Down
1 change: 0 additions & 1 deletion src/aosm/azext_aosm/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from knack.help_files import helps # pylint: disable=unused-import


helps[
"aosm"
] = """
Expand Down
18 changes: 17 additions & 1 deletion src/aosm/azext_aosm/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, _):
Expand Down Expand Up @@ -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"],
Expand Down
43 changes: 30 additions & 13 deletions src/aosm/azext_aosm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@
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.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_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.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
from azext_aosm._client_factory import cf_resources, cf_acr_registries
from azext_aosm._configuration import (
get_configuration,
CNFConfiguration,
NFConfiguration,
NSConfiguration,
VNFConfiguration,
get_configuration,
)

logger = get_logger(__name__)
Expand All @@ -37,6 +40,8 @@
def build_definition(
definition_type: str,
config_file: str,
order_params: bool = False,
interactive: bool = False,
):
"""
Build a definition.
Expand All @@ -53,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"):
Expand Down Expand Up @@ -89,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."
Expand Down Expand Up @@ -226,6 +240,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
"""
Expand All @@ -235,6 +250,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
Expand All @@ -251,7 +267,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"
Expand All @@ -262,6 +278,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:
Expand Down Expand Up @@ -293,6 +310,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.
Expand All @@ -319,6 +337,7 @@ def publish_design(
):
"""
Publish a generated design.
:param cmd:
:param client:
:type client: HybridNetworkManagementClient
Expand Down Expand Up @@ -358,8 +377,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)

Expand Down
3 changes: 1 addition & 2 deletions src/aosm/azext_aosm/delete/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)


Expand Down
5 changes: 2 additions & 3 deletions src/aosm/azext_aosm/deploy/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

# pylint: disable=unidiomatic-typecheck
"""A module to handle interacting with artifacts."""
from typing import Union
from dataclasses import dataclass
from typing import Union
from knack.log import get_logger
from oras.client import OrasClient

from azure.storage.blob import BlobClient, BlobType
from azext_aosm._configuration import ArtifactConfig, HelmPackageConfig
from oras.client import OrasClient


logger = get_logger(__name__)

Expand Down
Loading

0 comments on commit 1e29dcf

Please sign in to comment.