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

[ReleasePR azure-mgmt-costmanagement] Adding External Scopes properly based on ARM Suggestion #11062

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
30 changes: 11 additions & 19 deletions sdk/costmanagement/azure-mgmt-costmanagement/README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
## Microsoft Azure SDK for Python
# Microsoft Azure SDK for Python

This is the Microsoft Azure Cost Management Client Library.
This package has been tested with Python 2.7, 3.5, 3.6, 3.7 and 3.8.
For a more complete view of Azure libraries, see the [Github repo](https://github.com/Azure/azure-sdk-for-python/)

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.
# Usage

For the older Azure Service Management (ASM) libraries, see
[azure-servicemanagement-legacy](https://pypi.python.org/pypi/azure-servicemanagement-legacy)
library.
For code examples, see [Cost Management](https://docs.microsoft.com/python/api/overview/azure/)
on docs.microsoft.com.

For a more complete set of Azure libraries, see the
[azure](https://pypi.python.org/pypi/azure) bundle package.

## Usage
# Provide Feedback

For code examples, see [Cost
Management](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)
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.

![image](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fazure-mgmt-costmanagement%2FREADME.png)

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python%2Fazure-mgmt-costmanagement%2FREADME.png)
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
FormatType,
ExecutionType,
ExecutionStatus,
ExternalCloudProviderType,
)

__all__ = [
Expand Down Expand Up @@ -112,4 +113,5 @@
'FormatType',
'ExecutionType',
'ExecutionStatus',
'ExternalCloudProviderType',
]
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ class ExecutionStatus(str, Enum):
timeout = "Timeout"
new_data_not_available = "NewDataNotAvailable"
data_not_available = "DataNotAvailable"


class ExternalCloudProviderType(str, Enum):

external_subscriptions = "externalSubscriptions"
external_billing_accounts = "externalBillingAccounts"
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ def __init__(self, **kwargs):
class ErrorResponse(Model):
"""Error response indicates that the service is not able to process the
incoming request. The reason is provided in the error message.
Some Error responses:
* 429 TooManyRequests - Request is throttled. Retry after waiting for the
time specified in the "x-ms-ratelimit-microsoft.consumption-retry-after"
header.
* 503 ServiceUnavailable - Service is temporarily unavailable. Retry after
waiting for the time specified in the "Retry-After" header.

:param error: The details of the error.
:type error: ~azure.mgmt.costmanagement.models.ErrorDetails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ def __init__(self, **kwargs) -> None:
class ErrorResponse(Model):
"""Error response indicates that the service is not able to process the
incoming request. The reason is provided in the error message.
Some Error responses:
* 429 TooManyRequests - Request is throttled. Retry after waiting for the
time specified in the "x-ms-ratelimit-microsoft.consumption-retry-after"
header.
* 503 ServiceUnavailable - Service is temporarily unavailable. Retry after
waiting for the time specified in the "Retry-After" header.

:param error: The details of the error.
:type error: ~azure.mgmt.costmanagement.models.ErrorDetails
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,105 @@ def internal_paging(next_link=None):

return deserialized
list.metadata = {'url': '/{scope}/providers/Microsoft.CostManagement/dimensions'}

def by_external_cloud_provider_type(
self, external_cloud_provider_type, external_cloud_provider_id, filter=None, expand=None, skiptoken=None, top=None, custom_headers=None, raw=False, **operation_config):
"""Lists the dimensions by the external cloud provider type.

:param external_cloud_provider_type: The external cloud provider type
associated with dimension/query operations. This includes
'externalSubscriptions' for linked account and
'externalBillingAccounts' for consolidated account. Possible values
include: 'externalSubscriptions', 'externalBillingAccounts'
:type external_cloud_provider_type: str or
~azure.mgmt.costmanagement.models.ExternalCloudProviderType
:param external_cloud_provider_id: This can be
'{externalSubscriptionId}' for linked account or
'{externalBillingAccountId}' for consolidated account used with
dimension/query operations.
:type external_cloud_provider_id: str
:param filter: May be used to filter dimensions by
properties/category, properties/usageStart, properties/usageEnd.
Supported operators are 'eq','lt', 'gt', 'le', 'ge'.
:type filter: str
:param expand: May be used to expand the properties/data within a
dimension category. By default, data is not included when listing
dimensions.
:type expand: str
:param skiptoken: Skiptoken is only used if a previous operation
returned a partial result. If a previous response contains a nextLink
element, the value of the nextLink element will include a skiptoken
parameter that specifies a starting point to use for subsequent calls.
:type skiptoken: str
:param top: May be used to limit the number of results to the most
recent N dimension data.
:type top: int
: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: An iterator like instance of Dimension
:rtype:
~azure.mgmt.costmanagement.models.DimensionPaged[~azure.mgmt.costmanagement.models.Dimension]
:raises:
:class:`ErrorResponseException<azure.mgmt.costmanagement.models.ErrorResponseException>`
"""
def prepare_request(next_link=None):
if not next_link:
# Construct URL
url = self.by_external_cloud_provider_type.metadata['url']
path_format_arguments = {
'externalCloudProviderType': self._serialize.url("external_cloud_provider_type", external_cloud_provider_type, 'str'),
'externalCloudProviderId': self._serialize.url("external_cloud_provider_id", external_cloud_provider_id, 'str')
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
if filter is not None:
query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
if expand is not None:
query_parameters['$expand'] = self._serialize.query("expand", expand, 'str')
if skiptoken is not None:
query_parameters['$skiptoken'] = self._serialize.query("skiptoken", skiptoken, 'str')
if top is not None:
query_parameters['$top'] = self._serialize.query("top", top, 'int', maximum=1000, minimum=1)

else:
url = next_link
query_parameters = {}

# Construct headers
header_parameters = {}
header_parameters['Accept'] = 'application/json'
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 self.config.accept_language is not None:
header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

# Construct and send request
request = self._client.get(url, query_parameters, header_parameters)
return request

def internal_paging(next_link=None):
request = prepare_request(next_link)

response = self._client.send(request, stream=False, **operation_config)

if response.status_code not in [200]:
raise models.ErrorResponseException(self._deserialize, response)

return response

# Deserialize response
header_dict = None
if raw:
header_dict = {}
deserialized = models.DimensionPaged(internal_paging, self._deserialize.dependencies, header_dict)

return deserialized
by_external_cloud_provider_type.metadata = {'url': '/providers/Microsoft.CostManagement/{externalCloudProviderType}/{externalCloudProviderId}/dimensions'}
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,77 @@ def usage(

return deserialized
usage.metadata = {'url': '/{scope}/providers/Microsoft.CostManagement/query'}

def usage_by_external_cloud_provider_type(
self, external_cloud_provider_type, external_cloud_provider_id, parameters, custom_headers=None, raw=False, **operation_config):
"""Query the usage data for external cloud provider type defined.

:param external_cloud_provider_type: The external cloud provider type
associated with dimension/query operations. This includes
'externalSubscriptions' for linked account and
'externalBillingAccounts' for consolidated account. Possible values
include: 'externalSubscriptions', 'externalBillingAccounts'
:type external_cloud_provider_type: str or
~azure.mgmt.costmanagement.models.ExternalCloudProviderType
:param external_cloud_provider_id: This can be
'{externalSubscriptionId}' for linked account or
'{externalBillingAccountId}' for consolidated account used with
dimension/query operations.
:type external_cloud_provider_id: str
:param parameters: Parameters supplied to the CreateOrUpdate Query
Config operation.
:type parameters: ~azure.mgmt.costmanagement.models.QueryDefinition
: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: QueryResult or ClientRawResponse if raw=true
:rtype: ~azure.mgmt.costmanagement.models.QueryResult or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`ErrorResponseException<azure.mgmt.costmanagement.models.ErrorResponseException>`
"""
# Construct URL
url = self.usage_by_external_cloud_provider_type.metadata['url']
path_format_arguments = {
'externalCloudProviderType': self._serialize.url("external_cloud_provider_type", external_cloud_provider_type, 'str'),
'externalCloudProviderId': self._serialize.url("external_cloud_provider_id", external_cloud_provider_id, 'str')
}
url = self._client.format_url(url, **path_format_arguments)

# Construct parameters
query_parameters = {}
query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')

# 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 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(parameters, 'QueryDefinition')

# 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('QueryResult', response)

if raw:
client_raw_response = ClientRawResponse(deserialized, response)
return client_raw_response

return deserialized
usage_by_external_cloud_provider_type.metadata = {'url': '/providers/Microsoft.CostManagement/{externalCloudProviderType}/{externalCloudProviderId}/query'}
6 changes: 4 additions & 2 deletions sdk/costmanagement/azure-mgmt-costmanagement/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
pass

# Version extraction inspired from 'requests'
with open(os.path.join(package_folder_path, 'version.py'), 'r') as fd:
with open(os.path.join(package_folder_path, 'version.py')
if os.path.exists(os.path.join(package_folder_path, 'version.py'))
else os.path.join(package_folder_path, '_version.py'), 'r') as fd:
version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]',
fd.read(), re.MULTILINE).group(1)

Expand Down Expand Up @@ -64,10 +66,10 @@
'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',
'Programming Language :: Python :: 3.8',
'License :: OSI Approved :: MIT License',
],
zip_safe=False,
Expand Down