Skip to content

Commit

Permalink
Add aosm extension (#6426)
Browse files Browse the repository at this point in the history
* removed deploy with sdk

* added artifact list

* push example cnf bicep

* Add temporary build workflow for AOSM extension (#4)

* Add temporary build workflow for AOSM extension

* Add Releaser to maintain a release with the latest build in a consistent place

* added output dir; fixing getchartmappingschema

* Add empty init files to inner modules so setuptools recognises them as modules

* Use latest RG model to remove unnecessary dependency on version

* Use latest deployment model to remove unnecessary dependency on version

* fixed parameter mappings + copied needed files to output folder

* jinja2 and find value paths

* fixed typos + self.aritfacts only has unique artifacts

* use regex instead of string to find deploy params

* delete accidentaly commited input.json

* fixed deploy params; added indent to mapping file

* Update readme with install/bug reporting instructions

* Adjust headers so rendered readme looks nicer

* renamed values.nondef + added cli errors

* Split help command example lines

* Clarify that bug process is internal

* fixed parameter vals not updating

* delete unuseed temoplate and update jinja2 templates

* Update README.md

* Update README.md

* added docstrings; added basic error catching with file handling

* small refactor of generate nfd

* fixed j2 template captions; added create_nfd to cnf; edited error messages; added deleting existing folder to custom.py

* fixed file not found erroe

* Refactor commands to az aosm nfd|nsd build (#10)

* Refactor commands to az aosm nfd|nsd build

* setup.py version

* Version was wrong

* remove publish option from build

* lint

* wrong params

* fixed most style errors; ran static checks and azdev style

* pre merge commit

* more style changes; renamed vnfbicepnfd to vnfnfd

* Update readme with workflow

* added configfile validation

* added temp dir to vnf; renamed shared constants

* sunny markups

* removed create_nfd_folder; added schema prefix to constant

* added deploymentparams to constants.py

* added error catching for get chart name and version

* added meaningful logs; prevent auto overwriting input.json

* edited vnf schema to have accepted types

* added templates to setup.py

* added location from input file not resourceGroup().location

* added path_to_mappings to input.json; added logic to take mappings from file outside of helm package

* renamed non_def_values to mappings_path

* Pk5/add nsd cli (#15)

* First working version of the CLI NSD create

* Fully working version of the NSD CLI

* minor change to nsd_generate

* Sunny's refactor

* First round of cleanup

* Secound Round of cleanup

* fix the 2023 api NSDV

* description updates

* deleted comment

* Fix SNS creation

* Fix SNS creation try 2

* markups

* delete unnecessary file

* Testing markups

* Fix the SNS attempt 3

* minor fixes

* Fix config validation

* fix CNF depends on

* initial commit; ran python static checks fmt (except on vendored sdks), fixed styling on _configuration.py

* Name uploaded VHD correctly

* Self review markups

* broken config generation code

* fixed up configuration.py

* fixed cnf generator styling

* fixed styling for cnf generator

* fixed up nfd generator base and deploy with arm

* fixed styling for artifact.py

* fixed styling for atrifact manifest .py

* Code review markups

* fixed more linting

* first attempt at regex

* Sunny/choose deploy parameters (#23)

* choose-deploy-parameters

* optioned deployParameters for CNF

* lint

* lint2

* docs

* docs

* lint

* 9.82 score

* Fix bugs

* more useful debug logs

* Fix bugs and logging

* lint

* markups

* Fix for oras target string with erroneous spaces

* fixed regex; tested on existing charts and sas charts; committing to not lose prints for testing

* changed regex constants + tidied

* fixed blankspace

* markups

* initial commit

* tidied code and added comments

* add multi nf config

* Add style and lint check

* added logic for handling deployparams within lists

* one line fix from review

* removing print statement

* added new test file and one unit test

* added workflow for unit tests in pipeline + set up rough structure of unit testing

* instantiated cnf class; added fake invalid helm package; added new files to use for testing

* Nsd for cnfs (#33)

* NSD building for CNFs

* linting

* Add Publish command to the CNF azure CLI (#24)

* Working publish

* Fix the artifact upload

* Working image copy

* minor fix

* Minor fixes

* sunny merge add-aosm-extension into patryk's branch (#25)

* Sunny/choose deploy parameters (#23)

* choose-deploy-parameters

* optioned deployParameters for CNF

* lint

* lint2

* docs

* docs

* lint

* 9.82 score

* Fix bugs

* more useful debug logs

* Fix bugs and logging

* lint

* markups

* comment out breaking line

* minor TODOs

* deleted comment

* fix bring your own parameters

* Markups

* Fix the helm upload

* Minor markups

* Change error message

---------

Co-authored-by: sunnycarter <[email protected]>
Co-authored-by: Sunny Carter <[email protected]>

* Expose NFD version and managed identities (#34)

* NFDV version exposed as a CGV on an SNS

* Managed identities support on NFs

* Fix identiy, fix API versions

* history

---------

Co-authored-by: Jamie Parsons <[email protected]>
Co-authored-by: Sunny Carter <[email protected]>

* Add a first VNF test

* achurchard/style fixes (#35)

Fix style issues raised by `azdev style`

* Add CNF UTs that will fail at the moment

* Actually include all files.

* Always run tests

* Add another test that won't pass yet

* remove github pipeline tests - they should run in Azure

* Sundry fixes for CNF quickstart (#38)

* Sundry fixes for CNF quickstart

* merge add-aosm-ext in (#37)

* markups

* NSD UTs

* Update read me.

* Improve path handling, other small refactorings (#39)

# Main changes

## Make methods relying on self._tmp_dir private
- `self._tmp_dir` is only available in the context of calling `generate_nfd()`, so methods relying on `self._tmp_dir` should be private

## Use pathlib.Path rather than os file operations
- Provides clearer and stronger typing than passing `str`s around
- Adds some handy utility functions

## Variable renaming for clarity
- E.g. consistently use 'directory' / 'dir' (rather than mix with 'folder')
- Obvs somewhat subjective, but as someone new to most of this code, the changes made sense to me

## Add nfd_bicep_path as abstract property on NFDGenerator
- We rely on it when calling the concrete implementations
- Also use ABC rather than raise NotImplementedError

## Miscellaneous style updates to keep `azdev style aosm` happy
- isort
- black

* Fix Artifact upload on Windows (#40)

* Black

* Mark ups

* Sunny/fix artifact upload windows (#41)

* Fix Artifact upload on Windows

* mypy fixups

* mypy fixes

* linting

* mypy

* mypy for _configuration.py

* mypy for vnf_nfd_generator.py

* mypy appeasement

* python-static-checks fmt

* az style happy

* lint

* mypy cnf_nfd_generator

* copyright

* more lint

* Remove windows oras workaround now 0.0.18 oras out

* history

---------

Co-authored-by: Jamie Parsons <[email protected]>

* Fix VNFD build (#42)

* Multiple instances of the same NF

* fix vnf deploy schema types (#44)

* Tidy up

* Mypy and docs

* history.rst

* Update README with logging info (#43)

* Update README with logging info

* Update docs

* self markups

* Take oras 0.1.19 to fix Windows artifact upload (#46)

* Rename a few things

* DRY the deploy_nfd_from_bicep code

* Make conditional statements clearer

* black

* Update custom.py to use new nfd deploy method

* Black with text processing

* Create new nfRET class

* Mypy passing

* UTs passing

* Dry the deploy_nfd_from_bicep() code (#48)

- Removed duplicated code in the deploy_vnfd_from_bicep() and deploy_cnfd_from_bicep() methods
- Moved variables onto the class instance and stopped passing them around in the method signatures
  - Also made the deployer class a dataclass for cleaner __init__
- Made parameters a property of the class, and moved the logic for getting/generating them into that property method
- Improved the typing
  - Included adding enums for SkipSteps and DeployableResourceTypes
- Added the new skip step logic for image uploads
  - Added a new skip step type of IMAGE_UPLOAD

Testing:
- No MyPy errors
- Live tests for VNFS+NSD, CNFs, including all --skip options

* Unit tests added

* Versions are wrong in NSD template comments

* Self review markups

* Remove wrong comments

* Code review markups

* Extra markups

* Fix mypy

* Pk5/add integration tests (#51)

* Somewhat working example

* Cleanups

* Update recording

* fix minor linting error

* More markups

* Update output in tests

* Pk5/minor integration tests changes (#52)

* Modify changelog and rename tests

* Delete recording file

* Update recordings

* Update developer docs

* Remove credentials

* Fix linting

* cheeky extra change

* Remove credentials from the integration test recordings (#54)

* Modify changelog and rename tests

* Delete recording file

* Fix the credentials issue in the integration tests

* Update CHANGELOG

* Markups

* Fix typo

* Minor markups

* Make cleaning up resources more robust and remove the VHD external reference

* Markups

* Remove the integration test from the repo (#56)

* prerequisite docker for cnf

* Fix bicep render on Windows (#57)

* Fixes for Windows (#58)

* Fix bicep render on Windows

* Fixes for Windows

* python-static-checks ran

* ADO-880627: Use docker-less ACR login

For running in environments without docker, such as CI pipelines.
This affects uploading Helm charts for CNFs - the ACR login now fetches
an access token, which is used to login to the Helm registry and upload
the chart.

* docker is not required any more

* Remove pre-release build and lint files from release branch (#63)

* Release markups - release branch (#65)

* Markups from release comments

* history

* markups and fixes

* README changes

* linting fixes

* Fix integration tests (#67)

* Fix integration tests

* Update src/aosm/development.md

Co-authored-by: Cyclam <[email protected]>

* Update src/aosm/azext_aosm/tests/latest/test_aosm_cnf_publish_and_delete.py

Co-authored-by: Cyclam <[email protected]>

* Update src/aosm/azext_aosm/tests/latest/test_aosm_cnf_publish_and_delete.py

Co-authored-by: Cyclam <[email protected]>

* Markup changes

---------

Co-authored-by: Cyclam <[email protected]>
Co-authored-by: Sunny Carter <[email protected]>

* Add aosm to service_name.json

* move artifact upload to before nfd/nsd deploy (#62)

* move artifact upload to before nfd/nsd deploy

* markups

* check in new test recording

* non-working attempt to use token creds

* Check for Azure features on deploy and delete (#71)

* WIP: Check for features on deploy and delete

* linting

* Anand has confirmed names of flags

* Update test recording as now has calls to Features API

* Update src/aosm/azext_aosm/custom.py

Co-authored-by: jamiedparsons <[email protected]>

* docstring markups

---------

Co-authored-by: jamiedparsons <[email protected]>

* code working

* Fix generate-config

* Fix tests

* lint

* linting

* Jl/nfdv proxy (#73)

* added publisher scope to input file; changed to proxy nsdv

* fixed get request on proxy nfdv (should be overwritten when autogenerated again)

* small print bug fix

---------

Co-authored-by: Jordan <[email protected]>

* Code review mark ups

* Linting and fix UTs

* aosm codeowner

* Update HISTORY.rst

* Normalise aosm version to 1.0.0b1 for release

* update hashes in recording

* Temporary test revert of "aosm codeowner"

This reverts commit 479ba54.

* Fix license header formatting

* Revert "Temporary test revert of "aosm codeowner""

This reverts commit 0e4d0e7.

* Remove nonexistent entry from codeowners

* Fix source_local_docker_image defaults to placeholder text (#79)

* temp fix for bug

* minor formatting

* refactor + change validation ordering to mimic previous behaviour

* add docstring

---------

Co-authored-by: Jordan <[email protected]>

* renamed nsdg to nsd

* Helptext + a little bit of validation

* Fixed up validation

* Return True if _all_ required artifact manifests exist, not just the last one checked.

* Code markups + linting.

* Docs: CNF publish options and permissions (#91)

* Requirement for docker again

* revert bad markup (#94)

* Move live tests to swedensouth

* Actually move to uaenorth

* Don't log out ACR passwords when artifact commands fail (#97)

* Don't log out passwords when artifact commands fail

* Don't log out passwords when artifact commands fail part 2

* Comment to explain dropping the original exception

* Fix cnf image take 2 (#101)

* Fix CNF image copy to work cross subscription

* Cross subscription works for image copy. Still test same subscription

* lint

* Error message

* oops, code paste error

* markups

* appease mypy

* Default RG and ACR Values with Publisher Name (#103)

* added default rg and acr values for nf + nsd; added blob_url default for vnf

* added bug fix to close Paulo's bug

* change error message back

---------

Co-authored-by: Jordan <[email protected]>

* Fix unauthorized error bug

* Add spacing

* fix unexpected symbol when parsing lists (#107)

* Validation requirements on helm names (#109)

* Validation requirements on helm names

* lint

* markups

* lint

* Fix error parsing

* Lower case acr names (#112)

* Lower case ACR names and fix interactive mode for lists

* lint

* remove duplicate else branch

* always allow azureDeployLocation to be configurable

* Add new optional VHD parameters

* Make VNF publish and delete a live test only

* Validate VHD parameters in build UT

* Markups from the CLI team

* mark-ups

* remove azureDeployLocation as a configurable vhd parameter

* add explanitory comments

* Updates for 2023-09-01 API (#84)

* Regen Python SDK from 2023-09-01 API 
  - also uses latest AutoRest client
  - fix for HybridNetworkManagementClient init signature (swap order of subscription_id and credential parameters)

* Update CLI extension code to use new SDK

* added SAMI to publisher pre deploy

* Update bicep templates to use 2023-09-01

* Update NF templates

* Update metaschema

* Add Allow-Publisher to required feature flags

* Use secure objects for deployment parameters

* Correctly get array item types in CNF deployment parameter schemas

* Revert master .flake8 config

* Fix double space in user output.

Co-authored-by: Xing Zhou <[email protected]>

* Remove delete message to be consistent with other CLI extensions

* Move "Deleted <resource>" messages to logger.info().

* Remove Blob_SAS_URL Option from ArmTemplate in input file (#119)

* moved blob url to vhd config only; untested

* stopped error in post innit before validate

* changed ordering of inputs so that blob and filepath are next to each other; helptext for filepath different for each option

* Markups from sunny

* appease mypy

---------

Co-authored-by: Jordan <[email protected]>
Co-authored-by: Sunny Carter <[email protected]>

---------

Co-authored-by: Jordan <[email protected]>
Co-authored-by: Jacob Darby <[email protected]>
Co-authored-by: Chaos <[email protected]>
Co-authored-by: Chaos Chhapi <[email protected]>
Co-authored-by: jordlay <[email protected]>
Co-authored-by: patrykkulik-microsoft <[email protected]>
Co-authored-by: Jacob <[email protected]>
Co-authored-by: Jamie Parsons <[email protected]>
Co-authored-by: jamiedparsons <[email protected]>
Co-authored-by: Andy Churchard <[email protected]>
Co-authored-by: Cyclam <[email protected]>
Co-authored-by: William Bradley <[email protected]>
Co-authored-by: Xing Zhou <[email protected]>
  • Loading branch information
14 people committed Oct 24, 2023
1 parent e6c6870 commit 638f562
Show file tree
Hide file tree
Showing 142 changed files with 53,482 additions and 0 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ignore =
C901 # code flow is too complex, too many violations, to be removed in the future
W503 # line break before binary operator effect on readability is subjective
W504 # line break after binary operator effect on readability is subjective

exclude =
*/vendored_sdks
docs
Expand Down
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@

/src/alb/ @jaishals

/src/aosm/ @sunnycarter

/src/managedccfs/ @msftsettiy

/src/acrquery/ @CarolineNB
Expand Down
10 changes: 10 additions & 0 deletions src/aosm/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. :changelog:
Release History
===============

1.0.0b1
++++++++
* Initial release - beta quality
* `az aosm nfd|nsd generate-config` to generate an example config file to fill in for an NFD or NSD
* `az aosm nfd|nsd build|publish|delete` to prepare files for, publish or delete an NFD or NSD
203 changes: 203 additions & 0 deletions src/aosm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
# Microsoft Azure CLI 'aosm' Extension

This package is for the 'aosm' extension to support Azure Operator Service Manager
functions.
i.e. `az aosm`

## Background

The `az aosm` extension is intended to provide support for working with AOSM
resources and definitions. Currently it only implements commands which aid the
process of publishing Network Function Definitions and Network Service Designs to
use with Azure Operator Service Manager or Network Function Manager.

## Installation

`az extension add --name aosm`

For CNFs you will also need helm, and possibly docker installed. See [CNFs](#cnfs) below for details.

# nfd and nsd commands

These commands help with the publishing of Network Function Definition and Network
Service Design resources.

## Overview of function
A generic workflow of using the tool would be:
- Find the pre-requisite items you require for your use-case
- Run a `generate-config` command to output an example JSON config file for subsequent commands
- Fill in the config file
- Run a `build` command to output one or more bicep templates for your Network Function Definition or Network Service Design
- Review the output of the build command, edit the output as necessary for your requirements
- Run a `publish` command to:
* Create all pre-requisite resources such as Resource Group, Publisher, Artifact Stores, Groups
* Deploy those bicep templates
* Upload artifacts to the artifact stores

### Pre-requisites

#### VNFs

For VNFs, you will need a single ARM template which would create the Azure resources
for your VNF, for example a Virtual Machine, disks and NICs. You'll also need a VHD
image that would be used for the VNF Virtual Machine.

#### CNFs

For CNFs you must have these packages installed on the machine you are running the CLI from:
- `helm` package installed . Instructions on how to do this can be found [here](https://helm.sh/docs/intro/install/).
- `docker` installed only in some circumstances, those being if the source image is in your local docker repository, or you do not have subscription-wide permissions required to push charts and images. See the remainder of this section for further details. Docker provides packages that easily configure docker on [Windows](https://docs.docker.com/docker-for-windows/), or [Linux](https://docs.docker.com/engine/install/#supported-platforms) systems.

For CNFs, you must provide:
* helm packages with an associated schema. These files must be on your disk and will be referenced in the `input.json` config file.
* images for your CNF. For these you have the following options:
- a reference to an existing Azure Container Registry which contains the images for your CNF. Currently, only one ACR and namespace is supported per CNF. The images to be copied from this ACR are populated automatically based on the helm package schema. You must have Reader/AcrPull permissions on this ACR. To use this option, fill in `source_registry` and optionally `source_registry_namespace` in the input.json file.
- or, the image name of the source docker image from local machine. This is for a limited use case where the CNF only requires a single docker image which exists in the local docker repository. To use this option, fill in `source_local_docker_image` in the input.json file. This requires docker to be installed.
* optionally, you can provide a file (on disk) path_to_mappings which is a copy of values.yaml with your chosen values replaced by deployment parameters, thus exposing them as parameters to the CNF. You can get this file auto-generated by leaving the value as a blank string, either having every value as a deployment parameter, or using `--interactive` to interactively choose.
When filling in the input.json file, you must list helm packages in the order they are to be deployed. For example, if A must be deployed before B, your input.json should look something like this:

"helm_packages": [
{
"name": "A",
"path_to_chart": "Path to package A",
"path_to_mappings": "Path to package A mappings",
"depends_on": [
"Names of the Helm packages this package depends on"
]
},
{
"name": "B",
"path_to_chart": "Path to package B",
"path_to_mappings": "Path to package B mappings",
"depends_on": [
"Names of the Helm packages this package depends on"
]
},

##### Permissions for publishing CNFs
If sourcing the CNF images from an existing ACR, you need to have `Reader`/`AcrPull` permissions
from this ACR, and ideally, `Contributor` role + `AcrPush` role (or a custom role that allows the `importImage` action and `AcrPush`) over the whole subscription in order to be able to import to the new Artifact store. If you have these, you
do not need docker to be installed locally, and the image copy is very quick.

If you do not have the subscription-wide permissions then you can run the `az aosm nfd publish` command using the `--no-subscription-permissions` flag to pull the image to your local machine and then push it to the Artifact Store using manifest credentials scoped only to the store. This requires docker to be installed locally.

#### NSDs
For NSDs, you will need to have a Resource Group with a deployed Publisher, Artifact Store, Network Function Definition and Network Function Definition Version. You can use the `az aosm nfd` commands to create all of these resources.


### Command examples

#### Before you start
`az login` to login to the Azure CLI.
`az account set --subscription <subscription>` to choose the subscription you will work on.

#### NFDs

Get help on command arguments

`az aosm -h`
`az aosm nfd -h`
`az aosm nfd build -h`
etc...

All these commands take a `--definition-type` argument of `vnf` or `cnf`

Create an example config file for building a definition

`az aosm nfd generate-config`

This will output a file called `input.json` which must be filled in.
Once the config file has been filled in the following commands can be run.

Build an nfd definition locally

`az aosm nfd build --config-file input.json`

More options on building an nfd definition locally:

Choose which of the VNF ARM template parameters you want to expose as NFD deploymentParameters, with the option of interactively choosing each one.

`az aosm nfd build --config-file input.json --definition_type vnf --order_params`
`az aosm nfd build --config-file input.json --definition_type vnf --order_params --interactive`

Choose which of the CNF Helm values parameters you want to expose as NFD deploymentParameters.

`az aosm nfd build --config-file input.json --definition_type cnf [--interactive]`

Publish a pre-built definition

`az aosm nfd publish --config-file input.json`

Delete a published definition

`az aosm nfd delete --config-file input.json`

Delete a published definition and the publisher, artifact stores and NFD group

`az aosm nfd delete --config-file input.json --clean`

#### NSDs

Get help on command arguments

`az aosm -h`
`az aosm nsd -h`
`az aosm nsd build -h`
etc...

Create an example config file for building a definition

`az aosm nsd generate-config`

This will output a file called `input.json` which must be filled in.
Once the config file has been filled in the following commands can be run.

Build an nsd locally

`az aosm nsd build --config-file input.json`

Publish a pre-built design

`az aosm nsd publish --config-file input.json`

Delete a published design

`az aosm nsd delete --config-file input.json`

Delete a published design and the publisher, artifact stores and NSD group

`az aosm nsd delete --config-file input.json --clean`

## Bug Reporting

It would be much appreciated if you could report these so that we're aware of them!

Please see [Logging](#logging) for how to view and collect logs.

Please describe what you are doing and if possible provide the input and output files.

The (Microsoft internal) process for bug reporting during development is here:
https://eng.ms/docs/strategic-missions-and-technologies/strategic-missions-and-technologies-organization/azure-for-operators/aiops/aiops-orchestration/aosm-product-docs/processes/bug_process

CLI issues should be tagged and triaged as UX bugs.

## Logging

The CLI uses the standard Azure CLI logging mechanism. To enable logging to the console, you can use the following flags depending on the desired level of logging:
- `--verbose` - This flag changes the logging level to Info and above.
- `--debug` - This flag changes the logging level to Debug and above.
- `--only-show-errors` - This flag changes the logging level to Error only, suppressing Warning.

It is also possible to enable logging to file by running the following command:
```
az config set logging.enable_log_file=true
```
This will create a log file in the `~/.azure/logs` directory.

**Note:** The above command will enable logging for all Azure CLI commands until the logging is disabled again by the user. Not disabling file logging could slow down the performance of the CLI. To disable file logging, run the following command:
```
az config set logging.enable_log_file=false
```

## Development
Information about setting up and maintaining a development environment for this extension can be found [here](./development.md).
30 changes: 30 additions & 0 deletions src/aosm/azext_aosm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader

from azext_aosm._help import helps # pylint: disable=unused-import


class AosmCommandsLoader(AzCommandsLoader):
def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType

aosm_custom = CliCommandType(operations_tmpl="azext_aosm.custom#{}")
super().__init__(cli_ctx=cli_ctx, custom_command_type=aosm_custom)

def load_command_table(self, args):
from azext_aosm.commands import load_command_table

load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_aosm._params import load_arguments

load_arguments(self, command)


COMMAND_LOADER_CLS = AosmCommandsLoader
42 changes: 42 additions & 0 deletions src/aosm/azext_aosm/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core.profiles import ResourceType
from azure.mgmt.containerregistry import ContainerRegistryManagementClient

from .vendored_sdks import HybridNetworkManagementClient


def cf_aosm(cli_ctx, *_) -> HybridNetworkManagementClient:
# By default, get_mgmt_service_client() sets a parameter called 'base_url' when creating
# the client. For us, doing so results in a key error. Setting base_url_bound=False prevents
# that from happening
return get_mgmt_service_client(cli_ctx, HybridNetworkManagementClient, base_url_bound=False)


def cf_resources(cli_ctx, subscription_id=None):
return get_mgmt_service_client(
cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id
)


def cf_features(cli_ctx, subscription_id=None):
"""Return the client for checking feature enablement."""
return get_mgmt_service_client(
cli_ctx, ResourceType.MGMT_RESOURCE_FEATURES, subscription_id=subscription_id
)


def cf_acr_registries(cli_ctx, *_) -> ContainerRegistryManagementClient:
"""
Returns the client for managing container registries.
:param cli_ctx: CLI context
:return: ContainerRegistryManagementClient object
"""
return get_mgmt_service_client(
cli_ctx, ResourceType.MGMT_CONTAINERREGISTRY
).registries
Loading

0 comments on commit 638f562

Please sign in to comment.