diff --git a/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py b/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py index ee6329e9129..e4a50738666 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py +++ b/src/azure-cli/azure/cli/command_modules/vm/_client_factory.py @@ -91,10 +91,6 @@ def cf_dedicated_hosts(cli_ctx, _): return _compute_client_factory(cli_ctx).dedicated_hosts -def cf_dedicated_host_groups(cli_ctx, _): - return _compute_client_factory(cli_ctx).dedicated_host_groups - - def _log_analytics_client_factory(cli_ctx, subscription_id, *_): from azure.mgmt.loganalytics import LogAnalyticsManagementClient from azure.cli.core.commands.client_factory import get_mgmt_service_client diff --git a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/__init__.py b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/__init__.py index 054d52707ea..efc3964e3fb 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/__init__.py +++ b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/__init__.py @@ -9,6 +9,7 @@ # flake8: noqa from .__cmd_group import * +from ._create import * from ._delete import * from ._list import * from ._show import * diff --git a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_create.py b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_create.py new file mode 100644 index 00000000000..2e17d36f12d --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_create.py @@ -0,0 +1,375 @@ +# -------------------------------------------------------------------------------------------- +# 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 * + + +class Create(AAZCommand): + """Create a dedicated host group. + + :example: Create a dedicated host group. + az vm host group create --name MyDedicatedHostGroup --platform-fault-domain-count 2 --resource-group MyResourceGroup + """ + + _aaz_info = { + "version": "2024-11-01", + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/hostgroups/{}", "2024-11-01"], + ] + } + + def _handler(self, command_args): + super()._handler(command_args) + self._execute_operations() + return self._output() + + _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.host_group_name = AAZStrArg( + options=["-n", "--name", "--host-group-name"], + help="Name of the Dedicated Host Group.", + required=True, + ) + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + + # define Arg Group "Parameters" + + _args_schema = cls._args_schema + _args_schema.location = AAZResourceLocationArg( + arg_group="Parameters", + help="Resource location", + required=True, + fmt=AAZResourceLocationArgFormat( + resource_group_arg="resource_group", + ), + ) + _args_schema.tags = AAZDictArg( + options=["--tags"], + arg_group="Parameters", + help="Resource tags", + ) + _args_schema.zones = AAZListArg( + options=["--zones"], + arg_group="Parameters", + help="Availability Zone to use for this host group. Only single zone is supported. The zone can be assigned only during creation. If not provided, the group supports all zones in the region. If provided, enforces each host in the group to be in the same zone.", + ) + + tags = cls._args_schema.tags + tags.Element = AAZStrArg() + + zones = cls._args_schema.zones + zones.Element = AAZStrArg() + + # define Arg Group "Properties" + + _args_schema = cls._args_schema + _args_schema.additional_capabilities = AAZObjectArg( + options=["--additional-capabilities"], + arg_group="Properties", + help="Enables or disables a capability on the dedicated host group. Minimum api-version: 2022-03-01.", + ) + _args_schema.platform_fault_domain_count = AAZIntArg( + options=["--platform-fault-domain-count"], + arg_group="Properties", + help="Number of fault domains that the host group can span.", + fmt=AAZIntArgFormat( + minimum=1, + ), + ) + _args_schema.support_automatic_placement = AAZBoolArg( + options=["--support-automatic-placement"], + arg_group="Properties", + help="Specifies whether virtual machines or virtual machine scale sets can be placed automatically on the dedicated host group. Automatic placement means resources are allocated on dedicated hosts, that are chosen by Azure, under the dedicated host group. The value is defaulted to 'false' when not provided. Minimum api-version: 2020-06-01.", + ) + + additional_capabilities = cls._args_schema.additional_capabilities + additional_capabilities.ultra_ssd_enabled = AAZBoolArg( + options=["ultra-ssd-enabled"], + help="The flag that enables or disables a capability to have UltraSSD Enabled Virtual Machines on Dedicated Hosts of the Dedicated Host Group. For the Virtual Machines to be UltraSSD Enabled, UltraSSDEnabled flag for the resource needs to be set true as well. The value is defaulted to 'false' when not provided. Please refer to https://docs.microsoft.com/en-us/azure/virtual-machines/disks-enable-ultra-ssd for more details on Ultra SSD feature. **Note:** The ultraSSDEnabled setting can only be enabled for Host Groups that are created as zonal. Minimum api-version: 2022-03-01.", + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + self.DedicatedHostGroupsCreateOrUpdate(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, client_flatten=True) + return result + + class DedicatedHostGroupsCreateOrUpdate(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, 201]: + return self.on_200_201(session) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/hostGroups/{hostGroupName}", + **self.url_parameters + ) + + @property + def method(self): + return "PUT" + + @property + def error_format(self): + return "ODataV4Format" + + @property + def url_parameters(self): + parameters = { + **self.serialize_url_param( + "hostGroupName", self.ctx.args.host_group_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", "2024-11-01", + required=True, + ), + } + return parameters + + @property + def header_parameters(self): + parameters = { + **self.serialize_header_param( + "Content-Type", "application/json", + ), + **self.serialize_header_param( + "Accept", "application/json", + ), + } + return parameters + + @property + def content(self): + _content_value, _builder = self.new_content_builder( + self.ctx.args, + typ=AAZObjectType, + typ_kwargs={"flags": {"required": True, "client_flatten": True}} + ) + _builder.set_prop("location", AAZStrType, ".location", typ_kwargs={"flags": {"required": True}}) + _builder.set_prop("properties", AAZObjectType, typ_kwargs={"flags": {"client_flatten": True}}) + _builder.set_prop("tags", AAZDictType, ".tags") + _builder.set_prop("zones", AAZListType, ".zones") + + properties = _builder.get(".properties") + if properties is not None: + properties.set_prop("additionalCapabilities", AAZObjectType, ".additional_capabilities") + properties.set_prop("platformFaultDomainCount", AAZIntType, ".platform_fault_domain_count", typ_kwargs={"flags": {"required": True}}) + properties.set_prop("supportAutomaticPlacement", AAZBoolType, ".support_automatic_placement") + + additional_capabilities = _builder.get(".properties.additionalCapabilities") + if additional_capabilities is not None: + additional_capabilities.set_prop("ultraSSDEnabled", AAZBoolType, ".ultra_ssd_enabled") + + tags = _builder.get(".tags") + if tags is not None: + tags.set_elements(AAZStrType, ".") + + zones = _builder.get(".zones") + if zones is not None: + zones.set_elements(AAZStrType, ".") + + return self.serialize_content(_content_value) + + def on_200_201(self, session): + data = self.deserialize_http_content(session) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200_201 + ) + + _schema_on_200_201 = None + + @classmethod + def _build_schema_on_200_201(cls): + if cls._schema_on_200_201 is not None: + return cls._schema_on_200_201 + + cls._schema_on_200_201 = AAZObjectType() + + _schema_on_200_201 = cls._schema_on_200_201 + _schema_on_200_201.id = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200_201.location = AAZStrType( + flags={"required": True}, + ) + _schema_on_200_201.name = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200_201.properties = AAZObjectType( + flags={"client_flatten": True}, + ) + _schema_on_200_201.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + _schema_on_200_201.tags = AAZDictType() + _schema_on_200_201.type = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200_201.zones = AAZListType() + + properties = cls._schema_on_200_201.properties + properties.additional_capabilities = AAZObjectType( + serialized_name="additionalCapabilities", + ) + properties.hosts = AAZListType( + flags={"read_only": True}, + ) + properties.instance_view = AAZObjectType( + serialized_name="instanceView", + flags={"read_only": True}, + ) + properties.platform_fault_domain_count = AAZIntType( + serialized_name="platformFaultDomainCount", + flags={"required": True}, + ) + properties.support_automatic_placement = AAZBoolType( + serialized_name="supportAutomaticPlacement", + ) + + additional_capabilities = cls._schema_on_200_201.properties.additional_capabilities + additional_capabilities.ultra_ssd_enabled = AAZBoolType( + serialized_name="ultraSSDEnabled", + ) + + hosts = cls._schema_on_200_201.properties.hosts + hosts.Element = AAZObjectType() + + _element = cls._schema_on_200_201.properties.hosts.Element + _element.id = AAZStrType( + flags={"read_only": True}, + ) + + instance_view = cls._schema_on_200_201.properties.instance_view + instance_view.hosts = AAZListType() + + hosts = cls._schema_on_200_201.properties.instance_view.hosts + hosts.Element = AAZObjectType() + + _element = cls._schema_on_200_201.properties.instance_view.hosts.Element + _element.asset_id = AAZStrType( + serialized_name="assetId", + flags={"read_only": True}, + ) + _element.available_capacity = AAZObjectType( + serialized_name="availableCapacity", + ) + _element.name = AAZStrType( + flags={"read_only": True}, + ) + _element.statuses = AAZListType() + + available_capacity = cls._schema_on_200_201.properties.instance_view.hosts.Element.available_capacity + available_capacity.allocatable_v_ms = AAZListType( + serialized_name="allocatableVMs", + ) + + allocatable_v_ms = cls._schema_on_200_201.properties.instance_view.hosts.Element.available_capacity.allocatable_v_ms + allocatable_v_ms.Element = AAZObjectType() + + _element = cls._schema_on_200_201.properties.instance_view.hosts.Element.available_capacity.allocatable_v_ms.Element + _element.count = AAZFloatType() + _element.vm_size = AAZStrType( + serialized_name="vmSize", + ) + + statuses = cls._schema_on_200_201.properties.instance_view.hosts.Element.statuses + statuses.Element = AAZObjectType() + + _element = cls._schema_on_200_201.properties.instance_view.hosts.Element.statuses.Element + _element.code = AAZStrType() + _element.display_status = AAZStrType( + serialized_name="displayStatus", + ) + _element.level = AAZStrType() + _element.message = AAZStrType() + _element.time = AAZStrType() + + system_data = cls._schema_on_200_201.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", + ) + + tags = cls._schema_on_200_201.tags + tags.Element = AAZStrType() + + zones = cls._schema_on_200_201.zones + zones.Element = AAZStrType() + + return cls._schema_on_200_201 + + +class _CreateHelper: + """Helper class for Create""" + + +__all__ = ["Create"] diff --git a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_delete.py b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_delete.py index 72e0d5ab55b..70df2c491e6 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_delete.py +++ b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_delete.py @@ -20,9 +20,9 @@ class Delete(AAZCommand): """ _aaz_info = { - "version": "2019-03-01", + "version": "2024-11-01", "resources": [ - ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/hostgroups/{}", "2019-03-01"], + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/hostgroups/{}", "2024-11-01"], ] } @@ -49,7 +49,6 @@ def _build_arguments_schema(cls, *args, **kwargs): id_part="name", ) _args_schema.resource_group = AAZResourceGroupNameArg( - help="Name of resource group. You can configure the default group using `az configure --defaults group=`.", required=True, ) return cls._args_schema @@ -117,7 +116,7 @@ def url_parameters(self): def query_parameters(self): parameters = { **self.serialize_query_param( - "api-version", "2019-03-01", + "api-version", "2024-11-01", required=True, ), } diff --git a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_list.py b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_list.py index c8f35a2f544..9e50f9e3d88 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_list.py +++ b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_list.py @@ -21,10 +21,10 @@ class List(AAZCommand): """ _aaz_info = { - "version": "2019-03-01", + "version": "2024-11-01", "resources": [ - ["mgmt-plane", "/subscriptions/{}/providers/microsoft.compute/hostgroups", "2019-03-01"], - ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/hostgroups", "2019-03-01"], + ["mgmt-plane", "/subscriptions/{}/providers/microsoft.compute/hostgroups", "2024-11-01"], + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/hostgroups", "2024-11-01"], ] } @@ -45,9 +45,7 @@ def _build_arguments_schema(cls, *args, **kwargs): # define Arg Group "" _args_schema = cls._args_schema - _args_schema.resource_group = AAZResourceGroupNameArg( - help="Name of resource group. You can configure the default group using `az configure --defaults group=`.", - ) + _args_schema.resource_group = AAZResourceGroupNameArg() return cls._args_schema def _execute_operations(self): @@ -117,7 +115,7 @@ def url_parameters(self): def query_parameters(self): parameters = { **self.serialize_query_param( - "api-version", "2019-03-01", + "api-version", "2024-11-01", required=True, ), } @@ -173,6 +171,10 @@ def _build_schema_on_200(cls): _element.properties = AAZObjectType( flags={"client_flatten": True}, ) + _element.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) _element.tags = AAZDictType() _element.type = AAZStrType( flags={"read_only": True}, @@ -180,13 +182,28 @@ def _build_schema_on_200(cls): _element.zones = AAZListType() properties = cls._schema_on_200.value.Element.properties + properties.additional_capabilities = AAZObjectType( + serialized_name="additionalCapabilities", + ) properties.hosts = AAZListType( flags={"read_only": True}, ) + properties.instance_view = AAZObjectType( + serialized_name="instanceView", + flags={"read_only": True}, + ) properties.platform_fault_domain_count = AAZIntType( serialized_name="platformFaultDomainCount", flags={"required": True}, ) + properties.support_automatic_placement = AAZBoolType( + serialized_name="supportAutomaticPlacement", + ) + + additional_capabilities = cls._schema_on_200.value.Element.properties.additional_capabilities + additional_capabilities.ultra_ssd_enabled = AAZBoolType( + serialized_name="ultraSSDEnabled", + ) hosts = cls._schema_on_200.value.Element.properties.hosts hosts.Element = AAZObjectType() @@ -196,6 +213,71 @@ def _build_schema_on_200(cls): flags={"read_only": True}, ) + instance_view = cls._schema_on_200.value.Element.properties.instance_view + instance_view.hosts = AAZListType() + + hosts = cls._schema_on_200.value.Element.properties.instance_view.hosts + hosts.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element + _element.asset_id = AAZStrType( + serialized_name="assetId", + flags={"read_only": True}, + ) + _element.available_capacity = AAZObjectType( + serialized_name="availableCapacity", + ) + _element.name = AAZStrType( + flags={"read_only": True}, + ) + _element.statuses = AAZListType() + + available_capacity = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element.available_capacity + available_capacity.allocatable_v_ms = AAZListType( + serialized_name="allocatableVMs", + ) + + allocatable_v_ms = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element.available_capacity.allocatable_v_ms + allocatable_v_ms.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element.available_capacity.allocatable_v_ms.Element + _element.count = AAZFloatType() + _element.vm_size = AAZStrType( + serialized_name="vmSize", + ) + + statuses = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element.statuses + statuses.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element.statuses.Element + _element.code = AAZStrType() + _element.display_status = AAZStrType( + serialized_name="displayStatus", + ) + _element.level = AAZStrType() + _element.message = AAZStrType() + _element.time = AAZStrType() + + 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", + ) + tags = cls._schema_on_200.value.Element.tags tags.Element = AAZStrType() @@ -244,7 +326,7 @@ def url_parameters(self): def query_parameters(self): parameters = { **self.serialize_query_param( - "api-version", "2019-03-01", + "api-version", "2024-11-01", required=True, ), } @@ -300,6 +382,10 @@ def _build_schema_on_200(cls): _element.properties = AAZObjectType( flags={"client_flatten": True}, ) + _element.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) _element.tags = AAZDictType() _element.type = AAZStrType( flags={"read_only": True}, @@ -307,13 +393,28 @@ def _build_schema_on_200(cls): _element.zones = AAZListType() properties = cls._schema_on_200.value.Element.properties + properties.additional_capabilities = AAZObjectType( + serialized_name="additionalCapabilities", + ) properties.hosts = AAZListType( flags={"read_only": True}, ) + properties.instance_view = AAZObjectType( + serialized_name="instanceView", + flags={"read_only": True}, + ) properties.platform_fault_domain_count = AAZIntType( serialized_name="platformFaultDomainCount", flags={"required": True}, ) + properties.support_automatic_placement = AAZBoolType( + serialized_name="supportAutomaticPlacement", + ) + + additional_capabilities = cls._schema_on_200.value.Element.properties.additional_capabilities + additional_capabilities.ultra_ssd_enabled = AAZBoolType( + serialized_name="ultraSSDEnabled", + ) hosts = cls._schema_on_200.value.Element.properties.hosts hosts.Element = AAZObjectType() @@ -323,6 +424,71 @@ def _build_schema_on_200(cls): flags={"read_only": True}, ) + instance_view = cls._schema_on_200.value.Element.properties.instance_view + instance_view.hosts = AAZListType() + + hosts = cls._schema_on_200.value.Element.properties.instance_view.hosts + hosts.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element + _element.asset_id = AAZStrType( + serialized_name="assetId", + flags={"read_only": True}, + ) + _element.available_capacity = AAZObjectType( + serialized_name="availableCapacity", + ) + _element.name = AAZStrType( + flags={"read_only": True}, + ) + _element.statuses = AAZListType() + + available_capacity = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element.available_capacity + available_capacity.allocatable_v_ms = AAZListType( + serialized_name="allocatableVMs", + ) + + allocatable_v_ms = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element.available_capacity.allocatable_v_ms + allocatable_v_ms.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element.available_capacity.allocatable_v_ms.Element + _element.count = AAZFloatType() + _element.vm_size = AAZStrType( + serialized_name="vmSize", + ) + + statuses = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element.statuses + statuses.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element.properties.instance_view.hosts.Element.statuses.Element + _element.code = AAZStrType() + _element.display_status = AAZStrType( + serialized_name="displayStatus", + ) + _element.level = AAZStrType() + _element.message = AAZStrType() + _element.time = AAZStrType() + + 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", + ) + tags = cls._schema_on_200.value.Element.tags tags.Element = AAZStrType() diff --git a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_show.py b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_show.py index e4f0226d157..052c5941d99 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_show.py +++ b/src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vm/host/group/_show.py @@ -22,9 +22,9 @@ class Show(AAZCommand): """ _aaz_info = { - "version": "2019-03-01", + "version": "2024-11-01", "resources": [ - ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/hostgroups/{}", "2019-03-01"], + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/hostgroups/{}", "2024-11-01"], ] } @@ -51,9 +51,13 @@ def _build_arguments_schema(cls, *args, **kwargs): id_part="name", ) _args_schema.resource_group = AAZResourceGroupNameArg( - help="Name of resource group. You can configure the default group using `az configure --defaults group=`.", required=True, ) + _args_schema.expand = AAZStrArg( + options=["--expand"], + help="The expand expression to apply on the operation. 'InstanceView' will retrieve the list of instance views of the dedicated hosts under the dedicated host group. 'UserData' is not supported for dedicated host group.", + enum={"instanceView": "instanceView", "resiliencyView": "resiliencyView", "userData": "userData"}, + ) return cls._args_schema def _execute_operations(self): @@ -121,7 +125,10 @@ def url_parameters(self): def query_parameters(self): parameters = { **self.serialize_query_param( - "api-version", "2019-03-01", + "$expand", self.ctx.args.expand, + ), + **self.serialize_query_param( + "api-version", "2024-11-01", required=True, ), } @@ -166,6 +173,10 @@ def _build_schema_on_200(cls): _schema_on_200.properties = AAZObjectType( flags={"client_flatten": True}, ) + _schema_on_200.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) _schema_on_200.tags = AAZDictType() _schema_on_200.type = AAZStrType( flags={"read_only": True}, @@ -173,13 +184,28 @@ def _build_schema_on_200(cls): _schema_on_200.zones = AAZListType() properties = cls._schema_on_200.properties + properties.additional_capabilities = AAZObjectType( + serialized_name="additionalCapabilities", + ) properties.hosts = AAZListType( flags={"read_only": True}, ) + properties.instance_view = AAZObjectType( + serialized_name="instanceView", + flags={"read_only": True}, + ) properties.platform_fault_domain_count = AAZIntType( serialized_name="platformFaultDomainCount", flags={"required": True}, ) + properties.support_automatic_placement = AAZBoolType( + serialized_name="supportAutomaticPlacement", + ) + + additional_capabilities = cls._schema_on_200.properties.additional_capabilities + additional_capabilities.ultra_ssd_enabled = AAZBoolType( + serialized_name="ultraSSDEnabled", + ) hosts = cls._schema_on_200.properties.hosts hosts.Element = AAZObjectType() @@ -189,6 +215,71 @@ def _build_schema_on_200(cls): flags={"read_only": True}, ) + instance_view = cls._schema_on_200.properties.instance_view + instance_view.hosts = AAZListType() + + hosts = cls._schema_on_200.properties.instance_view.hosts + hosts.Element = AAZObjectType() + + _element = cls._schema_on_200.properties.instance_view.hosts.Element + _element.asset_id = AAZStrType( + serialized_name="assetId", + flags={"read_only": True}, + ) + _element.available_capacity = AAZObjectType( + serialized_name="availableCapacity", + ) + _element.name = AAZStrType( + flags={"read_only": True}, + ) + _element.statuses = AAZListType() + + available_capacity = cls._schema_on_200.properties.instance_view.hosts.Element.available_capacity + available_capacity.allocatable_v_ms = AAZListType( + serialized_name="allocatableVMs", + ) + + allocatable_v_ms = cls._schema_on_200.properties.instance_view.hosts.Element.available_capacity.allocatable_v_ms + allocatable_v_ms.Element = AAZObjectType() + + _element = cls._schema_on_200.properties.instance_view.hosts.Element.available_capacity.allocatable_v_ms.Element + _element.count = AAZFloatType() + _element.vm_size = AAZStrType( + serialized_name="vmSize", + ) + + statuses = cls._schema_on_200.properties.instance_view.hosts.Element.statuses + statuses.Element = AAZObjectType() + + _element = cls._schema_on_200.properties.instance_view.hosts.Element.statuses.Element + _element.code = AAZStrType() + _element.display_status = AAZStrType( + serialized_name="displayStatus", + ) + _element.level = AAZStrType() + _element.message = AAZStrType() + _element.time = AAZStrType() + + system_data = cls._schema_on_200.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", + ) + tags = cls._schema_on_200.tags tags.Element = AAZStrType() diff --git a/src/azure-cli/azure/cli/command_modules/vm/commands.py b/src/azure-cli/azure/cli/command_modules/vm/commands.py index 51c50586daf..80d0065febd 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/commands.py @@ -9,7 +9,7 @@ cf_vmss, cf_images, cf_galleries, cf_gallery_images, cf_gallery_image_versions, cf_proximity_placement_groups, - cf_dedicated_hosts, cf_dedicated_host_groups, + cf_dedicated_hosts, cf_log_analytics_data_plane, cf_capacity_reservation_groups, cf_capacity_reservations, cf_community_gallery) @@ -143,11 +143,6 @@ def load_command_table(self, _): client_factory=cf_dedicated_hosts, ) - compute_dedicated_host_groups_sdk = CliCommandType( - operations_tmpl="azure.mgmt.compute.operations#DedicatedHostGroupsOperations.{}", - client_factory=cf_dedicated_host_groups, - ) - image_builder_image_templates_sdk = CliCommandType( operations_tmpl="azure.mgmt.imagebuilder.operations#VirtualMachineImageTemplatesOperations.{}", client_factory=cf_img_bldr_image_templates, @@ -392,11 +387,13 @@ def load_command_table(self, _): g.custom_command('create', 'create_dedicated_host') g.generic_update_command('update', setter_name='begin_create_or_update') - with self.command_group('vm host group', compute_dedicated_host_groups_sdk, client_factory=cf_dedicated_host_groups, - min_api='2019-03-01') as g: - g.custom_command('get-instance-view', 'get_dedicated_host_group_instance_view', min_api='2020-06-01') + with self.command_group('vm host group') as g: + g.custom_command('get-instance-view', 'get_dedicated_host_group_instance_view') g.custom_command('create', 'create_dedicated_host_group') - g.generic_update_command('update') + g.generic_update_command('update', getter_name='get_dedicated_host_group', setter_arg_name='dedicated_host_group', setter_name='update_dedicated_host_group', setter_type=compute_custom, command_type=compute_custom) + + from .operations.vm_host_group import VMHostGroupShow + self.command_table['vm host group show'] = VMHostGroupShow(loader=self) with self.command_group('vmss') as g: g.custom_command('identity assign', 'assign_vmss_identity', validator=process_assign_identity_namespace) diff --git a/src/azure-cli/azure/cli/command_modules/vm/custom.py b/src/azure-cli/azure/cli/command_modules/vm/custom.py index 5380bfeef8f..828b839dcbc 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/custom.py +++ b/src/azure-cli/azure/cli/command_modules/vm/custom.py @@ -5906,22 +5906,57 @@ def update_image_version(cmd, resource_group_name, gallery_name, gallery_image_n # region dedicated host -def create_dedicated_host_group(cmd, client, host_group_name, resource_group_name, platform_fault_domain_count, +def create_dedicated_host_group(cmd, host_group_name, resource_group_name, platform_fault_domain_count, automatic_placement=None, location=None, zones=None, tags=None, ultra_ssd_enabled=None): - DedicatedHostGroup = cmd.get_models('DedicatedHostGroup') + from .aaz.latest.vm.host.group import Create as VmHostGroupCreate location = location or _get_resource_group_location(cmd.cli_ctx, resource_group_name) + command_args = { + 'host_group_name': host_group_name, + 'resource_group': resource_group_name, + 'location': location, + 'platform_fault_domain_count': platform_fault_domain_count + } + + if tags is not None: + command_args['tags'] = tags or {} + + if zones is not None: + command_args['zones'] = zones or [] - host_group_params = DedicatedHostGroup(location=location, platform_fault_domain_count=platform_fault_domain_count, - support_automatic_placement=automatic_placement, zones=zones, tags=tags) if ultra_ssd_enabled is not None: - additionalCapabilities = {'ultraSSDEnabled': ultra_ssd_enabled} - host_group_params.additional_capabilities = additionalCapabilities + command_args['additional_capabilities'] = { + 'ultra_ssd_enabled': ultra_ssd_enabled + } + + if automatic_placement is not None: + command_args['support_automatic_placement'] = automatic_placement - return client.create_or_update(resource_group_name, host_group_name, parameters=host_group_params) + return VmHostGroupCreate(cli_ctx=cmd.cli_ctx)(command_args=command_args) -def get_dedicated_host_group_instance_view(client, host_group_name, resource_group_name): - return client.get(resource_group_name, host_group_name, expand="instanceView") +def get_dedicated_host_group_instance_view(cmd, host_group_name, resource_group_name): + return get_dedicated_host_group(cmd, host_group_name, resource_group_name, 'instanceView') + + +def get_dedicated_host_group(cmd, host_group_name, resource_group_name, expand=None): + from .operations.vm_host_group import VMHostGroupShow + command_args = { + 'host_group_name': host_group_name, + 'resource_group': resource_group_name, + } + if expand: + command_args['expand'] = expand + return VMHostGroupShow(cli_ctx=cmd.cli_ctx)(command_args=command_args) + + +def update_dedicated_host_group(cmd, host_group_name, resource_group_name, **kwargs): + from .aaz.latest.vm.host.group import Create as VmHostGroupCreate + from .operations.vm_host_group import convert_show_result_to_snake_case + vm_host_group = kwargs['dedicated_host_group'] + vm_host_group = convert_show_result_to_snake_case(vm_host_group) + vm_host_group['host_group_name'] = host_group_name + vm_host_group['resource_group'] = resource_group_name + return VmHostGroupCreate(cli_ctx=cmd.cli_ctx)(command_args=vm_host_group) def create_dedicated_host(cmd, client, host_group_name, host_name, resource_group_name, sku, platform_fault_domain=None, @@ -5941,7 +5976,6 @@ def create_dedicated_host(cmd, client, host_group_name, host_name, resource_grou def get_dedicated_host_instance_view(client, host_group_name, host_name, resource_group_name): return client.get(resource_group_name, host_group_name, host_name, expand="instanceView") - # endregion diff --git a/src/azure-cli/azure/cli/command_modules/vm/operations/vm_host_group.py b/src/azure-cli/azure/cli/command_modules/vm/operations/vm_host_group.py new file mode 100644 index 00000000000..4b7a47b41ae --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/vm/operations/vm_host_group.py @@ -0,0 +1,52 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +# pylint: disable=no-self-use, line-too-long, protected-access, too-few-public-methods, unused-argument +from knack.log import get_logger + +from ..aaz.latest.vm.host.group import Show as _VMHostGroupShow + +logger = get_logger(__name__) + + +class VMHostGroupShow(_VMHostGroupShow): + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + args_schema = super()._build_arguments_schema(*args, **kwargs) + + args_schema.expand._registered = False + + return args_schema + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) + if 'tags' not in result: + result['tags'] = {} + return result + + +def convert_show_result_to_snake_case(result): + new_result = {} + if 'location' in result: + new_result['location'] = result['location'] + + if 'tags' in result: + new_result['tags'] = result['tags'] + + if 'zones' in result: + new_result['zones'] = result['zones'] + + if 'additionalCapabilities' in result: + new_result['additional_capabilities'] = result['additionalCapabilities'] + + if new_result['additional_capabilities'].get('ultraSSDEnabled'): + new_result['additional_capabilities']['ultra_ssd_enabled'] = new_result['additional_capabilities']['ultraSSDEnabled'] + new_result['additional_capabilities'].pop('ultraSSDEnabled') + + if 'platformFaultDomainCount' in result: + new_result['platform_fault_domain_count'] = result['platformFaultDomainCount'] + + if 'supportAutomaticPlacement' in result: + new_result['support_automatic_placement'] = result['supportAutomaticPlacement'] + return new_result diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_dedicated_host_e2e.yaml b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_dedicated_host_e2e.yaml index 0cbdc555684..369b4dc17a0 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_dedicated_host_e2e.yaml +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_dedicated_host_e2e.yaml @@ -3769,7 +3769,7 @@ interactions: - AZURECLI/2.47.0 (AAZ) azsdk-python-core/1.24.0 Python/3.10.11 (Linux-5.15.0-1036-azure-x86_64-with-glibc2.31) VSTS_7b238909-6802-4b65-b90d-184bca47f458_build_220_0 method: GET - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dedicated_host_000001/providers/Microsoft.Compute/hostGroups/my-host-group?api-version=2019-03-01 + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dedicated_host_000001/providers/Microsoft.Compute/hostGroups/my-host-group?api-version=2024-11-01 response: body: string: "{\r\n \"name\": \"my-host-group\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/CLI_TEST_DEDICATED_HOST_IJYO5AOQ2IBWTIRNYZVXXGUB3E3A45FXIL4RSKVKBUO6D6I25M2/providers/Microsoft.Compute/hostGroups/my-host-group\",\r\n @@ -4084,7 +4084,7 @@ interactions: - AZURECLI/2.47.0 (AAZ) azsdk-python-core/1.24.0 Python/3.10.11 (Linux-5.15.0-1036-azure-x86_64-with-glibc2.31) VSTS_7b238909-6802-4b65-b90d-184bca47f458_build_220_0 method: DELETE - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dedicated_host_000001/providers/Microsoft.Compute/hostGroups/my-host-group?api-version=2019-03-01 + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_dedicated_host_000001/providers/Microsoft.Compute/hostGroups/my-host-group?api-version=2024-11-01 response: body: string: '' diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_host_management.yaml b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_host_management.yaml index ce35f1bea97..a2e13d8e33b 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_host_management.yaml +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_host_management.yaml @@ -114,7 +114,7 @@ interactions: - AZURECLI/2.47.0 (AAZ) azsdk-python-core/1.24.0 Python/3.10.11 (Linux-5.15.0-1036-azure-x86_64-with-glibc2.31) VSTS_7b238909-6802-4b65-b90d-184bca47f458_build_220_0 method: GET - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_host_management_000001/providers/Microsoft.Compute/hostGroups?api-version=2019-03-01 + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_host_management_000001/providers/Microsoft.Compute/hostGroups?api-version=2024-11-01 response: body: string: "{\r\n \"value\": [\r\n {\r\n \"name\": \"my-host-group\",\r\n @@ -893,7 +893,7 @@ interactions: - AZURECLI/2.47.0 (AAZ) azsdk-python-core/1.24.0 Python/3.10.11 (Linux-5.15.0-1036-azure-x86_64-with-glibc2.31) VSTS_7b238909-6802-4b65-b90d-184bca47f458_build_220_0 method: DELETE - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_host_management_000001/providers/Microsoft.Compute/hostGroups/my-host-group?api-version=2019-03-01 + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_host_management_000001/providers/Microsoft.Compute/hostGroups/my-host-group?api-version=2024-11-01 response: body: string: '' diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_host_redeploy.yaml b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_host_redeploy.yaml index 317a4035f7f..7ba6fe3eaa7 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_host_redeploy.yaml +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vm_host_redeploy.yaml @@ -122,7 +122,7 @@ interactions: User-Agent: - AZURECLI/2.72.0 azsdk-python-core/1.31.0 Python/3.10.11 (Windows-10-10.0.26100-SP0) method: GET - uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_host_redeploy_000001/providers/Microsoft.Compute/hostGroups?api-version=2019-03-01 + uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_vm_host_redeploy_000001/providers/Microsoft.Compute/hostGroups?api-version=2024-11-01 response: body: string: '{"value":[{"name":"my-host-group","id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/CLI_TEST_VM_HOST_REDEPLOY_CJ4NDXY3MM2YBFYB25NY3YQ6GDCNAST5DV2Q4AY5UP6COWZWO/providers/Microsoft.Compute/hostGroups/my-host-group","type":"Microsoft.Compute/hostGroups","location":"eastus","properties":{"platformFaultDomainCount":1}}]}' diff --git a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py index 45b1af81cf1..68f831fcd5d 100644 --- a/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py +++ b/src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py @@ -9495,7 +9495,7 @@ def test_vm_host_ultra_ssd(self, resource_group): 'host-group': self.create_random_name('host', 10) }) self.cmd('vm host group create -n {host-group} -g {rg} --ultra-ssd-enabled true -c 1 -l eastus2euap --zone 3', checks=[ - self.check('additionalCapabilities.ultraSsdEnabled', True) + self.check('additionalCapabilities.ultraSSDEnabled', True) ]) @AllowLargeResponse()