rig 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/conf/accounts/default.yml +14 -0
- data/conf/config.yml +27 -0
- data/conf/templates/multi.yml +16 -0
- data/conf/templates/solo.yml +9 -0
- data/lib/rig/cloud.rb +0 -1
- data/lib/rig/cloud/connection.rb +3 -18
- data/lib/rig/cloud/instance.rb +8 -0
- data/lib/rig/command.rb +1 -1
- data/lib/rig/command/abstract.rb +13 -11
- data/lib/rig/command/main.rb +47 -32
- data/lib/rig/command/ssh.rb +27 -0
- data/lib/rig/config.rb +45 -7
- data/lib/rig/version.rb +1 -1
- data/rig.gemspec +1 -1
- metadata +10 -6
- data/lib/rig/command/instance/ssh.rb +0 -32
data/Gemfile
CHANGED
data/conf/config.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
rig:
|
3
|
+
|
4
|
+
# if you're using chef, set this to the knife.rb configuration file
|
5
|
+
# this will allow Rig to manage the chef nodes, environments and such.
|
6
|
+
#
|
7
|
+
#chef:
|
8
|
+
# knife: /path/to/chef/knife.rb
|
9
|
+
#
|
10
|
+
# TODO: Figure out the same thing for puppet
|
11
|
+
|
12
|
+
ssh:
|
13
|
+
# user to connect as, when ssh to server
|
14
|
+
user: root
|
15
|
+
|
16
|
+
# the account to use if one is not specified
|
17
|
+
default_account: default
|
18
|
+
|
19
|
+
# uncomment this and specify the accounts you want to support
|
20
|
+
# all others will be filtered from use.
|
21
|
+
#accounts:
|
22
|
+
# - default
|
23
|
+
# - production
|
24
|
+
|
25
|
+
|
26
|
+
# flavor_id: ami-8baa73e2 # ubuntu 11.10, non-ebs storage
|
27
|
+
# key_name: keyname
|
data/lib/rig/cloud.rb
CHANGED
data/lib/rig/cloud/connection.rb
CHANGED
@@ -6,33 +6,18 @@ module Rig
|
|
6
6
|
class << self
|
7
7
|
def compute
|
8
8
|
@compute ||= begin
|
9
|
-
Fog::Compute.new(
|
10
|
-
:provider => Rig.config.provider,
|
11
|
-
:aws_access_key_id => Rig.config.key,
|
12
|
-
:aws_secret_access_key => Rig.config.secret,
|
13
|
-
:region => Rig.config.region
|
14
|
-
)
|
9
|
+
Fog::Compute.new(Rig.account.compute.to_hash)
|
15
10
|
end
|
16
11
|
end
|
17
12
|
def balancer
|
18
13
|
@balancer ||= begin
|
19
14
|
#Fog::Compute.new(
|
20
|
-
Fog::AWS::ELB.new(
|
21
|
-
#:provider => Rig.config.provider,
|
22
|
-
:aws_access_key_id => Rig.config.key,
|
23
|
-
:aws_secret_access_key => Rig.config.secret,
|
24
|
-
:region => Rig.config.region
|
25
|
-
)
|
15
|
+
Fog::AWS::ELB.new(Rig.account.balancer.to_hash)
|
26
16
|
end
|
27
17
|
end
|
28
18
|
def dns
|
29
19
|
@dns ||= begin
|
30
|
-
Fog::DNS.new(
|
31
|
-
:provider => Rig.config.provider,
|
32
|
-
:aws_access_key_id => Rig.config.key,
|
33
|
-
:aws_secret_access_key => Rig.config.secret
|
34
|
-
#:region => Rig.config.region
|
35
|
-
)
|
20
|
+
Fog::DNS.new(Rig.account.dns.to_hash)
|
36
21
|
end
|
37
22
|
end
|
38
23
|
end
|
data/lib/rig/cloud/instance.rb
CHANGED
@@ -24,6 +24,14 @@ module Rig
|
|
24
24
|
def find_by_environment(env)
|
25
25
|
Rig::Cloud.compute.servers.all({"tag:Environment"=>env})
|
26
26
|
end
|
27
|
+
def find_by_role_and_environment(role, env)
|
28
|
+
Rig::Cloud.compute.servers.all({"tag:Environment"=> env, "tag:Role" => role})
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_by_nick(name)
|
32
|
+
(role, num, env) = name.match(/(\w+)(\d+)\.(\w+)/)[1..3]
|
33
|
+
find_by_role_and_environment(role, env).select {|s| s.tags['Name'] =~ /^#{role}#{num}/ }
|
34
|
+
end
|
27
35
|
|
28
36
|
def create(opts, tags={})
|
29
37
|
fog = Rig::Cloud.compute
|
data/lib/rig/command.rb
CHANGED
@@ -9,6 +9,7 @@ require 'rig/command/abstract'
|
|
9
9
|
require 'rig/command/options'
|
10
10
|
|
11
11
|
require 'rig/command/main'
|
12
|
+
require 'rig/command/ssh'
|
12
13
|
|
13
14
|
require 'rig/command/environment/main'
|
14
15
|
require 'rig/command/environment/list'
|
@@ -27,7 +28,6 @@ require 'rig/command/dns/edit'
|
|
27
28
|
require 'rig/command/dns/destroy'
|
28
29
|
|
29
30
|
require 'rig/command/instance/main'
|
30
|
-
require 'rig/command/instance/ssh'
|
31
31
|
require 'rig/command/instance/list'
|
32
32
|
require 'rig/command/instance/create'
|
33
33
|
require 'rig/command/instance/destroy'
|
data/lib/rig/command/abstract.rb
CHANGED
@@ -3,9 +3,10 @@ require 'terminal-table/import'
|
|
3
3
|
module Rig
|
4
4
|
module Command
|
5
5
|
class Abstract < Clamp::Command
|
6
|
-
option ["-n","--test"], :flag, "use Fog.mock! to test command without creating / destroying cloud resources" do |o|
|
6
|
+
option ["-n", "--test"], :flag, "use Fog.mock! to test command without creating / destroying cloud resources" do |o|
|
7
7
|
Fog.mock!
|
8
8
|
end
|
9
|
+
option ["-a", "--account"], "ACCOUNT", "set the rig account to use", :default => "default"
|
9
10
|
|
10
11
|
def print_table(columns, rows)
|
11
12
|
puts table(columns, *rows)
|
@@ -14,18 +15,19 @@ module Rig
|
|
14
15
|
def instance_list(list)
|
15
16
|
rows = []
|
16
17
|
list.each do |server|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
r = []
|
19
|
+
r << server.tags['Name']
|
20
|
+
r << server.tags['Environment']
|
21
|
+
r << server.tags['Role']
|
22
|
+
r << server.public_ip_address.to_s
|
23
|
+
r << server.private_ip_address.to_s
|
24
|
+
r << server.flavor_id.to_s
|
25
|
+
r << server.id.to_s
|
26
|
+
r << server.state.to_s.downcase
|
27
|
+
rows << r
|
26
28
|
end
|
27
29
|
|
28
|
-
print_table(%w{Name Environment Role PublicIP Size InstanceID State}, rows)
|
30
|
+
print_table(%w{Name Environment Role PublicIP PrivateIP Size InstanceID State}, rows)
|
29
31
|
end
|
30
32
|
|
31
33
|
def execute
|
data/lib/rig/command/main.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'awesome_print'
|
1
2
|
|
2
3
|
module Rig
|
3
4
|
module Command
|
@@ -8,40 +9,54 @@ module Rig
|
|
8
9
|
exit(0)
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
subcommand "accounts", "show account list" do
|
13
|
+
def execute
|
14
|
+
list = Rig.account_list
|
15
|
+
list.each do |n, f|
|
16
|
+
puts " #{n} => #{f}"
|
17
|
+
end
|
17
18
|
end
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
21
|
+
subcommand "init", "initialize configuration directory" do
|
22
|
+
option %w{-f --force}, :flag, "force creation of files", :default => false
|
23
|
+
option %w{-d --directory}, "DIRECTORY", "configuration directory", :default => "~/.rig"
|
24
|
+
|
25
|
+
def execute
|
26
|
+
dir = File.expand_path(ENV['RIG_CONFIG'] ? ENV['RIG_CONFIG'] : directory)
|
27
|
+
back = "#{dir}.bak.#{Time.now.to_i}"
|
28
|
+
conf = File.expand_path("../../../../conf", __FILE__)
|
29
|
+
|
30
|
+
files = ["config.yml", "accounts/default.yml", "templates/solo.yml", "templates/multi.yml"]
|
31
|
+
|
32
|
+
unless dir
|
33
|
+
puts "directory could not be found: tried environment variables RIG_CONFIG (#{ENV['RIG_CONFIG']}) and HOME (#{ENV['HOME']}"
|
34
|
+
exit(1)
|
35
|
+
end
|
36
|
+
|
37
|
+
if File.exists?(dir)
|
38
|
+
unless File.directory?(dir)
|
39
|
+
puts "moving old config #{dir} to #{back}"
|
40
|
+
FileUtils.mv(dir, new)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
puts "[create] #{dir}/"
|
45
|
+
FileUtils.mkdir_p(dir)
|
46
|
+
FileUtils.mkdir_p("#{dir}/accounts")
|
47
|
+
FileUtils.mkdir_p("#{dir}/templates")
|
48
|
+
|
49
|
+
files.each do |file|
|
50
|
+
src = "#{conf}/#{file}"
|
51
|
+
dest = "#{dir}/#{file}"
|
52
|
+
if File.exists?(dest) && !force?
|
53
|
+
puts "[skip] #{dest}"
|
54
|
+
else
|
55
|
+
puts "[create] #{dest}"
|
56
|
+
FileUtils.copy(src, dest)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
45
60
|
end
|
46
61
|
end
|
47
62
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rig
|
2
|
+
module Command
|
3
|
+
class Ssh < Abstract
|
4
|
+
parameter "NAME", "name of the host. <role><#>.<env>, eg: solo1.stable for the first solo role in environment stable"
|
5
|
+
def execute
|
6
|
+
user = Rig.config.ssh.user rescue nil
|
7
|
+
unless user
|
8
|
+
puts "must set rig:ssh:user in configuration."
|
9
|
+
exit(1)
|
10
|
+
end
|
11
|
+
|
12
|
+
list = Rig::Cloud::Instance.find_by_nick(name)
|
13
|
+
if list.count == 0
|
14
|
+
puts "server not found."
|
15
|
+
elsif list.count > 1
|
16
|
+
puts "query returned more than one server:"
|
17
|
+
instance_list(list)
|
18
|
+
else
|
19
|
+
server = list.first
|
20
|
+
puts "connecting as #{user} to: #{server.tags['Name']} (#{server.public_ip_address})"
|
21
|
+
exec("ssh #{user}@#{server.public_ip_address}")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
Rig::Command::Main.subcommand 'ssh', 'ssh to server', Rig::Command::Ssh
|
data/lib/rig/config.rb
CHANGED
@@ -1,19 +1,57 @@
|
|
1
1
|
|
2
2
|
module Rig
|
3
3
|
class << self
|
4
|
+
def configdir
|
5
|
+
@configdir ||= File.expand_path(ENV["RIG_CONFIG"] || "~/.rig")
|
6
|
+
end
|
7
|
+
|
4
8
|
def config
|
5
9
|
@configuration ||= begin
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
Rig::Oconfig.new(yaml['rig'])
|
10
|
+
c = Rig::Oconfig.load_yaml_file("#{configdir}/config.yml")
|
11
|
+
if c.chef
|
12
|
+
require 'rig/chef'
|
13
|
+
end
|
14
|
+
c
|
12
15
|
end
|
13
16
|
end
|
17
|
+
|
18
|
+
def account_list
|
19
|
+
@account_list ||= begin
|
20
|
+
accountdir = "#{configdir}/accounts"
|
21
|
+
Dir["#{accountdir}/*"].inject({}) do |h, e|
|
22
|
+
f = e.gsub("#{accountdir}/", "")
|
23
|
+
f = File.basename(f, ".yml")
|
24
|
+
h[f.to_sym] = e
|
25
|
+
h
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def account
|
31
|
+
@account ||= begin
|
32
|
+
Oconfig.load_yaml_file("#{configdir}/accounts/#{get_account}.yml")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_account
|
37
|
+
return ENV['RIG_ACCOUNT'] if ENV['RIG_ACCOUNT']
|
38
|
+
return Rig.config.default_account if Rig.config.default_account
|
39
|
+
return Rig.config.accounts.first if Rig.config.accounts.count > 0
|
40
|
+
"default"
|
41
|
+
end
|
14
42
|
end
|
15
43
|
|
16
44
|
class Oconfig
|
45
|
+
class << self
|
46
|
+
def load_yaml_file(path)
|
47
|
+
file = File.expand_path(path)
|
48
|
+
raise "Configuration not found: #{path} (#{file})" unless File.exists?(file)
|
49
|
+
yaml = YAML.load_file(file)
|
50
|
+
yaml = yaml[yaml.keys.first] if yaml.keys.count == 1
|
51
|
+
Rig::Oconfig.new(yaml)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
17
55
|
def initialize(data={})
|
18
56
|
@data = {}
|
19
57
|
update!(data)
|
@@ -53,7 +91,7 @@ module Rig
|
|
53
91
|
def to_hash
|
54
92
|
out = {}
|
55
93
|
@data.each do |k, v|
|
56
|
-
out[k
|
94
|
+
out[k] = v.kind_of?(Oconfig) ? v.to_hash : v
|
57
95
|
end
|
58
96
|
out
|
59
97
|
end
|
data/lib/rig/version.rb
CHANGED
data/rig.gemspec
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../lib/rig/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Shawn Catanzarite"]
|
6
|
-
gem.email = ["
|
6
|
+
gem.email = ["scatanzarite@gmail.com"]
|
7
7
|
gem.description = %q{Cloud provisioning tool built on ruby fog}
|
8
8
|
gem.summary = %q{Cloud provisioning tool built on ruby fog}
|
9
9
|
gem.homepage = "https://github.com/shawncatz/rig"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Shawn Catanzarite
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: clamp
|
@@ -103,7 +103,7 @@ dependencies:
|
|
103
103
|
version_requirements: *id006
|
104
104
|
description: Cloud provisioning tool built on ruby fog
|
105
105
|
email:
|
106
|
-
-
|
106
|
+
- scatanzarite@gmail.com
|
107
107
|
executables:
|
108
108
|
- rig
|
109
109
|
extensions: []
|
@@ -117,6 +117,10 @@ files:
|
|
117
117
|
- README.md
|
118
118
|
- Rakefile
|
119
119
|
- bin/rig
|
120
|
+
- conf/accounts/default.yml
|
121
|
+
- conf/config.yml
|
122
|
+
- conf/templates/multi.yml
|
123
|
+
- conf/templates/solo.yml
|
120
124
|
- lib/rig.rb
|
121
125
|
- lib/rig/capistrano.rb
|
122
126
|
- lib/rig/chef.rb
|
@@ -146,7 +150,6 @@ files:
|
|
146
150
|
- lib/rig/command/instance/destroy.rb
|
147
151
|
- lib/rig/command/instance/list.rb
|
148
152
|
- lib/rig/command/instance/main.rb
|
149
|
-
- lib/rig/command/instance/ssh.rb
|
150
153
|
- lib/rig/command/instance/tag/get.rb
|
151
154
|
- lib/rig/command/instance/tag/main.rb
|
152
155
|
- lib/rig/command/instance/tag/remove.rb
|
@@ -156,6 +159,7 @@ files:
|
|
156
159
|
- lib/rig/command/keypair/main.rb
|
157
160
|
- lib/rig/command/main.rb
|
158
161
|
- lib/rig/command/options.rb
|
162
|
+
- lib/rig/command/ssh.rb
|
159
163
|
- lib/rig/config.rb
|
160
164
|
- lib/rig/version.rb
|
161
165
|
- rig.gemspec
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'rig'
|
2
|
-
|
3
|
-
module Rig
|
4
|
-
module Command
|
5
|
-
module Instance
|
6
|
-
class Ssh < Abstract
|
7
|
-
include Options::Config
|
8
|
-
|
9
|
-
parameter "NAME", "the name of the instance to connect to"
|
10
|
-
|
11
|
-
def execute
|
12
|
-
connection = Rig::Cloud.compute
|
13
|
-
|
14
|
-
filters = {}
|
15
|
-
filters["tag:Name"] = name if name
|
16
|
-
|
17
|
-
list = connection.servers.all(filters)
|
18
|
-
if list.count > 1
|
19
|
-
puts "there is more than one instance that matches:"
|
20
|
-
instance_list(list)
|
21
|
-
return
|
22
|
-
end
|
23
|
-
|
24
|
-
server = list.first
|
25
|
-
puts "ssh root@#{server.public_ip_address}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
Rig::Command::Instance::Main.subcommand 'ssh', 'Connect to instance', Rig::Command::Instance::Ssh
|