choria-colt 0.5.1 → 0.6.0
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 +4 -4
- data/.rubocop_todo.yml +1 -6
- data/CHANGELOG.md +15 -0
- data/README.md +2 -2
- data/lib/choria/colt/cli.rb +34 -19
- data/lib/choria/colt/version.rb +1 -1
- data/lib/choria/colt.rb +5 -5
- data/lib/choria/orchestrator/task.rb +2 -2
- data/lib/choria/orchestrator.rb +9 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e76e667917bf1958b48d45148712fa5e0d6f2c15280bbbda0d4899b0537e9f8
|
4
|
+
data.tar.gz: 17637d3bf6738bef6c28a282aabb1c4ac7680e4b2e8a6f0fe873a27b59079cc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bacccbdfd46669936f1271d05e4fdceae1864e07ae7f14b260f6de3ec2ed1e90d0c3270f57ea3faaa424b267eab59e1460abcdf4262feec421c6ea510bc811d5
|
7
|
+
data.tar.gz: ad8aaf32f6f71f349d04955cb795c0439c4ecd30103f290da82b3ce7037c6dce330b7e89123a416c120b61bc194c754debfb97412e6e200af8d53264aaba169c
|
data/.rubocop_todo.yml
CHANGED
@@ -1,16 +1,11 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2022-
|
3
|
+
# on 2022-05-03 07:08:32 UTC using RuboCop version 1.26.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count: 1
|
10
|
-
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
11
|
-
Metrics/AbcSize:
|
12
|
-
Max: 22
|
13
|
-
|
14
9
|
# Offense count: 1
|
15
10
|
# Configuration parameters: IgnoredMethods.
|
16
11
|
Metrics/CyclomaticComplexity:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,20 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v0.6.0](https://github.com/opus-codium/choria-colt/tree/v0.6.0) (2022-05-16)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/opus-codium/choria-colt/compare/v0.5.1...v0.6.0)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Allow to run a task from any puppet environment [\#28](https://github.com/opus-codium/choria-colt/pull/28) ([neomilium](https://github.com/neomilium))
|
10
|
+
- CLI: Use symbol notation to target `:all` nodes [\#27](https://github.com/opus-codium/choria-colt/pull/27) ([neomilium](https://github.com/neomilium))
|
11
|
+
- CLI: Allow targeting on task status requests [\#26](https://github.com/opus-codium/choria-colt/pull/26) ([neomilium](https://github.com/neomilium))
|
12
|
+
- Fix `task status` command [\#25](https://github.com/opus-codium/choria-colt/pull/25) ([neomilium](https://github.com/neomilium))
|
13
|
+
|
14
|
+
## [v0.5.1](https://github.com/opus-codium/choria-colt/tree/v0.5.1) (2022-05-02)
|
15
|
+
|
16
|
+
[Full Changelog](https://github.com/opus-codium/choria-colt/compare/v0.5.0...v0.5.1)
|
17
|
+
|
3
18
|
## [v0.5.0](https://github.com/opus-codium/choria-colt/tree/v0.5.0) (2022-05-02)
|
4
19
|
|
5
20
|
[Full Changelog](https://github.com/opus-codium/choria-colt/compare/v0.4.0...v0.5.0)
|
data/README.md
CHANGED
@@ -51,8 +51,8 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
51
51
|
|
52
52
|
|
53
53
|
To release a new version:
|
54
|
-
1. update the version number in `version.rb`
|
55
|
-
1. generate CHANGELOG.md with `bundle exec rake changelog`
|
54
|
+
1. update the version number in `lib/choria/colt/version.rb`
|
55
|
+
1. generate `CHANGELOG.md` with `bundle exec rake changelog`
|
56
56
|
1. commit changes
|
57
57
|
1. run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
58
|
|
data/lib/choria/colt/cli.rb
CHANGED
@@ -9,6 +9,15 @@ module Choria
|
|
9
9
|
class Colt
|
10
10
|
class CLI < Thor
|
11
11
|
class Tasks < Thor
|
12
|
+
def self.define_targets_and_filters_options
|
13
|
+
option :targets,
|
14
|
+
aliases: ['--target', '-t'],
|
15
|
+
desc: 'Identifies the targets of the command.'
|
16
|
+
option :targets_with_classes,
|
17
|
+
aliases: ['--targets-with-class', '-C'],
|
18
|
+
desc: 'Select the targets which have the specified Puppet classes.'
|
19
|
+
end
|
20
|
+
|
12
21
|
class_option :log_level,
|
13
22
|
desc: 'Set log level for CLI',
|
14
23
|
default: 'info'
|
@@ -19,28 +28,22 @@ module Choria
|
|
19
28
|
|
20
29
|
Parameters take the form parameter=value.
|
21
30
|
DESC
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def run(*args) # rubocop:disable Metrics/AbcSize
|
29
|
-
input = extract_task_parameters_from_args(args)
|
30
|
-
targets = extract_targets_from_options
|
31
|
-
|
31
|
+
define_targets_and_filters_options
|
32
|
+
option :environment,
|
33
|
+
aliases: ['-E'],
|
34
|
+
desc: 'Puppet environment to grab tasks from',
|
35
|
+
default: 'production'
|
36
|
+
def run(*args)
|
32
37
|
raise Thor::Error, 'Task name is required' if args.empty?
|
33
|
-
raise Thor::Error, "Too many arguments: #{args}" unless args.count == 1
|
34
38
|
|
35
|
-
|
39
|
+
input = extract_task_parameters_from_args(args)
|
40
|
+
raise Thor::Error, "Too many arguments: #{args}" unless args.count == 1
|
36
41
|
|
37
42
|
task_name = args.shift
|
43
|
+
targets, targets_with_classes = extract_targets_and_filters_from_options
|
38
44
|
|
39
|
-
|
40
|
-
|
41
|
-
targets_with_classes = options['targets_with_classes']&.split(',')
|
42
|
-
|
43
|
-
results = colt.run_bolt_task task_name, input: input, targets: targets, targets_with_classes: targets_with_classes do |result|
|
45
|
+
environment = options['environment']
|
46
|
+
results = colt.run_bolt_task task_name, input: input, targets: targets, targets_with_classes: targets_with_classes, environment: environment do |result|
|
44
47
|
$stdout.puts formatter.process_result(result)
|
45
48
|
end
|
46
49
|
|
@@ -84,8 +87,11 @@ module Choria
|
|
84
87
|
|
85
88
|
A task ID is required to request Choria services and retrieve results.
|
86
89
|
DESC
|
90
|
+
define_targets_and_filters_options
|
87
91
|
def status(task_id)
|
88
|
-
|
92
|
+
targets, targets_with_classes = extract_targets_and_filters_from_options
|
93
|
+
|
94
|
+
results = colt.wait_bolt_task(task_id, targets: targets, targets_with_classes: targets_with_classes) do |result|
|
89
95
|
$stdout.puts formatter.process_result(result)
|
90
96
|
end
|
91
97
|
|
@@ -130,8 +136,17 @@ module Choria
|
|
130
136
|
end.to_h
|
131
137
|
end
|
132
138
|
|
139
|
+
def extract_targets_and_filters_from_options
|
140
|
+
raise Thor::Error, 'Flag --targets or --targets-with-class is required' if options['targets'].nil? && options['targets_with_classes'].nil?
|
141
|
+
|
142
|
+
targets = extract_targets_from_options
|
143
|
+
targets_with_classes = options['targets_with_classes']&.split(',')
|
144
|
+
|
145
|
+
[targets, targets_with_classes]
|
146
|
+
end
|
147
|
+
|
133
148
|
def extract_targets_from_options
|
134
|
-
return nil if options['targets'] == 'all'
|
149
|
+
return nil if options['targets'] == ':all'
|
135
150
|
|
136
151
|
targets = options['targets']&.split(',')
|
137
152
|
targets&.map do |t|
|
data/lib/choria/colt/version.rb
CHANGED
data/lib/choria/colt.rb
CHANGED
@@ -19,9 +19,9 @@ module Choria
|
|
19
19
|
@orchestrator = Choria::Orchestrator.new logger: @logger
|
20
20
|
end
|
21
21
|
|
22
|
-
def run_bolt_task(task_name, input: {}, targets: nil, targets_with_classes: nil, &block)
|
22
|
+
def run_bolt_task(task_name, input: {}, targets: nil, targets_with_classes: nil, environment: 'production', &block)
|
23
23
|
logger.debug "Instantiate task '#{task_name}' and validate input"
|
24
|
-
task = Choria::Orchestrator::Task.new(name: task_name, input: input, orchestrator: orchestrator)
|
24
|
+
task = Choria::Orchestrator::Task.new(name: task_name, input: input, environment: environment, orchestrator: orchestrator)
|
25
25
|
|
26
26
|
task.on_result(&block) if block_given?
|
27
27
|
|
@@ -33,11 +33,11 @@ module Choria
|
|
33
33
|
raise
|
34
34
|
end
|
35
35
|
|
36
|
-
def wait_bolt_task(task_id, &block)
|
37
|
-
|
36
|
+
def wait_bolt_task(task_id, targets: nil, targets_with_classes: nil, &block)
|
37
|
+
orchestrator.discover(targets: targets, targets_with_classes: targets_with_classes)
|
38
38
|
|
39
|
+
task = Choria::Orchestrator::Task.new(id: task_id, orchestrator: orchestrator)
|
39
40
|
task.on_result(&block) if block_given?
|
40
|
-
|
41
41
|
task.wait
|
42
42
|
task.results
|
43
43
|
rescue Choria::Orchestrator::Error => e
|
@@ -65,8 +65,8 @@ module Choria
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def rpc_results=(results)
|
68
|
-
|
69
|
-
@pending_targets ||=
|
68
|
+
completed_results = results.reject { |res| res[:data][:exitcode] == -1 }
|
69
|
+
@pending_targets ||= results.map { |res| res[:sender] }
|
70
70
|
|
71
71
|
new_results = completed_results.select { |res| @pending_targets.include? res[:sender] }
|
72
72
|
new_results.each do |res|
|
data/lib/choria/orchestrator.rb
CHANGED
@@ -39,10 +39,16 @@ module Choria
|
|
39
39
|
@tasks_support ||= MCollective::Util::Choria.new.tasks_support
|
40
40
|
end
|
41
41
|
|
42
|
-
def run(task, targets: nil, targets_with_classes: nil, verbose: false)
|
42
|
+
def run(task, targets: nil, targets_with_classes: nil, verbose: false)
|
43
43
|
rpc_client.progress = verbose
|
44
|
+
discover(targets: targets, targets_with_classes: targets_with_classes)
|
45
|
+
raise DiscoverError, 'No requests sent, no nodes discovered' if rpc_client.discover.size.zero?
|
46
|
+
|
47
|
+
task.run
|
48
|
+
end
|
44
49
|
|
45
|
-
|
50
|
+
def discover(targets: nil, targets_with_classes: nil)
|
51
|
+
logger.debug "Targets: #{targets.nil? ? 'all' : targets})"
|
46
52
|
targets&.each { |target| rpc_client.identity_filter target }
|
47
53
|
|
48
54
|
unless targets_with_classes.nil?
|
@@ -51,9 +57,7 @@ module Choria
|
|
51
57
|
end
|
52
58
|
|
53
59
|
logger.info 'Discovering targets…'
|
54
|
-
|
55
|
-
|
56
|
-
task.run
|
60
|
+
rpc_client.discover
|
57
61
|
end
|
58
62
|
|
59
63
|
def rpc_client
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: choria-colt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romuald Conty
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|