omc 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/omc/cli.rb +12 -4
- data/lib/omc/layer.rb +22 -0
- data/lib/omc/stack.rb +20 -0
- data/lib/omc/stack_command.rb +23 -6
- data/lib/omc/version.rb +1 -1
- data/omc.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46021d8d49c5f6627c59c726ab9d46ca780cae4e
|
4
|
+
data.tar.gz: 399407808e128c45549e0473a85f3f749ba86b30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f4f9dcbff7fa1a3199aaadd08473f1ad7afcb94dd1a7f6f32275c630e2b1c9ad89f7a13aa0d07309813acbffc2d573f3b700f11eb48fbee516e9f2561bc420f
|
7
|
+
data.tar.gz: 8bb6dbb519b9f98230bce973ea1658debc63bf00d3ec5362c9a26322f0b4bf56d75fc7159e958e12dd0551f10005c4793e6625d960093cc75a75f575d1121353
|
data/lib/omc/cli.rb
CHANGED
@@ -7,30 +7,38 @@ require "omc/config"
|
|
7
7
|
module Omc
|
8
8
|
class Cli < Thor
|
9
9
|
class_option :account, aliases: '-a', optional: true
|
10
|
+
class_option :layer, aliases: '-l', optional: true
|
10
11
|
|
11
12
|
desc 'ssh STACK', 'Connect to an instance on a stack on an account'
|
12
13
|
def ssh(stack)
|
13
|
-
command = StackCommand.new(user, stack)
|
14
|
+
command = StackCommand.new(user, stack, layer: options[:layer])
|
14
15
|
command.ssh
|
15
16
|
end
|
16
17
|
|
17
18
|
desc 'console STACK', 'Run a rails console on the given stack'
|
18
19
|
method_option :app
|
19
20
|
def console(stack)
|
20
|
-
command = StackCommand.new(user, stack, options[:app])
|
21
|
+
command = StackCommand.new(user, stack, app: options[:app], layer: options[:layer])
|
21
22
|
command.console
|
22
23
|
end
|
23
24
|
|
24
25
|
desc 'db STACK', 'Connect and run the database client on the given stack'
|
25
26
|
method_option :app
|
26
27
|
def db(stack)
|
27
|
-
command = StackCommand.new(user, stack, options[:app])
|
28
|
+
command = StackCommand.new(user, stack, app: options[:app], layer: options[:layer])
|
28
29
|
command.db
|
29
30
|
end
|
30
31
|
|
32
|
+
desc 'unicorn ACTION STACK', 'Connect and run the given action on the unicorns'
|
33
|
+
method_option :app
|
34
|
+
def unicorn(action, stack)
|
35
|
+
command = StackCommand.new(user, stack, app: options[:app])
|
36
|
+
command.unicorn(action)
|
37
|
+
end
|
38
|
+
|
31
39
|
desc 'status STACK', 'Show the instance status for the given stack'
|
32
40
|
def status(stack)
|
33
|
-
command = StackCommand.new(user, stack, options[:app])
|
41
|
+
command = StackCommand.new(user, stack, app: options[:app], layer: options[:layer])
|
34
42
|
command.status(self)
|
35
43
|
end
|
36
44
|
|
data/lib/omc/layer.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Omc
|
4
|
+
class Layer
|
5
|
+
attr_reader :stack, :attributes
|
6
|
+
|
7
|
+
extend Forwardable
|
8
|
+
def_delegators :@attributes, :[]
|
9
|
+
def_delegators :stack, :account, :client
|
10
|
+
|
11
|
+
def initialize stack, attributes
|
12
|
+
@stack = stack
|
13
|
+
@attributes = attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
def instances
|
17
|
+
@instances ||= @stack.instances.select do |i|
|
18
|
+
i[:layer_ids].include? self[:layer_id]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/omc/stack.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'omc/instances'
|
2
2
|
require 'omc/app'
|
3
|
+
require 'omc/layer'
|
3
4
|
require 'forwardable'
|
4
5
|
|
5
6
|
module Omc
|
@@ -26,5 +27,24 @@ module Omc
|
|
26
27
|
::Omc::App.new(self, app)
|
27
28
|
end
|
28
29
|
end
|
30
|
+
|
31
|
+
def layers
|
32
|
+
@layers ||= client.describe_layers(stack_id: self[:stack_id])[:layers].map do |layer|
|
33
|
+
::Omc::Layer.new(self, layer)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute_recipes(app, recipes: [], name: "execute_recipes")
|
38
|
+
client.create_deployment(
|
39
|
+
stack_id: self[:stack_id],
|
40
|
+
app_id: app[:app_id],
|
41
|
+
command: {
|
42
|
+
name: name,
|
43
|
+
args: {
|
44
|
+
"recipes" => recipes
|
45
|
+
}
|
46
|
+
}
|
47
|
+
)
|
48
|
+
end
|
29
49
|
end
|
30
50
|
end
|
data/lib/omc/stack_command.rb
CHANGED
@@ -3,10 +3,11 @@ require 'omc/account'
|
|
3
3
|
|
4
4
|
module Omc
|
5
5
|
class StackCommand
|
6
|
-
def initialize user, stack_name,
|
6
|
+
def initialize user, stack_name, app: nil, layer: nil
|
7
7
|
@user = user
|
8
8
|
@stack_name = stack_name
|
9
|
-
@app_name =
|
9
|
+
@app_name = app
|
10
|
+
@layer_name = layer
|
10
11
|
end
|
11
12
|
|
12
13
|
def ssh
|
@@ -21,6 +22,15 @@ module Omc
|
|
21
22
|
ssh_and_execute "cd /srv/www/#{app[:name]}/current && RAILS_ENV=#{app[:attributes]['RailsEnv']} bundle exec rails db -p"
|
22
23
|
end
|
23
24
|
|
25
|
+
def unicorn(action)
|
26
|
+
case action
|
27
|
+
when "restart"
|
28
|
+
stack.execute_recipes(app, recipes: ["deploy::rails-restart"], name: "restart")
|
29
|
+
else
|
30
|
+
abort("Unicorn action should be one of [restart]")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
def status(thor)
|
25
35
|
details = stack.instances.map do |i|
|
26
36
|
[
|
@@ -48,8 +58,15 @@ module Omc
|
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
61
|
+
def layer
|
62
|
+
if @layer_name
|
63
|
+
get_by_name(stack.layers, @layer_name, key: :shortname)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
51
67
|
def instance
|
52
|
-
|
68
|
+
instances = layer ? layer.instances : stack.instances
|
69
|
+
instances.detect(&:online?) || abort("No running instances")
|
53
70
|
end
|
54
71
|
|
55
72
|
def ssh_host
|
@@ -64,10 +81,10 @@ module Omc
|
|
64
81
|
@stack ||= get_by_name(account.stacks, @stack_name)
|
65
82
|
end
|
66
83
|
|
67
|
-
def get_by_name collection, name
|
84
|
+
def get_by_name collection, name, key: :name
|
68
85
|
collection.detect do |x|
|
69
|
-
x[
|
70
|
-
end || abort("Can't find #{name.inspect} among #{collection.map{|x| x[
|
86
|
+
x[key] == name
|
87
|
+
end || abort("Can't find #{name.inspect} among #{collection.map{|x| x[key] }.inspect}")
|
71
88
|
end
|
72
89
|
end
|
73
90
|
end
|
data/lib/omc/version.rb
CHANGED
data/omc.gemspec
CHANGED
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.
|
4
|
+
version: 0.0.7
|
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
|
+
date: 2014-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description:
|
84
98
|
email:
|
85
99
|
- clarke@freerunningtechnologies.com
|
@@ -100,6 +114,7 @@ files:
|
|
100
114
|
- lib/omc/cli.rb
|
101
115
|
- lib/omc/config.rb
|
102
116
|
- lib/omc/instances.rb
|
117
|
+
- lib/omc/layer.rb
|
103
118
|
- lib/omc/stack.rb
|
104
119
|
- lib/omc/stack_command.rb
|
105
120
|
- lib/omc/version.rb
|