Skip to content

Commit 49c29f3

Browse files
committed
Configurations: 'specification/consumption/resource-manager/Microsoft.Consumption/Consumption/tspconfig.yaml', API Version: 2024-08-01, SDK Release Type: beta, and CommitSHA: 'aa9df243e9a6ecf6110383e079d622a87bd405d3' in SpecRepo: 'https://github.com/Azure/azure-rest-api-specs' Pipeline run: https://dev.azure.com/azure-sdk/internal/_build/results?buildId=6339407 Refer to https://eng.ms/docs/products/azure-developer-experience/develop/sdk-release/sdk-release-prerequisites to prepare for SDK release.
1 parent a933792 commit 49c29f3

206 files changed

Lines changed: 19130 additions & 15093 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

sdk/consumption/azure-mgmt-consumption/CHANGELOG.md

Lines changed: 240 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
include _meta.json
2-
recursive-include tests *.py *.json
3-
recursive-include samples *.py *.md
41
include *.md
5-
include azure/__init__.py
6-
include azure/mgmt/__init__.py
72
include LICENSE
83
include azure/mgmt/consumption/py.typed
4+
recursive-include tests *.py
5+
recursive-include samples *.py *.md
6+
include azure/__init__.py
7+
include azure/mgmt/__init__.py
Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,61 @@
11
# Microsoft Azure SDK for Python
22

33
This is the Microsoft Azure Consumption Client Library.
4-
This package has been tested with Python 3.7+.
4+
This package has been tested with Python 3.10+.
55
For a more complete view of Azure libraries, see the [azure sdk python release](https://aka.ms/azsdk/python/all).
66

77
## _Disclaimer_
88

99
_Azure SDK Python packages support for Python 2.7 has ended 01 January 2022. For more information and questions, please refer to https://github.com/Azure/azure-sdk-for-python/issues/20691_
1010

11-
# Usage
11+
## Getting started
1212

13+
### Prerequisites
1314

14-
To learn how to use this package, see the [quickstart guide](https://aka.ms/azsdk/python/mgmt)
15-
16-
For docs and references, see [Python SDK References](https://docs.microsoft.com/python/api/overview/azure/consumption)
17-
Code samples for this package can be found at [Consumption](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20-%20Managing&terms=Getting%20started%20-%20Managing) on docs.microsoft.com.
18-
Additional code samples for different Azure services are available at [Samples Repo](https://github.com/Azure-Samples/azure-samples-python-management/tree/main/samples/consumption)
15+
- Python 3.10+ is required to use this package.
16+
- [Azure subscription](https://azure.microsoft.com/free/)
1917

18+
### Install the package
2019

21-
# Provide Feedback
20+
```bash
21+
pip install azure-mgmt-consumption
22+
pip install azure-identity
23+
```
2224

23-
If you encounter any bugs or have suggestions, please file an issue in the
24-
[Issues](https://github.com/Azure/azure-sdk-for-python/issues)
25-
section of the project.
25+
### Authentication
26+
27+
By default, [Azure Active Directory](https://aka.ms/awps/aad) token authentication depends on correct configuration of the following environment variables.
28+
29+
- `AZURE_CLIENT_ID` for Azure client ID.
30+
- `AZURE_TENANT_ID` for Azure tenant ID.
31+
- `AZURE_CLIENT_SECRET` for Azure client secret.
32+
33+
In addition, Azure subscription ID can be configured via environment variable `AZURE_SUBSCRIPTION_ID`.
34+
35+
With above configuration, client can be authenticated by following code:
36+
37+
```python
38+
from azure.identity import DefaultAzureCredential
39+
from azure.mgmt.consumption import ConsumptionManagementClient
40+
import os
2641

42+
sub_id = os.getenv("AZURE_SUBSCRIPTION_ID")
43+
client = ConsumptionManagementClient(credential=DefaultAzureCredential(), subscription_id=sub_id)
44+
```
2745

46+
## Examples
2847

48+
Code samples for this package can be found at:
49+
- [Search Consumption](https://docs.microsoft.com/samples/browse/?languages=python&term=Getting%20started%20-%20Managing&terms=Getting%20started%20-%20Managing) on docs.microsoft.com
50+
- [Azure Python Mgmt SDK Samples Repo](https://aka.ms/azsdk/python/mgmt/samples)
51+
52+
53+
## Troubleshooting
54+
55+
## Next steps
56+
57+
## Provide Feedback
58+
59+
If you encounter any bugs or have suggestions, please file an issue in the
60+
[Issues](https://github.com/Azure/azure-sdk-for-python/issues)
61+
section of the project.

sdk/consumption/azure-mgmt-consumption/_meta.json

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"apiVersion": "2024-08-01",
3+
"apiVersions": {
4+
"Microsoft.Consumption": "2024-08-01"
5+
},
6+
"commit": "aa9df243e9a6ecf6110383e079d622a87bd405d3",
7+
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
8+
"typespec_src": "specification/consumption/resource-manager/Microsoft.Consumption/Consumption",
9+
"emitterVersion": "0.62.1"
10+
}

sdk/consumption/azure-mgmt-consumption/apiview-properties.json

Lines changed: 176 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore

sdk/consumption/azure-mgmt-consumption/azure/mgmt/consumption/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@
22
# --------------------------------------------------------------------------
33
# Copyright (c) Microsoft Corporation. All rights reserved.
44
# Licensed under the MIT License. See License.txt in the project root for license information.
5-
# Code generated by Microsoft (R) AutoRest Code Generator.
5+
# Code generated by Microsoft (R) Python Code Generator.
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
8+
# pylint: disable=wrong-import-position
89

9-
from ._consumption_management_client import ConsumptionManagementClient
10+
from typing import TYPE_CHECKING
11+
12+
if TYPE_CHECKING:
13+
from ._patch import * # pylint: disable=unused-wildcard-import
14+
15+
from ._client import ConsumptionManagementClient # type: ignore
1016
from ._version import VERSION
1117

1218
__version__ = VERSION
1319

1420
try:
1521
from ._patch import __all__ as _patch_all
16-
from ._patch import * # pylint: disable=unused-wildcard-import
22+
from ._patch import *
1723
except ImportError:
1824
_patch_all = []
1925
from ._patch import patch_sdk as _patch_sdk
2026

2127
__all__ = [
2228
"ConsumptionManagementClient",
2329
]
24-
__all__.extend([p for p in _patch_all if p not in __all__])
30+
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore
2531

2632
_patch_sdk()

sdk/consumption/azure-mgmt-consumption/azure/mgmt/consumption/_consumption_management_client.py renamed to sdk/consumption/azure-mgmt-consumption/azure/mgmt/consumption/_client.py

Lines changed: 85 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
# --------------------------------------------------------------------------
33
# Copyright (c) Microsoft Corporation. All rights reserved.
44
# Licensed under the MIT License. See License.txt in the project root for license information.
5-
# Code generated by Microsoft (R) AutoRest Code Generator.
5+
# Code generated by Microsoft (R) Python Code Generator.
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

99
from copy import deepcopy
10-
from typing import Any, TYPE_CHECKING
10+
import sys
11+
from typing import Any, Optional, TYPE_CHECKING, cast
1112

13+
from azure.core.pipeline import policies
1214
from azure.core.rest import HttpRequest, HttpResponse
15+
from azure.core.settings import settings
1316
from azure.mgmt.core import ARMPipelineClient
17+
from azure.mgmt.core.policies import ARMAutoResourceProviderRegistrationPolicy
18+
from azure.mgmt.core.tools import get_arm_endpoints
1419

15-
from . import models as _models
1620
from ._configuration import ConsumptionManagementClientConfiguration
17-
from ._serialization import Deserializer, Serializer
21+
from ._utils.serialization import Deserializer, Serializer
1822
from .operations import (
1923
AggregatedCostOperations,
2024
BalancesOperations,
@@ -35,21 +39,32 @@
3539
UsageDetailsOperations,
3640
)
3741

42+
if sys.version_info >= (3, 11):
43+
from typing import Self
44+
else:
45+
from typing_extensions import Self # type: ignore
46+
3847
if TYPE_CHECKING:
39-
# pylint: disable=unused-import,ungrouped-imports
48+
from azure.core import AzureClouds
4049
from azure.core.credentials import TokenCredential
4150

4251

43-
class ConsumptionManagementClient: # pylint: disable=client-accepts-api-version-keyword,too-many-instance-attributes
52+
class ConsumptionManagementClient: # pylint: disable=too-many-instance-attributes
4453
"""Consumption management client provides access to consumption resources for Azure Enterprise
4554
Subscriptions.
4655
56+
:ivar operations: Operations operations
57+
:vartype operations: azure.mgmt.consumption.operations.Operations
58+
:ivar price_sheet: PriceSheetOperations operations
59+
:vartype price_sheet: azure.mgmt.consumption.operations.PriceSheetOperations
60+
:ivar budgets: BudgetsOperations operations
61+
:vartype budgets: azure.mgmt.consumption.operations.BudgetsOperations
62+
:ivar credits: CreditsOperations operations
63+
:vartype credits: azure.mgmt.consumption.operations.CreditsOperations
4764
:ivar usage_details: UsageDetailsOperations operations
4865
:vartype usage_details: azure.mgmt.consumption.operations.UsageDetailsOperations
4966
:ivar marketplaces: MarketplacesOperations operations
5067
:vartype marketplaces: azure.mgmt.consumption.operations.MarketplacesOperations
51-
:ivar budgets: BudgetsOperations operations
52-
:vartype budgets: azure.mgmt.consumption.operations.BudgetsOperations
5368
:ivar tags: TagsOperations operations
5469
:vartype tags: azure.mgmt.consumption.operations.TagsOperations
5570
:ivar charges: ChargesOperations operations
@@ -70,48 +85,82 @@ class ConsumptionManagementClient: # pylint: disable=client-accepts-api-version
7085
:ivar reservation_transactions: ReservationTransactionsOperations operations
7186
:vartype reservation_transactions:
7287
azure.mgmt.consumption.operations.ReservationTransactionsOperations
73-
:ivar price_sheet: PriceSheetOperations operations
74-
:vartype price_sheet: azure.mgmt.consumption.operations.PriceSheetOperations
75-
:ivar operations: Operations operations
76-
:vartype operations: azure.mgmt.consumption.operations.Operations
7788
:ivar aggregated_cost: AggregatedCostOperations operations
7889
:vartype aggregated_cost: azure.mgmt.consumption.operations.AggregatedCostOperations
7990
:ivar events: EventsOperations operations
8091
:vartype events: azure.mgmt.consumption.operations.EventsOperations
8192
:ivar lots: LotsOperations operations
8293
:vartype lots: azure.mgmt.consumption.operations.LotsOperations
83-
:ivar credits: CreditsOperations operations
84-
:vartype credits: azure.mgmt.consumption.operations.CreditsOperations
85-
:param credential: Credential needed for the client to connect to Azure. Required.
94+
:param credential: Credential used to authenticate requests to the service. Required.
8695
:type credential: ~azure.core.credentials.TokenCredential
87-
:param subscription_id: Azure Subscription ID. Required.
96+
:param subscription_id: The ID of the target subscription. The value must be an UUID. Required.
8897
:type subscription_id: str
89-
:param base_url: Service URL. Default value is "https://management.azure.com".
98+
:param base_url: Service host. Default value is None.
9099
:type base_url: str
91-
:keyword api_version: Api Version. Default value is "2021-10-01". Note that overriding this
92-
default value may result in unsupported behavior.
100+
:keyword cloud_setting: The cloud setting for which to get the ARM endpoint. Default value is
101+
None.
102+
:paramtype cloud_setting: ~azure.core.AzureClouds
103+
:keyword api_version: The API version to use for this operation. Known values are "2024-08-01"
104+
and None. Default value is None. If not set, the operation's default API version will be used.
105+
Note that overriding this default value may result in unsupported behavior.
93106
:paramtype api_version: str
107+
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
108+
Retry-After header is present.
94109
"""
95110

96111
def __init__(
97112
self,
98113
credential: "TokenCredential",
99114
subscription_id: str,
100-
base_url: str = "https://management.azure.com",
115+
base_url: Optional[str] = None,
116+
*,
117+
cloud_setting: Optional["AzureClouds"] = None,
101118
**kwargs: Any
102119
) -> None:
120+
_endpoint = "{endpoint}"
121+
_cloud = cloud_setting or settings.current.azure_cloud # type: ignore
122+
_endpoints = get_arm_endpoints(_cloud)
123+
if not base_url:
124+
base_url = _endpoints["resource_manager"]
125+
credential_scopes = kwargs.pop("credential_scopes", _endpoints["credential_scopes"])
103126
self._config = ConsumptionManagementClientConfiguration(
104-
credential=credential, subscription_id=subscription_id, **kwargs
127+
credential=credential,
128+
subscription_id=subscription_id,
129+
base_url=cast(str, base_url),
130+
cloud_setting=cloud_setting,
131+
credential_scopes=credential_scopes,
132+
**kwargs
105133
)
106-
self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)
107134

108-
client_models = {k: v for k, v in _models.__dict__.items() if isinstance(v, type)}
109-
self._serialize = Serializer(client_models)
110-
self._deserialize = Deserializer(client_models)
135+
_policies = kwargs.pop("policies", None)
136+
if _policies is None:
137+
_policies = [
138+
policies.RequestIdPolicy(**kwargs),
139+
self._config.headers_policy,
140+
self._config.user_agent_policy,
141+
self._config.proxy_policy,
142+
policies.ContentDecodePolicy(**kwargs),
143+
ARMAutoResourceProviderRegistrationPolicy(),
144+
self._config.redirect_policy,
145+
self._config.retry_policy,
146+
self._config.authentication_policy,
147+
self._config.custom_hook_policy,
148+
self._config.logging_policy,
149+
policies.DistributedTracingPolicy(**kwargs),
150+
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
151+
self._config.http_logging_policy,
152+
]
153+
self._client: ARMPipelineClient = ARMPipelineClient(base_url=cast(str, _endpoint), policies=_policies, **kwargs)
154+
155+
self._serialize = Serializer()
156+
self._deserialize = Deserializer()
111157
self._serialize.client_side_validation = False
158+
self.operations = Operations(self._client, self._config, self._serialize, self._deserialize)
159+
self.price_sheet = PriceSheetOperations(self._client, self._config, self._serialize, self._deserialize)
160+
self.budgets = BudgetsOperations(self._client, self._config, self._serialize, self._deserialize)
161+
self.credits = CreditsOperations(self._client, self._config, self._serialize, self._deserialize)
112162
self.usage_details = UsageDetailsOperations(self._client, self._config, self._serialize, self._deserialize)
113163
self.marketplaces = MarketplacesOperations(self._client, self._config, self._serialize, self._deserialize)
114-
self.budgets = BudgetsOperations(self._client, self._config, self._serialize, self._deserialize)
115164
self.tags = TagsOperations(self._client, self._config, self._serialize, self._deserialize)
116165
self.charges = ChargesOperations(self._client, self._config, self._serialize, self._deserialize)
117166
self.balances = BalancesOperations(self._client, self._config, self._serialize, self._deserialize)
@@ -130,20 +179,17 @@ def __init__(
130179
self.reservation_transactions = ReservationTransactionsOperations(
131180
self._client, self._config, self._serialize, self._deserialize
132181
)
133-
self.price_sheet = PriceSheetOperations(self._client, self._config, self._serialize, self._deserialize)
134-
self.operations = Operations(self._client, self._config, self._serialize, self._deserialize)
135182
self.aggregated_cost = AggregatedCostOperations(self._client, self._config, self._serialize, self._deserialize)
136183
self.events = EventsOperations(self._client, self._config, self._serialize, self._deserialize)
137184
self.lots = LotsOperations(self._client, self._config, self._serialize, self._deserialize)
138-
self.credits = CreditsOperations(self._client, self._config, self._serialize, self._deserialize)
139185

140-
def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
186+
def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
141187
"""Runs the network request through the client's chained policies.
142188
143189
>>> from azure.core.rest import HttpRequest
144190
>>> request = HttpRequest("GET", "https://www.example.org/")
145191
<HttpRequest [GET], url: 'https://www.example.org/'>
146-
>>> response = client._send_request(request)
192+
>>> response = client.send_request(request)
147193
<HttpResponse: 200 OK>
148194
149195
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
@@ -156,15 +202,19 @@ def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse:
156202
"""
157203

158204
request_copy = deepcopy(request)
159-
request_copy.url = self._client.format_url(request_copy.url)
160-
return self._client.send_request(request_copy, **kwargs)
205+
path_format_arguments = {
206+
"endpoint": self._serialize.url("self._config.base_url", self._config.base_url, "str", skip_quote=True),
207+
}
208+
209+
request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
210+
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore
161211

162212
def close(self) -> None:
163213
self._client.close()
164214

165-
def __enter__(self) -> "ConsumptionManagementClient":
215+
def __enter__(self) -> Self:
166216
self._client.__enter__()
167217
return self
168218

169-
def __exit__(self, *exc_details) -> None:
219+
def __exit__(self, *exc_details: Any) -> None:
170220
self._client.__exit__(*exc_details)

0 commit comments

Comments
 (0)