|
| 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 List(AAZCommand): |
| 15 | + """List the metric values for a resource. |
| 16 | + """ |
| 17 | + |
| 18 | + _aaz_info = { |
| 19 | + "version": "2018-01-01", |
| 20 | + "resources": [ |
| 21 | + ["mgmt-plane", "/{resourceuri}/providers/microsoft.insights/metrics", "2018-01-01"], |
| 22 | + ] |
| 23 | + } |
| 24 | + |
| 25 | + def _handler(self, command_args): |
| 26 | + super()._handler(command_args) |
| 27 | + self._execute_operations() |
| 28 | + return self._output() |
| 29 | + |
| 30 | + _args_schema = None |
| 31 | + |
| 32 | + @classmethod |
| 33 | + def _build_arguments_schema(cls, *args, **kwargs): |
| 34 | + if cls._args_schema is not None: |
| 35 | + return cls._args_schema |
| 36 | + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) |
| 37 | + |
| 38 | + # define Arg Group "" |
| 39 | + |
| 40 | + _args_schema = cls._args_schema |
| 41 | + _args_schema.resource_uri = AAZStrArg( |
| 42 | + options=["--resource-uri"], |
| 43 | + help="The identifier of the resource.", |
| 44 | + required=True, |
| 45 | + ) |
| 46 | + _args_schema.aggregation = AAZStrArg( |
| 47 | + options=["--aggregation"], |
| 48 | + help="The list of aggregation types (comma separated) to retrieve.", |
| 49 | + ) |
| 50 | + _args_schema.filter = AAZStrArg( |
| 51 | + options=["--filter"], |
| 52 | + help="The **$filter** is used to reduce the set of metric data returned. Example: Metric contains metadata A, B and C. - Return all time series of C where A = a1 and B = b1 or b2 **$filter=A eq 'a1' and B eq 'b1' or B eq 'b2' and C eq '*'** - Invalid variant: **$filter=A eq 'a1' and B eq 'b1' and C eq '*' or B = 'b2'** This is invalid because the logical or operator cannot separate two different metadata names. - Return all time series where A = a1, B = b1 and C = c1: **$filter=A eq 'a1' and B eq 'b1' and C eq 'c1'** - Return all time series where A = a1 **$filter=A eq 'a1' and B eq '*' and C eq '*'**. Special case: When dimension name or dimension value uses round brackets. Eg: When dimension name is **dim (test) 1** Instead of using $filter= \"dim (test) 1 eq '*' \" use **$filter= \"dim %2528test%2529 1 eq '*' \"** When dimension name is **dim (test) 3** and dimension value is **dim3 (test) val** Instead of using $filter= \"dim (test) 3 eq 'dim3 (test) val' \" use **$filter= \"dim %2528test%2529 3 eq 'dim3 %2528test%2529 val' \"**", |
| 53 | + ) |
| 54 | + _args_schema.interval = AAZDurationArg( |
| 55 | + options=["--interval"], |
| 56 | + help="The interval (i.e. timegrain) of the query.", |
| 57 | + ) |
| 58 | + _args_schema.metricnames = AAZStrArg( |
| 59 | + options=["--metricnames"], |
| 60 | + help="The names of the metrics (comma separated) to retrieve. Special case: If a metricname itself has a comma in it then use %2 to indicate it. Eg: 'Metric,Name1' should be **'Metric%2Name1'**", |
| 61 | + ) |
| 62 | + _args_schema.metricnamespace = AAZStrArg( |
| 63 | + options=["--metricnamespace"], |
| 64 | + help="Metric namespace to query metric definitions for.", |
| 65 | + ) |
| 66 | + _args_schema.orderby = AAZStrArg( |
| 67 | + options=["--orderby"], |
| 68 | + help="The aggregation to use for sorting results and the direction of the sort. Only one order can be specified. Examples: sum asc.", |
| 69 | + ) |
| 70 | + _args_schema.result_type = AAZStrArg( |
| 71 | + options=["--result-type"], |
| 72 | + help="Reduces the set of data collected. The syntax allowed depends on the operation. See the operation's description for details.", |
| 73 | + enum={"Data": "Data", "Metadata": "Metadata"}, |
| 74 | + ) |
| 75 | + _args_schema.timespan = AAZStrArg( |
| 76 | + options=["--timespan"], |
| 77 | + help="The timespan of the query. It is a string with the following format 'startDateTime_ISO/endDateTime_ISO'.", |
| 78 | + ) |
| 79 | + _args_schema.top = AAZIntArg( |
| 80 | + options=["--top"], |
| 81 | + help="The maximum number of records to retrieve. Valid only if $filter is specified. Defaults to 10.", |
| 82 | + ) |
| 83 | + return cls._args_schema |
| 84 | + |
| 85 | + def _execute_operations(self): |
| 86 | + self.pre_operations() |
| 87 | + self.MetricsList(ctx=self.ctx)() |
| 88 | + self.post_operations() |
| 89 | + |
| 90 | + @register_callback |
| 91 | + def pre_operations(self): |
| 92 | + pass |
| 93 | + |
| 94 | + @register_callback |
| 95 | + def post_operations(self): |
| 96 | + pass |
| 97 | + |
| 98 | + def _output(self, *args, **kwargs): |
| 99 | + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) |
| 100 | + return result |
| 101 | + |
| 102 | + class MetricsList(AAZHttpOperation): |
| 103 | + CLIENT_TYPE = "MgmtClient" |
| 104 | + |
| 105 | + def __call__(self, *args, **kwargs): |
| 106 | + request = self.make_request() |
| 107 | + session = self.client.send_request(request=request, stream=False, **kwargs) |
| 108 | + if session.http_response.status_code in [200]: |
| 109 | + return self.on_200(session) |
| 110 | + |
| 111 | + return self.on_error(session.http_response) |
| 112 | + |
| 113 | + @property |
| 114 | + def url(self): |
| 115 | + return self.client.format_url( |
| 116 | + "/{resourceUri}/providers/Microsoft.Insights/metrics", |
| 117 | + **self.url_parameters |
| 118 | + ) |
| 119 | + |
| 120 | + @property |
| 121 | + def method(self): |
| 122 | + return "GET" |
| 123 | + |
| 124 | + @property |
| 125 | + def error_format(self): |
| 126 | + return "ODataV4Format" |
| 127 | + |
| 128 | + @property |
| 129 | + def url_parameters(self): |
| 130 | + parameters = { |
| 131 | + **self.serialize_url_param( |
| 132 | + "resourceUri", self.ctx.args.resource_uri, |
| 133 | + skip_quote=True, |
| 134 | + required=True, |
| 135 | + ), |
| 136 | + } |
| 137 | + return parameters |
| 138 | + |
| 139 | + @property |
| 140 | + def query_parameters(self): |
| 141 | + parameters = { |
| 142 | + **self.serialize_query_param( |
| 143 | + "$filter", self.ctx.args.filter, |
| 144 | + ), |
| 145 | + **self.serialize_query_param( |
| 146 | + "aggregation", self.ctx.args.aggregation, |
| 147 | + ), |
| 148 | + **self.serialize_query_param( |
| 149 | + "interval", self.ctx.args.interval, |
| 150 | + ), |
| 151 | + **self.serialize_query_param( |
| 152 | + "metricnames", self.ctx.args.metricnames, |
| 153 | + ), |
| 154 | + **self.serialize_query_param( |
| 155 | + "metricnamespace", self.ctx.args.metricnamespace, |
| 156 | + ), |
| 157 | + **self.serialize_query_param( |
| 158 | + "orderby", self.ctx.args.orderby, |
| 159 | + ), |
| 160 | + **self.serialize_query_param( |
| 161 | + "resultType", self.ctx.args.result_type, |
| 162 | + ), |
| 163 | + **self.serialize_query_param( |
| 164 | + "timespan", self.ctx.args.timespan, |
| 165 | + ), |
| 166 | + **self.serialize_query_param( |
| 167 | + "top", self.ctx.args.top, |
| 168 | + ), |
| 169 | + **self.serialize_query_param( |
| 170 | + "api-version", "2018-01-01", |
| 171 | + required=True, |
| 172 | + ), |
| 173 | + } |
| 174 | + return parameters |
| 175 | + |
| 176 | + @property |
| 177 | + def header_parameters(self): |
| 178 | + parameters = { |
| 179 | + **self.serialize_header_param( |
| 180 | + "Accept", "application/json", |
| 181 | + ), |
| 182 | + } |
| 183 | + return parameters |
| 184 | + |
| 185 | + def on_200(self, session): |
| 186 | + data = self.deserialize_http_content(session) |
| 187 | + self.ctx.set_var( |
| 188 | + "instance", |
| 189 | + data, |
| 190 | + schema_builder=self._build_schema_on_200 |
| 191 | + ) |
| 192 | + |
| 193 | + _schema_on_200 = None |
| 194 | + |
| 195 | + @classmethod |
| 196 | + def _build_schema_on_200(cls): |
| 197 | + if cls._schema_on_200 is not None: |
| 198 | + return cls._schema_on_200 |
| 199 | + |
| 200 | + cls._schema_on_200 = AAZObjectType() |
| 201 | + |
| 202 | + _schema_on_200 = cls._schema_on_200 |
| 203 | + _schema_on_200.cost = AAZIntType() |
| 204 | + _schema_on_200.interval = AAZStrType() |
| 205 | + _schema_on_200.namespace = AAZStrType() |
| 206 | + _schema_on_200.resourceregion = AAZStrType() |
| 207 | + _schema_on_200.timespan = AAZStrType( |
| 208 | + flags={"required": True}, |
| 209 | + ) |
| 210 | + _schema_on_200.value = AAZListType( |
| 211 | + flags={"required": True}, |
| 212 | + ) |
| 213 | + |
| 214 | + value = cls._schema_on_200.value |
| 215 | + value.Element = AAZObjectType() |
| 216 | + |
| 217 | + _element = cls._schema_on_200.value.Element |
| 218 | + _element.display_description = AAZStrType( |
| 219 | + serialized_name="displayDescription", |
| 220 | + ) |
| 221 | + _element.error_code = AAZStrType( |
| 222 | + serialized_name="errorCode", |
| 223 | + ) |
| 224 | + _element.error_message = AAZStrType( |
| 225 | + serialized_name="errorMessage", |
| 226 | + ) |
| 227 | + _element.id = AAZStrType( |
| 228 | + flags={"required": True}, |
| 229 | + ) |
| 230 | + _element.name = AAZObjectType( |
| 231 | + flags={"required": True}, |
| 232 | + ) |
| 233 | + _ListHelper._build_schema_localizable_string_read(_element.name) |
| 234 | + _element.timeseries = AAZListType( |
| 235 | + flags={"required": True}, |
| 236 | + ) |
| 237 | + _element.type = AAZStrType( |
| 238 | + flags={"required": True}, |
| 239 | + ) |
| 240 | + _element.unit = AAZStrType( |
| 241 | + flags={"required": True}, |
| 242 | + ) |
| 243 | + |
| 244 | + timeseries = cls._schema_on_200.value.Element.timeseries |
| 245 | + timeseries.Element = AAZObjectType() |
| 246 | + |
| 247 | + _element = cls._schema_on_200.value.Element.timeseries.Element |
| 248 | + _element.data = AAZListType() |
| 249 | + _element.metadatavalues = AAZListType() |
| 250 | + |
| 251 | + data = cls._schema_on_200.value.Element.timeseries.Element.data |
| 252 | + data.Element = AAZObjectType() |
| 253 | + |
| 254 | + _element = cls._schema_on_200.value.Element.timeseries.Element.data.Element |
| 255 | + _element.average = AAZFloatType() |
| 256 | + _element.count = AAZFloatType() |
| 257 | + _element.maximum = AAZFloatType() |
| 258 | + _element.minimum = AAZFloatType() |
| 259 | + _element.time_stamp = AAZStrType( |
| 260 | + serialized_name="timeStamp", |
| 261 | + flags={"required": True}, |
| 262 | + ) |
| 263 | + _element.total = AAZFloatType() |
| 264 | + |
| 265 | + metadatavalues = cls._schema_on_200.value.Element.timeseries.Element.metadatavalues |
| 266 | + metadatavalues.Element = AAZObjectType() |
| 267 | + |
| 268 | + _element = cls._schema_on_200.value.Element.timeseries.Element.metadatavalues.Element |
| 269 | + _element.name = AAZObjectType() |
| 270 | + _ListHelper._build_schema_localizable_string_read(_element.name) |
| 271 | + _element.value = AAZStrType() |
| 272 | + |
| 273 | + return cls._schema_on_200 |
| 274 | + |
| 275 | + |
| 276 | +class _ListHelper: |
| 277 | + """Helper class for List""" |
| 278 | + |
| 279 | + _schema_localizable_string_read = None |
| 280 | + |
| 281 | + @classmethod |
| 282 | + def _build_schema_localizable_string_read(cls, _schema): |
| 283 | + if cls._schema_localizable_string_read is not None: |
| 284 | + _schema.localized_value = cls._schema_localizable_string_read.localized_value |
| 285 | + _schema.value = cls._schema_localizable_string_read.value |
| 286 | + return |
| 287 | + |
| 288 | + cls._schema_localizable_string_read = _schema_localizable_string_read = AAZObjectType() |
| 289 | + |
| 290 | + localizable_string_read = _schema_localizable_string_read |
| 291 | + localizable_string_read.localized_value = AAZStrType( |
| 292 | + serialized_name="localizedValue", |
| 293 | + ) |
| 294 | + localizable_string_read.value = AAZStrType( |
| 295 | + flags={"required": True}, |
| 296 | + ) |
| 297 | + |
| 298 | + _schema.localized_value = cls._schema_localizable_string_read.localized_value |
| 299 | + _schema.value = cls._schema_localizable_string_read.value |
| 300 | + |
| 301 | + |
| 302 | +__all__ = ["List"] |
0 commit comments