|
| 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 Reimage(AAZCommand): |
| 15 | + """Reimages (upgrade the operating system) one or more virtual machines in a VM scale set which don't have a ephemeral OS disk, for virtual machines who have a ephemeral OS disk the virtual machine is reset to initial state. |
| 16 | + """ |
| 17 | + |
| 18 | + _aaz_info = { |
| 19 | + "version": "2024-11-01", |
| 20 | + "resources": [ |
| 21 | + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.compute/virtualmachinescalesets/{}/reimage", "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 | + |
| 52 | + # define Arg Group "VmScaleSetReimageInput" |
| 53 | + |
| 54 | + _args_schema = cls._args_schema |
| 55 | + _args_schema.exact_version = AAZStrArg( |
| 56 | + options=["--exact-version"], |
| 57 | + arg_group="VmScaleSetReimageInput", |
| 58 | + help="Specifies in decimal number, the version the OS disk should be reimaged to. If exact version is not provided, the OS disk is reimaged to the existing version of OS Disk.", |
| 59 | + ) |
| 60 | + _args_schema.force_update_os_disk_for_ephemeral = AAZBoolArg( |
| 61 | + options=["--force-update-os-disk-for-ephemeral"], |
| 62 | + arg_group="VmScaleSetReimageInput", |
| 63 | + help="Parameter to force update ephemeral OS disk for a virtual machine scale set VM", |
| 64 | + ) |
| 65 | + _args_schema.instance_ids = AAZListArg( |
| 66 | + options=["--instance-ids"], |
| 67 | + arg_group="VmScaleSetReimageInput", |
| 68 | + 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.", |
| 69 | + ) |
| 70 | + _args_schema.os_profile = AAZObjectArg( |
| 71 | + options=["--os-profile"], |
| 72 | + arg_group="VmScaleSetReimageInput", |
| 73 | + help="Specifies information required for reimaging the non-ephemeral OS disk.", |
| 74 | + ) |
| 75 | + _args_schema.temp_disk = AAZBoolArg( |
| 76 | + options=["--temp-disk"], |
| 77 | + arg_group="VmScaleSetReimageInput", |
| 78 | + help="Specifies whether to reimage temp disk. Default value: false. Note: This temp disk reimage parameter is only supported for VM/VMSS with Ephemeral OS disk.", |
| 79 | + ) |
| 80 | + |
| 81 | + instance_ids = cls._args_schema.instance_ids |
| 82 | + instance_ids.Element = AAZStrArg() |
| 83 | + |
| 84 | + os_profile = cls._args_schema.os_profile |
| 85 | + os_profile.admin_password = AAZPasswordArg( |
| 86 | + options=["admin-password"], |
| 87 | + help="Specifies the password of the administrator account. <br><br> **Minimum-length (Windows):** 8 characters <br><br> **Minimum-length (Linux):** 6 characters <br><br> **Max-length (Windows):** 123 characters <br><br> **Max-length (Linux):** 72 characters <br><br> **Complexity requirements:** 3 out of 4 conditions below need to be fulfilled <br> Has lower characters <br>Has upper characters <br> Has a digit <br> Has a special character (Regex match [\\W_]) <br><br> **Disallowed values:** \"abc@123\", \"P@$$w0rd\", \"P@ssw0rd\", \"P@ssword123\", \"Pa$$word\", \"pass@word1\", \"Password!\", \"Password1\", \"Password22\", \"iloveyou!\" <br><br> For resetting the password, see [How to reset the Remote Desktop service or its login password in a Windows VM](https://docs.microsoft.com/troubleshoot/azure/virtual-machines/reset-rdp) <br><br> For resetting root password, see [Manage users, SSH, and check or repair disks on Azure Linux VMs using the VMAccess Extension](https://docs.microsoft.com/troubleshoot/azure/virtual-machines/troubleshoot-ssh-connection)", |
| 88 | + blank=AAZPromptPasswordInput( |
| 89 | + msg="Password:", |
| 90 | + ), |
| 91 | + ) |
| 92 | + os_profile.custom_data = AAZStrArg( |
| 93 | + options=["custom-data"], |
| 94 | + help="Specifies a base-64 encoded string of custom data. The base-64 encoded string is decoded to a binary array that is saved as a file on the Virtual Machine. The maximum length of the binary array is 65535 bytes. **Note: Do not pass any secrets or passwords in customData property.** This property cannot be updated after the VM is created. The property customData is passed to the VM to be saved as a file, for more information see [Custom Data on Azure VMs](https://azure.microsoft.com/blog/custom-data-and-cloud-init-on-windows-azure/). If using cloud-init for your Linux VM, see [Using cloud-init to customize a Linux VM during creation](https://docs.microsoft.com/azure/virtual-machines/linux/using-cloud-init).", |
| 95 | + ) |
| 96 | + return cls._args_schema |
| 97 | + |
| 98 | + def _execute_operations(self): |
| 99 | + self.pre_operations() |
| 100 | + yield self.VirtualMachineScaleSetsReimage(ctx=self.ctx)() |
| 101 | + self.post_operations() |
| 102 | + |
| 103 | + @register_callback |
| 104 | + def pre_operations(self): |
| 105 | + pass |
| 106 | + |
| 107 | + @register_callback |
| 108 | + def post_operations(self): |
| 109 | + pass |
| 110 | + |
| 111 | + class VirtualMachineScaleSetsReimage(AAZHttpOperation): |
| 112 | + CLIENT_TYPE = "MgmtClient" |
| 113 | + |
| 114 | + def __call__(self, *args, **kwargs): |
| 115 | + request = self.make_request() |
| 116 | + session = self.client.send_request(request=request, stream=False, **kwargs) |
| 117 | + if session.http_response.status_code in [202]: |
| 118 | + return self.client.build_lro_polling( |
| 119 | + self.ctx.args.no_wait, |
| 120 | + session, |
| 121 | + self.on_200, |
| 122 | + self.on_error, |
| 123 | + lro_options={"final-state-via": "location"}, |
| 124 | + path_format_arguments=self.url_parameters, |
| 125 | + ) |
| 126 | + if session.http_response.status_code in [200]: |
| 127 | + return self.client.build_lro_polling( |
| 128 | + self.ctx.args.no_wait, |
| 129 | + session, |
| 130 | + self.on_200, |
| 131 | + self.on_error, |
| 132 | + lro_options={"final-state-via": "location"}, |
| 133 | + path_format_arguments=self.url_parameters, |
| 134 | + ) |
| 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/virtualMachineScaleSets/{vmScaleSetName}/reimage", |
| 142 | + **self.url_parameters |
| 143 | + ) |
| 144 | + |
| 145 | + @property |
| 146 | + def method(self): |
| 147 | + return "POST" |
| 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 | + "resourceGroupName", self.ctx.args.resource_group, |
| 158 | + required=True, |
| 159 | + ), |
| 160 | + **self.serialize_url_param( |
| 161 | + "subscriptionId", self.ctx.subscription_id, |
| 162 | + required=True, |
| 163 | + ), |
| 164 | + **self.serialize_url_param( |
| 165 | + "vmScaleSetName", self.ctx.args.vm_scale_set_name, |
| 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 | + } |
| 188 | + return parameters |
| 189 | + |
| 190 | + @property |
| 191 | + def content(self): |
| 192 | + _content_value, _builder = self.new_content_builder( |
| 193 | + self.ctx.args, |
| 194 | + typ=AAZObjectType, |
| 195 | + typ_kwargs={"flags": {"client_flatten": True}} |
| 196 | + ) |
| 197 | + _builder.set_prop("exactVersion", AAZStrType, ".exact_version") |
| 198 | + _builder.set_prop("forceUpdateOSDiskForEphemeral", AAZBoolType, ".force_update_os_disk_for_ephemeral") |
| 199 | + _builder.set_prop("instanceIds", AAZListType, ".instance_ids") |
| 200 | + _builder.set_prop("osProfile", AAZObjectType, ".os_profile") |
| 201 | + _builder.set_prop("tempDisk", AAZBoolType, ".temp_disk") |
| 202 | + |
| 203 | + instance_ids = _builder.get(".instanceIds") |
| 204 | + if instance_ids is not None: |
| 205 | + instance_ids.set_elements(AAZStrType, ".") |
| 206 | + |
| 207 | + os_profile = _builder.get(".osProfile") |
| 208 | + if os_profile is not None: |
| 209 | + os_profile.set_prop("adminPassword", AAZStrType, ".admin_password", typ_kwargs={"flags": {"secret": True}}) |
| 210 | + os_profile.set_prop("customData", AAZStrType, ".custom_data") |
| 211 | + |
| 212 | + return self.serialize_content(_content_value) |
| 213 | + |
| 214 | + def on_200(self, session): |
| 215 | + pass |
| 216 | + |
| 217 | + |
| 218 | +class _ReimageHelper: |
| 219 | + """Helper class for Reimage""" |
| 220 | + |
| 221 | + |
| 222 | +__all__ = ["Reimage"] |
0 commit comments