Skip to content

Commit

Permalink
[Cloudservice] az cloud-service: Add new command group os-family
Browse files Browse the repository at this point in the history
…to support managing os family (#7252)
  • Loading branch information
Jing-song committed Mar 13, 2024
1 parent 9a6b508 commit 420fffb
Show file tree
Hide file tree
Showing 22 changed files with 3,996 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/cloudservice/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Release History
===============

1.0.0
++++++
* `az cloud-service`: Add new command group `os-family` to support managing os family.
* `az cloud-service`: Add new command group `os-version` to support managing os version.
* `az cloud-service`: Add new command group `role-instance` to support managing role instance.
* `az cloud-service`: Add new command `reimage` to support reinstalling the instance.

0.2.0
++++++
* Improve user experience.
Expand Down
11 changes: 11 additions & 0 deletions src/cloudservice/azext_cloudservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def __init__(self, cli_ctx=None):

def load_command_table(self, args):
from azext_cloudservice.generated.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)
try:
from azext_cloudservice.manual.commands import load_command_table as load_command_table_manual
Expand Down
6 changes: 6 additions & 0 deletions src/cloudservice/azext_cloudservice/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
# --------------------------------------------------------------------------------------------
10 changes: 10 additions & 0 deletions src/cloudservice/azext_cloudservice/aaz/latest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# --------------------------------------------------------------------------------------------
# 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

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(
"cloud-service",
)
class __CMDGroup(AAZCommandGroup):
"""Manage cloud service
"""
pass


__all__ = ["__CMDGroup"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# --------------------------------------------------------------------------------------------
# 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 ._reimage import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# --------------------------------------------------------------------------------------------
# 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(
"cloud-service reimage",
)
class Reimage(AAZCommand):
"""Reimage asynchronous operation reinstalls the operating system on instances of web roles or worker roles.
:example: Cloud service reimage
az cloud-service reimage -g rg --cloud-service-name cloudservice --role-instances '[ContosoFrontend_IN_0]'
"""

_aaz_info = {
"version": "2022-09-04",
"resources": [
["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/cloudservices/{}/reimage", "2022-09-04"],
]
}

AZ_SUPPORT_NO_WAIT = True

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

_args_schema = None

@classmethod
def _build_arguments_schema(cls, *args, **kwargs):
if cls._args_schema is not None:
return cls._args_schema
cls._args_schema = super()._build_arguments_schema(*args, **kwargs)

# define Arg Group ""

_args_schema = cls._args_schema
_args_schema.cloud_service_name = AAZStrArg(
options=["--cloud-service-name"],
help="Name of the cloud service.",
required=True,
id_part="name",
)
_args_schema.resource_group = AAZResourceGroupNameArg(
required=True,
)

# define Arg Group "Parameters"

_args_schema = cls._args_schema
_args_schema.role_instances = AAZListArg(
options=["--role-instances"],
arg_group="Parameters",
help="List of cloud service role instance names. Value of '*' will signify all role instances of the cloud service.",
)

role_instances = cls._args_schema.role_instances
role_instances.Element = AAZStrArg()
return cls._args_schema

def _execute_operations(self):
self.pre_operations()
yield self.CloudServicesReimage(ctx=self.ctx)()
self.post_operations()

@register_callback
def pre_operations(self):
pass

@register_callback
def post_operations(self):
pass

class CloudServicesReimage(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 [202]:
return self.client.build_lro_polling(
self.ctx.args.no_wait,
session,
self.on_200,
self.on_error,
lro_options={"final-state-via": "azure-async-operation"},
path_format_arguments=self.url_parameters,
)
if session.http_response.status_code in [200]:
return self.client.build_lro_polling(
self.ctx.args.no_wait,
session,
self.on_200,
self.on_error,
lro_options={"final-state-via": "azure-async-operation"},
path_format_arguments=self.url_parameters,
)

return self.on_error(session.http_response)

@property
def url(self):
return self.client.format_url(
"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/cloudServices/{cloudServiceName}/reimage",
**self.url_parameters
)

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

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

@property
def url_parameters(self):
parameters = {
**self.serialize_url_param(
"cloudServiceName", self.ctx.args.cloud_service_name,
required=True,
),
**self.serialize_url_param(
"resourceGroupName", self.ctx.args.resource_group,
required=True,
),
**self.serialize_url_param(
"subscriptionId", self.ctx.subscription_id,
required=True,
),
}
return parameters

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

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

@property
def content(self):
_content_value, _builder = self.new_content_builder(
self.ctx.args,
typ=AAZObjectType,
typ_kwargs={"flags": {"client_flatten": True}}
)
_builder.set_prop("roleInstances", AAZListType, ".role_instances", typ_kwargs={"flags": {"required": True}})

role_instances = _builder.get(".roleInstances")
if role_instances is not None:
role_instances.set_elements(AAZStrType, ".")

return self.serialize_content(_content_value)

def on_200(self, session):
pass


class _ReimageHelper:
"""Helper class for Reimage"""


__all__ = ["Reimage"]
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(
"cloud-service os-family",
)
class __CMDGroup(AAZCommandGroup):
"""Manage cloud service os family
"""
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 *
Loading

0 comments on commit 420fffb

Please sign in to comment.