1# coding: utf-8
2# Copyright (c) 2016, 2021, Oracle and/or its affiliates.  All rights reserved.
3# This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
4
5from __future__ import absolute_import
6
7from oci._vendor import requests  # noqa: F401
8from oci._vendor import six
9
10from oci import retry, circuit_breaker  # noqa: F401
11from oci.base_client import BaseClient
12from oci.config import get_config_value_or_default, validate_config
13from oci.signer import Signer
14from oci.util import Sentinel, get_signer_from_authentication_type, AUTHENTICATION_TYPE_FIELD_NAME
15from .models import budget_type_mapping
16missing = Sentinel("Missing")
17
18
19class BudgetClient(object):
20    """
21    Use the Budgets API to manage budgets and budget alerts.
22    """
23
24    def __init__(self, config, **kwargs):
25        """
26        Creates a new service client
27
28        :param dict config:
29            Configuration keys and values as per `SDK and Tool Configuration <https://docs.cloud.oracle.com/Content/API/Concepts/sdkconfig.htm>`__.
30            The :py:meth:`~oci.config.from_file` method can be used to load configuration from a file. Alternatively, a ``dict`` can be passed. You can validate_config
31            the dict using :py:meth:`~oci.config.validate_config`
32
33        :param str service_endpoint: (optional)
34            The endpoint of the service to call using this client. For example ``https://iaas.us-ashburn-1.oraclecloud.com``. If this keyword argument is
35            not provided then it will be derived using the region in the config parameter. You should only provide this keyword argument if you have an explicit
36            need to specify a service endpoint.
37
38        :param timeout: (optional)
39            The connection and read timeouts for the client. The default values are connection timeout 10 seconds and read timeout 60 seconds. This keyword argument can be provided
40            as a single float, in which case the value provided is used for both the read and connection timeouts, or as a tuple of two floats. If
41            a tuple is provided then the first value is used as the connection timeout and the second value as the read timeout.
42        :type timeout: float or tuple(float, float)
43
44        :param signer: (optional)
45            The signer to use when signing requests made by the service client. The default is to use a :py:class:`~oci.signer.Signer` based on the values
46            provided in the config parameter.
47
48            One use case for this parameter is for `Instance Principals authentication <https://docs.cloud.oracle.com/Content/Identity/Tasks/callingservicesfrominstances.htm>`__
49            by passing an instance of :py:class:`~oci.auth.signers.InstancePrincipalsSecurityTokenSigner` as the value for this keyword argument
50        :type signer: :py:class:`~oci.signer.AbstractBaseSigner`
51
52        :param obj retry_strategy: (optional)
53            A retry strategy to apply to all calls made by this service client (i.e. at the client level). There is no retry strategy applied by default.
54            Retry strategies can also be applied at the operation level by passing a ``retry_strategy`` keyword argument as part of calling the operation.
55            Any value provided at the operation level will override whatever is specified at the client level.
56
57            This should be one of the strategies available in the :py:mod:`~oci.retry` module. A convenience :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY`
58            is also available. The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
59
60        :param obj circuit_breaker_strategy: (optional)
61            A circuit breaker strategy to apply to all calls made by this service client (i.e. at the client level).
62            This client uses :py:data:`~oci.circuit_breaker.DEFAULT_CIRCUIT_BREAKER_STRATEGY` as default if no circuit breaker strategy is provided.
63            The specifics of circuit breaker strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/circuit_breakers.html>`__.
64
65        :param function circuit_breaker_callback: (optional)
66            Callback function to receive any exceptions triggerred by the circuit breaker.
67        """
68        validate_config(config, signer=kwargs.get('signer'))
69        if 'signer' in kwargs:
70            signer = kwargs['signer']
71
72        elif AUTHENTICATION_TYPE_FIELD_NAME in config:
73            signer = get_signer_from_authentication_type(config)
74
75        else:
76            signer = Signer(
77                tenancy=config["tenancy"],
78                user=config["user"],
79                fingerprint=config["fingerprint"],
80                private_key_file_location=config.get("key_file"),
81                pass_phrase=get_config_value_or_default(config, "pass_phrase"),
82                private_key_content=config.get("key_content")
83            )
84
85        base_client_init_kwargs = {
86            'regional_client': True,
87            'service_endpoint': kwargs.get('service_endpoint'),
88            'base_path': '/20190111',
89            'service_endpoint_template': 'https://usage.{region}.oci.{secondLevelDomain}',
90            'skip_deserialization': kwargs.get('skip_deserialization', False),
91            'circuit_breaker_strategy': kwargs.get('circuit_breaker_strategy', circuit_breaker.GLOBAL_CIRCUIT_BREAKER_STRATEGY)
92        }
93        if 'timeout' in kwargs:
94            base_client_init_kwargs['timeout'] = kwargs.get('timeout')
95        if base_client_init_kwargs.get('circuit_breaker_strategy') is None:
96            base_client_init_kwargs['circuit_breaker_strategy'] = circuit_breaker.DEFAULT_CIRCUIT_BREAKER_STRATEGY
97        self.base_client = BaseClient("budget", config, signer, budget_type_mapping, **base_client_init_kwargs)
98        self.retry_strategy = kwargs.get('retry_strategy')
99        self.circuit_breaker_callback = kwargs.get('circuit_breaker_callback')
100
101    def create_alert_rule(self, budget_id, create_alert_rule_details, **kwargs):
102        """
103        Creates a new Alert Rule.
104
105
106        :param str budget_id: (required)
107            The unique Budget OCID
108
109        :param oci.budget.models.CreateAlertRuleDetails create_alert_rule_details: (required)
110            Details for the new Alert Rule.
111
112        :param str opc_retry_token: (optional)
113            A token that uniquely identifies a request so it can be retried in case of a timeout or
114            server error without risk of executing that same action again. Retry tokens expire after 24
115            hours, but can be invalidated before then due to conflicting operations. For example, if a resource
116            has been deleted and purged from the system, then a retry of the original creation request
117            might be rejected.
118
119        :param str opc_request_id: (optional)
120            The client request ID for tracing.
121
122        :param obj retry_strategy: (optional)
123            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.
124
125            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
126            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
127
128            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.
129
130        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.budget.models.AlertRule`
131        :rtype: :class:`~oci.response.Response`
132
133        :example:
134        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/budget/create_alert_rule.py.html>`__ to see an example of how to use create_alert_rule API.
135        """
136        resource_path = "/budgets/{budgetId}/alertRules"
137        method = "POST"
138
139        # Don't accept unknown kwargs
140        expected_kwargs = [
141            "retry_strategy",
142            "opc_retry_token",
143            "opc_request_id"
144        ]
145        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
146        if extra_kwargs:
147            raise ValueError(
148                "create_alert_rule got unknown kwargs: {!r}".format(extra_kwargs))
149
150        path_params = {
151            "budgetId": budget_id
152        }
153
154        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}
155
156        for (k, v) in six.iteritems(path_params):
157            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
158                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))
159
160        header_params = {
161            "accept": "application/json",
162            "content-type": "application/json",
163            "opc-retry-token": kwargs.get("opc_retry_token", missing),
164            "opc-request-id": kwargs.get("opc_request_id", missing)
165        }
166        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}
167
168        retry_strategy = self.base_client.get_preferred_retry_strategy(
169            operation_retry_strategy=kwargs.get('retry_strategy'),
170            client_retry_strategy=self.retry_strategy
171        )
172
173        if retry_strategy:
174            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
175                self.base_client.add_opc_retry_token_if_needed(header_params)
176                self.base_client.add_opc_client_retries_header(header_params)
177                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
178            return retry_strategy.make_retrying_call(
179                self.base_client.call_api,
180                resource_path=resource_path,
181                method=method,
182                path_params=path_params,
183                header_params=header_params,
184                body=create_alert_rule_details,
185                response_type="AlertRule")
186        else:
187            return self.base_client.call_api(
188                resource_path=resource_path,
189                method=method,
190                path_params=path_params,
191                header_params=header_params,
192                body=create_alert_rule_details,
193                response_type="AlertRule")
194
195    def create_budget(self, create_budget_details, **kwargs):
196        """
197        Creates a new Budget.
198
199
200        :param oci.budget.models.CreateBudgetDetails create_budget_details: (required)
201            Details for the new Budget.
202
203        :param str opc_retry_token: (optional)
204            A token that uniquely identifies a request so it can be retried in case of a timeout or
205            server error without risk of executing that same action again. Retry tokens expire after 24
206            hours, but can be invalidated before then due to conflicting operations. For example, if a resource
207            has been deleted and purged from the system, then a retry of the original creation request
208            might be rejected.
209
210        :param str opc_request_id: (optional)
211            The client request ID for tracing.
212
213        :param obj retry_strategy: (optional)
214            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.
215
216            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
217            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
218
219            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.
220
221        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.budget.models.Budget`
222        :rtype: :class:`~oci.response.Response`
223
224        :example:
225        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/budget/create_budget.py.html>`__ to see an example of how to use create_budget API.
226        """
227        resource_path = "/budgets"
228        method = "POST"
229
230        # Don't accept unknown kwargs
231        expected_kwargs = [
232            "retry_strategy",
233            "opc_retry_token",
234            "opc_request_id"
235        ]
236        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
237        if extra_kwargs:
238            raise ValueError(
239                "create_budget got unknown kwargs: {!r}".format(extra_kwargs))
240
241        header_params = {
242            "accept": "application/json",
243            "content-type": "application/json",
244            "opc-retry-token": kwargs.get("opc_retry_token", missing),
245            "opc-request-id": kwargs.get("opc_request_id", missing)
246        }
247        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}
248
249        retry_strategy = self.base_client.get_preferred_retry_strategy(
250            operation_retry_strategy=kwargs.get('retry_strategy'),
251            client_retry_strategy=self.retry_strategy
252        )
253
254        if retry_strategy:
255            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
256                self.base_client.add_opc_retry_token_if_needed(header_params)
257                self.base_client.add_opc_client_retries_header(header_params)
258                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
259            return retry_strategy.make_retrying_call(
260                self.base_client.call_api,
261                resource_path=resource_path,
262                method=method,
263                header_params=header_params,
264                body=create_budget_details,
265                response_type="Budget")
266        else:
267            return self.base_client.call_api(
268                resource_path=resource_path,
269                method=method,
270                header_params=header_params,
271                body=create_budget_details,
272                response_type="Budget")
273
274    def delete_alert_rule(self, budget_id, alert_rule_id, **kwargs):
275        """
276        Deletes a specified Alert Rule resource.
277
278
279        :param str budget_id: (required)
280            The unique Budget OCID
281
282        :param str alert_rule_id: (required)
283            The unique Alert Rule OCID
284
285        :param str if_match: (optional)
286            For optimistic concurrency control. In the PUT or DELETE call
287            for a resource, set the `if-match` parameter to the value of the
288            etag from a previous GET or POST response for that resource.
289            The resource will be updated or deleted only if the etag you
290            provide matches the resource's current etag value.
291
292        :param str opc_request_id: (optional)
293            The client request ID for tracing.
294
295        :param obj retry_strategy: (optional)
296            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.
297
298            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
299            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
300
301            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.
302
303        :return: A :class:`~oci.response.Response` object with data of type None
304        :rtype: :class:`~oci.response.Response`
305
306        :example:
307        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/budget/delete_alert_rule.py.html>`__ to see an example of how to use delete_alert_rule API.
308        """
309        resource_path = "/budgets/{budgetId}/alertRules/{alertRuleId}"
310        method = "DELETE"
311
312        # Don't accept unknown kwargs
313        expected_kwargs = [
314            "retry_strategy",
315            "if_match",
316            "opc_request_id"
317        ]
318        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
319        if extra_kwargs:
320            raise ValueError(
321                "delete_alert_rule got unknown kwargs: {!r}".format(extra_kwargs))
322
323        path_params = {
324            "budgetId": budget_id,
325            "alertRuleId": alert_rule_id
326        }
327
328        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}
329
330        for (k, v) in six.iteritems(path_params):
331            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
332                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))
333
334        header_params = {
335            "accept": "application/json",
336            "content-type": "application/json",
337            "if-match": kwargs.get("if_match", missing),
338            "opc-request-id": kwargs.get("opc_request_id", missing)
339        }
340        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}
341
342        retry_strategy = self.base_client.get_preferred_retry_strategy(
343            operation_retry_strategy=kwargs.get('retry_strategy'),
344            client_retry_strategy=self.retry_strategy
345        )
346
347        if retry_strategy:
348            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
349                self.base_client.add_opc_client_retries_header(header_params)
350                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
351            return retry_strategy.make_retrying_call(
352                self.base_client.call_api,
353                resource_path=resource_path,
354                method=method,
355                path_params=path_params,
356                header_params=header_params)
357        else:
358            return self.base_client.call_api(
359                resource_path=resource_path,
360                method=method,
361                path_params=path_params,
362                header_params=header_params)
363
364    def delete_budget(self, budget_id, **kwargs):
365        """
366        Deletes a specified Budget resource
367
368
369        :param str budget_id: (required)
370            The unique Budget OCID
371
372        :param str if_match: (optional)
373            For optimistic concurrency control. In the PUT or DELETE call
374            for a resource, set the `if-match` parameter to the value of the
375            etag from a previous GET or POST response for that resource.
376            The resource will be updated or deleted only if the etag you
377            provide matches the resource's current etag value.
378
379        :param str opc_request_id: (optional)
380            The client request ID for tracing.
381
382        :param obj retry_strategy: (optional)
383            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.
384
385            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
386            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
387
388            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.
389
390        :return: A :class:`~oci.response.Response` object with data of type None
391        :rtype: :class:`~oci.response.Response`
392
393        :example:
394        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/budget/delete_budget.py.html>`__ to see an example of how to use delete_budget API.
395        """
396        resource_path = "/budgets/{budgetId}"
397        method = "DELETE"
398
399        # Don't accept unknown kwargs
400        expected_kwargs = [
401            "retry_strategy",
402            "if_match",
403            "opc_request_id"
404        ]
405        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
406        if extra_kwargs:
407            raise ValueError(
408                "delete_budget got unknown kwargs: {!r}".format(extra_kwargs))
409
410        path_params = {
411            "budgetId": budget_id
412        }
413
414        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}
415
416        for (k, v) in six.iteritems(path_params):
417            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
418                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))
419
420        header_params = {
421            "accept": "application/json",
422            "content-type": "application/json",
423            "if-match": kwargs.get("if_match", missing),
424            "opc-request-id": kwargs.get("opc_request_id", missing)
425        }
426        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}
427
428        retry_strategy = self.base_client.get_preferred_retry_strategy(
429            operation_retry_strategy=kwargs.get('retry_strategy'),
430            client_retry_strategy=self.retry_strategy
431        )
432
433        if retry_strategy:
434            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
435                self.base_client.add_opc_client_retries_header(header_params)
436                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
437            return retry_strategy.make_retrying_call(
438                self.base_client.call_api,
439                resource_path=resource_path,
440                method=method,
441                path_params=path_params,
442                header_params=header_params)
443        else:
444            return self.base_client.call_api(
445                resource_path=resource_path,
446                method=method,
447                path_params=path_params,
448                header_params=header_params)
449
450    def get_alert_rule(self, budget_id, alert_rule_id, **kwargs):
451        """
452        Gets an Alert Rule for a specified Budget.
453
454
455        :param str budget_id: (required)
456            The unique Budget OCID
457
458        :param str alert_rule_id: (required)
459            The unique Alert Rule OCID
460
461        :param str opc_request_id: (optional)
462            The client request ID for tracing.
463
464        :param obj retry_strategy: (optional)
465            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.
466
467            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
468            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
469
470            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.
471
472        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.budget.models.AlertRule`
473        :rtype: :class:`~oci.response.Response`
474
475        :example:
476        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/budget/get_alert_rule.py.html>`__ to see an example of how to use get_alert_rule API.
477        """
478        resource_path = "/budgets/{budgetId}/alertRules/{alertRuleId}"
479        method = "GET"
480
481        # Don't accept unknown kwargs
482        expected_kwargs = [
483            "retry_strategy",
484            "opc_request_id"
485        ]
486        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
487        if extra_kwargs:
488            raise ValueError(
489                "get_alert_rule got unknown kwargs: {!r}".format(extra_kwargs))
490
491        path_params = {
492            "budgetId": budget_id,
493            "alertRuleId": alert_rule_id
494        }
495
496        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}
497
498        for (k, v) in six.iteritems(path_params):
499            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
500                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))
501
502        header_params = {
503            "accept": "application/json",
504            "content-type": "application/json",
505            "opc-request-id": kwargs.get("opc_request_id", missing)
506        }
507        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}
508
509        retry_strategy = self.base_client.get_preferred_retry_strategy(
510            operation_retry_strategy=kwargs.get('retry_strategy'),
511            client_retry_strategy=self.retry_strategy
512        )
513
514        if retry_strategy:
515            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
516                self.base_client.add_opc_client_retries_header(header_params)
517                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
518            return retry_strategy.make_retrying_call(
519                self.base_client.call_api,
520                resource_path=resource_path,
521                method=method,
522                path_params=path_params,
523                header_params=header_params,
524                response_type="AlertRule")
525        else:
526            return self.base_client.call_api(
527                resource_path=resource_path,
528                method=method,
529                path_params=path_params,
530                header_params=header_params,
531                response_type="AlertRule")
532
533    def get_budget(self, budget_id, **kwargs):
534        """
535        Gets a Budget by identifier
536
537
538        :param str budget_id: (required)
539            The unique Budget OCID
540
541        :param str opc_request_id: (optional)
542            The client request ID for tracing.
543
544        :param obj retry_strategy: (optional)
545            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.
546
547            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
548            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
549
550            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.
551
552        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.budget.models.Budget`
553        :rtype: :class:`~oci.response.Response`
554
555        :example:
556        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/budget/get_budget.py.html>`__ to see an example of how to use get_budget API.
557        """
558        resource_path = "/budgets/{budgetId}"
559        method = "GET"
560
561        # Don't accept unknown kwargs
562        expected_kwargs = [
563            "retry_strategy",
564            "opc_request_id"
565        ]
566        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
567        if extra_kwargs:
568            raise ValueError(
569                "get_budget got unknown kwargs: {!r}".format(extra_kwargs))
570
571        path_params = {
572            "budgetId": budget_id
573        }
574
575        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}
576
577        for (k, v) in six.iteritems(path_params):
578            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
579                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))
580
581        header_params = {
582            "accept": "application/json",
583            "content-type": "application/json",
584            "opc-request-id": kwargs.get("opc_request_id", missing)
585        }
586        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}
587
588        retry_strategy = self.base_client.get_preferred_retry_strategy(
589            operation_retry_strategy=kwargs.get('retry_strategy'),
590            client_retry_strategy=self.retry_strategy
591        )
592
593        if retry_strategy:
594            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
595                self.base_client.add_opc_client_retries_header(header_params)
596                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
597            return retry_strategy.make_retrying_call(
598                self.base_client.call_api,
599                resource_path=resource_path,
600                method=method,
601                path_params=path_params,
602                header_params=header_params,
603                response_type="Budget")
604        else:
605            return self.base_client.call_api(
606                resource_path=resource_path,
607                method=method,
608                path_params=path_params,
609                header_params=header_params,
610                response_type="Budget")
611
612    def list_alert_rules(self, budget_id, **kwargs):
613        """
614        Returns a list of Alert Rules for a specified Budget.
615
616
617        :param str budget_id: (required)
618            The unique Budget OCID
619
620        :param int limit: (optional)
621            The maximum number of items to return.
622
623        :param str page: (optional)
624            The page token representing the page at which to start retrieving results. This is usually retrieved from a previous list call.
625
626        :param str sort_order: (optional)
627            The sort order to use, either 'asc' or 'desc'.
628
629            Allowed values are: "ASC", "DESC"
630
631        :param str sort_by: (optional)
632            The field to sort by. If not specified, the default is timeCreated.
633            The default sort order for timeCreated is DESC.
634            The default sort order for displayName is ASC in alphanumeric order.
635
636            Allowed values are: "timeCreated", "displayName"
637
638        :param str lifecycle_state: (optional)
639            The current state of the resource to filter by.
640
641            Allowed values are: "ACTIVE", "INACTIVE"
642
643        :param str display_name: (optional)
644            A user-friendly name. Does not have to be unique, and it's changeable.
645
646            Example: `My new resource`
647
648        :param str opc_request_id: (optional)
649            The client request ID for tracing.
650
651        :param obj retry_strategy: (optional)
652            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.
653
654            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
655            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
656
657            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.
658
659        :return: A :class:`~oci.response.Response` object with data of type list of :class:`~oci.budget.models.AlertRuleSummary`
660        :rtype: :class:`~oci.response.Response`
661
662        :example:
663        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/budget/list_alert_rules.py.html>`__ to see an example of how to use list_alert_rules API.
664        """
665        resource_path = "/budgets/{budgetId}/alertRules"
666        method = "GET"
667
668        # Don't accept unknown kwargs
669        expected_kwargs = [
670            "retry_strategy",
671            "limit",
672            "page",
673            "sort_order",
674            "sort_by",
675            "lifecycle_state",
676            "display_name",
677            "opc_request_id"
678        ]
679        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
680        if extra_kwargs:
681            raise ValueError(
682                "list_alert_rules got unknown kwargs: {!r}".format(extra_kwargs))
683
684        path_params = {
685            "budgetId": budget_id
686        }
687
688        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}
689
690        for (k, v) in six.iteritems(path_params):
691            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
692                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))
693
694        if 'sort_order' in kwargs:
695            sort_order_allowed_values = ["ASC", "DESC"]
696            if kwargs['sort_order'] not in sort_order_allowed_values:
697                raise ValueError(
698                    "Invalid value for `sort_order`, must be one of {0}".format(sort_order_allowed_values)
699                )
700
701        if 'sort_by' in kwargs:
702            sort_by_allowed_values = ["timeCreated", "displayName"]
703            if kwargs['sort_by'] not in sort_by_allowed_values:
704                raise ValueError(
705                    "Invalid value for `sort_by`, must be one of {0}".format(sort_by_allowed_values)
706                )
707
708        if 'lifecycle_state' in kwargs:
709            lifecycle_state_allowed_values = ["ACTIVE", "INACTIVE"]
710            if kwargs['lifecycle_state'] not in lifecycle_state_allowed_values:
711                raise ValueError(
712                    "Invalid value for `lifecycle_state`, must be one of {0}".format(lifecycle_state_allowed_values)
713                )
714
715        query_params = {
716            "limit": kwargs.get("limit", missing),
717            "page": kwargs.get("page", missing),
718            "sortOrder": kwargs.get("sort_order", missing),
719            "sortBy": kwargs.get("sort_by", missing),
720            "lifecycleState": kwargs.get("lifecycle_state", missing),
721            "displayName": kwargs.get("display_name", missing)
722        }
723        query_params = {k: v for (k, v) in six.iteritems(query_params) if v is not missing and v is not None}
724
725        header_params = {
726            "accept": "application/json",
727            "content-type": "application/json",
728            "opc-request-id": kwargs.get("opc_request_id", missing)
729        }
730        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}
731
732        retry_strategy = self.base_client.get_preferred_retry_strategy(
733            operation_retry_strategy=kwargs.get('retry_strategy'),
734            client_retry_strategy=self.retry_strategy
735        )
736
737        if retry_strategy:
738            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
739                self.base_client.add_opc_client_retries_header(header_params)
740                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
741            return retry_strategy.make_retrying_call(
742                self.base_client.call_api,
743                resource_path=resource_path,
744                method=method,
745                path_params=path_params,
746                query_params=query_params,
747                header_params=header_params,
748                response_type="list[AlertRuleSummary]")
749        else:
750            return self.base_client.call_api(
751                resource_path=resource_path,
752                method=method,
753                path_params=path_params,
754                query_params=query_params,
755                header_params=header_params,
756                response_type="list[AlertRuleSummary]")
757
758    def list_budgets(self, compartment_id, **kwargs):
759        """
760        Gets a list of Budgets in a compartment.
761
762        By default, ListBudgets returns budgets of 'COMPARTMENT' target type and the budget records with only ONE target compartment OCID.
763
764        To list ALL budgets, set the targetType query parameter to ALL.
765        Example:
766          'targetType=ALL'
767
768        Additional targetTypes would be available in future releases. Clients should ignore new targetType
769        or upgrade to latest version of client SDK to handle new targetType.
770
771
772        :param str compartment_id: (required)
773            The ID of the compartment in which to list resources.
774
775        :param int limit: (optional)
776            The maximum number of items to return.
777
778        :param str page: (optional)
779            The page token representing the page at which to start retrieving results. This is usually retrieved from a previous list call.
780
781        :param str sort_order: (optional)
782            The sort order to use, either 'asc' or 'desc'.
783
784            Allowed values are: "ASC", "DESC"
785
786        :param str sort_by: (optional)
787            The field to sort by. If not specified, the default is timeCreated.
788            The default sort order for timeCreated is DESC.
789            The default sort order for displayName is ASC in alphanumeric order.
790
791            Allowed values are: "timeCreated", "displayName"
792
793        :param str lifecycle_state: (optional)
794            The current state of the resource to filter by.
795
796            Allowed values are: "ACTIVE", "INACTIVE"
797
798        :param str display_name: (optional)
799            A user-friendly name. Does not have to be unique, and it's changeable.
800
801            Example: `My new resource`
802
803        :param str target_type: (optional)
804            The type of target to filter by.
805              * ALL - List all budgets
806              * COMPARTMENT - List all budgets with targetType == \"COMPARTMENT\"
807              * TAG - List all budgets with targetType == \"TAG\"
808
809            Allowed values are: "ALL", "COMPARTMENT", "TAG"
810
811        :param str opc_request_id: (optional)
812            The client request ID for tracing.
813
814        :param obj retry_strategy: (optional)
815            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.
816
817            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
818            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
819
820            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.
821
822        :return: A :class:`~oci.response.Response` object with data of type list of :class:`~oci.budget.models.BudgetSummary`
823        :rtype: :class:`~oci.response.Response`
824
825        :example:
826        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/budget/list_budgets.py.html>`__ to see an example of how to use list_budgets API.
827        """
828        resource_path = "/budgets"
829        method = "GET"
830
831        # Don't accept unknown kwargs
832        expected_kwargs = [
833            "retry_strategy",
834            "limit",
835            "page",
836            "sort_order",
837            "sort_by",
838            "lifecycle_state",
839            "display_name",
840            "target_type",
841            "opc_request_id"
842        ]
843        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
844        if extra_kwargs:
845            raise ValueError(
846                "list_budgets got unknown kwargs: {!r}".format(extra_kwargs))
847
848        if 'sort_order' in kwargs:
849            sort_order_allowed_values = ["ASC", "DESC"]
850            if kwargs['sort_order'] not in sort_order_allowed_values:
851                raise ValueError(
852                    "Invalid value for `sort_order`, must be one of {0}".format(sort_order_allowed_values)
853                )
854
855        if 'sort_by' in kwargs:
856            sort_by_allowed_values = ["timeCreated", "displayName"]
857            if kwargs['sort_by'] not in sort_by_allowed_values:
858                raise ValueError(
859                    "Invalid value for `sort_by`, must be one of {0}".format(sort_by_allowed_values)
860                )
861
862        if 'lifecycle_state' in kwargs:
863            lifecycle_state_allowed_values = ["ACTIVE", "INACTIVE"]
864            if kwargs['lifecycle_state'] not in lifecycle_state_allowed_values:
865                raise ValueError(
866                    "Invalid value for `lifecycle_state`, must be one of {0}".format(lifecycle_state_allowed_values)
867                )
868
869        if 'target_type' in kwargs:
870            target_type_allowed_values = ["ALL", "COMPARTMENT", "TAG"]
871            if kwargs['target_type'] not in target_type_allowed_values:
872                raise ValueError(
873                    "Invalid value for `target_type`, must be one of {0}".format(target_type_allowed_values)
874                )
875
876        query_params = {
877            "compartmentId": compartment_id,
878            "limit": kwargs.get("limit", missing),
879            "page": kwargs.get("page", missing),
880            "sortOrder": kwargs.get("sort_order", missing),
881            "sortBy": kwargs.get("sort_by", missing),
882            "lifecycleState": kwargs.get("lifecycle_state", missing),
883            "displayName": kwargs.get("display_name", missing),
884            "targetType": kwargs.get("target_type", missing)
885        }
886        query_params = {k: v for (k, v) in six.iteritems(query_params) if v is not missing and v is not None}
887
888        header_params = {
889            "accept": "application/json",
890            "content-type": "application/json",
891            "opc-request-id": kwargs.get("opc_request_id", missing)
892        }
893        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}
894
895        retry_strategy = self.base_client.get_preferred_retry_strategy(
896            operation_retry_strategy=kwargs.get('retry_strategy'),
897            client_retry_strategy=self.retry_strategy
898        )
899
900        if retry_strategy:
901            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
902                self.base_client.add_opc_client_retries_header(header_params)
903                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
904            return retry_strategy.make_retrying_call(
905                self.base_client.call_api,
906                resource_path=resource_path,
907                method=method,
908                query_params=query_params,
909                header_params=header_params,
910                response_type="list[BudgetSummary]")
911        else:
912            return self.base_client.call_api(
913                resource_path=resource_path,
914                method=method,
915                query_params=query_params,
916                header_params=header_params,
917                response_type="list[BudgetSummary]")
918
919    def update_alert_rule(self, budget_id, alert_rule_id, update_alert_rule_details, **kwargs):
920        """
921        Update an Alert Rule for the budget identified by the OCID.
922
923
924        :param str budget_id: (required)
925            The unique Budget OCID
926
927        :param str alert_rule_id: (required)
928            The unique Alert Rule OCID
929
930        :param oci.budget.models.UpdateAlertRuleDetails update_alert_rule_details: (required)
931            The information to be updated.
932
933        :param str if_match: (optional)
934            For optimistic concurrency control. In the PUT or DELETE call
935            for a resource, set the `if-match` parameter to the value of the
936            etag from a previous GET or POST response for that resource.
937            The resource will be updated or deleted only if the etag you
938            provide matches the resource's current etag value.
939
940        :param str opc_request_id: (optional)
941            The client request ID for tracing.
942
943        :param obj retry_strategy: (optional)
944            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.
945
946            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
947            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
948
949            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.
950
951        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.budget.models.AlertRule`
952        :rtype: :class:`~oci.response.Response`
953
954        :example:
955        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/budget/update_alert_rule.py.html>`__ to see an example of how to use update_alert_rule API.
956        """
957        resource_path = "/budgets/{budgetId}/alertRules/{alertRuleId}"
958        method = "PUT"
959
960        # Don't accept unknown kwargs
961        expected_kwargs = [
962            "retry_strategy",
963            "if_match",
964            "opc_request_id"
965        ]
966        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
967        if extra_kwargs:
968            raise ValueError(
969                "update_alert_rule got unknown kwargs: {!r}".format(extra_kwargs))
970
971        path_params = {
972            "budgetId": budget_id,
973            "alertRuleId": alert_rule_id
974        }
975
976        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}
977
978        for (k, v) in six.iteritems(path_params):
979            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
980                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))
981
982        header_params = {
983            "accept": "application/json",
984            "content-type": "application/json",
985            "if-match": kwargs.get("if_match", missing),
986            "opc-request-id": kwargs.get("opc_request_id", missing)
987        }
988        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}
989
990        retry_strategy = self.base_client.get_preferred_retry_strategy(
991            operation_retry_strategy=kwargs.get('retry_strategy'),
992            client_retry_strategy=self.retry_strategy
993        )
994
995        if retry_strategy:
996            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
997                self.base_client.add_opc_client_retries_header(header_params)
998                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
999            return retry_strategy.make_retrying_call(
1000                self.base_client.call_api,
1001                resource_path=resource_path,
1002                method=method,
1003                path_params=path_params,
1004                header_params=header_params,
1005                body=update_alert_rule_details,
1006                response_type="AlertRule")
1007        else:
1008            return self.base_client.call_api(
1009                resource_path=resource_path,
1010                method=method,
1011                path_params=path_params,
1012                header_params=header_params,
1013                body=update_alert_rule_details,
1014                response_type="AlertRule")
1015
1016    def update_budget(self, budget_id, update_budget_details, **kwargs):
1017        """
1018        Update a Budget identified by the OCID
1019
1020
1021        :param str budget_id: (required)
1022            The unique Budget OCID
1023
1024        :param oci.budget.models.UpdateBudgetDetails update_budget_details: (required)
1025            The information to be updated.
1026
1027        :param str if_match: (optional)
1028            For optimistic concurrency control. In the PUT or DELETE call
1029            for a resource, set the `if-match` parameter to the value of the
1030            etag from a previous GET or POST response for that resource.
1031            The resource will be updated or deleted only if the etag you
1032            provide matches the resource's current etag value.
1033
1034        :param str opc_request_id: (optional)
1035            The client request ID for tracing.
1036
1037        :param obj retry_strategy: (optional)
1038            A retry strategy to apply to this specific operation/call. This will override any retry strategy set at the client-level.
1039
1040            This should be one of the strategies available in the :py:mod:`~oci.retry` module. This operation will not retry by default, users can also use the convenient :py:data:`~oci.retry.DEFAULT_RETRY_STRATEGY` provided by the SDK to enable retries for it.
1041            The specifics of the default retry strategy are described `here <https://docs.oracle.com/en-us/iaas/tools/python/latest/sdk_behaviors/retries.html>`__.
1042
1043            To have this operation explicitly not perform any retries, pass an instance of :py:class:`~oci.retry.NoneRetryStrategy`.
1044
1045        :return: A :class:`~oci.response.Response` object with data of type :class:`~oci.budget.models.Budget`
1046        :rtype: :class:`~oci.response.Response`
1047
1048        :example:
1049        Click `here <https://docs.cloud.oracle.com/en-us/iaas/tools/python-sdk-examples/2.53.1/budget/update_budget.py.html>`__ to see an example of how to use update_budget API.
1050        """
1051        resource_path = "/budgets/{budgetId}"
1052        method = "PUT"
1053
1054        # Don't accept unknown kwargs
1055        expected_kwargs = [
1056            "retry_strategy",
1057            "if_match",
1058            "opc_request_id"
1059        ]
1060        extra_kwargs = [_key for _key in six.iterkeys(kwargs) if _key not in expected_kwargs]
1061        if extra_kwargs:
1062            raise ValueError(
1063                "update_budget got unknown kwargs: {!r}".format(extra_kwargs))
1064
1065        path_params = {
1066            "budgetId": budget_id
1067        }
1068
1069        path_params = {k: v for (k, v) in six.iteritems(path_params) if v is not missing}
1070
1071        for (k, v) in six.iteritems(path_params):
1072            if v is None or (isinstance(v, six.string_types) and len(v.strip()) == 0):
1073                raise ValueError('Parameter {} cannot be None, whitespace or empty string'.format(k))
1074
1075        header_params = {
1076            "accept": "application/json",
1077            "content-type": "application/json",
1078            "if-match": kwargs.get("if_match", missing),
1079            "opc-request-id": kwargs.get("opc_request_id", missing)
1080        }
1081        header_params = {k: v for (k, v) in six.iteritems(header_params) if v is not missing and v is not None}
1082
1083        retry_strategy = self.base_client.get_preferred_retry_strategy(
1084            operation_retry_strategy=kwargs.get('retry_strategy'),
1085            client_retry_strategy=self.retry_strategy
1086        )
1087
1088        if retry_strategy:
1089            if not isinstance(retry_strategy, retry.NoneRetryStrategy):
1090                self.base_client.add_opc_client_retries_header(header_params)
1091                retry_strategy.add_circuit_breaker_callback(self.circuit_breaker_callback)
1092            return retry_strategy.make_retrying_call(
1093                self.base_client.call_api,
1094                resource_path=resource_path,
1095                method=method,
1096                path_params=path_params,
1097                header_params=header_params,
1098                body=update_budget_details,
1099                response_type="Budget")
1100        else:
1101            return self.base_client.call_api(
1102                resource_path=resource_path,
1103                method=method,
1104                path_params=path_params,
1105                header_params=header_params,
1106                body=update_budget_details,
1107                response_type="Budget")
1108