Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default RG and ACR Values with Publisher Name + Bug Fix 920284 #103

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/aosm/azext_aosm/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def validate(self):
Validate the configuration.
"""
if not self.version:
raise ValidationError("version must be set.")
raise ValidationError("Version must be set.")
jordlay marked this conversation as resolved.
Show resolved Hide resolved
if self.blob_sas_url and self.file_path:
raise ValidationError("Only one of file_path or blob_sas_url may be set.")
if not (self.blob_sas_url or self.file_path):
Expand All @@ -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__()
jordlay marked this conversation as resolved.
Show resolved Hide resolved
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:
jordlay marked this conversation as resolved.
Show resolved Hide resolved
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