lex-nomad 0.1.1
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.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +16 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +50 -0
- data/CHANGELOG.md +12 -0
- data/CLAUDE.md +57 -0
- data/Dockerfile +6 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +171 -0
- data/LICENSE +21 -0
- data/README.md +68 -0
- data/lex-nomad.gemspec +37 -0
- data/lib/legion/extensions/nomad/client.rb +43 -0
- data/lib/legion/extensions/nomad/helpers/client.rb +22 -0
- data/lib/legion/extensions/nomad/runners/allocations.rb +59 -0
- data/lib/legion/extensions/nomad/runners/deployments.rb +66 -0
- data/lib/legion/extensions/nomad/runners/evaluations.rb +45 -0
- data/lib/legion/extensions/nomad/runners/jobs.rb +130 -0
- data/lib/legion/extensions/nomad/runners/namespaces.rb +42 -0
- data/lib/legion/extensions/nomad/runners/nodes.rb +60 -0
- data/lib/legion/extensions/nomad/runners/search.rb +30 -0
- data/lib/legion/extensions/nomad/runners/services.rb +33 -0
- data/lib/legion/extensions/nomad/runners/status.rb +28 -0
- data/lib/legion/extensions/nomad/runners/variables.rb +41 -0
- data/lib/legion/extensions/nomad/version.rb +9 -0
- data/lib/legion/extensions/nomad.rb +23 -0
- metadata +184 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ea9788d8ae72a73c8314fcfc45eca2c0cdbe55f2dbf05bbc0c638e7b62fdd5bb
|
|
4
|
+
data.tar.gz: 41b14d70b2477aefdd7ccf780864e961b384844b10fc4218e45f0233bbc7343f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a098209444e9c8faa88d37156ab9764997aa840577dade17d34fc7dd580f8e25e6f48e712eea33b70161c539ce99bc118338d1e4b84012d9333d15802c0832b4
|
|
7
|
+
data.tar.gz: ee0a2589d45e81758cfafa92c8b7b292b2b69762bcadf70eb7d6bc64b90aa1806875744d418869e8de5dfb8d2608e2dac1f6d5cf00cefe7987af0ea99becfd2b
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
ci:
|
|
9
|
+
uses: LegionIO/.github/.github/workflows/ci.yml@main
|
|
10
|
+
|
|
11
|
+
release:
|
|
12
|
+
needs: ci
|
|
13
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
14
|
+
uses: LegionIO/.github/.github/workflows/release.yml@main
|
|
15
|
+
secrets:
|
|
16
|
+
rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.4
|
|
3
|
+
NewCops: enable
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
|
|
6
|
+
Layout/LineLength:
|
|
7
|
+
Max: 160
|
|
8
|
+
|
|
9
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
|
10
|
+
EnforcedStyle: space
|
|
11
|
+
|
|
12
|
+
Layout/HashAlignment:
|
|
13
|
+
EnforcedHashRocketStyle: table
|
|
14
|
+
EnforcedColonStyle: table
|
|
15
|
+
|
|
16
|
+
Metrics/MethodLength:
|
|
17
|
+
Max: 50
|
|
18
|
+
|
|
19
|
+
Metrics/ClassLength:
|
|
20
|
+
Max: 1500
|
|
21
|
+
|
|
22
|
+
Metrics/ModuleLength:
|
|
23
|
+
Max: 1500
|
|
24
|
+
|
|
25
|
+
Metrics/BlockLength:
|
|
26
|
+
Max: 40
|
|
27
|
+
Exclude:
|
|
28
|
+
- 'spec/**/*'
|
|
29
|
+
|
|
30
|
+
Metrics/AbcSize:
|
|
31
|
+
Max: 60
|
|
32
|
+
|
|
33
|
+
Metrics/CyclomaticComplexity:
|
|
34
|
+
Max: 15
|
|
35
|
+
|
|
36
|
+
Metrics/PerceivedComplexity:
|
|
37
|
+
Max: 17
|
|
38
|
+
|
|
39
|
+
Style/Documentation:
|
|
40
|
+
Enabled: false
|
|
41
|
+
|
|
42
|
+
Style/SymbolArray:
|
|
43
|
+
Enabled: true
|
|
44
|
+
|
|
45
|
+
Style/FrozenStringLiteralComment:
|
|
46
|
+
Enabled: true
|
|
47
|
+
EnforcedStyle: always
|
|
48
|
+
|
|
49
|
+
Naming/FileName:
|
|
50
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.1] - 2026-03-22
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- Add runtime dependencies for all 7 legion sub-gems (legion-cache, legion-crypt, legion-data, legion-json, legion-logging, legion-settings, legion-transport)
|
|
7
|
+
- Update spec_helper with real sub-gem helper requires and Helpers::Lex stub
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-03-13
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- Initial release
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# lex-nomad: HashiCorp Nomad Integration for LegionIO
|
|
2
|
+
|
|
3
|
+
**Repository Level 3 Documentation**
|
|
4
|
+
- **Parent (Level 2)**: `/Users/miverso2/rubymine/legion/extensions/CLAUDE.md`
|
|
5
|
+
- **Parent (Level 1)**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
|
|
6
|
+
|
|
7
|
+
## Purpose
|
|
8
|
+
|
|
9
|
+
Legion Extension that connects LegionIO to HashiCorp Nomad. Provides runners for interacting with the full Nomad HTTP API v1 covering jobs, nodes, allocations, deployments, evaluations, namespaces, services, variables, cluster status, and search.
|
|
10
|
+
|
|
11
|
+
**GitHub**: https://github.com/LegionIO/lex-nomad
|
|
12
|
+
**License**: MIT
|
|
13
|
+
**Version**: 0.1.0
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
Legion::Extensions::Nomad
|
|
19
|
+
├── Runners/
|
|
20
|
+
│ ├── Jobs # CRUD jobs, plan, dispatch, revert, scale, versions, summary
|
|
21
|
+
│ ├── Nodes # List/get nodes, drain, purge, eligibility
|
|
22
|
+
│ ├── Allocations # List/get/stop/signal/restart allocations, services, checks
|
|
23
|
+
│ ├── Deployments # List/get deployments, fail, pause, promote, health, unblock
|
|
24
|
+
│ ├── Evaluations # List/get/delete evaluations, count
|
|
25
|
+
│ ├── Namespaces # CRUD namespaces
|
|
26
|
+
│ ├── Services # List/get/delete service registrations
|
|
27
|
+
│ ├── Variables # CRUD variables (Nomad KV)
|
|
28
|
+
│ ├── Status # Cluster leader and raft peers
|
|
29
|
+
│ └── Search # Prefix and fuzzy search across resources
|
|
30
|
+
├── Helpers/
|
|
31
|
+
│ └── Client # Faraday connection builder (Nomad API v1)
|
|
32
|
+
└── Client # Standalone client class (includes all runners)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Dependencies
|
|
36
|
+
|
|
37
|
+
| Gem | Purpose |
|
|
38
|
+
|-----|---------|
|
|
39
|
+
| `faraday` (>= 2.0) | HTTP client for Nomad REST API |
|
|
40
|
+
|
|
41
|
+
## Connection
|
|
42
|
+
|
|
43
|
+
Authentication uses `X-Nomad-Token` header (ACL token). Namespace scoping via `namespace` query parameter. Default address: `http://127.0.0.1:4646`.
|
|
44
|
+
|
|
45
|
+
## Testing
|
|
46
|
+
|
|
47
|
+
48 specs across 12 spec files.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
bundle install
|
|
51
|
+
bundle exec rspec
|
|
52
|
+
bundle exec rubocop
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
**Maintained By**: Matthew Iverson (@Esity)
|
data/Dockerfile
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
lex-nomad (0.1.1)
|
|
5
|
+
faraday (>= 2.0)
|
|
6
|
+
legion-cache (>= 1.3.11)
|
|
7
|
+
legion-crypt (>= 1.4.9)
|
|
8
|
+
legion-data (>= 1.4.17)
|
|
9
|
+
legion-json (>= 1.2.1)
|
|
10
|
+
legion-logging (>= 1.3.2)
|
|
11
|
+
legion-settings (>= 1.3.14)
|
|
12
|
+
legion-transport (>= 1.3.9)
|
|
13
|
+
|
|
14
|
+
GEM
|
|
15
|
+
remote: https://rubygems.org/
|
|
16
|
+
specs:
|
|
17
|
+
addressable (2.8.9)
|
|
18
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
19
|
+
amq-protocol (2.5.1)
|
|
20
|
+
ast (2.4.3)
|
|
21
|
+
aws-eventstream (1.4.0)
|
|
22
|
+
aws-sigv4 (1.12.1)
|
|
23
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
|
24
|
+
base64 (0.3.0)
|
|
25
|
+
bigdecimal (4.0.1)
|
|
26
|
+
bunny (2.24.0)
|
|
27
|
+
amq-protocol (~> 2.3)
|
|
28
|
+
sorted_set (~> 1, >= 1.0.2)
|
|
29
|
+
concurrent-ruby (1.3.6)
|
|
30
|
+
connection_pool (2.5.5)
|
|
31
|
+
dalli (5.0.2)
|
|
32
|
+
logger
|
|
33
|
+
diff-lcs (1.6.2)
|
|
34
|
+
docile (1.4.1)
|
|
35
|
+
ed25519 (1.4.0)
|
|
36
|
+
faraday (2.14.1)
|
|
37
|
+
faraday-net_http (>= 2.0, < 3.5)
|
|
38
|
+
json
|
|
39
|
+
logger
|
|
40
|
+
faraday-net_http (3.4.2)
|
|
41
|
+
net-http (~> 0.5)
|
|
42
|
+
json (2.19.1)
|
|
43
|
+
json-schema (6.2.0)
|
|
44
|
+
addressable (~> 2.8)
|
|
45
|
+
bigdecimal (>= 3.1, < 5)
|
|
46
|
+
json_pure (2.8.1)
|
|
47
|
+
jwt (3.1.2)
|
|
48
|
+
base64
|
|
49
|
+
language_server-protocol (3.17.0.5)
|
|
50
|
+
legion-cache (1.3.11)
|
|
51
|
+
connection_pool (>= 2.4)
|
|
52
|
+
dalli (>= 3.0)
|
|
53
|
+
legion-logging (>= 1.2.8)
|
|
54
|
+
legion-settings (>= 1.3.12)
|
|
55
|
+
redis (>= 5.0)
|
|
56
|
+
legion-crypt (1.4.9)
|
|
57
|
+
ed25519 (~> 1.3)
|
|
58
|
+
jwt (>= 2.7)
|
|
59
|
+
vault (>= 0.17)
|
|
60
|
+
legion-data (1.4.17)
|
|
61
|
+
legion-logging (>= 1.2.8)
|
|
62
|
+
legion-settings (>= 1.3.12)
|
|
63
|
+
sequel (>= 5.70)
|
|
64
|
+
sqlite3 (>= 2.0)
|
|
65
|
+
legion-json (1.2.1)
|
|
66
|
+
json_pure
|
|
67
|
+
multi_json
|
|
68
|
+
legion-logging (1.3.2)
|
|
69
|
+
logger
|
|
70
|
+
rainbow (~> 3)
|
|
71
|
+
legion-settings (1.3.14)
|
|
72
|
+
legion-json (>= 1.2.0)
|
|
73
|
+
legion-transport (1.3.9)
|
|
74
|
+
bunny (>= 2.23)
|
|
75
|
+
concurrent-ruby (>= 1.2)
|
|
76
|
+
legion-json (>= 1.2.0)
|
|
77
|
+
legion-settings (>= 1.3.12)
|
|
78
|
+
logger
|
|
79
|
+
lint_roller (1.1.0)
|
|
80
|
+
logger (1.7.0)
|
|
81
|
+
mcp (0.8.0)
|
|
82
|
+
json-schema (>= 4.1)
|
|
83
|
+
mini_portile2 (2.8.9)
|
|
84
|
+
multi_json (1.19.1)
|
|
85
|
+
net-http (0.9.1)
|
|
86
|
+
uri (>= 0.11.1)
|
|
87
|
+
net-http-persistent (4.0.8)
|
|
88
|
+
connection_pool (>= 2.2.4, < 4)
|
|
89
|
+
parallel (1.27.0)
|
|
90
|
+
parser (3.3.10.2)
|
|
91
|
+
ast (~> 2.4.1)
|
|
92
|
+
racc
|
|
93
|
+
prism (1.9.0)
|
|
94
|
+
public_suffix (7.0.5)
|
|
95
|
+
racc (1.8.1)
|
|
96
|
+
rainbow (3.1.1)
|
|
97
|
+
rake (13.3.1)
|
|
98
|
+
rbtree (0.4.6)
|
|
99
|
+
redis (5.4.1)
|
|
100
|
+
redis-client (>= 0.22.0)
|
|
101
|
+
redis-client (0.28.0)
|
|
102
|
+
connection_pool
|
|
103
|
+
regexp_parser (2.11.3)
|
|
104
|
+
rspec (3.13.2)
|
|
105
|
+
rspec-core (~> 3.13.0)
|
|
106
|
+
rspec-expectations (~> 3.13.0)
|
|
107
|
+
rspec-mocks (~> 3.13.0)
|
|
108
|
+
rspec-core (3.13.6)
|
|
109
|
+
rspec-support (~> 3.13.0)
|
|
110
|
+
rspec-expectations (3.13.5)
|
|
111
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
112
|
+
rspec-support (~> 3.13.0)
|
|
113
|
+
rspec-mocks (3.13.8)
|
|
114
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
115
|
+
rspec-support (~> 3.13.0)
|
|
116
|
+
rspec-support (3.13.7)
|
|
117
|
+
rspec_junit_formatter (0.6.0)
|
|
118
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
|
119
|
+
rubocop (1.85.1)
|
|
120
|
+
json (~> 2.3)
|
|
121
|
+
language_server-protocol (~> 3.17.0.2)
|
|
122
|
+
lint_roller (~> 1.1.0)
|
|
123
|
+
mcp (~> 0.6)
|
|
124
|
+
parallel (~> 1.10)
|
|
125
|
+
parser (>= 3.3.0.2)
|
|
126
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
127
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
128
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
129
|
+
ruby-progressbar (~> 1.7)
|
|
130
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
131
|
+
rubocop-ast (1.49.1)
|
|
132
|
+
parser (>= 3.3.7.2)
|
|
133
|
+
prism (~> 1.7)
|
|
134
|
+
ruby-progressbar (1.13.0)
|
|
135
|
+
sequel (5.102.0)
|
|
136
|
+
bigdecimal
|
|
137
|
+
simplecov (0.22.0)
|
|
138
|
+
docile (~> 1.1)
|
|
139
|
+
simplecov-html (~> 0.11)
|
|
140
|
+
simplecov_json_formatter (~> 0.1)
|
|
141
|
+
simplecov-html (0.13.2)
|
|
142
|
+
simplecov_json_formatter (0.1.4)
|
|
143
|
+
sorted_set (1.1.0)
|
|
144
|
+
rbtree
|
|
145
|
+
sqlite3 (2.9.2)
|
|
146
|
+
mini_portile2 (~> 2.8.0)
|
|
147
|
+
sqlite3 (2.9.2-arm64-darwin)
|
|
148
|
+
unicode-display_width (3.2.0)
|
|
149
|
+
unicode-emoji (~> 4.1)
|
|
150
|
+
unicode-emoji (4.2.0)
|
|
151
|
+
uri (1.1.1)
|
|
152
|
+
vault (0.20.0)
|
|
153
|
+
aws-sigv4
|
|
154
|
+
base64
|
|
155
|
+
connection_pool (~> 2.4)
|
|
156
|
+
net-http-persistent (~> 4.0, >= 4.0.2)
|
|
157
|
+
|
|
158
|
+
PLATFORMS
|
|
159
|
+
arm64-darwin-25
|
|
160
|
+
ruby
|
|
161
|
+
|
|
162
|
+
DEPENDENCIES
|
|
163
|
+
lex-nomad!
|
|
164
|
+
rake
|
|
165
|
+
rspec
|
|
166
|
+
rspec_junit_formatter
|
|
167
|
+
rubocop
|
|
168
|
+
simplecov
|
|
169
|
+
|
|
170
|
+
BUNDLED WITH
|
|
171
|
+
2.6.9
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Esity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# lex-nomad
|
|
2
|
+
|
|
3
|
+
HashiCorp Nomad integration for [LegionIO](https://github.com/LegionIO/LegionIO). Provides runners for interacting with the Nomad HTTP API covering jobs, nodes, allocations, deployments, evaluations, namespaces, services, variables, status, and search.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
gem install lex-nomad
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Functions
|
|
12
|
+
|
|
13
|
+
### Jobs
|
|
14
|
+
`list_jobs`, `get_job`, `create_job`, `update_job`, `delete_job`, `plan_job`, `dispatch_job`, `revert_job`, `job_versions`, `job_summary`, `job_allocations`, `job_evaluations`, `job_deployments`, `job_latest_deployment`, `evaluate_job`, `force_periodic_job`, `scale_job`, `job_scale_status`, `job_services`, `parse_job`
|
|
15
|
+
|
|
16
|
+
### Nodes
|
|
17
|
+
`list_nodes`, `get_node`, `node_allocations`, `evaluate_node`, `drain_node`, `purge_node`, `set_node_eligibility`
|
|
18
|
+
|
|
19
|
+
### Allocations
|
|
20
|
+
`list_allocations`, `get_allocation`, `stop_allocation`, `signal_allocation`, `restart_allocation`, `allocation_services`, `allocation_checks`
|
|
21
|
+
|
|
22
|
+
### Deployments
|
|
23
|
+
`list_deployments`, `get_deployment`, `deployment_allocations`, `fail_deployment`, `pause_deployment`, `promote_deployment`, `set_allocation_health`, `unblock_deployment`
|
|
24
|
+
|
|
25
|
+
### Evaluations
|
|
26
|
+
`list_evaluations`, `get_evaluation`, `evaluation_allocations`, `evaluations_count`, `delete_evaluations`
|
|
27
|
+
|
|
28
|
+
### Namespaces
|
|
29
|
+
`list_namespaces`, `get_namespace`, `create_or_update_namespace`, `delete_namespace`
|
|
30
|
+
|
|
31
|
+
### Services
|
|
32
|
+
`list_services`, `get_service`, `delete_service`
|
|
33
|
+
|
|
34
|
+
### Variables
|
|
35
|
+
`list_variables`, `get_variable`, `create_or_update_variable`, `delete_variable`
|
|
36
|
+
|
|
37
|
+
### Status
|
|
38
|
+
`leader`, `peers`
|
|
39
|
+
|
|
40
|
+
### Search
|
|
41
|
+
`prefix_search`, `fuzzy_search`
|
|
42
|
+
|
|
43
|
+
## Standalone Usage
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
require 'legion/extensions/nomad'
|
|
47
|
+
|
|
48
|
+
client = Legion::Extensions::Nomad::Client.new(
|
|
49
|
+
address: 'http://nomad.example.com:4646',
|
|
50
|
+
token: 'your-acl-token',
|
|
51
|
+
namespace: 'default'
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
client.list_jobs
|
|
55
|
+
client.get_job(job_id: 'my-service')
|
|
56
|
+
client.leader
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Requirements
|
|
60
|
+
|
|
61
|
+
- Ruby >= 3.4
|
|
62
|
+
- [LegionIO](https://github.com/LegionIO/LegionIO) framework (optional for standalone client usage)
|
|
63
|
+
- HashiCorp Nomad cluster (API v1)
|
|
64
|
+
- `faraday` >= 2.0
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
data/lex-nomad.gemspec
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/legion/extensions/nomad/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'lex-nomad'
|
|
7
|
+
spec.version = Legion::Extensions::Nomad::VERSION
|
|
8
|
+
spec.authors = ['Esity']
|
|
9
|
+
spec.email = ['matthewdiverson@gmail.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'LEX Nomad'
|
|
12
|
+
spec.description = 'Connects LegionIO to HashiCorp Nomad'
|
|
13
|
+
spec.homepage = 'https://github.com/LegionIO/lex-nomad'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 3.4'
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-nomad'
|
|
19
|
+
spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-nomad'
|
|
20
|
+
spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-nomad'
|
|
21
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-nomad/issues'
|
|
22
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
23
|
+
|
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
26
|
+
end
|
|
27
|
+
spec.require_paths = ['lib']
|
|
28
|
+
|
|
29
|
+
spec.add_dependency 'faraday', '>= 2.0'
|
|
30
|
+
spec.add_dependency 'legion-cache', '>= 1.3.11'
|
|
31
|
+
spec.add_dependency 'legion-crypt', '>= 1.4.9'
|
|
32
|
+
spec.add_dependency 'legion-data', '>= 1.4.17'
|
|
33
|
+
spec.add_dependency 'legion-json', '>= 1.2.1'
|
|
34
|
+
spec.add_dependency 'legion-logging', '>= 1.3.2'
|
|
35
|
+
spec.add_dependency 'legion-settings', '>= 1.3.14'
|
|
36
|
+
spec.add_dependency 'legion-transport', '>= 1.3.9'
|
|
37
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
require 'legion/extensions/nomad/runners/jobs'
|
|
5
|
+
require 'legion/extensions/nomad/runners/nodes'
|
|
6
|
+
require 'legion/extensions/nomad/runners/allocations'
|
|
7
|
+
require 'legion/extensions/nomad/runners/deployments'
|
|
8
|
+
require 'legion/extensions/nomad/runners/evaluations'
|
|
9
|
+
require 'legion/extensions/nomad/runners/namespaces'
|
|
10
|
+
require 'legion/extensions/nomad/runners/services'
|
|
11
|
+
require 'legion/extensions/nomad/runners/variables'
|
|
12
|
+
require 'legion/extensions/nomad/runners/status'
|
|
13
|
+
require 'legion/extensions/nomad/runners/search'
|
|
14
|
+
|
|
15
|
+
module Legion
|
|
16
|
+
module Extensions
|
|
17
|
+
module Nomad
|
|
18
|
+
class Client
|
|
19
|
+
include Helpers::Client
|
|
20
|
+
include Runners::Jobs
|
|
21
|
+
include Runners::Nodes
|
|
22
|
+
include Runners::Allocations
|
|
23
|
+
include Runners::Deployments
|
|
24
|
+
include Runners::Evaluations
|
|
25
|
+
include Runners::Namespaces
|
|
26
|
+
include Runners::Services
|
|
27
|
+
include Runners::Variables
|
|
28
|
+
include Runners::Status
|
|
29
|
+
include Runners::Search
|
|
30
|
+
|
|
31
|
+
attr_reader :opts
|
|
32
|
+
|
|
33
|
+
def initialize(address: 'http://127.0.0.1:4646', token: nil, namespace: nil, **extra)
|
|
34
|
+
@opts = { address: address, token: token, namespace: namespace, **extra }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def connection(**override)
|
|
38
|
+
super(**@opts.merge(override))
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Helpers
|
|
9
|
+
module Client
|
|
10
|
+
def connection(address: 'http://127.0.0.1:4646', token: nil, namespace: nil, **_opts)
|
|
11
|
+
Faraday.new(url: address) do |conn|
|
|
12
|
+
conn.request :json
|
|
13
|
+
conn.response :json, content_type: /\bjson$/
|
|
14
|
+
conn.headers['X-Nomad-Token'] = token if token
|
|
15
|
+
conn.params['namespace'] = namespace if namespace
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Runners
|
|
9
|
+
module Allocations
|
|
10
|
+
include Legion::Extensions::Nomad::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_allocations(prefix: nil, **)
|
|
13
|
+
params = {}
|
|
14
|
+
params[:prefix] = prefix if prefix
|
|
15
|
+
response = connection(**).get('/v1/allocations', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_allocation(alloc_id:, **)
|
|
20
|
+
response = connection(**).get("/v1/allocation/#{alloc_id}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def stop_allocation(alloc_id:, **)
|
|
25
|
+
response = connection(**).post("/v1/allocation/#{alloc_id}/stop")
|
|
26
|
+
{ result: response.body }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def signal_allocation(alloc_id:, signal: 'SIGTERM', task: nil, **)
|
|
30
|
+
body = { Signal: signal }
|
|
31
|
+
body[:Task] = task if task
|
|
32
|
+
response = connection(**).post("/v1/client/allocation/#{alloc_id}/signal", body)
|
|
33
|
+
{ result: response.body }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def restart_allocation(alloc_id:, task: nil, all_tasks: false, **)
|
|
37
|
+
body = { AllTasks: all_tasks }
|
|
38
|
+
body[:TaskName] = task if task
|
|
39
|
+
response = connection(**).post("/v1/client/allocation/#{alloc_id}/restart", body)
|
|
40
|
+
{ result: response.body }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def allocation_services(alloc_id:, **)
|
|
44
|
+
response = connection(**).get("/v1/allocation/#{alloc_id}/services")
|
|
45
|
+
{ result: response.body }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def allocation_checks(alloc_id:, **)
|
|
49
|
+
response = connection(**).get("/v1/allocation/#{alloc_id}/checks")
|
|
50
|
+
{ result: response.body }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
54
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Runners
|
|
9
|
+
module Deployments
|
|
10
|
+
include Legion::Extensions::Nomad::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_deployments(prefix: nil, **)
|
|
13
|
+
params = {}
|
|
14
|
+
params[:prefix] = prefix if prefix
|
|
15
|
+
response = connection(**).get('/v1/deployments', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_deployment(deployment_id:, **)
|
|
20
|
+
response = connection(**).get("/v1/deployment/#{deployment_id}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def deployment_allocations(deployment_id:, **)
|
|
25
|
+
response = connection(**).get("/v1/deployment/allocations/#{deployment_id}")
|
|
26
|
+
{ result: response.body }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def fail_deployment(deployment_id:, **)
|
|
30
|
+
response = connection(**).post("/v1/deployment/fail/#{deployment_id}")
|
|
31
|
+
{ result: response.body }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def pause_deployment(deployment_id:, pause: true, **)
|
|
35
|
+
body = { DeploymentID: deployment_id, Pause: pause }
|
|
36
|
+
response = connection(**).post("/v1/deployment/pause/#{deployment_id}", body)
|
|
37
|
+
{ result: response.body }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def promote_deployment(deployment_id:, all: true, groups: nil, **)
|
|
41
|
+
body = { DeploymentID: deployment_id, All: all }
|
|
42
|
+
body[:Groups] = groups if groups
|
|
43
|
+
response = connection(**).post("/v1/deployment/promote/#{deployment_id}", body)
|
|
44
|
+
{ result: response.body }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def set_allocation_health(deployment_id:, healthy_ids: nil, unhealthy_ids: nil, **)
|
|
48
|
+
body = { DeploymentID: deployment_id }
|
|
49
|
+
body[:HealthyAllocationIDs] = healthy_ids if healthy_ids
|
|
50
|
+
body[:UnhealthyAllocationIDs] = unhealthy_ids if unhealthy_ids
|
|
51
|
+
response = connection(**).post("/v1/deployment/allocation-health/#{deployment_id}", body)
|
|
52
|
+
{ result: response.body }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def unblock_deployment(deployment_id:, **)
|
|
56
|
+
response = connection(**).post("/v1/deployment/unblock/#{deployment_id}")
|
|
57
|
+
{ result: response.body }
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
61
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Runners
|
|
9
|
+
module Evaluations
|
|
10
|
+
include Legion::Extensions::Nomad::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_evaluations(prefix: nil, **)
|
|
13
|
+
params = {}
|
|
14
|
+
params[:prefix] = prefix if prefix
|
|
15
|
+
response = connection(**).get('/v1/evaluations', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_evaluation(eval_id:, **)
|
|
20
|
+
response = connection(**).get("/v1/evaluation/#{eval_id}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def evaluation_allocations(eval_id:, **)
|
|
25
|
+
response = connection(**).get("/v1/evaluation/#{eval_id}/allocations")
|
|
26
|
+
{ result: response.body }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def evaluations_count(**)
|
|
30
|
+
response = connection(**).get('/v1/evaluations/count')
|
|
31
|
+
{ result: response.body }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def delete_evaluations(eval_ids:, **)
|
|
35
|
+
response = connection(**).delete('/v1/evaluations', { EvalIDs: eval_ids })
|
|
36
|
+
{ result: response.body }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
40
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Runners
|
|
9
|
+
module Jobs
|
|
10
|
+
include Legion::Extensions::Nomad::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_jobs(prefix: nil, **)
|
|
13
|
+
params = {}
|
|
14
|
+
params[:prefix] = prefix if prefix
|
|
15
|
+
response = connection(**).get('/v1/jobs', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_job(job_id:, **)
|
|
20
|
+
response = connection(**).get("/v1/job/#{job_id}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_job(job:, **)
|
|
25
|
+
response = connection(**).post('/v1/jobs', { Job: job })
|
|
26
|
+
{ result: response.body }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def update_job(job_id:, job:, **)
|
|
30
|
+
response = connection(**).post("/v1/job/#{job_id}", { Job: job })
|
|
31
|
+
{ result: response.body }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def delete_job(job_id:, purge: false, **)
|
|
35
|
+
params = {}
|
|
36
|
+
params[:purge] = true if purge
|
|
37
|
+
response = connection(**).delete("/v1/job/#{job_id}", params)
|
|
38
|
+
{ result: response.body }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def plan_job(job_id:, job:, diff: true, **)
|
|
42
|
+
response = connection(**).post("/v1/job/#{job_id}/plan", { Job: job, Diff: diff })
|
|
43
|
+
{ result: response.body }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def dispatch_job(job_id:, payload: nil, meta: nil, **)
|
|
47
|
+
body = {}
|
|
48
|
+
body[:Payload] = payload if payload
|
|
49
|
+
body[:Meta] = meta if meta
|
|
50
|
+
response = connection(**).post("/v1/job/#{job_id}/dispatch", body)
|
|
51
|
+
{ result: response.body }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def revert_job(job_id:, version:, enforce_prior_version: nil, **)
|
|
55
|
+
body = { JobID: job_id, JobVersion: version }
|
|
56
|
+
body[:EnforcePriorVersion] = enforce_prior_version unless enforce_prior_version.nil?
|
|
57
|
+
response = connection(**).post("/v1/job/#{job_id}/revert", body)
|
|
58
|
+
{ result: response.body }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def job_versions(job_id:, **)
|
|
62
|
+
response = connection(**).get("/v1/job/#{job_id}/versions")
|
|
63
|
+
{ result: response.body }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def job_summary(job_id:, **)
|
|
67
|
+
response = connection(**).get("/v1/job/#{job_id}/summary")
|
|
68
|
+
{ result: response.body }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def job_allocations(job_id:, **)
|
|
72
|
+
response = connection(**).get("/v1/job/#{job_id}/allocations")
|
|
73
|
+
{ result: response.body }
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def job_evaluations(job_id:, **)
|
|
77
|
+
response = connection(**).get("/v1/job/#{job_id}/evaluations")
|
|
78
|
+
{ result: response.body }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def job_deployments(job_id:, **)
|
|
82
|
+
response = connection(**).get("/v1/job/#{job_id}/deployments")
|
|
83
|
+
{ result: response.body }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def job_latest_deployment(job_id:, **)
|
|
87
|
+
response = connection(**).get("/v1/job/#{job_id}/deployment")
|
|
88
|
+
{ result: response.body }
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def evaluate_job(job_id:, **)
|
|
92
|
+
response = connection(**).post("/v1/job/#{job_id}/evaluate")
|
|
93
|
+
{ result: response.body }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def force_periodic_job(job_id:, **)
|
|
97
|
+
response = connection(**).post("/v1/job/#{job_id}/periodic/force")
|
|
98
|
+
{ result: response.body }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def scale_job(job_id:, group:, count: nil, message: nil, **)
|
|
102
|
+
body = { Target: { Group: group } }
|
|
103
|
+
body[:Count] = count unless count.nil?
|
|
104
|
+
body[:Message] = message if message
|
|
105
|
+
response = connection(**).post("/v1/job/#{job_id}/scale", body)
|
|
106
|
+
{ result: response.body }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def job_scale_status(job_id:, **)
|
|
110
|
+
response = connection(**).get("/v1/job/#{job_id}/scale")
|
|
111
|
+
{ result: response.body }
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def job_services(job_id:, **)
|
|
115
|
+
response = connection(**).get("/v1/job/#{job_id}/services")
|
|
116
|
+
{ result: response.body }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def parse_job(hcl:, canonicalize: false, **)
|
|
120
|
+
response = connection(**).post('/v1/jobs/parse', { JobHCL: hcl, Canonicalize: canonicalize })
|
|
121
|
+
{ result: response.body }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
125
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Runners
|
|
9
|
+
module Namespaces
|
|
10
|
+
include Legion::Extensions::Nomad::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_namespaces(prefix: nil, **)
|
|
13
|
+
params = {}
|
|
14
|
+
params[:prefix] = prefix if prefix
|
|
15
|
+
response = connection(**).get('/v1/namespaces', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_namespace(namespace:, **)
|
|
20
|
+
response = connection(**).get("/v1/namespace/#{namespace}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_or_update_namespace(namespace:, description: nil, **)
|
|
25
|
+
body = { Name: namespace }
|
|
26
|
+
body[:Description] = description if description
|
|
27
|
+
response = connection(**).post("/v1/namespace/#{namespace}", body)
|
|
28
|
+
{ result: response.body }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def delete_namespace(namespace:, **)
|
|
32
|
+
response = connection(**).delete("/v1/namespace/#{namespace}")
|
|
33
|
+
{ result: response.body }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
37
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Runners
|
|
9
|
+
module Nodes
|
|
10
|
+
include Legion::Extensions::Nomad::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_nodes(prefix: nil, **)
|
|
13
|
+
params = {}
|
|
14
|
+
params[:prefix] = prefix if prefix
|
|
15
|
+
response = connection(**).get('/v1/nodes', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_node(node_id:, **)
|
|
20
|
+
response = connection(**).get("/v1/node/#{node_id}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def node_allocations(node_id:, **)
|
|
25
|
+
response = connection(**).get("/v1/node/#{node_id}/allocations")
|
|
26
|
+
{ result: response.body }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def evaluate_node(node_id:, **)
|
|
30
|
+
response = connection(**).post("/v1/node/#{node_id}/evaluate")
|
|
31
|
+
{ result: response.body }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def drain_node(node_id:, enable: true, deadline: nil, ignore_system_jobs: false, **)
|
|
35
|
+
drain_spec = nil
|
|
36
|
+
drain_spec = { Deadline: deadline || 0, IgnoreSystemJobs: ignore_system_jobs } if enable
|
|
37
|
+
body = { DrainSpec: drain_spec, NodeID: node_id }
|
|
38
|
+
response = connection(**).post("/v1/node/#{node_id}/drain", body)
|
|
39
|
+
{ result: response.body }
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def purge_node(node_id:, **)
|
|
43
|
+
response = connection(**).post("/v1/node/#{node_id}/purge")
|
|
44
|
+
{ result: response.body }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def set_node_eligibility(node_id:, eligible: true, **)
|
|
48
|
+
eligibility = eligible ? 'eligible' : 'ineligible'
|
|
49
|
+
body = { NodeID: node_id, Eligibility: eligibility }
|
|
50
|
+
response = connection(**).post("/v1/node/#{node_id}/eligibility", body)
|
|
51
|
+
{ result: response.body }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
55
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Runners
|
|
9
|
+
module Search
|
|
10
|
+
include Legion::Extensions::Nomad::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def prefix_search(prefix:, context: 'all', **)
|
|
13
|
+
body = { Prefix: prefix, Context: context }
|
|
14
|
+
response = connection(**).post('/v1/search', body)
|
|
15
|
+
{ result: response.body }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def fuzzy_search(text:, context: 'all', **)
|
|
19
|
+
body = { Text: text, Context: context }
|
|
20
|
+
response = connection(**).post('/v1/search/fuzzy', body)
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
25
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Runners
|
|
9
|
+
module Services
|
|
10
|
+
include Legion::Extensions::Nomad::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_services(**)
|
|
13
|
+
response = connection(**).get('/v1/services')
|
|
14
|
+
{ result: response.body }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_service(service_name:, **)
|
|
18
|
+
response = connection(**).get("/v1/service/#{service_name}")
|
|
19
|
+
{ result: response.body }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def delete_service(service_name:, service_id:, **)
|
|
23
|
+
response = connection(**).delete("/v1/service/#{service_name}/#{service_id}")
|
|
24
|
+
{ result: response.status == 200 }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
28
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Runners
|
|
9
|
+
module Status
|
|
10
|
+
include Legion::Extensions::Nomad::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def leader(**)
|
|
13
|
+
response = connection(**).get('/v1/status/leader')
|
|
14
|
+
{ result: response.body }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def peers(**)
|
|
18
|
+
response = connection(**).get('/v1/status/peers')
|
|
19
|
+
{ result: response.body }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
23
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Nomad
|
|
8
|
+
module Runners
|
|
9
|
+
module Variables
|
|
10
|
+
include Legion::Extensions::Nomad::Helpers::Client
|
|
11
|
+
|
|
12
|
+
def list_variables(prefix: nil, **)
|
|
13
|
+
params = {}
|
|
14
|
+
params[:prefix] = prefix if prefix
|
|
15
|
+
response = connection(**).get('/v1/vars', params)
|
|
16
|
+
{ result: response.body }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_variable(path:, **)
|
|
20
|
+
response = connection(**).get("/v1/var/#{path}")
|
|
21
|
+
{ result: response.body }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create_or_update_variable(path:, items:, **)
|
|
25
|
+
body = { Path: path, Items: items }
|
|
26
|
+
response = connection(**).put("/v1/var/#{path}", body)
|
|
27
|
+
{ result: response.body }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def delete_variable(path:, **)
|
|
31
|
+
response = connection(**).delete("/v1/var/#{path}")
|
|
32
|
+
{ result: response.status == 200 }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
36
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/nomad/version'
|
|
4
|
+
require 'legion/extensions/nomad/helpers/client'
|
|
5
|
+
require 'legion/extensions/nomad/runners/jobs'
|
|
6
|
+
require 'legion/extensions/nomad/runners/nodes'
|
|
7
|
+
require 'legion/extensions/nomad/runners/allocations'
|
|
8
|
+
require 'legion/extensions/nomad/runners/deployments'
|
|
9
|
+
require 'legion/extensions/nomad/runners/evaluations'
|
|
10
|
+
require 'legion/extensions/nomad/runners/namespaces'
|
|
11
|
+
require 'legion/extensions/nomad/runners/services'
|
|
12
|
+
require 'legion/extensions/nomad/runners/variables'
|
|
13
|
+
require 'legion/extensions/nomad/runners/status'
|
|
14
|
+
require 'legion/extensions/nomad/runners/search'
|
|
15
|
+
require 'legion/extensions/nomad/client'
|
|
16
|
+
|
|
17
|
+
module Legion
|
|
18
|
+
module Extensions
|
|
19
|
+
module Nomad
|
|
20
|
+
extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lex-nomad
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Esity
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: faraday
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: legion-cache
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.3.11
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 1.3.11
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: legion-crypt
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: 1.4.9
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 1.4.9
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: legion-data
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: 1.4.17
|
|
61
|
+
type: :runtime
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 1.4.17
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: legion-json
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: 1.2.1
|
|
75
|
+
type: :runtime
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: 1.2.1
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: legion-logging
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: 1.3.2
|
|
89
|
+
type: :runtime
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: 1.3.2
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: legion-settings
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: 1.3.14
|
|
103
|
+
type: :runtime
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: 1.3.14
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: legion-transport
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: 1.3.9
|
|
117
|
+
type: :runtime
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: 1.3.9
|
|
124
|
+
description: Connects LegionIO to HashiCorp Nomad
|
|
125
|
+
email:
|
|
126
|
+
- matthewdiverson@gmail.com
|
|
127
|
+
executables: []
|
|
128
|
+
extensions: []
|
|
129
|
+
extra_rdoc_files: []
|
|
130
|
+
files:
|
|
131
|
+
- ".github/workflows/ci.yml"
|
|
132
|
+
- ".gitignore"
|
|
133
|
+
- ".rspec"
|
|
134
|
+
- ".rubocop.yml"
|
|
135
|
+
- CHANGELOG.md
|
|
136
|
+
- CLAUDE.md
|
|
137
|
+
- Dockerfile
|
|
138
|
+
- Gemfile
|
|
139
|
+
- Gemfile.lock
|
|
140
|
+
- LICENSE
|
|
141
|
+
- README.md
|
|
142
|
+
- lex-nomad.gemspec
|
|
143
|
+
- lib/legion/extensions/nomad.rb
|
|
144
|
+
- lib/legion/extensions/nomad/client.rb
|
|
145
|
+
- lib/legion/extensions/nomad/helpers/client.rb
|
|
146
|
+
- lib/legion/extensions/nomad/runners/allocations.rb
|
|
147
|
+
- lib/legion/extensions/nomad/runners/deployments.rb
|
|
148
|
+
- lib/legion/extensions/nomad/runners/evaluations.rb
|
|
149
|
+
- lib/legion/extensions/nomad/runners/jobs.rb
|
|
150
|
+
- lib/legion/extensions/nomad/runners/namespaces.rb
|
|
151
|
+
- lib/legion/extensions/nomad/runners/nodes.rb
|
|
152
|
+
- lib/legion/extensions/nomad/runners/search.rb
|
|
153
|
+
- lib/legion/extensions/nomad/runners/services.rb
|
|
154
|
+
- lib/legion/extensions/nomad/runners/status.rb
|
|
155
|
+
- lib/legion/extensions/nomad/runners/variables.rb
|
|
156
|
+
- lib/legion/extensions/nomad/version.rb
|
|
157
|
+
homepage: https://github.com/LegionIO/lex-nomad
|
|
158
|
+
licenses:
|
|
159
|
+
- MIT
|
|
160
|
+
metadata:
|
|
161
|
+
homepage_uri: https://github.com/LegionIO/lex-nomad
|
|
162
|
+
source_code_uri: https://github.com/LegionIO/lex-nomad
|
|
163
|
+
documentation_uri: https://github.com/LegionIO/lex-nomad
|
|
164
|
+
changelog_uri: https://github.com/LegionIO/lex-nomad
|
|
165
|
+
bug_tracker_uri: https://github.com/LegionIO/lex-nomad/issues
|
|
166
|
+
rubygems_mfa_required: 'true'
|
|
167
|
+
rdoc_options: []
|
|
168
|
+
require_paths:
|
|
169
|
+
- lib
|
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
171
|
+
requirements:
|
|
172
|
+
- - ">="
|
|
173
|
+
- !ruby/object:Gem::Version
|
|
174
|
+
version: '3.4'
|
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
|
+
requirements:
|
|
177
|
+
- - ">="
|
|
178
|
+
- !ruby/object:Gem::Version
|
|
179
|
+
version: '0'
|
|
180
|
+
requirements: []
|
|
181
|
+
rubygems_version: 3.6.9
|
|
182
|
+
specification_version: 4
|
|
183
|
+
summary: LEX Nomad
|
|
184
|
+
test_files: []
|