1# coding=utf-8 2# -------------------------------------------------------------------------- 3# Copyright (c) Microsoft Corporation. All rights reserved. 4# Licensed under the MIT License. See License.txt in the project root for 5# license information. 6# 7# Code generated by Microsoft (R) AutoRest Code Generator. 8# Changes may cause incorrect behavior and will be lost if the code is 9# regenerated. 10# -------------------------------------------------------------------------- 11 12import uuid 13from msrest.pipeline import ClientRawResponse 14 15from .. import models 16 17 18class BalancesOperations(object): 19 """BalancesOperations operations. 20 21 :param client: Client for service requests. 22 :param config: Configuration of service client. 23 :param serializer: An object model serializer. 24 :param deserializer: An object model deserializer. 25 :ivar api_version: Version of the API to be used with the client request. The current version is 2019-04-01-preview. Constant value: "2019-04-01-preview". 26 """ 27 28 models = models 29 30 def __init__(self, client, config, serializer, deserializer): 31 32 self._client = client 33 self._serialize = serializer 34 self._deserialize = deserializer 35 self.api_version = "2019-04-01-preview" 36 37 self.config = config 38 39 def get_by_billing_account( 40 self, billing_account_id, custom_headers=None, raw=False, **operation_config): 41 """Gets the balances for a scope by billingAccountId. Balances are 42 available via this API only for May 1, 2014 or later. 43 44 :param billing_account_id: BillingAccount ID 45 :type billing_account_id: str 46 :param dict custom_headers: headers that will be added to the request 47 :param bool raw: returns the direct response alongside the 48 deserialized response 49 :param operation_config: :ref:`Operation configuration 50 overrides<msrest:optionsforoperations>`. 51 :return: Balance or ClientRawResponse if raw=true 52 :rtype: ~azure.mgmt.consumption.models.Balance or 53 ~msrest.pipeline.ClientRawResponse 54 :raises: 55 :class:`ErrorResponseException<azure.mgmt.consumption.models.ErrorResponseException>` 56 """ 57 # Construct URL 58 url = self.get_by_billing_account.metadata['url'] 59 path_format_arguments = { 60 'billingAccountId': self._serialize.url("billing_account_id", billing_account_id, 'str') 61 } 62 url = self._client.format_url(url, **path_format_arguments) 63 64 # Construct parameters 65 query_parameters = {} 66 query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') 67 68 # Construct headers 69 header_parameters = {} 70 header_parameters['Accept'] = 'application/json' 71 if self.config.generate_client_request_id: 72 header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) 73 if custom_headers: 74 header_parameters.update(custom_headers) 75 if self.config.accept_language is not None: 76 header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') 77 78 # Construct and send request 79 request = self._client.get(url, query_parameters, header_parameters) 80 response = self._client.send(request, stream=False, **operation_config) 81 82 if response.status_code not in [200]: 83 raise models.ErrorResponseException(self._deserialize, response) 84 85 deserialized = None 86 87 if response.status_code == 200: 88 deserialized = self._deserialize('Balance', response) 89 90 if raw: 91 client_raw_response = ClientRawResponse(deserialized, response) 92 return client_raw_response 93 94 return deserialized 95 get_by_billing_account.metadata = {'url': '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/balances'} 96 97 def get_for_billing_period_by_billing_account( 98 self, billing_account_id, billing_period_name, custom_headers=None, raw=False, **operation_config): 99 """Gets the balances for a scope by billing period and billingAccountId. 100 Balances are available via this API only for May 1, 2014 or later. 101 102 :param billing_account_id: BillingAccount ID 103 :type billing_account_id: str 104 :param billing_period_name: Billing Period Name. 105 :type billing_period_name: str 106 :param dict custom_headers: headers that will be added to the request 107 :param bool raw: returns the direct response alongside the 108 deserialized response 109 :param operation_config: :ref:`Operation configuration 110 overrides<msrest:optionsforoperations>`. 111 :return: Balance or ClientRawResponse if raw=true 112 :rtype: ~azure.mgmt.consumption.models.Balance or 113 ~msrest.pipeline.ClientRawResponse 114 :raises: 115 :class:`ErrorResponseException<azure.mgmt.consumption.models.ErrorResponseException>` 116 """ 117 # Construct URL 118 url = self.get_for_billing_period_by_billing_account.metadata['url'] 119 path_format_arguments = { 120 'billingAccountId': self._serialize.url("billing_account_id", billing_account_id, 'str'), 121 'billingPeriodName': self._serialize.url("billing_period_name", billing_period_name, 'str') 122 } 123 url = self._client.format_url(url, **path_format_arguments) 124 125 # Construct parameters 126 query_parameters = {} 127 query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str') 128 129 # Construct headers 130 header_parameters = {} 131 header_parameters['Accept'] = 'application/json' 132 if self.config.generate_client_request_id: 133 header_parameters['x-ms-client-request-id'] = str(uuid.uuid1()) 134 if custom_headers: 135 header_parameters.update(custom_headers) 136 if self.config.accept_language is not None: 137 header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str') 138 139 # Construct and send request 140 request = self._client.get(url, query_parameters, header_parameters) 141 response = self._client.send(request, stream=False, **operation_config) 142 143 if response.status_code not in [200]: 144 raise models.ErrorResponseException(self._deserialize, response) 145 146 deserialized = None 147 148 if response.status_code == 200: 149 deserialized = self._deserialize('Balance', response) 150 151 if raw: 152 client_raw_response = ClientRawResponse(deserialized, response) 153 return client_raw_response 154 155 return deserialized 156 get_for_billing_period_by_billing_account.metadata = {'url': '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/balances'} 157