|
| 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 | + "aks safeguards create", |
| 16 | +) |
| 17 | +class Create(AAZCommand): |
| 18 | + """Enable Deployment Safeguards for a Managed Cluster |
| 19 | +
|
| 20 | + :example: Create a DeploymentSafeguards resource at Warn level with a managed cluster resource id |
| 21 | + az aks safeguards create --resource /subscriptions/subid1/resourceGroups/rg1/providers/Microsoft.ContainerService/managedClusters/cluster1 --level Warn |
| 22 | +
|
| 23 | + :example: Create a DeploymentSafeguards resource at Warn level using subscription, resourcegroup, and name tags |
| 24 | + az aks safeguards create --subscription subid1 -g rg1 -n cluster1 --level Warn |
| 25 | +
|
| 26 | + :example: Create a DeploymentSafeguards resource at Warn level with ignored namespaces |
| 27 | + az aks safeguards create -g rg1 -n mc1 --excluded-ns ns1 ns2 --level Warn |
| 28 | + """ |
| 29 | + |
| 30 | + _aaz_info = { |
| 31 | + "version": "2025-04-01", |
| 32 | + "resources": [ |
| 33 | + ["mgmt-plane", |
| 34 | + "/{resourceuri}/providers/microsoft.containerservice/deploymentsafeguards/default", "2025-04-01"], |
| 35 | + ] |
| 36 | + } |
| 37 | + |
| 38 | + AZ_SUPPORT_NO_WAIT = True |
| 39 | + |
| 40 | + def _handler(self, command_args): |
| 41 | + super()._handler(command_args) |
| 42 | + return self.build_lro_poller(self._execute_operations, self._output) |
| 43 | + |
| 44 | + _args_schema = None |
| 45 | + |
| 46 | + @classmethod |
| 47 | + def _build_arguments_schema(cls, *args, **kwargs): |
| 48 | + if cls._args_schema is not None: |
| 49 | + return cls._args_schema |
| 50 | + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) |
| 51 | + |
| 52 | + # define Arg Group "" |
| 53 | + |
| 54 | + _args_schema = cls._args_schema |
| 55 | + _args_schema.managed_cluster = AAZStrArg( |
| 56 | + options=["-c", "--cluster", "--managed-cluster"], |
| 57 | + help="The fully qualified Azure Resource manager identifier of the Managed Cluster.", |
| 58 | + required=False, |
| 59 | + ) |
| 60 | + |
| 61 | + # define Arg Group "Properties" |
| 62 | + |
| 63 | + _args_schema = cls._args_schema |
| 64 | + _args_schema.excluded_namespaces = AAZListArg( |
| 65 | + options=["--excluded-ns", "--excluded-namespaces"], |
| 66 | + arg_group="Properties", |
| 67 | + help="User defined list of namespaces to exclude from Deployment Safeguards. Deployments in these namespaces will not be checked against any safeguards", |
| 68 | + ) |
| 69 | + _args_schema.level = AAZStrArg( |
| 70 | + options=["--level"], |
| 71 | + arg_group="Properties", |
| 72 | + help="The deployment safeguards level. Possible values are Warn and Enforce", |
| 73 | + enum={"Enforce": "Enforce", "Warn": "Warn"}, |
| 74 | + ) |
| 75 | + |
| 76 | + excluded_namespaces = cls._args_schema.excluded_namespaces |
| 77 | + excluded_namespaces.Element = AAZStrArg() |
| 78 | + return cls._args_schema |
| 79 | + |
| 80 | + def _execute_operations(self): |
| 81 | + self.pre_operations() |
| 82 | + yield self.DeploymentSafeguardsCreate(ctx=self.ctx)() |
| 83 | + self.post_operations() |
| 84 | + |
| 85 | + @register_callback |
| 86 | + def pre_operations(self): |
| 87 | + pass |
| 88 | + |
| 89 | + @register_callback |
| 90 | + def post_operations(self): |
| 91 | + pass |
| 92 | + |
| 93 | + def _output(self, *args, **kwargs): |
| 94 | + result = self.deserialize_output( |
| 95 | + self.ctx.vars.instance, client_flatten=True) |
| 96 | + return result |
| 97 | + |
| 98 | + class DeploymentSafeguardsCreate(AAZHttpOperation): |
| 99 | + CLIENT_TYPE = "MgmtClient" |
| 100 | + |
| 101 | + def __call__(self, *args, **kwargs): |
| 102 | + request = self.make_request() |
| 103 | + session = self.client.send_request( |
| 104 | + request=request, stream=False, **kwargs) |
| 105 | + if session.http_response.status_code in [202]: |
| 106 | + return self.client.build_lro_polling( |
| 107 | + self.ctx.args.no_wait, |
| 108 | + session, |
| 109 | + self.on_200_201, |
| 110 | + self.on_error, |
| 111 | + lro_options={"final-state-via": "azure-async-operation"}, |
| 112 | + path_format_arguments=self.url_parameters, |
| 113 | + ) |
| 114 | + if session.http_response.status_code in [200, 201]: |
| 115 | + return self.client.build_lro_polling( |
| 116 | + self.ctx.args.no_wait, |
| 117 | + session, |
| 118 | + self.on_200_201, |
| 119 | + self.on_error, |
| 120 | + lro_options={"final-state-via": "azure-async-operation"}, |
| 121 | + path_format_arguments=self.url_parameters, |
| 122 | + ) |
| 123 | + |
| 124 | + return self.on_error(session.http_response) |
| 125 | + |
| 126 | + @property |
| 127 | + def url(self): |
| 128 | + return self.client.format_url( |
| 129 | + "/{resourceUri}/providers/Microsoft.ContainerService/deploymentSafeguards/default", |
| 130 | + **self.url_parameters |
| 131 | + ) |
| 132 | + |
| 133 | + @property |
| 134 | + def method(self): |
| 135 | + return "PUT" |
| 136 | + |
| 137 | + @property |
| 138 | + def error_format(self): |
| 139 | + return "MgmtErrorFormat" |
| 140 | + |
| 141 | + @property |
| 142 | + def url_parameters(self): |
| 143 | + parameters = { |
| 144 | + **self.serialize_url_param( |
| 145 | + "resourceUri", self.ctx.args.managed_cluster, |
| 146 | + required=True, |
| 147 | + ), |
| 148 | + } |
| 149 | + return parameters |
| 150 | + |
| 151 | + @property |
| 152 | + def query_parameters(self): |
| 153 | + parameters = { |
| 154 | + **self.serialize_query_param( |
| 155 | + "api-version", "2025-04-01", |
| 156 | + required=True, |
| 157 | + ), |
| 158 | + } |
| 159 | + return parameters |
| 160 | + |
| 161 | + @property |
| 162 | + def header_parameters(self): |
| 163 | + parameters = { |
| 164 | + **self.serialize_header_param( |
| 165 | + "Content-Type", "application/json", |
| 166 | + ), |
| 167 | + **self.serialize_header_param( |
| 168 | + "Accept", "application/json", |
| 169 | + ), |
| 170 | + } |
| 171 | + return parameters |
| 172 | + |
| 173 | + @property |
| 174 | + def content(self): |
| 175 | + _content_value, _builder = self.new_content_builder( |
| 176 | + self.ctx.args, |
| 177 | + typ=AAZObjectType, |
| 178 | + typ_kwargs={ |
| 179 | + "flags": {"required": True, "client_flatten": True}} |
| 180 | + ) |
| 181 | + _builder.set_prop("properties", AAZObjectType) |
| 182 | + |
| 183 | + properties = _builder.get(".properties") |
| 184 | + if properties is not None: |
| 185 | + properties.set_prop("excludedNamespaces", |
| 186 | + AAZListType, ".excluded_namespaces") |
| 187 | + properties.set_prop("level", AAZStrType, ".level", typ_kwargs={ |
| 188 | + "flags": {"required": True}}) |
| 189 | + |
| 190 | + excluded_namespaces = _builder.get( |
| 191 | + ".properties.excludedNamespaces") |
| 192 | + if excluded_namespaces is not None: |
| 193 | + excluded_namespaces.set_elements(AAZStrType, ".") |
| 194 | + |
| 195 | + return self.serialize_content(_content_value) |
| 196 | + |
| 197 | + def on_200_201(self, session): |
| 198 | + data = self.deserialize_http_content(session) |
| 199 | + self.ctx.set_var( |
| 200 | + "instance", |
| 201 | + data, |
| 202 | + schema_builder=self._build_schema_on_200_201 |
| 203 | + ) |
| 204 | + |
| 205 | + _schema_on_200_201 = None |
| 206 | + |
| 207 | + @classmethod |
| 208 | + def _build_schema_on_200_201(cls): |
| 209 | + if cls._schema_on_200_201 is not None: |
| 210 | + return cls._schema_on_200_201 |
| 211 | + |
| 212 | + cls._schema_on_200_201 = AAZObjectType() |
| 213 | + |
| 214 | + _schema_on_200_201 = cls._schema_on_200_201 |
| 215 | + _schema_on_200_201.e_tag = AAZStrType( |
| 216 | + serialized_name="eTag", |
| 217 | + flags={"read_only": True}, |
| 218 | + ) |
| 219 | + _schema_on_200_201.id = AAZStrType( |
| 220 | + flags={"read_only": True}, |
| 221 | + ) |
| 222 | + _schema_on_200_201.name = AAZStrType( |
| 223 | + flags={"read_only": True}, |
| 224 | + ) |
| 225 | + _schema_on_200_201.properties = AAZObjectType() |
| 226 | + _schema_on_200_201.system_data = AAZObjectType( |
| 227 | + serialized_name="systemData", |
| 228 | + flags={"read_only": True}, |
| 229 | + ) |
| 230 | + _schema_on_200_201.type = AAZStrType( |
| 231 | + flags={"read_only": True}, |
| 232 | + ) |
| 233 | + |
| 234 | + properties = cls._schema_on_200_201.properties |
| 235 | + properties.excluded_namespaces = AAZListType( |
| 236 | + serialized_name="excludedNamespaces", |
| 237 | + ) |
| 238 | + properties.level = AAZStrType( |
| 239 | + flags={"required": True}, |
| 240 | + ) |
| 241 | + properties.provisioning_state = AAZStrType( |
| 242 | + serialized_name="provisioningState", |
| 243 | + flags={"read_only": True}, |
| 244 | + ) |
| 245 | + properties.system_excluded_namespaces = AAZListType( |
| 246 | + serialized_name="systemExcludedNamespaces", |
| 247 | + flags={"read_only": True}, |
| 248 | + ) |
| 249 | + |
| 250 | + excluded_namespaces = cls._schema_on_200_201.properties.excluded_namespaces |
| 251 | + excluded_namespaces.Element = AAZStrType() |
| 252 | + |
| 253 | + system_excluded_namespaces = cls._schema_on_200_201.properties.system_excluded_namespaces |
| 254 | + system_excluded_namespaces.Element = AAZStrType() |
| 255 | + |
| 256 | + system_data = cls._schema_on_200_201.system_data |
| 257 | + system_data.created_at = AAZStrType( |
| 258 | + serialized_name="createdAt", |
| 259 | + ) |
| 260 | + system_data.created_by = AAZStrType( |
| 261 | + serialized_name="createdBy", |
| 262 | + ) |
| 263 | + system_data.created_by_type = AAZStrType( |
| 264 | + serialized_name="createdByType", |
| 265 | + ) |
| 266 | + system_data.last_modified_at = AAZStrType( |
| 267 | + serialized_name="lastModifiedAt", |
| 268 | + ) |
| 269 | + system_data.last_modified_by = AAZStrType( |
| 270 | + serialized_name="lastModifiedBy", |
| 271 | + ) |
| 272 | + system_data.last_modified_by_type = AAZStrType( |
| 273 | + serialized_name="lastModifiedByType", |
| 274 | + ) |
| 275 | + |
| 276 | + return cls._schema_on_200_201 |
| 277 | + |
| 278 | + |
| 279 | +class _CreateHelper: |
| 280 | + """Helper class for Create""" |
| 281 | + |
| 282 | + |
| 283 | +__all__ = ["Create"] |
0 commit comments