forked from Azure/azure-cli-extensions
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding SNS handler and input config * adding SNS handler and input config * fixed style error * new recording of vnf test * fixed validations * fixed UT and deploy_all_parameter * fixed history --------- Co-authored-by: Priya Vijayaraghavan <priyavij@microsoft.com>
- Loading branch information
Showing
11 changed files
with
812 additions
and
458 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/aosm/azext_aosm/cli_handlers/onboarding_sns_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 | ||
|
||
import json | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
from knack.log import get_logger | ||
from azext_aosm.cli_handlers.onboarding_nfd_base_handler import OnboardingBaseCLIHandler | ||
from azext_aosm.common.constants import ( | ||
SNS_OUTPUT_FOLDER_FILENAME, | ||
SNS_INPUT_FILENAME | ||
) | ||
from azext_aosm.configuration_models.common_parameters_config import ( | ||
SNSCommonParametersConfig, | ||
) | ||
from azext_aosm.definition_folder.builder.bicep_builder import ( | ||
BicepDefinitionElementBuilder, | ||
) | ||
from azext_aosm.definition_folder.builder.json_builder import ( | ||
JSONDefinitionElementBuilder, | ||
) | ||
from azext_aosm.configuration_models.onboarding_sns_input_config import SiteNetworkServicePropertiesConfig | ||
logger = get_logger(__name__) | ||
|
||
|
||
class SNSCLIHandler(OnboardingBaseCLIHandler): | ||
"""CLI handler for SNS.""" | ||
|
||
config: SiteNetworkServicePropertiesConfig | ||
|
||
@property | ||
def default_config_file_name(self) -> str: | ||
"""Get the default configuration file name.""" | ||
return SNS_INPUT_FILENAME | ||
|
||
@property | ||
def output_folder_file_name(self) -> str: | ||
"""Get the output folder file name.""" | ||
return SNS_OUTPUT_FOLDER_FILENAME | ||
|
||
def build(self): | ||
"""Build the definition.""" | ||
self.definition_folder_builder.add_element(self.build_all_parameters_json()) | ||
self.definition_folder_builder.write() | ||
|
||
def _get_input_config(self, input_config: Optional[dict] = None) -> SiteNetworkServicePropertiesConfig: | ||
"""Get the configuration for the command.""" | ||
if input_config is None: | ||
input_config = {} | ||
return SiteNetworkServicePropertiesConfig(**input_config) | ||
|
||
def _get_params_config(self, config_file: Path) -> SNSCommonParametersConfig: | ||
"""Get the configuration for the command.""" | ||
with open(config_file, "r", encoding="utf-8") as _file: | ||
params_dict = json.load(_file) | ||
if params_dict is None: | ||
params_dict = {} | ||
return SNSCommonParametersConfig(**params_dict) | ||
|
||
def build_base_bicep(self) -> BicepDefinitionElementBuilder: | ||
pass | ||
|
||
def build_all_parameters_json(self) -> JSONDefinitionElementBuilder: | ||
"""Build all parameters json.""" | ||
params_content = { | ||
"location": self.config.location, | ||
"operatorResourceGroupName": self.config.operator_resource_group_name, | ||
"siteName": self.config.site_name | ||
} | ||
base_file = JSONDefinitionElementBuilder( | ||
Path(SNS_OUTPUT_FOLDER_FILENAME), json.dumps(params_content, indent=4) | ||
) | ||
return base_file | ||
|
||
def _get_processor_list(self): | ||
# Provide an implementation for this method | ||
pass | ||
|
||
def build_artifact_list(self): | ||
# Provide an implementation for this method | ||
pass | ||
|
||
def build_manifest_bicep(self): | ||
# Provide an implementation for this method | ||
pass | ||
|
||
def build_resource_bicep(self) -> BicepDefinitionElementBuilder: | ||
# Provide an implementation for this method | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/aosm/azext_aosm/configuration_models/onboarding_sns_input_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# 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 | ||
class SiteNetworkServicePropertiesConfig: | ||
"""SNS Object.""" | ||
location: str = field( | ||
default="", | ||
metadata={ | ||
"comment": "Azure location to use when creating resources e.g uksouth" | ||
}, | ||
) | ||
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 = ( | ||
field( | ||
default=None, | ||
metadata={ | ||
"comment": ("Information regarding NSDV to be used in SNS.") | ||
}, | ||
) | ||
) | ||
|
||
def validate(self): | ||
"""Validate the configuration.""" | ||
if not self.location: | ||
raise ValidationError("Location must be set") | ||
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: | ||
self.nsd_reference = {} | ||
self.nsd_reference = NSDVReferenceConfig(**self.nsd_reference) | ||
|
||
|
||
@dataclass | ||
class NSDVReferenceConfig: | ||
"""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_name: str = field( | ||
default="", | ||
metadata={"comment": "The resource group that the publisher NSDV is hosted in. "}, | ||
) | ||
nsd_name: str = field( | ||
default="", | ||
metadata={"comment": "Network Service Design" | ||
"(NSD) to be used from the publisher. This is the collection of Network Service Design Versions. "}, | ||
) | ||
nsd_version: str = field( | ||
default="", | ||
metadata={"comment": "Version of the NSD to be used which is in the format A.B.C "}, | ||
) | ||
|
||
def validate(self): | ||
"""Validate the configuration.""" | ||
if not self.publisher_name: | ||
raise ValidationError("Publisher Name must be set") | ||
if not self.publisher_resource_group_name: | ||
raise ValidationError("Publisher Resource Group must be set") | ||
if not self.nsd_name: | ||
raise ValidationError( | ||
"NSD Name must be set" | ||
) | ||
if not self.nsd_version: | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.