From 9466fe7222d74296534b8e63575255163474a23f Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Thu, 13 Sep 2018 17:07:12 -0700 Subject: [PATCH 1/3] [AutoPR monitor/data-plane] Publish public preview swagger spec for "Azure metrics Ingestion REST API" (#3322) * Generated from 89a8ab408aa67ec55ed702e229ec254dc39df5a5 Address the PR comments - Fix the readme.md naming incompatibilities - Remove the c#-ish namespace prefix * Packaging update of azure-monitor * Generated from 11666b828c6a64278ae35a0898f1c4f00203f61d -Drop all the types that recursively came with ObjectResult and use simple object type instead. This should make the swagger spec clean and more easily maintainable in the long run --- azure-monitor/HISTORY.rst | 9 + azure-monitor/MANIFEST.in | 2 + azure-monitor/README.rst | 49 ++++++ azure-monitor/azure/__init__.py | 1 + azure-monitor/azure/monitor/__init__.py | 18 ++ .../azure/monitor/azure_metrics_client.py | 162 ++++++++++++++++++ .../azure/monitor/models/__init__.py | 37 ++++ .../azure/monitor/models/api_error.py | 32 ++++ .../azure/monitor/models/api_error_py3.py | 32 ++++ .../monitor/models/api_failure_response.py | 28 +++ .../models/api_failure_response_py3.py | 28 +++ .../monitor/models/azure_metrics_base_data.py | 41 +++++ .../models/azure_metrics_base_data_py3.py | 41 +++++ .../monitor/models/azure_metrics_data.py | 28 +++ .../monitor/models/azure_metrics_data_py3.py | 28 +++ .../monitor/models/azure_metrics_document.py | 32 ++++ .../models/azure_metrics_document_py3.py | 32 ++++ .../monitor/models/azure_metrics_result.py | 45 +++++ .../models/azure_metrics_result_py3.py | 45 +++++ .../monitor/models/azure_time_series_data.py | 44 +++++ .../models/azure_time_series_data_py3.py | 44 +++++ azure-monitor/azure/monitor/version.py | 13 ++ azure-monitor/azure_bdist_wheel.py | 54 ++++++ azure-monitor/sdk_packaging.toml | 6 + azure-monitor/setup.cfg | 3 + azure-monitor/setup.py | 86 ++++++++++ 26 files changed, 940 insertions(+) create mode 100644 azure-monitor/HISTORY.rst create mode 100644 azure-monitor/MANIFEST.in create mode 100644 azure-monitor/README.rst create mode 100644 azure-monitor/azure/__init__.py create mode 100644 azure-monitor/azure/monitor/__init__.py create mode 100644 azure-monitor/azure/monitor/azure_metrics_client.py create mode 100644 azure-monitor/azure/monitor/models/__init__.py create mode 100644 azure-monitor/azure/monitor/models/api_error.py create mode 100644 azure-monitor/azure/monitor/models/api_error_py3.py create mode 100644 azure-monitor/azure/monitor/models/api_failure_response.py create mode 100644 azure-monitor/azure/monitor/models/api_failure_response_py3.py create mode 100644 azure-monitor/azure/monitor/models/azure_metrics_base_data.py create mode 100644 azure-monitor/azure/monitor/models/azure_metrics_base_data_py3.py create mode 100644 azure-monitor/azure/monitor/models/azure_metrics_data.py create mode 100644 azure-monitor/azure/monitor/models/azure_metrics_data_py3.py create mode 100644 azure-monitor/azure/monitor/models/azure_metrics_document.py create mode 100644 azure-monitor/azure/monitor/models/azure_metrics_document_py3.py create mode 100644 azure-monitor/azure/monitor/models/azure_metrics_result.py create mode 100644 azure-monitor/azure/monitor/models/azure_metrics_result_py3.py create mode 100644 azure-monitor/azure/monitor/models/azure_time_series_data.py create mode 100644 azure-monitor/azure/monitor/models/azure_time_series_data_py3.py create mode 100644 azure-monitor/azure/monitor/version.py create mode 100644 azure-monitor/azure_bdist_wheel.py create mode 100644 azure-monitor/sdk_packaging.toml create mode 100644 azure-monitor/setup.cfg create mode 100644 azure-monitor/setup.py diff --git a/azure-monitor/HISTORY.rst b/azure-monitor/HISTORY.rst new file mode 100644 index 000000000000..8924d5d6c445 --- /dev/null +++ b/azure-monitor/HISTORY.rst @@ -0,0 +1,9 @@ +.. :changelog: + +Release History +=============== + +0.1.0 (1970-01-01) +++++++++++++++++++ + +* Initial Release diff --git a/azure-monitor/MANIFEST.in b/azure-monitor/MANIFEST.in new file mode 100644 index 000000000000..9ecaeb15de50 --- /dev/null +++ b/azure-monitor/MANIFEST.in @@ -0,0 +1,2 @@ +include *.rst +include azure_bdist_wheel.py \ No newline at end of file diff --git a/azure-monitor/README.rst b/azure-monitor/README.rst new file mode 100644 index 000000000000..45de4e6b43dd --- /dev/null +++ b/azure-monitor/README.rst @@ -0,0 +1,49 @@ +Microsoft Azure SDK for Python +============================== + +This is the Microsoft Azure MyService Management Client Library. + +Azure Resource Manager (ARM) is the next generation of management APIs that +replace the old Azure Service Management (ASM). + +This package has been tested with Python 2.7, 3.4, 3.5, 3.6 and 3.7. + +For the older Azure Service Management (ASM) libraries, see +`azure-servicemanagement-legacy `__ library. + +For a more complete set of Azure libraries, see the `azure `__ bundle package. + + +Compatibility +============= + +**IMPORTANT**: If you have an earlier version of the azure package +(version < 1.0), you should uninstall it before installing this package. + +You can check the version using pip: + +.. code:: shell + + pip freeze + +If you see azure==0.11.0 (or any version below 1.0), uninstall it first: + +.. code:: shell + + pip uninstall azure + + +Usage +===== + +For code examples, see `MyService Management +`__ +on docs.microsoft.com. + + +Provide Feedback +================ + +If you encounter any bugs or have suggestions, please file an issue in the +`Issues `__ +section of the project. diff --git a/azure-monitor/azure/__init__.py b/azure-monitor/azure/__init__.py new file mode 100644 index 000000000000..de40ea7ca058 --- /dev/null +++ b/azure-monitor/azure/__init__.py @@ -0,0 +1 @@ +__import__('pkg_resources').declare_namespace(__name__) diff --git a/azure-monitor/azure/monitor/__init__.py b/azure-monitor/azure/monitor/__init__.py new file mode 100644 index 000000000000..64373a72d0eb --- /dev/null +++ b/azure-monitor/azure/monitor/__init__.py @@ -0,0 +1,18 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from .azure_metrics_client import AzureMetricsClient +from .version import VERSION + +__all__ = ['AzureMetricsClient'] + +__version__ = VERSION + diff --git a/azure-monitor/azure/monitor/azure_metrics_client.py b/azure-monitor/azure/monitor/azure_metrics_client.py new file mode 100644 index 000000000000..68db3bc28f5b --- /dev/null +++ b/azure-monitor/azure/monitor/azure_metrics_client.py @@ -0,0 +1,162 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.service_client import SDKClient +from msrest import Serializer, Deserializer +from msrestazure import AzureConfiguration +from .version import VERSION +from msrest.pipeline import ClientRawResponse +import uuid +from . import models + + +class AzureMetricsClientConfiguration(AzureConfiguration): + """Configuration for AzureMetricsClient + Note that all parameters used to create this instance are saved as instance + attributes. + + :param credentials: Credentials needed for the client to connect to Azure. + :type credentials: :mod:`A msrestazure Credentials + object` + :param str base_url: Service URL + """ + + def __init__( + self, credentials, base_url=None): + + if credentials is None: + raise ValueError("Parameter 'credentials' must not be None.") + if not base_url: + base_url = 'https://monitoring.azure.com' + + super(AzureMetricsClientConfiguration, self).__init__(base_url) + + self.add_user_agent('azure-monitor/{}'.format(VERSION)) + self.add_user_agent('Azure-SDK-For-Python') + + self.credentials = credentials + + +class AzureMetricsClient(SDKClient): + """Monitor Management Client + + :ivar config: Configuration for client. + :vartype config: AzureMetricsClientConfiguration + + :param credentials: Credentials needed for the client to connect to Azure. + :type credentials: :mod:`A msrestazure Credentials + object` + :param str base_url: Service URL + """ + + def __init__( + self, credentials, base_url=None): + + self.config = AzureMetricsClientConfiguration(credentials, base_url) + super(AzureMetricsClient, self).__init__(self.config.credentials, self.config) + + client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} + self.api_version = '2018-09-01-preview' + self._serialize = Serializer(client_models) + self._deserialize = Deserializer(client_models) + + + def azure_monitor_custom_metrics_ingestion_api( + self, subscription_id, resource_group_name, resource_provider, resource_type_name, resource_name, content_type=None, content_length=None, time=None, data=None, custom_headers=None, raw=False, **operation_config): + """Ingestion API used by Azure custom metrics + Responsible of below operation + 1. Authorize the request + 2. Deserialize payload request body + 3. Perform validation of the payload + 4. Commits the payload for metrics ingestion. + + :param subscription_id: The azure subscription id + :type subscription_id: str + :param resource_group_name: The ARM resource group name + :type resource_group_name: str + :param resource_provider: The ARM resource provider name + :type resource_provider: str + :param resource_type_name: The ARM resource type name + :type resource_type_name: str + :param resource_name: The ARM resource name + :type resource_name: str + :param content_type: Supports application/json and + application/x-ndjson + :type content_type: str + :param content_length: Content length of the payload + :type content_length: int + :param time: Gets or sets Time property (in ISO 8601 format) + :type time: str + :param data: + :type data: ~azure.monitor.models.AzureMetricsData + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: AzureMetricsResult or ClientRawResponse if raw=true + :rtype: ~azure.monitor.models.AzureMetricsResult or + ~msrest.pipeline.ClientRawResponse + :raises: + :class:`AzureMetricsResultException` + """ + body = models.AzureMetricsDocument(time=time, data=data) + + # Construct URL + url = self.azure_monitor_custom_metrics_ingestion_api.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceProvider': self._serialize.url("resource_provider", resource_provider, 'str'), + 'resourceTypeName': self._serialize.url("resource_type_name", resource_type_name, 'str'), + 'resourceName': self._serialize.url("resource_name", resource_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if content_type is not None: + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + if content_length is not None: + header_parameters['Content-Length'] = self._serialize.header("content_length", content_length, 'int') + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(body, 'AzureMetricsDocument') + + # Construct and send request + request = self._client.post(url, query_parameters, header_parameters, body_content) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.AzureMetricsResultException(self._deserialize, response) + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('AzureMetricsResult', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + azure_monitor_custom_metrics_ingestion_api.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProvider}/{resourceTypeName}/{resourceName}/metrics'} diff --git a/azure-monitor/azure/monitor/models/__init__.py b/azure-monitor/azure/monitor/models/__init__.py new file mode 100644 index 000000000000..bf624cd941ad --- /dev/null +++ b/azure-monitor/azure/monitor/models/__init__.py @@ -0,0 +1,37 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +try: + from .azure_time_series_data_py3 import AzureTimeSeriesData + from .azure_metrics_base_data_py3 import AzureMetricsBaseData + from .azure_metrics_data_py3 import AzureMetricsData + from .azure_metrics_document_py3 import AzureMetricsDocument + from .api_error_py3 import ApiError + from .api_failure_response_py3 import ApiFailureResponse + from .azure_metrics_result_py3 import AzureMetricsResult, AzureMetricsResultException +except (SyntaxError, ImportError): + from .azure_time_series_data import AzureTimeSeriesData + from .azure_metrics_base_data import AzureMetricsBaseData + from .azure_metrics_data import AzureMetricsData + from .azure_metrics_document import AzureMetricsDocument + from .api_error import ApiError + from .api_failure_response import ApiFailureResponse + from .azure_metrics_result import AzureMetricsResult, AzureMetricsResultException + +__all__ = [ + 'AzureTimeSeriesData', + 'AzureMetricsBaseData', + 'AzureMetricsData', + 'AzureMetricsDocument', + 'ApiError', + 'ApiFailureResponse', + 'AzureMetricsResult', 'AzureMetricsResultException', +] diff --git a/azure-monitor/azure/monitor/models/api_error.py b/azure-monitor/azure/monitor/models/api_error.py new file mode 100644 index 000000000000..907b47b54f2b --- /dev/null +++ b/azure-monitor/azure/monitor/models/api_error.py @@ -0,0 +1,32 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ApiError(Model): + """ApiError. + + :param code: Gets or sets the azure metrics error code + :type code: str + :param message: Gets or sets the azure metrics error message + :type message: str + """ + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + } + + def __init__(self, **kwargs): + super(ApiError, self).__init__(**kwargs) + self.code = kwargs.get('code', None) + self.message = kwargs.get('message', None) diff --git a/azure-monitor/azure/monitor/models/api_error_py3.py b/azure-monitor/azure/monitor/models/api_error_py3.py new file mode 100644 index 000000000000..84d0ad7f2475 --- /dev/null +++ b/azure-monitor/azure/monitor/models/api_error_py3.py @@ -0,0 +1,32 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ApiError(Model): + """ApiError. + + :param code: Gets or sets the azure metrics error code + :type code: str + :param message: Gets or sets the azure metrics error message + :type message: str + """ + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + } + + def __init__(self, *, code: str=None, message: str=None, **kwargs) -> None: + super(ApiError, self).__init__(**kwargs) + self.code = code + self.message = message diff --git a/azure-monitor/azure/monitor/models/api_failure_response.py b/azure-monitor/azure/monitor/models/api_failure_response.py new file mode 100644 index 000000000000..6575317af44c --- /dev/null +++ b/azure-monitor/azure/monitor/models/api_failure_response.py @@ -0,0 +1,28 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ApiFailureResponse(Model): + """ApiFailureResponse. + + :param error: + :type error: ~azure.monitor.models.ApiError + """ + + _attribute_map = { + 'error': {'key': 'error', 'type': 'ApiError'}, + } + + def __init__(self, **kwargs): + super(ApiFailureResponse, self).__init__(**kwargs) + self.error = kwargs.get('error', None) diff --git a/azure-monitor/azure/monitor/models/api_failure_response_py3.py b/azure-monitor/azure/monitor/models/api_failure_response_py3.py new file mode 100644 index 000000000000..d3155441153b --- /dev/null +++ b/azure-monitor/azure/monitor/models/api_failure_response_py3.py @@ -0,0 +1,28 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class ApiFailureResponse(Model): + """ApiFailureResponse. + + :param error: + :type error: ~azure.monitor.models.ApiError + """ + + _attribute_map = { + 'error': {'key': 'error', 'type': 'ApiError'}, + } + + def __init__(self, *, error=None, **kwargs) -> None: + super(ApiFailureResponse, self).__init__(**kwargs) + self.error = error diff --git a/azure-monitor/azure/monitor/models/azure_metrics_base_data.py b/azure-monitor/azure/monitor/models/azure_metrics_base_data.py new file mode 100644 index 000000000000..1ce686a8903b --- /dev/null +++ b/azure-monitor/azure/monitor/models/azure_metrics_base_data.py @@ -0,0 +1,41 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class AzureMetricsBaseData(Model): + """AzureMetricsBaseData. + + :param metric: Gets or sets the Metric name + :type metric: str + :param namespace: Gets or sets the Metric namespace + :type namespace: str + :param dim_names: Gets or sets the list of dimension names (optional) + :type dim_names: list[str] + :param series: Gets or sets the list of time series data for the metric + (one per unique dimension combination) + :type series: list[~azure.monitor.models.AzureTimeSeriesData] + """ + + _attribute_map = { + 'metric': {'key': 'metric', 'type': 'str'}, + 'namespace': {'key': 'namespace', 'type': 'str'}, + 'dim_names': {'key': 'dimNames', 'type': '[str]'}, + 'series': {'key': 'series', 'type': '[AzureTimeSeriesData]'}, + } + + def __init__(self, **kwargs): + super(AzureMetricsBaseData, self).__init__(**kwargs) + self.metric = kwargs.get('metric', None) + self.namespace = kwargs.get('namespace', None) + self.dim_names = kwargs.get('dim_names', None) + self.series = kwargs.get('series', None) diff --git a/azure-monitor/azure/monitor/models/azure_metrics_base_data_py3.py b/azure-monitor/azure/monitor/models/azure_metrics_base_data_py3.py new file mode 100644 index 000000000000..de1716f325c2 --- /dev/null +++ b/azure-monitor/azure/monitor/models/azure_metrics_base_data_py3.py @@ -0,0 +1,41 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class AzureMetricsBaseData(Model): + """AzureMetricsBaseData. + + :param metric: Gets or sets the Metric name + :type metric: str + :param namespace: Gets or sets the Metric namespace + :type namespace: str + :param dim_names: Gets or sets the list of dimension names (optional) + :type dim_names: list[str] + :param series: Gets or sets the list of time series data for the metric + (one per unique dimension combination) + :type series: list[~azure.monitor.models.AzureTimeSeriesData] + """ + + _attribute_map = { + 'metric': {'key': 'metric', 'type': 'str'}, + 'namespace': {'key': 'namespace', 'type': 'str'}, + 'dim_names': {'key': 'dimNames', 'type': '[str]'}, + 'series': {'key': 'series', 'type': '[AzureTimeSeriesData]'}, + } + + def __init__(self, *, metric: str=None, namespace: str=None, dim_names=None, series=None, **kwargs) -> None: + super(AzureMetricsBaseData, self).__init__(**kwargs) + self.metric = metric + self.namespace = namespace + self.dim_names = dim_names + self.series = series diff --git a/azure-monitor/azure/monitor/models/azure_metrics_data.py b/azure-monitor/azure/monitor/models/azure_metrics_data.py new file mode 100644 index 000000000000..75401e227ac9 --- /dev/null +++ b/azure-monitor/azure/monitor/models/azure_metrics_data.py @@ -0,0 +1,28 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class AzureMetricsData(Model): + """AzureMetricsData. + + :param base_data: + :type base_data: ~azure.monitor.models.AzureMetricsBaseData + """ + + _attribute_map = { + 'base_data': {'key': 'baseData', 'type': 'AzureMetricsBaseData'}, + } + + def __init__(self, **kwargs): + super(AzureMetricsData, self).__init__(**kwargs) + self.base_data = kwargs.get('base_data', None) diff --git a/azure-monitor/azure/monitor/models/azure_metrics_data_py3.py b/azure-monitor/azure/monitor/models/azure_metrics_data_py3.py new file mode 100644 index 000000000000..9f3d6cabf506 --- /dev/null +++ b/azure-monitor/azure/monitor/models/azure_metrics_data_py3.py @@ -0,0 +1,28 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class AzureMetricsData(Model): + """AzureMetricsData. + + :param base_data: + :type base_data: ~azure.monitor.models.AzureMetricsBaseData + """ + + _attribute_map = { + 'base_data': {'key': 'baseData', 'type': 'AzureMetricsBaseData'}, + } + + def __init__(self, *, base_data=None, **kwargs) -> None: + super(AzureMetricsData, self).__init__(**kwargs) + self.base_data = base_data diff --git a/azure-monitor/azure/monitor/models/azure_metrics_document.py b/azure-monitor/azure/monitor/models/azure_metrics_document.py new file mode 100644 index 000000000000..dcfed41944c9 --- /dev/null +++ b/azure-monitor/azure/monitor/models/azure_metrics_document.py @@ -0,0 +1,32 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class AzureMetricsDocument(Model): + """AzureMetricsDocument. + + :param time: Gets or sets Time property (in ISO 8601 format) + :type time: str + :param data: + :type data: ~azure.monitor.models.AzureMetricsData + """ + + _attribute_map = { + 'time': {'key': 'time', 'type': 'str'}, + 'data': {'key': 'data', 'type': 'AzureMetricsData'}, + } + + def __init__(self, **kwargs): + super(AzureMetricsDocument, self).__init__(**kwargs) + self.time = kwargs.get('time', None) + self.data = kwargs.get('data', None) diff --git a/azure-monitor/azure/monitor/models/azure_metrics_document_py3.py b/azure-monitor/azure/monitor/models/azure_metrics_document_py3.py new file mode 100644 index 000000000000..ad9514c28e7f --- /dev/null +++ b/azure-monitor/azure/monitor/models/azure_metrics_document_py3.py @@ -0,0 +1,32 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class AzureMetricsDocument(Model): + """AzureMetricsDocument. + + :param time: Gets or sets Time property (in ISO 8601 format) + :type time: str + :param data: + :type data: ~azure.monitor.models.AzureMetricsData + """ + + _attribute_map = { + 'time': {'key': 'time', 'type': 'str'}, + 'data': {'key': 'data', 'type': 'AzureMetricsData'}, + } + + def __init__(self, *, time: str=None, data=None, **kwargs) -> None: + super(AzureMetricsDocument, self).__init__(**kwargs) + self.time = time + self.data = data diff --git a/azure-monitor/azure/monitor/models/azure_metrics_result.py b/azure-monitor/azure/monitor/models/azure_metrics_result.py new file mode 100644 index 000000000000..f97bb493bd60 --- /dev/null +++ b/azure-monitor/azure/monitor/models/azure_metrics_result.py @@ -0,0 +1,45 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model +from msrest.exceptions import HttpOperationError + + +class AzureMetricsResult(Model): + """AzureMetricsResult. + + :param status_code: Http status code response + :type status_code: int + :param api_failure_response: + :type api_failure_response: ~azure.monitor.models.ApiFailureResponse + """ + + _attribute_map = { + 'status_code': {'key': 'statusCode', 'type': 'int'}, + 'api_failure_response': {'key': 'apiFailureResponse', 'type': 'ApiFailureResponse'}, + } + + def __init__(self, **kwargs): + super(AzureMetricsResult, self).__init__(**kwargs) + self.status_code = kwargs.get('status_code', None) + self.api_failure_response = kwargs.get('api_failure_response', None) + + +class AzureMetricsResultException(HttpOperationError): + """Server responsed with exception of type: 'AzureMetricsResult'. + + :param deserialize: A deserializer + :param response: Server response to be deserialized. + """ + + def __init__(self, deserialize, response, *args): + + super(AzureMetricsResultException, self).__init__(deserialize, response, 'AzureMetricsResult', *args) diff --git a/azure-monitor/azure/monitor/models/azure_metrics_result_py3.py b/azure-monitor/azure/monitor/models/azure_metrics_result_py3.py new file mode 100644 index 000000000000..56d5c1ddbeea --- /dev/null +++ b/azure-monitor/azure/monitor/models/azure_metrics_result_py3.py @@ -0,0 +1,45 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model +from msrest.exceptions import HttpOperationError + + +class AzureMetricsResult(Model): + """AzureMetricsResult. + + :param status_code: Http status code response + :type status_code: int + :param api_failure_response: + :type api_failure_response: ~azure.monitor.models.ApiFailureResponse + """ + + _attribute_map = { + 'status_code': {'key': 'statusCode', 'type': 'int'}, + 'api_failure_response': {'key': 'apiFailureResponse', 'type': 'ApiFailureResponse'}, + } + + def __init__(self, *, status_code: int=None, api_failure_response=None, **kwargs) -> None: + super(AzureMetricsResult, self).__init__(**kwargs) + self.status_code = status_code + self.api_failure_response = api_failure_response + + +class AzureMetricsResultException(HttpOperationError): + """Server responsed with exception of type: 'AzureMetricsResult'. + + :param deserialize: A deserializer + :param response: Server response to be deserialized. + """ + + def __init__(self, deserialize, response, *args): + + super(AzureMetricsResultException, self).__init__(deserialize, response, 'AzureMetricsResult', *args) diff --git a/azure-monitor/azure/monitor/models/azure_time_series_data.py b/azure-monitor/azure/monitor/models/azure_time_series_data.py new file mode 100644 index 000000000000..3c23d80624cf --- /dev/null +++ b/azure-monitor/azure/monitor/models/azure_time_series_data.py @@ -0,0 +1,44 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class AzureTimeSeriesData(Model): + """AzureTimeSeriesData. + + :param dim_values: Gets or sets dimension values + :type dim_values: list[str] + :param min: Gets or sets Min value + :type min: float + :param max: Gets or sets Max value + :type max: float + :param sum: Gets or sets Sum value + :type sum: float + :param count: Gets or sets Count value + :type count: int + """ + + _attribute_map = { + 'dim_values': {'key': 'dimValues', 'type': '[str]'}, + 'min': {'key': 'min', 'type': 'float'}, + 'max': {'key': 'max', 'type': 'float'}, + 'sum': {'key': 'sum', 'type': 'float'}, + 'count': {'key': 'count', 'type': 'int'}, + } + + def __init__(self, **kwargs): + super(AzureTimeSeriesData, self).__init__(**kwargs) + self.dim_values = kwargs.get('dim_values', None) + self.min = kwargs.get('min', None) + self.max = kwargs.get('max', None) + self.sum = kwargs.get('sum', None) + self.count = kwargs.get('count', None) diff --git a/azure-monitor/azure/monitor/models/azure_time_series_data_py3.py b/azure-monitor/azure/monitor/models/azure_time_series_data_py3.py new file mode 100644 index 000000000000..12a67eaf8985 --- /dev/null +++ b/azure-monitor/azure/monitor/models/azure_time_series_data_py3.py @@ -0,0 +1,44 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from msrest.serialization import Model + + +class AzureTimeSeriesData(Model): + """AzureTimeSeriesData. + + :param dim_values: Gets or sets dimension values + :type dim_values: list[str] + :param min: Gets or sets Min value + :type min: float + :param max: Gets or sets Max value + :type max: float + :param sum: Gets or sets Sum value + :type sum: float + :param count: Gets or sets Count value + :type count: int + """ + + _attribute_map = { + 'dim_values': {'key': 'dimValues', 'type': '[str]'}, + 'min': {'key': 'min', 'type': 'float'}, + 'max': {'key': 'max', 'type': 'float'}, + 'sum': {'key': 'sum', 'type': 'float'}, + 'count': {'key': 'count', 'type': 'int'}, + } + + def __init__(self, *, dim_values=None, min: float=None, max: float=None, sum: float=None, count: int=None, **kwargs) -> None: + super(AzureTimeSeriesData, self).__init__(**kwargs) + self.dim_values = dim_values + self.min = min + self.max = max + self.sum = sum + self.count = count diff --git a/azure-monitor/azure/monitor/version.py b/azure-monitor/azure/monitor/version.py new file mode 100644 index 000000000000..266f5a486d79 --- /dev/null +++ b/azure-monitor/azure/monitor/version.py @@ -0,0 +1,13 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +VERSION = "0.5.0" + diff --git a/azure-monitor/azure_bdist_wheel.py b/azure-monitor/azure_bdist_wheel.py new file mode 100644 index 000000000000..8a81d1b61775 --- /dev/null +++ b/azure-monitor/azure_bdist_wheel.py @@ -0,0 +1,54 @@ +#------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +#-------------------------------------------------------------------------- + +from distutils import log as logger +import os.path + +from wheel.bdist_wheel import bdist_wheel +class azure_bdist_wheel(bdist_wheel): + """The purpose of this class is to build wheel a little differently than the sdist, + without requiring to build the wheel from the sdist (i.e. you can build the wheel + directly from source). + """ + + description = "Create an Azure wheel distribution" + + user_options = bdist_wheel.user_options + \ + [('azure-namespace-package=', None, + "Name of the deepest nspkg used")] + + def initialize_options(self): + bdist_wheel.initialize_options(self) + self.azure_namespace_package = None + + def finalize_options(self): + bdist_wheel.finalize_options(self) + if self.azure_namespace_package and not self.azure_namespace_package.endswith("-nspkg"): + raise ValueError("azure_namespace_package must finish by -nspkg") + + def run(self): + if not self.distribution.install_requires: + self.distribution.install_requires = [] + self.distribution.install_requires.append( + "{}>=2.0.0".format(self.azure_namespace_package)) + bdist_wheel.run(self) + + def write_record(self, bdist_dir, distinfo_dir): + if self.azure_namespace_package: + # Split and remove last part, assuming it's "nspkg" + subparts = self.azure_namespace_package.split('-')[0:-1] + folder_with_init = [os.path.join(*subparts[0:i+1]) for i in range(len(subparts))] + for azure_sub_package in folder_with_init: + init_file = os.path.join(bdist_dir, azure_sub_package, '__init__.py') + if os.path.isfile(init_file): + logger.info("manually remove {} while building the wheel".format(init_file)) + os.remove(init_file) + else: + raise ValueError("Unable to find {}. Are you sure of your namespace package?".format(init_file)) + bdist_wheel.write_record(self, bdist_dir, distinfo_dir) +cmdclass = { + 'bdist_wheel': azure_bdist_wheel, +} diff --git a/azure-monitor/sdk_packaging.toml b/azure-monitor/sdk_packaging.toml new file mode 100644 index 000000000000..84aeab0d8073 --- /dev/null +++ b/azure-monitor/sdk_packaging.toml @@ -0,0 +1,6 @@ +[packaging] +package_name = "azure-monitor" +package_pprint_name = "MyService Management" +package_doc_id = "" +is_stable = false +is_arm = true diff --git a/azure-monitor/setup.cfg b/azure-monitor/setup.cfg new file mode 100644 index 000000000000..669e94e63df3 --- /dev/null +++ b/azure-monitor/setup.cfg @@ -0,0 +1,3 @@ +[bdist_wheel] +universal=1 +azure-namespace-package=azure-nspkg \ No newline at end of file diff --git a/azure-monitor/setup.py b/azure-monitor/setup.py new file mode 100644 index 000000000000..97c8b65f3591 --- /dev/null +++ b/azure-monitor/setup.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python + +#------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +#-------------------------------------------------------------------------- + +import re +import os.path +from io import open +from setuptools import find_packages, setup +try: + from azure_bdist_wheel import cmdclass +except ImportError: + from distutils import log as logger + logger.warn("Wheel is not available, disabling bdist_wheel hook") + cmdclass = {} + +# Change the PACKAGE_NAME only to change folder and different name +PACKAGE_NAME = "azure-monitor" +PACKAGE_PPRINT_NAME = "MyService Management" + +# a-b-c => a/b/c +package_folder_path = PACKAGE_NAME.replace('-', '/') +# a-b-c => a.b.c +namespace_name = PACKAGE_NAME.replace('-', '.') + +# azure v0.x is not compatible with this package +# azure v0.x used to have a __version__ attribute (newer versions don't) +try: + import azure + try: + ver = azure.__version__ + raise Exception( + 'This package is incompatible with azure=={}. '.format(ver) + + 'Uninstall it with "pip uninstall azure".' + ) + except AttributeError: + pass +except ImportError: + pass + +# Version extraction inspired from 'requests' +with open(os.path.join(package_folder_path, 'version.py'), 'r') as fd: + version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', + fd.read(), re.MULTILINE).group(1) + +if not version: + raise RuntimeError('Cannot find version information') + +with open('README.rst', encoding='utf-8') as f: + readme = f.read() +with open('HISTORY.rst', encoding='utf-8') as f: + history = f.read() + +setup( + name=PACKAGE_NAME, + version=version, + description='Microsoft Azure {} Client Library for Python'.format(PACKAGE_PPRINT_NAME), + long_description=readme + '\n\n' + history, + license='MIT License', + author='Microsoft Corporation', + author_email='azpysdkhelp@microsoft.com', + url='https://github.com/Azure/azure-sdk-for-python', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'License :: OSI Approved :: MIT License', + ], + zip_safe=False, + packages=find_packages(exclude=["tests"]), + install_requires=[ + 'msrest>=0.5.0', + 'msrestazure>=0.4.32,<2.0.0', + 'azure-common~=1.1', + ], + cmdclass=cmdclass +) From e6ea2790a90c1bc84bffc52f1cb316cc0fc624c6 Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Fri, 14 Sep 2018 16:02:12 -0700 Subject: [PATCH 2/3] [AutoPR monitor/data-plane] Fix the swagger spec to ensure the documentaiton generation works as expected (#3355) * Generated from 69db2fd1a1fd3e4e8b451be6f725fa1b8a582ebf -Fix the readme.md file to refer the correct file * Generated from f343eabd7713d9c94975a1531467dfbc374ae4db -Call operationId with suffix Create to be consistent -Rename the file to be consistent with operationId --- .../azure/monitor/azure_metrics_client.py | 100 +------------- .../azure/monitor/operations/__init__.py | 16 +++ .../monitor/operations/metrics_operations.py | 122 ++++++++++++++++++ 3 files changed, 144 insertions(+), 94 deletions(-) create mode 100644 azure-monitor/azure/monitor/operations/__init__.py create mode 100644 azure-monitor/azure/monitor/operations/metrics_operations.py diff --git a/azure-monitor/azure/monitor/azure_metrics_client.py b/azure-monitor/azure/monitor/azure_metrics_client.py index 68db3bc28f5b..58285285a100 100644 --- a/azure-monitor/azure/monitor/azure_metrics_client.py +++ b/azure-monitor/azure/monitor/azure_metrics_client.py @@ -13,8 +13,7 @@ from msrest import Serializer, Deserializer from msrestazure import AzureConfiguration from .version import VERSION -from msrest.pipeline import ClientRawResponse -import uuid +from .operations.metrics_operations import MetricsOperations from . import models @@ -51,6 +50,9 @@ class AzureMetricsClient(SDKClient): :ivar config: Configuration for client. :vartype config: AzureMetricsClientConfiguration + :ivar metrics: Metrics operations + :vartype metrics: azure.monitor.operations.MetricsOperations + :param credentials: Credentials needed for the client to connect to Azure. :type credentials: :mod:`A msrestazure Credentials object` @@ -68,95 +70,5 @@ def __init__( self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) - - def azure_monitor_custom_metrics_ingestion_api( - self, subscription_id, resource_group_name, resource_provider, resource_type_name, resource_name, content_type=None, content_length=None, time=None, data=None, custom_headers=None, raw=False, **operation_config): - """Ingestion API used by Azure custom metrics - Responsible of below operation - 1. Authorize the request - 2. Deserialize payload request body - 3. Perform validation of the payload - 4. Commits the payload for metrics ingestion. - - :param subscription_id: The azure subscription id - :type subscription_id: str - :param resource_group_name: The ARM resource group name - :type resource_group_name: str - :param resource_provider: The ARM resource provider name - :type resource_provider: str - :param resource_type_name: The ARM resource type name - :type resource_type_name: str - :param resource_name: The ARM resource name - :type resource_name: str - :param content_type: Supports application/json and - application/x-ndjson - :type content_type: str - :param content_length: Content length of the payload - :type content_length: int - :param time: Gets or sets Time property (in ISO 8601 format) - :type time: str - :param data: - :type data: ~azure.monitor.models.AzureMetricsData - :param dict custom_headers: headers that will be added to the request - :param bool raw: returns the direct response alongside the - deserialized response - :param operation_config: :ref:`Operation configuration - overrides`. - :return: AzureMetricsResult or ClientRawResponse if raw=true - :rtype: ~azure.monitor.models.AzureMetricsResult or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`AzureMetricsResultException` - """ - body = models.AzureMetricsDocument(time=time, data=data) - - # Construct URL - url = self.azure_monitor_custom_metrics_ingestion_api.metadata['url'] - path_format_arguments = { - 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), - 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), - 'resourceProvider': self._serialize.url("resource_provider", resource_provider, 'str'), - 'resourceTypeName': self._serialize.url("resource_type_name", resource_type_name, 'str'), - 'resourceName': self._serialize.url("resource_name", resource_name, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Accept'] = 'application/json' - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if self.config.generate_client_request_id: - header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) - if custom_headers: - header_parameters.update(custom_headers) - if content_type is not None: - header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') - if content_length is not None: - header_parameters['Content-Length'] = self._serialize.header("content_length", content_length, 'int') - if self.config.accept_language is not None: - header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') - - # Construct body - body_content = self._serialize.body(body, 'AzureMetricsDocument') - - # Construct and send request - request = self._client.post(url, query_parameters, header_parameters, body_content) - response = self._client.send(request, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.AzureMetricsResultException(self._deserialize, response) - - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('AzureMetricsResult', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - azure_monitor_custom_metrics_ingestion_api.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProvider}/{resourceTypeName}/{resourceName}/metrics'} + self.metrics = MetricsOperations( + self._client, self.config, self._serialize, self._deserialize) diff --git a/azure-monitor/azure/monitor/operations/__init__.py b/azure-monitor/azure/monitor/operations/__init__.py new file mode 100644 index 000000000000..5e29104fccf0 --- /dev/null +++ b/azure-monitor/azure/monitor/operations/__init__.py @@ -0,0 +1,16 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +from .metrics_operations import MetricsOperations + +__all__ = [ + 'MetricsOperations', +] diff --git a/azure-monitor/azure/monitor/operations/metrics_operations.py b/azure-monitor/azure/monitor/operations/metrics_operations.py new file mode 100644 index 000000000000..39ab24563571 --- /dev/null +++ b/azure-monitor/azure/monitor/operations/metrics_operations.py @@ -0,0 +1,122 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is +# regenerated. +# -------------------------------------------------------------------------- + +import uuid +from msrest.pipeline import ClientRawResponse + +from .. import models + + +class MetricsOperations(object): + """MetricsOperations operations. + + :param client: Client for service requests. + :param config: Configuration of service client. + :param serializer: An object model serializer. + :param deserializer: An object model deserializer. + """ + + models = models + + def __init__(self, client, config, serializer, deserializer): + + self._client = client + self._serialize = serializer + self._deserialize = deserializer + + self.config = config + + def create( + self, subscription_id, resource_group_name, resource_provider, resource_type_name, resource_name, content_type=None, content_length=None, time=None, data=None, custom_headers=None, raw=False, **operation_config): + """**Post the metric values for a resource**. + + :param subscription_id: The azure subscription id + :type subscription_id: str + :param resource_group_name: The ARM resource group name + :type resource_group_name: str + :param resource_provider: The ARM resource provider name + :type resource_provider: str + :param resource_type_name: The ARM resource type name + :type resource_type_name: str + :param resource_name: The ARM resource name + :type resource_name: str + :param content_type: Supports application/json and + application/x-ndjson + :type content_type: str + :param content_length: Content length of the payload + :type content_length: int + :param time: Gets or sets Time property (in ISO 8601 format) + :type time: str + :param data: + :type data: ~azure.monitor.models.AzureMetricsData + :param dict custom_headers: headers that will be added to the request + :param bool raw: returns the direct response alongside the + deserialized response + :param operation_config: :ref:`Operation configuration + overrides`. + :return: AzureMetricsResult or ClientRawResponse if raw=true + :rtype: ~azure.monitor.models.AzureMetricsResult or + ~msrest.pipeline.ClientRawResponse + :raises: + :class:`AzureMetricsResultException` + """ + body = models.AzureMetricsDocument(time=time, data=data) + + # Construct URL + url = self.create.metadata['url'] + path_format_arguments = { + 'subscriptionId': self._serialize.url("subscription_id", subscription_id, 'str'), + 'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'), + 'resourceProvider': self._serialize.url("resource_provider", resource_provider, 'str'), + 'resourceTypeName': self._serialize.url("resource_type_name", resource_type_name, 'str'), + 'resourceName': self._serialize.url("resource_name", resource_name, 'str') + } + url = self._client.format_url(url, **path_format_arguments) + + # Construct parameters + query_parameters = {} + + # Construct headers + header_parameters = {} + header_parameters['Accept'] = 'application/json' + header_parameters['Content-Type'] = 'application/json; charset=utf-8' + if self.config.generate_client_request_id: + header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) + if custom_headers: + header_parameters.update(custom_headers) + if content_type is not None: + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + if content_length is not None: + header_parameters['Content-Length'] = self._serialize.header("content_length", content_length, 'int') + if self.config.accept_language is not None: + header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') + + # Construct body + body_content = self._serialize.body(body, 'AzureMetricsDocument') + + # Construct and send request + request = self._client.post(url, query_parameters, header_parameters, body_content) + response = self._client.send(request, stream=False, **operation_config) + + if response.status_code not in [200]: + raise models.AzureMetricsResultException(self._deserialize, response) + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('AzureMetricsResult', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + create.metadata = {'url': '/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProvider}/{resourceTypeName}/{resourceName}/metrics'} From 431163cc4ac1a75837b3f0f03582823ec0312533 Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Tue, 18 Sep 2018 16:18:09 -0700 Subject: [PATCH 3/3] Generated from 2baeee1d9abeb41fa94a1e030e2c205eb9a2ca1f (#3374) -Fix an ordering issue in swagger json --- .../monitor/models/azure_metrics_base_data.py | 16 ++++++++++++---- .../models/azure_metrics_base_data_py3.py | 18 +++++++++++++----- .../monitor/models/azure_metrics_data.py | 8 +++++++- .../monitor/models/azure_metrics_data_py3.py | 10 ++++++++-- .../monitor/models/azure_metrics_document.py | 11 +++++++++-- .../models/azure_metrics_document_py3.py | 13 ++++++++++--- .../monitor/models/azure_time_series_data.py | 17 +++++++++++++---- .../models/azure_time_series_data_py3.py | 19 ++++++++++++++----- .../monitor/operations/metrics_operations.py | 18 ++++++++---------- 9 files changed, 94 insertions(+), 36 deletions(-) diff --git a/azure-monitor/azure/monitor/models/azure_metrics_base_data.py b/azure-monitor/azure/monitor/models/azure_metrics_base_data.py index 1ce686a8903b..9ada4502f0b2 100644 --- a/azure-monitor/azure/monitor/models/azure_metrics_base_data.py +++ b/azure-monitor/azure/monitor/models/azure_metrics_base_data.py @@ -15,17 +15,25 @@ class AzureMetricsBaseData(Model): """AzureMetricsBaseData. - :param metric: Gets or sets the Metric name + All required parameters must be populated in order to send to Azure. + + :param metric: Required. Gets or sets the Metric name :type metric: str - :param namespace: Gets or sets the Metric namespace + :param namespace: Required. Gets or sets the Metric namespace :type namespace: str :param dim_names: Gets or sets the list of dimension names (optional) :type dim_names: list[str] - :param series: Gets or sets the list of time series data for the metric - (one per unique dimension combination) + :param series: Required. Gets or sets the list of time series data for the + metric (one per unique dimension combination) :type series: list[~azure.monitor.models.AzureTimeSeriesData] """ + _validation = { + 'metric': {'required': True}, + 'namespace': {'required': True}, + 'series': {'required': True}, + } + _attribute_map = { 'metric': {'key': 'metric', 'type': 'str'}, 'namespace': {'key': 'namespace', 'type': 'str'}, diff --git a/azure-monitor/azure/monitor/models/azure_metrics_base_data_py3.py b/azure-monitor/azure/monitor/models/azure_metrics_base_data_py3.py index de1716f325c2..bee20bade35f 100644 --- a/azure-monitor/azure/monitor/models/azure_metrics_base_data_py3.py +++ b/azure-monitor/azure/monitor/models/azure_metrics_base_data_py3.py @@ -15,17 +15,25 @@ class AzureMetricsBaseData(Model): """AzureMetricsBaseData. - :param metric: Gets or sets the Metric name + All required parameters must be populated in order to send to Azure. + + :param metric: Required. Gets or sets the Metric name :type metric: str - :param namespace: Gets or sets the Metric namespace + :param namespace: Required. Gets or sets the Metric namespace :type namespace: str :param dim_names: Gets or sets the list of dimension names (optional) :type dim_names: list[str] - :param series: Gets or sets the list of time series data for the metric - (one per unique dimension combination) + :param series: Required. Gets or sets the list of time series data for the + metric (one per unique dimension combination) :type series: list[~azure.monitor.models.AzureTimeSeriesData] """ + _validation = { + 'metric': {'required': True}, + 'namespace': {'required': True}, + 'series': {'required': True}, + } + _attribute_map = { 'metric': {'key': 'metric', 'type': 'str'}, 'namespace': {'key': 'namespace', 'type': 'str'}, @@ -33,7 +41,7 @@ class AzureMetricsBaseData(Model): 'series': {'key': 'series', 'type': '[AzureTimeSeriesData]'}, } - def __init__(self, *, metric: str=None, namespace: str=None, dim_names=None, series=None, **kwargs) -> None: + def __init__(self, *, metric: str, namespace: str, series, dim_names=None, **kwargs) -> None: super(AzureMetricsBaseData, self).__init__(**kwargs) self.metric = metric self.namespace = namespace diff --git a/azure-monitor/azure/monitor/models/azure_metrics_data.py b/azure-monitor/azure/monitor/models/azure_metrics_data.py index 75401e227ac9..b92837d9a7db 100644 --- a/azure-monitor/azure/monitor/models/azure_metrics_data.py +++ b/azure-monitor/azure/monitor/models/azure_metrics_data.py @@ -15,10 +15,16 @@ class AzureMetricsData(Model): """AzureMetricsData. - :param base_data: + All required parameters must be populated in order to send to Azure. + + :param base_data: Required. :type base_data: ~azure.monitor.models.AzureMetricsBaseData """ + _validation = { + 'base_data': {'required': True}, + } + _attribute_map = { 'base_data': {'key': 'baseData', 'type': 'AzureMetricsBaseData'}, } diff --git a/azure-monitor/azure/monitor/models/azure_metrics_data_py3.py b/azure-monitor/azure/monitor/models/azure_metrics_data_py3.py index 9f3d6cabf506..cf31cc109327 100644 --- a/azure-monitor/azure/monitor/models/azure_metrics_data_py3.py +++ b/azure-monitor/azure/monitor/models/azure_metrics_data_py3.py @@ -15,14 +15,20 @@ class AzureMetricsData(Model): """AzureMetricsData. - :param base_data: + All required parameters must be populated in order to send to Azure. + + :param base_data: Required. :type base_data: ~azure.monitor.models.AzureMetricsBaseData """ + _validation = { + 'base_data': {'required': True}, + } + _attribute_map = { 'base_data': {'key': 'baseData', 'type': 'AzureMetricsBaseData'}, } - def __init__(self, *, base_data=None, **kwargs) -> None: + def __init__(self, *, base_data, **kwargs) -> None: super(AzureMetricsData, self).__init__(**kwargs) self.base_data = base_data diff --git a/azure-monitor/azure/monitor/models/azure_metrics_document.py b/azure-monitor/azure/monitor/models/azure_metrics_document.py index dcfed41944c9..2e94fd16194c 100644 --- a/azure-monitor/azure/monitor/models/azure_metrics_document.py +++ b/azure-monitor/azure/monitor/models/azure_metrics_document.py @@ -15,12 +15,19 @@ class AzureMetricsDocument(Model): """AzureMetricsDocument. - :param time: Gets or sets Time property (in ISO 8601 format) + All required parameters must be populated in order to send to Azure. + + :param time: Required. Gets or sets Time property (in ISO 8601 format) :type time: str - :param data: + :param data: Required. :type data: ~azure.monitor.models.AzureMetricsData """ + _validation = { + 'time': {'required': True}, + 'data': {'required': True}, + } + _attribute_map = { 'time': {'key': 'time', 'type': 'str'}, 'data': {'key': 'data', 'type': 'AzureMetricsData'}, diff --git a/azure-monitor/azure/monitor/models/azure_metrics_document_py3.py b/azure-monitor/azure/monitor/models/azure_metrics_document_py3.py index ad9514c28e7f..22a8508389a5 100644 --- a/azure-monitor/azure/monitor/models/azure_metrics_document_py3.py +++ b/azure-monitor/azure/monitor/models/azure_metrics_document_py3.py @@ -15,18 +15,25 @@ class AzureMetricsDocument(Model): """AzureMetricsDocument. - :param time: Gets or sets Time property (in ISO 8601 format) + All required parameters must be populated in order to send to Azure. + + :param time: Required. Gets or sets Time property (in ISO 8601 format) :type time: str - :param data: + :param data: Required. :type data: ~azure.monitor.models.AzureMetricsData """ + _validation = { + 'time': {'required': True}, + 'data': {'required': True}, + } + _attribute_map = { 'time': {'key': 'time', 'type': 'str'}, 'data': {'key': 'data', 'type': 'AzureMetricsData'}, } - def __init__(self, *, time: str=None, data=None, **kwargs) -> None: + def __init__(self, *, time: str, data, **kwargs) -> None: super(AzureMetricsDocument, self).__init__(**kwargs) self.time = time self.data = data diff --git a/azure-monitor/azure/monitor/models/azure_time_series_data.py b/azure-monitor/azure/monitor/models/azure_time_series_data.py index 3c23d80624cf..7ddb870cfa55 100644 --- a/azure-monitor/azure/monitor/models/azure_time_series_data.py +++ b/azure-monitor/azure/monitor/models/azure_time_series_data.py @@ -15,18 +15,27 @@ class AzureTimeSeriesData(Model): """AzureTimeSeriesData. + All required parameters must be populated in order to send to Azure. + :param dim_values: Gets or sets dimension values :type dim_values: list[str] - :param min: Gets or sets Min value + :param min: Required. Gets or sets Min value :type min: float - :param max: Gets or sets Max value + :param max: Required. Gets or sets Max value :type max: float - :param sum: Gets or sets Sum value + :param sum: Required. Gets or sets Sum value :type sum: float - :param count: Gets or sets Count value + :param count: Required. Gets or sets Count value :type count: int """ + _validation = { + 'min': {'required': True}, + 'max': {'required': True}, + 'sum': {'required': True}, + 'count': {'required': True}, + } + _attribute_map = { 'dim_values': {'key': 'dimValues', 'type': '[str]'}, 'min': {'key': 'min', 'type': 'float'}, diff --git a/azure-monitor/azure/monitor/models/azure_time_series_data_py3.py b/azure-monitor/azure/monitor/models/azure_time_series_data_py3.py index 12a67eaf8985..d26bdc03188a 100644 --- a/azure-monitor/azure/monitor/models/azure_time_series_data_py3.py +++ b/azure-monitor/azure/monitor/models/azure_time_series_data_py3.py @@ -15,18 +15,27 @@ class AzureTimeSeriesData(Model): """AzureTimeSeriesData. + All required parameters must be populated in order to send to Azure. + :param dim_values: Gets or sets dimension values :type dim_values: list[str] - :param min: Gets or sets Min value + :param min: Required. Gets or sets Min value :type min: float - :param max: Gets or sets Max value + :param max: Required. Gets or sets Max value :type max: float - :param sum: Gets or sets Sum value + :param sum: Required. Gets or sets Sum value :type sum: float - :param count: Gets or sets Count value + :param count: Required. Gets or sets Count value :type count: int """ + _validation = { + 'min': {'required': True}, + 'max': {'required': True}, + 'sum': {'required': True}, + 'count': {'required': True}, + } + _attribute_map = { 'dim_values': {'key': 'dimValues', 'type': '[str]'}, 'min': {'key': 'min', 'type': 'float'}, @@ -35,7 +44,7 @@ class AzureTimeSeriesData(Model): 'count': {'key': 'count', 'type': 'int'}, } - def __init__(self, *, dim_values=None, min: float=None, max: float=None, sum: float=None, count: int=None, **kwargs) -> None: + def __init__(self, *, min: float, max: float, sum: float, count: int, dim_values=None, **kwargs) -> None: super(AzureTimeSeriesData, self).__init__(**kwargs) self.dim_values = dim_values self.min = min diff --git a/azure-monitor/azure/monitor/operations/metrics_operations.py b/azure-monitor/azure/monitor/operations/metrics_operations.py index 39ab24563571..a465718af734 100644 --- a/azure-monitor/azure/monitor/operations/metrics_operations.py +++ b/azure-monitor/azure/monitor/operations/metrics_operations.py @@ -35,9 +35,14 @@ def __init__(self, client, config, serializer, deserializer): self.config = config def create( - self, subscription_id, resource_group_name, resource_provider, resource_type_name, resource_name, content_type=None, content_length=None, time=None, data=None, custom_headers=None, raw=False, **operation_config): + self, content_type, content_length, subscription_id, resource_group_name, resource_provider, resource_type_name, resource_name, time, data, custom_headers=None, raw=False, **operation_config): """**Post the metric values for a resource**. + :param content_type: Supports application/json and + application/x-ndjson + :type content_type: str + :param content_length: Content length of the payload + :type content_length: int :param subscription_id: The azure subscription id :type subscription_id: str :param resource_group_name: The ARM resource group name @@ -48,11 +53,6 @@ def create( :type resource_type_name: str :param resource_name: The ARM resource name :type resource_name: str - :param content_type: Supports application/json and - application/x-ndjson - :type content_type: str - :param content_length: Content length of the payload - :type content_length: int :param time: Gets or sets Time property (in ISO 8601 format) :type time: str :param data: @@ -92,10 +92,8 @@ def create( header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) if custom_headers: header_parameters.update(custom_headers) - if content_type is not None: - header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') - if content_length is not None: - header_parameters['Content-Length'] = self._serialize.header("content_length", content_length, 'int') + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Content-Length'] = self._serialize.header("content_length", content_length, 'int') if self.config.accept_language is not None: header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')