diff --git a/azure-loganalytics/azure/loganalytics/log_analytics_data_client.py b/azure-loganalytics/azure/loganalytics/log_analytics_data_client.py index 75521bb6886b..fed0faf2737c 100644 --- a/azure-loganalytics/azure/loganalytics/log_analytics_data_client.py +++ b/azure-loganalytics/azure/loganalytics/log_analytics_data_client.py @@ -12,7 +12,7 @@ from msrest.service_client import SDKClient from msrest import Configuration, Serializer, Deserializer from .version import VERSION -from msrest.pipeline import ClientRawResponse +from .operations.query_operations import QueryOperations from . import models @@ -48,6 +48,9 @@ class LogAnalyticsDataClient(SDKClient): :ivar config: Configuration for client. :vartype config: LogAnalyticsDataClientConfiguration + :ivar query: Query operations + :vartype query: azure.loganalytics.operations.QueryOperations + :param credentials: Subscription credentials which uniquely identify client subscription. :type credentials: None @@ -65,68 +68,5 @@ def __init__( self._serialize = Serializer(client_models) self._deserialize = Deserializer(client_models) - - def query( - self, workspace_id, body, custom_headers=None, raw=False, **operation_config): - """Execute an Analytics query. - - Executes an Analytics query for data. - [Here](https://dev.loganalytics.io/documentation/Using-the-API) is an - example for using POST with an Analytics query. - - :param workspace_id: ID of the workspace. This is Workspace ID from - the Properties blade in the Azure portal. - :type workspace_id: str - :param body: The Analytics query. Learn more about the [Analytics - query - syntax](https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/) - :type body: ~azure.loganalytics.models.QueryBody - :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: QueryResults or ClientRawResponse if raw=true - :rtype: ~azure.loganalytics.models.QueryResults or - ~msrest.pipeline.ClientRawResponse - :raises: - :class:`ErrorResponseException` - """ - # Construct URL - url = self.query.metadata['url'] - path_format_arguments = { - 'workspaceId': self._serialize.url("workspace_id", workspace_id, 'str') - } - url = self._client.format_url(url, **path_format_arguments) - - # Construct parameters - query_parameters = {} - - # Construct headers - header_parameters = {} - header_parameters['Content-Type'] = 'application/json; charset=utf-8' - if custom_headers: - header_parameters.update(custom_headers) - - # Construct body - body_content = self._serialize.body(body, 'QueryBody') - - # Construct and send request - request = self._client.post(url, query_parameters) - response = self._client.send( - request, header_parameters, body_content, stream=False, **operation_config) - - if response.status_code not in [200]: - raise models.ErrorResponseException(self._deserialize, response) - - deserialized = None - - if response.status_code == 200: - deserialized = self._deserialize('QueryResults', response) - - if raw: - client_raw_response = ClientRawResponse(deserialized, response) - return client_raw_response - - return deserialized - query.metadata = {'url': '/workspaces/{workspaceId}/query'} + self.query = QueryOperations( + self._client, self.config, self._serialize, self._deserialize) diff --git a/azure-loganalytics/azure/loganalytics/operations/__init__.py b/azure-loganalytics/azure/loganalytics/operations/__init__.py new file mode 100644 index 000000000000..4a2f82a9b381 --- /dev/null +++ b/azure-loganalytics/azure/loganalytics/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 .query_operations import QueryOperations + +__all__ = [ + 'QueryOperations', +] diff --git a/azure-loganalytics/azure/loganalytics/operations/query_operations.py b/azure-loganalytics/azure/loganalytics/operations/query_operations.py new file mode 100644 index 000000000000..d958d70d4e7e --- /dev/null +++ b/azure-loganalytics/azure/loganalytics/operations/query_operations.py @@ -0,0 +1,99 @@ +# 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.pipeline import ClientRawResponse + +from .. import models + + +class QueryOperations(object): + """QueryOperations 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 execute( + self, workspace_id, body, custom_headers=None, raw=False, **operation_config): + """Execute an Analytics query. + + Executes an Analytics query for data. + [Here](https://dev.loganalytics.io/documentation/Using-the-API) is an + example for using POST with an Analytics query. + + :param workspace_id: ID of the workspace. This is Workspace ID from + the Properties blade in the Azure portal. + :type workspace_id: str + :param body: The Analytics query. Learn more about the [Analytics + query + syntax](https://azure.microsoft.com/documentation/articles/app-insights-analytics-reference/) + :type body: ~azure.loganalytics.models.QueryBody + :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: QueryResults or ClientRawResponse if raw=true + :rtype: ~azure.loganalytics.models.QueryResults or + ~msrest.pipeline.ClientRawResponse + :raises: + :class:`ErrorResponseException` + """ + # Construct URL + url = self.execute.metadata['url'] + path_format_arguments = { + 'workspaceId': self._serialize.url("workspace_id", workspace_id, '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 custom_headers: + header_parameters.update(custom_headers) + + # Construct body + body_content = self._serialize.body(body, 'QueryBody') + + # 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.ErrorResponseException(self._deserialize, response) + + deserialized = None + + if response.status_code == 200: + deserialized = self._deserialize('QueryResults', response) + + if raw: + client_raw_response = ClientRawResponse(deserialized, response) + return client_raw_response + + return deserialized + execute.metadata = {'url': '/workspaces/{workspaceId}/query'} diff --git a/azure-loganalytics/setup.py b/azure-loganalytics/setup.py index 87ff80807710..d3d7639aa0f2 100644 --- a/azure-loganalytics/setup.py +++ b/azure-loganalytics/setup.py @@ -77,6 +77,7 @@ ]), install_requires=[ 'msrest>=0.5.0', + 'msrestazure>=0.4.32,<2.0.0', 'azure-common~=1.1', ], extras_require={