omc 0.0.7 → 0.0.8

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: 46021d8d49c5f6627c59c726ab9d46ca780cae4e
4
- data.tar.gz: 399407808e128c45549e0473a85f3f749ba86b30
3
+ metadata.gz: a6f0467e39b53057c023904b1d13696c2959bf9f
4
+ data.tar.gz: 89ca19b9cf793ca0a38e6dc1e0f9353457a26f7e
5
5
  SHA512:
6
- metadata.gz: 1f4f9dcbff7fa1a3199aaadd08473f1ad7afcb94dd1a7f6f32275c630e2b1c9ad89f7a13aa0d07309813acbffc2d573f3b700f11eb48fbee516e9f2561bc420f
7
- data.tar.gz: 8bb6dbb519b9f98230bce973ea1658debc63bf00d3ec5362c9a26322f0b4bf56d75fc7159e958e12dd0551f10005c4793e6625d960093cc75a75f575d1121353
6
+ metadata.gz: 642d1acc7fdc9fc3e06c0c45cd75ac4bf6a875b60c4e65cae90aed0a059c1f636ca4638819ceaba636942b23c50cf9ee012569c37d69d07d58efa06810358d77
7
+ data.tar.gz: ebe7a0e6e7fb88a09732835b0ce89ee50088e2147945f74bf1b2aea8c5306bea8eca53c4941db0cf2347c6523b97659f686080c5240ccb0b567cce2f55a2a9a6
@@ -10,7 +10,7 @@ module Omc
10
10
 
11
11
  def stacks
12
12
  @stacks ||= client.describe_stacks[:stacks].map do |stack|
13
- ::Omc::Stack.new(self, stack)
13
+ Stack.new(self, stack)
14
14
  end
15
15
  end
16
16
  end
@@ -11,41 +11,50 @@ module Omc
11
11
 
12
12
  desc 'ssh STACK', 'Connect to an instance on a stack on an account'
13
13
  def ssh(stack)
14
- command = StackCommand.new(user, stack, layer: options[:layer])
14
+ command = StackCommand.new(aws_account, user, stack, layer: options[:layer])
15
15
  command.ssh
16
16
  end
17
17
 
18
+ desc 'ssh_exec STACK COMMAND', 'Connect to an instance on a stack on an account and execute a command'
19
+ def ssh_exec(stack, user_command)
20
+ command = StackCommand.new(aws_account, user, stack, layer: options[:layer])
21
+ command.ssh_and_execute user_command
22
+ end
23
+
18
24
  desc 'console STACK', 'Run a rails console on the given stack'
19
25
  method_option :app
20
26
  def console(stack)
21
- command = StackCommand.new(user, stack, app: options[:app], layer: options[:layer])
27
+ command = StackCommand.new(aws_account, user, stack, app: options[:app], layer: options[:layer])
22
28
  command.console
23
29
  end
24
30
 
25
31
  desc 'db STACK', 'Connect and run the database client on the given stack'
26
32
  method_option :app
27
33
  def db(stack)
28
- command = StackCommand.new(user, stack, app: options[:app], layer: options[:layer])
34
+ command = StackCommand.new(aws_account, user, stack, app: options[:app], layer: options[:layer])
29
35
  command.db
30
36
  end
31
37
 
32
38
  desc 'unicorn ACTION STACK', 'Connect and run the given action on the unicorns'
33
39
  method_option :app
34
40
  def unicorn(action, stack)
35
- command = StackCommand.new(user, stack, app: options[:app])
41
+ command = StackCommand.new(aws_account, user, stack, app: options[:app])
36
42
  command.unicorn(action)
37
43
  end
38
44
 
39
45
  desc 'status STACK', 'Show the instance status for the given stack'
40
46
  def status(stack)
41
- command = StackCommand.new(user, stack, app: options[:app], layer: options[:layer])
47
+ command = StackCommand.new(aws_account, user, stack, app: options[:app], layer: options[:layer])
42
48
  command.status(self)
43
49
  end
44
50
 
45
51
  private
46
52
  def user
47
- iam_account = vault.account(account) || abort("Account #{account.inspect} not configured")
48
- iam_account.users.first || abort("No users configured under #{account.inspect}")
53
+ aws_account.users.first || abort("No users configured under #{account.inspect}")
54
+ end
55
+
56
+ def aws_account
57
+ vault.account(account) || abort("Account #{account.inspect} not configured")
49
58
  end
50
59
 
51
60
  def account
@@ -17,21 +17,15 @@ module Omc
17
17
  end
18
18
 
19
19
  def instances
20
- @instances ||= client.describe_instances(stack_id: self[:stack_id])[:instances].map do |instance|
21
- ::Omc::Instance.new(self, instance)
22
- end
20
+ @instances ||= describe(:instances).map{ |instance| Instance.new(self, instance) }
23
21
  end
24
22
 
25
23
  def apps
26
- @apps ||= client.describe_apps(stack_id: self[:stack_id])[:apps].map do |app|
27
- ::Omc::App.new(self, app)
28
- end
24
+ @apps ||= describe(:apps).map{ |app| App.new(self, app) }
29
25
  end
30
26
 
31
27
  def layers
32
- @layers ||= client.describe_layers(stack_id: self[:stack_id])[:layers].map do |layer|
33
- ::Omc::Layer.new(self, layer)
34
- end
28
+ @layers ||= describe(:layers).map{ |layer| Layer.new(self, layer) }
35
29
  end
36
30
 
37
31
  def execute_recipes(app, recipes: [], name: "execute_recipes")
@@ -46,5 +40,11 @@ module Omc
46
40
  }
47
41
  )
48
42
  end
43
+
44
+ private
45
+
46
+ def describe(object)
47
+ client.public_send("describe_#{object}", stack_id: self[:stack_id])[object]
48
+ end
49
49
  end
50
50
  end
@@ -3,7 +3,8 @@ require 'omc/account'
3
3
 
4
4
  module Omc
5
5
  class StackCommand
6
- def initialize user, stack_name, app: nil, layer: nil
6
+ def initialize aws_account, user, stack_name, app: nil, layer: nil
7
+ @aws_account = aws_account
7
8
  @user = user
8
9
  @stack_name = stack_name
9
10
  @app_name = app
@@ -11,15 +12,15 @@ module Omc
11
12
  end
12
13
 
13
14
  def ssh
14
- exec "ssh", ssh_host
15
+ exec "ssh", *([ssh_host] + default_ssh_args)
15
16
  end
16
17
 
17
18
  def console
18
- ssh_and_execute "cd /srv/www/#{app[:name]}/current && RAILS_ENV=#{app[:attributes]['RailsEnv']} bundle exec rails c"
19
+ ssh_and_execute_as_deploy "cd /srv/www/#{app[:shortname]}/current && RAILS_ENV=#{app[:attributes]['RailsEnv']} bundle exec rails c"
19
20
  end
20
21
 
21
22
  def db
22
- ssh_and_execute "cd /srv/www/#{app[:name]}/current && RAILS_ENV=#{app[:attributes]['RailsEnv']} bundle exec rails db -p"
23
+ ssh_and_execute_as_deploy "cd /srv/www/#{app[:shortname]}/current && RAILS_ENV=#{app[:attributes]['RailsEnv']} bundle exec rails db -p"
23
24
  end
24
25
 
25
26
  def unicorn(action)
@@ -40,14 +41,22 @@ module Omc
40
41
  i[:availability_zone],
41
42
  i[:ec2_instance_id],
42
43
  i[:public_ip],
44
+ i[:private_ip],
43
45
  ]
44
46
  end
45
47
  thor.print_table(details)
46
48
  end
47
49
 
48
- private
49
50
  def ssh_and_execute(command)
50
- exec 'ssh', '-t', ssh_host, "sudo su deploy -c '#{command}'"
51
+ puts "Executing '#{command}'"
52
+ args = default_ssh_args + ['-t', ssh_host, command]
53
+
54
+ exec 'ssh', *args
55
+ end
56
+
57
+ private
58
+ def ssh_and_execute_as_deploy(command)
59
+ ssh_and_execute "sudo su deploy -c '#{command}'"
51
60
  end
52
61
 
53
62
  def app
@@ -70,7 +79,10 @@ module Omc
70
79
  end
71
80
 
72
81
  def ssh_host
73
- "#{@user.name}@#{instance[:public_ip]}"
82
+ ip_address = bastion ? instance[:private_ip] : instance[:public_ip]
83
+ host = "#{@user.name}@#{ip_address}"
84
+ puts "Connecting to #{host}"
85
+ host
74
86
  end
75
87
 
76
88
  def account
@@ -81,6 +93,14 @@ module Omc
81
93
  @stack ||= get_by_name(account.stacks, @stack_name)
82
94
  end
83
95
 
96
+ def bastion
97
+ @aws_account.bastions.detect { |y| y.name == @stack_name }
98
+ end
99
+
100
+ def default_ssh_args
101
+ bastion ? [ '-o', "ProxyCommand ssh -W %h:%p #{bastion.host}" ] : []
102
+ end
103
+
84
104
  def get_by_name collection, name, key: :name
85
105
  collection.detect do |x|
86
106
  x[key] == name
@@ -1,3 +1,3 @@
1
1
  module Omc
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "thor", '~> 0.19'
21
- spec.add_dependency "aws_cred_vault", '~> 0.0'
21
+ spec.add_dependency "aws_cred_vault", '~> 0.0.7'
22
22
  spec.add_dependency "aws-sdk", '~> 1.56'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clarke Brunsdon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-26 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.0'
33
+ version: 0.0.7
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0.0'
40
+ version: 0.0.7
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: aws-sdk
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  requirements: []
141
141
  rubyforge_project:
142
- rubygems_version: 2.2.2
142
+ rubygems_version: 2.4.5
143
143
  signing_key:
144
144
  specification_version: 4
145
145
  summary: Opsworks Missing Console - Useful Commands for Opsworks