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 ReservationsSummariesOperations(object):
19    """ReservationsSummariesOperations 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 list_by_reservation_order(
40            self, reservation_order_id, grain, filter=None, custom_headers=None, raw=False, **operation_config):
41        """Lists the reservations summaries for daily or monthly grain.
42
43        :param reservation_order_id: Order Id of the reservation
44        :type reservation_order_id: str
45        :param grain: Can be daily or monthly. Possible values include:
46         'DailyGrain', 'MonthlyGrain'
47        :type grain: str or ~azure.mgmt.consumption.models.Datagrain
48        :param filter: Required only for daily grain. The properties/UsageDate
49         for start date and end date. The filter supports 'le' and  'ge'
50        :type filter: str
51        :param dict custom_headers: headers that will be added to the request
52        :param bool raw: returns the direct response alongside the
53         deserialized response
54        :param operation_config: :ref:`Operation configuration
55         overrides<msrest:optionsforoperations>`.
56        :return: An iterator like instance of ReservationSummary
57        :rtype:
58         ~azure.mgmt.consumption.models.ReservationSummaryPaged[~azure.mgmt.consumption.models.ReservationSummary]
59        :raises:
60         :class:`ErrorResponseException<azure.mgmt.consumption.models.ErrorResponseException>`
61        """
62        def internal_paging(next_link=None, raw=False):
63
64            if not next_link:
65                # Construct URL
66                url = self.list_by_reservation_order.metadata['url']
67                path_format_arguments = {
68                    'reservationOrderId': self._serialize.url("reservation_order_id", reservation_order_id, 'str')
69                }
70                url = self._client.format_url(url, **path_format_arguments)
71
72                # Construct parameters
73                query_parameters = {}
74                query_parameters['grain'] = self._serialize.query("grain", grain, 'str')
75                if filter is not None:
76                    query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
77                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
78
79            else:
80                url = next_link
81                query_parameters = {}
82
83            # Construct headers
84            header_parameters = {}
85            header_parameters['Accept'] = 'application/json'
86            if self.config.generate_client_request_id:
87                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
88            if custom_headers:
89                header_parameters.update(custom_headers)
90            if self.config.accept_language is not None:
91                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
92
93            # Construct and send request
94            request = self._client.get(url, query_parameters, header_parameters)
95            response = self._client.send(request, stream=False, **operation_config)
96
97            if response.status_code not in [200]:
98                raise models.ErrorResponseException(self._deserialize, response)
99
100            return response
101
102        # Deserialize response
103        deserialized = models.ReservationSummaryPaged(internal_paging, self._deserialize.dependencies)
104
105        if raw:
106            header_dict = {}
107            client_raw_response = models.ReservationSummaryPaged(internal_paging, self._deserialize.dependencies, header_dict)
108            return client_raw_response
109
110        return deserialized
111    list_by_reservation_order.metadata = {'url': '/providers/Microsoft.Capacity/reservationorders/{reservationOrderId}/providers/Microsoft.Consumption/reservationSummaries'}
112
113    def list_by_reservation_order_and_reservation(
114            self, reservation_order_id, reservation_id, grain, filter=None, custom_headers=None, raw=False, **operation_config):
115        """Lists the reservations summaries for daily or monthly grain.
116
117        :param reservation_order_id: Order Id of the reservation
118        :type reservation_order_id: str
119        :param reservation_id: Id of the reservation
120        :type reservation_id: str
121        :param grain: Can be daily or monthly. Possible values include:
122         'DailyGrain', 'MonthlyGrain'
123        :type grain: str or ~azure.mgmt.consumption.models.Datagrain
124        :param filter: Required only for daily grain. The properties/UsageDate
125         for start date and end date. The filter supports 'le' and  'ge'
126        :type filter: str
127        :param dict custom_headers: headers that will be added to the request
128        :param bool raw: returns the direct response alongside the
129         deserialized response
130        :param operation_config: :ref:`Operation configuration
131         overrides<msrest:optionsforoperations>`.
132        :return: An iterator like instance of ReservationSummary
133        :rtype:
134         ~azure.mgmt.consumption.models.ReservationSummaryPaged[~azure.mgmt.consumption.models.ReservationSummary]
135        :raises:
136         :class:`ErrorResponseException<azure.mgmt.consumption.models.ErrorResponseException>`
137        """
138        def internal_paging(next_link=None, raw=False):
139
140            if not next_link:
141                # Construct URL
142                url = self.list_by_reservation_order_and_reservation.metadata['url']
143                path_format_arguments = {
144                    'reservationOrderId': self._serialize.url("reservation_order_id", reservation_order_id, 'str'),
145                    'reservationId': self._serialize.url("reservation_id", reservation_id, 'str')
146                }
147                url = self._client.format_url(url, **path_format_arguments)
148
149                # Construct parameters
150                query_parameters = {}
151                query_parameters['grain'] = self._serialize.query("grain", grain, 'str')
152                if filter is not None:
153                    query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
154                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
155
156            else:
157                url = next_link
158                query_parameters = {}
159
160            # Construct headers
161            header_parameters = {}
162            header_parameters['Accept'] = 'application/json'
163            if self.config.generate_client_request_id:
164                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
165            if custom_headers:
166                header_parameters.update(custom_headers)
167            if self.config.accept_language is not None:
168                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
169
170            # Construct and send request
171            request = self._client.get(url, query_parameters, header_parameters)
172            response = self._client.send(request, stream=False, **operation_config)
173
174            if response.status_code not in [200]:
175                raise models.ErrorResponseException(self._deserialize, response)
176
177            return response
178
179        # Deserialize response
180        deserialized = models.ReservationSummaryPaged(internal_paging, self._deserialize.dependencies)
181
182        if raw:
183            header_dict = {}
184            client_raw_response = models.ReservationSummaryPaged(internal_paging, self._deserialize.dependencies, header_dict)
185            return client_raw_response
186
187        return deserialized
188    list_by_reservation_order_and_reservation.metadata = {'url': '/providers/Microsoft.Capacity/reservationorders/{reservationOrderId}/reservations/{reservationId}/providers/Microsoft.Consumption/reservationSummaries'}
189