Skip to content

Commit

Permalink
Default RG and ACR Values with Publisher Name (#103) (#104)
Browse files Browse the repository at this point in the history
* added default rg and acr values for nf + nsd; added blob_url default for vnf

* added bug fix to close Paulo's bug

* change error message back

---------

Co-authored-by: Jordan <jordan.layton@metaswitch.com>
  • Loading branch information
jordlay and Jordan authored Oct 4, 2023
1 parent 513adbd commit f48827b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 22 additions & 5 deletions src/aosm/azext_aosm/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ class Configuration(abc.ABC):
acr_artifact_store_name: str = ""
location: str = ""

def __post_init__(self):
"""
Set defaults for resource group and ACR as the publisher name tagged with -rg or -acr
"""
if self.publisher_name:
if not self.publisher_resource_group_name:
self.publisher_resource_group_name = f"{self.publisher_name}-rg"
if not self.acr_artifact_store_name:
self.acr_artifact_store_name = f"{self.publisher_name}-acr"

@classmethod
def helptext(cls):
"""
Expand All @@ -83,11 +93,12 @@ def helptext(cls):
"Will be created if it does not exist."
),
publisher_resource_group_name=(
"Resource group for the Publisher resource. "
"Will be created if it does not exist."
"Optional. Resource group for the Publisher resource. "
"Will be created if it does not exist (with a default name if none is supplied)."
),
acr_artifact_store_name=(
"Name of the ACR Artifact Store resource. Will be created if it does not exist."
"Optional. Name of the ACR Artifact Store resource. "
"Will be created if it does not exist (with a default name if none is supplied)."
),
location="Azure location to use when creating resources.",
)
Expand Down Expand Up @@ -203,8 +214,8 @@ def helptext(cls) -> "VNFConfiguration":
"""
return VNFConfiguration(
blob_artifact_store_name=(
"Name of the storage account Artifact Store resource. Will be created if it "
"does not exist."
"Optional. Name of the storage account Artifact Store resource. Will be created if it "
"does not exist (with a default name if none is supplied)."
),
image_name_parameter=(
"The parameter name in the VM ARM template which specifies the name of the "
Expand All @@ -221,6 +232,10 @@ def __post_init__(self):
Used when creating VNFConfiguration object from a loaded json config file.
"""
super().__post_init__()
if self.publisher_name and not self.blob_artifact_store_name:
self.blob_artifact_store_name = f"{self.publisher_name}-sa"

if isinstance(self.arm_template, dict):
self.arm_template["file_path"] = self.path_from_cli_dir(
self.arm_template["file_path"]
Expand Down Expand Up @@ -383,6 +398,7 @@ def __post_init__(self):
Used when creating CNFConfiguration object from a loaded json config file.
"""
super().__post_init__()
for package_index, package in enumerate(self.helm_packages):
if isinstance(package, dict):
package["path_to_chart"] = self.path_from_cli_dir(
Expand Down Expand Up @@ -580,6 +596,7 @@ class NSConfiguration(Configuration):

def __post_init__(self):
"""Covert things to the correct format."""
super().__post_init__()
if self.network_functions and isinstance(self.network_functions[0], dict):
nf_ret_list = [
NFDRETConfiguration(**config) for config in self.network_functions
Expand Down
4 changes: 2 additions & 2 deletions src/aosm/azext_aosm/generate_nfd/cnf_nfd_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,12 @@ 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)) or not v:
elif isinstance(item, (str, int, bool)) or not v:
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 "
f"Found an unexpected type {type(item)} of key {k} in "
"values.yaml, cannot generate values mapping file."
)
elif not v:
Expand Down

0 comments on commit f48827b

Please sign in to comment.