|
| 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 | + "storage advanced-platform-metric create", |
| 16 | + is_preview=True, |
| 17 | +) |
| 18 | +class Create(AAZCommand): |
| 19 | + """Create the advanced platform metrics rule for the storage account. |
| 20 | +
|
| 21 | + :example: Create AllContainersFilter AdvancedPlatformMetric |
| 22 | + az storage advanced-platform-metric create -g resource_group_name --account-name storage_account_name --enabled --rule-config-filter-type AllContainersFilter |
| 23 | +
|
| 24 | + :example: Create ContainerPrefixFilter AdvancedPlatformMetric |
| 25 | + az storage advanced-platform-metric create -g resource_group_name --account-name storage_account_name --enabled --rule-config-filter-type ContainerPrefixFilter --rule-config-filter-values logsprefix dataprefix |
| 26 | +
|
| 27 | + :example: Create ContainerListFilter AdvancedPlatformMetric |
| 28 | + az storage advanced-platform-metric create -g resource_group_name --account-name storage_account_name --enabled --rule-config-filter-type ContainerListFilter --rule-config-filter-values logs data |
| 29 | + """ |
| 30 | + |
| 31 | + _aaz_info = { |
| 32 | + "version": "2026-04-01", |
| 33 | + "resources": [ |
| 34 | + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.storage/storageaccounts/{}/advancedplatformmetrics/{}", "2026-04-01"], |
| 35 | + ] |
| 36 | + } |
| 37 | + |
| 38 | + def _handler(self, command_args): |
| 39 | + super()._handler(command_args) |
| 40 | + self._execute_operations() |
| 41 | + return self._output() |
| 42 | + |
| 43 | + _args_schema = None |
| 44 | + |
| 45 | + @classmethod |
| 46 | + def _build_arguments_schema(cls, *args, **kwargs): |
| 47 | + if cls._args_schema is not None: |
| 48 | + return cls._args_schema |
| 49 | + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) |
| 50 | + |
| 51 | + # define Arg Group "" |
| 52 | + |
| 53 | + _args_schema = cls._args_schema |
| 54 | + _args_schema.account_name = AAZStrArg( |
| 55 | + options=["--account-name"], |
| 56 | + help="The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only.", |
| 57 | + required=True, |
| 58 | + fmt=AAZStrArgFormat( |
| 59 | + pattern="^[a-z0-9]+$", |
| 60 | + max_length=24, |
| 61 | + min_length=3, |
| 62 | + ), |
| 63 | + ) |
| 64 | + _args_schema.advanced_platform_metrics_rule_type = AAZStrArg( |
| 65 | + options=["-n", "--name", "--advanced-platform-metrics-rule-type"], |
| 66 | + help="The type of the advanced platform metrics rule.", |
| 67 | + required=True, |
| 68 | + default="ContainerLevelCapacityMetrics", |
| 69 | + enum={"ContainerLevelCapacityMetrics": "ContainerLevelCapacityMetrics"}, |
| 70 | + ) |
| 71 | + _args_schema.resource_group = AAZResourceGroupNameArg( |
| 72 | + required=True, |
| 73 | + ) |
| 74 | + |
| 75 | + # define Arg Group "Properties" |
| 76 | + |
| 77 | + _args_schema = cls._args_schema |
| 78 | + _args_schema.enabled = AAZBoolArg( |
| 79 | + options=["--enabled"], |
| 80 | + arg_group="Properties", |
| 81 | + help="A boolean flag which enables the advanced platform metrics rule.", |
| 82 | + ) |
| 83 | + |
| 84 | + # define Arg Group "RuleConfig" |
| 85 | + |
| 86 | + _args_schema = cls._args_schema |
| 87 | + _args_schema.rule_config_filter_type = AAZStrArg( |
| 88 | + options=["--filter-type", "--rule-config-filter-type"], |
| 89 | + arg_group="RuleConfig", |
| 90 | + help="The type of filter applied to the rule. Possible values include: AllContainersFilter, ContainerPrefixFilter, ContainerListFilter.", |
| 91 | + enum={"AllContainersFilter": "AllContainersFilter", "ContainerListFilter": "ContainerListFilter", "ContainerPrefixFilter": "ContainerPrefixFilter"}, |
| 92 | + ) |
| 93 | + _args_schema.rule_config_filter_values = AAZListArg( |
| 94 | + options=["--filter-values", "--rule-config-filter-values"], |
| 95 | + arg_group="RuleConfig", |
| 96 | + help="The values for the filter applied to the rule. If filter type is AllContainersFilter, filter values should be empty. If filter type is ContainerPrefixFilter, filter values should contain a list of container prefixes. If filter type is ContainerListFilter, filter values should contain a list of container names.", |
| 97 | + ) |
| 98 | + |
| 99 | + rule_config_filter_values = cls._args_schema.rule_config_filter_values |
| 100 | + rule_config_filter_values.Element = AAZStrArg() |
| 101 | + return cls._args_schema |
| 102 | + |
| 103 | + def _execute_operations(self): |
| 104 | + self.pre_operations() |
| 105 | + self.AdvancedPlatformMetricsCreateOrUpdate(ctx=self.ctx)() |
| 106 | + self.post_operations() |
| 107 | + |
| 108 | + @register_callback |
| 109 | + def pre_operations(self): |
| 110 | + pass |
| 111 | + |
| 112 | + @register_callback |
| 113 | + def post_operations(self): |
| 114 | + pass |
| 115 | + |
| 116 | + def _output(self, *args, **kwargs): |
| 117 | + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) |
| 118 | + return result |
| 119 | + |
| 120 | + class AdvancedPlatformMetricsCreateOrUpdate(AAZHttpOperation): |
| 121 | + CLIENT_TYPE = "MgmtClient" |
| 122 | + |
| 123 | + def __call__(self, *args, **kwargs): |
| 124 | + request = self.make_request() |
| 125 | + session = self.client.send_request(request=request, stream=False, **kwargs) |
| 126 | + if session.http_response.status_code in [200, 201]: |
| 127 | + return self.on_200_201(session) |
| 128 | + |
| 129 | + return self.on_error(session.http_response) |
| 130 | + |
| 131 | + @property |
| 132 | + def url(self): |
| 133 | + return self.client.format_url( |
| 134 | + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/advancedPlatformMetrics/{advancedPlatformMetricsRuleType}", |
| 135 | + **self.url_parameters |
| 136 | + ) |
| 137 | + |
| 138 | + @property |
| 139 | + def method(self): |
| 140 | + return "PUT" |
| 141 | + |
| 142 | + @property |
| 143 | + def error_format(self): |
| 144 | + return "MgmtErrorFormat" |
| 145 | + |
| 146 | + @property |
| 147 | + def url_parameters(self): |
| 148 | + parameters = { |
| 149 | + **self.serialize_url_param( |
| 150 | + "accountName", self.ctx.args.account_name, |
| 151 | + required=True, |
| 152 | + ), |
| 153 | + **self.serialize_url_param( |
| 154 | + "advancedPlatformMetricsRuleType", self.ctx.args.advanced_platform_metrics_rule_type, |
| 155 | + required=True, |
| 156 | + ), |
| 157 | + **self.serialize_url_param( |
| 158 | + "resourceGroupName", self.ctx.args.resource_group, |
| 159 | + required=True, |
| 160 | + ), |
| 161 | + **self.serialize_url_param( |
| 162 | + "subscriptionId", self.ctx.subscription_id, |
| 163 | + required=True, |
| 164 | + ), |
| 165 | + } |
| 166 | + return parameters |
| 167 | + |
| 168 | + @property |
| 169 | + def query_parameters(self): |
| 170 | + parameters = { |
| 171 | + **self.serialize_query_param( |
| 172 | + "api-version", "2026-04-01", |
| 173 | + required=True, |
| 174 | + ), |
| 175 | + } |
| 176 | + return parameters |
| 177 | + |
| 178 | + @property |
| 179 | + def header_parameters(self): |
| 180 | + parameters = { |
| 181 | + **self.serialize_header_param( |
| 182 | + "Content-Type", "application/json", |
| 183 | + ), |
| 184 | + **self.serialize_header_param( |
| 185 | + "Accept", "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": {"required": True, "client_flatten": True}} |
| 196 | + ) |
| 197 | + _builder.set_prop("properties", AAZObjectType) |
| 198 | + |
| 199 | + properties = _builder.get(".properties") |
| 200 | + if properties is not None: |
| 201 | + properties.set_prop("enabled", AAZBoolType, ".enabled", typ_kwargs={"flags": {"required": True}}) |
| 202 | + properties.set_prop("ruleConfig", AAZObjectType, ".", typ_kwargs={"flags": {"required": True}}) |
| 203 | + |
| 204 | + rule_config = _builder.get(".properties.ruleConfig") |
| 205 | + if rule_config is not None: |
| 206 | + rule_config.set_prop("filterType", AAZStrType, ".rule_config_filter_type") |
| 207 | + rule_config.set_prop("filterValues", AAZListType, ".rule_config_filter_values") |
| 208 | + |
| 209 | + filter_values = _builder.get(".properties.ruleConfig.filterValues") |
| 210 | + if filter_values is not None: |
| 211 | + filter_values.set_elements(AAZStrType, ".") |
| 212 | + |
| 213 | + return self.serialize_content(_content_value) |
| 214 | + |
| 215 | + def on_200_201(self, session): |
| 216 | + data = self.deserialize_http_content(session) |
| 217 | + self.ctx.set_var( |
| 218 | + "instance", |
| 219 | + data, |
| 220 | + schema_builder=self._build_schema_on_200_201 |
| 221 | + ) |
| 222 | + |
| 223 | + _schema_on_200_201 = None |
| 224 | + |
| 225 | + @classmethod |
| 226 | + def _build_schema_on_200_201(cls): |
| 227 | + if cls._schema_on_200_201 is not None: |
| 228 | + return cls._schema_on_200_201 |
| 229 | + |
| 230 | + cls._schema_on_200_201 = AAZObjectType() |
| 231 | + |
| 232 | + _schema_on_200_201 = cls._schema_on_200_201 |
| 233 | + _schema_on_200_201.id = AAZStrType( |
| 234 | + flags={"read_only": True}, |
| 235 | + ) |
| 236 | + _schema_on_200_201.name = AAZStrType( |
| 237 | + flags={"read_only": True}, |
| 238 | + ) |
| 239 | + _schema_on_200_201.properties = AAZObjectType() |
| 240 | + _schema_on_200_201.system_data = AAZObjectType( |
| 241 | + serialized_name="systemData", |
| 242 | + flags={"read_only": True}, |
| 243 | + ) |
| 244 | + _schema_on_200_201.type = AAZStrType( |
| 245 | + flags={"read_only": True}, |
| 246 | + ) |
| 247 | + |
| 248 | + properties = cls._schema_on_200_201.properties |
| 249 | + properties.enabled = AAZBoolType( |
| 250 | + flags={"required": True}, |
| 251 | + ) |
| 252 | + properties.last_modified_time = AAZStrType( |
| 253 | + serialized_name="lastModifiedTime", |
| 254 | + flags={"read_only": True}, |
| 255 | + ) |
| 256 | + properties.metrics_emitted = AAZListType( |
| 257 | + serialized_name="metricsEmitted", |
| 258 | + flags={"read_only": True}, |
| 259 | + ) |
| 260 | + properties.rule_config = AAZObjectType( |
| 261 | + serialized_name="ruleConfig", |
| 262 | + flags={"required": True}, |
| 263 | + ) |
| 264 | + properties.rule_type = AAZStrType( |
| 265 | + serialized_name="ruleType", |
| 266 | + flags={"read_only": True}, |
| 267 | + ) |
| 268 | + |
| 269 | + metrics_emitted = cls._schema_on_200_201.properties.metrics_emitted |
| 270 | + metrics_emitted.Element = AAZStrType() |
| 271 | + |
| 272 | + rule_config = cls._schema_on_200_201.properties.rule_config |
| 273 | + rule_config.filter_type = AAZStrType( |
| 274 | + serialized_name="filterType", |
| 275 | + ) |
| 276 | + rule_config.filter_values = AAZListType( |
| 277 | + serialized_name="filterValues", |
| 278 | + ) |
| 279 | + |
| 280 | + filter_values = cls._schema_on_200_201.properties.rule_config.filter_values |
| 281 | + filter_values.Element = AAZStrType() |
| 282 | + |
| 283 | + system_data = cls._schema_on_200_201.system_data |
| 284 | + system_data.created_at = AAZStrType( |
| 285 | + serialized_name="createdAt", |
| 286 | + ) |
| 287 | + system_data.created_by = AAZStrType( |
| 288 | + serialized_name="createdBy", |
| 289 | + ) |
| 290 | + system_data.created_by_type = AAZStrType( |
| 291 | + serialized_name="createdByType", |
| 292 | + ) |
| 293 | + system_data.last_modified_at = AAZStrType( |
| 294 | + serialized_name="lastModifiedAt", |
| 295 | + ) |
| 296 | + system_data.last_modified_by = AAZStrType( |
| 297 | + serialized_name="lastModifiedBy", |
| 298 | + ) |
| 299 | + system_data.last_modified_by_type = AAZStrType( |
| 300 | + serialized_name="lastModifiedByType", |
| 301 | + ) |
| 302 | + |
| 303 | + return cls._schema_on_200_201 |
| 304 | + |
| 305 | + |
| 306 | +class _CreateHelper: |
| 307 | + """Helper class for Create""" |
| 308 | + |
| 309 | + |
| 310 | +__all__ = ["Create"] |
0 commit comments