Skip to content

Commit

Permalink
Merge pull request #85 from jddarby/JDP/fix_helptext_and_validation
Browse files Browse the repository at this point in the history
Fix up helptext and validation to be a bit saner
  • Loading branch information
jamiedparsons authored Sep 26, 2023
2 parents ceeeb2d + c699258 commit 84eff1f
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 279 deletions.
569 changes: 327 additions & 242 deletions src/aosm/azext_aosm/_configuration.py

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions src/aosm/azext_aosm/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ def generate_definition_config(definition_type: str, output_file: str = "input.j
:param definition_type: CNF, VNF
:param output_file: path to output config file, defaults to "input.json"
:type output_file: str, optional
"""
_generate_config(configuration_type=definition_type, output_file=output_file)
config: Configuration
if definition_type == CNF:
config = CNFConfiguration.helptext()
elif definition_type == VNF:
config = VNFConfiguration.helptext()

_generate_config(configuration=config, output_file=output_file)


def _get_config_from_file(config_file: str, configuration_type: str) -> Configuration:
Expand Down Expand Up @@ -324,21 +329,21 @@ def generate_design_config(output_file: str = "input.json"):
:param output_file: path to output config file, defaults to "input.json"
:type output_file: str, optional
"""
_generate_config(NSD, output_file)
_generate_config(NSConfiguration.helptext(), output_file)


def _generate_config(configuration_type: str, output_file: str = "input.json"):
def _generate_config(configuration: Configuration, output_file: str = "input.json"):
"""
Generic generate config function for NFDs and NSDs.
:param configuration_type: CNF, VNF or NSD
:param configuration: The Configuration object with helptext filled in for each of
the fields.
:param output_file: path to output config file, defaults to "input.json"
:type output_file: str, optional
"""
# 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 = asdict(configuration)
config.pop("config_file")

config_as_dict = json.dumps(config, indent=4)
Expand All @@ -353,10 +358,10 @@ 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):
prtName = "definition"
else:
if isinstance(configuration, NSConfiguration):
prtName = "design"
else:
prtName = "definition"
print(f"Empty {prtName} configuration has been written to {output_file}")
logger.info(
"Empty %s configuration has been written to %s", prtName, output_file
Expand Down
25 changes: 20 additions & 5 deletions src/aosm/azext_aosm/deploy/deploy_with_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
from knack.util import CLIError

from azext_aosm._configuration import (
ArtifactConfig,
CNFConfiguration,
Configuration,
NFConfiguration,
NFDRETConfiguration,
NSConfiguration,
VNFConfiguration,
)
Expand Down Expand Up @@ -179,14 +181,20 @@ def _vnfd_artifact_upload(self) -> None:
vhd_artifact = storage_account_manifest.artifacts[0]
arm_template_artifact = acr_manifest.artifacts[0]

vhd_config = self.config.vhd
arm_template_config = self.config.arm_template

assert isinstance(vhd_config, ArtifactConfig)
assert isinstance(arm_template_config, ArtifactConfig)

if self.skip == IMAGE_UPLOAD:
print("Skipping VHD artifact upload")
else:
print("Uploading VHD artifact")
vhd_artifact.upload(self.config.vhd)
vhd_artifact.upload(vhd_config)

print("Uploading ARM template artifact")
arm_template_artifact.upload(self.config.arm_template)
arm_template_artifact.upload(arm_template_config)

def _cnfd_artifact_upload(self) -> None:
"""Uploads the Helm chart and any additional images."""
Expand Down Expand Up @@ -302,6 +310,8 @@ def construct_parameters(self) -> Dict[str, Any]:
"""
if self.resource_type == VNF:
assert isinstance(self.config, VNFConfiguration)
assert isinstance(self.config.vhd, ArtifactConfig)
assert isinstance(self.config.arm_template, ArtifactConfig)
return {
"location": {"value": self.config.location},
"publisherName": {"value": self.config.publisher_name},
Expand Down Expand Up @@ -341,6 +351,8 @@ def construct_manifest_parameters(self) -> Dict[str, Any]:
"""Create the parmeters dictionary for VNF, CNF or NSD."""
if self.resource_type == VNF:
assert isinstance(self.config, VNFConfiguration)
assert isinstance(self.config.vhd, ArtifactConfig)
assert isinstance(self.config.arm_template, ArtifactConfig)
return {
"location": {"value": self.config.location},
"publisherName": {"value": self.config.publisher_name},
Expand All @@ -363,9 +375,11 @@ def construct_manifest_parameters(self) -> Dict[str, Any]:
if self.resource_type == NSD:
assert isinstance(self.config, NSConfiguration)

arm_template_names = [
nf.arm_template.artifact_name for nf in self.config.network_functions
]
arm_template_names = []

for nf in self.config.network_functions:
assert isinstance(nf, NFDRETConfiguration)
arm_template_names.append(nf.arm_template.artifact_name)

# Set the artifact version to be the same as the NSD version, so that they
# don't get over written when a new NSD is published.
Expand Down Expand Up @@ -417,6 +431,7 @@ def deploy_nsd_from_bicep(self) -> None:
for manifest, nf in zip(
self.config.acr_manifest_names, self.config.network_functions
):
assert isinstance(nf, NFDRETConfiguration)
acr_manifest = ArtifactManifestOperator(
self.config,
self.api_clients,
Expand Down
4 changes: 1 addition & 3 deletions src/aosm/azext_aosm/deploy/pre_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,7 @@ def ensure_nsd_exists(
network_service_design_group_name=nsd_name,
parameters=NetworkServiceDesignGroup(location=location),
)
LongRunningOperation(self.cli_ctx, "Creating Network Service Design...")(
poller
)
LongRunningOperation(self.cli_ctx, "Creating Network Service Design...")(poller)

def resource_exists_by_name(self, rg_name: str, resource_name: str) -> bool:
"""
Expand Down
2 changes: 2 additions & 0 deletions src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def generate_nfd(self) -> None:
try:
for helm_package in self.config.helm_packages:
# Unpack the chart into the tmp directory
assert isinstance(helm_package, HelmPackageConfig)

self._extract_chart(Path(helm_package.path_to_chart))

# TODO: Validate charts
Expand Down
5 changes: 4 additions & 1 deletion src/aosm/azext_aosm/generate_nfd/vnf_nfd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from knack.log import get_logger

from azext_aosm._configuration import VNFConfiguration
from azext_aosm._configuration import ArtifactConfig, VNFConfiguration
from azext_aosm.generate_nfd.nfd_generator_base import NFDGenerator
from azext_aosm.util.constants import (
CONFIG_MAPPINGS_DIR_NAME,
Expand Down Expand Up @@ -64,6 +64,9 @@ class VnfNfdGenerator(NFDGenerator):
def __init__(self, config: VNFConfiguration, order_params: bool, interactive: bool):
self.config = config

assert isinstance(self.config.arm_template, ArtifactConfig)
assert self.config.arm_template.file_path

self.arm_template_path = Path(self.config.arm_template.file_path)
self.output_directory: Path = self.config.output_directory_for_build

Expand Down
14 changes: 8 additions & 6 deletions src/aosm/azext_aosm/generate_nsd/nf_ret.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ def _get_nfdv(
"Reading existing NFDV resource object "
f"{config.version} from group {config.name}"
)
nfdv_object = api_clients.aosm_client.proxy_network_function_definition_versions.get(
publisher_scope_name=config.publisher_scope,
publisher_location_name=config.publisher_offering_location,
proxy_publisher_name=config.publisher,
network_function_definition_group_name=config.name,
network_function_definition_version_name=config.version,
nfdv_object = (
api_clients.aosm_client.proxy_network_function_definition_versions.get(
publisher_scope_name=config.publisher_scope,
publisher_location_name=config.publisher_offering_location,
proxy_publisher_name=config.publisher,
network_function_definition_group_name=config.name,
network_function_definition_version_name=config.version,
)
)
return nfdv_object

Expand Down
14 changes: 9 additions & 5 deletions src/aosm/azext_aosm/generate_nsd/nsd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from jinja2 import Template
from knack.log import get_logger

from azext_aosm._configuration import NSConfiguration
from azext_aosm._configuration import NFDRETConfiguration, NSConfiguration
from azext_aosm.generate_nsd.nf_ret import NFRETGenerator
from azext_aosm.util.constants import (
CONFIG_MAPPINGS_DIR_NAME,
Expand Down Expand Up @@ -56,10 +56,14 @@ def __init__(self, api_clients: ApiClients, config: NSConfiguration):
self.config = config
self.nsd_bicep_template_name = NSD_DEFINITION_JINJA2_SOURCE_TEMPLATE
self.nsd_bicep_output_name = NSD_BICEP_FILENAME
self.nf_ret_generators = [
NFRETGenerator(api_clients, nf_config, self.config.cg_schema_name)
for nf_config in self.config.network_functions
]

self.nf_ret_generators = []

for nf_config in self.config.network_functions:
assert isinstance(nf_config, NFDRETConfiguration)
self.nf_ret_generators.append(
NFRETGenerator(api_clients, nf_config, self.config.cg_schema_name)
)

def generate_nsd(self) -> None:
"""Generate a NSD templates which includes an Artifact Manifest, NFDV and NF templates."""
Expand Down
2 changes: 1 addition & 1 deletion src/aosm/azext_aosm/tests/latest/mock_nsd/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"publisher_scope": "private"
}
],
"nsdg_name": "ubuntu",
"nsd_name": "ubuntu",
"nsd_version": "1.0.0",
"nsdv_description": "Plain ubuntu VM"
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"version": "1.0.0",
"publisher_offering_location": "eastus",
"type": "cnf",
"multiple_instances": false
"multiple_instances": "False"
},
{
"publisher": "reference-publisher",
Expand All @@ -25,7 +25,7 @@
"multiple_instances": false
}
],
"nsdg_name": "multinf",
"nsd_name": "multinf",
"nsd_version": "1.0.1",
"nsdv_description": "Test deploying multiple NFs"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"version": "1.0.0",
"publisher_offering_location": "eastus",
"type": "vnf",
"multiple_instances": true,
"multiple_instances": "True",
"publisher_scope": "private",
"publisher": "jamie-mobile-publisher",
"publisher_resource_group": "Jamie-publisher"
}
],
"nsdg_name": "ubuntu",
"nsd_name": "ubuntu",
"nsd_version": "1.0.0",
"nsdv_description": "Plain ubuntu VM"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"publisher_resource_group": "{{publisher_resource_group_name}}"
}
],
"nsdg_name": "nginx",
"nsd_name": "nginx",
"nsd_version": "1.0.0",
"nsdv_description": "Deploys a basic NGINX CNF"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"publisher_resource_group": "{{publisher_resource_group_name}}"
}
],
"nsdg_name": "ubuntu",
"nsd_name": "ubuntu",
"nsd_version": "1.0.0",
"nsdv_description": "Plain ubuntu VM"
}

0 comments on commit 84eff1f

Please sign in to comment.