nomadpy 0.2.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. nomadpy-0.4.0/PKG-INFO +67 -0
  2. nomadpy-0.4.0/README.md +38 -0
  3. {nomadpy-0.2.0 → nomadpy-0.4.0}/pyproject.toml +6 -2
  4. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/__init__.py +24 -0
  5. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/allocations.py +16 -6
  6. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/allocations_exec.py +16 -11
  7. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/api.py +20 -11
  8. nomadpy-0.4.0/src/nomadpy/batch_job_queue.py +132 -0
  9. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/constraint.py +1 -0
  10. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/consul.py +22 -1
  11. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/csi.py +13 -0
  12. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/deployments.py +3 -3
  13. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/evaluations.py +1 -1
  14. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/fs.py +1 -1
  15. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/host_volume_claims.py +1 -0
  16. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/host_volumes.py +5 -0
  17. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/jobs.py +24 -6
  18. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/models.py +8 -16
  19. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/namespace.py +1 -1
  20. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/node_pools.py +2 -0
  21. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/nodes.py +17 -0
  22. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/operator.py +1 -0
  23. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/operator_autopilot.py +1 -1
  24. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/resources.py +11 -0
  25. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/scaling.py +1 -1
  26. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/services.py +4 -0
  27. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/task_sched.py +2 -0
  28. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/tasks.py +32 -0
  29. nomadpy-0.4.0/src/nomadpy.egg-info/PKG-INFO +67 -0
  30. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy.egg-info/SOURCES.txt +2 -0
  31. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy.egg-info/requires.txt +1 -0
  32. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_api.py +24 -0
  33. nomadpy-0.4.0/tests/test_batch_job_queue.py +41 -0
  34. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_drift.py +2 -2
  35. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_exec.py +23 -0
  36. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_node_pools.py +56 -1
  37. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_wire.py +19 -0
  38. nomadpy-0.2.0/PKG-INFO +0 -116
  39. nomadpy-0.2.0/README.md +0 -92
  40. nomadpy-0.2.0/src/nomadpy.egg-info/PKG-INFO +0 -116
  41. {nomadpy-0.2.0 → nomadpy-0.4.0}/LICENSE +0 -0
  42. {nomadpy-0.2.0 → nomadpy-0.4.0}/setup.cfg +0 -0
  43. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/acl.py +0 -0
  44. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/agent.py +0 -0
  45. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/error_unexpected_response.py +0 -0
  46. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/event_stream.py +0 -0
  47. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/keyring.py +0 -0
  48. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/node_identity.py +0 -0
  49. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/node_meta.py +0 -0
  50. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/operator_metrics.py +0 -0
  51. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/quota.py +0 -0
  52. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/recommendations.py +0 -0
  53. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/regions.py +0 -0
  54. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/search.py +0 -0
  55. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/sentinel.py +0 -0
  56. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/status.py +0 -0
  57. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/system.py +0 -0
  58. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy/variables.py +0 -0
  59. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy.egg-info/dependency_links.txt +0 -0
  60. {nomadpy-0.2.0 → nomadpy-0.4.0}/src/nomadpy.egg-info/top_level.txt +0 -0
  61. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_acl.py +0 -0
  62. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_agent.py +0 -0
  63. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_allocations.py +0 -0
  64. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_deployments.py +0 -0
  65. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_enterprise.py +0 -0
  66. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_evaluations.py +0 -0
  67. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_jobs.py +0 -0
  68. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_keyring.py +0 -0
  69. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_namespace.py +0 -0
  70. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_nodes.py +0 -0
  71. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_operator.py +0 -0
  72. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_regions.py +0 -0
  73. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_scaling.py +0 -0
  74. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_services.py +0 -0
  75. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_status.py +0 -0
  76. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_streams.py +0 -0
  77. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_tls.py +0 -0
  78. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_variables.py +0 -0
  79. {nomadpy-0.2.0 → nomadpy-0.4.0}/tests/test_volumes.py +0 -0
nomadpy-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: nomadpy
3
+ Version: 0.4.0
4
+ Summary: Python client for the HashiCorp Nomad HTTP API
5
+ License-Expression: MPL-2.0
6
+ Project-URL: Homepage, https://github.com/benemon/nomadpy
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Classifier: Programming Language :: Python :: 3.14
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: System :: Clustering
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Provides-Extra: dev
18
+ Requires-Dist: pytest>=8; extra == "dev"
19
+ Requires-Dist: pytest-xdist>=3; extra == "dev"
20
+ Requires-Dist: ruff>=0.14; extra == "dev"
21
+ Provides-Extra: exec
22
+ Requires-Dist: websockets>=17; extra == "exec"
23
+ Provides-Extra: docs
24
+ Requires-Dist: mkdocs-material>=9; extra == "docs"
25
+ Requires-Dist: mkdocstrings[python]>=1; extra == "docs"
26
+ Requires-Dist: mkdocs-literate-nav>=0.6; extra == "docs"
27
+ Requires-Dist: mkdocs-macros-plugin>=1; extra == "docs"
28
+ Dynamic: license-file
29
+
30
+ # nomadpy
31
+
32
+ [![ci](https://github.com/benemon/nomadpy/actions/workflows/ci.yml/badge.svg)](https://github.com/benemon/nomadpy/actions/workflows/ci.yml) [![compat](https://github.com/benemon/nomadpy/actions/workflows/compat.yml/badge.svg)](https://github.com/benemon/nomadpy/actions/workflows/compat.yml) [![codeql](https://github.com/benemon/nomadpy/actions/workflows/codeql.yml/badge.svg)](https://github.com/benemon/nomadpy/actions/workflows/codeql.yml) [![release](https://github.com/benemon/nomadpy/actions/workflows/release.yml/badge.svg)](https://github.com/benemon/nomadpy/actions/workflows/release.yml) [![Dependabot Updates](https://github.com/benemon/nomadpy/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/benemon/nomadpy/actions/workflows/dependabot/dependabot-updates) [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/benemon/nomadpy/badge)](https://scorecard.dev/viewer/?uri=github.com/benemon/nomadpy) [![PyPI](https://img.shields.io/pypi/v/nomadpy)](https://pypi.org/project/nomadpy/)
33
+
34
+ Python client for the HashiCorp Nomad HTTP API, Community and Enterprise.
35
+ A port of the Go `api` package from `github.com/hashicorp/nomad`.
36
+ Documentation: https://benemon.github.io/nomadpy/
37
+
38
+ ```python
39
+ from nomadpy import Client
40
+
41
+ client = Client() # reads the NOMAD_* variables the Nomad CLI reads
42
+ print(client.status.leader())
43
+ ```
44
+
45
+ The variables and their meaning are documented with the Nomad CLI:
46
+ https://developer.hashicorp.com/nomad/commands#environment-variables
47
+
48
+ The package has no dependencies. Allocation exec runs over a WebSocket and
49
+ needs the `exec` extra, `pip install 'nomadpy[exec]'`, which installs the
50
+ `websockets` package.
51
+
52
+ ## Contributing
53
+
54
+ Test lanes, the drift guard and the generators are documented in
55
+ [Contributing](https://benemon.github.io/nomadpy/contributing/).
56
+
57
+ ## Releases
58
+
59
+ A release is a tag `v<version>` matching `project.version` in
60
+ `pyproject.toml`. The release workflow refuses a tag that does not match,
61
+ requires a green test run for the tagged commit, builds the sdist and wheel,
62
+ publishes them to PyPI through trusted publishing from the `pypi`
63
+ environment, and creates the GitHub release with generated notes.
64
+
65
+ Prerequisites, once: a PyPI project `nomadpy` with this repository's
66
+ `release.yml` registered as a trusted publisher for the `pypi` environment,
67
+ and that environment created in the repository settings.
@@ -0,0 +1,38 @@
1
+ # nomadpy
2
+
3
+ [![ci](https://github.com/benemon/nomadpy/actions/workflows/ci.yml/badge.svg)](https://github.com/benemon/nomadpy/actions/workflows/ci.yml) [![compat](https://github.com/benemon/nomadpy/actions/workflows/compat.yml/badge.svg)](https://github.com/benemon/nomadpy/actions/workflows/compat.yml) [![codeql](https://github.com/benemon/nomadpy/actions/workflows/codeql.yml/badge.svg)](https://github.com/benemon/nomadpy/actions/workflows/codeql.yml) [![release](https://github.com/benemon/nomadpy/actions/workflows/release.yml/badge.svg)](https://github.com/benemon/nomadpy/actions/workflows/release.yml) [![Dependabot Updates](https://github.com/benemon/nomadpy/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/benemon/nomadpy/actions/workflows/dependabot/dependabot-updates) [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/benemon/nomadpy/badge)](https://scorecard.dev/viewer/?uri=github.com/benemon/nomadpy) [![PyPI](https://img.shields.io/pypi/v/nomadpy)](https://pypi.org/project/nomadpy/)
4
+
5
+ Python client for the HashiCorp Nomad HTTP API, Community and Enterprise.
6
+ A port of the Go `api` package from `github.com/hashicorp/nomad`.
7
+ Documentation: https://benemon.github.io/nomadpy/
8
+
9
+ ```python
10
+ from nomadpy import Client
11
+
12
+ client = Client() # reads the NOMAD_* variables the Nomad CLI reads
13
+ print(client.status.leader())
14
+ ```
15
+
16
+ The variables and their meaning are documented with the Nomad CLI:
17
+ https://developer.hashicorp.com/nomad/commands#environment-variables
18
+
19
+ The package has no dependencies. Allocation exec runs over a WebSocket and
20
+ needs the `exec` extra, `pip install 'nomadpy[exec]'`, which installs the
21
+ `websockets` package.
22
+
23
+ ## Contributing
24
+
25
+ Test lanes, the drift guard and the generators are documented in
26
+ [Contributing](https://benemon.github.io/nomadpy/contributing/).
27
+
28
+ ## Releases
29
+
30
+ A release is a tag `v<version>` matching `project.version` in
31
+ `pyproject.toml`. The release workflow refuses a tag that does not match,
32
+ requires a green test run for the tagged commit, builds the sdist and wheel,
33
+ publishes them to PyPI through trusted publishing from the `pypi`
34
+ environment, and creates the GitHub release with generated notes.
35
+
36
+ Prerequisites, once: a PyPI project `nomadpy` with this repository's
37
+ `release.yml` registered as a trusted publisher for the `pypi` environment,
38
+ and that environment created in the repository settings.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "nomadpy"
7
- version = "0.2.0"
7
+ version = "0.4.0"
8
8
  description = "Python client for the HashiCorp Nomad HTTP API"
9
9
  readme = "README.md"
10
10
  license = "MPL-2.0"
@@ -12,6 +12,10 @@ requires-python = ">=3.11"
12
12
  dependencies = []
13
13
  classifiers = [
14
14
  "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
15
19
  "Operating System :: OS Independent",
16
20
  "Topic :: System :: Clustering",
17
21
  ]
@@ -22,7 +26,7 @@ Homepage = "https://github.com/benemon/nomadpy"
22
26
  [project.optional-dependencies]
23
27
  dev = ["pytest>=8", "pytest-xdist>=3", "ruff>=0.14"]
24
28
  exec = ["websockets>=17"]
25
- docs = ["mkdocs-material>=9", "mkdocstrings[python]>=1", "mkdocs-literate-nav>=0.6"]
29
+ docs = ["mkdocs-material>=9", "mkdocstrings[python]>=1", "mkdocs-literate-nav>=0.6", "mkdocs-macros-plugin>=1"]
26
30
 
27
31
  [tool.setuptools.packages.find]
28
32
  where = ["src"]
@@ -69,6 +69,19 @@ from .allocations import (
69
69
  RescheduleEvent,
70
70
  RescheduleTracker,
71
71
  )
72
+ from .batch_job_queue import (
73
+ AgeConfig,
74
+ BatchJobQueueJobsResponse,
75
+ BatchJobQueueStatusResponse,
76
+ BatchQueueConfig,
77
+ DynamicPriorityTenant,
78
+ DynamicPriorityWorkload,
79
+ DynamicQueueConfig,
80
+ FifoQueueConfig,
81
+ JobSizeConfig,
82
+ TenantFairshareConfig,
83
+ Workload,
84
+ )
72
85
  from .constraint import Constraint
73
86
  from .consul import (
74
87
  Consul,
@@ -361,6 +374,7 @@ __all__ = [
361
374
  "ACLTokenRoleLink",
362
375
  "Action",
363
376
  "Affinity",
377
+ "AgeConfig",
364
378
  "AgentHealth",
365
379
  "AgentHealthResponse",
366
380
  "AgentMember",
@@ -392,6 +406,9 @@ __all__ = [
392
406
  "AutopilotUpgrade",
393
407
  "AutopilotZone",
394
408
  "AutopilotZoneUpgradeVersions",
409
+ "BatchJobQueueJobsResponse",
410
+ "BatchJobQueueStatusResponse",
411
+ "BatchQueueConfig",
395
412
  "ChangeScript",
396
413
  "CheckRestart",
397
414
  "Client",
@@ -454,6 +471,9 @@ __all__ = [
454
471
  "DrainSpec",
455
472
  "DrainStrategy",
456
473
  "DriverInfo",
474
+ "DynamicPriorityTenant",
475
+ "DynamicPriorityWorkload",
476
+ "DynamicQueueConfig",
457
477
  "EphemeralDisk",
458
478
  "ErrCASConflict",
459
479
  "Evaluation",
@@ -461,6 +481,7 @@ __all__ = [
461
481
  "Event",
462
482
  "Events",
463
483
  "FieldDiff",
484
+ "FifoQueueConfig",
464
485
  "FuzzyMatch",
465
486
  "FuzzySearchResponse",
466
487
  "GaugeValue",
@@ -494,6 +515,7 @@ __all__ = [
494
515
  "JobUILink",
495
516
  "JobValidateResponse",
496
517
  "JobVersionTag",
518
+ "JobSizeConfig",
497
519
  "KeyringResponse",
498
520
  "License",
499
521
  "LicenseReply",
@@ -614,6 +636,7 @@ __all__ = [
614
636
  "TaskScheduleCron",
615
637
  "TaskState",
616
638
  "Template",
639
+ "TenantFairshareConfig",
617
640
  "TLSConfig",
618
641
  "UnexpectedResponseError",
619
642
  "UpdateStrategy",
@@ -626,6 +649,7 @@ __all__ = [
626
649
  "VolumeMount",
627
650
  "VolumeRequest",
628
651
  "WaitConfig",
652
+ "Workload",
629
653
  "WorkloadIdentity",
630
654
  "WriteMeta",
631
655
  "WriteOptions",
@@ -182,6 +182,7 @@ ALLOC_RESTART_REASON_WITHIN_POLICY = "Restart within policy"
182
182
 
183
183
  @dataclass
184
184
  class AllocNetworkStatus(Model):
185
+ """AllocNetworkStatus mirrors [api.AllocNetworkStatus](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#AllocNetworkStatus)."""
185
186
  interface_name: str = ""
186
187
  address: str = ""
187
188
  address_i_pv6: str = ""
@@ -190,6 +191,7 @@ class AllocNetworkStatus(Model):
190
191
 
191
192
  @dataclass
192
193
  class AllocationMetric(Model):
194
+ """AllocationMetric mirrors [api.AllocationMetric](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#AllocationMetric)."""
193
195
  nodes_evaluated: int = 0
194
196
  nodes_filtered: int = 0
195
197
  nodes_in_pool: int = 0
@@ -210,6 +212,7 @@ class AllocationMetric(Model):
210
212
 
211
213
  @dataclass
212
214
  class DesiredTransition(DesiredTransitionMethods, Model):
215
+ """DesiredTransition mirrors [api.DesiredTransition](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#DesiredTransition)."""
213
216
  migrate: bool | None = None
214
217
  reschedule: bool | None = None
215
218
  force_reschedule: bool | None = None
@@ -219,23 +222,27 @@ class DesiredTransition(DesiredTransitionMethods, Model):
219
222
 
220
223
  @dataclass
221
224
  class ExecStreamingExitResult(Model):
225
+ """ExecStreamingExitResult mirrors [api.ExecStreamingExitResult](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#ExecStreamingExitResult)."""
222
226
  exit_code: int = field(default=0, metadata={'json': 'exit_code'})
223
227
 
224
228
 
225
229
  @dataclass
226
230
  class ExecStreamingIOOperation(Model):
231
+ """ExecStreamingIOOperation mirrors [api.ExecStreamingIOOperation](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#ExecStreamingIOOperation)."""
227
232
  data: str | None = field(default=None, metadata={'json': 'data', 'omitempty': True})
228
233
  close: bool = field(default=False, metadata={'json': 'close', 'omitempty': True})
229
234
 
230
235
 
231
236
  @dataclass
232
237
  class ExecStreamingInput(Model):
238
+ """ExecStreamingInput mirrors [api.ExecStreamingInput](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#ExecStreamingInput)."""
233
239
  stdin: ExecStreamingIOOperation | None = field(default=None, metadata={'json': 'stdin', 'omitempty': True})
234
240
  tty_size: TerminalSize | None = field(default=None, metadata={'json': 'tty_size', 'omitempty': True})
235
241
 
236
242
 
237
243
  @dataclass
238
244
  class ExecStreamingOutput(Model):
245
+ """ExecStreamingOutput mirrors [api.ExecStreamingOutput](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#ExecStreamingOutput)."""
239
246
  stdout: ExecStreamingIOOperation | None = field(default=None, metadata={'json': 'stdout', 'omitempty': True})
240
247
  stderr: ExecStreamingIOOperation | None = field(default=None, metadata={'json': 'stderr', 'omitempty': True})
241
248
  exited: bool = field(default=False, metadata={'json': 'exited', 'omitempty': True})
@@ -244,6 +251,7 @@ class ExecStreamingOutput(Model):
244
251
 
245
252
  @dataclass
246
253
  class NodeScoreMeta(Model):
254
+ """NodeScoreMeta mirrors [api.NodeScoreMeta](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#NodeScoreMeta)."""
247
255
  node_id: str = field(default="", metadata={'json': 'NodeID'})
248
256
  scores: dict[str, float] | None = None
249
257
  norm_score: float = 0.0
@@ -251,12 +259,14 @@ class NodeScoreMeta(Model):
251
259
 
252
260
  @dataclass
253
261
  class TerminalSize(Model):
262
+ """TerminalSize mirrors [api.TerminalSize](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#TerminalSize)."""
254
263
  height: int = field(default=0, metadata={'json': 'height', 'omitempty': True})
255
264
  width: int = field(default=0, metadata={'json': 'width', 'omitempty': True})
256
265
 
257
266
 
258
267
  @dataclass
259
268
  class Allocation(AllocationMethods, Model):
269
+ """Allocation mirrors [api.Allocation](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#Allocation)."""
260
270
  id: str = field(default="", metadata={'json': 'ID'})
261
271
  namespace: str = ""
262
272
  eval_id: str = field(default="", metadata={'json': 'EvalID'})
@@ -296,8 +306,8 @@ class Allocation(AllocationMethods, Model):
296
306
  # end generated
297
307
 
298
308
 
299
- def stubs(resp: list[dict[str, Any]]) -> list[AllocationListStub]:
300
- """stubs decodes a list response into AllocationListStub, newest first."""
309
+ def _stubs(resp: list[dict[str, Any]]) -> list[AllocationListStub]:
310
+ """_stubs decodes a list response into AllocationListStub, newest first."""
301
311
  stubs = [AllocationListStub.from_json(a) for a in resp]
302
312
  stubs.sort(key=lambda a: a.create_index, reverse=True)
303
313
  return stubs
@@ -311,7 +321,7 @@ class Allocations:
311
321
 
312
322
  def list(self, q: QueryOptions | None = None) -> tuple[list[AllocationListStub], QueryMeta]:
313
323
  resp, qm = self._client.query("/v1/allocations", q)
314
- return stubs(resp), qm
324
+ return _stubs(resp), qm
315
325
 
316
326
  def prefix_list(self, prefix: str) -> tuple[list[AllocationListStub], QueryMeta]:
317
327
  return self.list(QueryOptions(prefix=prefix))
@@ -366,7 +376,7 @@ class Allocations:
366
376
  hangs the terminal up, so stdin must stay open until the command
367
377
  exits. `timeout` bounds the handshake and each wait for output.
368
378
  """
369
- from .allocations_exec import exec_params, run
379
+ from .allocations_exec import _exec_params, _run
370
380
 
371
- endpoint = f"/v1/client/allocation/{quote(alloc_id, safe='')}/exec?" + urlencode(exec_params(task, tty, command))
372
- return run(self._client, endpoint, q, stdin, stdout, stderr, resize, timeout)
381
+ endpoint = f"/v1/client/allocation/{quote(alloc_id, safe='')}/exec?" + urlencode(_exec_params(task, tty, command))
382
+ return _run(self._client, endpoint, q, stdin, stdout, stderr, resize, timeout)
@@ -1,16 +1,16 @@
1
1
  """Exec sessions over the allocation exec and job action WebSocket endpoints, the port of allocations_exec.go.
2
2
 
3
- The session needs the websockets package, installed by the `exec` extra. It
4
- is imported when a session starts, so the rest of the package carries no
5
- dependency. The Go session dials the allocation's node first and falls back
6
- to the server; this one always goes through the server, like every other
7
- call in the package.
3
+ The session needs the websockets package, installed by the `exec` extra.
4
+ The Go session dials the allocation's node first and falls back to the
5
+ server; this one always goes through the server, like every other call in
6
+ the package.
8
7
  """
9
8
 
10
9
  from __future__ import annotations
11
10
 
12
11
  import base64
13
12
  import json
13
+ import logging
14
14
  import threading
15
15
  from collections.abc import Iterable
16
16
  from typing import TYPE_CHECKING, BinaryIO
@@ -21,18 +21,22 @@ from .api import QueryOptions, UnexpectedResponseError
21
21
  if TYPE_CHECKING:
22
22
  from .api import Client
23
23
 
24
+ # websockets logs every handshake header, the ACL token among them, when its logger is enabled for DEBUG.
25
+ _LOG = logging.getLogger(__name__)
26
+ _LOG.setLevel(logging.INFO)
27
+
24
28
  HEARTBEAT_INTERVAL = 10.0
25
29
  STDIN_CHUNK = 2048
26
30
 
27
31
 
28
- def exec_params(task: str, tty: bool, command: list[str]) -> list[tuple[str, str]]:
32
+ def _exec_params(task: str, tty: bool, command: list[str]) -> list[tuple[str, str]]:
29
33
  # Go marshals the command without spaces; the server decodes either form, the wire fixture holds Go's.
30
34
  return [("tty", "true" if tty else "false"), ("task", task), ("command", json.dumps(command, separators=(",", ":")))]
31
35
 
32
36
 
33
- def run(client: Client, endpoint: str, q: QueryOptions | None, stdin: BinaryIO | None, stdout: BinaryIO | None, stderr: BinaryIO | None,
34
- resize: Iterable[TerminalSize] | None, timeout: float | None) -> int:
35
- """run drives one session to the command's exit and returns its exit code.
37
+ def _run(client: Client, endpoint: str, q: QueryOptions | None, stdin: BinaryIO | None, stdout: BinaryIO | None, stderr: BinaryIO | None,
38
+ resize: Iterable[TerminalSize] | None, timeout: float | None) -> int:
39
+ """_run drives one session to the command's exit and returns its exit code.
36
40
 
37
41
  stdin is pumped to the task in a thread until EOF, then closed; without
38
42
  one the task sees EOF at once. Output frames go to stdout and stderr as
@@ -46,9 +50,10 @@ def run(client: Client, endpoint: str, q: QueryOptions | None, stdin: BinaryIO |
46
50
  from websockets.sync.client import connect
47
51
  except ImportError:
48
52
  raise ImportError("allocation exec needs the websockets package: pip install 'nomadpy[exec]'") from None
49
- url, headers, ssl_context, server_name = client.websocket_target(endpoint, q)
53
+ url, headers, ssl_context, server_name = client._websocket_target(endpoint, q)
50
54
  try:
51
- with connect(url, ssl=ssl_context, server_hostname=server_name or None, additional_headers=headers, open_timeout=timeout) as conn:
55
+ with connect(url, ssl=ssl_context, server_hostname=server_name or None, additional_headers=headers, open_timeout=timeout,
56
+ logger=_LOG) as conn:
52
57
  return _session(conn, stdin, stdout, stderr, resize, timeout)
53
58
  except InvalidStatus as e:
54
59
  body = (e.response.body or b"").decode(errors="replace").strip()
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import base64
4
+ import codecs
4
5
  import http.client
5
6
  import json
6
7
  import os
@@ -9,7 +10,7 @@ import time
9
10
  import urllib.error
10
11
  import urllib.parse
11
12
  import urllib.request
12
- from dataclasses import dataclass, field
13
+ from dataclasses import dataclass, field, fields
13
14
  from datetime import timedelta
14
15
  from typing import Any
15
16
  from collections.abc import Iterator
@@ -102,6 +103,12 @@ class Config:
102
103
  tls_config: TLSConfig = field(default_factory=TLSConfig)
103
104
  headers: dict[str, str] = field(default_factory=dict)
104
105
 
106
+ def __repr__(self) -> str:
107
+ url = urllib.parse.urlsplit(self.address)
108
+ shown = {f.name: getattr(self, f.name) for f in fields(self) if f.repr}
109
+ shown["address"] = url._replace(netloc=url.netloc.rpartition("@")[2]).geturl()
110
+ return "Config(" + ", ".join(f"{k}={v!r}" for k, v in shown.items()) + ")"
111
+
105
112
 
106
113
  def default_config() -> Config:
107
114
  """default_config returns a default configuration for the client, read from the NOMAD_* environment."""
@@ -155,17 +162,18 @@ class _ServerNameHTTPSHandler(urllib.request.HTTPSHandler):
155
162
 
156
163
  def __init__(self, context: ssl.SSLContext, server_name: str):
157
164
  super().__init__(context=context)
165
+ self._ssl_context = context
158
166
  self._server_name = server_name
159
167
 
160
168
  def https_open(self, req):
161
- server_name = self._server_name
169
+ context, server_name = self._ssl_context, self._server_name
162
170
 
163
171
  class Connection(http.client.HTTPSConnection):
164
172
  def connect(self):
165
173
  http.client.HTTPConnection.connect(self)
166
- self.sock = self._context.wrap_socket(self.sock, server_hostname=server_name)
174
+ self.sock = context.wrap_socket(self.sock, server_hostname=server_name)
167
175
 
168
- return self.do_open(Connection, req, context=self._context)
176
+ return self.do_open(Connection, req, context=context)
169
177
 
170
178
 
171
179
  def _msec(d: timedelta) -> str:
@@ -213,6 +221,7 @@ class Client:
213
221
  self.agent = Agent(self)
214
222
  self.alloc_fs = AllocFS(self)
215
223
  self.allocations = Allocations(self)
224
+ self.batch_queue = BatchQueue(self)
216
225
  self.csi_plugins = CSIPlugins(self)
217
226
  self.csi_volumes = CSIVolumes(self)
218
227
  self.deployments = Deployments(self)
@@ -282,19 +291,18 @@ class Client:
282
291
  def stream_json(self, endpoint: str, q: QueryOptions | None = None, timeout: float | None = None) -> Iterator[Any]:
283
292
  """stream_json yields each JSON value of a streaming response as it arrives.
284
293
 
285
- The filesystem stream sends frames without newlines, so values are
286
- decoded from the byte stream as they complete. `timeout` bounds each
287
- wait for more bytes, as a socket timeout; close the generator to end
288
- the subscription.
294
+ `timeout` bounds each wait for more bytes, as a socket timeout; close
295
+ the generator to end the subscription.
289
296
  """
290
297
  params, headers, token = self._base_request(endpoint)
291
298
  token = self._apply_query_options(q, params, headers, token)
292
299
  resp = self._open("GET", endpoint, params, headers, token, None, (200,), timeout)
293
300
  decoder = json.JSONDecoder()
301
+ utf8 = codecs.getincrementaldecoder("utf-8")()
294
302
  buffer = ""
295
303
  try:
296
304
  while chunk := resp.read1(65536):
297
- buffer += chunk.decode()
305
+ buffer += utf8.decode(chunk)
298
306
  while True:
299
307
  buffer = buffer.lstrip()
300
308
  if not buffer:
@@ -308,8 +316,8 @@ class Client:
308
316
  finally:
309
317
  resp.close()
310
318
 
311
- def websocket_target(self, endpoint: str, q: QueryOptions | None = None) -> tuple[str, dict[str, str], ssl.SSLContext | None, str]:
312
- """websocket_target returns the ws or wss URL of `endpoint` with the query options applied, the request headers, the TLS context and the server name to verify."""
319
+ def _websocket_target(self, endpoint: str, q: QueryOptions | None = None) -> tuple[str, dict[str, str], ssl.SSLContext | None, str]:
320
+ """_websocket_target returns the ws or wss URL of `endpoint` with the query options applied, the request headers, the TLS context and the server name to verify."""
313
321
  params, headers, token = self._base_request(endpoint)
314
322
  token = self._apply_query_options(q, params, headers, token)
315
323
  self._authorize(headers, token)
@@ -446,6 +454,7 @@ def _decode(raw: bytes) -> Any:
446
454
  from .agent import Agent # noqa: E402
447
455
  from .acl import ACLAuth, ACLAuthMethods, ACLBindingRules, ACLIdentity, ACLPolicies, ACLRoles, ACLTokens # noqa: E402
448
456
  from .allocations import Allocations # noqa: E402
457
+ from .batch_job_queue import BatchQueue # noqa: E402
449
458
  from .csi import CSIPlugins, CSIVolumes # noqa: E402
450
459
  from .deployments import Deployments # noqa: E402
451
460
  from .host_volume_claims import TaskGroupHostVolumeClaims # noqa: E402
@@ -0,0 +1,132 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass, field
4
+ from typing import TYPE_CHECKING, Any
5
+
6
+ from .models import Model
7
+
8
+ if TYPE_CHECKING:
9
+ from .api import Client, QueryMeta, QueryOptions
10
+
11
+
12
+ class BatchQueue:
13
+ """BatchQueue queries the experimental batch job queue endpoints."""
14
+
15
+ def __init__(self, client: Client):
16
+ self._client = client
17
+
18
+ def jobs(self, q: QueryOptions | None = None) -> tuple[BatchJobQueueJobsResponse, QueryMeta]:
19
+ resp, qm = self._client.query("/v1/queue/jobs", q)
20
+ return BatchJobQueueJobsResponse.from_json(resp), qm
21
+
22
+ def status(self, q: QueryOptions | None = None) -> tuple[BatchJobQueueStatusResponse, QueryMeta]:
23
+ resp, qm = self._client.query("/v1/queue/status", q)
24
+ return BatchJobQueueStatusResponse.from_json(resp), qm
25
+
26
+
27
+ # generated from surface.json: file=batch_job_queue.go
28
+
29
+ BATCH_QUEUE_TENANT_METADATA = "metadata"
30
+ BATCH_QUEUE_TENANT_NAMESPACE = "namespace"
31
+ BATCH_QUEUE_TYPE_DYNAMIC = "dynamic_priority"
32
+ BATCH_QUEUE_TYPE_FIFO = "fifo"
33
+ BATCH_QUEUE_TYPE_PASSTHROUGH = "passthrough"
34
+
35
+
36
+ @dataclass
37
+ class AgeConfig(Model):
38
+ """AgeConfig mirrors [api.AgeConfig](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#AgeConfig)."""
39
+ weight: int = 0
40
+ max: int = 0
41
+
42
+
43
+ @dataclass
44
+ class BatchJobQueueJobsResponse(Model):
45
+ """BatchJobQueueJobsResponse mirrors [api.BatchJobQueueJobsResponse](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#BatchJobQueueJobsResponse)."""
46
+ type: str = ""
47
+ workloads: Any = None
48
+
49
+
50
+ @dataclass
51
+ class BatchJobQueueStatusResponse(Model):
52
+ """BatchJobQueueStatusResponse mirrors [api.BatchJobQueueStatusResponse](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#BatchJobQueueStatusResponse)."""
53
+ type: str = ""
54
+ status: Any = None
55
+
56
+
57
+ @dataclass
58
+ class BatchQueueConfig(Model):
59
+ """BatchQueueConfig mirrors [api.BatchQueueConfig](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#BatchQueueConfig)."""
60
+ constraint_timeout: int = 0
61
+ dynamic_priority: DynamicQueueConfig | None = None
62
+ fifo: FifoQueueConfig | None = None
63
+
64
+
65
+ @dataclass
66
+ class DynamicPriorityTenant(Model):
67
+ """DynamicPriorityTenant mirrors [api.DynamicPriorityTenant](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#DynamicPriorityTenant)."""
68
+ tenant_id: str = field(default="", metadata={'json': 'TenantID'})
69
+ percentage_used: int = 0
70
+ tenant_fairshare: dict[str, float] | None = None
71
+ total_fairshare: dict[str, float] | None = None
72
+
73
+
74
+ @dataclass
75
+ class DynamicPriorityWorkload(Model):
76
+ """DynamicPriorityWorkload mirrors [api.DynamicPriorityWorkload](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#DynamicPriorityWorkload)."""
77
+ job_id: str = field(default="", metadata={'json': 'JobID'})
78
+ tenant: str = ""
79
+ status: str = ""
80
+ position: int = 0
81
+ adjusted_priority: int = 0
82
+ base_priority: int = 0
83
+ fairshare_adjustment: int = 0
84
+ age_adjustment: int = 0
85
+ cpu_adjustment: int = 0
86
+ memory_adjustment: int = 0
87
+ created_at: int = 0
88
+
89
+
90
+ @dataclass
91
+ class FifoQueueConfig(Model):
92
+ """FifoQueueConfig mirrors [api.FifoQueueConfig](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#FifoQueueConfig)."""
93
+
94
+
95
+ @dataclass
96
+ class JobSizeConfig(Model):
97
+ """JobSizeConfig mirrors [api.JobSizeConfig](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#JobSizeConfig)."""
98
+ cpu_weight: int = 0
99
+ cpu_max: int = 0
100
+ memory_weight: int = 0
101
+ memory_max: int = 0
102
+
103
+
104
+ @dataclass
105
+ class TenantFairshareConfig(Model):
106
+ """TenantFairshareConfig mirrors [api.TenantFairshareConfig](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#TenantFairshareConfig)."""
107
+ tenant_type: str = ""
108
+ metadata_key: str = ""
109
+ cpu_weight: int = 0
110
+ memory_weight: int = 0
111
+ exclude_alloc_statuses: list[str] | None = None
112
+
113
+
114
+ @dataclass
115
+ class Workload(Model):
116
+ """Workload mirrors [api.Workload](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#Workload)."""
117
+ job_id: str = field(default="", metadata={'json': 'JobID'})
118
+ position: int = 0
119
+ status: str = ""
120
+ created_at: int = 0
121
+
122
+
123
+ @dataclass
124
+ class DynamicQueueConfig(Model):
125
+ """DynamicQueueConfig mirrors [api.DynamicQueueConfig](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#DynamicQueueConfig)."""
126
+ calc_interval: int = 0
127
+ tenant_fairshare: TenantFairshareConfig = field(default_factory=TenantFairshareConfig)
128
+ age: AgeConfig = field(default_factory=AgeConfig)
129
+ job_size: JobSizeConfig = field(default_factory=JobSizeConfig)
130
+
131
+
132
+ # end generated
@@ -21,6 +21,7 @@ CONSTRAINT_ATTRIBUTE_IS_NOT_SET = "is_not_set"
21
21
 
22
22
  @dataclass
23
23
  class Constraint(Model):
24
+ """Constraint mirrors [api.Constraint](https://pkg.go.dev/github.com/hashicorp/nomad/api@v0.0.0-20261102183041-8384458dc8ac#Constraint)."""
24
25
  l_target: str = ""
25
26
  r_target: str = ""
26
27
  operand: str = ""