Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Log Analytics data plane SDK #2557

Merged
merged 16 commits into from
Jul 11, 2018
Merged
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/azure-batch/ @annatisch @matthchr
/azure-keyvault/ @schaabs
/azure-loganalytics/ @alexeldeib
/azure-mgmt-batch/ @annatisch @matthchr
/azure-mgmt-batchai/ @AlexanderYukhanov
/azure-mgmt-cdn/ @tjprescott
Expand Down
9 changes: 9 additions & 0 deletions azure-loganalytics/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.. :changelog:

Release History
===============

0.1.0 (2018-07-11)
++++++++++++++++++

* Initial Release
2 changes: 2 additions & 0 deletions azure-loganalytics/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include *.rst
include azure_bdist_wheel.py
43 changes: 43 additions & 0 deletions azure-loganalytics/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Microsoft Azure SDK for Python
==============================

This is the Microsoft Azure Log Analytics Client Library.

This package has been tested with Python 2.7, 3.4, 3.5 and 3.6.

For a more complete set of Azure libraries, see the `azure <https://pypi.python.org/pypi/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 `Log Analytics
<https://docs.microsoft.com/python/api/overview/azure/>`__
on docs.microsoft.com.


Provide Feedback
================

If you encounter any bugs or have suggestions, please file an issue in the
`Issues <https://github.com/Azure/azure-sdk-for-python/issues>`__
section of the project.
1 change: 1 addition & 0 deletions azure-loganalytics/azure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
18 changes: 18 additions & 0 deletions azure-loganalytics/azure/loganalytics/__init__.py
Original file line number Diff line number Diff line change
@@ -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 .log_analytics_data_client import LogAnalyticsDataClient
from .version import VERSION

__all__ = ['LogAnalyticsDataClient']

__version__ = VERSION

132 changes: 132 additions & 0 deletions azure-loganalytics/azure/loganalytics/log_analytics_data_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# 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 Configuration, Serializer, Deserializer
from .version import VERSION
from msrest.pipeline import ClientRawResponse
from . import models


class LogAnalyticsDataClientConfiguration(Configuration):
"""Configuration for LogAnalyticsDataClient
Note that all parameters used to create this instance are saved as instance
attributes.

:param credentials: Subscription credentials which uniquely identify
client subscription.
:type credentials: None
: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://api.loganalytics.io/v1'

super(LogAnalyticsDataClientConfiguration, self).__init__(base_url)

self.add_user_agent('azure-loganalytics/{}'.format(VERSION))

self.credentials = credentials


class LogAnalyticsDataClient(SDKClient):
"""Log Analytics Data Plane Client

:ivar config: Configuration for client.
:vartype config: LogAnalyticsDataClientConfiguration

:param credentials: Subscription credentials which uniquely identify
client subscription.
:type credentials: None
:param str base_url: Service URL
"""

def __init__(
self, credentials, base_url=None):

self.config = LogAnalyticsDataClientConfiguration(credentials, base_url)
super(LogAnalyticsDataClient, 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 = 'v1'
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'}
37 changes: 37 additions & 0 deletions azure-loganalytics/azure/loganalytics/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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 .query_body_py3 import QueryBody
from .column_py3 import Column
from .table_py3 import Table
from .query_results_py3 import QueryResults
from .error_detail_py3 import ErrorDetail
from .error_info_py3 import ErrorInfo
from .error_response_py3 import ErrorResponse, ErrorResponseException
except (SyntaxError, ImportError):
from .query_body import QueryBody
from .column import Column
from .table import Table
from .query_results import QueryResults
from .error_detail import ErrorDetail
from .error_info import ErrorInfo
from .error_response import ErrorResponse, ErrorResponseException

__all__ = [
'QueryBody',
'Column',
'Table',
'QueryResults',
'ErrorDetail',
'ErrorInfo',
'ErrorResponse', 'ErrorResponseException',
]
34 changes: 34 additions & 0 deletions azure-loganalytics/azure/loganalytics/models/column.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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 Column(Model):
"""A table column.

A column in a table.

:param name: The name of this column.
:type name: str
:param type: The data type of this column.
:type type: str
"""

_attribute_map = {
'name': {'key': 'name', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
}

def __init__(self, **kwargs):
super(Column, self).__init__(**kwargs)
self.name = kwargs.get('name', None)
self.type = kwargs.get('type', None)
34 changes: 34 additions & 0 deletions azure-loganalytics/azure/loganalytics/models/column_py3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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 Column(Model):
"""A table column.

A column in a table.

:param name: The name of this column.
:type name: str
:param type: The data type of this column.
:type type: str
"""

_attribute_map = {
'name': {'key': 'name', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
}

def __init__(self, *, name: str=None, type: str=None, **kwargs) -> None:
super(Column, self).__init__(**kwargs)
self.name = name
self.type = type
58 changes: 58 additions & 0 deletions azure-loganalytics/azure/loganalytics/models/error_detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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 ErrorDetail(Model):
"""Error details.

All required parameters must be populated in order to send to Azure.

:param code: Required. The error's code.
:type code: str
:param message: Required. A human readable error message.
:type message: str
:param target: Indicates which property in the request is responsible for
the error.
:type target: str
:param value: Indicates which value in 'target' is responsible for the
error.
:type value: str
:param resources: Indicates resources which were responsible for the
error.
:type resources: list[str]
:param additional_properties:
:type additional_properties: object
"""

_validation = {
'code': {'required': True},
'message': {'required': True},
}

_attribute_map = {
'code': {'key': 'code', 'type': 'str'},
'message': {'key': 'message', 'type': 'str'},
'target': {'key': 'target', 'type': 'str'},
'value': {'key': 'value', 'type': 'str'},
'resources': {'key': 'resources', 'type': '[str]'},
'additional_properties': {'key': 'additionalProperties', 'type': 'object'},
}

def __init__(self, **kwargs):
super(ErrorDetail, self).__init__(**kwargs)
self.code = kwargs.get('code', None)
self.message = kwargs.get('message', None)
self.target = kwargs.get('target', None)
self.value = kwargs.get('value', None)
self.resources = kwargs.get('resources', None)
self.additional_properties = kwargs.get('additional_properties', None)
Loading