|
| 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 Deallocate(AAZCommand): |
| 15 | + """Deallocates specific virtual machines in a VM scale set. Shuts down the virtual machines and releases the compute resources. You are not billed for the compute resources that this virtual machine scale set deallocates. |
| 16 | + """ |
| 17 | + |
| 18 | + _aaz_info = { |
| 19 | + "version": "2024-11-01", |
| 20 | + "resources": [ |
| 21 | + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachinescalesets/{}/deallocate", "2024-11-01"], |
| 22 | + ] |
| 23 | + } |
| 24 | + |
| 25 | + AZ_SUPPORT_NO_WAIT = True |
| 26 | + |
| 27 | + def _handler(self, command_args): |
| 28 | + super()._handler(command_args) |
| 29 | + return self.build_lro_poller(self._execute_operations, None) |
| 30 | + |
| 31 | + _args_schema = None |
| 32 | + |
| 33 | + @classmethod |
| 34 | + def _build_arguments_schema(cls, *args, **kwargs): |
| 35 | + if cls._args_schema is not None: |
| 36 | + return cls._args_schema |
| 37 | + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) |
| 38 | + |
| 39 | + # define Arg Group "" |
| 40 | + |
| 41 | + _args_schema = cls._args_schema |
| 42 | + _args_schema.resource_group = AAZResourceGroupNameArg( |
| 43 | + required=True, |
| 44 | + ) |
| 45 | + _args_schema.vm_scale_set_name = AAZStrArg( |
| 46 | + options=["--vm-scale-set-name"], |
| 47 | + help="The name of the VM scale set.", |
| 48 | + required=True, |
| 49 | + id_part="name", |
| 50 | + ) |
| 51 | + _args_schema.hibernate = AAZBoolArg( |
| 52 | + options=["--hibernate"], |
| 53 | + help="Optional parameter to hibernate a virtual machine from the VM scale set. (This feature is available for VMSS with Flexible OrchestrationMode only)", |
| 54 | + ) |
| 55 | + |
| 56 | + # define Arg Group "VmInstanceIDs" |
| 57 | + |
| 58 | + _args_schema = cls._args_schema |
| 59 | + _args_schema.instance_ids = AAZListArg( |
| 60 | + options=["--instance-ids"], |
| 61 | + arg_group="VmInstanceIDs", |
| 62 | + help="The virtual machine scale set instance ids. Omitting the virtual machine scale set instance ids will result in the operation being performed on all virtual machines in the virtual machine scale set.", |
| 63 | + ) |
| 64 | + |
| 65 | + instance_ids = cls._args_schema.instance_ids |
| 66 | + instance_ids.Element = AAZStrArg() |
| 67 | + return cls._args_schema |
| 68 | + |
| 69 | + def _execute_operations(self): |
| 70 | + self.pre_operations() |
| 71 | + yield self.VirtualMachineScaleSetsDeallocate(ctx=self.ctx)() |
| 72 | + self.post_operations() |
| 73 | + |
| 74 | + @register_callback |
| 75 | + def pre_operations(self): |
| 76 | + pass |
| 77 | + |
| 78 | + @register_callback |
| 79 | + def post_operations(self): |
| 80 | + pass |
| 81 | + |
| 82 | + class VirtualMachineScaleSetsDeallocate(AAZHttpOperation): |
| 83 | + CLIENT_TYPE = "MgmtClient" |
| 84 | + |
| 85 | + def __call__(self, *args, **kwargs): |
| 86 | + request = self.make_request() |
| 87 | + session = self.client.send_request(request=request, stream=False, **kwargs) |
| 88 | + if session.http_response.status_code in [202]: |
| 89 | + return self.client.build_lro_polling( |
| 90 | + self.ctx.args.no_wait, |
| 91 | + session, |
| 92 | + self.on_200, |
| 93 | + self.on_error, |
| 94 | + lro_options={"final-state-via": "location"}, |
| 95 | + path_format_arguments=self.url_parameters, |
| 96 | + ) |
| 97 | + if session.http_response.status_code in [200]: |
| 98 | + return self.client.build_lro_polling( |
| 99 | + self.ctx.args.no_wait, |
| 100 | + session, |
| 101 | + self.on_200, |
| 102 | + self.on_error, |
| 103 | + lro_options={"final-state-via": "location"}, |
| 104 | + path_format_arguments=self.url_parameters, |
| 105 | + ) |
| 106 | + |
| 107 | + return self.on_error(session.http_response) |
| 108 | + |
| 109 | + @property |
| 110 | + def url(self): |
| 111 | + return self.client.format_url( |
| 112 | + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/deallocate", |
| 113 | + **self.url_parameters |
| 114 | + ) |
| 115 | + |
| 116 | + @property |
| 117 | + def method(self): |
| 118 | + return "POST" |
| 119 | + |
| 120 | + @property |
| 121 | + def error_format(self): |
| 122 | + return "ODataV4Format" |
| 123 | + |
| 124 | + @property |
| 125 | + def url_parameters(self): |
| 126 | + parameters = { |
| 127 | + **self.serialize_url_param( |
| 128 | + "resourceGroupName", self.ctx.args.resource_group, |
| 129 | + required=True, |
| 130 | + ), |
| 131 | + **self.serialize_url_param( |
| 132 | + "subscriptionId", self.ctx.subscription_id, |
| 133 | + required=True, |
| 134 | + ), |
| 135 | + **self.serialize_url_param( |
| 136 | + "vmScaleSetName", self.ctx.args.vm_scale_set_name, |
| 137 | + required=True, |
| 138 | + ), |
| 139 | + } |
| 140 | + return parameters |
| 141 | + |
| 142 | + @property |
| 143 | + def query_parameters(self): |
| 144 | + parameters = { |
| 145 | + **self.serialize_query_param( |
| 146 | + "hibernate", self.ctx.args.hibernate, |
| 147 | + ), |
| 148 | + **self.serialize_query_param( |
| 149 | + "api-version", "2024-11-01", |
| 150 | + required=True, |
| 151 | + ), |
| 152 | + } |
| 153 | + return parameters |
| 154 | + |
| 155 | + @property |
| 156 | + def header_parameters(self): |
| 157 | + parameters = { |
| 158 | + **self.serialize_header_param( |
| 159 | + "Content-Type", "application/json", |
| 160 | + ), |
| 161 | + } |
| 162 | + return parameters |
| 163 | + |
| 164 | + @property |
| 165 | + def content(self): |
| 166 | + _content_value, _builder = self.new_content_builder( |
| 167 | + self.ctx.args, |
| 168 | + typ=AAZObjectType, |
| 169 | + typ_kwargs={"flags": {"client_flatten": True}} |
| 170 | + ) |
| 171 | + _builder.set_prop("instanceIds", AAZListType, ".instance_ids") |
| 172 | + |
| 173 | + instance_ids = _builder.get(".instanceIds") |
| 174 | + if instance_ids is not None: |
| 175 | + instance_ids.set_elements(AAZStrType, ".") |
| 176 | + |
| 177 | + return self.serialize_content(_content_value) |
| 178 | + |
| 179 | + def on_200(self, session): |
| 180 | + pass |
| 181 | + |
| 182 | + |
| 183 | +class _DeallocateHelper: |
| 184 | + """Helper class for Deallocate""" |
| 185 | + |
| 186 | + |
| 187 | +__all__ = ["Deallocate"] |
0 commit comments