omc 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/omc.rb +0 -1
- data/lib/omc/cli.rb +14 -14
- data/lib/omc/stack_command.rb +48 -0
- data/lib/omc/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40766a4dd46b353e2b9bfdd9cc5628f83845d90b
|
4
|
+
data.tar.gz: 591dc4424274502ba89c3a1c487745ac19293955
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d280a904f65b44571e6a4f9c45f6b5ae34f6c26b921e95eff6df3395adc3007443893b9a5bf7afd3d75fdcef9cb44666fbeaefcf64389bd602c14efd225d1f3
|
7
|
+
data.tar.gz: db7927aca1c1e0a498bdfd73b4454549b29d984ef39aef69aebe06bb31c5f39cccd0f3653dd0b697d870be4167ea27f7e4b19e1fb6fe14e705fcfb4fd4ec8b3e
|
data/lib/omc.rb
CHANGED
data/lib/omc/cli.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'aws_cred_vault'
|
3
3
|
require 'aws-sdk'
|
4
|
+
require "omc/stack_command"
|
4
5
|
|
5
6
|
module Omc
|
6
7
|
class Cli < Thor
|
7
8
|
desc 'ssh', 'Connect to an instance on a stack on an account'
|
8
|
-
def ssh(
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def ssh(account_name, stack)
|
10
|
+
command = StackCommand.new(user(account), stack)
|
11
|
+
command.ssh
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
desc 'console', 'Run a rails console on the given stack'
|
15
|
+
def console(account, stack)
|
16
|
+
command = StackCommand.new(user(account), stack)
|
17
|
+
command.console
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
20
|
-
def
|
21
|
-
|
21
|
+
def user(account)
|
22
|
+
iam_account = vault.account(account) || abort("Account #{account.inspect} not configured")
|
23
|
+
iam_account.users.first || abort("No users configured under #{account.inspect}")
|
22
24
|
end
|
23
25
|
|
24
|
-
def
|
25
|
-
|
26
|
-
x[:name] == name
|
27
|
-
end || abort("Can't find #{name.inspect} among #{collection.map{|x| x[:name] }.inspect}")
|
26
|
+
def vault
|
27
|
+
AwsCredVault::Toml.new File.join(ENV['HOME'], '.aws_cred_vault')
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module Omc
|
4
|
+
class StackCommand
|
5
|
+
def initialize user, stack_name
|
6
|
+
@user = user
|
7
|
+
@stack_name = stack_name
|
8
|
+
end
|
9
|
+
|
10
|
+
def ssh
|
11
|
+
exec "ssh", ssh_host
|
12
|
+
end
|
13
|
+
|
14
|
+
def console
|
15
|
+
app = applications.first
|
16
|
+
exec 'ssh', '-t', ssh_host, "sudo su deploy -c 'cd /srv/www/#{app[:name]}/current && RAILS_ENV=#{app[:attributes]['RailsEnv']} bundle exec rails c'"
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def applications
|
21
|
+
ops.describe_apps(stack_id: stack[:stack_id])[:apps]
|
22
|
+
end
|
23
|
+
|
24
|
+
def instance
|
25
|
+
instances = ops.describe_instances(stack_id: stack[:stack_id])[:instances]
|
26
|
+
instances.reject!{|i| i[:status] != "online" }
|
27
|
+
instance = instances.first || abort("No running instances")
|
28
|
+
end
|
29
|
+
|
30
|
+
def ssh_host
|
31
|
+
"#{@user.name}@#{instance[:public_ip]}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def ops
|
35
|
+
@ops ||= ::AWS::OpsWorks::Client.new @user.credentials
|
36
|
+
end
|
37
|
+
|
38
|
+
def stack
|
39
|
+
@stack ||= get_by_name ops.describe_stacks[:stacks], @stack_name
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_by_name collection, name
|
43
|
+
collection.detect do |x|
|
44
|
+
x[:name] == name
|
45
|
+
end || abort("Can't find #{name.inspect} among #{collection.map{|x| x[:name] }.inspect}")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/omc/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Clarke Brunsdon
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- bin/omc
|
97
97
|
- lib/omc.rb
|
98
98
|
- lib/omc/cli.rb
|
99
|
+
- lib/omc/stack_command.rb
|
99
100
|
- lib/omc/version.rb
|
100
101
|
- omc.gemspec
|
101
102
|
homepage: http://github.com/freerunningtech/omc
|