Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 6 additions & 66 deletions azure-loganalytics/azure/loganalytics/log_analytics_data_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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<msrest:optionsforoperations>`.
:return: QueryResults or ClientRawResponse if raw=true
:rtype: ~azure.loganalytics.models.QueryResults or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`ErrorResponseException<azure.loganalytics.models.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)
16 changes: 16 additions & 0 deletions azure-loganalytics/azure/loganalytics/operations/__init__.py
Original file line number Diff line number Diff line change
@@ -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',
]
Original file line number Diff line number Diff line change
@@ -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<msrest:optionsforoperations>`.
:return: QueryResults or ClientRawResponse if raw=true
:rtype: ~azure.loganalytics.models.QueryResults or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`ErrorResponseException<azure.loganalytics.models.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'}
1 change: 1 addition & 0 deletions azure-loganalytics/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
]),
install_requires=[
'msrest>=0.5.0',
'msrestazure>=0.4.32,<2.0.0',
'azure-common~=1.1',
],
extras_require={
Expand Down