Skip to content

Commit

Permalink
Merge pull request Azure#21 from jddarby/jl/fix-style
Browse files Browse the repository at this point in the history
Jl/fix style
  • Loading branch information
jordlay authored Jun 7, 2023
2 parents 6cda523 + a6c292c commit 649ace6
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 184 deletions.
107 changes: 52 additions & 55 deletions src/aosm/azext_aosm/_configuration.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,69 @@
## Disabling as every if statement in validate in NSConfig class has this condition
# pylint: disable=simplifiable-condition

from dataclasses import dataclass, field
from typing import Dict, Optional, Any, List
from pathlib import Path
import os
from azure.cli.core.azclierror import ValidationError, InvalidArgumentValueError
from azext_aosm.util.constants import (
DEFINITION_OUTPUT_BICEP_PREFIX,
VNF,
CNF,
NSD,
SCHEMA,
NSD_DEFINITION_OUTPUT_BICEP_PREFIX,
NF_DEFINITION_JSON_FILE,
)
import os


DESCRIPTION_MAP: Dict[str, str] = {
"publisher_resource_group_name": (
"Resource group for the Publisher resource. Will be "
"created if it does not exist."
),
"publisher_name": (
"Name of the Publisher resource you want your definition "
"published to. Will be created if it does not exist."
),
"publisher_name_nsd": (
"Name of the Publisher resource you want your design published to. This published should be the same as the publisher used for your NFDVs"
),
"publisher_resource_group_name_nsd": ("Resource group for the Publisher resource."),
"publisher_resource_group_name":
"Resource group for the Publisher resource. Will be created if it does not exist."
,
"publisher_name":
"Name of the Publisher resource you want your definition published to. Will be created if it does not exist."
,
"publisher_name_nsd":
"Name of the Publisher resource you want your design published to. "
"This should be the same as the publisher used for your NFDVs"
,
"publisher_resource_group_name_nsd": "Resource group for the Publisher resource.",
"nf_name": "Name of NF definition",
"version": "Version of the NF definition",
"acr_artifact_store_name": "Name of the ACR Artifact Store resource. Will be created if it does not exist.",
"location": "Azure location to use when creating resources.",
"blob_artifact_store_name": "Name of the storage account Artifact Store resource. Will be created if it does not exist.",
"file_path": (
"Optional. File path of the artifact you wish to upload from your "
"local disk. Delete if not required."
),
"blob_sas_url": (
"Optional. SAS URL of the blob artifact you wish to copy to your "
"Artifact Store. Delete if not required."
),
"artifact_version": (
"blob_artifact_store_name":
"Name of the storage account Artifact Store resource. Will be created if it does not exist.",
"artifact_name": "Name of the artifact",
"file_path":
"Optional. File path of the artifact you wish to upload from your local disk. "
"Delete if not required.",
"blob_sas_url":
"Optional. SAS URL of the blob artifact you wish to copy to your Artifact Store. "
"Delete if not required.",
"artifact_version":
"Version of the artifact. For VHDs this must be in format A-B-C. "
"For ARM templates this must be in format A.B.C"
),
"For ARM templates this must be in format A.B.C",
"nsdv_description": "Description of the NSDV",
"nsdg_name": "Network Service Design Group Name. This is the collection of Network Service Design Versions. Will be "
"created if it does not exist.",
"nsdg_name":
"Network Service Design Group Name. This is the collection of Network Service Design Versions. "
"Will be created if it does not exist.",
"nsd_version": "Version of the NSD to be created. This should be in the format A.B.C",
"network_function_definition_group_name": "Exising Network Function Definition Group Name. This can be created using the 'az aosm nfd' commands.",
"network_function_definition_version_name": "Exising Network Function Definition Version Name. This can be created using the 'az aosm nfd' commands.",
"network_function_definition_group_name":
"Exising Network Function Definition Group Name. "
"This can be created using the 'az aosm nfd' commands.",
"network_function_definition_version_name":
"Exising Network Function Definition Version Name. "
"This can be created using the 'az aosm nfd' commands.",
"network_function_definition_offering_location": "Offering location of the Network Function Definition",
"helm_package_name": "Name of the Helm package",
"path_to_chart": (
"File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz"
),
"path_to_mappings": (
"File path of value mappings on local disk. Accepts .yaml or .yml"
),
"helm_depends_on": (
"path_to_chart":
"File path of Helm Chart on local disk. Accepts .tgz, .tar or .tar.gz",
"path_to_mappings":
"File path of value mappings on local disk. Accepts .yaml or .yml",
"helm_depends_on":
"Names of the Helm packages this package depends on. "
"Leave as an empty array if no dependencies"
),
"Leave as an empty array if no dependencies",
}


Expand Down Expand Up @@ -97,6 +100,7 @@ def acr_manifest_name(self) -> str:

@dataclass
class NSConfiguration:
# pylint: disable=too-many-instance-attributes
location: str = DESCRIPTION_MAP["location"]
publisher_name: str = DESCRIPTION_MAP["publisher_name_nsd"]
publisher_resource_group_name: str = DESCRIPTION_MAP[
Expand All @@ -117,33 +121,24 @@ class NSConfiguration:
nsdv_description: str = DESCRIPTION_MAP["nsdv_description"]

def validate(self):
## validate that all of the configuration parameters are set
""" Validate that all of the configuration parameters are set """

if self.location == DESCRIPTION_MAP["location"] or "":
raise ValueError("Location must be set")
if self.publisher_name == DESCRIPTION_MAP["publisher_name_nsd"] or "":
raise ValueError("Publisher name must be set")
if (
self.publisher_resource_group_name
== DESCRIPTION_MAP["publisher_resource_group_name_nsd"]
or ""
):
if self.publisher_resource_group_name == DESCRIPTION_MAP["publisher_resource_group_name_nsd"] or "":
raise ValueError("Publisher resource group name must be set")
if (
self.acr_artifact_store_name == DESCRIPTION_MAP["acr_artifact_store_name"]
or ""
):
if self.acr_artifact_store_name == DESCRIPTION_MAP["acr_artifact_store_name"] or "":
raise ValueError("ACR Artifact Store name must be set")
if (
self.network_function_definition_group_name
== DESCRIPTION_MAP["network_function_definition_group_name"]
or ""
== DESCRIPTION_MAP["network_function_definition_group_name"] or ""
):
raise ValueError("Network Function Definition Group name must be set")
if (
self.network_function_definition_version_name
== DESCRIPTION_MAP["network_function_definition_version_name"]
or ""
self.network_function_definition_version_name ==
DESCRIPTION_MAP["network_function_definition_version_name"] or ""
):
raise ValueError("Network Function Definition Version name must be set")
if (
Expand Down Expand Up @@ -178,7 +173,8 @@ def network_function_name(self) -> str:
@property
def acr_manifest_name(self) -> str:
"""Return the ACR manifest name from the NFD name."""
return f"{self.network_function_name.lower().replace('_', '-')}-acr-manifest-{self.nsd_version.replace('.', '-')}"
return \
f"{self.network_function_name.lower().replace('_', '-')}-acr-manifest-{self.nsd_version.replace('.', '-')}"

@property
def nfvi_site_name(self) -> str:
Expand Down Expand Up @@ -231,6 +227,7 @@ def validate(self) -> None:
:raises ValidationError for any invalid config
"""

if self.vhd.version == DESCRIPTION_MAP["version"]:
# Config has not been filled in. Don't validate.
return
Expand Down
9 changes: 4 additions & 5 deletions src/aosm/azext_aosm/delete/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def delete_vnf(self, clean: bool = False):

def delete_nsd(self):
"""
Delete the NSDV and manifests. If they don't exist it still reports them as
deleted.
Delete the NSDV and manifests.
If they don't exist it still reports them as deleted.
"""
assert isinstance(self.config, NSConfiguration)

Expand Down Expand Up @@ -261,9 +262,7 @@ def delete_publisher(self) -> None:
raise

def delete_config_group_schema(self) -> None:
"""
Delete the Configuration Group Schema.
"""
"""Delete the Configuration Group Schema."""
message = f"Delete Configuration Group Schema {self.config.cg_schema_name}"
logger.debug(message)
print(message)
Expand Down
19 changes: 12 additions & 7 deletions src/aosm/azext_aosm/deploy/artifact.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Highly Confidential Material
"""A module to handle interacting with artifacts."""

from knack.log import get_logger
from dataclasses import dataclass
# pylint: disable=unidiomatic-typecheck
"""A module to handle interacting with artifacts."""
from typing import Union
from dataclasses import dataclass
from knack.log import get_logger

from azure.storage.blob import BlobClient, BlobType
from azext_aosm._configuration import ArtifactConfig
from oras.client import OrasClient
from azext_aosm._configuration import ArtifactConfig


logger = get_logger(__name__)

Expand Down Expand Up @@ -45,8 +48,9 @@ def _upload_to_acr(self, artifact_config: ArtifactConfig) -> None:
# the field.

if artifact_config.file_path:
target = f"{self.artifact_client.remote.hostname.replace('https://', '')}/{self.artifact_name}:{self.artifact_version}"
logger.debug(f"Uploading {artifact_config.file_path} to {target}")
target = f"{self.artifact_client.remote.hostname.replace('https://', '')}\
/{self.artifact_name}:{self.artifact_version}"
logger.debug("Uploading %s to %s", artifact_config.file_path, target)
self.artifact_client.push(
files=[artifact_config.file_path],
target=target,
Expand All @@ -70,7 +74,7 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None:
with open(artifact_config.file_path, "rb") as artifact:
self.artifact_client.upload_blob(artifact, overwrite=True, blob_type=BlobType.PAGEBLOB)
logger.info(
f"Successfully uploaded {artifact_config.file_path} to {self.artifact_client.account_name}"
"Successfully uploaded %s to %s", artifact_config.file_path, self.artifact_client.account_name
)
else:
logger.info("Copy from SAS URL to blob store")
Expand All @@ -80,7 +84,8 @@ def _upload_to_storage_account(self, artifact_config: ArtifactConfig) -> None:
logger.debug(source_blob.url)
self.artifact_client.start_copy_from_url(source_blob.url)
logger.info(
f"Successfully copied {source_blob.blob_name} from {source_blob.account_name} to {self.artifact_client.account_name}"
"Successfully copied %s from %s to %s",
source_blob.blob_name, source_blob.account_name, self.artifact_client.account_name
)
else:
raise RuntimeError(
Expand Down
19 changes: 9 additions & 10 deletions src/aosm/azext_aosm/deploy/artifact_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@
# Highly Confidential Material
"""A module to handle interacting with artifact manifests."""

from knack.log import get_logger
from functools import cached_property, lru_cache
from typing import Any, List, Union
from knack.log import get_logger
from oras.client import OrasClient

from azure.cli.core.azclierror import AzCLIError
from azext_aosm.deploy.artifact import Artifact
from azure.storage.blob import BlobClient
from oras.client import OrasClient

from azext_aosm.deploy.artifact import Artifact
from azext_aosm._configuration import NFConfiguration, NSConfiguration
from azext_aosm.vendored_sdks.models import (
ArtifactManifest,
ManifestArtifactFormat,
CredentialType,
ArtifactType,
)

from azext_aosm.util.management_clients import ApiClients

logger = get_logger(__name__)


class ArtifactManifestOperator:
"""ArtifactManifest class."""

# pylint: disable=too-few-public-methods
def __init__(
self,
config: NFConfiguration or NSConfiguration,
Expand Down Expand Up @@ -122,8 +123,7 @@ def _get_artifact_client(
# Check we have the required artifact types for this credential. Indicates
# a coding error if we hit this but worth checking.
if not (
artifact.artifact_type == ArtifactType.IMAGE_FILE
or artifact.artifact_type == ArtifactType.VHD_IMAGE_FILE
artifact.artifact_type in (ArtifactType.IMAGE_FILE, ArtifactType.VHD_IMAGE_FILE)
):
raise AzCLIError(
f"Cannot upload artifact {artifact.artifact_name}."
Expand All @@ -145,8 +145,7 @@ def _get_artifact_client(

blob_url = self._get_blob_url(container_name, blob_name)
return BlobClient.from_blob_url(blob_url)
else:
return self._oras_client(self._manifest_credentials["acr_server_url"])
return self._oras_client(self._manifest_credentials["acr_server_url"])

def _get_blob_url(self, container_name: str, blob_name: str) -> str:
"""
Expand All @@ -158,7 +157,7 @@ def _get_blob_url(self, container_name: str, blob_name: str) -> str:
for container_credential in self._manifest_credentials["container_credentials"]:
if container_credential["container_name"] == container_name:
sas_uri = str(container_credential["container_sas_uri"])
sas_uri_prefix = sas_uri.split("?")[0]
sas_uri_prefix = sas_uri.split("?")[0] # pylint: disable=use-maxsplit-arg
sas_uri_token = sas_uri.split("?")[1]

blob_url = f"{sas_uri_prefix}/{blob_name}?{sas_uri_token}"
Expand Down
Loading

0 comments on commit 649ace6

Please sign in to comment.