Skip to content

Commit

Permalink
[AutoPR consumption/resource-manager] Added schema spec for cost allo…
Browse files Browse the repository at this point in the history
…cation tags (#2263)

* Generated from 6388784ef9904e750e9ce09918b2b65e7d984616

Added schema spec for cost allocation tags

Added schema spec for cost allocation tags

* Generated from 3ccf1b464815326349f015f17a600df4ab5e35ab

Updated Get Operation

Updated Get Operation

* Generated from 884aabe8882d794b987236ad2b0927a98317d28f

Incorporated review comments

Incorporated review comments

* Generated from 3d1c7c16a7266814f1e4bd997169df1ebd1d2bce

Review comments incorporated

Review comments incorporated

* Generated from def63250017ef0071aadd68a751623913f788af3

Updated path

Updated path
  • Loading branch information
AutorestCI authored Apr 6, 2018
1 parent 223df61 commit ef356ef
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .operations.budgets_operations import BudgetsOperations
from .operations.operations import Operations
from .operations.price_sheet_operations import PriceSheetOperations
from .operations.cost_allocation_tags_operations import CostAllocationTagsOperations
from . import models


Expand All @@ -34,21 +35,16 @@ class ConsumptionManagementClientConfiguration(AzureConfiguration):
object<msrestazure.azure_active_directory>`
:param subscription_id: Azure Subscription ID.
:type subscription_id: str
:param grain: Can be daily or monthly. Possible values include:
'DailyGrain', 'MonthlyGrain'
:type grain: str or ~azure.mgmt.consumption.models.Datagrain
:param str base_url: Service URL
"""

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

if credentials is None:
raise ValueError("Parameter 'credentials' must not be None.")
if subscription_id is None:
raise ValueError("Parameter 'subscription_id' must not be None.")
if grain is None:
raise ValueError("Parameter 'grain' must not be None.")
if not base_url:
base_url = 'https://management.azure.com'

Expand All @@ -59,7 +55,6 @@ def __init__(

self.credentials = credentials
self.subscription_id = subscription_id
self.grain = grain


class ConsumptionManagementClient(object):
Expand All @@ -84,22 +79,21 @@ class ConsumptionManagementClient(object):
:vartype operations: azure.mgmt.consumption.operations.Operations
:ivar price_sheet: PriceSheet operations
:vartype price_sheet: azure.mgmt.consumption.operations.PriceSheetOperations
:ivar cost_allocation_tags: CostAllocationTags operations
:vartype cost_allocation_tags: azure.mgmt.consumption.operations.CostAllocationTagsOperations
:param credentials: Credentials needed for the client to connect to Azure.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
:param subscription_id: Azure Subscription ID.
:type subscription_id: str
:param grain: Can be daily or monthly. Possible values include:
'DailyGrain', 'MonthlyGrain'
:type grain: str or ~azure.mgmt.consumption.models.Datagrain
:param str base_url: Service URL
"""

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

self.config = ConsumptionManagementClientConfiguration(credentials, subscription_id, grain, base_url)
self.config = ConsumptionManagementClientConfiguration(credentials, subscription_id, base_url)
self._client = ServiceClient(self.config.credentials, self.config)

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
Expand All @@ -123,3 +117,5 @@ def __init__(
self._client, self.config, self._serialize, self._deserialize)
self.price_sheet = PriceSheetOperations(
self._client, self.config, self._serialize, self._deserialize)
self.cost_allocation_tags = CostAllocationTagsOperations(
self._client, self.config, self._serialize, self._deserialize)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from .current_spend import CurrentSpend
from .notification import Notification
from .budget import Budget
from .cost_allocation_tag import CostAllocationTag
from .cost_allocation_tags import CostAllocationTags
from .error_details import ErrorDetails
from .error_response import ErrorResponse, ErrorResponseException
from .operation_display import OperationDisplay
Expand Down Expand Up @@ -56,6 +58,8 @@
'CurrentSpend',
'Notification',
'Budget',
'CostAllocationTag',
'CostAllocationTags',
'ErrorDetails',
'ErrorResponse', 'ErrorResponseException',
'OperationDisplay',
Expand Down
Original file line number Diff line number Diff line change
@@ -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 CostAllocationTag(Model):
"""The cost allocation tag.
:param key: Cost allocation tag key.
:type key: str
"""

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

def __init__(self, key=None):
super(CostAllocationTag, self).__init__()
self.key = key
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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 .proxy_resource import ProxyResource


class CostAllocationTags(ProxyResource):
"""A cost allocation tag resource.
Variables are only populated by the server, and will be ignored when
sending a request.
:ivar id: Resource Id.
:vartype id: str
:ivar name: Resource name.
:vartype name: str
:ivar type: Resource type.
:vartype type: str
:param e_tag: eTag of the resource. To handle concurrent update scenarion,
this field will be used to determine whether the user is updating the
latest version or not.
:type e_tag: str
:param cost_allocation_tags: Cost allocation tags.
:type cost_allocation_tags:
list[~azure.mgmt.consumption.models.CostAllocationTag]
"""

_validation = {
'id': {'readonly': True},
'name': {'readonly': True},
'type': {'readonly': True},
}

_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'name': {'key': 'name', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
'e_tag': {'key': 'eTag', 'type': 'str'},
'cost_allocation_tags': {'key': 'properties.costAllocationTags', 'type': '[CostAllocationTag]'},
}

def __init__(self, e_tag=None, cost_allocation_tags=None):
super(CostAllocationTags, self).__init__(e_tag=e_tag)
self.cost_allocation_tags = cost_allocation_tags
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .budgets_operations import BudgetsOperations
from .operations import Operations
from .price_sheet_operations import PriceSheetOperations
from .cost_allocation_tags_operations import CostAllocationTagsOperations

__all__ = [
'UsageDetailsOperations',
Expand All @@ -27,4 +28,5 @@
'BudgetsOperations',
'Operations',
'PriceSheetOperations',
'CostAllocationTagsOperations',
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# 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 CostAllocationTagsOperations(object):
"""CostAllocationTagsOperations 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.
:ivar api_version: Version of the API to be used with the client request. The current version is 2018-03-31. Constant value: "2018-03-31".
"""

models = models

def __init__(self, client, config, serializer, deserializer):

self._client = client
self._serialize = serializer
self._deserialize = deserializer
self.api_version = "2018-03-31"

self.config = config

def get(
self, billing_account_id, custom_headers=None, raw=False, **operation_config):
"""Get cost allocation tags for a billing account.
:param billing_account_id: Azure Billing Account ID.
:type billing_account_id: str
: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: CostAllocationTags or ClientRawResponse if raw=true
:rtype: ~azure.mgmt.consumption.models.CostAllocationTags or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`ErrorResponseException<azure.mgmt.consumption.models.ErrorResponseException>`
"""
# Construct URL
url = self.get.metadata['url']
path_format_arguments = {
'billingAccountId': self._serialize.url("billing_account_id", billing_account_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['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 and send request
request = self._client.get(url, query_parameters)
response = self._client.send(request, header_parameters, 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('CostAllocationTags', response)

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

return deserialized
get.metadata = {'url': '/providers/Microsoft.CostManagement/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/costAllocationTags'}

def create_or_update(
self, billing_account_id, e_tag=None, cost_allocation_tags=None, custom_headers=None, raw=False, **operation_config):
"""The operation to create or update cost allocation tags assiciated with
a billing account. Update operation requires latest eTag to be set in
the request mandatorily. You may obtain the latest eTag by performing a
get operation. Create operation does not require eTag.
:param billing_account_id: Azure Billing Account ID.
:type billing_account_id: str
:param e_tag: eTag of the resource. To handle concurrent update
scenarion, this field will be used to determine whether the user is
updating the latest version or not.
:type e_tag: str
:param cost_allocation_tags: Cost allocation tags.
:type cost_allocation_tags:
list[~azure.mgmt.consumption.models.CostAllocationTag]
: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: CostAllocationTags or ClientRawResponse if raw=true
:rtype: ~azure.mgmt.consumption.models.CostAllocationTags or
~msrest.pipeline.ClientRawResponse
:raises:
:class:`ErrorResponseException<azure.mgmt.consumption.models.ErrorResponseException>`
"""
parameters = models.CostAllocationTags(e_tag=e_tag, cost_allocation_tags=cost_allocation_tags)

# Construct URL
url = self.create_or_update.metadata['url']
path_format_arguments = {
'billingAccountId': self._serialize.url("billing_account_id", billing_account_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['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, 'CostAllocationTags')

# Construct and send request
request = self._client.put(url, query_parameters)
response = self._client.send(
request, header_parameters, body_content, stream=False, **operation_config)

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

deserialized = None

if response.status_code == 200:
deserialized = self._deserialize('CostAllocationTags', response)
if response.status_code == 201:
deserialized = self._deserialize('CostAllocationTags', response)

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

return deserialized
create_or_update.metadata = {'url': '/providers/Microsoft.CostManagement/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/costAllocationTags'}
Loading

0 comments on commit ef356ef

Please sign in to comment.