Skip to content

Commit

Permalink
[Automanage] PLR release (#5404)
Browse files Browse the repository at this point in the history
* automanage init

* start tests

* test

* add empty --configuration to automanage configuration-profile create

* add configuration-profile tests, test for version is N/A because of server issue

* rerun tests

* configuration as dict of strings

* configuration profile assignment for vm

* configuration profile assignment for arc, test failing

* freeformdict for configuration

* lint

* run arc test(needed role assignment)

* add cluster test

* split up assignment reports

* no longer flatten report response

* move report into each type of assignment

* fix arg len

* add test for assignment report

* rerun tests, lint

* vm create --generate-ssh-keys

* make test record-only

* make test record-only

* rerun aazdev and rerun test

* latest swagger and rerun test

* rerun azdev

* server errors all fixed.

* rerun all tests

* record only

* add examples

* remove test which relying on other extensions

* add readme example
  • Loading branch information
calvinhzy authored Jan 28, 2023
1 parent d3bc6dc commit 98d8c30
Show file tree
Hide file tree
Showing 83 changed files with 14,620 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,5 @@
/src/billing-benefits/ @gaoyp830 @rkapso @msft-adrianma @sornaks

/src/mobile-network/ @jsntcy

/src/automanage/ @calvinhzy
8 changes: 8 additions & 0 deletions src/automanage/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. :changelog:
Release History
===============

0.1.0
++++++
* Initial release.
39 changes: 39 additions & 0 deletions src/automanage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Azure CLI Automanage Extension #
This is an extension to Azure CLI to manage Automanage resources.

## How to use ##
# configuration-profile
Create a configuration-profile
`az automanage configuration-profile create -n {profile_name} -g {rg} --configuration {"Antimalware/Enable":false,"Backup/Enable":false,"VMInsights/Enable":true,"AzureSecurityCenter/Enable":true,"UpdateManagement/Enable":true,"ChangeTrackingAndInventory/Enable":true,"GuestConfiguration/Enable":true,"LogAnalytics/Enable":true,"BootDiagnostics/Enable":true}`

Show a configuration-profile
`az automanage configuration-profile show -n {profile_name} -g {rg}`

Update a configuration-profile
`az automanage configuration-profile update -n {profile_name} -g {rg} --configuration {"Antimalware/Enable":true,"VMInsights/Enable":false}`

List configuration-profiles
`az automanage configuration-profile list -g {rg}`

Delete a configuration-profile
`az automanage configuration-profile delete -n {profile_name} -g {rg}`

# configuration-profile-assignment
Create a configuration-profile-assignment for vm
`az automanage configuration-profile-assignment vm create -n default -g {rg} --vm-name {vm_name} --configuration-profile {profile_id}`

Show a configuration-profile-assignment for vm
`az automanage configuration-profile-assignment vm show -n default -g {rg} --vm-name {vm_name}`

Update a configuration-profile-assignment for vm
`az automanage configuration-profile-assignment vm update --n default -g {rg} --vm-name {vm_name} --configuration-profile {profile_id_2}`

Delete configuration-profile-assignment for vm
`az automanage configuration-profile-assignment vm delete -n default -g {rg} --vm-name {vm_name}`

Create a configuration-profile-assignment for arc
`az automanage configuration-profile-assignment arc create -n default -g {rg} --machine-name {arc_name} --configuration-profile {profile_id}`

# configuration-profile-assignment report
List configuration-profile-assignment report for vm
`az automanage configuration-profile-assignment vm report list --assignment-name default -g {rg} --vm-name {vm_name}`
42 changes: 42 additions & 0 deletions src/automanage/azext_automanage/__init__.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.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from azext_automanage._help import helps # pylint: disable=unused-import


class AutomanageCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
custom_command_type = CliCommandType(
operations_tmpl='azext_automanage.custom#{}')
super().__init__(cli_ctx=cli_ctx,
custom_command_type=custom_command_type)

def load_command_table(self, args):
from azext_automanage.commands import load_command_table
from azure.cli.core.aaz import load_aaz_command_table
try:
from . import aaz
except ImportError:
aaz = None
if aaz:
load_aaz_command_table(
loader=self,
aaz_pkg_name=aaz.__name__,
args=args
)
load_command_table(self, args)
return self.command_table

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


COMMAND_LOADER_CLS = AutomanageCommandsLoader
11 changes: 11 additions & 0 deletions src/automanage/azext_automanage/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: disable=line-too-long
# pylint: disable=too-many-lines

from knack.help_files import helps # pylint: disable=unused-import
13 changes: 13 additions & 0 deletions src/automanage/azext_automanage/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: disable=too-many-lines
# pylint: disable=too-many-statements


def load_arguments(self, _): # pylint: disable=unused-argument
pass
6 changes: 6 additions & 0 deletions src/automanage/azext_automanage/aaz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------
6 changes: 6 additions & 0 deletions src/automanage/azext_automanage/aaz/latest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"automanage",
)
class __CMDGroup(AAZCommandGroup):
"""Manage Automanage
"""
pass


__all__ = ["__CMDGroup"]
11 changes: 11 additions & 0 deletions src/automanage/azext_automanage/aaz/latest/automanage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command_group(
"automanage best-practice",
)
class __CMDGroup(AAZCommandGroup):
"""Manage Automanage best practice
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from .__cmd_group import *
from ._list import *
from ._show import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
#
# Code generated by aaz-dev-tools
# --------------------------------------------------------------------------------------------

# pylint: skip-file
# flake8: noqa

from azure.cli.core.aaz import *


@register_command(
"automanage best-practice list",
)
class List(AAZCommand):
"""List Automanage best practices
:example: List best practices
az automanage best-practice list
"""

_aaz_info = {
"version": "2022-05-04",
"resources": [
["mgmt-plane", "/providers/microsoft.automanage/bestpractices", "2022-05-04"],
]
}

def _handler(self, command_args):
super()._handler(command_args)
self._execute_operations()
return self._output()

def _execute_operations(self):
self.pre_operations()
self.BestPracticesListByTenant(ctx=self.ctx)()
self.post_operations()

@register_callback
def pre_operations(self):
pass

@register_callback
def post_operations(self):
pass

def _output(self, *args, **kwargs):
result = self.deserialize_output(self.ctx.vars.instance.value, client_flatten=True)
return result

class BestPracticesListByTenant(AAZHttpOperation):
CLIENT_TYPE = "MgmtClient"

def __call__(self, *args, **kwargs):
request = self.make_request()
session = self.client.send_request(request=request, stream=False, **kwargs)
if session.http_response.status_code in [200]:
return self.on_200(session)

return self.on_error(session.http_response)

@property
def url(self):
return self.client.format_url(
"/providers/Microsoft.Automanage/bestPractices",
**self.url_parameters
)

@property
def method(self):
return "GET"

@property
def error_format(self):
return "MgmtErrorFormat"

@property
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2022-05-04",
required=True,
),
}
return parameters

@property
def header_parameters(self):
parameters = {
**self.serialize_header_param(
"Accept", "application/json",
),
}
return parameters

def on_200(self, session):
data = self.deserialize_http_content(session)
self.ctx.set_var(
"instance",
data,
schema_builder=self._build_schema_on_200
)

_schema_on_200 = None

@classmethod
def _build_schema_on_200(cls):
if cls._schema_on_200 is not None:
return cls._schema_on_200

cls._schema_on_200 = AAZObjectType()

_schema_on_200 = cls._schema_on_200
_schema_on_200.value = AAZListType()

value = cls._schema_on_200.value
value.Element = AAZObjectType()

_element = cls._schema_on_200.value.Element
_element.id = AAZStrType(
flags={"read_only": True},
)
_element.name = AAZStrType(
flags={"read_only": True},
)
_element.properties = AAZObjectType()
_element.system_data = AAZObjectType(
serialized_name="systemData",
flags={"read_only": True},
)
_element.type = AAZStrType(
flags={"read_only": True},
)

properties = cls._schema_on_200.value.Element.properties
properties.configuration = AAZFreeFormDictType()

system_data = cls._schema_on_200.value.Element.system_data
system_data.created_at = AAZStrType(
serialized_name="createdAt",
)
system_data.created_by = AAZStrType(
serialized_name="createdBy",
)
system_data.created_by_type = AAZStrType(
serialized_name="createdByType",
)
system_data.last_modified_at = AAZStrType(
serialized_name="lastModifiedAt",
)
system_data.last_modified_by = AAZStrType(
serialized_name="lastModifiedBy",
)
system_data.last_modified_by_type = AAZStrType(
serialized_name="lastModifiedByType",
)

return cls._schema_on_200


class _ListHelper:
"""Helper class for List"""


__all__ = ["List"]
Loading

0 comments on commit 98d8c30

Please sign in to comment.