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

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: 002150433708bb563757f2ef3cc21fc87e0388e2
4
- data.tar.gz: 64857892d8fbc611a72331e90a911239f808a562
3
+ metadata.gz: 4d3035a0d9dd7ac8f7b5dd79b887977db11a88a2
4
+ data.tar.gz: b82f7711f5d74ae2630e5376482852a072559378
5
5
  SHA512:
6
- metadata.gz: 5a756b321848f7c1bdaafcf41da7573a9d67b0398e44f684d6d591c0639f2edc3798b3dea1155af4f90819e3632fb3569474c75c12fb1bc34a46bbb9ecf88af7
7
- data.tar.gz: a80fccd7831292c544a86f3e1e5545daad80294f4a6e1ac51e541766f139909ee7086117724185cf20ead681622c96b286ef1f3011ec1333bfb933dc91bd1be3
6
+ metadata.gz: a4f93bea43e2a5b10831c2948cd234e10ea5d74bfb90c79a8e05fc54eb96d6c7afd644b47d079730e90fa055721b26607eae2733c508e5f53b1f8c281fcf3d99
7
+ data.tar.gz: c43bac58d37eff2b546e10e92fca070836a7cc30a4b87f4e01e222801c4c7fcb1be3cd27bf49d92943664fa6dba930c96c465c49a04c7f5488fe9afb0370623f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0-beta1
1
+ 0.8.0-beta2
@@ -4,6 +4,7 @@ require 'rainbow'
4
4
  require 'json'
5
5
  require 'clamp'
6
6
  require 'set'
7
+ require 'logger'
7
8
  require 'gaptool_client/api'
8
9
  require 'gaptool_client/helpers'
9
10
  require 'gaptool_client/ssh'
@@ -82,7 +83,7 @@ module Gaptool
82
83
  option ['-s', '--serial'], :flag, 'Run command serially. Order of execution is unknown.'
83
84
  option ['-x', '--exclude-hidden'], :flag, 'Exclude hidden hosts'
84
85
  option ['-c', '--continue-on-errors'], :flag, 'Continue execution even if one or more hosts fail'
85
- option ['-b', '--batch-size'], 'SIZE', "How many hosts to run in parallel (defaults to #{Gaptool::SSH::BATCH_SIZE})", default: Gaptool::SSH::BATCH_SIZE
86
+ option ['-B', '--batch-size'], 'SIZE', "How many hosts to run in parallel (defaults to #{Gaptool::SSH::BATCH_SIZE})", default: Gaptool::SSH::BATCH_SIZE
86
87
  parameter 'COMMAND ...', 'Command to run', attribute_name: :commands
87
88
 
88
89
  def execute
@@ -216,7 +217,7 @@ module Gaptool
216
217
  option ['-s', '--serial'], :flag, 'Run command serially. Order of execution is unknown.'
217
218
  option ['-W', '--whyrun'], :flag, 'Whyrun, like dry-run but different.'
218
219
  option ['-c', '--continue-on-errors'], :flag, 'Continue execution even if one or more hosts fail'
219
- option ['-b', '--batch-size'], 'SIZE', "How many hosts to run in parallel (defaults to #{Gaptool::SSH::BATCH_SIZE})", default: Gaptool::SSH::BATCH_SIZE
220
+ option ['-B', '--batch-size'], 'SIZE', "How many hosts to run in parallel (defaults to #{Gaptool::SSH::BATCH_SIZE})", default: Gaptool::SSH::BATCH_SIZE
220
221
 
221
222
  def execute
222
223
  attrs = Gaptool::Helpers.split_attrs(attribute_list)
@@ -241,9 +242,9 @@ module Gaptool
241
242
  pull = "#{git} fetch --all; #{git} reset --hard origin/`#{git} rev-parse --abbrev-ref HEAD`"
242
243
  wopts = node['whyrun'] ? ' -W ' : ''
243
244
 
244
- unless node['chef_branch'].nil?
245
- json['chefbranch'] = node['chef_branch']
246
- pull = "#{git} checkout -f #{node['chef_branch']}; #{git} fetch --all; #{git} reset --hard origin/#{node['chef_branch']}"
245
+ unless node['attrs']['chef_branch'].nil?
246
+ 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']}"
247
248
  end
248
249
  upload!(StringIO.new(json.to_json), '/tmp/chef.json')
249
250
  script = <<-EOS
@@ -278,7 +279,7 @@ EOS
278
279
  option ['-H', '--hidden'], :flag, 'Display hidden hosts'
279
280
  option ['-s', '--serial'], :flag, 'Run command serially. Order of execution is unknown.'
280
281
  option ['-c', '--continue-on-errors'], :flag, 'Continue execution even if one or more hosts fail'
281
- option ['-b', '--batch-size'], 'SIZE', "How many hosts to run in parallel (defaults to #{Gaptool::SSH::BATCH_SIZE})", default: Gaptool::SSH::BATCH_SIZE
282
+ option ['-B', '--batch-size'], 'SIZE', "How many hosts to run in parallel (defaults to #{Gaptool::SSH::BATCH_SIZE})", default: Gaptool::SSH::BATCH_SIZE
282
283
  option ['-v', '--verbose'], :flag, 'More verbose output'
283
284
 
284
285
  def execute
@@ -377,4 +378,77 @@ EOS
377
378
  puts "gaptool-server #{vinfo['server_version']}"
378
379
  end
379
380
  end
381
+
382
+ class ScpCommand < Clamp::Command
383
+ option ['-r', '--role'], 'ROLE', 'Instance role'
384
+ option ['-e', '--environment'], 'ENVIRONMENT', 'Instance environment'
385
+ option ['-i', '--instance'], 'INSTANCE', 'Instance id (i-xxxxxxxx)'
386
+ option ['-s', '--serial'], :flag, 'Run command serially. Order of execution is unknown.'
387
+ option ['-x', '--exclude-hidden'], :flag, 'Exclude hidden hosts'
388
+ option ['-c', '--continue-on-errors'], :flag, 'Continue execution even if one or more hosts fail'
389
+ option ['-B', '--batch-size'], 'SIZE', "How many hosts to run in parallel (defaults to #{Gaptool::SSH::BATCH_SIZE})", default: Gaptool::SSH::BATCH_SIZE
390
+ parameter 'SRC', 'Source file spec', attribute_name: :src
391
+ parameter '[DEST]', 'Dest file spec.', attribute_name: :dest
392
+
393
+ def execute
394
+ if src.start_with?(':')
395
+ # from remote to local
396
+ signal_usage_error('SRC and DEST cannot be both remote') \
397
+ if dest && dest.start_with?(':')
398
+ source = src[1..-1]
399
+ destf = dest ? dest : File.join(Dir.pwd, File.basename(source))
400
+ destd = File.dirname(destf)
401
+ Gaptool::Helpers.error("Cannot write to #{destd}") \
402
+ unless File.writable?(destd)
403
+
404
+ pre_hook = proc do |node|
405
+ download! node['source'], "#{node['destf']}.#{node['instance']}"
406
+ end
407
+
408
+ else
409
+ # from local to remote
410
+ signal_usage_error('SRC and DEST cannot be both local') \
411
+ if dest && !dest.start_with?(':')
412
+ begin
413
+ source = File.realpath(src)
414
+ rescue => e
415
+ Gaptool::Helpers.error(e)
416
+ end
417
+ destf = dest ? dest[1..-1] : File.basename(src)
418
+ if destf.end_with?('/')
419
+ destd = destf
420
+ destf = File.join(destf, File.basename(src))
421
+ else
422
+ destd = File.dirname(destf)
423
+ end
424
+
425
+ pre_hook = proc do |node|
426
+ if test("[ -w #{node['destd']} ]")
427
+ upload! node['source'], node['destf']
428
+ else
429
+ fail "No such directory #{node['destd']}" \
430
+ unless test("[ -d #{node['destd']} ]")
431
+ tmp = File.join('/tmp', File.basename(node['destf']))
432
+ upload! node['source'], tmp
433
+ execute("sudo mv #{tmp} #{node['destf']}")
434
+ end
435
+ end
436
+ end
437
+
438
+ params = exclude_hidden? ? {} : { hidden: true }
439
+ nodes = Gaptool::API.query_nodes(params.merge(instance: instance,
440
+ role: role,
441
+ environment: environment))
442
+ nodes = nodes.map { |x| x.merge('source' => source, 'destd' => destd, 'destf' => destf) }
443
+
444
+ res = Gaptool::SSH.exec(
445
+ nodes, [],
446
+ pre_hooks: [pre_hook], serial: serial?,
447
+ continue_on_errors: continue_on_errors?,
448
+ batch_size: batch_size,
449
+ log_level: Logger::INFO
450
+ )
451
+ exit res
452
+ end
453
+ end
380
454
  end
@@ -77,8 +77,8 @@ EOF
77
77
  File.open(config, 'w') { |f| f.write(content) }
78
78
  end
79
79
 
80
- def self.configure_sshkit
81
- SSHKit.config.output_verbosity = Logger::WARN
80
+ def self.configure_sshkit(opts = {})
81
+ SSHKit.config.output_verbosity = opts[:log_level] || Logger::WARN
82
82
  SSHKit::Backend::Netssh.configure do |ssh|
83
83
  ssh.connection_timeout = 30
84
84
  ssh.ssh_options = {
@@ -99,12 +99,12 @@ EOF
99
99
  end
100
100
  pre = opts[:pre_hooks] || []
101
101
  post = opts[:post_hooks] || []
102
+ Gaptool::SSH.configure_sshkit(log_level: opts[:log_level])
102
103
  opts = {
103
104
  limit: opts[:batch_size].to_i || BATCH_SIZE,
104
105
  on_errors: opts[:continue_on_errors] ? :continue : :exit,
105
106
  wait: opts[:wait] || 0
106
107
  }
107
- Gaptool::SSH.configure_sshkit
108
108
  runner_cls = if serial
109
109
  SSHKit::Runner::SafeSequential
110
110
  else
@@ -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 'scp', 'Copy file to-from instance(s)', ScpCommand
19
20
  subcommand 'version', 'Show version', VersionCommand
20
21
  end
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.beta1
4
+ version: 0.8.0.pre.beta2
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-05 00:00:00.000000000 Z
13
+ date: 2016-01-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json