Skip to content

Commit

Permalink
CodeGen from PR 22637 in Azure/azure-rest-api-specs
Browse files Browse the repository at this point in the history
Merge 95bf03e972fb51757a490a10ca21d6c8fc7b577b into ac7f9d6f1003acf6e54682534f30a9f5ec7fc5d2
  • Loading branch information
SDKAuto committed Feb 27, 2023
1 parent aaec274 commit 874f761
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 46 deletions.
4 changes: 2 additions & 2 deletions sdk/commerce/azure-mgmt-commerce/_meta.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"commit": "18e0a756cd948b08cec7d4264f2dbbbfa53246ac",
"commit": "7169b6e1f8a67633adfb1451441861fba16dcc4d",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"autorest": "3.9.2",
"use": [
"@autorest/python@6.4.0",
"@autorest/modelerfour@4.24.3"
],
"autorest_command": "autorest specification/commerce/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/home/vsts/work/1/azure-sdk-for-python/sdk --use=@autorest/python@6.4.0 --use=@autorest/modelerfour@4.24.3 --version=3.9.2 --version-tolerant=False",
"autorest_command": "autorest specification/commerce/resource-manager/readme.md --generate-sample=True --include-x-ms-examples-original-file=True --python --python-sdks-folder=/mnt/vss/_work/1/s/azure-sdk-for-python/sdk --use=@autorest/python@6.4.0 --use=@autorest/modelerfour@4.24.3 --version=3.9.2 --version-tolerant=False",
"readme": "specification/commerce/resource-manager/readme.md"
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class UsageManagementClient: # pylint: disable=client-accepts-api-version-keywo
:keyword api_version: Api Version. Default value is "2015-06-01-preview". Note that overriding
this default value may result in unsupported behavior.
:paramtype api_version: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

VERSION = "6.1.0b1"
VERSION = "1.0.0b1"
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class UsageManagementClient: # pylint: disable=client-accepts-api-version-keywo
:keyword api_version: Api Version. Default value is "2015-06-01-preview". Note that overriding
this default value may result in unsupported behavior.
:paramtype api_version: str
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# --------------------------------------------------------------------------
import datetime
import sys
from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union
from typing import Any, AsyncIterable, Callable, Dict, Optional, TypeVar, Union, cast
import urllib.parse

from azure.core.async_paging import AsyncItemPaged, AsyncList
Expand All @@ -22,10 +22,13 @@
)
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import AsyncHttpResponse
from azure.core.polling import AsyncLROPoller, AsyncNoPolling, AsyncPollingMethod
from azure.core.rest import HttpRequest
from azure.core.tracing.decorator import distributed_trace
from azure.core.tracing.decorator_async import distributed_trace_async
from azure.core.utils import case_insensitive_dict
from azure.mgmt.core.exceptions import ARMErrorFormat
from azure.mgmt.core.polling.async_arm_polling import AsyncARMPolling

from ... import models as _models
from ..._vendor import _convert_request
Expand Down Expand Up @@ -58,16 +61,83 @@ def __init__(self, *args, **kwargs) -> None:
self._serialize = input_args.pop(0) if input_args else kwargs.pop("serializer")
self._deserialize = input_args.pop(0) if input_args else kwargs.pop("deserializer")

@distributed_trace
def list(
async def _list_initial(
self,
reported_start_time: datetime.datetime,
reported_end_time: datetime.datetime,
show_details: Optional[bool] = None,
aggregation_granularity: Union[str, _models.AggregationGranularity] = "Daily",
continuation_token_parameter: Optional[str] = None,
**kwargs: Any
) -> AsyncIterable["_models.UsageAggregation"]:
) -> Union[_models.UsageAggregationListResult, _models.ErrorResponse]:
error_map = {
401: ClientAuthenticationError,
404: ResourceNotFoundError,
409: ResourceExistsError,
304: ResourceNotModifiedError,
}
error_map.update(kwargs.pop("error_map", {}) or {})

_headers = kwargs.pop("headers", {}) or {}
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

api_version: Literal["2015-06-01-preview"] = kwargs.pop(
"api_version", _params.pop("api-version", self._config.api_version)
)
cls: ClsType[Union[_models.UsageAggregationListResult, _models.ErrorResponse]] = kwargs.pop("cls", None)

request = build_list_request(
subscription_id=self._config.subscription_id,
reported_start_time=reported_start_time,
reported_end_time=reported_end_time,
show_details=show_details,
aggregation_granularity=aggregation_granularity,
continuation_token_parameter=continuation_token_parameter,
api_version=api_version,
template_url=self._list_initial.metadata["url"],
headers=_headers,
params=_params,
)
request = _convert_request(request)
request.url = self._client.format_url(request.url)

pipeline_response: PipelineResponse = await self._client._pipeline.run( # pylint: disable=protected-access
request, stream=False, **kwargs
)

response = pipeline_response.http_response

if response.status_code not in [200, 202]:
map_error(status_code=response.status_code, response=response, error_map=error_map)
error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response)
raise HttpResponseError(response=response, model=error, error_format=ARMErrorFormat)

response_headers = {}
if response.status_code == 200:
deserialized = self._deserialize("UsageAggregationListResult", pipeline_response)

if response.status_code == 202:
response_headers["Location"] = self._deserialize("str", response.headers.get("Location"))

deserialized = self._deserialize("ErrorResponse", pipeline_response)

if cls:
return cls(pipeline_response, deserialized, response_headers) # type: ignore

return deserialized # type: ignore

_list_initial.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Commerce/UsageAggregates"}

@distributed_trace_async
async def begin_list(
self,
reported_start_time: datetime.datetime,
reported_end_time: datetime.datetime,
show_details: Optional[bool] = None,
aggregation_granularity: Union[str, _models.AggregationGranularity] = "Daily",
continuation_token_parameter: Optional[str] = None,
**kwargs: Any
) -> AsyncLROPoller[AsyncIterable["_models.UsageAggregation"]]:
"""Query aggregated Azure subscription consumption data for a date range.
.. seealso::
Expand All @@ -94,10 +164,21 @@ def list(
Default value is None.
:type continuation_token_parameter: str
:keyword callable cls: A custom type or function that will be passed the direct response
:return: An iterator like instance of either UsageAggregation or the result of cls(response)
:rtype: ~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.commerce.models.UsageAggregation]
:keyword str continuation_token: A continuation token to restart a poller from a saved state.
:keyword polling: By default, your polling method will be AsyncARMPolling. Pass in False for
this operation to not poll, or pass in your own initialized polling object for a personal
polling strategy.
:paramtype polling: bool or ~azure.core.polling.AsyncPollingMethod
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
:return: An instance of LROPoller that returns an iterator like instance of either
UsageAggregationListResult or An instance of LROPoller that returns an iterator like instance
of either ErrorResponse or the result of cls(response)
:rtype:
~azure.core.polling.AsyncLROPoller[~azure.core.async_paging.AsyncItemPaged[~azure.mgmt.commerce.models.UsageAggregation]]
:raises ~azure.core.exceptions.HttpResponseError:
"""

_headers = kwargs.pop("headers", {}) or {}
_params = case_insensitive_dict(kwargs.pop("params", {}) or {})

Expand Down Expand Up @@ -125,7 +206,7 @@ def prepare_request(next_link=None):
aggregation_granularity=aggregation_granularity,
continuation_token_parameter=continuation_token_parameter,
api_version=api_version,
template_url=self.list.metadata["url"],
template_url=self.begin_list.metadata["url"],
headers=_headers,
params=_params,
)
Expand Down Expand Up @@ -172,6 +253,47 @@ async def get_next(next_link=None):

return pipeline_response

return AsyncItemPaged(get_next, extract_data)
polling: Union[bool, AsyncPollingMethod] = kwargs.pop("polling", True)
lro_delay = kwargs.pop("polling_interval", self._config.polling_interval)
cont_token: Optional[str] = kwargs.pop("continuation_token", None)
if cont_token is None:
raw_result = await self._list_initial(
reported_start_time=reported_start_time,
reported_end_time=reported_end_time,
show_details=show_details,
aggregation_granularity=aggregation_granularity,
continuation_token_parameter=continuation_token_parameter,
api_version=api_version,
cls=lambda x, y, z: x,
headers=_headers,
params=_params,
**kwargs
)
kwargs.pop("error_map", None)

def get_long_running_output(pipeline_response):
async def internal_get_next(next_link=None):
if next_link is None:
return pipeline_response
return await get_next(next_link)

return AsyncItemPaged(internal_get_next, extract_data)

if polling is True:
polling_method: AsyncPollingMethod = cast(
AsyncPollingMethod, AsyncARMPolling(lro_delay, lro_options={"final-state-via": "location"}, **kwargs)
)
elif polling is False:
polling_method = cast(AsyncPollingMethod, AsyncNoPolling())
else:
polling_method = polling
if cont_token:
return AsyncLROPoller.from_continuation_token(
polling_method=polling_method,
continuation_token=cont_token,
client=self._client,
deserialization_callback=get_long_running_output,
)
return AsyncLROPoller(self._client, raw_result, get_long_running_output, polling_method) # type: ignore

list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Commerce/UsageAggregates"}
begin_list.metadata = {"url": "/subscriptions/{subscriptionId}/providers/Microsoft.Commerce/UsageAggregates"}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# --------------------------------------------------------------------------

from ._models_py3 import ErrorResponse
from ._models_py3 import InfoField
from ._models_py3 import MeterInfo
from ._models_py3 import MonetaryCommitment
from ._models_py3 import MonetaryCredit
Expand All @@ -26,7 +25,6 @@

__all__ = [
"ErrorResponse",
"InfoField",
"MeterInfo",
"MonetaryCommitment",
"MonetaryCredit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,6 @@ def __init__(self, *, code: Optional[str] = None, message: Optional[str] = None,
self.message = message


class InfoField(_serialization.Model):
"""Key-value pairs of instance details in the legacy format.
:ivar project: Identifies the name of the instance provisioned by the user.
:vartype project: str
"""

_attribute_map = {
"project": {"key": "project", "type": "str"},
}

def __init__(self, *, project: Optional[str] = None, **kwargs: Any) -> None:
"""
:keyword project: Identifies the name of the instance provisioned by the user.
:paramtype project: str
"""
super().__init__(**kwargs)
self.project = project


class MeterInfo(_serialization.Model):
"""Detailed information about the meter.
Expand Down Expand Up @@ -485,7 +465,7 @@ class UsageAggregation(_serialization.Model): # pylint: disable=too-many-instan
:ivar meter_region: Region of the meterId used for billing purposes.
:vartype meter_region: str
:ivar info_fields: Key-value pairs of instance details (legacy format).
:vartype info_fields: ~azure.mgmt.commerce.models.InfoField
:vartype info_fields: any
:ivar instance_data: Key-value pairs of instance details represented as a string.
:vartype instance_data: str
"""
Expand All @@ -504,7 +484,7 @@ class UsageAggregation(_serialization.Model): # pylint: disable=too-many-instan
"meter_category": {"key": "properties.meterCategory", "type": "str"},
"meter_sub_category": {"key": "properties.meterSubCategory", "type": "str"},
"meter_region": {"key": "properties.meterRegion", "type": "str"},
"info_fields": {"key": "properties.infoFields", "type": "InfoField"},
"info_fields": {"key": "properties.infoFields", "type": "object"},
"instance_data": {"key": "properties.instanceData", "type": "str"},
}

Expand All @@ -524,7 +504,7 @@ def __init__(
meter_category: Optional[str] = None,
meter_sub_category: Optional[str] = None,
meter_region: Optional[str] = None,
info_fields: Optional["_models.InfoField"] = None,
info_fields: Optional[Any] = None,
instance_data: Optional[str] = None,
**kwargs: Any
) -> None:
Expand Down Expand Up @@ -558,7 +538,7 @@ def __init__(
:keyword meter_region: Region of the meterId used for billing purposes.
:paramtype meter_region: str
:keyword info_fields: Key-value pairs of instance details (legacy format).
:paramtype info_fields: ~azure.mgmt.commerce.models.InfoField
:paramtype info_fields: any
:keyword instance_data: Key-value pairs of instance details represented as a string.
:paramtype instance_data: str
"""
Expand Down
Loading

0 comments on commit 874f761

Please sign in to comment.