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

Priyavij/sitework #188

Merged
merged 8 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 2 additions & 3 deletions src/aosm/azext_aosm/cli_handlers/onboarding_sns_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
JSONDefinitionElementBuilder,
)
from azext_aosm.configuration_models.onboarding_sns_input_config import SiteNetworkServicePropertiesConfig

from azext_aosm.configuration_models.onboarding_sns_input_config import NSDVReferenceConfig
logger = get_logger(__name__)


Expand Down Expand Up @@ -72,9 +72,8 @@ def build_all_parameters_json(self) -> JSONDefinitionElementBuilder:
for property_name, value in vars(self.config).items():
params_content[property_name] = value
base_file = JSONDefinitionElementBuilder(
Path(SNS_OUTPUT_FOLDER_FILENAME), json.dumps(params_content, indent=4)
Path(SNS_OUTPUT_FOLDER_FILENAME), json.dumps(params_content, indent=4, default=NSDVReferenceConfig.to_dict)
priyavj08 marked this conversation as resolved.
Show resolved Hide resolved
)

return base_file

def _get_processor_list(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from __future__ import annotations

from dataclasses import dataclass, field

from azure.cli.core.azclierror import ValidationError
import semver


@dataclass
Expand All @@ -19,21 +19,19 @@ class SiteNetworkServicePropertiesConfig:
"comment": "Azure location to use when creating resources e.g uksouth"
},
)
operator_resource_group: str = field(
operator_resource_group_name: str = field(
default="",
metadata={"comment": "The resource group that the operator resources will be hosted in."},
)
site_name: str = field(
default="",
metadata={"comment": "Name of the site."},
)
nsd_reference: "NSDVReferenceConfig" = (
nsd_reference: NSDVReferenceConfig = (
priyavj08 marked this conversation as resolved.
Show resolved Hide resolved
field(
default_factory=lambda: [NSDVReferenceConfig()],
default=None,
priyavj08 marked this conversation as resolved.
Show resolved Hide resolved
metadata={
"comment": (
"Information regarding NSDV to be used in SNS."
)
"comment": ("Information regarding NSDV to be used in SNS.")
},
)
)
Expand All @@ -42,24 +40,31 @@ def validate(self):
"""Validate the configuration."""
if not self.location:
raise ValidationError("Location must be set")
if not self.operator_resource_group:
if not self.operator_resource_group_name:
raise ValidationError("Operator resource group name must be set")
if not self.site_name:
raise ValidationError(
"site name must be set"
)
if not self.nsd_reference:
raise ValidationError("At least one Network Service Design Version must be included.")
self.nsd_reference.validate()

def __post_init__(self):
if self.nsd_reference is None:
priyavj08 marked this conversation as resolved.
Show resolved Hide resolved
self.nsd_reference = {}
self.nsd_reference = NSDVReferenceConfig(**self.nsd_reference)

@dataclass
class NSDVReferenceConfig:
"""SNS Object."""
"""NSDV Reference."""
publisher_name: str = field(
default="",
metadata={
"comment": "Name of the Publisher resource where Network Service Design resource to be used in SNS exists"
},
)
publisher_resource_group: str = field(
publisher_resource_group_name: str = field(
default="",
metadata={"comment": "The resource group that the publisher NSDV is hosted in. "},
)
Expand All @@ -77,7 +82,7 @@ def validate(self):
"""Validate the configuration."""
if not self.publisher_name:
raise ValidationError("Publisher Name must be set")
if not self.publisher_resource_group:
if not self.publisher_resource_group_name:
raise ValidationError("Publisher Resource Group must be set")
if not self.nsd_name:
raise ValidationError(
Expand All @@ -87,3 +92,15 @@ def validate(self):
raise ValidationError(
"NSD Version must be set"
)
try:
semver.VersionInfo.parse(self.nsd_version)
except ValueError:
raise ValidationError(f"{self.nsd_version} is not a valid semantic version")

def to_dict(self):
return {
'publisher_name': self.publisher_name,
'publisher_resource_group_name': self.publisher_resource_group_name,
'nsd_name': self.nsd_name,
'nsd_version': self.nsd_version
}