|
| 1 | +# -------------------------------------------------------------------------------------------- |
| 2 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | +# |
| 5 | +# Code generated by aaz-dev-tools |
| 6 | +# -------------------------------------------------------------------------------------------- |
| 7 | + |
| 8 | +# pylint: skip-file |
| 9 | +# flake8: noqa |
| 10 | + |
| 11 | +from azure.cli.core.aaz import * |
| 12 | + |
| 13 | + |
| 14 | +class Create(AAZCommand): |
| 15 | + """Create a dedicated host group. |
| 16 | +
|
| 17 | + :example: Create a dedicated host group. |
| 18 | + az vm host group create --name MyDedicatedHostGroup --platform-fault-domain-count 2 --resource-group MyResourceGroup |
| 19 | + """ |
| 20 | + |
| 21 | + _aaz_info = { |
| 22 | + "version": "2024-11-01", |
| 23 | + "resources": [ |
| 24 | + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/hostgroups/{}", "2024-11-01"], |
| 25 | + ] |
| 26 | + } |
| 27 | + |
| 28 | + def _handler(self, command_args): |
| 29 | + super()._handler(command_args) |
| 30 | + self._execute_operations() |
| 31 | + return self._output() |
| 32 | + |
| 33 | + _args_schema = None |
| 34 | + |
| 35 | + @classmethod |
| 36 | + def _build_arguments_schema(cls, *args, **kwargs): |
| 37 | + if cls._args_schema is not None: |
| 38 | + return cls._args_schema |
| 39 | + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) |
| 40 | + |
| 41 | + # define Arg Group "" |
| 42 | + |
| 43 | + _args_schema = cls._args_schema |
| 44 | + _args_schema.host_group_name = AAZStrArg( |
| 45 | + options=["-n", "--name", "--host-group-name"], |
| 46 | + help="Name of the Dedicated Host Group.", |
| 47 | + required=True, |
| 48 | + ) |
| 49 | + _args_schema.resource_group = AAZResourceGroupNameArg( |
| 50 | + required=True, |
| 51 | + ) |
| 52 | + |
| 53 | + # define Arg Group "Parameters" |
| 54 | + |
| 55 | + _args_schema = cls._args_schema |
| 56 | + _args_schema.location = AAZResourceLocationArg( |
| 57 | + arg_group="Parameters", |
| 58 | + help="Resource location", |
| 59 | + required=True, |
| 60 | + fmt=AAZResourceLocationArgFormat( |
| 61 | + resource_group_arg="resource_group", |
| 62 | + ), |
| 63 | + ) |
| 64 | + _args_schema.tags = AAZDictArg( |
| 65 | + options=["--tags"], |
| 66 | + arg_group="Parameters", |
| 67 | + help="Resource tags", |
| 68 | + ) |
| 69 | + _args_schema.zones = AAZListArg( |
| 70 | + options=["--zones"], |
| 71 | + arg_group="Parameters", |
| 72 | + 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.", |
| 73 | + ) |
| 74 | + |
| 75 | + tags = cls._args_schema.tags |
| 76 | + tags.Element = AAZStrArg() |
| 77 | + |
| 78 | + zones = cls._args_schema.zones |
| 79 | + zones.Element = AAZStrArg() |
| 80 | + |
| 81 | + # define Arg Group "Properties" |
| 82 | + |
| 83 | + _args_schema = cls._args_schema |
| 84 | + _args_schema.additional_capabilities = AAZObjectArg( |
| 85 | + options=["--additional-capabilities"], |
| 86 | + arg_group="Properties", |
| 87 | + help="Enables or disables a capability on the dedicated host group. Minimum api-version: 2022-03-01.", |
| 88 | + ) |
| 89 | + _args_schema.platform_fault_domain_count = AAZIntArg( |
| 90 | + options=["--platform-fault-domain-count"], |
| 91 | + arg_group="Properties", |
| 92 | + help="Number of fault domains that the host group can span.", |
| 93 | + fmt=AAZIntArgFormat( |
| 94 | + minimum=1, |
| 95 | + ), |
| 96 | + ) |
| 97 | + _args_schema.support_automatic_placement = AAZBoolArg( |
| 98 | + options=["--support-automatic-placement"], |
| 99 | + arg_group="Properties", |
| 100 | + 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.", |
| 101 | + ) |
| 102 | + |
| 103 | + additional_capabilities = cls._args_schema.additional_capabilities |
| 104 | + additional_capabilities.ultra_ssd_enabled = AAZBoolArg( |
| 105 | + options=["ultra-ssd-enabled"], |
| 106 | + 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.", |
| 107 | + ) |
| 108 | + return cls._args_schema |
| 109 | + |
| 110 | + def _execute_operations(self): |
| 111 | + self.pre_operations() |
| 112 | + self.DedicatedHostGroupsCreateOrUpdate(ctx=self.ctx)() |
| 113 | + self.post_operations() |
| 114 | + |
| 115 | + @register_callback |
| 116 | + def pre_operations(self): |
| 117 | + pass |
| 118 | + |
| 119 | + @register_callback |
| 120 | + def post_operations(self): |
| 121 | + pass |
| 122 | + |
| 123 | + def _output(self, *args, **kwargs): |
| 124 | + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) |
| 125 | + return result |
| 126 | + |
| 127 | + class DedicatedHostGroupsCreateOrUpdate(AAZHttpOperation): |
| 128 | + CLIENT_TYPE = "MgmtClient" |
| 129 | + |
| 130 | + def __call__(self, *args, **kwargs): |
| 131 | + request = self.make_request() |
| 132 | + session = self.client.send_request(request=request, stream=False, **kwargs) |
| 133 | + if session.http_response.status_code in [200, 201]: |
| 134 | + return self.on_200_201(session) |
| 135 | + |
| 136 | + return self.on_error(session.http_response) |
| 137 | + |
| 138 | + @property |
| 139 | + def url(self): |
| 140 | + return self.client.format_url( |
| 141 | + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/hostGroups/{hostGroupName}", |
| 142 | + **self.url_parameters |
| 143 | + ) |
| 144 | + |
| 145 | + @property |
| 146 | + def method(self): |
| 147 | + return "PUT" |
| 148 | + |
| 149 | + @property |
| 150 | + def error_format(self): |
| 151 | + return "ODataV4Format" |
| 152 | + |
| 153 | + @property |
| 154 | + def url_parameters(self): |
| 155 | + parameters = { |
| 156 | + **self.serialize_url_param( |
| 157 | + "hostGroupName", self.ctx.args.host_group_name, |
| 158 | + required=True, |
| 159 | + ), |
| 160 | + **self.serialize_url_param( |
| 161 | + "resourceGroupName", self.ctx.args.resource_group, |
| 162 | + required=True, |
| 163 | + ), |
| 164 | + **self.serialize_url_param( |
| 165 | + "subscriptionId", self.ctx.subscription_id, |
| 166 | + required=True, |
| 167 | + ), |
| 168 | + } |
| 169 | + return parameters |
| 170 | + |
| 171 | + @property |
| 172 | + def query_parameters(self): |
| 173 | + parameters = { |
| 174 | + **self.serialize_query_param( |
| 175 | + "api-version", "2024-11-01", |
| 176 | + required=True, |
| 177 | + ), |
| 178 | + } |
| 179 | + return parameters |
| 180 | + |
| 181 | + @property |
| 182 | + def header_parameters(self): |
| 183 | + parameters = { |
| 184 | + **self.serialize_header_param( |
| 185 | + "Content-Type", "application/json", |
| 186 | + ), |
| 187 | + **self.serialize_header_param( |
| 188 | + "Accept", "application/json", |
| 189 | + ), |
| 190 | + } |
| 191 | + return parameters |
| 192 | + |
| 193 | + @property |
| 194 | + def content(self): |
| 195 | + _content_value, _builder = self.new_content_builder( |
| 196 | + self.ctx.args, |
| 197 | + typ=AAZObjectType, |
| 198 | + typ_kwargs={"flags": {"required": True, "client_flatten": True}} |
| 199 | + ) |
| 200 | + _builder.set_prop("location", AAZStrType, ".location", typ_kwargs={"flags": {"required": True}}) |
| 201 | + _builder.set_prop("properties", AAZObjectType, typ_kwargs={"flags": {"client_flatten": True}}) |
| 202 | + _builder.set_prop("tags", AAZDictType, ".tags") |
| 203 | + _builder.set_prop("zones", AAZListType, ".zones") |
| 204 | + |
| 205 | + properties = _builder.get(".properties") |
| 206 | + if properties is not None: |
| 207 | + properties.set_prop("additionalCapabilities", AAZObjectType, ".additional_capabilities") |
| 208 | + properties.set_prop("platformFaultDomainCount", AAZIntType, ".platform_fault_domain_count", typ_kwargs={"flags": {"required": True}}) |
| 209 | + properties.set_prop("supportAutomaticPlacement", AAZBoolType, ".support_automatic_placement") |
| 210 | + |
| 211 | + additional_capabilities = _builder.get(".properties.additionalCapabilities") |
| 212 | + if additional_capabilities is not None: |
| 213 | + additional_capabilities.set_prop("ultraSSDEnabled", AAZBoolType, ".ultra_ssd_enabled") |
| 214 | + |
| 215 | + tags = _builder.get(".tags") |
| 216 | + if tags is not None: |
| 217 | + tags.set_elements(AAZStrType, ".") |
| 218 | + |
| 219 | + zones = _builder.get(".zones") |
| 220 | + if zones is not None: |
| 221 | + zones.set_elements(AAZStrType, ".") |
| 222 | + |
| 223 | + return self.serialize_content(_content_value) |
| 224 | + |
| 225 | + def on_200_201(self, session): |
| 226 | + data = self.deserialize_http_content(session) |
| 227 | + self.ctx.set_var( |
| 228 | + "instance", |
| 229 | + data, |
| 230 | + schema_builder=self._build_schema_on_200_201 |
| 231 | + ) |
| 232 | + |
| 233 | + _schema_on_200_201 = None |
| 234 | + |
| 235 | + @classmethod |
| 236 | + def _build_schema_on_200_201(cls): |
| 237 | + if cls._schema_on_200_201 is not None: |
| 238 | + return cls._schema_on_200_201 |
| 239 | + |
| 240 | + cls._schema_on_200_201 = AAZObjectType() |
| 241 | + |
| 242 | + _schema_on_200_201 = cls._schema_on_200_201 |
| 243 | + _schema_on_200_201.id = AAZStrType( |
| 244 | + flags={"read_only": True}, |
| 245 | + ) |
| 246 | + _schema_on_200_201.location = AAZStrType( |
| 247 | + flags={"required": True}, |
| 248 | + ) |
| 249 | + _schema_on_200_201.name = AAZStrType( |
| 250 | + flags={"read_only": True}, |
| 251 | + ) |
| 252 | + _schema_on_200_201.properties = AAZObjectType( |
| 253 | + flags={"client_flatten": True}, |
| 254 | + ) |
| 255 | + _schema_on_200_201.system_data = AAZObjectType( |
| 256 | + serialized_name="systemData", |
| 257 | + flags={"read_only": True}, |
| 258 | + ) |
| 259 | + _schema_on_200_201.tags = AAZDictType() |
| 260 | + _schema_on_200_201.type = AAZStrType( |
| 261 | + flags={"read_only": True}, |
| 262 | + ) |
| 263 | + _schema_on_200_201.zones = AAZListType() |
| 264 | + |
| 265 | + properties = cls._schema_on_200_201.properties |
| 266 | + properties.additional_capabilities = AAZObjectType( |
| 267 | + serialized_name="additionalCapabilities", |
| 268 | + ) |
| 269 | + properties.hosts = AAZListType( |
| 270 | + flags={"read_only": True}, |
| 271 | + ) |
| 272 | + properties.instance_view = AAZObjectType( |
| 273 | + serialized_name="instanceView", |
| 274 | + flags={"read_only": True}, |
| 275 | + ) |
| 276 | + properties.platform_fault_domain_count = AAZIntType( |
| 277 | + serialized_name="platformFaultDomainCount", |
| 278 | + flags={"required": True}, |
| 279 | + ) |
| 280 | + properties.support_automatic_placement = AAZBoolType( |
| 281 | + serialized_name="supportAutomaticPlacement", |
| 282 | + ) |
| 283 | + |
| 284 | + additional_capabilities = cls._schema_on_200_201.properties.additional_capabilities |
| 285 | + additional_capabilities.ultra_ssd_enabled = AAZBoolType( |
| 286 | + serialized_name="ultraSSDEnabled", |
| 287 | + ) |
| 288 | + |
| 289 | + hosts = cls._schema_on_200_201.properties.hosts |
| 290 | + hosts.Element = AAZObjectType() |
| 291 | + |
| 292 | + _element = cls._schema_on_200_201.properties.hosts.Element |
| 293 | + _element.id = AAZStrType( |
| 294 | + flags={"read_only": True}, |
| 295 | + ) |
| 296 | + |
| 297 | + instance_view = cls._schema_on_200_201.properties.instance_view |
| 298 | + instance_view.hosts = AAZListType() |
| 299 | + |
| 300 | + hosts = cls._schema_on_200_201.properties.instance_view.hosts |
| 301 | + hosts.Element = AAZObjectType() |
| 302 | + |
| 303 | + _element = cls._schema_on_200_201.properties.instance_view.hosts.Element |
| 304 | + _element.asset_id = AAZStrType( |
| 305 | + serialized_name="assetId", |
| 306 | + flags={"read_only": True}, |
| 307 | + ) |
| 308 | + _element.available_capacity = AAZObjectType( |
| 309 | + serialized_name="availableCapacity", |
| 310 | + ) |
| 311 | + _element.name = AAZStrType( |
| 312 | + flags={"read_only": True}, |
| 313 | + ) |
| 314 | + _element.statuses = AAZListType() |
| 315 | + |
| 316 | + available_capacity = cls._schema_on_200_201.properties.instance_view.hosts.Element.available_capacity |
| 317 | + available_capacity.allocatable_v_ms = AAZListType( |
| 318 | + serialized_name="allocatableVMs", |
| 319 | + ) |
| 320 | + |
| 321 | + allocatable_v_ms = cls._schema_on_200_201.properties.instance_view.hosts.Element.available_capacity.allocatable_v_ms |
| 322 | + allocatable_v_ms.Element = AAZObjectType() |
| 323 | + |
| 324 | + _element = cls._schema_on_200_201.properties.instance_view.hosts.Element.available_capacity.allocatable_v_ms.Element |
| 325 | + _element.count = AAZFloatType() |
| 326 | + _element.vm_size = AAZStrType( |
| 327 | + serialized_name="vmSize", |
| 328 | + ) |
| 329 | + |
| 330 | + statuses = cls._schema_on_200_201.properties.instance_view.hosts.Element.statuses |
| 331 | + statuses.Element = AAZObjectType() |
| 332 | + |
| 333 | + _element = cls._schema_on_200_201.properties.instance_view.hosts.Element.statuses.Element |
| 334 | + _element.code = AAZStrType() |
| 335 | + _element.display_status = AAZStrType( |
| 336 | + serialized_name="displayStatus", |
| 337 | + ) |
| 338 | + _element.level = AAZStrType() |
| 339 | + _element.message = AAZStrType() |
| 340 | + _element.time = AAZStrType() |
| 341 | + |
| 342 | + system_data = cls._schema_on_200_201.system_data |
| 343 | + system_data.created_at = AAZStrType( |
| 344 | + serialized_name="createdAt", |
| 345 | + ) |
| 346 | + system_data.created_by = AAZStrType( |
| 347 | + serialized_name="createdBy", |
| 348 | + ) |
| 349 | + system_data.created_by_type = AAZStrType( |
| 350 | + serialized_name="createdByType", |
| 351 | + ) |
| 352 | + system_data.last_modified_at = AAZStrType( |
| 353 | + serialized_name="lastModifiedAt", |
| 354 | + ) |
| 355 | + system_data.last_modified_by = AAZStrType( |
| 356 | + serialized_name="lastModifiedBy", |
| 357 | + ) |
| 358 | + system_data.last_modified_by_type = AAZStrType( |
| 359 | + serialized_name="lastModifiedByType", |
| 360 | + ) |
| 361 | + |
| 362 | + tags = cls._schema_on_200_201.tags |
| 363 | + tags.Element = AAZStrType() |
| 364 | + |
| 365 | + zones = cls._schema_on_200_201.zones |
| 366 | + zones.Element = AAZStrType() |
| 367 | + |
| 368 | + return cls._schema_on_200_201 |
| 369 | + |
| 370 | + |
| 371 | +class _CreateHelper: |
| 372 | + """Helper class for Create""" |
| 373 | + |
| 374 | + |
| 375 | +__all__ = ["Create"] |
0 commit comments