Skip to content

Commit

Permalink
Add CNFConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
jddarby committed May 5, 2023
1 parent 1b77c7e commit 0d15355
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
28 changes: 21 additions & 7 deletions src/aosm/azext_aosm/_configuration.py
Original file line number Diff line number Diff line change
@@ -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

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

Expand Down
2 changes: 1 addition & 1 deletion src/aosm/azext_aosm/deploy/deploy_with_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
Expand Down

0 comments on commit 0d15355

Please sign in to comment.