From 06bde758d80d02b47ad351d5ff70aaeb9bda31ee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:53:10 +0000 Subject: [PATCH 1/5] Bump black from 22.12.0 to 24.3.0 Bumps [black](https://github.com/psf/black) from 22.12.0 to 24.3.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](https://github.com/psf/black/compare/22.12.0...24.3.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements-lint.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-lint.txt b/requirements-lint.txt index ad9fd7e..27d521b 100644 --- a/requirements-lint.txt +++ b/requirements-lint.txt @@ -1,2 +1,2 @@ pylint==2.15.10 -black==22.12.0 \ No newline at end of file +black==24.3.0 \ No newline at end of file From 81d63303e32782fd683d93bf158e1cc1a36a16a6 Mon Sep 17 00:00:00 2001 From: Nikita Beletskii Date: Mon, 22 Apr 2024 16:28:17 -0400 Subject: [PATCH 2/5] fix syntax --- nomad/__init__.py | 6 +++++- nomad/api/__init__.py | 1 + nomad/api/agent.py | 1 + nomad/api/allocation.py | 1 + nomad/api/allocations.py | 1 + nomad/api/base.py | 5 ++++- nomad/api/client.py | 19 +++++++++++-------- nomad/api/deployment.py | 14 ++++++++++---- nomad/api/deployments.py | 1 + nomad/api/evaluation.py | 1 + nomad/api/evaluations.py | 1 + nomad/api/event.py | 9 +++++++-- nomad/api/exceptions.py | 5 ++++- nomad/api/jobs.py | 6 +++++- nomad/api/metrics.py | 1 + nomad/api/namespace.py | 1 + nomad/api/namespaces.py | 1 + nomad/api/node.py | 22 ++++++++++++++++++---- nomad/api/nodes.py | 1 + nomad/api/operator.py | 1 + nomad/api/regions.py | 1 + nomad/api/scaling.py | 8 ++++++-- nomad/api/search.py | 18 +++++++++++++++--- nomad/api/sentinel.py | 1 + nomad/api/status.py | 1 + nomad/api/system.py | 1 + nomad/api/validate.py | 2 +- nomad/api/variable.py | 1 + nomad/api/variables.py | 1 + 29 files changed, 104 insertions(+), 28 deletions(-) diff --git a/nomad/__init__.py b/nomad/__init__.py index fdb4f16..974c48a 100644 --- a/nomad/__init__.py +++ b/nomad/__init__.py @@ -1,4 +1,5 @@ """Nomad Python library""" + import os from typing import Optional @@ -25,7 +26,10 @@ def __init__( # pylint: disable=too-many-arguments region: Optional[str] = os.getenv("NOMAD_REGION", None), version: str = "v1", verify: bool = False, - cert: tuple = (os.getenv("NOMAD_CLIENT_CERT", None), os.getenv("NOMAD_CLIENT_KEY", None)), + cert: tuple = ( + os.getenv("NOMAD_CLIENT_CERT", None), + os.getenv("NOMAD_CLIENT_KEY", None), + ), session: requests.Session = None, ): """Nomad api client diff --git a/nomad/api/__init__.py b/nomad/api/__init__.py index 3886570..0c3f17e 100644 --- a/nomad/api/__init__.py +++ b/nomad/api/__init__.py @@ -1,4 +1,5 @@ """Nomad Python library""" + import nomad.api.exceptions from nomad.api.acl import Acl from nomad.api.agent import Agent diff --git a/nomad/api/agent.py b/nomad/api/agent.py index 7ad412c..c62babe 100644 --- a/nomad/api/agent.py +++ b/nomad/api/agent.py @@ -1,4 +1,5 @@ """Nomad Agent: https://developer.hashicorp.com/nomad/api-docs/agent""" + from nomad.api.base import Requester diff --git a/nomad/api/allocation.py b/nomad/api/allocation.py index 87d64d9..9e9da20 100644 --- a/nomad/api/allocation.py +++ b/nomad/api/allocation.py @@ -1,4 +1,5 @@ """Nomad allocation: https://developer.hashicorp.com/nomad/api-docs/allocations""" + import nomad.api.exceptions from nomad.api.base import Requester diff --git a/nomad/api/allocations.py b/nomad/api/allocations.py index 128b072..920beaa 100644 --- a/nomad/api/allocations.py +++ b/nomad/api/allocations.py @@ -1,4 +1,5 @@ """Nomad allocation: https://developer.hashicorp.com/nomad/api-docs/allocations""" + from typing import Optional from nomad.api.base import Requester diff --git a/nomad/api/base.py b/nomad/api/base.py index 87f3714..a4c67e2 100644 --- a/nomad/api/base.py +++ b/nomad/api/base.py @@ -1,4 +1,5 @@ """Requester""" + from typing import Optional import requests @@ -91,7 +92,9 @@ def _query_string_builder(self, endpoint, params=None): # Remove parameters that are None params = {key: val for key, val in params.items() if val is not None} - if ("namespace" not in params) and (self.namespace and self._required_namespace(endpoint)): + if ("namespace" not in params) and ( + self.namespace and self._required_namespace(endpoint) + ): query_string["namespace"] = self.namespace if "region" not in params and self.region: diff --git a/nomad/api/client.py b/nomad/api/client.py index cefbd33..105f942 100644 --- a/nomad/api/client.py +++ b/nomad/api/client.py @@ -33,7 +33,6 @@ def __getattr__(self, item): class ls(Requester): - """ The /fs/ls endpoint is used to list files in an allocation directory. This API endpoint is hosted by the Nomad client and requests have to be @@ -67,7 +66,6 @@ def list_files(self, id_=None, path="/"): class cat(Requester): - """ The /fs/cat endpoint is used to read the contents of a file in an allocation directory. This API endpoint is hosted by the Nomad @@ -102,7 +100,6 @@ def read_file(self, id_=None, path="/"): class read_at(Requester): - """ This endpoint reads the contents of a file in an allocation directory at a particular offset and limit. @@ -134,7 +131,6 @@ def read_file_offset(self, id_, offset, limit, path="/"): class stream_file(Requester): - """ This endpoint streams the contents of a file in an allocation directory. @@ -166,7 +162,6 @@ def stream(self, id_, offset, origin, path="/"): class stream_logs(Requester): - """ This endpoint streams a task's stderr/stdout logs. @@ -178,7 +173,9 @@ class stream_logs(Requester): def __init__(self, **kwargs): super().__init__(**kwargs) - def stream(self, id_, task, type_, follow=False, offset=0, origin="start", plain=False): + def stream( + self, id_, task, type_, follow=False, offset=0, origin="start", plain=False + ): """This endpoint streams a task's stderr/stdout logs. https://www.nomadproject.io/api/client.html#stream-logs @@ -196,7 +193,14 @@ def stream(self, id_, task, type_, follow=False, offset=0, origin="start", plain - nomad.api.exceptions.BaseNomadException - nomad.api.exceptions.BadRequestNomadException """ - params = {"task": task, "type": type_, "follow": follow, "offset": offset, "origin": origin, "plain": plain} + params = { + "task": task, + "type": type_, + "follow": follow, + "offset": offset, + "origin": origin, + "plain": plain, + } return self.request(id_, params=params, method="get").text @@ -304,7 +308,6 @@ def restart_allocation(self, id_): class gc_allocation(Requester): - """ This endpoint forces a garbage collection of a particular, stopped allocation on a node. diff --git a/nomad/api/deployment.py b/nomad/api/deployment.py index 2b2432c..f22e758 100644 --- a/nomad/api/deployment.py +++ b/nomad/api/deployment.py @@ -1,11 +1,11 @@ """Nomad Deployment: https://developer.hashicorp.com/nomad/api-docs/deployments""" + import nomad.api.exceptions from nomad.api.base import Requester class Deployment(Requester): - """ The /deployment endpoints are used to query for and interact with deployments. @@ -138,9 +138,13 @@ def promote_deployment_groups(self, id_, groups=None): if groups is None: groups = [] promote_groups_json = {"Groups": groups, "DeploymentID": id_} - return self.request("promote", id_, json=promote_groups_json, method="post").json() + return self.request( + "promote", id_, json=promote_groups_json, method="post" + ).json() - def deployment_allocation_health(self, id_, healthy_allocations=None, unhealthy_allocations=None): + def deployment_allocation_health( + self, id_, healthy_allocations=None, unhealthy_allocations=None + ): """This endpoint is used to set the health of an allocation that is in the deployment manually. In some use cases, automatic detection of allocation health may not be desired. As such those task groups can be marked with an upgrade policy that uses health_check = "manual". Those allocations must have their health marked @@ -169,4 +173,6 @@ def deployment_allocation_health(self, id_, healthy_allocations=None, unhealthy_ "UnHealthyAllocationIDs": unhealthy_allocations, "DeploymentID": id_, } - return self.request("allocation-health", id_, json=allocations, method="post").json() + return self.request( + "allocation-health", id_, json=allocations, method="post" + ).json() diff --git a/nomad/api/deployments.py b/nomad/api/deployments.py index 91dd335..54d1012 100644 --- a/nomad/api/deployments.py +++ b/nomad/api/deployments.py @@ -1,4 +1,5 @@ """Nomad Deployment: https://developer.hashicorp.com/nomad/api-docs/deployments""" + import nomad.api.exceptions from nomad.api.base import Requester diff --git a/nomad/api/evaluation.py b/nomad/api/evaluation.py index 2f1546a..6f8fcad 100644 --- a/nomad/api/evaluation.py +++ b/nomad/api/evaluation.py @@ -1,4 +1,5 @@ """Nomad Evaluation: https://developer.hashicorp.com/nomad/api-docs/evaluations""" + import nomad.api.exceptions from nomad.api.base import Requester diff --git a/nomad/api/evaluations.py b/nomad/api/evaluations.py index dae0f61..f91c9d2 100644 --- a/nomad/api/evaluations.py +++ b/nomad/api/evaluations.py @@ -1,4 +1,5 @@ """Nomad Evaluations: https://developer.hashicorp.com/nomad/api-docs/evaluations""" + import nomad.api.exceptions from nomad.api.base import Requester diff --git a/nomad/api/event.py b/nomad/api/event.py index cafadb2..3f361ac 100644 --- a/nomad/api/event.py +++ b/nomad/api/event.py @@ -1,4 +1,5 @@ """Nomad Events: https://developer.hashicorp.com/nomad/api-docs/events""" + import json import threading import queue @@ -39,7 +40,9 @@ class stream(Requester): # pylint: disable=invalid-name def __init__(self, **kwargs): super().__init__(**kwargs) - def _get_stream(self, method, params, timeout, event_queue, exit_event): # pylint: disable=too-many-arguments + def _get_stream( + self, method, params, timeout, event_queue, exit_event + ): # pylint: disable=too-many-arguments """ Used as threading target, to obtain json() value Args: @@ -52,7 +55,9 @@ def _get_stream(self, method, params, timeout, event_queue, exit_event): # pyli while exit_event.is_set() is False: try: - with self.request(method=method, params=params, timeout=timeout, stream=True) as resp: + with self.request( + method=method, params=params, timeout=timeout, stream=True + ) as resp: for raw_msg in resp.iter_lines(): msg = json.loads(raw_msg) diff --git a/nomad/api/exceptions.py b/nomad/api/exceptions.py index 578c16f..715db56 100644 --- a/nomad/api/exceptions.py +++ b/nomad/api/exceptions.py @@ -1,4 +1,5 @@ """Internal library exceptions""" + import requests @@ -9,7 +10,9 @@ def __init__(self, nomad_resp): self.nomad_resp = nomad_resp def __str__(self): - if isinstance(self.nomad_resp, requests.Response) and hasattr(self.nomad_resp, "text"): + if isinstance(self.nomad_resp, requests.Response) and hasattr( + self.nomad_resp, "text" + ): return f"The {self.__class__.__name__} was raised with following response: {self.nomad_resp.text}." return f"The {self.__class__.__name__} was raised due to the following error: {self.nomad_resp}" diff --git a/nomad/api/jobs.py b/nomad/api/jobs.py index c57f31c..1b3488c 100644 --- a/nomad/api/jobs.py +++ b/nomad/api/jobs.py @@ -1,4 +1,5 @@ """Nomad job: https://developer.hashicorp.com/nomad/api-docs/jobs""" + from typing import Optional import nomad.api.exceptions @@ -119,5 +120,8 @@ def parse(self, hcl, canonicalize=False): - nomad.api.exceptions.URLNotFoundNomadException """ return self.request( - "parse", json={"JobHCL": hcl, "Canonicalize": canonicalize}, method="post", allow_redirects=True + "parse", + json={"JobHCL": hcl, "Canonicalize": canonicalize}, + method="post", + allow_redirects=True, ).json() diff --git a/nomad/api/metrics.py b/nomad/api/metrics.py index 0575eff..acc5fab 100644 --- a/nomad/api/metrics.py +++ b/nomad/api/metrics.py @@ -1,4 +1,5 @@ """Nomad Metrics: https://developer.hashicorp.com/nomad/api-docs/metrics""" + from nomad.api.base import Requester diff --git a/nomad/api/namespace.py b/nomad/api/namespace.py index 4044e5b..66f096c 100644 --- a/nomad/api/namespace.py +++ b/nomad/api/namespace.py @@ -1,4 +1,5 @@ """Nomad namespace: https://developer.hashicorp.com/nomad/api-docs/namespaces""" + import nomad.api.exceptions from nomad.api.base import Requester diff --git a/nomad/api/namespaces.py b/nomad/api/namespaces.py index a87108f..6017016 100644 --- a/nomad/api/namespaces.py +++ b/nomad/api/namespaces.py @@ -1,4 +1,5 @@ """Nomad namespace: https://developer.hashicorp.com/nomad/api-docs/namespaces""" + import nomad.api.exceptions from nomad.api.base import Requester diff --git a/nomad/api/node.py b/nomad/api/node.py index 86a7462..a6d2727 100644 --- a/nomad/api/node.py +++ b/nomad/api/node.py @@ -1,4 +1,5 @@ """Nomad Node: https://developer.hashicorp.com/nomad/api-docs/nodes""" + from typing import Optional import nomad.api.exceptions @@ -102,9 +103,13 @@ def drain_node(self, id_, enable: bool = False): - nomad.api.exceptions.URLNotFoundNomadException """ - return self.request(id_, "drain", params={"enable": enable}, method="post").json() + return self.request( + id_, "drain", params={"enable": enable}, method="post" + ).json() - def drain_node_with_spec(self, id_, drain_spec: Optional[dict], mark_eligible: Optional[bool] = None): + def drain_node_with_spec( + self, id_, drain_spec: Optional[dict], mark_eligible: Optional[bool] = None + ): """This endpoint toggles the drain mode of the node. When draining is enabled, no further allocations will be assigned to this node, and existing allocations will be migrated to new nodes. @@ -125,7 +130,11 @@ def drain_node_with_spec(self, id_, drain_spec: Optional[dict], mark_eligible: O payload = {} if drain_spec and mark_eligible is not None: - payload = {"NodeID": id_, "DrainSpec": drain_spec, "MarkEligible": mark_eligible} + payload = { + "NodeID": id_, + "DrainSpec": drain_spec, + "MarkEligible": mark_eligible, + } elif drain_spec and mark_eligible is None: payload = {"NodeID": id_, "DrainSpec": drain_spec} elif not drain_spec and mark_eligible is not None: @@ -138,7 +147,12 @@ def drain_node_with_spec(self, id_, drain_spec: Optional[dict], mark_eligible: O return self.request(id_, "drain", json=payload, method="post").json() - def eligible_node(self, id_: str, eligible: Optional[bool] = None, ineligible: Optional[bool] = None): + def eligible_node( + self, + id_: str, + eligible: Optional[bool] = None, + ineligible: Optional[bool] = None, + ): """Toggle the eligibility of the node. https://www.nomadproject.io/docs/http/node.html diff --git a/nomad/api/nodes.py b/nomad/api/nodes.py index 28949e4..dfa77dc 100644 --- a/nomad/api/nodes.py +++ b/nomad/api/nodes.py @@ -1,4 +1,5 @@ """Nomad Node: https://developer.hashicorp.com/nomad/api-docs/nodes""" + from typing import Optional import nomad.api.exceptions diff --git a/nomad/api/operator.py b/nomad/api/operator.py index 8fa2146..777d5d8 100644 --- a/nomad/api/operator.py +++ b/nomad/api/operator.py @@ -1,4 +1,5 @@ """Nomad Operator: https://developer.hashicorp.com/nomad/api-docs/operator""" + from nomad.api.base import Requester diff --git a/nomad/api/regions.py b/nomad/api/regions.py index bc89989..0b22a0d 100644 --- a/nomad/api/regions.py +++ b/nomad/api/regions.py @@ -1,4 +1,5 @@ """Nomad region: https://developer.hashicorp.com/nomad/api-docs/regions""" + import nomad.api.exceptions from nomad.api.base import Requester diff --git a/nomad/api/scaling.py b/nomad/api/scaling.py index a05fa8a..4635822 100644 --- a/nomad/api/scaling.py +++ b/nomad/api/scaling.py @@ -1,4 +1,5 @@ """Nomad Scalling API: https://developer.hashicorp.com/nomad/api-docs/scaling-policies""" + import nomad.api.exceptions from nomad.api.base import Requester @@ -27,7 +28,9 @@ def __getattr__(self, item): raise AttributeError(msg) # we want to have common arguments name with Nomad API - def get_scaling_policies(self, job="", type_=""): # pylint: disable=redefined-builtin + def get_scaling_policies( + self, job="", type_="" + ): # pylint: disable=redefined-builtin """ This endpoint returns the scaling policies from all jobs. @@ -50,7 +53,8 @@ def get_scaling_policies(self, job="", type_=""): # pylint: disable=redefined-b if type_ not in type_of_scaling_policies: raise nomad.api.exceptions.InvalidParameters( - "type is invalid " f"(expected values are {type_of_scaling_policies} but got {type_})" + "type is invalid " + f"(expected values are {type_of_scaling_policies} but got {type_})" ) params = {"job": job, "type": type_} diff --git a/nomad/api/search.py b/nomad/api/search.py index e373ee8..3047e38 100644 --- a/nomad/api/search.py +++ b/nomad/api/search.py @@ -1,4 +1,5 @@ """Nomad Search API: https://developer.hashicorp.com/nomad/api-docs/search""" + import nomad.api.exceptions from nomad.api.base import Requester @@ -46,10 +47,20 @@ def search(self, prefix, context): - nomad.api.exceptions.URLNotFoundNomadException - nomad.api.exceptions.InvalidParameters """ - accetaple_contexts = ("jobs", "evals", "allocs", "nodes", "deployment", "plugins", "volumes", "all") + accetaple_contexts = ( + "jobs", + "evals", + "allocs", + "nodes", + "deployment", + "plugins", + "volumes", + "all", + ) if context not in accetaple_contexts: raise nomad.api.exceptions.InvalidParameters( - "context is invalid " f"(expected values are {accetaple_contexts} but got {context})" + "context is invalid " + f"(expected values are {accetaple_contexts} but got {context})" ) params = {"Prefix": prefix, "Context": context} @@ -82,7 +93,8 @@ def fuzzy_search(self, text, context): accetaple_contexts = ("jobs", "allocs", "nodes", "plugins", "all") if context not in accetaple_contexts: raise nomad.api.exceptions.InvalidParameters( - "context is invalid " f"(expected values are {accetaple_contexts} but got {context})" + "context is invalid " + f"(expected values are {accetaple_contexts} but got {context})" ) return self.request("fuzzy", json=params, method="post").json() diff --git a/nomad/api/sentinel.py b/nomad/api/sentinel.py index eaf7c20..ef2a0f0 100644 --- a/nomad/api/sentinel.py +++ b/nomad/api/sentinel.py @@ -1,4 +1,5 @@ """Nomad Sentinel API: https://developer.hashicorp.com/nomad/api-docs/sentinel-policies""" + from nomad.api.base import Requester diff --git a/nomad/api/status.py b/nomad/api/status.py index 85d8a42..db52510 100644 --- a/nomad/api/status.py +++ b/nomad/api/status.py @@ -1,4 +1,5 @@ """Nomad Status API: https://developer.hashicorp.com/nomad/api-docs/status""" + import nomad.api.exceptions from nomad.api.base import Requester diff --git a/nomad/api/system.py b/nomad/api/system.py index 4255ab4..daf119f 100644 --- a/nomad/api/system.py +++ b/nomad/api/system.py @@ -1,4 +1,5 @@ """Nomad System API: https://developer.hashicorp.com/nomad/api-docs/system""" + from nomad.api.base import Requester diff --git a/nomad/api/validate.py b/nomad/api/validate.py index ea17fda..5372905 100644 --- a/nomad/api/validate.py +++ b/nomad/api/validate.py @@ -1,9 +1,9 @@ """Nomad Validate API: https://developer.hashicorp.com/nomad/api-docs/validate""" + from nomad.api.base import Requester class Validate(Requester): - """ The system endpoint is used to for system maintenance and should not be necessary for most users. diff --git a/nomad/api/variable.py b/nomad/api/variable.py index 7df2446..e4bcdf1 100644 --- a/nomad/api/variable.py +++ b/nomad/api/variable.py @@ -1,4 +1,5 @@ """Nomad Valiables API: https://developer.hashicorp.com/nomad/api-docs/variables""" + import nomad.api.exceptions from nomad.api.base import Requester diff --git a/nomad/api/variables.py b/nomad/api/variables.py index d75f482..2d9d972 100644 --- a/nomad/api/variables.py +++ b/nomad/api/variables.py @@ -1,4 +1,5 @@ """Nomad Valiables API: https://developer.hashicorp.com/nomad/api-docs/variables""" + from nomad.api.base import Requester From c555fe3be5fd4d94cadf48fb18cee8f32b6136cf Mon Sep 17 00:00:00 2001 From: Nikita Beletskii Date: Mon, 22 Apr 2024 16:31:37 -0400 Subject: [PATCH 3/5] upgrade to the latest version --- requirements-lint.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-lint.txt b/requirements-lint.txt index 27d521b..2855e0a 100644 --- a/requirements-lint.txt +++ b/requirements-lint.txt @@ -1,2 +1,2 @@ pylint==2.15.10 -black==24.3.0 \ No newline at end of file +black==24.4.0 \ No newline at end of file From 6884c15d708741eb6258dc6a5e0ee9cc3b255d33 Mon Sep 17 00:00:00 2001 From: Nikita Beletskii Date: Mon, 22 Apr 2024 16:32:41 -0400 Subject: [PATCH 4/5] fix syntax more --- nomad/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nomad/__init__.py b/nomad/__init__.py index bd09cf1..406d2db 100644 --- a/nomad/__init__.py +++ b/nomad/__init__.py @@ -58,7 +58,10 @@ def __init__( # pylint: disable=too-many-arguments - nomad.api.exceptions.URLNotFoundNomadException - nomad.api.exceptions.URLNotAuthorizedNomadException """ - cert = cert or (os.getenv("NOMAD_CLIENT_CERT", None), os.getenv("NOMAD_CLIENT_KEY", None)) + cert = cert or ( + os.getenv("NOMAD_CLIENT_CERT", None), + os.getenv("NOMAD_CLIENT_KEY", None), + ) self.host = host self.secure = secure From bd8810f8d70667cb3a5f65544e72c8b99a65909c Mon Sep 17 00:00:00 2001 From: Nikita Beletskii Date: Mon, 22 Apr 2024 16:33:57 -0400 Subject: [PATCH 5/5] fix --- nomad/api/base.py | 4 +--- nomad/api/client.py | 4 +--- nomad/api/deployment.py | 12 +++--------- nomad/api/event.py | 8 ++------ nomad/api/exceptions.py | 4 +--- nomad/api/node.py | 8 ++------ nomad/api/scaling.py | 7 ++----- nomad/api/search.py | 6 ++---- 8 files changed, 14 insertions(+), 39 deletions(-) diff --git a/nomad/api/base.py b/nomad/api/base.py index a4c67e2..209899b 100644 --- a/nomad/api/base.py +++ b/nomad/api/base.py @@ -92,9 +92,7 @@ def _query_string_builder(self, endpoint, params=None): # Remove parameters that are None params = {key: val for key, val in params.items() if val is not None} - if ("namespace" not in params) and ( - self.namespace and self._required_namespace(endpoint) - ): + if ("namespace" not in params) and (self.namespace and self._required_namespace(endpoint)): query_string["namespace"] = self.namespace if "region" not in params and self.region: diff --git a/nomad/api/client.py b/nomad/api/client.py index 105f942..ebf5991 100644 --- a/nomad/api/client.py +++ b/nomad/api/client.py @@ -173,9 +173,7 @@ class stream_logs(Requester): def __init__(self, **kwargs): super().__init__(**kwargs) - def stream( - self, id_, task, type_, follow=False, offset=0, origin="start", plain=False - ): + def stream(self, id_, task, type_, follow=False, offset=0, origin="start", plain=False): """This endpoint streams a task's stderr/stdout logs. https://www.nomadproject.io/api/client.html#stream-logs diff --git a/nomad/api/deployment.py b/nomad/api/deployment.py index f22e758..ff7ac3b 100644 --- a/nomad/api/deployment.py +++ b/nomad/api/deployment.py @@ -138,13 +138,9 @@ def promote_deployment_groups(self, id_, groups=None): if groups is None: groups = [] promote_groups_json = {"Groups": groups, "DeploymentID": id_} - return self.request( - "promote", id_, json=promote_groups_json, method="post" - ).json() + return self.request("promote", id_, json=promote_groups_json, method="post").json() - def deployment_allocation_health( - self, id_, healthy_allocations=None, unhealthy_allocations=None - ): + def deployment_allocation_health(self, id_, healthy_allocations=None, unhealthy_allocations=None): """This endpoint is used to set the health of an allocation that is in the deployment manually. In some use cases, automatic detection of allocation health may not be desired. As such those task groups can be marked with an upgrade policy that uses health_check = "manual". Those allocations must have their health marked @@ -173,6 +169,4 @@ def deployment_allocation_health( "UnHealthyAllocationIDs": unhealthy_allocations, "DeploymentID": id_, } - return self.request( - "allocation-health", id_, json=allocations, method="post" - ).json() + return self.request("allocation-health", id_, json=allocations, method="post").json() diff --git a/nomad/api/event.py b/nomad/api/event.py index 3f361ac..e812b42 100644 --- a/nomad/api/event.py +++ b/nomad/api/event.py @@ -40,9 +40,7 @@ class stream(Requester): # pylint: disable=invalid-name def __init__(self, **kwargs): super().__init__(**kwargs) - def _get_stream( - self, method, params, timeout, event_queue, exit_event - ): # pylint: disable=too-many-arguments + def _get_stream(self, method, params, timeout, event_queue, exit_event): # pylint: disable=too-many-arguments """ Used as threading target, to obtain json() value Args: @@ -55,9 +53,7 @@ def _get_stream( while exit_event.is_set() is False: try: - with self.request( - method=method, params=params, timeout=timeout, stream=True - ) as resp: + with self.request(method=method, params=params, timeout=timeout, stream=True) as resp: for raw_msg in resp.iter_lines(): msg = json.loads(raw_msg) diff --git a/nomad/api/exceptions.py b/nomad/api/exceptions.py index 715db56..dcc0d66 100644 --- a/nomad/api/exceptions.py +++ b/nomad/api/exceptions.py @@ -10,9 +10,7 @@ def __init__(self, nomad_resp): self.nomad_resp = nomad_resp def __str__(self): - if isinstance(self.nomad_resp, requests.Response) and hasattr( - self.nomad_resp, "text" - ): + if isinstance(self.nomad_resp, requests.Response) and hasattr(self.nomad_resp, "text"): return f"The {self.__class__.__name__} was raised with following response: {self.nomad_resp.text}." return f"The {self.__class__.__name__} was raised due to the following error: {self.nomad_resp}" diff --git a/nomad/api/node.py b/nomad/api/node.py index a6d2727..6b4099c 100644 --- a/nomad/api/node.py +++ b/nomad/api/node.py @@ -103,13 +103,9 @@ def drain_node(self, id_, enable: bool = False): - nomad.api.exceptions.URLNotFoundNomadException """ - return self.request( - id_, "drain", params={"enable": enable}, method="post" - ).json() + return self.request(id_, "drain", params={"enable": enable}, method="post").json() - def drain_node_with_spec( - self, id_, drain_spec: Optional[dict], mark_eligible: Optional[bool] = None - ): + def drain_node_with_spec(self, id_, drain_spec: Optional[dict], mark_eligible: Optional[bool] = None): """This endpoint toggles the drain mode of the node. When draining is enabled, no further allocations will be assigned to this node, and existing allocations will be migrated to new nodes. diff --git a/nomad/api/scaling.py b/nomad/api/scaling.py index 4635822..3adf426 100644 --- a/nomad/api/scaling.py +++ b/nomad/api/scaling.py @@ -28,9 +28,7 @@ def __getattr__(self, item): raise AttributeError(msg) # we want to have common arguments name with Nomad API - def get_scaling_policies( - self, job="", type_="" - ): # pylint: disable=redefined-builtin + def get_scaling_policies(self, job="", type_=""): # pylint: disable=redefined-builtin """ This endpoint returns the scaling policies from all jobs. @@ -53,8 +51,7 @@ def get_scaling_policies( if type_ not in type_of_scaling_policies: raise nomad.api.exceptions.InvalidParameters( - "type is invalid " - f"(expected values are {type_of_scaling_policies} but got {type_})" + "type is invalid " f"(expected values are {type_of_scaling_policies} but got {type_})" ) params = {"job": job, "type": type_} diff --git a/nomad/api/search.py b/nomad/api/search.py index 3047e38..e104e41 100644 --- a/nomad/api/search.py +++ b/nomad/api/search.py @@ -59,8 +59,7 @@ def search(self, prefix, context): ) if context not in accetaple_contexts: raise nomad.api.exceptions.InvalidParameters( - "context is invalid " - f"(expected values are {accetaple_contexts} but got {context})" + "context is invalid " f"(expected values are {accetaple_contexts} but got {context})" ) params = {"Prefix": prefix, "Context": context} @@ -93,8 +92,7 @@ def fuzzy_search(self, text, context): accetaple_contexts = ("jobs", "allocs", "nodes", "plugins", "all") if context not in accetaple_contexts: raise nomad.api.exceptions.InvalidParameters( - "context is invalid " - f"(expected values are {accetaple_contexts} but got {context})" + "context is invalid " f"(expected values are {accetaple_contexts} but got {context})" ) return self.request("fuzzy", json=params, method="post").json()