gaptool-client 0.8.0.pre.alpha9 → 0.8.0.pre.alpha10

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: 5eb227c335b95b93411e1446529c5da13437e753
4
- data.tar.gz: 870b19b48fa7ae86a5f701153e0277b44dfb0213
3
+ metadata.gz: fa9dd20c5a3510871c8f608509468eecbe10af1d
4
+ data.tar.gz: 6b630911606322dcfe84c079d39ac1f84a3519d8
5
5
  SHA512:
6
- metadata.gz: b2e6a9fde7bd8dc82e2712e96e694e25a46f7a17084c42e04e0655989e8a6ba863170f0e392975d060972061efe1d69384eb3ba11ab21330b872c8c0d7ae8771
7
- data.tar.gz: a382e833341ba9f73f7a16a5b8d9c717c6dae977e3ef82113cc0e005b1554ee20f7249f1877557520a96810a473b092c7cc7d784b9b15fbabbbf949321e4d05f
6
+ metadata.gz: e1a964392d1513c5d6737d74be6c80a4c1f7817c49aa41670fd6737a8253330b1410b5fdebee963567c8e6db5859635e8af716ca36a070415f6c9483628280d5
7
+ data.tar.gz: 97a514d92544ed74fe8be26135623f816d568cd42460a36717289369faf3f7f53feadb5ecf70f37e095e1a88b13a88cd66b326ee5651146a9f635ef6d319b315
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0-alpha9
1
+ 0.8.0-alpha10
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
18
18
  s.add_runtime_dependency 'json', '~> 1.8'
19
19
  s.add_runtime_dependency 'rainbow', '~> 2.0'
20
20
  s.add_runtime_dependency 'clamp', '~> 0.6'
21
- s.add_runtime_dependency 'gaptool-api', '~> 0.8'
21
+ s.add_runtime_dependency 'gaptool-api', '>= 0.8.1'
22
22
  s.add_runtime_dependency 'sshkit', '~> 1.8', '>= 1.8.1'
23
23
  end
@@ -4,7 +4,11 @@ require 'gaptool-api'
4
4
  module Gaptool
5
5
  module API
6
6
  def self.client
7
- @client ||= GTAPI::GaptoolServer.new(
7
+ @client ||= new
8
+ end
9
+
10
+ def self.new
11
+ GTAPI::GaptoolServer.new(
8
12
  ENV['GT_USER'], ENV['GT_KEY'],
9
13
  ENV['GT_URL'], ENV['GT_AWS_ZONE']
10
14
  )
@@ -15,19 +19,20 @@ module Gaptool
15
19
  role = opts[:role]
16
20
  environment = opts[:environment]
17
21
  params = opts[:params]
22
+ cl = opts[:client] || client
18
23
 
19
24
  if instance
20
25
  puts Rainbow('Ignoring role and environment as instance is set').red \
21
26
  if role || environment
22
- [Gaptool::API.client.getonenode(instance)]
27
+ [cl.getonenode(instance)]
23
28
  elsif role && environment
24
- Gaptool::API.client.getenvroles(role, environment, params)
29
+ cl.getenvroles(role, environment, params)
25
30
  elsif role
26
- Gaptool::API.client.getrolenodes(role, params)
31
+ cl.getrolenodes(role, params)
27
32
  elsif environment
28
- Gaptool::API.client.getenvnodes(environment, params)
33
+ cl.getenvnodes(environment, params)
29
34
  else
30
- Gaptool::API.client.getallnodes(params)
35
+ cl.getallnodes(params)
31
36
  end
32
37
  end
33
38
 
@@ -1,6 +1,5 @@
1
1
  # coding: utf-8
2
2
  # rubocop:disable Metrics/LineLength
3
- #
4
3
  require 'rainbow'
5
4
  require 'json'
6
5
  require 'clamp'
@@ -23,11 +22,21 @@ module Gaptool
23
22
  'override chef run_list. recipe[cb::recipe] or role[myrole]. Can be specified multiple times',
24
23
  multivalued: true, attribute_name: 'chef_runlist')
25
24
  option ['--no-terminate'], :flag, 'Add terminate protection'
25
+
26
26
  def execute
27
27
  no_terminate = no_terminate? ? true : nil
28
- Gaptool::API.client.addnode(zone, type, role, environment, nil, security_group,
29
- ami, chef_repo, chef_branch, chef_runlist,
30
- no_terminate)
28
+ res = Gaptool::API.client.addnode(zone, type, role, environment, nil, security_group,
29
+ ami, chef_repo, chef_branch, chef_runlist,
30
+ no_terminate)
31
+ if res['result'] == 'error'
32
+ puts Rainbow(res['message']).red
33
+ exit 1
34
+ end
35
+
36
+ puts "#{Rainbow('Successfully init instance').green} #{Rainbow(res['instance']).blue}:"
37
+ res.select { |k, _| k != 'instance' && k != 'secret' }.sort.each do |k, v|
38
+ puts "- #{k}: #{Rainbow(v).blue}"
39
+ end
31
40
  end
32
41
  end
33
42
 
@@ -214,28 +223,16 @@ module Gaptool
214
223
 
215
224
  nodes = nodes.map do |x|
216
225
  x['whyrun'] = whyrun?
217
- x['chef_branch'] = chef_branch
218
- x['attrs'] = attrs
226
+ x['attrs'] = {
227
+ 'chef_branch' => chef_branch
228
+ }.merge(attrs)
219
229
  x
220
230
  end
221
231
 
222
232
  pre_hook = proc do |node|
223
- if node['chef_runlist'].nil?
224
- runlist = ['recipe[main]']
225
- elsif node['chef_runlist'].is_a? Array
226
- runlist = node['chef_runlist']
227
- end
228
- json = {
229
- 'role' => node['role'],
230
- 'environment' => node['environment'],
231
- 'run_list' => runlist,
232
- 'apps' => node['apps'] || [],
233
- 'gaptool' => {
234
- 'user' => ENV['GT_USER'],
235
- 'key' => ENV['GT_KEY'],
236
- 'url' => ENV['GT_URL']
237
- }
238
- }.merge(node['attrs'])
233
+ cl = Gaptool::API.new
234
+ json = cl.getnodeattrs(node['instance'], node['attrs'])
235
+ json['run_list'] ||= node['chef_runlist'] || ['recipe[main]']
239
236
  git = 'sudo -u admin git'
240
237
  pull = "#{git} fetch --all; #{git} reset --hard origin/`#{git} rev-parse --abbrev-ref HEAD`"
241
238
  wopts = node['whyrun'] ? ' -W ' : ''
@@ -246,6 +243,8 @@ module Gaptool
246
243
  end
247
244
  upload!(StringIO.new(json.to_json), '/tmp/chef.json')
248
245
  script = <<-EOS
246
+ #!/bin/bash
247
+ set -e
249
248
  cd /var/data/admin/ops
250
249
  #{pull}
251
250
  sudo chef-solo -c /var/data/admin/ops/cookbooks/solo.rb -j /tmp/chef.json -E #{node['environment']}#{wopts}
@@ -276,8 +275,9 @@ EOS
276
275
  option ['-s', '--serial'], :flag, 'Run command serially. Order of execution is unknown.'
277
276
  option ['-c', '--continue-on-errors'], :flag, 'Continue execution even if one or more hosts fail'
278
277
  option ['-b', '--batch-size'], 'SIZE', "How many hosts to run in parallel (defaults to #{Gaptool::SSH::BATCH_SIZE})", default: Gaptool::SSH::BATCH_SIZE
278
+ option ['-v', '--verbose'], :flag, 'More verbose output'
279
279
 
280
- def execute # rubocop:disable Metrics/MethodLength
280
+ def execute
281
281
  attrs = Gaptool::Helpers.split_attrs(attribute_list)
282
282
  if instance
283
283
  n = Gaptool::API.client.getonenode(instance)
@@ -307,45 +307,33 @@ EOS
307
307
  seen << x['instance']
308
308
  res
309
309
  end
310
+
310
311
  nodes = nodes.map do |x|
311
- x['apps'] = x['apps']
312
- x['apps_to_deploy'] = (Set.new(x['apps']) & app_set).to_a
313
- x['rollback'] = rollback?
314
- x['branch'] = branch || 'master'
315
- x['migrate'] = migrate?
316
- x['attrs'] = attrs
312
+ x['verbose'] = verbose?
313
+ x['attrs'] = {
314
+ 'deploy_apps' => (Set.new(x['apps']) & app_set).to_a,
315
+ 'rollback' => rollback?,
316
+ 'branch' => branch,
317
+ 'migrate' => migrate?
318
+ }.merge(attrs)
317
319
  x
318
320
  end
319
321
 
320
322
  pre_hook = proc do |node|
323
+ client = Gaptool::API.new
324
+ json = client.getnodeattrs(node['instance'], node['attrs'])
325
+ json['run_list'] = node['chef_runlist'] || ['recipe[deploy]']
321
326
  host = "#{node['role']}:#{node['environment']}:#{node['instance']}"
322
327
  puts "#{Rainbow('Deploying apps').cyan} '" + \
323
- Rainbow(node['apps_to_deploy'].join(' ')).green + \
328
+ Rainbow(json['deploy_apps'].join(' ')).green + \
324
329
  "' #{Rainbow('on').cyan} " + \
325
330
  Rainbow(host).green
331
+ puts "#{Rainbow(host).green}: #{JSON.pretty_generate(json)}" if node['verbose']
326
332
 
327
- if node['chef_runlist'].nil?
328
- runlist = ['recipe[deploy]']
329
- elsif node['chef_runlist'].is_a? Array
330
- runlist = node['chef_runlist']
331
- end
332
- json = {
333
- 'role' => node['role'],
334
- 'environment' => node['environment'],
335
- 'run_list' => runlist,
336
- 'apps' => node['apps'],
337
- 'deploy_apps' => node['apps_to_deploy'],
338
- 'rollback' => node['rollback'],
339
- 'branch' => node['branch'],
340
- 'migrate' => node['migrate'],
341
- 'gaptool' => {
342
- 'user' => ENV['GT_USER'],
343
- 'key' => ENV['GT_KEY'],
344
- 'url' => ENV['GT_URL']
345
- }
346
- }.merge(node['attrs']).to_json
347
- upload!(StringIO.new(json), '/tmp/chef.json')
333
+ upload!(StringIO.new(json.to_json), '/tmp/chef.json')
348
334
  script = <<-EOS
335
+ #!/bin/bash
336
+ set -e
349
337
  cd /var/data/admin/ops
350
338
  sudo -u admin git pull
351
339
  sudo chef-solo -c /var/data/admin/ops/cookbooks/solo.rb -j /tmp/chef.json -E #{node['environment']}
@@ -58,14 +58,14 @@ Host #{host} #{node['instance']}
58
58
  emark = "# -- end #{node['instance']}"
59
59
 
60
60
  if Regexp.new(mark).match(content)
61
- puts Rainbow("Updating ssh config for #{get_host(node)}").green if verbose
61
+ puts Rainbow("Updating ssh config for #{Gaptool::API.get_host(node)}").green if verbose
62
62
  content.gsub!(/#{mark}.*?#{emark}/m, snip.strip)
63
63
  elsif Regexp.new(STOP_MARKER).match(content)
64
- puts Rainbow("Adding ssh config for #{get_host(node)}").green if verbose
64
+ puts Rainbow("Adding ssh config for #{Gaptool::API.get_host(node)}").green if verbose
65
65
  content.gsub!(/#{STOP_MARKER}/m, snip + "\n" + STOP_MARKER)
66
66
  else
67
67
  puts Rainbow('No gt ssh config found: please run gt ssh-config').yellow
68
- puts Rainbow("Adding ssh config for #{get_host(node)}").green if verbose
68
+ puts Rainbow("Adding ssh config for #{Gaptool::API.get_host(node)}").green if verbose
69
69
  content = <<-EOF
70
70
  #{content}
71
71
  #{START_MARKER}
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.alpha9
4
+ version: 0.8.0.pre.alpha10
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-03 00:00:00.000000000 Z
13
+ date: 2016-01-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
@@ -58,16 +58,16 @@ dependencies:
58
58
  name: gaptool-api
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - "~>"
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: '0.8'
63
+ version: 0.8.1
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - "~>"
68
+ - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: '0.8'
70
+ version: 0.8.1
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: sshkit
73
73
  requirement: !ruby/object:Gem::Requirement