gaptool-client 0.8.0.pre.beta2 → 0.8.0.pre.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d3035a0d9dd7ac8f7b5dd79b887977db11a88a2
4
- data.tar.gz: b82f7711f5d74ae2630e5376482852a072559378
3
+ metadata.gz: 4fc4330da672fc107c70bda1d79f2cedb56e5263
4
+ data.tar.gz: b4e11ee2bd119cb1bf4583c39dfbe2c384c8a999
5
5
  SHA512:
6
- metadata.gz: a4f93bea43e2a5b10831c2948cd234e10ea5d74bfb90c79a8e05fc54eb96d6c7afd644b47d079730e90fa055721b26607eae2733c508e5f53b1f8c281fcf3d99
7
- data.tar.gz: c43bac58d37eff2b546e10e92fca070836a7cc30a4b87f4e01e222801c4c7fcb1be3cd27bf49d92943664fa6dba930c96c465c49a04c7f5488fe9afb0370623f
6
+ metadata.gz: 860ffa9d687753c1e5d452a205d7db7ee317dbffed6037aa66b516fe4b665da07b52c369c7c6d02e729a716ff46a2d962b9582468ce042b86cb74d52e17c234c
7
+ data.tar.gz: 753ab4bc8d11193c440f190743a1d46b49ce29ad55f0988ffd9b7c705ea169e5c3d94bcaec4fd9212050e283fb5e70a5cbfb08211f748f34e478df525a73bf95
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0-beta2
1
+ 0.8.0-beta3
@@ -97,6 +97,42 @@ module Gaptool
97
97
  end
98
98
  end
99
99
 
100
+ class RunScriptCommand < Clamp::Command
101
+ option ['-r', '--role'], 'ROLE', 'Instance role'
102
+ option ['-e', '--environment'], 'ENVIRONMENT', 'Instance environment'
103
+ option ['-i', '--instance'], 'INSTANCE', 'Instance id (i-xxxxxxxx)'
104
+ option ['-s', '--serial'], :flag, 'Run command serially. Order of execution is unknown.'
105
+ option ['-x', '--exclude-hidden'], :flag, 'Exclude hidden hosts'
106
+ option ['-c', '--continue-on-errors'], :flag, 'Continue execution even if one or more hosts fail'
107
+ option ['-B', '--batch-size'], 'SIZE', "How many hosts to run in parallel (defaults to #{Gaptool::SSH::BATCH_SIZE})", default: Gaptool::SSH::BATCH_SIZE
108
+ option ['-v', '--verbose'], :flag, 'Enable verbose logging;'
109
+ option ['-D', '--debug'], :flag, 'Enable debug logging;'
110
+ parameter 'SCRIPT', 'Ruby script to run'
111
+
112
+ def execute
113
+ params = exclude_hidden? ? {} : { hidden: true }
114
+ nodes = Gaptool::API.query_nodes(params.merge(instance: instance,
115
+ role: role, environment: environment))
116
+ log_level = if debug?
117
+ Logger::DEBUG
118
+ elsif verbose?
119
+ Logger::INFO
120
+ end
121
+ command = "echo 'done'" unless log_level
122
+ sc = File.read(script)
123
+ nodes = nodes.map { |x| x.merge(script: sc, file: script, verbose: log_level.nil?) }
124
+ hook = proc do |node|
125
+ node.handler.on_data('', :stdout, "Executing #{node[:file]}", '') if node[:verbose]
126
+ eval(node[:script])
127
+ end
128
+ res = Gaptool::SSH.exec(nodes, [command],
129
+ pre_hooks: [hook], serial: serial?,
130
+ continue_on_errors: continue_on_errors?,
131
+ log_level: log_level, batch_size: batch_size)
132
+ exit res
133
+ end
134
+ end
135
+
100
136
  class SSHConfigCommand < Clamp::Command
101
137
  option ['-r', '--remove'], :flag, 'Remove ssh configuration'
102
138
 
@@ -237,14 +273,14 @@ module Gaptool
237
273
  pre_hook = proc do |node|
238
274
  cl = Gaptool::API.new
239
275
  json = cl.getnodeattrs(node['instance'], node['attrs'])
240
- json['run_list'] ||= node['chef_runlist'] || ['recipe[main]']
276
+ json['run_list'] ||= node['chef_runlist'] || ['role[base]']
241
277
  git = 'sudo -u admin git'
242
278
  pull = "#{git} fetch --all; #{git} reset --hard origin/`#{git} rev-parse --abbrev-ref HEAD`"
243
279
  wopts = node['whyrun'] ? ' -W ' : ''
244
280
 
245
281
  unless node['attrs']['chef_branch'].nil?
246
282
  json['chefbranch'] = node['attrs']['chef_branch']
247
- pull = "#{git} checkout -f #{node['attrs']['chef_branch']}; #{git} fetch --all; #{git} reset --hard origin/#{node['attrs']['chef_branch']}"
283
+ pull = "#{git} checkout -fB #{node['attrs']['chef_branch']}; #{git} fetch --all; #{git} reset --hard origin/#{node['attrs']['chef_branch']}"
248
284
  end
249
285
  upload!(StringIO.new(json.to_json), '/tmp/chef.json')
250
286
  script = <<-EOS
@@ -114,6 +114,7 @@ EOF
114
114
  runner = runner_cls.new(hosts, opts) do |host|
115
115
  pre.each { |h| instance_exec(host, &h) }
116
116
  commands.each do |cmd|
117
+ next if cmd.nil? || cmd.empty?
117
118
  execute(:bash, "-l -c '#{cmd}'",
118
119
  interaction_handler: host.handler)
119
120
  end
@@ -16,6 +16,7 @@ module Gaptool
16
16
  subcommand 'deploy', 'deploy on an application', DeployCommand
17
17
  subcommand 'rehash', 'Regenerate all host metadata. KNOW WHAT THIS DOES BEFORE RUNNING IT', RehashCommand
18
18
  subcommand 'runcmd', 'Run command on instance', RuncmdCommand
19
+ subcommand 'runscript', 'Run command on instance', RunScriptCommand
19
20
  subcommand 'scp', 'Copy file to-from instance(s)', ScpCommand
20
21
  subcommand 'version', 'Show version', VersionCommand
21
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaptool-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.pre.beta2
4
+ version: 0.8.0.pre.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Laurita
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-01-06 00:00:00.000000000 Z
13
+ date: 2016-01-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json