diff --git a/DO_OPENAPI_COMMIT_SHA.txt b/DO_OPENAPI_COMMIT_SHA.txt index 1707de88..7c9a8d22 100644 --- a/DO_OPENAPI_COMMIT_SHA.txt +++ b/DO_OPENAPI_COMMIT_SHA.txt @@ -1 +1 @@ -257e7e4 +0267e38 diff --git a/src/pydo/_client.py b/src/pydo/_client.py index 378251b8..c59a0d6d 100644 --- a/src/pydo/_client.py +++ b/src/pydo/_client.py @@ -40,6 +40,7 @@ ImageActionsOperations, ImagesOperations, InferenceOperations, + InsightsOperations, InvoicesOperations, KubernetesOperations, LoadBalancersOperations, @@ -157,6 +158,8 @@ class GeneratedClient: # pylint: disable=client-accepts-api-version-keyword,too :vartype images: pydo.operations.ImagesOperations :ivar image_actions: ImageActionsOperations operations :vartype image_actions: pydo.operations.ImageActionsOperations + :ivar insights: InsightsOperations operations + :vartype insights: pydo.operations.InsightsOperations :ivar kubernetes: KubernetesOperations operations :vartype kubernetes: pydo.operations.KubernetesOperations :ivar load_balancers: LoadBalancersOperations operations @@ -366,6 +369,9 @@ def __init__( self.image_actions = ImageActionsOperations( self._client, self._config, self._serialize, self._deserialize ) + self.insights = InsightsOperations( + self._client, self._config, self._serialize, self._deserialize + ) self.kubernetes = KubernetesOperations( self._client, self._config, self._serialize, self._deserialize ) diff --git a/src/pydo/aio/_client.py b/src/pydo/aio/_client.py index 61a44790..cb653108 100644 --- a/src/pydo/aio/_client.py +++ b/src/pydo/aio/_client.py @@ -40,6 +40,7 @@ ImageActionsOperations, ImagesOperations, InferenceOperations, + InsightsOperations, InvoicesOperations, KubernetesOperations, LoadBalancersOperations, @@ -157,6 +158,8 @@ class GeneratedClient: # pylint: disable=client-accepts-api-version-keyword,too :vartype images: pydo.aio.operations.ImagesOperations :ivar image_actions: ImageActionsOperations operations :vartype image_actions: pydo.aio.operations.ImageActionsOperations + :ivar insights: InsightsOperations operations + :vartype insights: pydo.aio.operations.InsightsOperations :ivar kubernetes: KubernetesOperations operations :vartype kubernetes: pydo.aio.operations.KubernetesOperations :ivar load_balancers: LoadBalancersOperations operations @@ -366,6 +369,9 @@ def __init__( self.image_actions = ImageActionsOperations( self._client, self._config, self._serialize, self._deserialize ) + self.insights = InsightsOperations( + self._client, self._config, self._serialize, self._deserialize + ) self.kubernetes = KubernetesOperations( self._client, self._config, self._serialize, self._deserialize ) diff --git a/src/pydo/aio/operations/__init__.py b/src/pydo/aio/operations/__init__.py index 58cfa4c4..163af5e7 100644 --- a/src/pydo/aio/operations/__init__.py +++ b/src/pydo/aio/operations/__init__.py @@ -37,6 +37,7 @@ from ._operations import FunctionsAccessKeyOperations from ._operations import ImagesOperations from ._operations import ImageActionsOperations +from ._operations import InsightsOperations from ._operations import KubernetesOperations from ._operations import LoadBalancersOperations from ._operations import MonitoringOperations @@ -110,6 +111,7 @@ "FunctionsAccessKeyOperations", "ImagesOperations", "ImageActionsOperations", + "InsightsOperations", "KubernetesOperations", "LoadBalancersOperations", "MonitoringOperations", diff --git a/src/pydo/aio/operations/_operations.py b/src/pydo/aio/operations/_operations.py index db4b964c..e7b97537 100644 --- a/src/pydo/aio/operations/_operations.py +++ b/src/pydo/aio/operations/_operations.py @@ -430,6 +430,24 @@ build_inference_list_batches_request, build_inference_list_models_request, build_inference_upload_batch_file_request, + build_insights_create_alert_rule_request, + build_insights_create_notification_channel_request, + build_insights_delete_alert_rule_request, + build_insights_delete_notification_channel_request, + build_insights_get_alert_instance_request, + build_insights_get_alert_rule_request, + build_insights_get_notification_channel_request, + build_insights_get_prom_label_values_request, + build_insights_get_prom_labels_request, + build_insights_get_prom_query_range_request, + build_insights_get_prom_query_request, + build_insights_get_prom_series_request, + build_insights_list_alert_instances_request, + build_insights_list_alert_rules_request, + build_insights_list_notification_channels_request, + build_insights_post_logs_search_request, + build_insights_update_alert_rule_request, + build_insights_update_notification_channel_request, build_invoices_get_by_uuid_request, build_invoices_get_csv_by_uuid_request, build_invoices_get_pdf_by_uuid_request, @@ -129898,9 +129916,10 @@ async def update_user( For Kafka and OpenSearch clusters, additional options can be configured in the ``settings`` object (for example, topic or index ACLs). - Updating users is not supported for MongoDB clusters. MongoDB roles and database - access are set with ``settings.mongo_user_settings`` when creating a user and cannot - be changed afterward; recreate the user to apply different roles or databases. + Updating users is supported for PostgreSQL, Kafka, and OpenSearch clusters. For + other engines, the request returns a 422. MongoDB roles and database access are + set with ``settings.mongo_user_settings`` when creating a user and cannot be + changed afterward; recreate the user to apply different roles or databases. The response will be a JSON object with a key called ``user``. The value of this will be an object that contains the name of the updated database user, along with the ``settings`` object @@ -130041,7 +130060,7 @@ async def update_user( } } } - # response body for status code(s): 404 + # response body for status code(s): 404, 422 response == { "id": "str", # A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would @@ -130081,9 +130100,10 @@ async def update_user( For Kafka and OpenSearch clusters, additional options can be configured in the ``settings`` object (for example, topic or index ACLs). - Updating users is not supported for MongoDB clusters. MongoDB roles and database - access are set with ``settings.mongo_user_settings`` when creating a user and cannot - be changed afterward; recreate the user to apply different roles or databases. + Updating users is supported for PostgreSQL, Kafka, and OpenSearch clusters. For + other engines, the request returns a 422. MongoDB roles and database access are + set with ``settings.mongo_user_settings`` when creating a user and cannot be + changed afterward; recreate the user to apply different roles or databases. The response will be a JSON object with a key called ``user``. The value of this will be an object that contains the name of the updated database user, along with the ``settings`` object @@ -130185,7 +130205,7 @@ async def update_user( } } } - # response body for status code(s): 404 + # response body for status code(s): 404, 422 response == { "id": "str", # A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would @@ -130223,9 +130243,10 @@ async def update_user( For Kafka and OpenSearch clusters, additional options can be configured in the ``settings`` object (for example, topic or index ACLs). - Updating users is not supported for MongoDB clusters. MongoDB roles and database - access are set with ``settings.mongo_user_settings`` when creating a user and cannot - be changed afterward; recreate the user to apply different roles or databases. + Updating users is supported for PostgreSQL, Kafka, and OpenSearch clusters. For + other engines, the request returns a 422. MongoDB roles and database access are + set with ``settings.mongo_user_settings`` when creating a user and cannot be + changed afterward; recreate the user to apply different roles or databases. The response will be a JSON object with a key called ``user``. The value of this will be an object that contains the name of the updated database user, along with the ``settings`` object @@ -130363,7 +130384,7 @@ async def update_user( } } } - # response body for status code(s): 404 + # response body for status code(s): 404, 422 response == { "id": "str", # A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would @@ -130424,7 +130445,7 @@ async def update_user( response = pipeline_response.http_response - if response.status_code not in [201, 404]: + if response.status_code not in [201, 404, 422]: if _stream: await response.read() # Load the body in memory and close the socket map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore @@ -130463,6 +130484,22 @@ async def update_user( else: deserialized = None + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + if cls: return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore @@ -160858,14 +160895,14 @@ async def get(self, image_id: int, action_id: int, **kwargs: Any) -> JSON: return cast(JSON, deserialized) # type: ignore -class KubernetesOperations: # pylint: disable=too-many-public-methods +class InsightsOperations: """ .. warning:: **DO NOT** instantiate this class directly. Instead, you should access the following operations through :class:`~pydo.aio.GeneratedClient`'s - :attr:`kubernetes` attribute. + :attr:`insights` attribute. """ def __init__(self, *args, **kwargs) -> None: @@ -160878,19 +160915,46 @@ def __init__(self, *args, **kwargs) -> None: ) @distributed_trace_async - async def list_clusters( - self, *, per_page: int = 20, page: int = 1, **kwargs: Any + async def list_alert_instances( + self, + *, + per_page: int = 20, + page: int = 1, + status: Optional[str] = None, + rule_id: Optional[str] = None, + resource_urn: Optional[str] = None, + **kwargs: Any ) -> JSON: # pylint: disable=line-too-long - """List All Kubernetes Clusters. + """List Alert Instances. - To list all of the Kubernetes clusters on your account, send a GET request - to ``/v2/kubernetes/clusters``. + To list alert instances for your account, send a GET request to + ``/v2/insights/alert-instances``. Alert instances are read-only records of + alert rule firings against your resources. + + Results can optionally be filtered by ``status``\\ , ``rule_id``\\ , or + ``resource_urn``. + + Results are ordered by ``triggered_at`` descending (newest first). Because + the list is append-only and continuously growing, offset-based pagination + is best-effort: newly triggered instances may shift older rows onto + subsequent pages between fetches. For stable pagination, filter by + ``rule_id`` or a fixed time window on the client side. :keyword per_page: Number of items returned per page. Default value is 20. :paramtype per_page: int :keyword page: Which 'page' of paginated results to return. Default value is 1. :paramtype page: int + :keyword status: Optional filter. When set, only alert instances with this status are + returned. Known values are: "active" and "resolved". Default value is None. + :paramtype status: str + :keyword rule_id: Optional filter. When set, only alert instances fired by the alert rule + with this ID are returned. Default value is None. + :paramtype rule_id: str + :keyword resource_urn: Optional filter. When set, only resources associated with this resource + URN + are returned. Default value is None. + :paramtype resource_urn: str :return: JSON object :rtype: JSON :raises ~azure.core.exceptions.HttpResponseError: @@ -160903,263 +160967,5633 @@ async def list_clusters( "meta": { "total": 0 # Optional. Number of objects returned by the request. }, - "kubernetes_clusters": [ + "alert_instances": [ { - "name": "str", # A human-readable name for a Kubernetes - cluster. Required. - "node_pools": [ - { - "auto_scale": bool, # Optional. A boolean - value indicating whether auto-scaling is enabled for this node - pool. - "count": 0, # Optional. The number of - Droplet instances in the node pool. - "gpu_partition_mode": "str", # Optional. The - AMD GPU partition mode for this node pool. Only applicable to AMD - GPU sizes that support partitioning. Immutable after the node - pool is created. When omitted, the GPUs in the pool are left - unpartitioned. Known values are: "AMD_PARTITION_MODE_SPX_NPS1" - and "AMD_PARTITION_MODE_DPX_NPS2". - "id": "str", # Optional. A unique ID that - can be used to identify and reference a specific node pool. - "labels": {}, # Optional. An object of - key/value mappings specifying labels to apply to all nodes in a - pool. Labels will automatically be applied to all existing nodes - and any subsequent nodes added to the pool. Note that when a - label is removed, it is not deleted from the nodes in the pool. - "max_nodes": 0, # Optional. The maximum - number of nodes that this node pool can be auto-scaled to. The - value will be ``0`` if ``auto_scale`` is set to ``false``. - "min_nodes": 0, # Optional. The minimum - number of nodes that this node pool can be auto-scaled to. The - value will be ``0`` if ``auto_scale`` is set to ``false``. - "name": "str", # Optional. A human-readable - name for the node pool. - "nodes": [ - { - "created_at": "2020-02-20 - 00:00:00", # Optional. A time value given in ISO8601 - combined date and time format that represents when the - node was created. - "droplet_id": "str", # - Optional. The ID of the Droplet used for the worker node. - "id": "str", # Optional. A - unique ID that can be used to identify and reference the - node. - "name": "str", # Optional. - An automatically generated, human-readable name for the - node. - "status": { - "state": "str" # - Optional. A string indicating the current status of - the node. Known values are: "provisioning", - "running", "draining", and "deleting". - }, - "updated_at": "2020-02-20 - 00:00:00" # Optional. A time value given in ISO8601 - combined date and time format that represents when the - node was last updated. - } - ], - "size": "str", # Optional. The slug - identifier for the type of Droplet used as workers in the node - pool. - "tags": [ - "str" # Optional. An array - containing the tags applied to the node pool. All node pools - are automatically tagged ``k8s``"" , ``k8s-worker``"" , and - ``k8s:$K8S_CLUSTER_ID``. :code:`
`:code:`
`Requires - ``tag:read`` scope. - ], - "taints": [ - { - "effect": "str", # Optional. - How the node reacts to pods that it won't tolerate. - Available effect values are ``NoSchedule``"" , - ``PreferNoSchedule``"" , and ``NoExecute``. Known values - are: "NoSchedule", "PreferNoSchedule", and "NoExecute". - "key": "str", # Optional. An - arbitrary string. The ``key`` and ``value`` fields of the - ``taint`` object form a key-value pair. For example, if - the value of the ``key`` field is "special" and the value - of the ``value`` field is "gpu", the key value pair would - be ``special=gpu``. - "value": "str" # Optional. - An arbitrary string. The ``key`` and ``value`` fields of - the ``taint`` object form a key-value pair. For example, - if the value of the ``key`` field is "special" and the - value of the ``value`` field is "gpu", the key value pair - would be ``special=gpu``. - } - ] - } - ], - "region": "str", # The slug identifier for the region where - the Kubernetes cluster is located. Required. - "version": "str", # The slug identifier for the version of - Kubernetes used for the cluster. If set to a minor version (e.g. "1.14"), - the latest version within it will be used (e.g. "1.14.6-do.1"); if set to - "latest", the latest published version will be used. See the - ``/v2/kubernetes/options`` endpoint to find all currently available - versions. Required. - "amd_gpu_device_metrics_exporter_plugin": { - "enabled": bool # Optional. Indicates whether the - AMD Device Metrics Exporter is enabled. - }, - "amd_gpu_device_plugin": { - "enabled": bool # Optional. Indicates whether the - AMD GPU Device Plugin is enabled. - }, - "amd_gpu_dra_driver": { - "enabled": bool # Optional. Indicates whether the - AMD GPU DRA Driver is enabled. - }, - "auto_upgrade": False, # Optional. Default value is False. A - boolean value indicating whether the cluster will be automatically - upgraded to new patch releases during its maintenance window. - "cluster_autoscaler_configuration": { - "expanders": [ - "str" # Optional. Customizes expanders used - by cluster-autoscaler. The autoscaler will apply each expander - from the provided list to narrow down the selection of node types - created to scale up, until either a single node type is left, or - the list of expanders is exhausted. If this flag is unset, - autoscaler will use its default expander ``random``. Passing an - empty list ("" *not* ``null``"" ) will unset any previous - expander customizations. Available expanders: * ``random``"" : - Randomly selects a node group to scale. * `priority`: Selects the - node group with the highest priority as per [user-provided - configuration](https://docs.digitalocean.com/products/kubernetes/how-to/autoscale/#configuring-priority-expander) - * ``least_waste``"" : Selects the node group that will result in - the least amount of idle resources. - ], - "scale_down_unneeded_time": "str", # Optional. Used - to customize how long a node is unneeded before being scaled down. - "scale_down_utilization_threshold": 0.0 # Optional. - Used to customize when cluster autoscaler scales down non-empty nodes - by setting the node utilization threshold. - }, - "cluster_subnet": "str", # Optional. The range of IP - addresses for the overlay network of the Kubernetes cluster in CIDR - notation. - "control_plane_firewall": { - "allowed_addresses": [ - "str" # Optional. An array of public - addresses (IPv4 or CIDR) allowed to access the control plane. - ], - "enabled": bool # Optional. Indicates whether the - control plane firewall is enabled. - }, - "coredns_autoscaler": { - "enabled": bool # Optional. Indicates whether the - CoreDNS Cluster Proportional Autoscaler add-on is enabled. - }, - "created_at": "2020-02-20 00:00:00", # Optional. A time - value given in ISO8601 combined date and time format that represents when - the Kubernetes cluster was created. - "endpoint": "str", # Optional. The base URL of the API - server on the Kubernetes master node. - "ha": False, # Optional. Default value is False. A boolean - value indicating whether the control plane is run in a highly available - configuration in the cluster. Highly available control planes incur less - downtime. The property cannot be disabled. When omitted on create, the - default is version-dependent; for DOKS 1.36.0 and later, the default is - true; for earlier versions, the default is false. - "id": "str", # Optional. A unique ID that can be used to - identify and reference a Kubernetes cluster. - "ipv4": "str", # Optional. The public IPv4 address of the - Kubernetes master node. This will not be set if high availability is - configured on the cluster (v1.21+). - "isolated_workers": False, # Optional. Default value is - False. A boolean value indicating whether worker nodes in the cluster are - not assigned public IP addresses. When omitted on create, the default - value is false. When enabled, a NAT gateway must exist in the VPC where - the cluster is created. - "maintenance_policy": { - "day": "str", # Optional. The day of the maintenance - window policy. May be one of ``monday`` through ``sunday``"" , or - ``any`` to indicate an arbitrary week day. Known values are: "any", - "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", - and "sunday". - "duration": "str", # Optional. The duration of the - maintenance window policy in human-readable format. - "start_time": "str" # Optional. The start time in - UTC of the maintenance window policy in 24-hour clock format / HH:MM - notation (e.g., ``15:00``"" ). - }, - "nfs_csi_plugin": { - "enabled": bool # Optional. Indicates whether the - NFS CSI plugin is enabled. - }, - "nvidia_gpu_device_plugin": { - "enabled": bool # Optional. Indicates whether the - Nvidia GPU Device Plugin is enabled. - }, - "nvidia_gpu_dra_driver": { - "enabled": bool # Optional. Indicates whether the - NVIDIA GPU DRA Driver is enabled. - }, - "p2p_oci_registry_plugin": { - "enabled": bool # Optional. Indicates whether the - Peer-to-peer OCI registry component is enabled. - }, - "rdma_shared_dev_plugin": { - "enabled": bool # Optional. Indicates whether the - RDMA shared device plugin is enabled. - }, - "registries": [ - "str" # Optional. An array of integrated DOCR - registries. - ], - "registry_enabled": bool, # Optional. A read-only boolean - value indicating if a container registry is integrated with the cluster. - "routing_agent": { - "enabled": bool # Optional. Indicates whether the - routing-agent component is enabled. - }, - "service_subnet": "str", # Optional. The range of assignable - IP addresses for services running in the Kubernetes cluster in CIDR - notation. - "sso": { - "client_id": "str", # Optional. The OIDC client ID - registered with the identity provider. Required when ``enabled`` is - ``true``. - "enabled": False, # Optional. Default value is - False. Indicates whether SSO authentication is enabled for the - cluster. - "issuer_url": "str", # Optional. The OIDC issuer URL - for the identity provider. Required when ``enabled`` is ``true``. - "required": False # Optional. Default value is - False. Indicates whether any non-SSO forms of authentication are - disallowed. Can only be set to ``true`` when ``enabled`` is ``true``. - }, - "status": { - "message": "str", # Optional. An optional message - providing additional information about the current cluster state. - "state": "str" # Optional. A string indicating the - current status of the cluster. Known values are: "running", - "provisioning", "degraded", "error", "deleted", "upgrading", and - "deleting". - }, - "surge_upgrade": False, # Optional. Default value is False. - A boolean value indicating whether surge upgrade is enabled/disabled for - the cluster. Surge upgrade makes cluster upgrades fast and reliable by - bringing up new nodes before destroying the outdated nodes. - "tags": [ - "str" # Optional. An array of tags applied to the - Kubernetes cluster. All clusters are automatically tagged ``k8s`` and - ``k8s:$K8S_CLUSTER_ID``. :code:`
`:code:`
`Requires - ``tag:read`` scope. - ], - "updated_at": "2020-02-20 00:00:00", # Optional. A time - value given in ISO8601 combined date and time format that represents when - the Kubernetes cluster was last updated. - "vpc_uuid": "str", # Optional. A string specifying the UUID - of the VPC to which the Kubernetes cluster is - assigned.:code:`
`:code:`
`Requires ``vpc:read`` scope. - "worker_subnet_uuid": "str" # Optional. The UUID of the VPC - subnet worker nodes are attached to. When unset, the default subnet for - the VPC is used.:code:`
`:code:`
`Requires ``vpc:read`` scope. + "id": "str", # A unique identifier for the alert instance. + Required. + "last_triggered_at": "2020-02-20 00:00:00", # Time the alert + instance most recently fired. Required. + "rule_id": "str", # ID of the alert rule that fired this + alert instance. Required. + "severity": "str", # Severity of the breached threshold. + Required. Known values are: "warning" and "critical". + "status": "str", # Current status of the alert instance. + Required. Known values are: "active" and "resolved". + "triggered_at": "2020-02-20 00:00:00", # Time the alert + instance first fired. Required. + "value": 0.0, # The observed metric value that breached the + threshold. Required. + "last_notified_at": "2020-02-20 00:00:00", # Optional. Time + a notification was last sent for this alert instance. + "resolved_at": "2020-02-20 00:00:00", # Optional. Time the + alert instance resolved. Only present when ``status`` is ``resolved``. + "resource_urn": "str" # Optional. URN of the DigitalOcean + resource the alert fired for. May be an empty string for alerts fired on + non-resource-bound signals (for example, cluster/pod/namespace-scoped + Kubernetes alerts). + } + ], + "links": { + "pages": {} + } + } + # response body for status code(s): 400 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_list_alert_instances_request( + per_page=per_page, + page=page, + status=status, + rule_id=rule_id, + resource_urn=resource_urn, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace_async + async def get_alert_instance(self, id: str, **kwargs: Any) -> JSON: + # pylint: disable=line-too-long + """Retrieve an Alert Instance. + + To retrieve a single alert instance, send a GET request to + ``/v2/insights/alert-instances/{id}``. + + :param id: A unique identifier for an alert instance. Required. + :type id: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "alert_instance": { + "id": "str", # A unique identifier for the alert instance. Required. + "last_triggered_at": "2020-02-20 00:00:00", # Time the alert + instance most recently fired. Required. + "rule_id": "str", # ID of the alert rule that fired this alert + instance. Required. + "severity": "str", # Severity of the breached threshold. Required. + Known values are: "warning" and "critical". + "status": "str", # Current status of the alert instance. Required. + Known values are: "active" and "resolved". + "triggered_at": "2020-02-20 00:00:00", # Time the alert instance + first fired. Required. + "value": 0.0, # The observed metric value that breached the + threshold. Required. + "last_notified_at": "2020-02-20 00:00:00", # Optional. Time a + notification was last sent for this alert instance. + "resolved_at": "2020-02-20 00:00:00", # Optional. Time the alert + instance resolved. Only present when ``status`` is ``resolved``. + "resource_urn": "str" # Optional. URN of the DigitalOcean resource + the alert fired for. May be an empty string for alerts fired on + non-resource-bound signals (for example, cluster/pod/namespace-scoped + Kubernetes alerts). + } + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_alert_instance_request( + id=id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 404]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace_async + async def list_alert_rules( + self, + *, + page: int = 1, + per_page: int = 20, + resource_urn: Optional[str] = None, + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """List Alert Rules. + + To list alert rules for your account, send a GET request to + ``/v2/insights/alert-rules``. Results are paginated with ``page`` and ``per_page`` + (default ``20``\\ , maximum ``200``\\ ). Optionally filter by ``resource_urn``. + + :keyword page: Which 'page' of paginated results to return. Default value is 1. + :paramtype page: int + :keyword per_page: Number of items returned per page. Default value is 20. + :paramtype per_page: int + :keyword resource_urn: Optional filter. When set, only resources associated with this resource + URN + are returned. Default value is None. + :paramtype resource_urn: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "alert_rules": [ + { + "created_at": "2020-02-20 00:00:00", # Time the alert rule + was created. Required. + "id": "str", # A unique identifier for the alert rule. + Required. + "spec": { + "name": "str", # A human-readable name for the alert + rule. Required. + "query": { + "metric": "str", # Dotted OpenTelemetry + metric name to evaluate (for example + ``do.droplets.cpu_utilization``"" ). Required. + "filters": [ + { + "field": "str", # The metric + label or field to filter on. Required. + "operator": "str", # + Comparison operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` + = ``greater_than`` * + ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value + compared against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or + omitted means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource + tags used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator + applied to the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``THRESHOLD_OPERATOR_LESS_THAN`` = + ``less_than`` * ``THRESHOLD_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical + threshold value. + "warning": 0.0 # Optional. Warning threshold + value. + }, + "condition": { + "window": "str" # Optional. Time window over + which the metric is evaluated. Allowed values: * + ``EVALUATION_WINDOW_1M`` = ``1m`` * ``EVALUATION_WINDOW_5M`` = + ``5m`` * ``EVALUATION_WINDOW_10M`` = ``10m`` * + ``EVALUATION_WINDOW_15M`` = ``15m`` * ``EVALUATION_WINDOW_30M`` = + ``30m`` * ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # + ID of an existing notification channel owned by the account. + Required. + "notify_on": [ + "str" # Optional. Severities + that trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait + before re-notifying a still-firing alert. Defaults to + ``RE_ALERT_DURATION_4H`` on create when omitted. Allowed values: * + ``RE_ALERT_DURATION_30M`` = ``30m`` * ``RE_ALERT_DURATION_1H`` = + ``1h`` * ``RE_ALERT_DURATION_4H`` = ``4h`` * + ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", + "RE_ALERT_DURATION_4H", and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed + values: * ``ALERT_RULE_STATUS_ACTIVE`` = active * + ``ALERT_RULE_STATUS_PAUSED`` = paused. Required. Known values are: + "ALERT_RULE_STATUS_ACTIVE" and "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule + was last updated. Required. + } + ], + "meta": { + "total": 0 # Optional. Number of objects returned by the request. + }, + "links": { + "pages": {} + } + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_list_alert_rules_request( + page=page, + per_page=per_page, + resource_urn=resource_urn, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @overload + async def create_alert_rule( + self, body: JSON, *, content_type: str = "application/json", **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create an Alert Rule. + + To create an alert rule, send a POST request to ``/v2/insights/alert-rules`` + with a ``spec`` containing ``name``\\ , ``query``\\ , ``thresholds``\\ , and at least one + ``notification_channels`` binding. ``status`` defaults to + ``ALERT_RULE_STATUS_ACTIVE`` when omitted. ``re_alert_duration`` defaults to + ``RE_ALERT_DURATION_4H`` when omitted. + + ``query.metric`` must be a dotted OpenTelemetry name such as + ``do.droplets.cpu_utilization``. Underscored Prometheus-style names are + rejected with ``422 Unprocessable Entity``. + + :param body: Required. + :type body: JSON + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "spec": { + "name": "str", # A human-readable name for the alert rule. Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name to + evaluate (for example ``do.droplets.cpu_utilization``"" ). Required. + "filters": [ + { + "field": "str", # The metric label or field + to filter on. Required. + "operator": "str", # Comparison operator for + the filter. Allowed values: * ``FILTER_OPERATOR_EQUAL`` = equal + * ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``FILTER_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared against the + field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of DigitalOcean + resource URNs the rule applies to. Empty or omitted means the rule is + not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags used to + select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to the + aggregated metric value. Allowed values: * ``THRESHOLD_OPERATOR_EQUAL`` + = equal * ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` + * ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = ``greater_than_or_equal`` + * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = ``not_equal``. Required. Known + values are: "THRESHOLD_OPERATOR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which the + metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` = + ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * ``EVALUATION_WINDOW_10M`` = + ``10m`` * ``EVALUATION_WINDOW_15M`` = ``15m`` * ``EVALUATION_WINDOW_30M`` + = ``30m`` * ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", "EVALUATION_WINDOW_10M", + "EVALUATION_WINDOW_15M", "EVALUATION_WINDOW_30M", and + "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that trigger + this channel. Allowed values: * ``SEVERITY_WARNING`` = warning + * ``SEVERITY_CRITICAL`` = critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` on + create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = ``30m`` + * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = ``4h`` * + ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", and + "RE_ALERT_DURATION_NEVER". + }, + "status": "str" # Optional. Desired alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = paused. + Known values are: "ALERT_RULE_STATUS_ACTIVE" and "ALERT_RULE_STATUS_PAUSED". + } + + # response body for status code(s): 201 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + async def create_alert_rule( + self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create an Alert Rule. + + To create an alert rule, send a POST request to ``/v2/insights/alert-rules`` + with a ``spec`` containing ``name``\\ , ``query``\\ , ``thresholds``\\ , and at least one + ``notification_channels`` binding. ``status`` defaults to + ``ALERT_RULE_STATUS_ACTIVE`` when omitted. ``re_alert_duration`` defaults to + ``RE_ALERT_DURATION_4H`` when omitted. + + ``query.metric`` must be a dotted OpenTelemetry name such as + ``do.droplets.cpu_utilization``. Underscored Prometheus-style names are + rejected with ``422 Unprocessable Entity``. + + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 201 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @distributed_trace_async + async def create_alert_rule( + self, body: Union[JSON, IO[bytes]], **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create an Alert Rule. + + To create an alert rule, send a POST request to ``/v2/insights/alert-rules`` + with a ``spec`` containing ``name``\\ , ``query``\\ , ``thresholds``\\ , and at least one + ``notification_channels`` binding. ``status`` defaults to + ``ALERT_RULE_STATUS_ACTIVE`` when omitted. ``re_alert_duration`` defaults to + ``RE_ALERT_DURATION_4H`` when omitted. + + ``query.metric`` must be a dotted OpenTelemetry name such as + ``do.droplets.cpu_utilization``. Underscored Prometheus-style names are + rejected with ``422 Unprocessable Entity``. + + :param body: Is either a JSON type or a IO[bytes] type. Required. + :type body: JSON or IO[bytes] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "spec": { + "name": "str", # A human-readable name for the alert rule. Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name to + evaluate (for example ``do.droplets.cpu_utilization``"" ). Required. + "filters": [ + { + "field": "str", # The metric label or field + to filter on. Required. + "operator": "str", # Comparison operator for + the filter. Allowed values: * ``FILTER_OPERATOR_EQUAL`` = equal + * ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``FILTER_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared against the + field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of DigitalOcean + resource URNs the rule applies to. Empty or omitted means the rule is + not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags used to + select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to the + aggregated metric value. Allowed values: * ``THRESHOLD_OPERATOR_EQUAL`` + = equal * ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` + * ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = ``greater_than_or_equal`` + * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = ``not_equal``. Required. Known + values are: "THRESHOLD_OPERATOR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which the + metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` = + ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * ``EVALUATION_WINDOW_10M`` = + ``10m`` * ``EVALUATION_WINDOW_15M`` = ``15m`` * ``EVALUATION_WINDOW_30M`` + = ``30m`` * ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", "EVALUATION_WINDOW_10M", + "EVALUATION_WINDOW_15M", "EVALUATION_WINDOW_30M", and + "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that trigger + this channel. Allowed values: * ``SEVERITY_WARNING`` = warning + * ``SEVERITY_CRITICAL`` = critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` on + create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = ``30m`` + * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = ``4h`` * + ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", and + "RE_ALERT_DURATION_NEVER". + }, + "status": "str" # Optional. Desired alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = paused. + Known values are: "ALERT_RULE_STATUS_ACTIVE" and "ALERT_RULE_STATUS_PAUSED". + } + + # response body for status code(s): 201 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + cls: ClsType[JSON] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(body, (IOBase, bytes)): + _content = body + else: + _json = body + + _request = build_insights_create_alert_rule_request( + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [201, 400, 422]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 201: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace_async + async def get_alert_rule(self, id: str, **kwargs: Any) -> JSON: + # pylint: disable=line-too-long + """Retrieve an Alert Rule. + + To retrieve an alert rule, send a GET request to + ``/v2/insights/alert-rules/{id}``. + + :param id: A unique identifier for an alert rule. Required. + :type id: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_alert_rule_request( + id=id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 404]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @overload + async def update_alert_rule( + self, + id: str, + body: JSON, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Update an Alert Rule. + + This PUT endpoint uses merge semantics. To update an alert rule, send a + request to ``/v2/insights/alert-rules/{id}`` with a full ``spec``. Omit + ``notification_channels`` to keep existing bindings. Omit ``status`` or + ``re_alert_duration`` to keep those existing values. + + :param id: A unique identifier for an alert rule. Required. + :type id: str + :param body: Required. + :type body: JSON + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "spec": { + "name": "str", # A human-readable name for the alert rule. Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name to + evaluate (for example ``do.droplets.cpu_utilization``"" ). Required. + "filters": [ + { + "field": "str", # The metric label or field + to filter on. Required. + "operator": "str", # Comparison operator for + the filter. Allowed values: * ``FILTER_OPERATOR_EQUAL`` = equal + * ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``FILTER_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared against the + field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of DigitalOcean + resource URNs the rule applies to. Empty or omitted means the rule is + not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags used to + select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to the + aggregated metric value. Allowed values: * ``THRESHOLD_OPERATOR_EQUAL`` + = equal * ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` + * ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = ``greater_than_or_equal`` + * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = ``not_equal``. Required. Known + values are: "THRESHOLD_OPERATOR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which the + metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` = + ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * ``EVALUATION_WINDOW_10M`` = + ``10m`` * ``EVALUATION_WINDOW_15M`` = ``15m`` * ``EVALUATION_WINDOW_30M`` + = ``30m`` * ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", "EVALUATION_WINDOW_10M", + "EVALUATION_WINDOW_15M", "EVALUATION_WINDOW_30M", and + "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that trigger + this channel. Allowed values: * ``SEVERITY_WARNING`` = warning + * ``SEVERITY_CRITICAL`` = critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` on + create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = ``30m`` + * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = ``4h`` * + ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", and + "RE_ALERT_DURATION_NEVER". + }, + "status": "str" # Optional. Desired alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = paused. + Known values are: "ALERT_RULE_STATUS_ACTIVE" and "ALERT_RULE_STATUS_PAUSED". + } + + # response body for status code(s): 200 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 404, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + async def update_alert_rule( + self, + id: str, + body: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Update an Alert Rule. + + This PUT endpoint uses merge semantics. To update an alert rule, send a + request to ``/v2/insights/alert-rules/{id}`` with a full ``spec``. Omit + ``notification_channels`` to keep existing bindings. Omit ``status`` or + ``re_alert_duration`` to keep those existing values. + + :param id: A unique identifier for an alert rule. Required. + :type id: str + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 404, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @distributed_trace_async + async def update_alert_rule( + self, id: str, body: Union[JSON, IO[bytes]], **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Update an Alert Rule. + + This PUT endpoint uses merge semantics. To update an alert rule, send a + request to ``/v2/insights/alert-rules/{id}`` with a full ``spec``. Omit + ``notification_channels`` to keep existing bindings. Omit ``status`` or + ``re_alert_duration`` to keep those existing values. + + :param id: A unique identifier for an alert rule. Required. + :type id: str + :param body: Is either a JSON type or a IO[bytes] type. Required. + :type body: JSON or IO[bytes] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "spec": { + "name": "str", # A human-readable name for the alert rule. Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name to + evaluate (for example ``do.droplets.cpu_utilization``"" ). Required. + "filters": [ + { + "field": "str", # The metric label or field + to filter on. Required. + "operator": "str", # Comparison operator for + the filter. Allowed values: * ``FILTER_OPERATOR_EQUAL`` = equal + * ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``FILTER_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared against the + field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of DigitalOcean + resource URNs the rule applies to. Empty or omitted means the rule is + not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags used to + select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to the + aggregated metric value. Allowed values: * ``THRESHOLD_OPERATOR_EQUAL`` + = equal * ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` + * ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = ``greater_than_or_equal`` + * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = ``not_equal``. Required. Known + values are: "THRESHOLD_OPERATOR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which the + metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` = + ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * ``EVALUATION_WINDOW_10M`` = + ``10m`` * ``EVALUATION_WINDOW_15M`` = ``15m`` * ``EVALUATION_WINDOW_30M`` + = ``30m`` * ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", "EVALUATION_WINDOW_10M", + "EVALUATION_WINDOW_15M", "EVALUATION_WINDOW_30M", and + "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that trigger + this channel. Allowed values: * ``SEVERITY_WARNING`` = warning + * ``SEVERITY_CRITICAL`` = critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` on + create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = ``30m`` + * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = ``4h`` * + ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", and + "RE_ALERT_DURATION_NEVER". + }, + "status": "str" # Optional. Desired alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = paused. + Known values are: "ALERT_RULE_STATUS_ACTIVE" and "ALERT_RULE_STATUS_PAUSED". + } + + # response body for status code(s): 200 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 404, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + cls: ClsType[JSON] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(body, (IOBase, bytes)): + _content = body + else: + _json = body + + _request = build_insights_update_alert_rule_request( + id=id, + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 404, 422]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace_async + async def delete_alert_rule(self, id: str, **kwargs: Any) -> Optional[JSON]: + # pylint: disable=line-too-long + """Delete an Alert Rule. + + To delete an alert rule, send a DELETE request to + ``/v2/insights/alert-rules/{id}``. + + :param id: A unique identifier for an alert rule. Required. + :type id: str + :return: JSON object or None + :rtype: JSON or None + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[Optional[JSON]] = kwargs.pop("cls", None) + + _request = build_insights_delete_alert_rule_request( + id=id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [204, 404]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + deserialized = None + response_headers = {} + if response.status_code == 204: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @distributed_trace_async + async def list_notification_channels( + self, *, page: int = 1, per_page: int = 20, **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """List Notification Channels. + + To list all notification channels for your account, send a GET request to + ``/v2/insights/notification-channels``. Results are paginated with ``page`` and + ``per_page`` (default ``20``\\ , maximum ``200``\\ ). + + :keyword page: Which 'page' of paginated results to return. Default value is 1. + :paramtype page: int + :keyword per_page: Number of items returned per page. Default value is 20. + :paramtype per_page: int + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "meta": { + "total": 0 # Optional. Number of objects returned by the request. + }, + "notification_channels": [ + { + "channel_type": "str", # The configured channel type. + Allowed values: * ``CHANNEL_TYPE_EMAIL`` = email * + ``CHANNEL_TYPE_SLACK`` = slack * ``CHANNEL_TYPE_WEBHOOK`` = webhook. + Required. Known values are: "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", + and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification + channel was created. Required. + "id": "str", # A unique identifier for the notification + channel. Required. + "name": "str", # A human-readable name for the notification + channel. Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification + channel was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to + notify. Required. + "webhook_url": "str" # Optional. Slack incoming + webhook URL. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. Omit on update to retain the existing + value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules + that reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook + deliveries. Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. + Required. + "password": "str" # Optional. Basic auth + password. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token + value sent in the Authorization header. Write-only secret "u2014 + full value on create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom + HTTP headers to include on webhook deliveries. At most 20 headers + are allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret + used to sign webhook payloads. Write-only secret "u2014 full + value on create/update; masked as ``********`` on read. + } + } + } + ], + "links": { + "pages": {} + } + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_list_notification_channels_request( + page=page, + per_page=per_page, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @overload + async def create_notification_channel( + self, body: JSON, *, content_type: str = "application/json", **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create a Notification Channel. + + To create a notification channel, send a POST request to + ``/v2/insights/notification-channels`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Email recipients must be verified team member addresses. Webhook URLs must + use HTTPS. Secret fields (\\ ``slack.webhook_url``\\ , webhook credentials) are + write-only and returned masked on subsequent reads. + + :param body: Required. + :type body: JSON + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "name": "str", # A human-readable name for the notification channel. + Required. + "email": { + "to": "str" # One or more recipient email addresses, separated by + commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as ``********`` + on read. Omit on update to retain the existing value. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. Returned + in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent in the + Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP headers to + include on webhook deliveries. At most 20 headers are allowed. Reserved + header names such as ``host``"" , ``content-type``"" , and ``proxy-*`` + are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to sign + webhook payloads. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. + } + } + } + + # response body for status code(s): 201 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + async def create_notification_channel( + self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create a Notification Channel. + + To create a notification channel, send a POST request to + ``/v2/insights/notification-channels`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Email recipients must be verified team member addresses. Webhook URLs must + use HTTPS. Secret fields (\\ ``slack.webhook_url``\\ , webhook credentials) are + write-only and returned masked on subsequent reads. + + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 201 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @distributed_trace_async + async def create_notification_channel( + self, body: Union[JSON, IO[bytes]], **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create a Notification Channel. + + To create a notification channel, send a POST request to + ``/v2/insights/notification-channels`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Email recipients must be verified team member addresses. Webhook URLs must + use HTTPS. Secret fields (\\ ``slack.webhook_url``\\ , webhook credentials) are + write-only and returned masked on subsequent reads. + + :param body: Is either a JSON type or a IO[bytes] type. Required. + :type body: JSON or IO[bytes] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "name": "str", # A human-readable name for the notification channel. + Required. + "email": { + "to": "str" # One or more recipient email addresses, separated by + commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as ``********`` + on read. Omit on update to retain the existing value. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. Returned + in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent in the + Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP headers to + include on webhook deliveries. At most 20 headers are allowed. Reserved + header names such as ``host``"" , ``content-type``"" , and ``proxy-*`` + are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to sign + webhook payloads. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. + } + } + } + + # response body for status code(s): 201 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + cls: ClsType[JSON] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(body, (IOBase, bytes)): + _content = body + else: + _json = body + + _request = build_insights_create_notification_channel_request( + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [201, 400]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 201: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace_async + async def get_notification_channel(self, id: str, **kwargs: Any) -> JSON: + # pylint: disable=line-too-long + """Retrieve a Notification Channel. + + To retrieve a notification channel, send a GET request to + ``/v2/insights/notification-channels/{id}``. Secret fields are returned masked + as ``********``. + + :param id: A unique identifier for a notification channel. Required. + :type id: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_notification_channel_request( + id=id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 404]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @overload + async def update_notification_channel( + self, + id: str, + body: JSON, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Update a Notification Channel. + + To update a notification channel, send a PUT request to + ``/v2/insights/notification-channels/{id}`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Sending a secret field rotates it; omitting the secret field keeps the + existing value. + + :param id: A unique identifier for a notification channel. Required. + :type id: str + :param body: Required. + :type body: JSON + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "name": "str", # A human-readable name for the notification channel. + Required. + "email": { + "to": "str" # One or more recipient email addresses, separated by + commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as ``********`` + on read. Omit on update to retain the existing value. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. Returned + in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent in the + Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP headers to + include on webhook deliveries. At most 20 headers are allowed. Reserved + header names such as ``host``"" , ``content-type``"" , and ``proxy-*`` + are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to sign + webhook payloads. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. + } + } + } + + # response body for status code(s): 200 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + async def update_notification_channel( + self, + id: str, + body: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Update a Notification Channel. + + To update a notification channel, send a PUT request to + ``/v2/insights/notification-channels/{id}`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Sending a secret field rotates it; omitting the secret field keeps the + existing value. + + :param id: A unique identifier for a notification channel. Required. + :type id: str + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @distributed_trace_async + async def update_notification_channel( + self, id: str, body: Union[JSON, IO[bytes]], **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Update a Notification Channel. + + To update a notification channel, send a PUT request to + ``/v2/insights/notification-channels/{id}`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Sending a secret field rotates it; omitting the secret field keeps the + existing value. + + :param id: A unique identifier for a notification channel. Required. + :type id: str + :param body: Is either a JSON type or a IO[bytes] type. Required. + :type body: JSON or IO[bytes] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "name": "str", # A human-readable name for the notification channel. + Required. + "email": { + "to": "str" # One or more recipient email addresses, separated by + commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as ``********`` + on read. Omit on update to retain the existing value. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. Returned + in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent in the + Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP headers to + include on webhook deliveries. At most 20 headers are allowed. Reserved + header names such as ``host``"" , ``content-type``"" , and ``proxy-*`` + are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to sign + webhook payloads. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. + } + } + } + + # response body for status code(s): 200 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + cls: ClsType[JSON] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(body, (IOBase, bytes)): + _content = body + else: + _json = body + + _request = build_insights_update_notification_channel_request( + id=id, + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 404]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace_async + async def delete_notification_channel( + self, id: str, **kwargs: Any + ) -> Optional[JSON]: + # pylint: disable=line-too-long + """Delete a Notification Channel. + + To delete a notification channel, send a DELETE request to + ``/v2/insights/notification-channels/{id}``. + + Deleting a channel that is still referenced by one or more alert rules + returns ``409 Conflict``. + + :param id: A unique identifier for a notification channel. Required. + :type id: str + :return: JSON object or None + :rtype: JSON or None + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 404, 409 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[Optional[JSON]] = kwargs.pop("cls", None) + + _request = build_insights_delete_notification_channel_request( + id=id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [204, 404, 409]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + deserialized = None + response_headers = {} + if response.status_code == 204: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 409: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @distributed_trace_async + async def get_prom_query( + self, + region: str, + *, + query: str, + time: Optional[str] = None, + timeout: Optional[str] = None, + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Execute an instant PromQL query. + + To evaluate a PromQL expression at a single point in time, send a GET request to + ``/v2/insights/query/{region}/prom/api/v1/query``. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :keyword query: A PromQL expression. This may be a metric selector (for example + ``do.droplets.cpu_time``\\ ) or a fuller expression (for example + ``rate(do.droplets.cpu_time[5m])``\\ ). Required. + :paramtype query: str + :keyword time: Evaluation timestamp for an instant query. Accepts a RFC3339 string or a UNIX + timestamp. Defaults to now when omitted. Default value is None. + :paramtype time: str + :keyword timeout: Optional evaluation timeout as a Prometheus duration string. Default value is + None. + :paramtype timeout: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": { + "result": {}, + "resultType": "str" # Required. Known values are: "vector", + "matrix", "scalar", and "string". + }, + "status": "str" # Required. "success" + } + # response body for status code(s): 400, 422, 500, 503 + response == { + "error": "str", # Human-readable error message. Required. + "errorType": "str", # Prometheus error category. Required. Known values are: + "bad_data", "internal", "timeout", "canceled", "execution", and "unavailable". + "status": "str" # Required. "error" + } + # response body for status code(s): 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_prom_query_request( + region=region, + query=query, + time=time, + timeout=timeout, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404, 422, 500, 503]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 500: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 503: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace_async + async def get_prom_query_range( + self, + region: str, + *, + query: str, + start: str, + end: str, + step: str, + timeout: Optional[str] = None, + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Execute a range PromQL query. + + To evaluate a PromQL expression over a time range, send a GET request to + ``/v2/insights/query/{region}/prom/api/v1/query_range``. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :keyword query: A PromQL expression. This may be a metric selector (for example + ``do.droplets.cpu_time``\\ ) or a fuller expression (for example + ``rate(do.droplets.cpu_time[5m])``\\ ). Required. + :paramtype query: str + :keyword start: Start timestamp (inclusive). Accepts a RFC3339 string or a UNIX timestamp. + Required. + :paramtype start: str + :keyword end: End timestamp (inclusive). Accepts a RFC3339 string or a UNIX timestamp. + Required. + :paramtype end: str + :keyword step: Query resolution step width as a Prometheus duration string (for example + ``15s``\\ , ``1m``\\ , ``1h``\\ ). Required. + :paramtype step: str + :keyword timeout: Optional evaluation timeout as a Prometheus duration string. Default value is + None. + :paramtype timeout: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": { + "result": [ + { + "metric": { + "str": "str" # Metric labels as key/value + pairs. By default, metric names in responses use Prometheus + underscored spelling (for example ``do_droplets_cpu_time``"" ), + even when the request used a dotted selector (for example + ``do.droplets.cpu_time``"" ). Required. + }, + "values": [ + [ + {} + ] + ] + } + ], + "resultType": "str" # Required. "matrix" + }, + "status": "str" # Required. "success" + } + # response body for status code(s): 400, 422, 500, 503 + response == { + "error": "str", # Human-readable error message. Required. + "errorType": "str", # Prometheus error category. Required. Known values are: + "bad_data", "internal", "timeout", "canceled", "execution", and "unavailable". + "status": "str" # Required. "error" + } + # response body for status code(s): 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_prom_query_range_request( + region=region, + query=query, + start=start, + end=end, + step=step, + timeout=timeout, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404, 422, 500, 503]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 500: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 503: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace_async + async def get_prom_labels( + self, + region: str, + *, + start: Optional[str] = None, + end: Optional[str] = None, + match: Optional[List[str]] = None, + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """List label names. + + To list label names, send a GET request to ``/v2/insights/query/{region}/prom/api/v1/labels``. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :keyword start: Optional start timestamp (inclusive). Accepts a RFC3339 string or a UNIX + timestamp. Default value is None. + :paramtype start: str + :keyword end: Optional end timestamp (inclusive). Accepts a RFC3339 string or a UNIX timestamp. + Default value is None. + :paramtype end: str + :keyword match: One or more series selectors. Repeat the parameter for multiple matchers. + Default value is None. + :paramtype match: list[str] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": [ + "str" # Required. + ], + "status": "str" # Required. "success" + } + # response body for status code(s): 400, 422, 500, 503 + response == { + "error": "str", # Human-readable error message. Required. + "errorType": "str", # Prometheus error category. Required. Known values are: + "bad_data", "internal", "timeout", "canceled", "execution", and "unavailable". + "status": "str" # Required. "error" + } + # response body for status code(s): 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_prom_labels_request( + region=region, + start=start, + end=end, + match=match, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404, 422, 500, 503]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 500: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 503: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace_async + async def get_prom_label_values( + self, + region: str, + name: str, + *, + start: Optional[str] = None, + end: Optional[str] = None, + match: Optional[List[str]] = None, + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """List values for a label. + + To list values for a label name, send a GET request to + ``/v2/insights/query/{region}/prom/api/v1/label/{name}/values``. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :param name: The label name whose values should be listed. Required. + :type name: str + :keyword start: Optional start timestamp (inclusive). Accepts a RFC3339 string or a UNIX + timestamp. Default value is None. + :paramtype start: str + :keyword end: Optional end timestamp (inclusive). Accepts a RFC3339 string or a UNIX timestamp. + Default value is None. + :paramtype end: str + :keyword match: One or more series selectors. Repeat the parameter for multiple matchers. + Default value is None. + :paramtype match: list[str] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": [ + "str" # Required. + ], + "status": "str" # Required. "success" + } + # response body for status code(s): 400, 422, 500, 503 + response == { + "error": "str", # Human-readable error message. Required. + "errorType": "str", # Prometheus error category. Required. Known values are: + "bad_data", "internal", "timeout", "canceled", "execution", and "unavailable". + "status": "str" # Required. "error" + } + # response body for status code(s): 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_prom_label_values_request( + region=region, + name=name, + start=start, + end=end, + match=match, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404, 422, 500, 503]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 500: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 503: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace_async + async def get_prom_series( + self, + region: str, + *, + match: List[str], + start: Optional[str] = None, + end: Optional[str] = None, + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Find series by label selectors. + + To find series matching one or more selectors, send a GET request to + ``/v2/insights/query/{region}/prom/api/v1/series``. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :keyword match: One or more series selectors. At least one matcher is required. Repeat the + parameter for multiple matchers. Required. + :paramtype match: list[str] + :keyword start: Optional start timestamp (inclusive). Accepts a RFC3339 string or a UNIX + timestamp. Default value is None. + :paramtype start: str + :keyword end: Optional end timestamp (inclusive). Accepts a RFC3339 string or a UNIX timestamp. + Default value is None. + :paramtype end: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": [ + { + "str": "str" # Required. + } + ], + "status": "str" # Required. "success" + } + # response body for status code(s): 400, 422, 500, 503 + response == { + "error": "str", # Human-readable error message. Required. + "errorType": "str", # Prometheus error category. Required. Known values are: + "bad_data", "internal", "timeout", "canceled", "execution", and "unavailable". + "status": "str" # Required. "error" + } + # response body for status code(s): 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_prom_series_request( + region=region, + match=match, + start=start, + end=end, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404, 422, 500, 503]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 500: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 503: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @overload + async def post_logs_search( + self, + region: str, + body: JSON, + *, + content_type: str = "application/json", + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Search logs. + + To search log records in a region, send a POST request to + ``/v2/insights/query/{region}/logs/search`` with a JSON body describing the time range, + optional filter, ordering, and pagination. + The time range must not exceed 7 days. ``pagination.limit`` defaults to 100 and is clamped to + 1000. Cursor pagination requires ordering by ``timestamp`` alone; other sort orders return + ``has_more: false`` and cannot be paged. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :param body: Required. + :type body: JSON + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "time_range": { + "from": { + "absolute": "2020-02-20 00:00:00", # Optional. An absolute + timestamp. Accepts RFC3339/RFC3339Nano strings or Unix + seconds/nanoseconds as decimal strings. + "relative": "str", # Optional. A relative time. Use ``now`` + for the current time, a bare duration such as ``1h`` or ``7d`` to look + back from now, or an offset such as ``now-1h`` or ``now+30m``. Supported + units are ``s``"" , ``m``"" , ``h``"" , ``d``"" , and ``w``. + "unix_nano": "str" # Optional. A Unix nanosecond timestamp, + encoded as a string to preserve 64-bit precision. + }, + "to": { + "absolute": "2020-02-20 00:00:00", # Optional. An absolute + timestamp. Accepts RFC3339/RFC3339Nano strings or Unix + seconds/nanoseconds as decimal strings. + "relative": "str", # Optional. A relative time. Use ``now`` + for the current time, a bare duration such as ``1h`` or ``7d`` to look + back from now, or an offset such as ``now-1h`` or ``now+30m``. Supported + units are ``s``"" , ``m``"" , ``h``"" , ``d``"" , and ``w``. + "unix_nano": "str" # Optional. A Unix nanosecond timestamp, + encoded as a string to preserve 64-bit precision. + } + }, + "filter": { + "and": { + "expressions": [ + ... + ] + }, + "condition": { + "field": { + "name": "str", # The field name. Intrinsic columns + include ``timestamp``"" , ``severity_text``"" , ``severity_number``"" + , ``body``"" , ``trace_id``"" , ``span_id``"" , and ``trace_flags``. + The dotted shorthands ``service.name``"" , ``resource.type``"" , and + ``resource.urn`` are also supported. Arbitrary resource or log + attributes can be accessed with ``ResourceAttributes['key']`` or + ``LogAttributes['key']``. Required. + "scope": "str" # Optional. The attribute scope to + resolve the field against. Omit to let the server apply its default + mapping for the field name. Known values are: "FIELD_SCOPE_RESOURCE" + and "FIELD_SCOPE_ATTRIBUTES". + }, + "operator": "str", # The comparison operator. Required. + Known values are: "FILTER_OPERATOR_EQ", "FILTER_OPERATOR_NEQ", + "FILTER_OPERATOR_IN", "FILTER_OPERATOR_EXISTS", "FILTER_OPERATOR_GTE", + and "FILTER_OPERATOR_LTE". + "value": { + "bool_value": bool, # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + "number_array_value": { + "values": [ + 0.0 # Required. + ] + }, + "number_value": 0.0, # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + "string_array_value": { + "values": [ + "str" # Required. + ] + }, + "string_value": "str" # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + } + }, + "not": ..., + "or": { + "expressions": [ + ... + ] + }, + "text_search": { + "query": "str" # The search string. Required. + } + }, + "order_by": [ + { + "field": { + "name": "str", # The field name. Intrinsic columns + include ``timestamp``"" , ``severity_text``"" , ``severity_number``"" + , ``body``"" , ``trace_id``"" , ``span_id``"" , and ``trace_flags``. + The dotted shorthands ``service.name``"" , ``resource.type``"" , and + ``resource.urn`` are also supported. Arbitrary resource or log + attributes can be accessed with ``ResourceAttributes['key']`` or + ``LogAttributes['key']``. Required. + "scope": "str" # Optional. The attribute scope to + resolve the field against. Omit to let the server apply its default + mapping for the field name. Known values are: "FIELD_SCOPE_RESOURCE" + and "FIELD_SCOPE_ATTRIBUTES". + }, + "direction": "str" # Optional. The sort direction. Omit to + use the server default. Known values are: "SORT_DIRECTION_ASC" and + "SORT_DIRECTION_DESC". + } + ], + "pagination": { + "cursor": "str", # Optional. Opaque cursor from a previous response. + "limit": 100 # Optional. Default value is 100. Maximum number of + results to return. Defaults to 100 and is clamped to 1000. + } + } + + # response body for status code(s): 200 + response == { + "data": [ + { + "timestamp": "2020-02-20 00:00:00", # The log record + timestamp. Required. + "attributes": { + "str": "str" # Optional. Log attributes. + }, + "body": "str", # Optional. The log message body. Omitted + when empty. + "resource": { + "str": "str" # Optional. Resource attributes + associated with the log. + }, + "service_name": "str", # Optional. The service name that + emitted the log. + "severity_number": 0, # Optional. The numeric severity + level. + "severity_text": "str", # Optional. The textual severity + level. + "span_id": "str", # Optional. The span ID if present. + "trace_id": "str" # Optional. The trace ID if present. + } + ], + "pagination": { + "has_more": bool, # Optional. Whether more results are available. + "next_cursor": "str" # Optional. Opaque cursor to fetch the next + page. + } + } + # response body for status code(s): 400, 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + async def post_logs_search( + self, + region: str, + body: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Search logs. + + To search log records in a region, send a POST request to + ``/v2/insights/query/{region}/logs/search`` with a JSON body describing the time range, + optional filter, ordering, and pagination. + The time range must not exceed 7 days. ``pagination.limit`` defaults to 100 and is clamped to + 1000. Cursor pagination requires ordering by ``timestamp`` alone; other sort orders return + ``has_more: false`` and cannot be paged. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": [ + { + "timestamp": "2020-02-20 00:00:00", # The log record + timestamp. Required. + "attributes": { + "str": "str" # Optional. Log attributes. + }, + "body": "str", # Optional. The log message body. Omitted + when empty. + "resource": { + "str": "str" # Optional. Resource attributes + associated with the log. + }, + "service_name": "str", # Optional. The service name that + emitted the log. + "severity_number": 0, # Optional. The numeric severity + level. + "severity_text": "str", # Optional. The textual severity + level. + "span_id": "str", # Optional. The span ID if present. + "trace_id": "str" # Optional. The trace ID if present. + } + ], + "pagination": { + "has_more": bool, # Optional. Whether more results are available. + "next_cursor": "str" # Optional. Opaque cursor to fetch the next + page. + } + } + # response body for status code(s): 400, 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @distributed_trace_async + async def post_logs_search( + self, region: str, body: Union[JSON, IO[bytes]], **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Search logs. + + To search log records in a region, send a POST request to + ``/v2/insights/query/{region}/logs/search`` with a JSON body describing the time range, + optional filter, ordering, and pagination. + The time range must not exceed 7 days. ``pagination.limit`` defaults to 100 and is clamped to + 1000. Cursor pagination requires ordering by ``timestamp`` alone; other sort orders return + ``has_more: false`` and cannot be paged. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :param body: Is either a JSON type or a IO[bytes] type. Required. + :type body: JSON or IO[bytes] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "time_range": { + "from": { + "absolute": "2020-02-20 00:00:00", # Optional. An absolute + timestamp. Accepts RFC3339/RFC3339Nano strings or Unix + seconds/nanoseconds as decimal strings. + "relative": "str", # Optional. A relative time. Use ``now`` + for the current time, a bare duration such as ``1h`` or ``7d`` to look + back from now, or an offset such as ``now-1h`` or ``now+30m``. Supported + units are ``s``"" , ``m``"" , ``h``"" , ``d``"" , and ``w``. + "unix_nano": "str" # Optional. A Unix nanosecond timestamp, + encoded as a string to preserve 64-bit precision. + }, + "to": { + "absolute": "2020-02-20 00:00:00", # Optional. An absolute + timestamp. Accepts RFC3339/RFC3339Nano strings or Unix + seconds/nanoseconds as decimal strings. + "relative": "str", # Optional. A relative time. Use ``now`` + for the current time, a bare duration such as ``1h`` or ``7d`` to look + back from now, or an offset such as ``now-1h`` or ``now+30m``. Supported + units are ``s``"" , ``m``"" , ``h``"" , ``d``"" , and ``w``. + "unix_nano": "str" # Optional. A Unix nanosecond timestamp, + encoded as a string to preserve 64-bit precision. + } + }, + "filter": { + "and": { + "expressions": [ + ... + ] + }, + "condition": { + "field": { + "name": "str", # The field name. Intrinsic columns + include ``timestamp``"" , ``severity_text``"" , ``severity_number``"" + , ``body``"" , ``trace_id``"" , ``span_id``"" , and ``trace_flags``. + The dotted shorthands ``service.name``"" , ``resource.type``"" , and + ``resource.urn`` are also supported. Arbitrary resource or log + attributes can be accessed with ``ResourceAttributes['key']`` or + ``LogAttributes['key']``. Required. + "scope": "str" # Optional. The attribute scope to + resolve the field against. Omit to let the server apply its default + mapping for the field name. Known values are: "FIELD_SCOPE_RESOURCE" + and "FIELD_SCOPE_ATTRIBUTES". + }, + "operator": "str", # The comparison operator. Required. + Known values are: "FILTER_OPERATOR_EQ", "FILTER_OPERATOR_NEQ", + "FILTER_OPERATOR_IN", "FILTER_OPERATOR_EXISTS", "FILTER_OPERATOR_GTE", + and "FILTER_OPERATOR_LTE". + "value": { + "bool_value": bool, # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + "number_array_value": { + "values": [ + 0.0 # Required. + ] + }, + "number_value": 0.0, # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + "string_array_value": { + "values": [ + "str" # Required. + ] + }, + "string_value": "str" # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + } + }, + "not": ..., + "or": { + "expressions": [ + ... + ] + }, + "text_search": { + "query": "str" # The search string. Required. + } + }, + "order_by": [ + { + "field": { + "name": "str", # The field name. Intrinsic columns + include ``timestamp``"" , ``severity_text``"" , ``severity_number``"" + , ``body``"" , ``trace_id``"" , ``span_id``"" , and ``trace_flags``. + The dotted shorthands ``service.name``"" , ``resource.type``"" , and + ``resource.urn`` are also supported. Arbitrary resource or log + attributes can be accessed with ``ResourceAttributes['key']`` or + ``LogAttributes['key']``. Required. + "scope": "str" # Optional. The attribute scope to + resolve the field against. Omit to let the server apply its default + mapping for the field name. Known values are: "FIELD_SCOPE_RESOURCE" + and "FIELD_SCOPE_ATTRIBUTES". + }, + "direction": "str" # Optional. The sort direction. Omit to + use the server default. Known values are: "SORT_DIRECTION_ASC" and + "SORT_DIRECTION_DESC". + } + ], + "pagination": { + "cursor": "str", # Optional. Opaque cursor from a previous response. + "limit": 100 # Optional. Default value is 100. Maximum number of + results to return. Defaults to 100 and is clamped to 1000. + } + } + + # response body for status code(s): 200 + response == { + "data": [ + { + "timestamp": "2020-02-20 00:00:00", # The log record + timestamp. Required. + "attributes": { + "str": "str" # Optional. Log attributes. + }, + "body": "str", # Optional. The log message body. Omitted + when empty. + "resource": { + "str": "str" # Optional. Resource attributes + associated with the log. + }, + "service_name": "str", # Optional. The service name that + emitted the log. + "severity_number": 0, # Optional. The numeric severity + level. + "severity_text": "str", # Optional. The textual severity + level. + "span_id": "str", # Optional. The span ID if present. + "trace_id": "str" # Optional. The trace ID if present. + } + ], + "pagination": { + "has_more": bool, # Optional. Whether more results are available. + "next_cursor": "str" # Optional. Opaque cursor to fetch the next + page. + } + } + # response body for status code(s): 400, 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + cls: ClsType[JSON] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(body, (IOBase, bytes)): + _content = body + else: + _json = body + + _request = build_insights_post_logs_search_request( + region=region, + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + await self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404]: + if _stream: + await response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + +class KubernetesOperations: # pylint: disable=too-many-public-methods + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~pydo.aio.GeneratedClient`'s + :attr:`kubernetes` attribute. + """ + + def __init__(self, *args, **kwargs) -> None: + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + 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_async + async def list_clusters( + self, *, per_page: int = 20, page: int = 1, **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """List All Kubernetes Clusters. + + To list all of the Kubernetes clusters on your account, send a GET request + to ``/v2/kubernetes/clusters``. + + :keyword per_page: Number of items returned per page. Default value is 20. + :paramtype per_page: int + :keyword page: Which 'page' of paginated results to return. Default value is 1. + :paramtype page: int + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "meta": { + "total": 0 # Optional. Number of objects returned by the request. + }, + "kubernetes_clusters": [ + { + "name": "str", # A human-readable name for a Kubernetes + cluster. Required. + "node_pools": [ + { + "auto_scale": bool, # Optional. A boolean + value indicating whether auto-scaling is enabled for this node + pool. + "count": 0, # Optional. The number of + Droplet instances in the node pool. + "gpu_partition_mode": "str", # Optional. The + AMD GPU partition mode for this node pool. Only applicable to AMD + GPU sizes that support partitioning. Immutable after the node + pool is created. When omitted, the GPUs in the pool are left + unpartitioned. Known values are: "AMD_PARTITION_MODE_SPX_NPS1" + and "AMD_PARTITION_MODE_DPX_NPS2". + "id": "str", # Optional. A unique ID that + can be used to identify and reference a specific node pool. + "labels": {}, # Optional. An object of + key/value mappings specifying labels to apply to all nodes in a + pool. Labels will automatically be applied to all existing nodes + and any subsequent nodes added to the pool. Note that when a + label is removed, it is not deleted from the nodes in the pool. + "max_nodes": 0, # Optional. The maximum + number of nodes that this node pool can be auto-scaled to. The + value will be ``0`` if ``auto_scale`` is set to ``false``. + "min_nodes": 0, # Optional. The minimum + number of nodes that this node pool can be auto-scaled to. The + value will be ``0`` if ``auto_scale`` is set to ``false``. + "name": "str", # Optional. A human-readable + name for the node pool. + "nodes": [ + { + "created_at": "2020-02-20 + 00:00:00", # Optional. A time value given in ISO8601 + combined date and time format that represents when the + node was created. + "droplet_id": "str", # + Optional. The ID of the Droplet used for the worker node. + "id": "str", # Optional. A + unique ID that can be used to identify and reference the + node. + "name": "str", # Optional. + An automatically generated, human-readable name for the + node. + "status": { + "state": "str" # + Optional. A string indicating the current status of + the node. Known values are: "provisioning", + "running", "draining", and "deleting". + }, + "updated_at": "2020-02-20 + 00:00:00" # Optional. A time value given in ISO8601 + combined date and time format that represents when the + node was last updated. + } + ], + "size": "str", # Optional. The slug + identifier for the type of Droplet used as workers in the node + pool. + "tags": [ + "str" # Optional. An array + containing the tags applied to the node pool. All node pools + are automatically tagged ``k8s``"" , ``k8s-worker``"" , and + ``k8s:$K8S_CLUSTER_ID``. :code:`
`:code:`
`Requires + ``tag:read`` scope. + ], + "taints": [ + { + "effect": "str", # Optional. + How the node reacts to pods that it won't tolerate. + Available effect values are ``NoSchedule``"" , + ``PreferNoSchedule``"" , and ``NoExecute``. Known values + are: "NoSchedule", "PreferNoSchedule", and "NoExecute". + "key": "str", # Optional. An + arbitrary string. The ``key`` and ``value`` fields of the + ``taint`` object form a key-value pair. For example, if + the value of the ``key`` field is "special" and the value + of the ``value`` field is "gpu", the key value pair would + be ``special=gpu``. + "value": "str" # Optional. + An arbitrary string. The ``key`` and ``value`` fields of + the ``taint`` object form a key-value pair. For example, + if the value of the ``key`` field is "special" and the + value of the ``value`` field is "gpu", the key value pair + would be ``special=gpu``. + } + ] + } + ], + "region": "str", # The slug identifier for the region where + the Kubernetes cluster is located. Required. + "version": "str", # The slug identifier for the version of + Kubernetes used for the cluster. If set to a minor version (e.g. "1.14"), + the latest version within it will be used (e.g. "1.14.6-do.1"); if set to + "latest", the latest published version will be used. See the + ``/v2/kubernetes/options`` endpoint to find all currently available + versions. Required. + "amd_gpu_device_metrics_exporter_plugin": { + "enabled": bool # Optional. Indicates whether the + AMD Device Metrics Exporter is enabled. + }, + "amd_gpu_device_plugin": { + "enabled": bool # Optional. Indicates whether the + AMD GPU Device Plugin is enabled. + }, + "amd_gpu_dra_driver": { + "enabled": bool # Optional. Indicates whether the + AMD GPU DRA Driver is enabled. + }, + "auto_upgrade": False, # Optional. Default value is False. A + boolean value indicating whether the cluster will be automatically + upgraded to new patch releases during its maintenance window. + "cluster_autoscaler_configuration": { + "expanders": [ + "str" # Optional. Customizes expanders used + by cluster-autoscaler. The autoscaler will apply each expander + from the provided list to narrow down the selection of node types + created to scale up, until either a single node type is left, or + the list of expanders is exhausted. If this flag is unset, + autoscaler will use its default expander ``random``. Passing an + empty list ("" *not* ``null``"" ) will unset any previous + expander customizations. Available expanders: * ``random``"" : + Randomly selects a node group to scale. * `priority`: Selects the + node group with the highest priority as per [user-provided + configuration](https://docs.digitalocean.com/products/kubernetes/how-to/autoscale/#configuring-priority-expander) + * ``least_waste``"" : Selects the node group that will result in + the least amount of idle resources. + ], + "scale_down_unneeded_time": "str", # Optional. Used + to customize how long a node is unneeded before being scaled down. + "scale_down_utilization_threshold": 0.0 # Optional. + Used to customize when cluster autoscaler scales down non-empty nodes + by setting the node utilization threshold. + }, + "cluster_subnet": "str", # Optional. The range of IP + addresses for the overlay network of the Kubernetes cluster in CIDR + notation. + "control_plane_firewall": { + "allowed_addresses": [ + "str" # Optional. An array of public + addresses (IPv4 or CIDR) allowed to access the control plane. + ], + "enabled": bool # Optional. Indicates whether the + control plane firewall is enabled. + }, + "coredns_autoscaler": { + "enabled": bool # Optional. Indicates whether the + CoreDNS Cluster Proportional Autoscaler add-on is enabled. + }, + "created_at": "2020-02-20 00:00:00", # Optional. A time + value given in ISO8601 combined date and time format that represents when + the Kubernetes cluster was created. + "endpoint": "str", # Optional. The base URL of the API + server on the Kubernetes master node. + "ha": False, # Optional. Default value is False. A boolean + value indicating whether the control plane is run in a highly available + configuration in the cluster. Highly available control planes incur less + downtime. The property cannot be disabled. When omitted on create, the + default is version-dependent; for DOKS 1.36.0 and later, the default is + true; for earlier versions, the default is false. + "id": "str", # Optional. A unique ID that can be used to + identify and reference a Kubernetes cluster. + "ipv4": "str", # Optional. The public IPv4 address of the + Kubernetes master node. This will not be set if high availability is + configured on the cluster (v1.21+). + "isolated_workers": False, # Optional. Default value is + False. A boolean value indicating whether worker nodes in the cluster are + not assigned public IP addresses. When omitted on create, the default + value is false. When enabled, a NAT gateway must exist in the VPC where + the cluster is created. + "maintenance_policy": { + "day": "str", # Optional. The day of the maintenance + window policy. May be one of ``monday`` through ``sunday``"" , or + ``any`` to indicate an arbitrary week day. Known values are: "any", + "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", + and "sunday". + "duration": "str", # Optional. The duration of the + maintenance window policy in human-readable format. + "start_time": "str" # Optional. The start time in + UTC of the maintenance window policy in 24-hour clock format / HH:MM + notation (e.g., ``15:00``"" ). + }, + "nfs_csi_plugin": { + "enabled": bool # Optional. Indicates whether the + NFS CSI plugin is enabled. + }, + "nvidia_gpu_device_plugin": { + "enabled": bool # Optional. Indicates whether the + Nvidia GPU Device Plugin is enabled. + }, + "nvidia_gpu_dra_driver": { + "enabled": bool # Optional. Indicates whether the + NVIDIA GPU DRA Driver is enabled. + }, + "p2p_oci_registry_plugin": { + "enabled": bool # Optional. Indicates whether the + Peer-to-peer OCI registry component is enabled. + }, + "rdma_shared_dev_plugin": { + "enabled": bool # Optional. Indicates whether the + RDMA shared device plugin is enabled. + }, + "registries": [ + "str" # Optional. An array of integrated DOCR + registries. + ], + "registry_enabled": bool, # Optional. A read-only boolean + value indicating if a container registry is integrated with the cluster. + "routing_agent": { + "enabled": bool # Optional. Indicates whether the + routing-agent component is enabled. + }, + "service_subnet": "str", # Optional. The range of assignable + IP addresses for services running in the Kubernetes cluster in CIDR + notation. + "sso": { + "client_id": "str", # Optional. The OIDC client ID + registered with the identity provider. Required when ``enabled`` is + ``true``. + "enabled": False, # Optional. Default value is + False. Indicates whether SSO authentication is enabled for the + cluster. + "issuer_url": "str", # Optional. The OIDC issuer URL + for the identity provider. Required when ``enabled`` is ``true``. + "required": False # Optional. Default value is + False. Indicates whether any non-SSO forms of authentication are + disallowed. Can only be set to ``true`` when ``enabled`` is ``true``. + }, + "status": { + "message": "str", # Optional. An optional message + providing additional information about the current cluster state. + "state": "str" # Optional. A string indicating the + current status of the cluster. Known values are: "running", + "provisioning", "degraded", "error", "deleted", "upgrading", and + "deleting". + }, + "surge_upgrade": False, # Optional. Default value is False. + A boolean value indicating whether surge upgrade is enabled/disabled for + the cluster. Surge upgrade makes cluster upgrades fast and reliable by + bringing up new nodes before destroying the outdated nodes. + "tags": [ + "str" # Optional. An array of tags applied to the + Kubernetes cluster. All clusters are automatically tagged ``k8s`` and + ``k8s:$K8S_CLUSTER_ID``. :code:`
`:code:`
`Requires + ``tag:read`` scope. + ], + "updated_at": "2020-02-20 00:00:00", # Optional. A time + value given in ISO8601 combined date and time format that represents when + the Kubernetes cluster was last updated. + "vpc_uuid": "str", # Optional. A string specifying the UUID + of the VPC to which the Kubernetes cluster is + assigned.:code:`
`:code:`
`Requires ``vpc:read`` scope. + "worker_subnet_uuid": "str" # Optional. The UUID of the VPC + subnet worker nodes are attached to. When unset, the default subnet for + the VPC is used.:code:`
`:code:`
`Requires ``vpc:read`` scope. } ], "links": { @@ -168933,14 +174367,7 @@ async def create( .. code-block:: python # JSON input template you can fill out and use as your body input. - body = { - "ip": "str" # Optional. An optional IP address to assign to the load - balancer from one of your Bring Your Own IP (BYOIP) prefixes. The address must be - an unassigned BYOIP address on your account in the same region as the load - balancer. If omitted, DigitalOcean assigns a public IP address automatically. - This field is only applied when creating the load balancer, cannot be changed - afterward, and is not supported for ``GLOBAL`` or ``INTERNAL`` load balancers. - } + body = {} # response body for status code(s): 202 response == { @@ -168997,6 +174424,10 @@ async def create( Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -169085,6 +174516,24 @@ async def create( "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -169226,6 +174675,10 @@ async def create( Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -169314,6 +174767,24 @@ async def create( "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -169396,14 +174867,7 @@ async def create(self, body: Union[JSON, IO[bytes]], **kwargs: Any) -> JSON: .. code-block:: python # JSON input template you can fill out and use as your body input. - body = { - "ip": "str" # Optional. An optional IP address to assign to the load - balancer from one of your Bring Your Own IP (BYOIP) prefixes. The address must be - an unassigned BYOIP address on your account in the same region as the load - balancer. If omitted, DigitalOcean assigns a public IP address automatically. - This field is only applied when creating the load balancer, cannot be changed - afterward, and is not supported for ``GLOBAL`` or ``INTERNAL`` load balancers. - } + body = {} # response body for status code(s): 202 response == { @@ -169460,6 +174924,10 @@ async def create(self, body: Union[JSON, IO[bytes]], **kwargs: Any) -> JSON: Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -169548,6 +175016,24 @@ async def create(self, body: Union[JSON, IO[bytes]], **kwargs: Any) -> JSON: "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -169759,6 +175245,10 @@ async def list(self, *, per_page: int = 20, page: int = 1, **kwargs: Any) -> JSO with a Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the + Droplets assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -169851,6 +175341,25 @@ async def list(self, *, per_page: int = 20, page: int = 1, **kwargs: Any) -> JSO "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that + represents whether new Droplets can be created in this region. + Required. + "features": [ + "str" # This attribute is set to an array + which contains features available in this region. Required. + ], + "name": "str", # The display name of the region. + This will be a full name that is used in the control panel and other + interfaces. Required. + "sizes": [ + "str" # This attribute is set to an array + which contains the identifying slugs for the sizes available in + this region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used + as a unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now @@ -170041,6 +175550,10 @@ async def get(self, lb_id: str, **kwargs: Any) -> JSON: Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -170129,6 +175642,24 @@ async def get(self, lb_id: str, **kwargs: Any) -> JSON: "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -170361,6 +175892,272 @@ async def update( Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], + "enable_backend_keepalive": False, # Optional. Default value is + False. A boolean value indicating whether HTTP keepalive connections are + maintained to target Droplets. + "enable_proxy_protocol": False, # Optional. Default value is False. + A boolean value indicating whether PROXY Protocol is in use. + "firewall": { + "allow": [ + "str" # Optional. the rules for allowing traffic to + the load balancer (in the form 'ip:1.2.3.4' or 'cidr:1.2.0.0/16'). + ], + "deny": [ + "str" # Optional. the rules for denying traffic to + the load balancer (in the form 'ip:1.2.3.4' or 'cidr:1.2.0.0/16'). + ] + }, + "glb_settings": { + "cdn": { + "is_enabled": bool # Optional. A boolean flag to + enable CDN caching. + }, + "failover_threshold": 0, # Optional. An integer value as a + percentage to indicate failure threshold to decide how the regional + priorities will take effect. A value of ``50`` would indicate that the + Global load balancer will choose a lower priority region to forward + traffic to once this failure threshold has been reached for the higher + priority region. + "region_priorities": { + "str": 0 # Optional. A map of region string to an + integer priority value indicating preference for which regional + target a Global load balancer will forward traffic to. A lower value + indicates a higher priority. + }, + "target_port": 0, # Optional. An integer representing the + port on the target backends which the load balancer will forward traffic + to. + "target_protocol": "str" # Optional. The protocol used for + forwarding traffic from the load balancer to the target backends. The + possible values are ``http``"" , ``https`` and ``http2``. Known values + are: "http", "https", and "http2". + }, + "health_check": { + "check_interval_seconds": 10, # Optional. Default value is + 10. The number of seconds between between two consecutive health checks. + "healthy_threshold": 3, # Optional. Default value is 3. The + number of times a health check must pass for a backend Droplet to be + marked "healthy" and be re-added to the pool. + "path": "/", # Optional. Default value is "/". The path on + the backend Droplets to which the load balancer instance will send a + request. + "port": 80, # Optional. Default value is 80. An integer + representing the port on the backend Droplets on which the health check + will attempt a connection. + "protocol": "http", # Optional. Default value is "http". The + protocol used for health checks sent to the backend Droplets. The + possible values are ``http``"" , ``https``"" , or ``tcp``. Known values + are: "http", "https", and "tcp". + "response_timeout_seconds": 5, # Optional. Default value is + 5. The number of seconds the load balancer instance will wait for a + response until marking a health check as failed. + "unhealthy_threshold": 5 # Optional. Default value is 5. The + number of times a health check must fail for a backend Droplet to be + marked "unhealthy" and be removed from the pool. + }, + "http_idle_timeout_seconds": 60, # Optional. Default value is 60. An + integer value which configures the idle timeout for HTTP requests to the + target droplets. + "id": "str", # Optional. A unique ID that can be used to identify + and reference a load balancer. + "ipv6": "str", # Optional. An attribute containing the public-facing + IPv6 address of the load balancer. + "name": "str", # Optional. A human-readable name for a load balancer + instance. + "network": "EXTERNAL", # Optional. Default value is "EXTERNAL". A + string indicating whether the load balancer should be external or internal. + Internal load balancers have no public IPs and are only accessible to + resources on the same VPC network. This property cannot be updated after + creating the load balancer. Known values are: "EXTERNAL" and "INTERNAL". + "network_stack": "IPV4", # Optional. Default value is "IPV4". A + string indicating whether the load balancer will support IPv4 or both IPv4 + and IPv6 networking. This property cannot be updated after creating the load + balancer. Known values are: "IPV4" and "DUALSTACK". + "project_id": "str", # Optional. The ID of the project that the load + balancer is associated with. If no ID is provided at creation, the load + balancer associates with the user's default project. If an invalid project ID + is provided, the load balancer will not be created. + "redirect_http_to_https": False, # Optional. Default value is False. + A boolean value indicating whether HTTP requests to the load balancer on port + 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, + "size": "lb-small", # Optional. Default value is "lb-small". This + field has been replaced by the ``size_unit`` field for all regions except in + AMS2, NYC2, and SFO1. Each available load balancer size now equates to the + load balancer having a set number of nodes. * ``lb-small`` = 1 node * + ``lb-medium`` = 3 nodes * ``lb-large`` = 6 nodes You can resize load + balancers after creation up to once per hour. You cannot resize a load + balancer within the first hour of its creation. Known values are: "lb-small", + "lb-medium", and "lb-large". + "size_unit": 1, # Optional. Default value is 1. How many nodes the + load balancer contains. Each additional node increases the load balancer's + ability to manage more connections. Load balancers can be scaled up or down, + and you can change the number of nodes after creation up to once per hour. + This field is currently not available in the AMS2, NYC2, or SFO1 regions. Use + the ``size`` field to scale load balancers that reside in these regions. + "status": "str", # Optional. A status string indicating the current + state of the load balancer. This can be ``new``"" , ``active``"" , or + ``errored``. Known values are: "new", "active", and "errored". + "sticky_sessions": { + "cookie_name": "str", # Optional. The name of the cookie + sent to the client. This attribute is only returned when using + ``cookies`` for the sticky sessions type. + "cookie_ttl_seconds": 0, # Optional. The number of seconds + until the cookie set by the load balancer expires. This attribute is only + returned when using ``cookies`` for the sticky sessions type. + "type": "none" # Optional. Default value is "none". An + attribute indicating how and if requests from a client will be + persistently served by the same backend Droplet. The possible values are + ``cookies`` or ``none``. Known values are: "cookies" and "none". + }, + "subnet_uuid": "str", # Optional. A string specifying the UUID of + the VPC subnet to which the load balancer is assigned. + "tag": "str", # Optional. The name of a Droplet tag corresponding to + Droplets assigned to the load balancer. + "target_load_balancer_ids": [ + "str" # Optional. An array containing the UUIDs of the + Regional load balancers to be used as target backends for a Global load + balancer. + ], + "tls_cipher_policy": "DEFAULT", # Optional. Default value is + "DEFAULT". A string indicating the policy for the TLS cipher suites used by + the load balancer. The possible values are ``DEFAULT`` or ``STRONG``. The + default value is ``DEFAULT``. Known values are: "DEFAULT" and "STRONG". + "type": "REGIONAL", # Optional. Default value is "REGIONAL". A + string indicating whether the load balancer should be a standard regional + HTTP load balancer, a regional network load balancer that routes traffic at + the TCP/UDP transport layer, or a global load balancer. Known values are: + "REGIONAL", "REGIONAL_NETWORK", and "GLOBAL". + "vpc_uuid": "str" # Optional. A string specifying the UUID of the + VPC to which the load balancer is assigned. + } + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + async def update( + self, + lb_id: str, + body: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Update a Load Balancer. + + To update a load balancer's settings, send a PUT request to + ``/v2/load_balancers/$LOAD_BALANCER_ID``. The request should contain a full + representation of the load balancer including existing attributes. It may + contain *one of* the ``droplets_ids`` or ``tag`` attributes as they are mutually + exclusive. **Note that any attribute that is not provided will be reset to its + default value.**. + + :param lb_id: A unique identifier for a load balancer. Required. + :type lb_id: str + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "load_balancer": { + "forwarding_rules": [ + { + "entry_port": 0, # An integer representing the port + on which the load balancer instance will listen. Required. + "entry_protocol": "str", # The protocol used for + traffic to the load balancer. The possible values are: ``http``"" , + ``https``"" , ``http2``"" , ``http3``"" , ``tcp``"" , or ``udp``. If + you set the ``entry_protocol`` to ``udp``"" , the + ``target_protocol`` must be set to ``udp``. When using UDP, the load + balancer requires that you set up a health check with a port that + uses TCP, HTTP, or HTTPS to work properly. Required. Known values + are: "http", "https", "http2", "http3", "tcp", and "udp". + "target_port": 0, # An integer representing the port + on the backend Droplets to which the load balancer will send traffic. + Required. + "target_protocol": "str", # The protocol used for + traffic from the load balancer to the backend Droplets. The possible + values are: ``http``"" , ``https``"" , ``http2``"" , ``tcp``"" , or + ``udp``. If you set the ``target_protocol`` to ``udp``"" , the + ``entry_protocol`` must be set to ``udp``. When using UDP, the load + balancer requires that you set up a health check with a port that + uses TCP, HTTP, or HTTPS to work properly. Required. Known values + are: "http", "https", "http2", "tcp", and "udp". + "certificate_id": "str", # Optional. The ID of the + TLS certificate used for SSL termination if enabled. + "tls_passthrough": bool # Optional. A boolean value + indicating whether SSL encrypted traffic will be passed through to + the backend Droplets. + } + ], + "algorithm": "round_robin", # Optional. Default value is + "round_robin". This field has been deprecated. You can no longer specify an + algorithm for load balancers. Known values are: "round_robin" and + "least_connections". + "created_at": "2020-02-20 00:00:00", # Optional. A time value given + in ISO8601 combined date and time format that represents when the load + balancer was created. + "disable_lets_encrypt_dns_records": False, # Optional. Default value + is False. A boolean value indicating whether to disable automatic DNS record + creation for Let's Encrypt certificates that are added to the load balancer. + "domains": [ + { + "certificate_id": "str", # Optional. The ID of the + TLS certificate used for SSL termination. + "is_managed": bool, # Optional. A boolean value + indicating if the domain is already managed by DigitalOcean. If true, + all A and AAAA records required to enable Global load balancers will + be automatically added. + "name": "str" # Optional. FQDN to associate with a + Global load balancer. + } + ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -170449,246 +176246,24 @@ async def update( "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. - "size": "lb-small", # Optional. Default value is "lb-small". This - field has been replaced by the ``size_unit`` field for all regions except in - AMS2, NYC2, and SFO1. Each available load balancer size now equates to the - load balancer having a set number of nodes. * ``lb-small`` = 1 node * - ``lb-medium`` = 3 nodes * ``lb-large`` = 6 nodes You can resize load - balancers after creation up to once per hour. You cannot resize a load - balancer within the first hour of its creation. Known values are: "lb-small", - "lb-medium", and "lb-large". - "size_unit": 1, # Optional. Default value is 1. How many nodes the - load balancer contains. Each additional node increases the load balancer's - ability to manage more connections. Load balancers can be scaled up or down, - and you can change the number of nodes after creation up to once per hour. - This field is currently not available in the AMS2, NYC2, or SFO1 regions. Use - the ``size`` field to scale load balancers that reside in these regions. - "status": "str", # Optional. A status string indicating the current - state of the load balancer. This can be ``new``"" , ``active``"" , or - ``errored``. Known values are: "new", "active", and "errored". - "sticky_sessions": { - "cookie_name": "str", # Optional. The name of the cookie - sent to the client. This attribute is only returned when using - ``cookies`` for the sticky sessions type. - "cookie_ttl_seconds": 0, # Optional. The number of seconds - until the cookie set by the load balancer expires. This attribute is only - returned when using ``cookies`` for the sticky sessions type. - "type": "none" # Optional. Default value is "none". An - attribute indicating how and if requests from a client will be - persistently served by the same backend Droplet. The possible values are - ``cookies`` or ``none``. Known values are: "cookies" and "none". - }, - "subnet_uuid": "str", # Optional. A string specifying the UUID of - the VPC subnet to which the load balancer is assigned. - "tag": "str", # Optional. The name of a Droplet tag corresponding to - Droplets assigned to the load balancer. - "target_load_balancer_ids": [ - "str" # Optional. An array containing the UUIDs of the - Regional load balancers to be used as target backends for a Global load - balancer. - ], - "tls_cipher_policy": "DEFAULT", # Optional. Default value is - "DEFAULT". A string indicating the policy for the TLS cipher suites used by - the load balancer. The possible values are ``DEFAULT`` or ``STRONG``. The - default value is ``DEFAULT``. Known values are: "DEFAULT" and "STRONG". - "type": "REGIONAL", # Optional. Default value is "REGIONAL". A - string indicating whether the load balancer should be a standard regional - HTTP load balancer, a regional network load balancer that routes traffic at - the TCP/UDP transport layer, or a global load balancer. Known values are: - "REGIONAL", "REGIONAL_NETWORK", and "GLOBAL". - "vpc_uuid": "str" # Optional. A string specifying the UUID of the - VPC to which the load balancer is assigned. - } - } - # response body for status code(s): 404 - response == { - "id": "str", # A short identifier corresponding to the HTTP status code - returned. For example, the ID for a response returning a 404 status code would - be "not_found.". Required. - "message": "str", # A message providing additional information about the - error, including details to help resolve it when possible. Required. - "request_id": "str" # Optional. Optionally, some endpoints may include a - request ID that should be provided when reporting bugs or opening support - tickets to help identify the issue. - } - """ - - @overload - async def update( - self, - lb_id: str, - body: IO[bytes], - *, - content_type: str = "application/json", - **kwargs: Any - ) -> JSON: - # pylint: disable=line-too-long - """Update a Load Balancer. - - To update a load balancer's settings, send a PUT request to - ``/v2/load_balancers/$LOAD_BALANCER_ID``. The request should contain a full - representation of the load balancer including existing attributes. It may - contain *one of* the ``droplets_ids`` or ``tag`` attributes as they are mutually - exclusive. **Note that any attribute that is not provided will be reset to its - default value.**. - - :param lb_id: A unique identifier for a load balancer. Required. - :type lb_id: str - :param body: Required. - :type body: IO[bytes] - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :return: JSON object - :rtype: JSON - :raises ~azure.core.exceptions.HttpResponseError: - - Example: - .. code-block:: python - - # response body for status code(s): 200 - response == { - "load_balancer": { - "forwarding_rules": [ - { - "entry_port": 0, # An integer representing the port - on which the load balancer instance will listen. Required. - "entry_protocol": "str", # The protocol used for - traffic to the load balancer. The possible values are: ``http``"" , - ``https``"" , ``http2``"" , ``http3``"" , ``tcp``"" , or ``udp``. If - you set the ``entry_protocol`` to ``udp``"" , the - ``target_protocol`` must be set to ``udp``. When using UDP, the load - balancer requires that you set up a health check with a port that - uses TCP, HTTP, or HTTPS to work properly. Required. Known values - are: "http", "https", "http2", "http3", "tcp", and "udp". - "target_port": 0, # An integer representing the port - on the backend Droplets to which the load balancer will send traffic. - Required. - "target_protocol": "str", # The protocol used for - traffic from the load balancer to the backend Droplets. The possible - values are: ``http``"" , ``https``"" , ``http2``"" , ``tcp``"" , or - ``udp``. If you set the ``target_protocol`` to ``udp``"" , the - ``entry_protocol`` must be set to ``udp``. When using UDP, the load - balancer requires that you set up a health check with a port that - uses TCP, HTTP, or HTTPS to work properly. Required. Known values - are: "http", "https", "http2", "tcp", and "udp". - "certificate_id": "str", # Optional. The ID of the - TLS certificate used for SSL termination if enabled. - "tls_passthrough": bool # Optional. A boolean value - indicating whether SSL encrypted traffic will be passed through to - the backend Droplets. - } - ], - "algorithm": "round_robin", # Optional. Default value is - "round_robin". This field has been deprecated. You can no longer specify an - algorithm for load balancers. Known values are: "round_robin" and - "least_connections". - "created_at": "2020-02-20 00:00:00", # Optional. A time value given - in ISO8601 combined date and time format that represents when the load - balancer was created. - "disable_lets_encrypt_dns_records": False, # Optional. Default value - is False. A boolean value indicating whether to disable automatic DNS record - creation for Let's Encrypt certificates that are added to the load balancer. - "domains": [ - { - "certificate_id": "str", # Optional. The ID of the - TLS certificate used for SSL termination. - "is_managed": bool, # Optional. A boolean value - indicating if the domain is already managed by DigitalOcean. If true, - all A and AAAA records required to enable Global load balancers will - be automatically added. - "name": "str" # Optional. FQDN to associate with a - Global load balancer. - } - ], - "enable_backend_keepalive": False, # Optional. Default value is - False. A boolean value indicating whether HTTP keepalive connections are - maintained to target Droplets. - "enable_proxy_protocol": False, # Optional. Default value is False. - A boolean value indicating whether PROXY Protocol is in use. - "firewall": { - "allow": [ - "str" # Optional. the rules for allowing traffic to - the load balancer (in the form 'ip:1.2.3.4' or 'cidr:1.2.0.0/16'). + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. ], - "deny": [ - "str" # Optional. the rules for denying traffic to - the load balancer (in the form 'ip:1.2.3.4' or 'cidr:1.2.0.0/16'). - ] - }, - "glb_settings": { - "cdn": { - "is_enabled": bool # Optional. A boolean flag to - enable CDN caching. - }, - "failover_threshold": 0, # Optional. An integer value as a - percentage to indicate failure threshold to decide how the regional - priorities will take effect. A value of ``50`` would indicate that the - Global load balancer will choose a lower priority region to forward - traffic to once this failure threshold has been reached for the higher - priority region. - "region_priorities": { - "str": 0 # Optional. A map of region string to an - integer priority value indicating preference for which regional - target a Global load balancer will forward traffic to. A lower value - indicates a higher priority. - }, - "target_port": 0, # Optional. An integer representing the - port on the target backends which the load balancer will forward traffic - to. - "target_protocol": "str" # Optional. The protocol used for - forwarding traffic from the load balancer to the target backends. The - possible values are ``http``"" , ``https`` and ``http2``. Known values - are: "http", "https", and "http2". - }, - "health_check": { - "check_interval_seconds": 10, # Optional. Default value is - 10. The number of seconds between between two consecutive health checks. - "healthy_threshold": 3, # Optional. Default value is 3. The - number of times a health check must pass for a backend Droplet to be - marked "healthy" and be re-added to the pool. - "path": "/", # Optional. Default value is "/". The path on - the backend Droplets to which the load balancer instance will send a - request. - "port": 80, # Optional. Default value is 80. An integer - representing the port on the backend Droplets on which the health check - will attempt a connection. - "protocol": "http", # Optional. Default value is "http". The - protocol used for health checks sent to the backend Droplets. The - possible values are ``http``"" , ``https``"" , or ``tcp``. Known values - are: "http", "https", and "tcp". - "response_timeout_seconds": 5, # Optional. Default value is - 5. The number of seconds the load balancer instance will wait for a - response until marking a health check as failed. - "unhealthy_threshold": 5 # Optional. Default value is 5. The - number of times a health check must fail for a backend Droplet to be - marked "unhealthy" and be removed from the pool. + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. }, - "http_idle_timeout_seconds": 60, # Optional. Default value is 60. An - integer value which configures the idle timeout for HTTP requests to the - target droplets. - "id": "str", # Optional. A unique ID that can be used to identify - and reference a load balancer. - "ipv6": "str", # Optional. An attribute containing the public-facing - IPv6 address of the load balancer. - "name": "str", # Optional. A human-readable name for a load balancer - instance. - "network": "EXTERNAL", # Optional. Default value is "EXTERNAL". A - string indicating whether the load balancer should be external or internal. - Internal load balancers have no public IPs and are only accessible to - resources on the same VPC network. This property cannot be updated after - creating the load balancer. Known values are: "EXTERNAL" and "INTERNAL". - "network_stack": "IPV4", # Optional. Default value is "IPV4". A - string indicating whether the load balancer will support IPv4 or both IPv4 - and IPv6 networking. This property cannot be updated after creating the load - balancer. Known values are: "IPV4" and "DUALSTACK". - "project_id": "str", # Optional. The ID of the project that the load - balancer is associated with. If no ID is provided at creation, the load - balancer associates with the user's default project. If an invalid project ID - is provided, the load balancer will not be created. - "redirect_http_to_https": False, # Optional. Default value is False. - A boolean value indicating whether HTTP requests to the load balancer on port - 80 will be redirected to HTTPS on port 443. "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -170836,6 +176411,10 @@ async def update( Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -170924,6 +176503,24 @@ async def update( "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -171332,8 +176929,8 @@ async def add_droplets( # JSON input template you can fill out and use as your body input. body = { "droplet_ids": [ - 0 # An array containing the IDs of the Droplets assigned to the load - balancer. Required. + 0 # Optional. An array containing the IDs of the Droplets assigned + to the load balancer. ] } @@ -171432,8 +177029,8 @@ async def add_droplets( # JSON input template you can fill out and use as your body input. body = { "droplet_ids": [ - 0 # An array containing the IDs of the Droplets assigned to the load - balancer. Required. + 0 # Optional. An array containing the IDs of the Droplets assigned + to the load balancer. ] } @@ -171574,8 +177171,8 @@ async def remove_droplets( # JSON input template you can fill out and use as your body input. body = { "droplet_ids": [ - 0 # An array containing the IDs of the Droplets assigned to the load - balancer. Required. + 0 # Optional. An array containing the IDs of the Droplets assigned + to the load balancer. ] } @@ -171668,8 +177265,8 @@ async def remove_droplets( # JSON input template you can fill out and use as your body input. body = { "droplet_ids": [ - 0 # An array containing the IDs of the Droplets assigned to the load - balancer. Required. + 0 # Optional. An array containing the IDs of the Droplets assigned + to the load balancer. ] } diff --git a/src/pydo/operations/__init__.py b/src/pydo/operations/__init__.py index 58cfa4c4..163af5e7 100644 --- a/src/pydo/operations/__init__.py +++ b/src/pydo/operations/__init__.py @@ -37,6 +37,7 @@ from ._operations import FunctionsAccessKeyOperations from ._operations import ImagesOperations from ._operations import ImageActionsOperations +from ._operations import InsightsOperations from ._operations import KubernetesOperations from ._operations import LoadBalancersOperations from ._operations import MonitoringOperations @@ -110,6 +111,7 @@ "FunctionsAccessKeyOperations", "ImagesOperations", "ImageActionsOperations", + "InsightsOperations", "KubernetesOperations", "LoadBalancersOperations", "MonitoringOperations", diff --git a/src/pydo/operations/_operations.py b/src/pydo/operations/_operations.py index 3c4d00e7..93f35028 100644 --- a/src/pydo/operations/_operations.py +++ b/src/pydo/operations/_operations.py @@ -7238,6 +7238,523 @@ def build_image_actions_get_request( return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs) +def build_insights_list_alert_instances_request( # pylint: disable=name-too-long + *, + per_page: int = 20, + page: int = 1, + status: Optional[str] = None, + rule_id: Optional[str] = None, + resource_urn: Optional[str] = None, + **kwargs: Any, +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/alert-instances" + + # Construct parameters + if per_page is not None: + _params["per_page"] = _SERIALIZER.query( + "per_page", per_page, "int", maximum=200, minimum=1 + ) + if page is not None: + _params["page"] = _SERIALIZER.query("page", page, "int", minimum=1) + if status is not None: + _params["status"] = _SERIALIZER.query("status", status, "str") + if rule_id is not None: + _params["rule_id"] = _SERIALIZER.query("rule_id", rule_id, "str") + if resource_urn is not None: + _params["resource_urn"] = _SERIALIZER.query("resource_urn", resource_urn, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) + + +def build_insights_get_alert_instance_request( + id: str, **kwargs: Any +) -> HttpRequest: # pylint: disable=name-too-long + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/alert-instances/{id}" + path_format_arguments = { + "id": _SERIALIZER.url("id", id, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs) + + +def build_insights_list_alert_rules_request( + *, + page: int = 1, + per_page: int = 20, + resource_urn: Optional[str] = None, + **kwargs: Any, +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/alert-rules" + + # Construct parameters + if page is not None: + _params["page"] = _SERIALIZER.query("page", page, "int", minimum=1) + if per_page is not None: + _params["per_page"] = _SERIALIZER.query( + "per_page", per_page, "int", maximum=200, minimum=1 + ) + if resource_urn is not None: + _params["resource_urn"] = _SERIALIZER.query("resource_urn", resource_urn, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) + + +def build_insights_create_alert_rule_request(**kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/alert-rules" + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header( + "content_type", content_type, "str" + ) + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) + + +def build_insights_get_alert_rule_request(id: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/alert-rules/{id}" + path_format_arguments = { + "id": _SERIALIZER.url("id", id, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs) + + +def build_insights_update_alert_rule_request(id: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/alert-rules/{id}" + path_format_arguments = { + "id": _SERIALIZER.url("id", id, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header( + "content_type", content_type, "str" + ) + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs) + + +def build_insights_delete_alert_rule_request(id: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/alert-rules/{id}" + path_format_arguments = { + "id": _SERIALIZER.url("id", id, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, headers=_headers, **kwargs) + + +def build_insights_list_notification_channels_request( # pylint: disable=name-too-long + *, page: int = 1, per_page: int = 20, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/notification-channels" + + # Construct parameters + if page is not None: + _params["page"] = _SERIALIZER.query("page", page, "int", minimum=1) + if per_page is not None: + _params["per_page"] = _SERIALIZER.query( + "per_page", per_page, "int", maximum=200, minimum=1 + ) + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) + + +def build_insights_create_notification_channel_request( + **kwargs: Any, +) -> HttpRequest: # pylint: disable=name-too-long + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/notification-channels" + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header( + "content_type", content_type, "str" + ) + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) + + +def build_insights_get_notification_channel_request( # pylint: disable=name-too-long + id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/notification-channels/{id}" + path_format_arguments = { + "id": _SERIALIZER.url("id", id, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, headers=_headers, **kwargs) + + +def build_insights_update_notification_channel_request( # pylint: disable=name-too-long + id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/notification-channels/{id}" + path_format_arguments = { + "id": _SERIALIZER.url("id", id, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header( + "content_type", content_type, "str" + ) + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="PUT", url=_url, headers=_headers, **kwargs) + + +def build_insights_delete_notification_channel_request( # pylint: disable=name-too-long + id: str, **kwargs: Any +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/notification-channels/{id}" + path_format_arguments = { + "id": _SERIALIZER.url("id", id, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="DELETE", url=_url, headers=_headers, **kwargs) + + +def build_insights_get_prom_query_request( + region: str, + *, + query: str, + time: Optional[str] = None, + timeout: Optional[str] = None, + **kwargs: Any, +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/query/{region}/prom/api/v1/query" + path_format_arguments = { + "region": _SERIALIZER.url("region", region, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["query"] = _SERIALIZER.query("query", query, "str") + if time is not None: + _params["time"] = _SERIALIZER.query("time", time, "str") + if timeout is not None: + _params["timeout"] = _SERIALIZER.query("timeout", timeout, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) + + +def build_insights_get_prom_query_range_request( # pylint: disable=name-too-long + region: str, + *, + query: str, + start: str, + end: str, + step: str, + timeout: Optional[str] = None, + **kwargs: Any, +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/query/{region}/prom/api/v1/query_range" + path_format_arguments = { + "region": _SERIALIZER.url("region", region, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["query"] = _SERIALIZER.query("query", query, "str") + _params["start"] = _SERIALIZER.query("start", start, "str") + _params["end"] = _SERIALIZER.query("end", end, "str") + _params["step"] = _SERIALIZER.query("step", step, "str") + if timeout is not None: + _params["timeout"] = _SERIALIZER.query("timeout", timeout, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) + + +def build_insights_get_prom_labels_request( + region: str, + *, + start: Optional[str] = None, + end: Optional[str] = None, + match: Optional[List[str]] = None, + **kwargs: Any, +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/query/{region}/prom/api/v1/labels" + path_format_arguments = { + "region": _SERIALIZER.url("region", region, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + if start is not None: + _params["start"] = _SERIALIZER.query("start", start, "str") + if end is not None: + _params["end"] = _SERIALIZER.query("end", end, "str") + if match is not None: + _params["match[]"] = [ + _SERIALIZER.query("match", q, "str") if q is not None else "" for q in match + ] + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) + + +def build_insights_get_prom_label_values_request( # pylint: disable=name-too-long + region: str, + name: str, + *, + start: Optional[str] = None, + end: Optional[str] = None, + match: Optional[List[str]] = None, + **kwargs: Any, +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/query/{region}/prom/api/v1/label/{name}/values" + path_format_arguments = { + "region": _SERIALIZER.url("region", region, "str"), + "name": _SERIALIZER.url("name", name, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + if start is not None: + _params["start"] = _SERIALIZER.query("start", start, "str") + if end is not None: + _params["end"] = _SERIALIZER.query("end", end, "str") + if match is not None: + _params["match[]"] = [ + _SERIALIZER.query("match", q, "str") if q is not None else "" for q in match + ] + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) + + +def build_insights_get_prom_series_request( + region: str, + *, + match: List[str], + start: Optional[str] = None, + end: Optional[str] = None, + **kwargs: Any, +) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = case_insensitive_dict(kwargs.pop("params", {}) or {}) + + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/query/{region}/prom/api/v1/series" + path_format_arguments = { + "region": _SERIALIZER.url("region", region, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct parameters + _params["match[]"] = [ + _SERIALIZER.query("match", q, "str") if q is not None else "" for q in match + ] + if start is not None: + _params["start"] = _SERIALIZER.query("start", start, "str") + if end is not None: + _params["end"] = _SERIALIZER.query("end", end, "str") + + # Construct headers + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest( + method="GET", url=_url, params=_params, headers=_headers, **kwargs + ) + + +def build_insights_post_logs_search_request(region: str, **kwargs: Any) -> HttpRequest: + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + accept = _headers.pop("Accept", "application/json") + + # Construct URL + _url = "/v2/insights/query/{region}/logs/search" + path_format_arguments = { + "region": _SERIALIZER.url("region", region, "str"), + } + + _url: str = _url.format(**path_format_arguments) # type: ignore + + # Construct headers + if content_type is not None: + _headers["Content-Type"] = _SERIALIZER.header( + "content_type", content_type, "str" + ) + _headers["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, headers=_headers, **kwargs) + + def build_kubernetes_list_clusters_request( *, per_page: int = 20, page: int = 1, **kwargs: Any ) -> HttpRequest: @@ -147715,9 +148232,10 @@ def update_user( For Kafka and OpenSearch clusters, additional options can be configured in the ``settings`` object (for example, topic or index ACLs). - Updating users is not supported for MongoDB clusters. MongoDB roles and database - access are set with ``settings.mongo_user_settings`` when creating a user and cannot - be changed afterward; recreate the user to apply different roles or databases. + Updating users is supported for PostgreSQL, Kafka, and OpenSearch clusters. For + other engines, the request returns a 422. MongoDB roles and database access are + set with ``settings.mongo_user_settings`` when creating a user and cannot be + changed afterward; recreate the user to apply different roles or databases. The response will be a JSON object with a key called ``user``. The value of this will be an object that contains the name of the updated database user, along with the ``settings`` object @@ -147858,7 +148376,7 @@ def update_user( } } } - # response body for status code(s): 404 + # response body for status code(s): 404, 422 response == { "id": "str", # A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would @@ -147898,9 +148416,10 @@ def update_user( For Kafka and OpenSearch clusters, additional options can be configured in the ``settings`` object (for example, topic or index ACLs). - Updating users is not supported for MongoDB clusters. MongoDB roles and database - access are set with ``settings.mongo_user_settings`` when creating a user and cannot - be changed afterward; recreate the user to apply different roles or databases. + Updating users is supported for PostgreSQL, Kafka, and OpenSearch clusters. For + other engines, the request returns a 422. MongoDB roles and database access are + set with ``settings.mongo_user_settings`` when creating a user and cannot be + changed afterward; recreate the user to apply different roles or databases. The response will be a JSON object with a key called ``user``. The value of this will be an object that contains the name of the updated database user, along with the ``settings`` object @@ -148002,7 +148521,7 @@ def update_user( } } } - # response body for status code(s): 404 + # response body for status code(s): 404, 422 response == { "id": "str", # A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would @@ -148040,9 +148559,10 @@ def update_user( For Kafka and OpenSearch clusters, additional options can be configured in the ``settings`` object (for example, topic or index ACLs). - Updating users is not supported for MongoDB clusters. MongoDB roles and database - access are set with ``settings.mongo_user_settings`` when creating a user and cannot - be changed afterward; recreate the user to apply different roles or databases. + Updating users is supported for PostgreSQL, Kafka, and OpenSearch clusters. For + other engines, the request returns a 422. MongoDB roles and database access are + set with ``settings.mongo_user_settings`` when creating a user and cannot be + changed afterward; recreate the user to apply different roles or databases. The response will be a JSON object with a key called ``user``. The value of this will be an object that contains the name of the updated database user, along with the ``settings`` object @@ -148180,7 +148700,7 @@ def update_user( } } } - # response body for status code(s): 404 + # response body for status code(s): 404, 422 response == { "id": "str", # A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would @@ -148241,7 +148761,7 @@ def update_user( response = pipeline_response.http_response - if response.status_code not in [201, 404]: + if response.status_code not in [201, 404, 422]: if _stream: response.read() # Load the body in memory and close the socket map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore @@ -148280,6 +148800,22 @@ def update_user( else: deserialized = None + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + if cls: return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore @@ -178124,37 +178660,5391 @@ def list(self, image_id: int, **kwargs: Any) -> JSON: return cast(JSON, deserialized) # type: ignore @overload - def post( + def post( + self, + image_id: int, + body: Optional[JSON] = None, + *, + content_type: str = "application/json", + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Initiate an Image Action. + + The following actions are available on an Image. + + Convert an Image to a Snapshot + ------------------------------ + + To convert an image, for example, a backup to a snapshot, send a POST request + to ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``convert``. + + Transfer an Image + ----------------- + + To transfer an image to another region, send a POST request to + ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``transfer`` and set + ``region`` attribute to the slug identifier of the region you wish to transfer + to. + + :param image_id: A unique number that can be used to identify and reference a specific image. + Required. + :type image_id: int + :param body: Default value is None. + :type body: JSON + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = {} + + # response body for status code(s): 201 + response == { + "completed_at": "2020-02-20 00:00:00", # Optional. A time value given in + ISO8601 combined date and time format that represents when the action was + completed. + "id": 0, # Optional. A unique numeric ID that can be used to identify and + reference an action. + "region": { + "available": bool, # This is a boolean value that represents whether + new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which contains + features available in this region. Required. + ], + "name": "str", # The display name of the region. This will be a + full name that is used in the control panel and other interfaces. Required. + "sizes": [ + "str" # This attribute is set to an array which contains the + identifying slugs for the sizes available in this region. sizes:read is + required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a unique + identifier for each region. Required. + }, + "region_slug": "str", # Optional. A human-readable string that is used as a + unique identifier for each region. + "resource_id": 0, # Optional. A unique identifier for the resource that the + action is associated with. + "resource_type": "str", # Optional. The type of resource that the action is + associated with. + "started_at": "2020-02-20 00:00:00", # Optional. A time value given in + ISO8601 combined date and time format that represents when the action was + initiated. + "status": "in-progress", # Optional. Default value is "in-progress". The + current status of the action. This can be "in-progress", "completed", or + "errored". Known values are: "in-progress", "completed", and "errored". + "type": "str" # Optional. This is the type of action that the object + represents. For example, this could be "transfer" to represent the state of an + image transfer action. + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + def post( + self, + image_id: int, + body: Optional[IO[bytes]] = None, + *, + content_type: str = "application/json", + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Initiate an Image Action. + + The following actions are available on an Image. + + Convert an Image to a Snapshot + ------------------------------ + + To convert an image, for example, a backup to a snapshot, send a POST request + to ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``convert``. + + Transfer an Image + ----------------- + + To transfer an image to another region, send a POST request to + ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``transfer`` and set + ``region`` attribute to the slug identifier of the region you wish to transfer + to. + + :param image_id: A unique number that can be used to identify and reference a specific image. + Required. + :type image_id: int + :param body: Default value is None. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 201 + response == { + "completed_at": "2020-02-20 00:00:00", # Optional. A time value given in + ISO8601 combined date and time format that represents when the action was + completed. + "id": 0, # Optional. A unique numeric ID that can be used to identify and + reference an action. + "region": { + "available": bool, # This is a boolean value that represents whether + new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which contains + features available in this region. Required. + ], + "name": "str", # The display name of the region. This will be a + full name that is used in the control panel and other interfaces. Required. + "sizes": [ + "str" # This attribute is set to an array which contains the + identifying slugs for the sizes available in this region. sizes:read is + required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a unique + identifier for each region. Required. + }, + "region_slug": "str", # Optional. A human-readable string that is used as a + unique identifier for each region. + "resource_id": 0, # Optional. A unique identifier for the resource that the + action is associated with. + "resource_type": "str", # Optional. The type of resource that the action is + associated with. + "started_at": "2020-02-20 00:00:00", # Optional. A time value given in + ISO8601 combined date and time format that represents when the action was + initiated. + "status": "in-progress", # Optional. Default value is "in-progress". The + current status of the action. This can be "in-progress", "completed", or + "errored". Known values are: "in-progress", "completed", and "errored". + "type": "str" # Optional. This is the type of action that the object + represents. For example, this could be "transfer" to represent the state of an + image transfer action. + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @distributed_trace + def post( + self, + image_id: int, + body: Optional[Union[JSON, IO[bytes]]] = None, + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Initiate an Image Action. + + The following actions are available on an Image. + + Convert an Image to a Snapshot + ------------------------------ + + To convert an image, for example, a backup to a snapshot, send a POST request + to ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``convert``. + + Transfer an Image + ----------------- + + To transfer an image to another region, send a POST request to + ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``transfer`` and set + ``region`` attribute to the slug identifier of the region you wish to transfer + to. + + :param image_id: A unique number that can be used to identify and reference a specific image. + Required. + :type image_id: int + :param body: Is either a JSON type or a IO[bytes] type. Default value is None. + :type body: JSON or IO[bytes] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = {} + + # response body for status code(s): 201 + response == { + "completed_at": "2020-02-20 00:00:00", # Optional. A time value given in + ISO8601 combined date and time format that represents when the action was + completed. + "id": 0, # Optional. A unique numeric ID that can be used to identify and + reference an action. + "region": { + "available": bool, # This is a boolean value that represents whether + new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which contains + features available in this region. Required. + ], + "name": "str", # The display name of the region. This will be a + full name that is used in the control panel and other interfaces. Required. + "sizes": [ + "str" # This attribute is set to an array which contains the + identifying slugs for the sizes available in this region. sizes:read is + required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a unique + identifier for each region. Required. + }, + "region_slug": "str", # Optional. A human-readable string that is used as a + unique identifier for each region. + "resource_id": 0, # Optional. A unique identifier for the resource that the + action is associated with. + "resource_type": "str", # Optional. The type of resource that the action is + associated with. + "started_at": "2020-02-20 00:00:00", # Optional. A time value given in + ISO8601 combined date and time format that represents when the action was + initiated. + "status": "in-progress", # Optional. Default value is "in-progress". The + current status of the action. This can be "in-progress", "completed", or + "errored". Known values are: "in-progress", "completed", and "errored". + "type": "str" # Optional. This is the type of action that the object + represents. For example, this could be "transfer" to represent the state of an + image transfer action. + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + cls: ClsType[JSON] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(body, (IOBase, bytes)): + _content = body + else: + if body is not None: + _json = body + else: + _json = None + + _request = build_image_actions_post_request( + image_id=image_id, + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [201, 404]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 201: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def get(self, image_id: int, action_id: int, **kwargs: Any) -> JSON: + # pylint: disable=line-too-long + """Retrieve an Existing Action. + + To retrieve the status of an image action, send a GET request to + ``/v2/images/$IMAGE_ID/actions/$IMAGE_ACTION_ID``. + + :param image_id: A unique number that can be used to identify and reference a specific image. + Required. + :type image_id: int + :param action_id: A unique numeric ID that can be used to identify and reference an action. + Required. + :type action_id: int + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "completed_at": "2020-02-20 00:00:00", # Optional. A time value given in + ISO8601 combined date and time format that represents when the action was + completed. + "id": 0, # Optional. A unique numeric ID that can be used to identify and + reference an action. + "region": { + "available": bool, # This is a boolean value that represents whether + new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which contains + features available in this region. Required. + ], + "name": "str", # The display name of the region. This will be a + full name that is used in the control panel and other interfaces. Required. + "sizes": [ + "str" # This attribute is set to an array which contains the + identifying slugs for the sizes available in this region. sizes:read is + required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a unique + identifier for each region. Required. + }, + "region_slug": "str", # Optional. A human-readable string that is used as a + unique identifier for each region. + "resource_id": 0, # Optional. A unique identifier for the resource that the + action is associated with. + "resource_type": "str", # Optional. The type of resource that the action is + associated with. + "started_at": "2020-02-20 00:00:00", # Optional. A time value given in + ISO8601 combined date and time format that represents when the action was + initiated. + "status": "in-progress", # Optional. Default value is "in-progress". The + current status of the action. This can be "in-progress", "completed", or + "errored". Known values are: "in-progress", "completed", and "errored". + "type": "str" # Optional. This is the type of action that the object + represents. For example, this could be "transfer" to represent the state of an + image transfer action. + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_image_actions_get_request( + image_id=image_id, + action_id=action_id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 404]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + +class InsightsOperations: + """ + .. warning:: + **DO NOT** instantiate this class directly. + + Instead, you should access the following operations through + :class:`~pydo.GeneratedClient`'s + :attr:`insights` attribute. + """ + + def __init__(self, *args, **kwargs): + input_args = list(args) + self._client = input_args.pop(0) if input_args else kwargs.pop("client") + self._config = input_args.pop(0) if input_args else kwargs.pop("config") + 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_alert_instances( + self, + *, + per_page: int = 20, + page: int = 1, + status: Optional[str] = None, + rule_id: Optional[str] = None, + resource_urn: Optional[str] = None, + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """List Alert Instances. + + To list alert instances for your account, send a GET request to + ``/v2/insights/alert-instances``. Alert instances are read-only records of + alert rule firings against your resources. + + Results can optionally be filtered by ``status``\\ , ``rule_id``\\ , or + ``resource_urn``. + + Results are ordered by ``triggered_at`` descending (newest first). Because + the list is append-only and continuously growing, offset-based pagination + is best-effort: newly triggered instances may shift older rows onto + subsequent pages between fetches. For stable pagination, filter by + ``rule_id`` or a fixed time window on the client side. + + :keyword per_page: Number of items returned per page. Default value is 20. + :paramtype per_page: int + :keyword page: Which 'page' of paginated results to return. Default value is 1. + :paramtype page: int + :keyword status: Optional filter. When set, only alert instances with this status are + returned. Known values are: "active" and "resolved". Default value is None. + :paramtype status: str + :keyword rule_id: Optional filter. When set, only alert instances fired by the alert rule + with this ID are returned. Default value is None. + :paramtype rule_id: str + :keyword resource_urn: Optional filter. When set, only resources associated with this resource + URN + are returned. Default value is None. + :paramtype resource_urn: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "meta": { + "total": 0 # Optional. Number of objects returned by the request. + }, + "alert_instances": [ + { + "id": "str", # A unique identifier for the alert instance. + Required. + "last_triggered_at": "2020-02-20 00:00:00", # Time the alert + instance most recently fired. Required. + "rule_id": "str", # ID of the alert rule that fired this + alert instance. Required. + "severity": "str", # Severity of the breached threshold. + Required. Known values are: "warning" and "critical". + "status": "str", # Current status of the alert instance. + Required. Known values are: "active" and "resolved". + "triggered_at": "2020-02-20 00:00:00", # Time the alert + instance first fired. Required. + "value": 0.0, # The observed metric value that breached the + threshold. Required. + "last_notified_at": "2020-02-20 00:00:00", # Optional. Time + a notification was last sent for this alert instance. + "resolved_at": "2020-02-20 00:00:00", # Optional. Time the + alert instance resolved. Only present when ``status`` is ``resolved``. + "resource_urn": "str" # Optional. URN of the DigitalOcean + resource the alert fired for. May be an empty string for alerts fired on + non-resource-bound signals (for example, cluster/pod/namespace-scoped + Kubernetes alerts). + } + ], + "links": { + "pages": {} + } + } + # response body for status code(s): 400 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_list_alert_instances_request( + per_page=per_page, + page=page, + status=status, + rule_id=rule_id, + resource_urn=resource_urn, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def get_alert_instance(self, id: str, **kwargs: Any) -> JSON: + # pylint: disable=line-too-long + """Retrieve an Alert Instance. + + To retrieve a single alert instance, send a GET request to + ``/v2/insights/alert-instances/{id}``. + + :param id: A unique identifier for an alert instance. Required. + :type id: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "alert_instance": { + "id": "str", # A unique identifier for the alert instance. Required. + "last_triggered_at": "2020-02-20 00:00:00", # Time the alert + instance most recently fired. Required. + "rule_id": "str", # ID of the alert rule that fired this alert + instance. Required. + "severity": "str", # Severity of the breached threshold. Required. + Known values are: "warning" and "critical". + "status": "str", # Current status of the alert instance. Required. + Known values are: "active" and "resolved". + "triggered_at": "2020-02-20 00:00:00", # Time the alert instance + first fired. Required. + "value": 0.0, # The observed metric value that breached the + threshold. Required. + "last_notified_at": "2020-02-20 00:00:00", # Optional. Time a + notification was last sent for this alert instance. + "resolved_at": "2020-02-20 00:00:00", # Optional. Time the alert + instance resolved. Only present when ``status`` is ``resolved``. + "resource_urn": "str" # Optional. URN of the DigitalOcean resource + the alert fired for. May be an empty string for alerts fired on + non-resource-bound signals (for example, cluster/pod/namespace-scoped + Kubernetes alerts). + } + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_alert_instance_request( + id=id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 404]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def list_alert_rules( + self, + *, + page: int = 1, + per_page: int = 20, + resource_urn: Optional[str] = None, + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """List Alert Rules. + + To list alert rules for your account, send a GET request to + ``/v2/insights/alert-rules``. Results are paginated with ``page`` and ``per_page`` + (default ``20``\\ , maximum ``200``\\ ). Optionally filter by ``resource_urn``. + + :keyword page: Which 'page' of paginated results to return. Default value is 1. + :paramtype page: int + :keyword per_page: Number of items returned per page. Default value is 20. + :paramtype per_page: int + :keyword resource_urn: Optional filter. When set, only resources associated with this resource + URN + are returned. Default value is None. + :paramtype resource_urn: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "alert_rules": [ + { + "created_at": "2020-02-20 00:00:00", # Time the alert rule + was created. Required. + "id": "str", # A unique identifier for the alert rule. + Required. + "spec": { + "name": "str", # A human-readable name for the alert + rule. Required. + "query": { + "metric": "str", # Dotted OpenTelemetry + metric name to evaluate (for example + ``do.droplets.cpu_utilization``"" ). Required. + "filters": [ + { + "field": "str", # The metric + label or field to filter on. Required. + "operator": "str", # + Comparison operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` + = ``greater_than`` * + ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value + compared against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or + omitted means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource + tags used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator + applied to the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``THRESHOLD_OPERATOR_LESS_THAN`` = + ``less_than`` * ``THRESHOLD_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical + threshold value. + "warning": 0.0 # Optional. Warning threshold + value. + }, + "condition": { + "window": "str" # Optional. Time window over + which the metric is evaluated. Allowed values: * + ``EVALUATION_WINDOW_1M`` = ``1m`` * ``EVALUATION_WINDOW_5M`` = + ``5m`` * ``EVALUATION_WINDOW_10M`` = ``10m`` * + ``EVALUATION_WINDOW_15M`` = ``15m`` * ``EVALUATION_WINDOW_30M`` = + ``30m`` * ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # + ID of an existing notification channel owned by the account. + Required. + "notify_on": [ + "str" # Optional. Severities + that trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait + before re-notifying a still-firing alert. Defaults to + ``RE_ALERT_DURATION_4H`` on create when omitted. Allowed values: * + ``RE_ALERT_DURATION_30M`` = ``30m`` * ``RE_ALERT_DURATION_1H`` = + ``1h`` * ``RE_ALERT_DURATION_4H`` = ``4h`` * + ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", + "RE_ALERT_DURATION_4H", and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed + values: * ``ALERT_RULE_STATUS_ACTIVE`` = active * + ``ALERT_RULE_STATUS_PAUSED`` = paused. Required. Known values are: + "ALERT_RULE_STATUS_ACTIVE" and "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule + was last updated. Required. + } + ], + "meta": { + "total": 0 # Optional. Number of objects returned by the request. + }, + "links": { + "pages": {} + } + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_list_alert_rules_request( + page=page, + per_page=per_page, + resource_urn=resource_urn, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @overload + def create_alert_rule( + self, body: JSON, *, content_type: str = "application/json", **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create an Alert Rule. + + To create an alert rule, send a POST request to ``/v2/insights/alert-rules`` + with a ``spec`` containing ``name``\\ , ``query``\\ , ``thresholds``\\ , and at least one + ``notification_channels`` binding. ``status`` defaults to + ``ALERT_RULE_STATUS_ACTIVE`` when omitted. ``re_alert_duration`` defaults to + ``RE_ALERT_DURATION_4H`` when omitted. + + ``query.metric`` must be a dotted OpenTelemetry name such as + ``do.droplets.cpu_utilization``. Underscored Prometheus-style names are + rejected with ``422 Unprocessable Entity``. + + :param body: Required. + :type body: JSON + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "spec": { + "name": "str", # A human-readable name for the alert rule. Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name to + evaluate (for example ``do.droplets.cpu_utilization``"" ). Required. + "filters": [ + { + "field": "str", # The metric label or field + to filter on. Required. + "operator": "str", # Comparison operator for + the filter. Allowed values: * ``FILTER_OPERATOR_EQUAL`` = equal + * ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``FILTER_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared against the + field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of DigitalOcean + resource URNs the rule applies to. Empty or omitted means the rule is + not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags used to + select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to the + aggregated metric value. Allowed values: * ``THRESHOLD_OPERATOR_EQUAL`` + = equal * ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` + * ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = ``greater_than_or_equal`` + * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = ``not_equal``. Required. Known + values are: "THRESHOLD_OPERATOR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which the + metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` = + ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * ``EVALUATION_WINDOW_10M`` = + ``10m`` * ``EVALUATION_WINDOW_15M`` = ``15m`` * ``EVALUATION_WINDOW_30M`` + = ``30m`` * ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", "EVALUATION_WINDOW_10M", + "EVALUATION_WINDOW_15M", "EVALUATION_WINDOW_30M", and + "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that trigger + this channel. Allowed values: * ``SEVERITY_WARNING`` = warning + * ``SEVERITY_CRITICAL`` = critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` on + create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = ``30m`` + * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = ``4h`` * + ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", and + "RE_ALERT_DURATION_NEVER". + }, + "status": "str" # Optional. Desired alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = paused. + Known values are: "ALERT_RULE_STATUS_ACTIVE" and "ALERT_RULE_STATUS_PAUSED". + } + + # response body for status code(s): 201 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + def create_alert_rule( + self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create an Alert Rule. + + To create an alert rule, send a POST request to ``/v2/insights/alert-rules`` + with a ``spec`` containing ``name``\\ , ``query``\\ , ``thresholds``\\ , and at least one + ``notification_channels`` binding. ``status`` defaults to + ``ALERT_RULE_STATUS_ACTIVE`` when omitted. ``re_alert_duration`` defaults to + ``RE_ALERT_DURATION_4H`` when omitted. + + ``query.metric`` must be a dotted OpenTelemetry name such as + ``do.droplets.cpu_utilization``. Underscored Prometheus-style names are + rejected with ``422 Unprocessable Entity``. + + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 201 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @distributed_trace + def create_alert_rule(self, body: Union[JSON, IO[bytes]], **kwargs: Any) -> JSON: + # pylint: disable=line-too-long + """Create an Alert Rule. + + To create an alert rule, send a POST request to ``/v2/insights/alert-rules`` + with a ``spec`` containing ``name``\\ , ``query``\\ , ``thresholds``\\ , and at least one + ``notification_channels`` binding. ``status`` defaults to + ``ALERT_RULE_STATUS_ACTIVE`` when omitted. ``re_alert_duration`` defaults to + ``RE_ALERT_DURATION_4H`` when omitted. + + ``query.metric`` must be a dotted OpenTelemetry name such as + ``do.droplets.cpu_utilization``. Underscored Prometheus-style names are + rejected with ``422 Unprocessable Entity``. + + :param body: Is either a JSON type or a IO[bytes] type. Required. + :type body: JSON or IO[bytes] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "spec": { + "name": "str", # A human-readable name for the alert rule. Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name to + evaluate (for example ``do.droplets.cpu_utilization``"" ). Required. + "filters": [ + { + "field": "str", # The metric label or field + to filter on. Required. + "operator": "str", # Comparison operator for + the filter. Allowed values: * ``FILTER_OPERATOR_EQUAL`` = equal + * ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``FILTER_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared against the + field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of DigitalOcean + resource URNs the rule applies to. Empty or omitted means the rule is + not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags used to + select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to the + aggregated metric value. Allowed values: * ``THRESHOLD_OPERATOR_EQUAL`` + = equal * ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` + * ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = ``greater_than_or_equal`` + * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = ``not_equal``. Required. Known + values are: "THRESHOLD_OPERATOR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which the + metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` = + ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * ``EVALUATION_WINDOW_10M`` = + ``10m`` * ``EVALUATION_WINDOW_15M`` = ``15m`` * ``EVALUATION_WINDOW_30M`` + = ``30m`` * ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", "EVALUATION_WINDOW_10M", + "EVALUATION_WINDOW_15M", "EVALUATION_WINDOW_30M", and + "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that trigger + this channel. Allowed values: * ``SEVERITY_WARNING`` = warning + * ``SEVERITY_CRITICAL`` = critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` on + create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = ``30m`` + * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = ``4h`` * + ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", and + "RE_ALERT_DURATION_NEVER". + }, + "status": "str" # Optional. Desired alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = paused. + Known values are: "ALERT_RULE_STATUS_ACTIVE" and "ALERT_RULE_STATUS_PAUSED". + } + + # response body for status code(s): 201 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + cls: ClsType[JSON] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(body, (IOBase, bytes)): + _content = body + else: + _json = body + + _request = build_insights_create_alert_rule_request( + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [201, 400, 422]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 201: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def get_alert_rule(self, id: str, **kwargs: Any) -> JSON: + # pylint: disable=line-too-long + """Retrieve an Alert Rule. + + To retrieve an alert rule, send a GET request to + ``/v2/insights/alert-rules/{id}``. + + :param id: A unique identifier for an alert rule. Required. + :type id: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_alert_rule_request( + id=id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 404]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @overload + def update_alert_rule( + self, + id: str, + body: JSON, + *, + content_type: str = "application/json", + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Update an Alert Rule. + + This PUT endpoint uses merge semantics. To update an alert rule, send a + request to ``/v2/insights/alert-rules/{id}`` with a full ``spec``. Omit + ``notification_channels`` to keep existing bindings. Omit ``status`` or + ``re_alert_duration`` to keep those existing values. + + :param id: A unique identifier for an alert rule. Required. + :type id: str + :param body: Required. + :type body: JSON + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "spec": { + "name": "str", # A human-readable name for the alert rule. Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name to + evaluate (for example ``do.droplets.cpu_utilization``"" ). Required. + "filters": [ + { + "field": "str", # The metric label or field + to filter on. Required. + "operator": "str", # Comparison operator for + the filter. Allowed values: * ``FILTER_OPERATOR_EQUAL`` = equal + * ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``FILTER_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared against the + field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of DigitalOcean + resource URNs the rule applies to. Empty or omitted means the rule is + not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags used to + select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to the + aggregated metric value. Allowed values: * ``THRESHOLD_OPERATOR_EQUAL`` + = equal * ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` + * ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = ``greater_than_or_equal`` + * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = ``not_equal``. Required. Known + values are: "THRESHOLD_OPERATOR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which the + metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` = + ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * ``EVALUATION_WINDOW_10M`` = + ``10m`` * ``EVALUATION_WINDOW_15M`` = ``15m`` * ``EVALUATION_WINDOW_30M`` + = ``30m`` * ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", "EVALUATION_WINDOW_10M", + "EVALUATION_WINDOW_15M", "EVALUATION_WINDOW_30M", and + "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that trigger + this channel. Allowed values: * ``SEVERITY_WARNING`` = warning + * ``SEVERITY_CRITICAL`` = critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` on + create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = ``30m`` + * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = ``4h`` * + ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", and + "RE_ALERT_DURATION_NEVER". + }, + "status": "str" # Optional. Desired alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = paused. + Known values are: "ALERT_RULE_STATUS_ACTIVE" and "ALERT_RULE_STATUS_PAUSED". + } + + # response body for status code(s): 200 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 404, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + def update_alert_rule( + self, + id: str, + body: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Update an Alert Rule. + + This PUT endpoint uses merge semantics. To update an alert rule, send a + request to ``/v2/insights/alert-rules/{id}`` with a full ``spec``. Omit + ``notification_channels`` to keep existing bindings. Omit ``status`` or + ``re_alert_duration`` to keep those existing values. + + :param id: A unique identifier for an alert rule. Required. + :type id: str + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 404, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @distributed_trace + def update_alert_rule( + self, id: str, body: Union[JSON, IO[bytes]], **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Update an Alert Rule. + + This PUT endpoint uses merge semantics. To update an alert rule, send a + request to ``/v2/insights/alert-rules/{id}`` with a full ``spec``. Omit + ``notification_channels`` to keep existing bindings. Omit ``status`` or + ``re_alert_duration`` to keep those existing values. + + :param id: A unique identifier for an alert rule. Required. + :type id: str + :param body: Is either a JSON type or a IO[bytes] type. Required. + :type body: JSON or IO[bytes] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "spec": { + "name": "str", # A human-readable name for the alert rule. Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name to + evaluate (for example ``do.droplets.cpu_utilization``"" ). Required. + "filters": [ + { + "field": "str", # The metric label or field + to filter on. Required. + "operator": "str", # Comparison operator for + the filter. Allowed values: * ``FILTER_OPERATOR_EQUAL`` = equal + * ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``FILTER_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared against the + field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of DigitalOcean + resource URNs the rule applies to. Empty or omitted means the rule is + not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags used to + select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to the + aggregated metric value. Allowed values: * ``THRESHOLD_OPERATOR_EQUAL`` + = equal * ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` + * ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = ``greater_than_or_equal`` + * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = ``not_equal``. Required. Known + values are: "THRESHOLD_OPERATOR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which the + metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` = + ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * ``EVALUATION_WINDOW_10M`` = + ``10m`` * ``EVALUATION_WINDOW_15M`` = ``15m`` * ``EVALUATION_WINDOW_30M`` + = ``30m`` * ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", "EVALUATION_WINDOW_10M", + "EVALUATION_WINDOW_15M", "EVALUATION_WINDOW_30M", and + "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that trigger + this channel. Allowed values: * ``SEVERITY_WARNING`` = warning + * ``SEVERITY_CRITICAL`` = critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` on + create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = ``30m`` + * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = ``4h`` * + ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", and + "RE_ALERT_DURATION_NEVER". + }, + "status": "str" # Optional. Desired alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = paused. + Known values are: "ALERT_RULE_STATUS_ACTIVE" and "ALERT_RULE_STATUS_PAUSED". + } + + # response body for status code(s): 200 + response == { + "alert_rule": { + "created_at": "2020-02-20 00:00:00", # Time the alert rule was + created. Required. + "id": "str", # A unique identifier for the alert rule. Required. + "spec": { + "name": "str", # A human-readable name for the alert rule. + Required. + "query": { + "metric": "str", # Dotted OpenTelemetry metric name + to evaluate (for example ``do.droplets.cpu_utilization``"" ). + Required. + "filters": [ + { + "field": "str", # The metric label + or field to filter on. Required. + "operator": "str", # Comparison + operator for the filter. Allowed values: * + ``FILTER_OPERATOR_EQUAL`` = equal * + ``FILTER_OPERATOR_NOT_EQUAL`` = ``not_equal`` * + ``FILTER_OPERATOR_LESS_THAN`` = ``less_than`` * + ``FILTER_OPERATOR_LESS_THAN_OR_EQUAL`` = + ``less_than_or_equal`` * ``FILTER_OPERATOR_GREATER_THAN`` = + ``greater_than`` * ``FILTER_OPERATOR_GREATER_THAN_OR_EQUAL`` + = ``greater_than_or_equal``. Required. Known values are: + "FILTER_OPERATOR_EQUAL", "FILTER_OPERATOR_NOT_EQUAL", + "FILTER_OPERATOR_LESS_THAN", + "FILTER_OPERATOR_LESS_THAN_OR_EQUAL", + "FILTER_OPERATOR_GREATER_THAN", and + "FILTER_OPERATOR_GREATER_THAN_OR_EQUAL". + "value": "str" # Value compared + against the field. Required. + } + ], + "resource_urns": [ + "str" # Optional. Optional list of + DigitalOcean resource URNs the rule applies to. Empty or omitted + means the rule is not scoped to specific resources. + ], + "tags": [ + "str" # Optional. Optional resource tags + used to select matching resources. + ] + }, + "thresholds": { + "operator": "str", # Comparison operator applied to + the aggregated metric value. Allowed values: * + ``THRESHOLD_OPERATOR_EQUAL`` = equal * + ``THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL`` = ``less_than_or_equal`` * + ``THRESHOLD_OPERATOR_LESS_THAN`` = ``less_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN`` = ``greater_than`` * + ``THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL`` = + ``greater_than_or_equal`` * ``THRESHOLD_OPERATOR_NOT_EQUAL`` = + ``not_equal``. Required. Known values are: + "THRESHOLD_OPERATOR_EQUAL", "THRESHOLD_OPERATOR_LESS_THAN_OR_EQUAL", + "THRESHOLD_OPERATOR_LESS_THAN", "THRESHOLD_OPERATOR_GREATER_THAN", + "THRESHOLD_OPERATOR_GREATER_THAN_OR_EQUAL", and + "THRESHOLD_OPERATOR_NOT_EQUAL". + "critical": 0.0, # Optional. Critical threshold + value. + "warning": 0.0 # Optional. Warning threshold value. + }, + "condition": { + "window": "str" # Optional. Time window over which + the metric is evaluated. Allowed values: * ``EVALUATION_WINDOW_1M`` + = ``1m`` * ``EVALUATION_WINDOW_5M`` = ``5m`` * + ``EVALUATION_WINDOW_10M`` = ``10m`` * ``EVALUATION_WINDOW_15M`` = + ``15m`` * ``EVALUATION_WINDOW_30M`` = ``30m`` * + ``EVALUATION_WINDOW_1H`` = ``1h``. Known values are: + "EVALUATION_WINDOW_1M", "EVALUATION_WINDOW_5M", + "EVALUATION_WINDOW_10M", "EVALUATION_WINDOW_15M", + "EVALUATION_WINDOW_30M", and "EVALUATION_WINDOW_1H". + }, + "notification_channels": [ + { + "notification_channel_id": "str", # ID of an + existing notification channel owned by the account. Required. + "notify_on": [ + "str" # Optional. Severities that + trigger this channel. Allowed values: * + ``SEVERITY_WARNING`` = warning * ``SEVERITY_CRITICAL`` = + critical. + ] + } + ], + "re_alert_duration": "str" # Optional. Minimum wait before + re-notifying a still-firing alert. Defaults to ``RE_ALERT_DURATION_4H`` + on create when omitted. Allowed values: * ``RE_ALERT_DURATION_30M`` = + ``30m`` * ``RE_ALERT_DURATION_1H`` = ``1h`` * ``RE_ALERT_DURATION_4H`` = + ``4h`` * ``RE_ALERT_DURATION_NEVER`` = never. Known values are: + "RE_ALERT_DURATION_30M", "RE_ALERT_DURATION_1H", "RE_ALERT_DURATION_4H", + and "RE_ALERT_DURATION_NEVER". + }, + "status": "str", # Current alert rule status. Allowed values: * + ``ALERT_RULE_STATUS_ACTIVE`` = active * ``ALERT_RULE_STATUS_PAUSED`` = + paused. Required. Known values are: "ALERT_RULE_STATUS_ACTIVE" and + "ALERT_RULE_STATUS_PAUSED". + "updated_at": "2020-02-20 00:00:00" # Time the alert rule was last + updated. Required. + } + } + # response body for status code(s): 400, 404, 422 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + cls: ClsType[JSON] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(body, (IOBase, bytes)): + _content = body + else: + _json = body + + _request = build_insights_update_alert_rule_request( + id=id, + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 404, 422]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def delete_alert_rule(self, id: str, **kwargs: Any) -> Optional[JSON]: + # pylint: disable=line-too-long + """Delete an Alert Rule. + + To delete an alert rule, send a DELETE request to + ``/v2/insights/alert-rules/{id}``. + + :param id: A unique identifier for an alert rule. Required. + :type id: str + :return: JSON object or None + :rtype: JSON or None + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[Optional[JSON]] = kwargs.pop("cls", None) + + _request = build_insights_delete_alert_rule_request( + id=id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [204, 404]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + deserialized = None + response_headers = {} + if response.status_code == 204: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def list_notification_channels( + self, *, page: int = 1, per_page: int = 20, **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """List Notification Channels. + + To list all notification channels for your account, send a GET request to + ``/v2/insights/notification-channels``. Results are paginated with ``page`` and + ``per_page`` (default ``20``\\ , maximum ``200``\\ ). + + :keyword page: Which 'page' of paginated results to return. Default value is 1. + :paramtype page: int + :keyword per_page: Number of items returned per page. Default value is 20. + :paramtype per_page: int + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "meta": { + "total": 0 # Optional. Number of objects returned by the request. + }, + "notification_channels": [ + { + "channel_type": "str", # The configured channel type. + Allowed values: * ``CHANNEL_TYPE_EMAIL`` = email * + ``CHANNEL_TYPE_SLACK`` = slack * ``CHANNEL_TYPE_WEBHOOK`` = webhook. + Required. Known values are: "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", + and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification + channel was created. Required. + "id": "str", # A unique identifier for the notification + channel. Required. + "name": "str", # A human-readable name for the notification + channel. Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification + channel was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to + notify. Required. + "webhook_url": "str" # Optional. Slack incoming + webhook URL. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. Omit on update to retain the existing + value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules + that reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook + deliveries. Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. + Required. + "password": "str" # Optional. Basic auth + password. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token + value sent in the Authorization header. Write-only secret "u2014 + full value on create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom + HTTP headers to include on webhook deliveries. At most 20 headers + are allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret + used to sign webhook payloads. Write-only secret "u2014 full + value on create/update; masked as ``********`` on read. + } + } + } + ], + "links": { + "pages": {} + } + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_list_notification_channels_request( + page=page, + per_page=per_page, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @overload + def create_notification_channel( + self, body: JSON, *, content_type: str = "application/json", **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create a Notification Channel. + + To create a notification channel, send a POST request to + ``/v2/insights/notification-channels`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Email recipients must be verified team member addresses. Webhook URLs must + use HTTPS. Secret fields (\\ ``slack.webhook_url``\\ , webhook credentials) are + write-only and returned masked on subsequent reads. + + :param body: Required. + :type body: JSON + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "name": "str", # A human-readable name for the notification channel. + Required. + "email": { + "to": "str" # One or more recipient email addresses, separated by + commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as ``********`` + on read. Omit on update to retain the existing value. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. Returned + in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent in the + Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP headers to + include on webhook deliveries. At most 20 headers are allowed. Reserved + header names such as ``host``"" , ``content-type``"" , and ``proxy-*`` + are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to sign + webhook payloads. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. + } + } + } + + # response body for status code(s): 201 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + def create_notification_channel( + self, body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create a Notification Channel. + + To create a notification channel, send a POST request to + ``/v2/insights/notification-channels`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Email recipients must be verified team member addresses. Webhook URLs must + use HTTPS. Secret fields (\\ ``slack.webhook_url``\\ , webhook credentials) are + write-only and returned masked on subsequent reads. + + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 201 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @distributed_trace + def create_notification_channel( + self, body: Union[JSON, IO[bytes]], **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Create a Notification Channel. + + To create a notification channel, send a POST request to + ``/v2/insights/notification-channels`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Email recipients must be verified team member addresses. Webhook URLs must + use HTTPS. Secret fields (\\ ``slack.webhook_url``\\ , webhook credentials) are + write-only and returned masked on subsequent reads. + + :param body: Is either a JSON type or a IO[bytes] type. Required. + :type body: JSON or IO[bytes] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "name": "str", # A human-readable name for the notification channel. + Required. + "email": { + "to": "str" # One or more recipient email addresses, separated by + commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as ``********`` + on read. Omit on update to retain the existing value. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. Returned + in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent in the + Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP headers to + include on webhook deliveries. At most 20 headers are allowed. Reserved + header names such as ``host``"" , ``content-type``"" , and ``proxy-*`` + are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to sign + webhook payloads. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. + } + } + } + + # response body for status code(s): 201 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + cls: ClsType[JSON] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(body, (IOBase, bytes)): + _content = body + else: + _json = body + + _request = build_insights_create_notification_channel_request( + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [201, 400]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 201: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def get_notification_channel(self, id: str, **kwargs: Any) -> JSON: + # pylint: disable=line-too-long + """Retrieve a Notification Channel. + + To retrieve a notification channel, send a GET request to + ``/v2/insights/notification-channels/{id}``. Secret fields are returned masked + as ``********``. + + :param id: A unique identifier for a notification channel. Required. + :type id: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_notification_channel_request( + id=id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 404]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @overload + def update_notification_channel( + self, + id: str, + body: JSON, + *, + content_type: str = "application/json", + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Update a Notification Channel. + + To update a notification channel, send a PUT request to + ``/v2/insights/notification-channels/{id}`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Sending a secret field rotates it; omitting the secret field keeps the + existing value. + + :param id: A unique identifier for a notification channel. Required. + :type id: str + :param body: Required. + :type body: JSON + :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "name": "str", # A human-readable name for the notification channel. + Required. + "email": { + "to": "str" # One or more recipient email addresses, separated by + commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as ``********`` + on read. Omit on update to retain the existing value. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. Returned + in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent in the + Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP headers to + include on webhook deliveries. At most 20 headers are allowed. Reserved + header names such as ``host``"" , ``content-type``"" , and ``proxy-*`` + are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to sign + webhook payloads. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. + } + } + } + + # response body for status code(s): 200 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + def update_notification_channel( + self, + id: str, + body: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Update a Notification Channel. + + To update a notification channel, send a PUT request to + ``/v2/insights/notification-channels/{id}`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Sending a secret field rotates it; omitting the secret field keeps the + existing value. + + :param id: A unique identifier for a notification channel. Required. + :type id: str + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @distributed_trace + def update_notification_channel( + self, id: str, body: Union[JSON, IO[bytes]], **kwargs: Any + ) -> JSON: + # pylint: disable=line-too-long + """Update a Notification Channel. + + To update a notification channel, send a PUT request to + ``/v2/insights/notification-channels/{id}`` with a ``name`` and exactly one of + ``email``\\ , ``slack``\\ , or ``webhook``. + + Sending a secret field rotates it; omitting the secret field keeps the + existing value. + + :param id: A unique identifier for a notification channel. Required. + :type id: str + :param body: Is either a JSON type or a IO[bytes] type. Required. + :type body: JSON or IO[bytes] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # JSON input template you can fill out and use as your body input. + body = { + "name": "str", # A human-readable name for the notification channel. + Required. + "email": { + "to": "str" # One or more recipient email addresses, separated by + commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as ``********`` + on read. Omit on update to retain the existing value. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. Returned + in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent in the + Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP headers to + include on webhook deliveries. At most 20 headers are allowed. Reserved + header names such as ``host``"" , ``content-type``"" , and ``proxy-*`` + are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to sign + webhook payloads. Write-only secret "u2014 full value on create/update; + masked as ``********`` on read. + } + } + } + + # response body for status code(s): 200 + response == { + "notification_channel": { + "channel_type": "str", # The configured channel type. Allowed + values: * ``CHANNEL_TYPE_EMAIL`` = email * ``CHANNEL_TYPE_SLACK`` = slack * + ``CHANNEL_TYPE_WEBHOOK`` = webhook. Required. Known values are: + "CHANNEL_TYPE_EMAIL", "CHANNEL_TYPE_SLACK", and "CHANNEL_TYPE_WEBHOOK". + "created_at": "2020-02-20 00:00:00", # Time the notification channel + was created. Required. + "id": "str", # A unique identifier for the notification channel. + Required. + "name": "str", # A human-readable name for the notification channel. + Required. + "updated_at": "2020-02-20 00:00:00", # Time the notification channel + was last updated. Required. + "email": { + "to": "str" # One or more recipient email addresses, + separated by commas, semicolons, or spaces. Required. + }, + "slack": { + "channel": "str", # The Slack channel name to notify. + Required. + "webhook_url": "str" # Optional. Slack incoming webhook URL. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. Omit on update to retain the existing value. + }, + "usage": { + "rule_count": 0 # Optional. Number of alert rules that + reference this channel. + }, + "webhook": { + "url": "str", # HTTPS URL that receives webhook deliveries. + Returned in full on read. Required. + "basic_auth": { + "username": "str", # Basic auth username. Required. + "password": "str" # Optional. Basic auth password. + Write-only secret "u2014 full value on create/update; masked as + ``********`` on read. + }, + "bearer_token": { + "token": "str" # Optional. Bearer token value sent + in the Authorization header. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + }, + "headers": { + "str": "str" # Optional. Optional custom HTTP + headers to include on webhook deliveries. At most 20 headers are + allowed. Reserved header names such as ``host``"" , + ``content-type``"" , and ``proxy-*`` are rejected. + }, + "signature": { + "secret": "str" # Optional. Shared secret used to + sign webhook payloads. Write-only secret "u2014 full value on + create/update; masked as ``********`` on read. + } + } + } + } + # response body for status code(s): 400, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = case_insensitive_dict(kwargs.pop("headers", {}) or {}) + _params = kwargs.pop("params", {}) or {} + + content_type: Optional[str] = kwargs.pop( + "content_type", _headers.pop("Content-Type", None) + ) + cls: ClsType[JSON] = kwargs.pop("cls", None) + + content_type = content_type or "application/json" + _json = None + _content = None + if isinstance(body, (IOBase, bytes)): + _content = body + else: + _json = body + + _request = build_insights_update_notification_channel_request( + id=id, + content_type=content_type, + json=_json, + content=_content, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 404]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def delete_notification_channel(self, id: str, **kwargs: Any) -> Optional[JSON]: + # pylint: disable=line-too-long + """Delete a Notification Channel. + + To delete a notification channel, send a DELETE request to + ``/v2/insights/notification-channels/{id}``. + + Deleting a channel that is still referenced by one or more alert rules + returns ``409 Conflict``. + + :param id: A unique identifier for a notification channel. Required. + :type id: str + :return: JSON object or None + :rtype: JSON or None + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 404, 409 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + 500: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[Optional[JSON]] = kwargs.pop("cls", None) + + _request = build_insights_delete_notification_channel_request( + id=id, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [204, 404, 409]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + deserialized = None + response_headers = {} + if response.status_code == 204: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 409: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, deserialized, response_headers) # type: ignore + + return deserialized # type: ignore + + @distributed_trace + def get_prom_query( + self, + region: str, + *, + query: str, + time: Optional[str] = None, + timeout: Optional[str] = None, + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Execute an instant PromQL query. + + To evaluate a PromQL expression at a single point in time, send a GET request to + ``/v2/insights/query/{region}/prom/api/v1/query``. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :keyword query: A PromQL expression. This may be a metric selector (for example + ``do.droplets.cpu_time``\\ ) or a fuller expression (for example + ``rate(do.droplets.cpu_time[5m])``\\ ). Required. + :paramtype query: str + :keyword time: Evaluation timestamp for an instant query. Accepts a RFC3339 string or a UNIX + timestamp. Defaults to now when omitted. Default value is None. + :paramtype time: str + :keyword timeout: Optional evaluation timeout as a Prometheus duration string. Default value is + None. + :paramtype timeout: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": { + "result": {}, + "resultType": "str" # Required. Known values are: "vector", + "matrix", "scalar", and "string". + }, + "status": "str" # Required. "success" + } + # response body for status code(s): 400, 422, 500, 503 + response == { + "error": "str", # Human-readable error message. Required. + "errorType": "str", # Prometheus error category. Required. Known values are: + "bad_data", "internal", "timeout", "canceled", "execution", and "unavailable". + "status": "str" # Required. "error" + } + # response body for status code(s): 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_prom_query_request( + region=region, + query=query, + time=time, + timeout=timeout, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404, 422, 500, 503]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 500: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 503: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def get_prom_query_range( + self, + region: str, + *, + query: str, + start: str, + end: str, + step: str, + timeout: Optional[str] = None, + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Execute a range PromQL query. + + To evaluate a PromQL expression over a time range, send a GET request to + ``/v2/insights/query/{region}/prom/api/v1/query_range``. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :keyword query: A PromQL expression. This may be a metric selector (for example + ``do.droplets.cpu_time``\\ ) or a fuller expression (for example + ``rate(do.droplets.cpu_time[5m])``\\ ). Required. + :paramtype query: str + :keyword start: Start timestamp (inclusive). Accepts a RFC3339 string or a UNIX timestamp. + Required. + :paramtype start: str + :keyword end: End timestamp (inclusive). Accepts a RFC3339 string or a UNIX timestamp. + Required. + :paramtype end: str + :keyword step: Query resolution step width as a Prometheus duration string (for example + ``15s``\\ , ``1m``\\ , ``1h``\\ ). Required. + :paramtype step: str + :keyword timeout: Optional evaluation timeout as a Prometheus duration string. Default value is + None. + :paramtype timeout: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": { + "result": [ + { + "metric": { + "str": "str" # Metric labels as key/value + pairs. By default, metric names in responses use Prometheus + underscored spelling (for example ``do_droplets_cpu_time``"" ), + even when the request used a dotted selector (for example + ``do.droplets.cpu_time``"" ). Required. + }, + "values": [ + [ + {} + ] + ] + } + ], + "resultType": "str" # Required. "matrix" + }, + "status": "str" # Required. "success" + } + # response body for status code(s): 400, 422, 500, 503 + response == { + "error": "str", # Human-readable error message. Required. + "errorType": "str", # Prometheus error category. Required. Known values are: + "bad_data", "internal", "timeout", "canceled", "execution", and "unavailable". + "status": "str" # Required. "error" + } + # response body for status code(s): 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_prom_query_range_request( + region=region, + query=query, + start=start, + end=end, + step=step, + timeout=timeout, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404, 422, 500, 503]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 500: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 503: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def get_prom_labels( + self, + region: str, + *, + start: Optional[str] = None, + end: Optional[str] = None, + match: Optional[List[str]] = None, + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """List label names. + + To list label names, send a GET request to ``/v2/insights/query/{region}/prom/api/v1/labels``. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :keyword start: Optional start timestamp (inclusive). Accepts a RFC3339 string or a UNIX + timestamp. Default value is None. + :paramtype start: str + :keyword end: Optional end timestamp (inclusive). Accepts a RFC3339 string or a UNIX timestamp. + Default value is None. + :paramtype end: str + :keyword match: One or more series selectors. Repeat the parameter for multiple matchers. + Default value is None. + :paramtype match: list[str] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": [ + "str" # Required. + ], + "status": "str" # Required. "success" + } + # response body for status code(s): 400, 422, 500, 503 + response == { + "error": "str", # Human-readable error message. Required. + "errorType": "str", # Prometheus error category. Required. Known values are: + "bad_data", "internal", "timeout", "canceled", "execution", and "unavailable". + "status": "str" # Required. "error" + } + # response body for status code(s): 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_prom_labels_request( + region=region, + start=start, + end=end, + match=match, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404, 422, 500, 503]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 500: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 503: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def get_prom_label_values( + self, + region: str, + name: str, + *, + start: Optional[str] = None, + end: Optional[str] = None, + match: Optional[List[str]] = None, + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """List values for a label. + + To list values for a label name, send a GET request to + ``/v2/insights/query/{region}/prom/api/v1/label/{name}/values``. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :param name: The label name whose values should be listed. Required. + :type name: str + :keyword start: Optional start timestamp (inclusive). Accepts a RFC3339 string or a UNIX + timestamp. Default value is None. + :paramtype start: str + :keyword end: Optional end timestamp (inclusive). Accepts a RFC3339 string or a UNIX timestamp. + Default value is None. + :paramtype end: str + :keyword match: One or more series selectors. Repeat the parameter for multiple matchers. + Default value is None. + :paramtype match: list[str] + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": [ + "str" # Required. + ], + "status": "str" # Required. "success" + } + # response body for status code(s): 400, 422, 500, 503 + response == { + "error": "str", # Human-readable error message. Required. + "errorType": "str", # Prometheus error category. Required. Known values are: + "bad_data", "internal", "timeout", "canceled", "execution", and "unavailable". + "status": "str" # Required. "error" + } + # response body for status code(s): 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_prom_label_values_request( + region=region, + name=name, + start=start, + end=end, + match=match, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404, 422, 500, 503]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 500: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 503: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @distributed_trace + def get_prom_series( + self, + region: str, + *, + match: List[str], + start: Optional[str] = None, + end: Optional[str] = None, + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Find series by label selectors. + + To find series matching one or more selectors, send a GET request to + ``/v2/insights/query/{region}/prom/api/v1/series``. + + :param region: The datacenter region slug for the query. Required. + :type region: str + :keyword match: One or more series selectors. At least one matcher is required. Repeat the + parameter for multiple matchers. Required. + :paramtype match: list[str] + :keyword start: Optional start timestamp (inclusive). Accepts a RFC3339 string or a UNIX + timestamp. Default value is None. + :paramtype start: str + :keyword end: Optional end timestamp (inclusive). Accepts a RFC3339 string or a UNIX timestamp. + Default value is None. + :paramtype end: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "data": [ + { + "str": "str" # Required. + } + ], + "status": "str" # Required. "success" + } + # response body for status code(s): 400, 422, 500, 503 + response == { + "error": "str", # Human-readable error message. Required. + "errorType": "str", # Prometheus error category. Required. Known values are: + "bad_data", "internal", "timeout", "canceled", "execution", and "unavailable". + "status": "str" # Required. "error" + } + # response body for status code(s): 403, 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + error_map: MutableMapping[int, Type[HttpResponseError]] = { + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 304: ResourceNotModifiedError, + 401: cast( + Type[HttpResponseError], + lambda response: ClientAuthenticationError(response=response), + ), + 429: HttpResponseError, + } + error_map.update(kwargs.pop("error_map", {}) or {}) + + _headers = kwargs.pop("headers", {}) or {} + _params = kwargs.pop("params", {}) or {} + + cls: ClsType[JSON] = kwargs.pop("cls", None) + + _request = build_insights_get_prom_series_request( + region=region, + match=match, + start=start, + end=end, + headers=_headers, + params=_params, + ) + _request.url = self._client.format_url(_request.url) + + _stream = False + pipeline_response: PipelineResponse = ( + self._client._pipeline.run( # pylint: disable=protected-access + _request, stream=_stream, **kwargs + ) + ) + + response = pipeline_response.http_response + + if response.status_code not in [200, 400, 403, 404, 422, 500, 503]: + if _stream: + response.read() # Load the body in memory and close the socket + map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore + raise HttpResponseError(response=response) + + response_headers = {} + if response.status_code == 200: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 400: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 403: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 404: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 422: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 500: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if response.status_code == 503: + response_headers["ratelimit-limit"] = self._deserialize( + "int", response.headers.get("ratelimit-limit") + ) + response_headers["ratelimit-remaining"] = self._deserialize( + "int", response.headers.get("ratelimit-remaining") + ) + response_headers["ratelimit-reset"] = self._deserialize( + "int", response.headers.get("ratelimit-reset") + ) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore + + return cast(JSON, deserialized) # type: ignore + + @overload + def post_logs_search( self, - image_id: int, - body: Optional[JSON] = None, + region: str, + body: JSON, *, content_type: str = "application/json", **kwargs: Any, ) -> JSON: # pylint: disable=line-too-long - """Initiate an Image Action. - - The following actions are available on an Image. - - Convert an Image to a Snapshot - ------------------------------ - - To convert an image, for example, a backup to a snapshot, send a POST request - to ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``convert``. - - Transfer an Image - ----------------- + """Search logs. - To transfer an image to another region, send a POST request to - ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``transfer`` and set - ``region`` attribute to the slug identifier of the region you wish to transfer - to. + To search log records in a region, send a POST request to + ``/v2/insights/query/{region}/logs/search`` with a JSON body describing the time range, + optional filter, ordering, and pagination. + The time range must not exceed 7 days. ``pagination.limit`` defaults to 100 and is clamped to + 1000. Cursor pagination requires ordering by ``timestamp`` alone; other sort orders return + ``has_more: false`` and cannot be paged. - :param image_id: A unique number that can be used to identify and reference a specific image. - Required. - :type image_id: int - :param body: Default value is None. + :param region: The datacenter region slug for the query. Required. + :type region: str + :param body: Required. :type body: JSON :keyword content_type: Body Parameter content-type. Content type parameter for JSON body. Default value is "application/json". @@ -178167,49 +184057,146 @@ def post( .. code-block:: python # JSON input template you can fill out and use as your body input. - body = {} + body = { + "time_range": { + "from": { + "absolute": "2020-02-20 00:00:00", # Optional. An absolute + timestamp. Accepts RFC3339/RFC3339Nano strings or Unix + seconds/nanoseconds as decimal strings. + "relative": "str", # Optional. A relative time. Use ``now`` + for the current time, a bare duration such as ``1h`` or ``7d`` to look + back from now, or an offset such as ``now-1h`` or ``now+30m``. Supported + units are ``s``"" , ``m``"" , ``h``"" , ``d``"" , and ``w``. + "unix_nano": "str" # Optional. A Unix nanosecond timestamp, + encoded as a string to preserve 64-bit precision. + }, + "to": { + "absolute": "2020-02-20 00:00:00", # Optional. An absolute + timestamp. Accepts RFC3339/RFC3339Nano strings or Unix + seconds/nanoseconds as decimal strings. + "relative": "str", # Optional. A relative time. Use ``now`` + for the current time, a bare duration such as ``1h`` or ``7d`` to look + back from now, or an offset such as ``now-1h`` or ``now+30m``. Supported + units are ``s``"" , ``m``"" , ``h``"" , ``d``"" , and ``w``. + "unix_nano": "str" # Optional. A Unix nanosecond timestamp, + encoded as a string to preserve 64-bit precision. + } + }, + "filter": { + "and": { + "expressions": [ + ... + ] + }, + "condition": { + "field": { + "name": "str", # The field name. Intrinsic columns + include ``timestamp``"" , ``severity_text``"" , ``severity_number``"" + , ``body``"" , ``trace_id``"" , ``span_id``"" , and ``trace_flags``. + The dotted shorthands ``service.name``"" , ``resource.type``"" , and + ``resource.urn`` are also supported. Arbitrary resource or log + attributes can be accessed with ``ResourceAttributes['key']`` or + ``LogAttributes['key']``. Required. + "scope": "str" # Optional. The attribute scope to + resolve the field against. Omit to let the server apply its default + mapping for the field name. Known values are: "FIELD_SCOPE_RESOURCE" + and "FIELD_SCOPE_ATTRIBUTES". + }, + "operator": "str", # The comparison operator. Required. + Known values are: "FILTER_OPERATOR_EQ", "FILTER_OPERATOR_NEQ", + "FILTER_OPERATOR_IN", "FILTER_OPERATOR_EXISTS", "FILTER_OPERATOR_GTE", + and "FILTER_OPERATOR_LTE". + "value": { + "bool_value": bool, # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + "number_array_value": { + "values": [ + 0.0 # Required. + ] + }, + "number_value": 0.0, # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + "string_array_value": { + "values": [ + "str" # Required. + ] + }, + "string_value": "str" # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + } + }, + "not": ..., + "or": { + "expressions": [ + ... + ] + }, + "text_search": { + "query": "str" # The search string. Required. + } + }, + "order_by": [ + { + "field": { + "name": "str", # The field name. Intrinsic columns + include ``timestamp``"" , ``severity_text``"" , ``severity_number``"" + , ``body``"" , ``trace_id``"" , ``span_id``"" , and ``trace_flags``. + The dotted shorthands ``service.name``"" , ``resource.type``"" , and + ``resource.urn`` are also supported. Arbitrary resource or log + attributes can be accessed with ``ResourceAttributes['key']`` or + ``LogAttributes['key']``. Required. + "scope": "str" # Optional. The attribute scope to + resolve the field against. Omit to let the server apply its default + mapping for the field name. Known values are: "FIELD_SCOPE_RESOURCE" + and "FIELD_SCOPE_ATTRIBUTES". + }, + "direction": "str" # Optional. The sort direction. Omit to + use the server default. Known values are: "SORT_DIRECTION_ASC" and + "SORT_DIRECTION_DESC". + } + ], + "pagination": { + "cursor": "str", # Optional. Opaque cursor from a previous response. + "limit": 100 # Optional. Default value is 100. Maximum number of + results to return. Defaults to 100 and is clamped to 1000. + } + } - # response body for status code(s): 201 + # response body for status code(s): 200 response == { - "completed_at": "2020-02-20 00:00:00", # Optional. A time value given in - ISO8601 combined date and time format that represents when the action was - completed. - "id": 0, # Optional. A unique numeric ID that can be used to identify and - reference an action. - "region": { - "available": bool, # This is a boolean value that represents whether - new Droplets can be created in this region. Required. - "features": [ - "str" # This attribute is set to an array which contains - features available in this region. Required. - ], - "name": "str", # The display name of the region. This will be a - full name that is used in the control panel and other interfaces. Required. - "sizes": [ - "str" # This attribute is set to an array which contains the - identifying slugs for the sizes available in this region. sizes:read is - required to view. Required. - ], - "slug": "str" # A human-readable string that is used as a unique - identifier for each region. Required. - }, - "region_slug": "str", # Optional. A human-readable string that is used as a - unique identifier for each region. - "resource_id": 0, # Optional. A unique identifier for the resource that the - action is associated with. - "resource_type": "str", # Optional. The type of resource that the action is - associated with. - "started_at": "2020-02-20 00:00:00", # Optional. A time value given in - ISO8601 combined date and time format that represents when the action was - initiated. - "status": "in-progress", # Optional. Default value is "in-progress". The - current status of the action. This can be "in-progress", "completed", or - "errored". Known values are: "in-progress", "completed", and "errored". - "type": "str" # Optional. This is the type of action that the object - represents. For example, this could be "transfer" to represent the state of an - image transfer action. + "data": [ + { + "timestamp": "2020-02-20 00:00:00", # The log record + timestamp. Required. + "attributes": { + "str": "str" # Optional. Log attributes. + }, + "body": "str", # Optional. The log message body. Omitted + when empty. + "resource": { + "str": "str" # Optional. Resource attributes + associated with the log. + }, + "service_name": "str", # Optional. The service name that + emitted the log. + "severity_number": 0, # Optional. The numeric severity + level. + "severity_text": "str", # Optional. The textual severity + level. + "span_id": "str", # Optional. The span ID if present. + "trace_id": "str" # Optional. The trace ID if present. + } + ], + "pagination": { + "has_more": bool, # Optional. Whether more results are available. + "next_cursor": "str" # Optional. Opaque cursor to fetch the next + page. + } } - # response body for status code(s): 404 + # response body for status code(s): 400, 403, 404 response == { "id": "str", # A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would @@ -178223,37 +184210,27 @@ def post( """ @overload - def post( + def post_logs_search( self, - image_id: int, - body: Optional[IO[bytes]] = None, + region: str, + body: IO[bytes], *, content_type: str = "application/json", **kwargs: Any, ) -> JSON: # pylint: disable=line-too-long - """Initiate an Image Action. + """Search logs. - The following actions are available on an Image. - - Convert an Image to a Snapshot - ------------------------------ - - To convert an image, for example, a backup to a snapshot, send a POST request - to ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``convert``. - - Transfer an Image - ----------------- - - To transfer an image to another region, send a POST request to - ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``transfer`` and set - ``region`` attribute to the slug identifier of the region you wish to transfer - to. + To search log records in a region, send a POST request to + ``/v2/insights/query/{region}/logs/search`` with a JSON body describing the time range, + optional filter, ordering, and pagination. + The time range must not exceed 7 days. ``pagination.limit`` defaults to 100 and is clamped to + 1000. Cursor pagination requires ordering by ``timestamp`` alone; other sort orders return + ``has_more: false`` and cannot be paged. - :param image_id: A unique number that can be used to identify and reference a specific image. - Required. - :type image_id: int - :param body: Default value is None. + :param region: The datacenter region slug for the query. Required. + :type region: str + :param body: Required. :type body: IO[bytes] :keyword content_type: Body Parameter content-type. Content type parameter for binary body. Default value is "application/json". @@ -178265,47 +184242,38 @@ def post( Example: .. code-block:: python - # response body for status code(s): 201 + # response body for status code(s): 200 response == { - "completed_at": "2020-02-20 00:00:00", # Optional. A time value given in - ISO8601 combined date and time format that represents when the action was - completed. - "id": 0, # Optional. A unique numeric ID that can be used to identify and - reference an action. - "region": { - "available": bool, # This is a boolean value that represents whether - new Droplets can be created in this region. Required. - "features": [ - "str" # This attribute is set to an array which contains - features available in this region. Required. - ], - "name": "str", # The display name of the region. This will be a - full name that is used in the control panel and other interfaces. Required. - "sizes": [ - "str" # This attribute is set to an array which contains the - identifying slugs for the sizes available in this region. sizes:read is - required to view. Required. - ], - "slug": "str" # A human-readable string that is used as a unique - identifier for each region. Required. - }, - "region_slug": "str", # Optional. A human-readable string that is used as a - unique identifier for each region. - "resource_id": 0, # Optional. A unique identifier for the resource that the - action is associated with. - "resource_type": "str", # Optional. The type of resource that the action is - associated with. - "started_at": "2020-02-20 00:00:00", # Optional. A time value given in - ISO8601 combined date and time format that represents when the action was - initiated. - "status": "in-progress", # Optional. Default value is "in-progress". The - current status of the action. This can be "in-progress", "completed", or - "errored". Known values are: "in-progress", "completed", and "errored". - "type": "str" # Optional. This is the type of action that the object - represents. For example, this could be "transfer" to represent the state of an - image transfer action. + "data": [ + { + "timestamp": "2020-02-20 00:00:00", # The log record + timestamp. Required. + "attributes": { + "str": "str" # Optional. Log attributes. + }, + "body": "str", # Optional. The log message body. Omitted + when empty. + "resource": { + "str": "str" # Optional. Resource attributes + associated with the log. + }, + "service_name": "str", # Optional. The service name that + emitted the log. + "severity_number": 0, # Optional. The numeric severity + level. + "severity_text": "str", # Optional. The textual severity + level. + "span_id": "str", # Optional. The span ID if present. + "trace_id": "str" # Optional. The trace ID if present. + } + ], + "pagination": { + "has_more": bool, # Optional. Whether more results are available. + "next_cursor": "str" # Optional. Opaque cursor to fetch the next + page. + } } - # response body for status code(s): 404 + # response body for status code(s): 400, 403, 404 response == { "id": "str", # A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would @@ -178319,35 +184287,22 @@ def post( """ @distributed_trace - def post( - self, - image_id: int, - body: Optional[Union[JSON, IO[bytes]]] = None, - **kwargs: Any, + def post_logs_search( + self, region: str, body: Union[JSON, IO[bytes]], **kwargs: Any ) -> JSON: # pylint: disable=line-too-long - """Initiate an Image Action. + """Search logs. - The following actions are available on an Image. + To search log records in a region, send a POST request to + ``/v2/insights/query/{region}/logs/search`` with a JSON body describing the time range, + optional filter, ordering, and pagination. + The time range must not exceed 7 days. ``pagination.limit`` defaults to 100 and is clamped to + 1000. Cursor pagination requires ordering by ``timestamp`` alone; other sort orders return + ``has_more: false`` and cannot be paged. - Convert an Image to a Snapshot - ------------------------------ - - To convert an image, for example, a backup to a snapshot, send a POST request - to ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``convert``. - - Transfer an Image - ----------------- - - To transfer an image to another region, send a POST request to - ``/v2/images/$IMAGE_ID/actions``. Set the ``type`` attribute to ``transfer`` and set - ``region`` attribute to the slug identifier of the region you wish to transfer - to. - - :param image_id: A unique number that can be used to identify and reference a specific image. - Required. - :type image_id: int - :param body: Is either a JSON type or a IO[bytes] type. Default value is None. + :param region: The datacenter region slug for the query. Required. + :type region: str + :param body: Is either a JSON type or a IO[bytes] type. Required. :type body: JSON or IO[bytes] :return: JSON object :rtype: JSON @@ -178357,49 +184312,146 @@ def post( .. code-block:: python # JSON input template you can fill out and use as your body input. - body = {} + body = { + "time_range": { + "from": { + "absolute": "2020-02-20 00:00:00", # Optional. An absolute + timestamp. Accepts RFC3339/RFC3339Nano strings or Unix + seconds/nanoseconds as decimal strings. + "relative": "str", # Optional. A relative time. Use ``now`` + for the current time, a bare duration such as ``1h`` or ``7d`` to look + back from now, or an offset such as ``now-1h`` or ``now+30m``. Supported + units are ``s``"" , ``m``"" , ``h``"" , ``d``"" , and ``w``. + "unix_nano": "str" # Optional. A Unix nanosecond timestamp, + encoded as a string to preserve 64-bit precision. + }, + "to": { + "absolute": "2020-02-20 00:00:00", # Optional. An absolute + timestamp. Accepts RFC3339/RFC3339Nano strings or Unix + seconds/nanoseconds as decimal strings. + "relative": "str", # Optional. A relative time. Use ``now`` + for the current time, a bare duration such as ``1h`` or ``7d`` to look + back from now, or an offset such as ``now-1h`` or ``now+30m``. Supported + units are ``s``"" , ``m``"" , ``h``"" , ``d``"" , and ``w``. + "unix_nano": "str" # Optional. A Unix nanosecond timestamp, + encoded as a string to preserve 64-bit precision. + } + }, + "filter": { + "and": { + "expressions": [ + ... + ] + }, + "condition": { + "field": { + "name": "str", # The field name. Intrinsic columns + include ``timestamp``"" , ``severity_text``"" , ``severity_number``"" + , ``body``"" , ``trace_id``"" , ``span_id``"" , and ``trace_flags``. + The dotted shorthands ``service.name``"" , ``resource.type``"" , and + ``resource.urn`` are also supported. Arbitrary resource or log + attributes can be accessed with ``ResourceAttributes['key']`` or + ``LogAttributes['key']``. Required. + "scope": "str" # Optional. The attribute scope to + resolve the field against. Omit to let the server apply its default + mapping for the field name. Known values are: "FIELD_SCOPE_RESOURCE" + and "FIELD_SCOPE_ATTRIBUTES". + }, + "operator": "str", # The comparison operator. Required. + Known values are: "FILTER_OPERATOR_EQ", "FILTER_OPERATOR_NEQ", + "FILTER_OPERATOR_IN", "FILTER_OPERATOR_EXISTS", "FILTER_OPERATOR_GTE", + and "FILTER_OPERATOR_LTE". + "value": { + "bool_value": bool, # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + "number_array_value": { + "values": [ + 0.0 # Required. + ] + }, + "number_value": 0.0, # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + "string_array_value": { + "values": [ + "str" # Required. + ] + }, + "string_value": "str" # Optional. A typed literal or + list value for a filter condition. Exactly one kind is set per + message. + } + }, + "not": ..., + "or": { + "expressions": [ + ... + ] + }, + "text_search": { + "query": "str" # The search string. Required. + } + }, + "order_by": [ + { + "field": { + "name": "str", # The field name. Intrinsic columns + include ``timestamp``"" , ``severity_text``"" , ``severity_number``"" + , ``body``"" , ``trace_id``"" , ``span_id``"" , and ``trace_flags``. + The dotted shorthands ``service.name``"" , ``resource.type``"" , and + ``resource.urn`` are also supported. Arbitrary resource or log + attributes can be accessed with ``ResourceAttributes['key']`` or + ``LogAttributes['key']``. Required. + "scope": "str" # Optional. The attribute scope to + resolve the field against. Omit to let the server apply its default + mapping for the field name. Known values are: "FIELD_SCOPE_RESOURCE" + and "FIELD_SCOPE_ATTRIBUTES". + }, + "direction": "str" # Optional. The sort direction. Omit to + use the server default. Known values are: "SORT_DIRECTION_ASC" and + "SORT_DIRECTION_DESC". + } + ], + "pagination": { + "cursor": "str", # Optional. Opaque cursor from a previous response. + "limit": 100 # Optional. Default value is 100. Maximum number of + results to return. Defaults to 100 and is clamped to 1000. + } + } - # response body for status code(s): 201 + # response body for status code(s): 200 response == { - "completed_at": "2020-02-20 00:00:00", # Optional. A time value given in - ISO8601 combined date and time format that represents when the action was - completed. - "id": 0, # Optional. A unique numeric ID that can be used to identify and - reference an action. - "region": { - "available": bool, # This is a boolean value that represents whether - new Droplets can be created in this region. Required. - "features": [ - "str" # This attribute is set to an array which contains - features available in this region. Required. - ], - "name": "str", # The display name of the region. This will be a - full name that is used in the control panel and other interfaces. Required. - "sizes": [ - "str" # This attribute is set to an array which contains the - identifying slugs for the sizes available in this region. sizes:read is - required to view. Required. - ], - "slug": "str" # A human-readable string that is used as a unique - identifier for each region. Required. - }, - "region_slug": "str", # Optional. A human-readable string that is used as a - unique identifier for each region. - "resource_id": 0, # Optional. A unique identifier for the resource that the - action is associated with. - "resource_type": "str", # Optional. The type of resource that the action is - associated with. - "started_at": "2020-02-20 00:00:00", # Optional. A time value given in - ISO8601 combined date and time format that represents when the action was - initiated. - "status": "in-progress", # Optional. Default value is "in-progress". The - current status of the action. This can be "in-progress", "completed", or - "errored". Known values are: "in-progress", "completed", and "errored". - "type": "str" # Optional. This is the type of action that the object - represents. For example, this could be "transfer" to represent the state of an - image transfer action. + "data": [ + { + "timestamp": "2020-02-20 00:00:00", # The log record + timestamp. Required. + "attributes": { + "str": "str" # Optional. Log attributes. + }, + "body": "str", # Optional. The log message body. Omitted + when empty. + "resource": { + "str": "str" # Optional. Resource attributes + associated with the log. + }, + "service_name": "str", # Optional. The service name that + emitted the log. + "severity_number": 0, # Optional. The numeric severity + level. + "severity_text": "str", # Optional. The textual severity + level. + "span_id": "str", # Optional. The span ID if present. + "trace_id": "str" # Optional. The trace ID if present. + } + ], + "pagination": { + "has_more": bool, # Optional. Whether more results are available. + "next_cursor": "str" # Optional. Opaque cursor to fetch the next + page. + } } - # response body for status code(s): 404 + # response body for status code(s): 400, 403, 404 response == { "id": "str", # A short identifier corresponding to the HTTP status code returned. For example, the ID for a response returning a 404 status code would @@ -178438,13 +184490,10 @@ def post( if isinstance(body, (IOBase, bytes)): _content = body else: - if body is not None: - _json = body - else: - _json = None + _json = body - _request = build_image_actions_post_request( - image_id=image_id, + _request = build_insights_post_logs_search_request( + region=region, content_type=content_type, json=_json, content=_content, @@ -178462,14 +184511,14 @@ def post( response = pipeline_response.http_response - if response.status_code not in [201, 404]: + if response.status_code not in [200, 400, 403, 404]: if _stream: response.read() # Load the body in memory and close the socket map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore raise HttpResponseError(response=response) response_headers = {} - if response.status_code == 201: + if response.status_code == 200: response_headers["ratelimit-limit"] = self._deserialize( "int", response.headers.get("ratelimit-limit") ) @@ -178485,7 +184534,7 @@ def post( else: deserialized = None - if response.status_code == 404: + if response.status_code == 400: response_headers["ratelimit-limit"] = self._deserialize( "int", response.headers.get("ratelimit-limit") ) @@ -178501,127 +184550,7 @@ def post( else: deserialized = None - if cls: - return cls(pipeline_response, cast(JSON, deserialized), response_headers) # type: ignore - - return cast(JSON, deserialized) # type: ignore - - @distributed_trace - def get(self, image_id: int, action_id: int, **kwargs: Any) -> JSON: - # pylint: disable=line-too-long - """Retrieve an Existing Action. - - To retrieve the status of an image action, send a GET request to - ``/v2/images/$IMAGE_ID/actions/$IMAGE_ACTION_ID``. - - :param image_id: A unique number that can be used to identify and reference a specific image. - Required. - :type image_id: int - :param action_id: A unique numeric ID that can be used to identify and reference an action. - Required. - :type action_id: int - :return: JSON object - :rtype: JSON - :raises ~azure.core.exceptions.HttpResponseError: - - Example: - .. code-block:: python - - # response body for status code(s): 200 - response == { - "completed_at": "2020-02-20 00:00:00", # Optional. A time value given in - ISO8601 combined date and time format that represents when the action was - completed. - "id": 0, # Optional. A unique numeric ID that can be used to identify and - reference an action. - "region": { - "available": bool, # This is a boolean value that represents whether - new Droplets can be created in this region. Required. - "features": [ - "str" # This attribute is set to an array which contains - features available in this region. Required. - ], - "name": "str", # The display name of the region. This will be a - full name that is used in the control panel and other interfaces. Required. - "sizes": [ - "str" # This attribute is set to an array which contains the - identifying slugs for the sizes available in this region. sizes:read is - required to view. Required. - ], - "slug": "str" # A human-readable string that is used as a unique - identifier for each region. Required. - }, - "region_slug": "str", # Optional. A human-readable string that is used as a - unique identifier for each region. - "resource_id": 0, # Optional. A unique identifier for the resource that the - action is associated with. - "resource_type": "str", # Optional. The type of resource that the action is - associated with. - "started_at": "2020-02-20 00:00:00", # Optional. A time value given in - ISO8601 combined date and time format that represents when the action was - initiated. - "status": "in-progress", # Optional. Default value is "in-progress". The - current status of the action. This can be "in-progress", "completed", or - "errored". Known values are: "in-progress", "completed", and "errored". - "type": "str" # Optional. This is the type of action that the object - represents. For example, this could be "transfer" to represent the state of an - image transfer action. - } - # response body for status code(s): 404 - response == { - "id": "str", # A short identifier corresponding to the HTTP status code - returned. For example, the ID for a response returning a 404 status code would - be "not_found.". Required. - "message": "str", # A message providing additional information about the - error, including details to help resolve it when possible. Required. - "request_id": "str" # Optional. Optionally, some endpoints may include a - request ID that should be provided when reporting bugs or opening support - tickets to help identify the issue. - } - """ - error_map: MutableMapping[int, Type[HttpResponseError]] = { - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 304: ResourceNotModifiedError, - 401: cast( - Type[HttpResponseError], - lambda response: ClientAuthenticationError(response=response), - ), - 429: HttpResponseError, - 500: HttpResponseError, - } - error_map.update(kwargs.pop("error_map", {}) or {}) - - _headers = kwargs.pop("headers", {}) or {} - _params = kwargs.pop("params", {}) or {} - - cls: ClsType[JSON] = kwargs.pop("cls", None) - - _request = build_image_actions_get_request( - image_id=image_id, - action_id=action_id, - headers=_headers, - params=_params, - ) - _request.url = self._client.format_url(_request.url) - - _stream = False - pipeline_response: PipelineResponse = ( - self._client._pipeline.run( # pylint: disable=protected-access - _request, stream=_stream, **kwargs - ) - ) - - response = pipeline_response.http_response - - if response.status_code not in [200, 404]: - if _stream: - response.read() # Load the body in memory and close the socket - map_error(status_code=response.status_code, response=response, error_map=error_map) # type: ignore - raise HttpResponseError(response=response) - - response_headers = {} - if response.status_code == 200: + if response.status_code == 403: response_headers["ratelimit-limit"] = self._deserialize( "int", response.headers.get("ratelimit-limit") ) @@ -186732,14 +192661,7 @@ def create( .. code-block:: python # JSON input template you can fill out and use as your body input. - body = { - "ip": "str" # Optional. An optional IP address to assign to the load - balancer from one of your Bring Your Own IP (BYOIP) prefixes. The address must be - an unassigned BYOIP address on your account in the same region as the load - balancer. If omitted, DigitalOcean assigns a public IP address automatically. - This field is only applied when creating the load balancer, cannot be changed - afterward, and is not supported for ``GLOBAL`` or ``INTERNAL`` load balancers. - } + body = {} # response body for status code(s): 202 response == { @@ -186796,6 +192718,10 @@ def create( Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -186884,6 +192810,24 @@ def create( "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -187025,6 +192969,10 @@ def create( Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -187113,6 +193061,24 @@ def create( "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -187195,14 +193161,7 @@ def create(self, body: Union[JSON, IO[bytes]], **kwargs: Any) -> JSON: .. code-block:: python # JSON input template you can fill out and use as your body input. - body = { - "ip": "str" # Optional. An optional IP address to assign to the load - balancer from one of your Bring Your Own IP (BYOIP) prefixes. The address must be - an unassigned BYOIP address on your account in the same region as the load - balancer. If omitted, DigitalOcean assigns a public IP address automatically. - This field is only applied when creating the load balancer, cannot be changed - afterward, and is not supported for ``GLOBAL`` or ``INTERNAL`` load balancers. - } + body = {} # response body for status code(s): 202 response == { @@ -187259,6 +193218,10 @@ def create(self, body: Union[JSON, IO[bytes]], **kwargs: Any) -> JSON: Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -187347,6 +193310,24 @@ def create(self, body: Union[JSON, IO[bytes]], **kwargs: Any) -> JSON: "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -187558,6 +193539,10 @@ def list(self, *, per_page: int = 20, page: int = 1, **kwargs: Any) -> JSON: with a Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the + Droplets assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -187650,6 +193635,25 @@ def list(self, *, per_page: int = 20, page: int = 1, **kwargs: Any) -> JSON: "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that + represents whether new Droplets can be created in this region. + Required. + "features": [ + "str" # This attribute is set to an array + which contains features available in this region. Required. + ], + "name": "str", # The display name of the region. + This will be a full name that is used in the control panel and other + interfaces. Required. + "sizes": [ + "str" # This attribute is set to an array + which contains the identifying slugs for the sizes available in + this region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used + as a unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now @@ -187840,6 +193844,10 @@ def get(self, lb_id: str, **kwargs: Any) -> JSON: Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -187928,6 +193936,24 @@ def get(self, lb_id: str, **kwargs: Any) -> JSON: "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -188160,6 +194186,272 @@ def update( Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], + "enable_backend_keepalive": False, # Optional. Default value is + False. A boolean value indicating whether HTTP keepalive connections are + maintained to target Droplets. + "enable_proxy_protocol": False, # Optional. Default value is False. + A boolean value indicating whether PROXY Protocol is in use. + "firewall": { + "allow": [ + "str" # Optional. the rules for allowing traffic to + the load balancer (in the form 'ip:1.2.3.4' or 'cidr:1.2.0.0/16'). + ], + "deny": [ + "str" # Optional. the rules for denying traffic to + the load balancer (in the form 'ip:1.2.3.4' or 'cidr:1.2.0.0/16'). + ] + }, + "glb_settings": { + "cdn": { + "is_enabled": bool # Optional. A boolean flag to + enable CDN caching. + }, + "failover_threshold": 0, # Optional. An integer value as a + percentage to indicate failure threshold to decide how the regional + priorities will take effect. A value of ``50`` would indicate that the + Global load balancer will choose a lower priority region to forward + traffic to once this failure threshold has been reached for the higher + priority region. + "region_priorities": { + "str": 0 # Optional. A map of region string to an + integer priority value indicating preference for which regional + target a Global load balancer will forward traffic to. A lower value + indicates a higher priority. + }, + "target_port": 0, # Optional. An integer representing the + port on the target backends which the load balancer will forward traffic + to. + "target_protocol": "str" # Optional. The protocol used for + forwarding traffic from the load balancer to the target backends. The + possible values are ``http``"" , ``https`` and ``http2``. Known values + are: "http", "https", and "http2". + }, + "health_check": { + "check_interval_seconds": 10, # Optional. Default value is + 10. The number of seconds between between two consecutive health checks. + "healthy_threshold": 3, # Optional. Default value is 3. The + number of times a health check must pass for a backend Droplet to be + marked "healthy" and be re-added to the pool. + "path": "/", # Optional. Default value is "/". The path on + the backend Droplets to which the load balancer instance will send a + request. + "port": 80, # Optional. Default value is 80. An integer + representing the port on the backend Droplets on which the health check + will attempt a connection. + "protocol": "http", # Optional. Default value is "http". The + protocol used for health checks sent to the backend Droplets. The + possible values are ``http``"" , ``https``"" , or ``tcp``. Known values + are: "http", "https", and "tcp". + "response_timeout_seconds": 5, # Optional. Default value is + 5. The number of seconds the load balancer instance will wait for a + response until marking a health check as failed. + "unhealthy_threshold": 5 # Optional. Default value is 5. The + number of times a health check must fail for a backend Droplet to be + marked "unhealthy" and be removed from the pool. + }, + "http_idle_timeout_seconds": 60, # Optional. Default value is 60. An + integer value which configures the idle timeout for HTTP requests to the + target droplets. + "id": "str", # Optional. A unique ID that can be used to identify + and reference a load balancer. + "ipv6": "str", # Optional. An attribute containing the public-facing + IPv6 address of the load balancer. + "name": "str", # Optional. A human-readable name for a load balancer + instance. + "network": "EXTERNAL", # Optional. Default value is "EXTERNAL". A + string indicating whether the load balancer should be external or internal. + Internal load balancers have no public IPs and are only accessible to + resources on the same VPC network. This property cannot be updated after + creating the load balancer. Known values are: "EXTERNAL" and "INTERNAL". + "network_stack": "IPV4", # Optional. Default value is "IPV4". A + string indicating whether the load balancer will support IPv4 or both IPv4 + and IPv6 networking. This property cannot be updated after creating the load + balancer. Known values are: "IPV4" and "DUALSTACK". + "project_id": "str", # Optional. The ID of the project that the load + balancer is associated with. If no ID is provided at creation, the load + balancer associates with the user's default project. If an invalid project ID + is provided, the load balancer will not be created. + "redirect_http_to_https": False, # Optional. Default value is False. + A boolean value indicating whether HTTP requests to the load balancer on port + 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, + "size": "lb-small", # Optional. Default value is "lb-small". This + field has been replaced by the ``size_unit`` field for all regions except in + AMS2, NYC2, and SFO1. Each available load balancer size now equates to the + load balancer having a set number of nodes. * ``lb-small`` = 1 node * + ``lb-medium`` = 3 nodes * ``lb-large`` = 6 nodes You can resize load + balancers after creation up to once per hour. You cannot resize a load + balancer within the first hour of its creation. Known values are: "lb-small", + "lb-medium", and "lb-large". + "size_unit": 1, # Optional. Default value is 1. How many nodes the + load balancer contains. Each additional node increases the load balancer's + ability to manage more connections. Load balancers can be scaled up or down, + and you can change the number of nodes after creation up to once per hour. + This field is currently not available in the AMS2, NYC2, or SFO1 regions. Use + the ``size`` field to scale load balancers that reside in these regions. + "status": "str", # Optional. A status string indicating the current + state of the load balancer. This can be ``new``"" , ``active``"" , or + ``errored``. Known values are: "new", "active", and "errored". + "sticky_sessions": { + "cookie_name": "str", # Optional. The name of the cookie + sent to the client. This attribute is only returned when using + ``cookies`` for the sticky sessions type. + "cookie_ttl_seconds": 0, # Optional. The number of seconds + until the cookie set by the load balancer expires. This attribute is only + returned when using ``cookies`` for the sticky sessions type. + "type": "none" # Optional. Default value is "none". An + attribute indicating how and if requests from a client will be + persistently served by the same backend Droplet. The possible values are + ``cookies`` or ``none``. Known values are: "cookies" and "none". + }, + "subnet_uuid": "str", # Optional. A string specifying the UUID of + the VPC subnet to which the load balancer is assigned. + "tag": "str", # Optional. The name of a Droplet tag corresponding to + Droplets assigned to the load balancer. + "target_load_balancer_ids": [ + "str" # Optional. An array containing the UUIDs of the + Regional load balancers to be used as target backends for a Global load + balancer. + ], + "tls_cipher_policy": "DEFAULT", # Optional. Default value is + "DEFAULT". A string indicating the policy for the TLS cipher suites used by + the load balancer. The possible values are ``DEFAULT`` or ``STRONG``. The + default value is ``DEFAULT``. Known values are: "DEFAULT" and "STRONG". + "type": "REGIONAL", # Optional. Default value is "REGIONAL". A + string indicating whether the load balancer should be a standard regional + HTTP load balancer, a regional network load balancer that routes traffic at + the TCP/UDP transport layer, or a global load balancer. Known values are: + "REGIONAL", "REGIONAL_NETWORK", and "GLOBAL". + "vpc_uuid": "str" # Optional. A string specifying the UUID of the + VPC to which the load balancer is assigned. + } + } + # response body for status code(s): 404 + response == { + "id": "str", # A short identifier corresponding to the HTTP status code + returned. For example, the ID for a response returning a 404 status code would + be "not_found.". Required. + "message": "str", # A message providing additional information about the + error, including details to help resolve it when possible. Required. + "request_id": "str" # Optional. Optionally, some endpoints may include a + request ID that should be provided when reporting bugs or opening support + tickets to help identify the issue. + } + """ + + @overload + def update( + self, + lb_id: str, + body: IO[bytes], + *, + content_type: str = "application/json", + **kwargs: Any, + ) -> JSON: + # pylint: disable=line-too-long + """Update a Load Balancer. + + To update a load balancer's settings, send a PUT request to + ``/v2/load_balancers/$LOAD_BALANCER_ID``. The request should contain a full + representation of the load balancer including existing attributes. It may + contain *one of* the ``droplets_ids`` or ``tag`` attributes as they are mutually + exclusive. **Note that any attribute that is not provided will be reset to its + default value.**. + + :param lb_id: A unique identifier for a load balancer. Required. + :type lb_id: str + :param body: Required. + :type body: IO[bytes] + :keyword content_type: Body Parameter content-type. Content type parameter for binary body. + Default value is "application/json". + :paramtype content_type: str + :return: JSON object + :rtype: JSON + :raises ~azure.core.exceptions.HttpResponseError: + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response == { + "load_balancer": { + "forwarding_rules": [ + { + "entry_port": 0, # An integer representing the port + on which the load balancer instance will listen. Required. + "entry_protocol": "str", # The protocol used for + traffic to the load balancer. The possible values are: ``http``"" , + ``https``"" , ``http2``"" , ``http3``"" , ``tcp``"" , or ``udp``. If + you set the ``entry_protocol`` to ``udp``"" , the + ``target_protocol`` must be set to ``udp``. When using UDP, the load + balancer requires that you set up a health check with a port that + uses TCP, HTTP, or HTTPS to work properly. Required. Known values + are: "http", "https", "http2", "http3", "tcp", and "udp". + "target_port": 0, # An integer representing the port + on the backend Droplets to which the load balancer will send traffic. + Required. + "target_protocol": "str", # The protocol used for + traffic from the load balancer to the backend Droplets. The possible + values are: ``http``"" , ``https``"" , ``http2``"" , ``tcp``"" , or + ``udp``. If you set the ``target_protocol`` to ``udp``"" , the + ``entry_protocol`` must be set to ``udp``. When using UDP, the load + balancer requires that you set up a health check with a port that + uses TCP, HTTP, or HTTPS to work properly. Required. Known values + are: "http", "https", "http2", "tcp", and "udp". + "certificate_id": "str", # Optional. The ID of the + TLS certificate used for SSL termination if enabled. + "tls_passthrough": bool # Optional. A boolean value + indicating whether SSL encrypted traffic will be passed through to + the backend Droplets. + } + ], + "algorithm": "round_robin", # Optional. Default value is + "round_robin". This field has been deprecated. You can no longer specify an + algorithm for load balancers. Known values are: "round_robin" and + "least_connections". + "created_at": "2020-02-20 00:00:00", # Optional. A time value given + in ISO8601 combined date and time format that represents when the load + balancer was created. + "disable_lets_encrypt_dns_records": False, # Optional. Default value + is False. A boolean value indicating whether to disable automatic DNS record + creation for Let's Encrypt certificates that are added to the load balancer. + "domains": [ + { + "certificate_id": "str", # Optional. The ID of the + TLS certificate used for SSL termination. + "is_managed": bool, # Optional. A boolean value + indicating if the domain is already managed by DigitalOcean. If true, + all A and AAAA records required to enable Global load balancers will + be automatically added. + "name": "str" # Optional. FQDN to associate with a + Global load balancer. + } + ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -188248,246 +194540,24 @@ def update( "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. - "size": "lb-small", # Optional. Default value is "lb-small". This - field has been replaced by the ``size_unit`` field for all regions except in - AMS2, NYC2, and SFO1. Each available load balancer size now equates to the - load balancer having a set number of nodes. * ``lb-small`` = 1 node * - ``lb-medium`` = 3 nodes * ``lb-large`` = 6 nodes You can resize load - balancers after creation up to once per hour. You cannot resize a load - balancer within the first hour of its creation. Known values are: "lb-small", - "lb-medium", and "lb-large". - "size_unit": 1, # Optional. Default value is 1. How many nodes the - load balancer contains. Each additional node increases the load balancer's - ability to manage more connections. Load balancers can be scaled up or down, - and you can change the number of nodes after creation up to once per hour. - This field is currently not available in the AMS2, NYC2, or SFO1 regions. Use - the ``size`` field to scale load balancers that reside in these regions. - "status": "str", # Optional. A status string indicating the current - state of the load balancer. This can be ``new``"" , ``active``"" , or - ``errored``. Known values are: "new", "active", and "errored". - "sticky_sessions": { - "cookie_name": "str", # Optional. The name of the cookie - sent to the client. This attribute is only returned when using - ``cookies`` for the sticky sessions type. - "cookie_ttl_seconds": 0, # Optional. The number of seconds - until the cookie set by the load balancer expires. This attribute is only - returned when using ``cookies`` for the sticky sessions type. - "type": "none" # Optional. Default value is "none". An - attribute indicating how and if requests from a client will be - persistently served by the same backend Droplet. The possible values are - ``cookies`` or ``none``. Known values are: "cookies" and "none". - }, - "subnet_uuid": "str", # Optional. A string specifying the UUID of - the VPC subnet to which the load balancer is assigned. - "tag": "str", # Optional. The name of a Droplet tag corresponding to - Droplets assigned to the load balancer. - "target_load_balancer_ids": [ - "str" # Optional. An array containing the UUIDs of the - Regional load balancers to be used as target backends for a Global load - balancer. - ], - "tls_cipher_policy": "DEFAULT", # Optional. Default value is - "DEFAULT". A string indicating the policy for the TLS cipher suites used by - the load balancer. The possible values are ``DEFAULT`` or ``STRONG``. The - default value is ``DEFAULT``. Known values are: "DEFAULT" and "STRONG". - "type": "REGIONAL", # Optional. Default value is "REGIONAL". A - string indicating whether the load balancer should be a standard regional - HTTP load balancer, a regional network load balancer that routes traffic at - the TCP/UDP transport layer, or a global load balancer. Known values are: - "REGIONAL", "REGIONAL_NETWORK", and "GLOBAL". - "vpc_uuid": "str" # Optional. A string specifying the UUID of the - VPC to which the load balancer is assigned. - } - } - # response body for status code(s): 404 - response == { - "id": "str", # A short identifier corresponding to the HTTP status code - returned. For example, the ID for a response returning a 404 status code would - be "not_found.". Required. - "message": "str", # A message providing additional information about the - error, including details to help resolve it when possible. Required. - "request_id": "str" # Optional. Optionally, some endpoints may include a - request ID that should be provided when reporting bugs or opening support - tickets to help identify the issue. - } - """ - - @overload - def update( - self, - lb_id: str, - body: IO[bytes], - *, - content_type: str = "application/json", - **kwargs: Any, - ) -> JSON: - # pylint: disable=line-too-long - """Update a Load Balancer. - - To update a load balancer's settings, send a PUT request to - ``/v2/load_balancers/$LOAD_BALANCER_ID``. The request should contain a full - representation of the load balancer including existing attributes. It may - contain *one of* the ``droplets_ids`` or ``tag`` attributes as they are mutually - exclusive. **Note that any attribute that is not provided will be reset to its - default value.**. - - :param lb_id: A unique identifier for a load balancer. Required. - :type lb_id: str - :param body: Required. - :type body: IO[bytes] - :keyword content_type: Body Parameter content-type. Content type parameter for binary body. - Default value is "application/json". - :paramtype content_type: str - :return: JSON object - :rtype: JSON - :raises ~azure.core.exceptions.HttpResponseError: - - Example: - .. code-block:: python - - # response body for status code(s): 200 - response == { - "load_balancer": { - "forwarding_rules": [ - { - "entry_port": 0, # An integer representing the port - on which the load balancer instance will listen. Required. - "entry_protocol": "str", # The protocol used for - traffic to the load balancer. The possible values are: ``http``"" , - ``https``"" , ``http2``"" , ``http3``"" , ``tcp``"" , or ``udp``. If - you set the ``entry_protocol`` to ``udp``"" , the - ``target_protocol`` must be set to ``udp``. When using UDP, the load - balancer requires that you set up a health check with a port that - uses TCP, HTTP, or HTTPS to work properly. Required. Known values - are: "http", "https", "http2", "http3", "tcp", and "udp". - "target_port": 0, # An integer representing the port - on the backend Droplets to which the load balancer will send traffic. - Required. - "target_protocol": "str", # The protocol used for - traffic from the load balancer to the backend Droplets. The possible - values are: ``http``"" , ``https``"" , ``http2``"" , ``tcp``"" , or - ``udp``. If you set the ``target_protocol`` to ``udp``"" , the - ``entry_protocol`` must be set to ``udp``. When using UDP, the load - balancer requires that you set up a health check with a port that - uses TCP, HTTP, or HTTPS to work properly. Required. Known values - are: "http", "https", "http2", "tcp", and "udp". - "certificate_id": "str", # Optional. The ID of the - TLS certificate used for SSL termination if enabled. - "tls_passthrough": bool # Optional. A boolean value - indicating whether SSL encrypted traffic will be passed through to - the backend Droplets. - } - ], - "algorithm": "round_robin", # Optional. Default value is - "round_robin". This field has been deprecated. You can no longer specify an - algorithm for load balancers. Known values are: "round_robin" and - "least_connections". - "created_at": "2020-02-20 00:00:00", # Optional. A time value given - in ISO8601 combined date and time format that represents when the load - balancer was created. - "disable_lets_encrypt_dns_records": False, # Optional. Default value - is False. A boolean value indicating whether to disable automatic DNS record - creation for Let's Encrypt certificates that are added to the load balancer. - "domains": [ - { - "certificate_id": "str", # Optional. The ID of the - TLS certificate used for SSL termination. - "is_managed": bool, # Optional. A boolean value - indicating if the domain is already managed by DigitalOcean. If true, - all A and AAAA records required to enable Global load balancers will - be automatically added. - "name": "str" # Optional. FQDN to associate with a - Global load balancer. - } - ], - "enable_backend_keepalive": False, # Optional. Default value is - False. A boolean value indicating whether HTTP keepalive connections are - maintained to target Droplets. - "enable_proxy_protocol": False, # Optional. Default value is False. - A boolean value indicating whether PROXY Protocol is in use. - "firewall": { - "allow": [ - "str" # Optional. the rules for allowing traffic to - the load balancer (in the form 'ip:1.2.3.4' or 'cidr:1.2.0.0/16'). + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. ], - "deny": [ - "str" # Optional. the rules for denying traffic to - the load balancer (in the form 'ip:1.2.3.4' or 'cidr:1.2.0.0/16'). - ] - }, - "glb_settings": { - "cdn": { - "is_enabled": bool # Optional. A boolean flag to - enable CDN caching. - }, - "failover_threshold": 0, # Optional. An integer value as a - percentage to indicate failure threshold to decide how the regional - priorities will take effect. A value of ``50`` would indicate that the - Global load balancer will choose a lower priority region to forward - traffic to once this failure threshold has been reached for the higher - priority region. - "region_priorities": { - "str": 0 # Optional. A map of region string to an - integer priority value indicating preference for which regional - target a Global load balancer will forward traffic to. A lower value - indicates a higher priority. - }, - "target_port": 0, # Optional. An integer representing the - port on the target backends which the load balancer will forward traffic - to. - "target_protocol": "str" # Optional. The protocol used for - forwarding traffic from the load balancer to the target backends. The - possible values are ``http``"" , ``https`` and ``http2``. Known values - are: "http", "https", and "http2". - }, - "health_check": { - "check_interval_seconds": 10, # Optional. Default value is - 10. The number of seconds between between two consecutive health checks. - "healthy_threshold": 3, # Optional. Default value is 3. The - number of times a health check must pass for a backend Droplet to be - marked "healthy" and be re-added to the pool. - "path": "/", # Optional. Default value is "/". The path on - the backend Droplets to which the load balancer instance will send a - request. - "port": 80, # Optional. Default value is 80. An integer - representing the port on the backend Droplets on which the health check - will attempt a connection. - "protocol": "http", # Optional. Default value is "http". The - protocol used for health checks sent to the backend Droplets. The - possible values are ``http``"" , ``https``"" , or ``tcp``. Known values - are: "http", "https", and "tcp". - "response_timeout_seconds": 5, # Optional. Default value is - 5. The number of seconds the load balancer instance will wait for a - response until marking a health check as failed. - "unhealthy_threshold": 5 # Optional. Default value is 5. The - number of times a health check must fail for a backend Droplet to be - marked "unhealthy" and be removed from the pool. + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. }, - "http_idle_timeout_seconds": 60, # Optional. Default value is 60. An - integer value which configures the idle timeout for HTTP requests to the - target droplets. - "id": "str", # Optional. A unique ID that can be used to identify - and reference a load balancer. - "ipv6": "str", # Optional. An attribute containing the public-facing - IPv6 address of the load balancer. - "name": "str", # Optional. A human-readable name for a load balancer - instance. - "network": "EXTERNAL", # Optional. Default value is "EXTERNAL". A - string indicating whether the load balancer should be external or internal. - Internal load balancers have no public IPs and are only accessible to - resources on the same VPC network. This property cannot be updated after - creating the load balancer. Known values are: "EXTERNAL" and "INTERNAL". - "network_stack": "IPV4", # Optional. Default value is "IPV4". A - string indicating whether the load balancer will support IPv4 or both IPv4 - and IPv6 networking. This property cannot be updated after creating the load - balancer. Known values are: "IPV4" and "DUALSTACK". - "project_id": "str", # Optional. The ID of the project that the load - balancer is associated with. If no ID is provided at creation, the load - balancer associates with the user's default project. If an invalid project ID - is provided, the load balancer will not be created. - "redirect_http_to_https": False, # Optional. Default value is False. - A boolean value indicating whether HTTP requests to the load balancer on port - 80 will be redirected to HTTPS on port 443. "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -188633,6 +194703,10 @@ def update(self, lb_id: str, body: Union[JSON, IO[bytes]], **kwargs: Any) -> JSO Global load balancer. } ], + "droplet_ids": [ + 0 # Optional. An array containing the IDs of the Droplets + assigned to the load balancer. + ], "enable_backend_keepalive": False, # Optional. Default value is False. A boolean value indicating whether HTTP keepalive connections are maintained to target Droplets. @@ -188721,6 +194795,24 @@ def update(self, lb_id: str, body: Union[JSON, IO[bytes]], **kwargs: Any) -> JSO "redirect_http_to_https": False, # Optional. Default value is False. A boolean value indicating whether HTTP requests to the load balancer on port 80 will be redirected to HTTPS on port 443. + "region": { + "available": bool, # This is a boolean value that represents + whether new Droplets can be created in this region. Required. + "features": [ + "str" # This attribute is set to an array which + contains features available in this region. Required. + ], + "name": "str", # The display name of the region. This will + be a full name that is used in the control panel and other interfaces. + Required. + "sizes": [ + "str" # This attribute is set to an array which + contains the identifying slugs for the sizes available in this + region. sizes:read is required to view. Required. + ], + "slug": "str" # A human-readable string that is used as a + unique identifier for each region. Required. + }, "size": "lb-small", # Optional. Default value is "lb-small". This field has been replaced by the ``size_unit`` field for all regions except in AMS2, NYC2, and SFO1. Each available load balancer size now equates to the @@ -189129,8 +195221,8 @@ def add_droplets( # JSON input template you can fill out and use as your body input. body = { "droplet_ids": [ - 0 # An array containing the IDs of the Droplets assigned to the load - balancer. Required. + 0 # Optional. An array containing the IDs of the Droplets assigned + to the load balancer. ] } @@ -189229,8 +195321,8 @@ def add_droplets( # JSON input template you can fill out and use as your body input. body = { "droplet_ids": [ - 0 # An array containing the IDs of the Droplets assigned to the load - balancer. Required. + 0 # Optional. An array containing the IDs of the Droplets assigned + to the load balancer. ] } @@ -189371,8 +195463,8 @@ def remove_droplets( # JSON input template you can fill out and use as your body input. body = { "droplet_ids": [ - 0 # An array containing the IDs of the Droplets assigned to the load - balancer. Required. + 0 # Optional. An array containing the IDs of the Droplets assigned + to the load balancer. ] } @@ -189465,8 +195557,8 @@ def remove_droplets( # JSON input template you can fill out and use as your body input. body = { "droplet_ids": [ - 0 # An array containing the IDs of the Droplets assigned to the load - balancer. Required. + 0 # Optional. An array containing the IDs of the Droplets assigned + to the load balancer. ] }