hammer_cli_foreman_remote_execution 0.0.4 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +4 -0
  3. data/.travis.yml +5 -3
  4. data/.tx/config +8 -0
  5. data/Gemfile +8 -3
  6. data/README.md +53 -14
  7. data/Rakefile +19 -8
  8. data/hammer_cli_foreman_remote_execution.gemspec +3 -3
  9. data/lib/hammer_cli_foreman_remote_execution.rb +1 -0
  10. data/lib/hammer_cli_foreman_remote_execution/foreign_input_set.rb +4 -4
  11. data/lib/hammer_cli_foreman_remote_execution/i18n.rb +13 -1
  12. data/lib/hammer_cli_foreman_remote_execution/job_invocation.rb +65 -7
  13. data/lib/hammer_cli_foreman_remote_execution/job_template.rb +31 -1
  14. data/lib/hammer_cli_foreman_remote_execution/remote_execution_feature.rb +41 -0
  15. data/lib/hammer_cli_foreman_remote_execution/template_input.rb +12 -4
  16. data/lib/hammer_cli_foreman_remote_execution/version.rb +1 -1
  17. data/locale/Makefile +57 -0
  18. data/locale/README.md +18 -0
  19. data/locale/de/hammer-cli-foreman-remote-execution.po +93 -0
  20. data/locale/en/hammer-cli-foreman-remote-execution.po +209 -0
  21. data/locale/es/hammer-cli-foreman-remote-execution.po +93 -0
  22. data/locale/fr/hammer-cli-foreman-remote-execution.po +93 -0
  23. data/locale/hammer-cli-foreman-remote-execution.pot +358 -0
  24. data/locale/it/hammer-cli-foreman-remote-execution.po +93 -0
  25. data/locale/ja/hammer-cli-foreman-remote-execution.po +93 -0
  26. data/locale/ko/hammer-cli-foreman-remote-execution.po +93 -0
  27. data/locale/pt_BR/hammer-cli-foreman-remote-execution.po +94 -0
  28. data/locale/ru/hammer-cli-foreman-remote-execution.po +95 -0
  29. data/locale/zh_CN/hammer-cli-foreman-remote-execution.po +94 -0
  30. data/locale/zh_TW/hammer-cli-foreman-remote-execution.po +94 -0
  31. data/test/data/1.14/foreman_api.json +1 -0
  32. data/test/data/1.16/foreman_api.json +1 -0
  33. data/test/data/1.17/foreman_api.json +1 -0
  34. data/test/data/export.erb +9 -0
  35. data/test/{unit/data → data}/template.txt +0 -0
  36. data/test/unit/foreign_input_set_test.rb +3 -3
  37. data/test/unit/job_invocation_test.rb +41 -5
  38. data/test/unit/job_template_test.rb +31 -4
  39. data/test/unit/remote_execution_feature_test.rb +44 -0
  40. data/test/unit/template_input_test.rb +11 -3
  41. metadata +35 -12
  42. data/test/unit/data/1.10/foreman_api.json +0 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bdb90815b99416e087efed5bf5901d8207aee6c9
4
- data.tar.gz: 28ac9b4a9e859af2fac1354ab87dcebf54d40601
2
+ SHA256:
3
+ metadata.gz: 82a8e161e362047b1b57912566bba871c744abf23f65b23f5425865138f281a2
4
+ data.tar.gz: 3a26ec61f5fda760497bbc0bb8d9744ffa1d99bb5717f3d15a82b9750e37d949
5
5
  SHA512:
6
- metadata.gz: 21ecf180e141ffbb370d15cbb1fb798fd25c3c5fb1a18a138f18da2b85e3339299cc55cf8da8faa79a42b66c9f3ff1009ffd7957b2831a603ca4287344f47874
7
- data.tar.gz: dac550144f0ecc605bf5d418274bbb5970d04803d185c08428fca862c9e562f1c7c46437392ad71b55a40fffb447bb62e11485b9996cd0f5a0cabdb5df813484
6
+ metadata.gz: f3ee7406b730f5036b5b283e35d2353f7341a007b28e10da883f5dc2fe9ab9ad801ac162765e6646b664a8cf61bd7da355eae1d10e76ca940909f9ab87a3c8ac
7
+ data.tar.gz: 12bad04f757471161f6ac7e4e8cb3b5e25c4971957af6e37e9cc4fa8d7755f9257aa5c3940586696db72afe686c49ff2dcda02af30f9df2f946178ad3f12a61d
data/.gitignore CHANGED
@@ -18,3 +18,7 @@ tags
18
18
  .idea
19
19
  *.sw?
20
20
  *~
21
+
22
+ # Locale files
23
+ locale/*/*.edit.po
24
+ locale/*/*.po.time_stamp
@@ -1,7 +1,9 @@
1
1
  ---
2
2
  language: ruby
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1.0
4
+ - 2.4.0
5
+ - 2.5.0
6
+ - 2.6.0
7
7
  sudo: false
8
+ before_install:
9
+ - gem update bundler
@@ -0,0 +1,8 @@
1
+ [main]
2
+ host = https://www.transifex.com
3
+
4
+ [foreman.hammer_cli_foreman_tasks]
5
+ file_filter = locale/<lang>/hammer-cli-foreman-remote-execution.edit.po
6
+ source_file = locale/hammer-cli-foreman-remote-exectution.pot
7
+ source_lang = en
8
+ type = PO
data/Gemfile CHANGED
@@ -3,11 +3,14 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  gem 'gettext', '>= 3.1.3', '< 4.0.0'
6
+ if RUBY_VERSION < '2.1.0'
7
+ gem 'fast_gettext', '< 1.2.0'
8
+ end
6
9
 
7
10
  group :test do
8
11
  gem 'rake', '~> 10.1.0'
9
12
  gem 'thor'
10
- gem 'minitest', '< 5.0.0'
13
+ gem 'minitest', '< 4.7.4'
11
14
  gem 'minitest-spec-context'
12
15
  gem 'simplecov'
13
16
  gem 'mocha'
@@ -15,5 +18,7 @@ group :test do
15
18
  end
16
19
 
17
20
  # load local gemfile
18
- local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
19
- self.instance_eval(Bundler.read_file(local_gemfile)) if File.exist?(local_gemfile)
21
+ ['Gemfile.local.rb', 'Gemfile.local'].map do |file_name|
22
+ local_gemfile = File.join(File.dirname(__FILE__), file_name)
23
+ self.instance_eval(Bundler.read_file(local_gemfile)) if File.exist?(local_gemfile)
24
+ end
data/README.md CHANGED
@@ -8,41 +8,60 @@ CLI Plugin for Foreman Remote Execution
8
8
 
9
9
  This [Hammer CLI](https://github.com/theforeman/hammer-cli) plugin contains commands for [foreman_remote_execution](https://github.com/theforeman/foreman_remote_execution).
10
10
 
11
- Examples
12
- --------
11
+ # Examples
13
12
 
14
- ### Create a Template
13
+ ## Templates
14
+
15
+ ### List templates
16
+
17
+ ```
18
+ hammer job-template list
19
+ ```
20
+
21
+ ### Create a template
15
22
 
16
23
  ```
17
24
  hammer job-template create --file /tmp/template.txt --name "Ping a Host"\
18
- --provider-type Ssh --job-name "Ping"
25
+ --provider-type SSH --job-category "Commands"
19
26
  ```
20
27
 
21
- ### Create a Template Input
28
+ ### Create a template input
22
29
 
23
30
  ```
24
31
  hammer template-input create --template-id 17 --name hostname\
25
32
  --input-type user --options www.google.com,www.facebook.com,localhost
26
33
  ```
27
34
 
28
- ### Run a Job Examples
35
+ ## Jobs
36
+
37
+ ### Show jobs
29
38
 
30
- #### Command line inputs
39
+ ```
40
+ hammer job-invocation list
41
+ ```
42
+
43
+ Show details:
31
44
 
32
45
  ```
33
- hammer job-invocation create --job-name "Run Command" --inputs command="ping -c 50 www.google.com"\
34
- --search-query "name ~ rex01"
46
+ hammer job-invocation info --id 83
35
47
  ```
36
48
 
49
+ ### Run a job with command line inputs
50
+
51
+ ```
52
+ hammer job-invocation create --job-template "Run Command - SSH Default" \
53
+ --inputs command="ping -c 50 www.google.com" --search-query "name ~ rex01"
37
54
  ```
38
- hammer job-invocation create --job-name "Package Action"\
55
+
56
+ ```
57
+ hammer job-invocation create --job-template "Package Action - SSH Default" \
39
58
  --inputs package=vim-enhanced,action=install --search-query "name ~ rex01"
40
59
  ```
41
60
 
42
- #### File inputs:
61
+ ### Run a job with file inputs
43
62
 
44
63
  ```
45
- hammer job-invocation create --job-name "Run Command"\
64
+ hammer job-invocation create --job-template "Run Command - SSH Default"\
46
65
  --input-files command=/tmp/script.sh --search-query "name ~ rex01"
47
66
  ```
48
67
 
@@ -60,7 +79,27 @@ Alternatively, pass the `--async` option to see the output so far:
60
79
  hammer job-invocation output --id 155 --host rex01.example.com --async
61
80
  ```
62
81
 
63
- License
64
- -------
82
+ ## Developer Information
83
+
84
+ ### Updating API docs
85
+
86
+ In `test/data/[foreman_version]/foreman_api.json`, we include the Apipie
87
+ documentation, with generated examples from the tests.
88
+
89
+ When adding new features to the hammer, you'll need to update this.
90
+
91
+ 1. From foreman directory, run remote execution tests with examples enabled:
92
+
93
+ APIPIE_RECORD=examples rake test:foreman_remote_execution
94
+
95
+ 2. From foreman directory, generate the apipie cache for English:
96
+
97
+ FOREMAN_APIPIE_LANGS=en rake apipie:cache
98
+
99
+ 3. Copy the docs to hammer_cli_foreman_remote_execution
100
+
101
+ cp public/apipie-cache/apidoc/v2.en.json ~/hammer_cli_foreman_remote_execution/test/data/1.10/foreman_api.json
102
+
103
+ ## License
65
104
 
66
105
  This project is licensed under the GPLv3+.
data/Rakefile CHANGED
@@ -9,17 +9,28 @@ Rake::TestTask.new :test do |t|
9
9
  end
10
10
 
11
11
  namespace :gettext do
12
- desc 'Update pot file'
13
- task :find do
14
- require 'hammer_cli_foreman_remote_execution/version'
15
- require 'hammer_cli_foreman_remote_execution/i18n'
16
- require 'gettext/tools'
12
+
13
+ task :setup do
14
+ require "hammer_cli_foreman_remote_execution/version"
15
+ require "hammer_cli_foreman_remote_execution/i18n"
16
+ require 'gettext/tools/task'
17
17
 
18
18
  domain = HammerCLIForemanRemoteExecution::I18n::LocaleDomain.new
19
- GetText.update_pofiles(domain.domain_name, domain.translated_files,
20
- "#{domain.domain_name} #{HammerCLIForemanRemoteExecution.version}",
21
- :po_root => domain.locale_dir)
19
+ GetText::Tools::Task.define do |task|
20
+ task.package_name = domain.domain_name
21
+ task.package_version = HammerCLIForemanRemoteExecution.version.to_s
22
+ task.domain = domain.domain_name
23
+ task.mo_base_directory = domain.locale_dir
24
+ task.po_base_directory = domain.locale_dir
25
+ task.files = domain.translated_files
26
+ end
27
+ end
28
+
29
+ desc "Update pot file"
30
+ task :find => [:setup] do
31
+ Rake::Task["gettext:po:update"].invoke
22
32
  end
33
+
23
34
  end
24
35
 
25
36
  namespace :pkg do
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ['Foreman Remote Execution team']
8
8
  s.email = ['foreman-dev@googlegroups.com']
9
- s.homepage = 'http://github.com/theforeman/hammer_cli_foreman_remote_execution'
10
- s.license = 'GPL v3+'
9
+ s.homepage = 'https://github.com/theforeman/hammer_cli_foreman_remote_execution'
10
+ s.license = 'GPL-3.0-or-later'
11
11
 
12
12
  s.summary = 'CLI for the Foreman remote execution plugin'
13
13
  s.description = 'CLI for the Foreman remote execution plugin'
@@ -16,6 +16,6 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files test`.split("\n")
17
17
  s.extra_rdoc_files = `git ls-files doc`.split("\n") + Dir['README*', 'LICENSE']
18
18
 
19
- s.add_dependency 'hammer_cli_foreman', '>= 0.1.3', '< 1.0.0'
19
+ s.add_dependency 'hammer_cli_foreman', '>= 0.1.3', '< 3.0.0'
20
20
  s.add_dependency 'hammer_cli_foreman_tasks', '~> 0.0.3'
21
21
  end
@@ -8,6 +8,7 @@ module HammerCLIForemanRemoteExecution
8
8
  require 'hammer_cli_foreman_remote_execution/job_template'
9
9
  require 'hammer_cli_foreman_remote_execution/template_input'
10
10
  require 'hammer_cli_foreman_remote_execution/foreign_input_set'
11
+ require 'hammer_cli_foreman_remote_execution/remote_execution_feature'
11
12
 
12
13
  def self.exception_handler_class
13
14
  HammerCLIForeman::ExceptionHandler
@@ -5,8 +5,8 @@ module HammerCLIForemanRemoteExecution
5
5
 
6
6
  class ListCommand < HammerCLIForeman::ListCommand
7
7
  output do
8
- field :id, _('Id')
9
- field :target_template_id, _('Target template id')
8
+ field :id, _('ID')
9
+ field :target_template_id, _('Target template ID')
10
10
  field :target_template_name, _('Target template name')
11
11
  end
12
12
 
@@ -15,9 +15,9 @@ module HammerCLIForemanRemoteExecution
15
15
 
16
16
  class InfoCommand < HammerCLIForeman::InfoCommand
17
17
  output do
18
- field :id, _('Id')
18
+ field :id, _('ID')
19
19
  field :name, _('Name')
20
- field :target_template_id, _('Target template id')
20
+ field :target_template_id, _('Target template ID')
21
21
  field :target_template_name, _('Target template name')
22
22
  field :include_all, _('Include all')
23
23
  field :include, _('Include')
@@ -2,7 +2,9 @@ require 'hammer_cli/i18n'
2
2
 
3
3
  module HammerCLIForemanRemoteExecution
4
4
  module I18n
5
+
5
6
  class LocaleDomain < HammerCLI::I18n::LocaleDomain
7
+
6
8
  def translated_files
7
9
  Dir.glob(File.join(File.dirname(__FILE__), '../**/*.rb'))
8
10
  end
@@ -15,7 +17,17 @@ module HammerCLIForemanRemoteExecution
15
17
  'hammer-cli-foreman-remote-execution'
16
18
  end
17
19
  end
20
+
21
+ class SystemLocaleDomain < LocaleDomain
22
+
23
+ def locale_dir
24
+ '/usr/share/locale'
25
+ end
26
+
27
+ end
28
+
18
29
  end
19
30
  end
20
31
 
21
- HammerCLI::I18n.add_domain(HammerCLIForemanRemoteExecution::I18n::LocaleDomain.new)
32
+ domain = [HammerCLIForemanRemoteExecution::I18n::LocaleDomain.new, HammerCLIForemanRemoteExecution::I18n::SystemLocaleDomain.new].find { |d| d.available? }
33
+ HammerCLI::I18n.add_domain(domain) if domain
@@ -2,9 +2,15 @@ module HammerCLIForemanRemoteExecution
2
2
  class JobInvocation < HammerCLIForeman::Command
3
3
  resource :job_invocations
4
4
 
5
+ module WithoutNameOption
6
+ def create_option_builder
7
+ HammerCLI::Apipie::OptionBuilder.new(resource, resource.action(action), :require_options => false)
8
+ end
9
+ end
10
+
5
11
  class ListCommand < HammerCLIForeman::ListCommand
6
12
  output do
7
- field :id, _('Id')
13
+ field :id, _('ID')
8
14
  field :description, _('Description')
9
15
  field :status_label, _('Status')
10
16
  field :succeeded, _('Success')
@@ -12,6 +18,7 @@ module HammerCLIForemanRemoteExecution
12
18
  field :pending, _('Pending')
13
19
  field :total, _('Total')
14
20
  field :start_at, _('Start')
21
+ field :randomized_ordering, _('Randomized ordering')
15
22
  end
16
23
 
17
24
  def extend_data(invocation)
@@ -22,6 +29,7 @@ module HammerCLIForemanRemoteExecution
22
29
  end
23
30
 
24
31
  class InfoCommand < HammerCLIForeman::InfoCommand
32
+ extend WithoutNameOption
25
33
  output ListCommand.output_definition do
26
34
  field :job_category, _('Job Category')
27
35
  field :mode, _('Mode')
@@ -54,17 +62,39 @@ module HammerCLIForemanRemoteExecution
54
62
  puts line['output']
55
63
  since = line['timestamp']
56
64
  end
65
+ since
66
+ end
57
67
 
58
- if output['refresh'] && !option_async?
59
- sleep 1
60
- print_data(resource.call(action, request_params.merge(:since => since), request_headers, request_options))
68
+ def execute
69
+ data = get_output
70
+ if data['delayed']
71
+ puts _('The job is scheduled to start at %{timestamp}') % { :timestamp => data['start_at'] }
72
+ return HammerCLI::EX_OK if option_async?
61
73
  end
74
+ since = print_data(data)
75
+
76
+ output_loop(data, since)
77
+ return HammerCLI::EX_OK
62
78
  end
63
79
 
64
80
  build_options do |o|
65
81
  o.expand(:all).except(:job_invocations)
66
82
  o.without(:since)
67
83
  end
84
+
85
+ private
86
+
87
+ def output_loop(data, since = nil)
88
+ while data['refresh'] && !option_async? do
89
+ sleep 1
90
+ data = get_output(since)
91
+ since = print_data(data)
92
+ end
93
+ end
94
+
95
+ def get_output(since = nil)
96
+ resource.call(action, request_params.merge(:since => since), request_headers, request_options)
97
+ end
68
98
  end
69
99
 
70
100
  class CreateCommand < HammerCLIForeman::CreateCommand
@@ -112,9 +142,11 @@ module HammerCLIForemanRemoteExecution
112
142
  super(task)
113
143
  end
114
144
 
145
+ alias original_option_async? option_async?
146
+
115
147
  def option_async?
116
148
  if immediate?
117
- defined?(option_async) ? option_async : false
149
+ original_option_async?
118
150
  else
119
151
  true
120
152
  end
@@ -129,9 +161,35 @@ module HammerCLIForemanRemoteExecution
129
161
  end
130
162
  end
131
163
 
164
+ class CancelCommand < HammerCLIForeman::Command
165
+ extend WithoutNameOption
166
+
167
+ action :cancel
168
+ command_name 'cancel'
169
+ desc _('Cancel the job')
170
+ success_message _('Job invocation %{id} cancelled')
171
+ failure_message _('Could not cancel the job invocation')
172
+
173
+ build_options { |o| o.expand(:none) }
174
+ end
175
+
176
+ class RerunCommand < HammerCLIForeman::CreateCommand
177
+ extend WithoutNameOption
178
+
179
+ action :rerun
180
+ command_name 'rerun'
181
+ desc _('Rerun the job')
182
+ success_message _('Job invocation was rerun as %{id}')
183
+
184
+ build_options { |o| o.expand(:none) }
185
+ end
186
+
132
187
  def self.extend_data(invocation)
133
- if invocation['targeting'] && invocation['targeting']['hosts']
134
- invocation['hosts'] = "\n" + invocation['targeting']['hosts'].map { |host| " - #{host['name']}" }.join("\n")
188
+ if (targeting = invocation['targeting']) && invocation['targeting']['hosts']
189
+ invocation['randomized_ordering'] = targeting['randomized_ordering']
190
+ if (hosts = targeting['hosts'])
191
+ invocation['hosts'] = "\n" + hosts.map { |host| " - #{host['name']}" }.join("\n")
192
+ end
135
193
  end
136
194
 
137
195
  if invocation['recurrence']
@@ -4,7 +4,7 @@ module HammerCLIForemanRemoteExecution
4
4
 
5
5
  class ListCommand < HammerCLIForeman::ListCommand
6
6
  output do
7
- field :id, _('Id')
7
+ field :id, _('ID')
8
8
  field :name, _('Name')
9
9
  field :job_category, _('Job Category')
10
10
  field :provider_type, _('Provider')
@@ -20,6 +20,7 @@ module HammerCLIForemanRemoteExecution
20
20
 
21
21
  class InfoCommand < HammerCLIForeman::InfoCommand
22
22
  output ListCommand.output_definition do
23
+ field :description, _('Description'), Fields::Text
23
24
  field :template_inputs, _('Inputs')
24
25
  HammerCLIForeman::References.taxonomies(self)
25
26
  end
@@ -55,6 +56,35 @@ module HammerCLIForemanRemoteExecution
55
56
  end
56
57
  end
57
58
 
59
+ class ImportCommand < HammerCLIForeman::CreateCommand
60
+ command_name 'import'
61
+ action :import
62
+
63
+ option '--file', 'TEMPLATE', N_('Path to a file that contains the template - must include ERB metadata'),
64
+ :attribute_name => :option_template, :required => true,
65
+ :format => HammerCLI::Options::Normalizers::File.new
66
+
67
+ success_message _('Job template imported')
68
+ failure_message _('Could not import the job template')
69
+
70
+ build_options do |o|
71
+ o.without(:template)
72
+ end
73
+ end
74
+
75
+ class ExportCommand < HammerCLIForeman::InfoCommand
76
+ command_name 'export'
77
+ action :export
78
+
79
+ desc _('Export a template including all metadata')
80
+
81
+ def print_data(template)
82
+ puts template
83
+ end
84
+
85
+ build_options
86
+ end
87
+
58
88
  class UpdateCommand < HammerCLIForeman::UpdateCommand
59
89
  option '--file', 'TEMPLATE', N_('Path to a file that contains the template'),
60
90
  :attribute_name => :option_template,