|
| 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 | +@register_command( |
| 15 | + "vmss start", |
| 16 | +) |
| 17 | +class Start(AAZCommand): |
| 18 | + """Start VMs within a VMSS |
| 19 | +
|
| 20 | + :example: Start VMs within a VMSS. |
| 21 | + az vmss start --instance-ids 1 --name MyScaleSet --resource-group MyResourceGroup |
| 22 | + """ |
| 23 | + |
| 24 | + _aaz_info = { |
| 25 | + "version": "2024-11-01", |
| 26 | + "resources": [ |
| 27 | + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachinescalesets/{}/start", "2024-11-01"], |
| 28 | + ] |
| 29 | + } |
| 30 | + |
| 31 | + AZ_SUPPORT_NO_WAIT = True |
| 32 | + |
| 33 | + def _handler(self, command_args): |
| 34 | + super()._handler(command_args) |
| 35 | + return self.build_lro_poller(self._execute_operations, None) |
| 36 | + |
| 37 | + _args_schema = None |
| 38 | + |
| 39 | + @classmethod |
| 40 | + def _build_arguments_schema(cls, *args, **kwargs): |
| 41 | + if cls._args_schema is not None: |
| 42 | + return cls._args_schema |
| 43 | + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) |
| 44 | + |
| 45 | + # define Arg Group "" |
| 46 | + |
| 47 | + _args_schema = cls._args_schema |
| 48 | + _args_schema.resource_group = AAZResourceGroupNameArg( |
| 49 | + help="Name of resource group. You can configure the default group using `az configure --defaults group=<name>`", |
| 50 | + required=True, |
| 51 | + ) |
| 52 | + _args_schema.name = AAZStrArg( |
| 53 | + options=["--name"], |
| 54 | + help="Scale set name. You can configure the default using `az configure --defaults vmss=<name>`", |
| 55 | + required=True, |
| 56 | + id_part="name", |
| 57 | + ) |
| 58 | + |
| 59 | + # define Arg Group "VmInstanceIDs" |
| 60 | + |
| 61 | + _args_schema = cls._args_schema |
| 62 | + _args_schema.instance_ids = AAZListArg( |
| 63 | + options=["--instance-ids"], |
| 64 | + arg_group="VmInstanceIDs", |
| 65 | + 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.", |
| 66 | + ) |
| 67 | + |
| 68 | + instance_ids = cls._args_schema.instance_ids |
| 69 | + instance_ids.Element = AAZStrArg() |
| 70 | + return cls._args_schema |
| 71 | + |
| 72 | + def _execute_operations(self): |
| 73 | + self.pre_operations() |
| 74 | + yield self.VirtualMachineScaleSetsStart(ctx=self.ctx)() |
| 75 | + self.post_operations() |
| 76 | + |
| 77 | + @register_callback |
| 78 | + def pre_operations(self): |
| 79 | + pass |
| 80 | + |
| 81 | + @register_callback |
| 82 | + def post_operations(self): |
| 83 | + pass |
| 84 | + |
| 85 | + class VirtualMachineScaleSetsStart(AAZHttpOperation): |
| 86 | + CLIENT_TYPE = "MgmtClient" |
| 87 | + |
| 88 | + def __call__(self, *args, **kwargs): |
| 89 | + request = self.make_request() |
| 90 | + session = self.client.send_request(request=request, stream=False, **kwargs) |
| 91 | + if session.http_response.status_code in [202]: |
| 92 | + return self.client.build_lro_polling( |
| 93 | + self.ctx.args.no_wait, |
| 94 | + session, |
| 95 | + self.on_200, |
| 96 | + self.on_error, |
| 97 | + lro_options={"final-state-via": "location"}, |
| 98 | + path_format_arguments=self.url_parameters, |
| 99 | + ) |
| 100 | + if session.http_response.status_code in [200]: |
| 101 | + return self.client.build_lro_polling( |
| 102 | + self.ctx.args.no_wait, |
| 103 | + session, |
| 104 | + self.on_200, |
| 105 | + self.on_error, |
| 106 | + lro_options={"final-state-via": "location"}, |
| 107 | + path_format_arguments=self.url_parameters, |
| 108 | + ) |
| 109 | + |
| 110 | + return self.on_error(session.http_response) |
| 111 | + |
| 112 | + @property |
| 113 | + def url(self): |
| 114 | + return self.client.format_url( |
| 115 | + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/start", |
| 116 | + **self.url_parameters |
| 117 | + ) |
| 118 | + |
| 119 | + @property |
| 120 | + def method(self): |
| 121 | + return "POST" |
| 122 | + |
| 123 | + @property |
| 124 | + def error_format(self): |
| 125 | + return "ODataV4Format" |
| 126 | + |
| 127 | + @property |
| 128 | + def url_parameters(self): |
| 129 | + parameters = { |
| 130 | + **self.serialize_url_param( |
| 131 | + "resourceGroupName", self.ctx.args.resource_group, |
| 132 | + required=True, |
| 133 | + ), |
| 134 | + **self.serialize_url_param( |
| 135 | + "subscriptionId", self.ctx.subscription_id, |
| 136 | + required=True, |
| 137 | + ), |
| 138 | + **self.serialize_url_param( |
| 139 | + "vmScaleSetName", self.ctx.args.name, |
| 140 | + required=True, |
| 141 | + ), |
| 142 | + } |
| 143 | + return parameters |
| 144 | + |
| 145 | + @property |
| 146 | + def query_parameters(self): |
| 147 | + parameters = { |
| 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 _StartHelper: |
| 184 | + """Helper class for Start""" |
| 185 | + |
| 186 | + |
| 187 | +__all__ = ["Start"] |
0 commit comments