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

Achurchard/publish #130

Merged
merged 12 commits into from
Jan 19, 2024
78 changes: 7 additions & 71 deletions src/aosm/azext_aosm/_params.py
Cyclam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -49,75 +49,12 @@ def load_arguments(self: AzCommandsLoader, _):
help="Also delete artifact stores, NFD Group and Publisher. Use with care.",
)
c.argument(
"definition_file",
options_list=["--definition-file", "-b"],
"build_output_folder",
options_list=["--build-output-folder", "-b"],
type=file_type,
completer=FilesCompleter(allowednames="*.json"),
help=(
"Optional path to a bicep file to publish. Use to override publish of"
" the built definition with an alternative file."
),
)
c.argument(
"design_file",
options_list=["--design-file", "-b"],
type=file_type,
completer=FilesCompleter(allowednames="*.bicep"),
help=(
"Optional path to a bicep file to publish. Use to override publish of"
" the built design with an alternative file."
),
)
c.argument(
"order_params",
arg_type=get_three_state_flag(),
help=(
"VNF definition_type only - ignored for CNF. Order deploymentParameters"
" schema and configMappings to have the parameters without default"
" values at the top and those with default values at the bottom. Can"
" make it easier to remove those with defaults which you do not want to"
" expose as NFD parameters."
),
)
c.argument(
"interactive",
options_list=["--interactive", "-i"],
arg_type=get_three_state_flag(),
help=(
"Prompt user to choose every parameter to expose as an NFD parameter."
" Those without defaults are automatically included."
),
)
c.argument(
"parameters_json_file",
options_list=["--parameters-file", "-p"],
type=file_type,
completer=FilesCompleter(allowednames="*.json"),
help=(
"Optional path to a parameters file for the bicep definition file. Use"
" to override publish of the built definition and config with"
" alternative parameters."
),
)
c.argument(
"manifest_file",
options_list=["--manifest-file", "-m"],
type=file_type,
completer=FilesCompleter(allowednames="*.json"),
help=(
"Optional path to a bicep file to publish manifests. Use to override"
" publish of the built definition with an alternative file."
),
)
c.argument(
"manifest_params_file",
options_list=["--manifest-params-file"],
type=file_type,
completer=FilesCompleter(allowednames="*.json"),
help=(
"Optional path to a parameters file for the manifest definition file."
" Use to override publish of the built definition and config with"
" alternative parameters."
"Path to the folder to publish, created by the build command."
),
)
c.argument(
Expand All @@ -135,11 +72,10 @@ def load_arguments(self: AzCommandsLoader, _):
options_list=["--no-subscription-permissions", "-u"],
arg_type=get_three_state_flag(),
help=(
"CNF definition_type publish only - ignored for VNF."
" Set to True if you do not "
"have permission to import to the Publisher subscription (Contributor "
"role + AcrPush role, or a custom role that allows the importImage "
"action and AcrPush over the "
"CNF definition_type publish only - ignored for VNF. "
"Pass this flag if you do not have permission to import to the "
"Publisher subscription (Contributor role + AcrPush role, or a "
"custom role that allows the importImage action and AcrPush over the "
"whole subscription). This means that the image artifacts will be "
"pulled to your local machine and then pushed to the Artifact Store. "
"Requires Docker to be installed locally."
Expand Down
42 changes: 22 additions & 20 deletions src/aosm/azext_aosm/cli_handlers/onboarding_base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
from azure.cli.core.azclierror import UnclassifiedUserFault
from jinja2 import StrictUndefined, Template
from knack.log import get_logger

from azext_aosm.configuration_models.onboarding_base_input_config import (
OnboardingBaseInputConfig,
)
from azext_aosm.definition_folder.builder.definition_folder_builder import (
DefinitionFolderBuilder,
)
from azext_aosm.definition_folder.reader.definition_folder import DefinitionFolder
from azext_aosm.common.command_context import CommandContext
from azext_aosm.configuration_models.onboarding_base_input_config import \
OnboardingBaseInputConfig
from azext_aosm.configuration_models.common_parameters_config import \
BaseCommonParametersConfig
from azext_aosm.definition_folder.builder.definition_folder_builder import \
DefinitionFolderBuilder

from azext_aosm.vendored_sdks.models import AzureCoreNetworkFunctionVhdApplication

logger = get_logger(__name__)
Expand Down Expand Up @@ -84,15 +87,21 @@ def build(self, aosm_client=None):
self.definition_folder_builder.add_element(self.build_common_parameters_json())
self.definition_folder_builder.write()

def publish(self):
def publish(self, command_context: CommandContext):
"""Publish the definition."""
# Takes folder, deploys to Azure
# - Work out where the definition folder is
# - If not specified, use a set path (see constants.py for directory names), and error if not found with option of moving to correct dir, or specifying path
# - If specified, use that path
# - Read folder/ create folder object
# - For each step (element):
# - Do element.deploy()
# TODO: Implement
if command_context.cli_options["definition_folder"]:
definition_folder = DefinitionFolder(
command_context.cli_options["definition_folder"]
)
# TODO: else logic for finding VNF_OUTPUT_FOLDER_FILENAME, etc., assuming command run from same directory as build.
definition_folder.deploy(config=self.config, command_context=command_context)

def delete(self):
def delete(self, command_context: CommandContext):
"""Delete the definition."""
# Takes folder, deletes to Azure
# - Read folder/ create folder object
Expand Down Expand Up @@ -145,21 +154,14 @@ def _read_params_config_from_file(self, input_json_path) -> dict:
""" Reads input file, takes only the {parameters:values} + returns config as dictionary

For example,
{'location': {'value': 'test'} is added to the schema as
{'location': {'value': 'test'} is returned as
{'location': 'test'}

"""
with open(input_json_path, "r", encoding="utf-8") as _file:
params_schema = json.load(_file)

sanitised_schema = {}
for param in params_schema["parameters"]:
# Converting camel case to snake case, so armTemplate becomes arm_template
snake_case_param = ''.join(['_' + char.lower() if char.isupper()
else char for char in param]).lstrip('_')
# Add formatted param as key and the param["value"] as the value
sanitised_schema[snake_case_param] = params_schema["parameters"][param]["value"]
return sanitised_schema
params = params_schema["parameters"]
return {param: params[param]["value"] for param in params}

def _render_base_bicep_contents(self, template_path):
"""Write the base bicep file from given template."""
Expand Down
2 changes: 2 additions & 0 deletions src/aosm/azext_aosm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@


def load_command_table(self: AzCommandsLoader, _):
# TODO: think client_factory can be deleted. The handlers don't use it
Cyclam marked this conversation as resolved.
Show resolved Hide resolved
with self.command_group("aosm nfd", client_factory=cf_aosm) as g:
# Add each command and bind it to a function in custom.py
g.custom_command("generate-config", "onboard_nfd_generate_config")
g.custom_command("build", "onboard_nfd_build")
g.custom_command("publish", "onboard_nfd_publish")
g.custom_command("delete", "onboard_nfd_delete")

# TODO: think client_factory can be deleted. The handlers don't use it
with self.command_group("aosm nsd", client_factory=cf_aosm) as g:
# Add each command and bind it to a function in custom.py
g.custom_command("generate-config", "onboard_nsd_generate_config")
Expand Down
Loading
Loading