|
| 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 | +@register_command( |
| 14 | + "lab vm hibernate", |
| 15 | + is_preview=True |
| 16 | +) |
| 17 | +class Hibernate(AAZCommand): |
| 18 | + """Hibernate a virtual machine This operation can take a while to complete. |
| 19 | + :example: Hibernate a virtual machine. |
| 20 | + az lab vm hibernate --resource-group MyResourceGroup --lab-name MyLab --name MyVM |
| 21 | + """ |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + _aaz_info = { |
| 26 | + "version": "2018-09-15", |
| 27 | + "resources": [ |
| 28 | + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.devtestlab/labs/{}/virtualmachines/{}/hibernate", "2018-10-15-preview"], |
| 29 | + ] |
| 30 | + } |
| 31 | + |
| 32 | + AZ_SUPPORT_NO_WAIT = True |
| 33 | + |
| 34 | + def _handler(self, command_args): |
| 35 | + super()._handler(command_args) |
| 36 | + return self.build_lro_poller(self._execute_operations, None) |
| 37 | + |
| 38 | + _args_schema = None |
| 39 | + |
| 40 | + @classmethod |
| 41 | + def _build_arguments_schema(cls, *args, **kwargs): |
| 42 | + if cls._args_schema is not None: |
| 43 | + return cls._args_schema |
| 44 | + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) |
| 45 | + |
| 46 | + # define Arg Group "" |
| 47 | + |
| 48 | + _args_schema = cls._args_schema |
| 49 | + _args_schema.lab_name = AAZStrArg( |
| 50 | + options=["--lab-name"], |
| 51 | + help="The name of the lab.", |
| 52 | + required=True, |
| 53 | + id_part="name", |
| 54 | + ) |
| 55 | + _args_schema.name = AAZStrArg( |
| 56 | + options=["--name"], |
| 57 | + help="The name of the virtual machine.", |
| 58 | + required=True, |
| 59 | + id_part="child_name_1", |
| 60 | + ) |
| 61 | + _args_schema.resource_group = AAZResourceGroupNameArg( |
| 62 | + required=True, |
| 63 | + ) |
| 64 | + return cls._args_schema |
| 65 | + |
| 66 | + def _execute_operations(self): |
| 67 | + self.pre_operations() |
| 68 | + yield self.VirtualMachinesHibernate(ctx=self.ctx)() |
| 69 | + self.post_operations() |
| 70 | + |
| 71 | + @register_callback |
| 72 | + def pre_operations(self): |
| 73 | + pass |
| 74 | + |
| 75 | + @register_callback |
| 76 | + def post_operations(self): |
| 77 | + pass |
| 78 | + |
| 79 | + class VirtualMachinesHibernate(AAZHttpOperation): |
| 80 | + CLIENT_TYPE = "MgmtClient" |
| 81 | + |
| 82 | + def __call__(self, *args, **kwargs): |
| 83 | + request = self.make_request() |
| 84 | + session = self.client.send_request(request=request, stream=False, **kwargs) |
| 85 | + if session.http_response.status_code in [202]: |
| 86 | + return self.client.build_lro_polling( |
| 87 | + self.ctx.args.no_wait, |
| 88 | + session, |
| 89 | + self.on_200, |
| 90 | + self.on_error, |
| 91 | + lro_options={"final-state-via": "azure-async-operation"}, |
| 92 | + path_format_arguments=self.url_parameters, |
| 93 | + ) |
| 94 | + if session.http_response.status_code in [200]: |
| 95 | + return self.client.build_lro_polling( |
| 96 | + self.ctx.args.no_wait, |
| 97 | + session, |
| 98 | + self.on_200, |
| 99 | + self.on_error, |
| 100 | + lro_options={"final-state-via": "azure-async-operation"}, |
| 101 | + path_format_arguments=self.url_parameters, |
| 102 | + ) |
| 103 | + |
| 104 | + return self.on_error(session.http_response) |
| 105 | + |
| 106 | + @property |
| 107 | + def url(self): |
| 108 | + return self.client.format_url( |
| 109 | + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/hibernate", |
| 110 | + **self.url_parameters |
| 111 | + ) |
| 112 | + |
| 113 | + @property |
| 114 | + def method(self): |
| 115 | + return "POST" |
| 116 | + |
| 117 | + @property |
| 118 | + def error_format(self): |
| 119 | + return "ODataV4Format" |
| 120 | + |
| 121 | + @property |
| 122 | + def url_parameters(self): |
| 123 | + parameters = { |
| 124 | + **self.serialize_url_param( |
| 125 | + "labName", self.ctx.args.lab_name, |
| 126 | + required=True, |
| 127 | + ), |
| 128 | + **self.serialize_url_param( |
| 129 | + "name", self.ctx.args.name, |
| 130 | + required=True, |
| 131 | + ), |
| 132 | + **self.serialize_url_param( |
| 133 | + "resourceGroupName", self.ctx.args.resource_group, |
| 134 | + required=True, |
| 135 | + ), |
| 136 | + **self.serialize_url_param( |
| 137 | + "subscriptionId", self.ctx.subscription_id, |
| 138 | + required=True, |
| 139 | + ), |
| 140 | + } |
| 141 | + return parameters |
| 142 | + |
| 143 | + @property |
| 144 | + def query_parameters(self): |
| 145 | + parameters = { |
| 146 | + **self.serialize_query_param( |
| 147 | + "api-version", "2018-10-15-preview", |
| 148 | + required=True, |
| 149 | + ), |
| 150 | + } |
| 151 | + return parameters |
| 152 | + |
| 153 | + def on_200(self, session): |
| 154 | + pass |
| 155 | + |
| 156 | + |
| 157 | +class _HibernateHelper: |
| 158 | + """Helper class for Hibernate""" |
| 159 | + |
| 160 | + |
| 161 | +__all__ = ["Hibernate"] |
0 commit comments