rig 0.4.5 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/conf/accounts/default.yml +3 -3
- data/conf/config.yml +33 -6
- data/conf/plugins/chef.rb +105 -0
- data/conf/plugins/mongo.rb +135 -0
- data/{lib/rig/command/database.rb → conf/plugins/mysql.rb} +12 -8
- data/conf/plugins/scout.rb +81 -0
- data/conf/userdata/chef/userdata.sh.erb +7 -1
- data/lib/rig.rb +11 -1
- data/lib/rig/account.rb +43 -0
- data/lib/rig/command.rb +92 -41
- data/lib/rig/command/abstract.rb +1 -2
- data/lib/rig/command/balancer.rb +102 -0
- data/lib/rig/command/dns.rb +47 -0
- data/lib/rig/command/environment.rb +67 -0
- data/lib/rig/command/keypair.rb +15 -0
- data/lib/rig/command/server.rb +181 -0
- data/lib/rig/config.rb +35 -105
- data/lib/rig/log.rb +66 -0
- data/lib/rig/model/account.rb +1 -1
- data/lib/rig/model/connection.rb +13 -6
- data/lib/rig/model/environment.rb +12 -8
- data/lib/rig/model/instance.rb +3 -8
- data/lib/rig/model/template.rb +1 -1
- data/lib/rig/model/userdata.rb +1 -1
- data/lib/rig/plugin.rb +61 -0
- data/lib/rig/version.rb +2 -2
- metadata +15 -35
- data/lib/rig/chef.rb +0 -59
- data/lib/rig/command/balancer/destroy.rb +0 -16
- data/lib/rig/command/balancer/list.rb +0 -30
- data/lib/rig/command/balancer/listener.rb +0 -31
- data/lib/rig/command/balancer/main.rb +0 -40
- data/lib/rig/command/balancer/view.rb +0 -19
- data/lib/rig/command/dns/create.rb +0 -19
- data/lib/rig/command/dns/destroy.rb +0 -16
- data/lib/rig/command/dns/edit.rb +0 -20
- data/lib/rig/command/dns/list.rb +0 -21
- data/lib/rig/command/dns/main.rb +0 -13
- data/lib/rig/command/environment/create.rb +0 -21
- data/lib/rig/command/environment/destroy.rb +0 -18
- data/lib/rig/command/environment/list.rb +0 -31
- data/lib/rig/command/environment/main.rb +0 -15
- data/lib/rig/command/environment/protect.rb +0 -22
- data/lib/rig/command/instance/create.rb +0 -60
- data/lib/rig/command/instance/destroy.rb +0 -19
- data/lib/rig/command/instance/list.rb +0 -26
- data/lib/rig/command/instance/main.rb +0 -16
- data/lib/rig/command/instance/tag/get.rb +0 -20
- data/lib/rig/command/instance/tag/main.rb +0 -14
- data/lib/rig/command/instance/tag/remove.rb +0 -44
- data/lib/rig/command/instance/tag/set.rb +0 -46
- data/lib/rig/command/instance/view.rb +0 -20
- data/lib/rig/command/keypair/list.rb +0 -14
- data/lib/rig/command/keypair/main.rb +0 -11
- data/lib/rig/command/main.rb +0 -90
- data/lib/rig/model/database.rb +0 -23
- data/lib/rig/model/database/base.rb +0 -11
- data/lib/rig/model/database/mongodb.rb +0 -70
- data/lib/rig/model/database/mysql.rb +0 -12
data/Gemfile
CHANGED
data/conf/accounts/default.yml
CHANGED
@@ -10,12 +10,12 @@
|
|
10
10
|
# the same DNS provider for all of your accounts.
|
11
11
|
:dns_zone: blah.com
|
12
12
|
|
13
|
-
# this is the
|
13
|
+
# this is the keypair that you use to SSH to the servers
|
14
14
|
:keypair: keyname
|
15
15
|
|
16
16
|
# security groups to use when creating instances
|
17
17
|
# groups configuration precedence:
|
18
|
-
# template instances -> template -> account
|
18
|
+
# template instances -> template -> account
|
19
19
|
# :groups:
|
20
20
|
# - default
|
21
21
|
|
@@ -28,7 +28,7 @@
|
|
28
28
|
# ~/.rig/userdata/default
|
29
29
|
#
|
30
30
|
# The following are provided:
|
31
|
-
# "default" is a vanilla install
|
31
|
+
# "default" is a vanilla install (intended for Ubuntu on AWS)
|
32
32
|
# "chef" is designed to bootstrap a chef implementation
|
33
33
|
#
|
34
34
|
# See the corresponding userdata.yml for more information
|
data/conf/config.yml
CHANGED
@@ -13,13 +13,40 @@
|
|
13
13
|
# AWS defaults to the user "ubuntu"
|
14
14
|
:user: ubuntu
|
15
15
|
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
#
|
16
|
+
# logging system, by default level is set to WARN
|
17
|
+
# the default log file is RIG_CONFIG/rig.log
|
18
|
+
:logging:
|
19
|
+
# define a logger, the key is the name of the logger
|
20
|
+
# you can define as many as you would like.
|
21
|
+
:console:
|
22
|
+
# opts correspond to the options passed to Logger.new
|
23
|
+
# this will convert STDOUT and STDERR to the corresponding constant
|
24
|
+
:opts: STDOUT
|
25
|
+
# supported log levels are:
|
26
|
+
# debug, info, warn, error, fatal
|
27
|
+
:level: warn
|
28
|
+
:log:
|
29
|
+
# relative file names are relative to the Rig configuration directory
|
30
|
+
# rig.log below corresponds to RIG_CONFIG/rig.log (~/.rig/rig.log)
|
31
|
+
:opts: [ rig.log, daily ]
|
32
|
+
:level: debug
|
21
33
|
|
22
|
-
#
|
34
|
+
# event-based plugins framework
|
35
|
+
#
|
36
|
+
#:plugins:
|
37
|
+
# :chef:
|
38
|
+
# # if you're using chef, set this to the location of the knife.rb
|
39
|
+
# # configuration file.
|
40
|
+
# :knife: /Users/Shawn/work/chef/.chef/knife.rb
|
41
|
+
#
|
42
|
+
# :puppet:
|
43
|
+
# #TODO: Figure out the same thing for puppet
|
44
|
+
#
|
45
|
+
# :scout:
|
46
|
+
# # if you're using Scout, set the API account details here.
|
47
|
+
# :account: youraccount
|
48
|
+
# :email: your@awesome.com
|
49
|
+
# :secret: sekret
|
23
50
|
|
24
51
|
#
|
25
52
|
# DO NOT PUT ACCOUNT RELATED INFORMATION
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'chef'
|
4
|
+
require 'chef/config'
|
5
|
+
require 'chef/api_client'
|
6
|
+
require 'chef/node'
|
7
|
+
require 'chef/environment'
|
8
|
+
|
9
|
+
module Rig
|
10
|
+
module Plugin
|
11
|
+
module Chef
|
12
|
+
include Rig::Plugin::Base
|
13
|
+
|
14
|
+
on "environment:create" do |args|
|
15
|
+
environment = args.shift
|
16
|
+
name = environment.name
|
17
|
+
self.environment_create(name)
|
18
|
+
end
|
19
|
+
|
20
|
+
on "environment:destroy" do |args|
|
21
|
+
environment = args.shift
|
22
|
+
name = environment.name
|
23
|
+
self.environment_destroy(name)
|
24
|
+
end
|
25
|
+
|
26
|
+
on "instance:create" do |args|
|
27
|
+
# do nothing
|
28
|
+
# the instance will add itself through the chef-client call in userdata package
|
29
|
+
end
|
30
|
+
|
31
|
+
on "instance:destroy" do |args|
|
32
|
+
instance = args.shift
|
33
|
+
tags = args.shift
|
34
|
+
name = tags['Name']
|
35
|
+
self.client_delete(name)
|
36
|
+
self.node_delete(name)
|
37
|
+
end
|
38
|
+
|
39
|
+
command "chef", "test chef configuration" do
|
40
|
+
def execute
|
41
|
+
list = Rig::Plugin::Chef.client_list
|
42
|
+
rows = []
|
43
|
+
list.each do |c|
|
44
|
+
rows << c
|
45
|
+
end
|
46
|
+
print_table(%w{Name Location}, rows)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class << self
|
51
|
+
def configure
|
52
|
+
@config ||= config_for self
|
53
|
+
@chef ||= ::Chef::Config.from_file(File.expand_path(@config[:knife]))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test
|
57
|
+
self.client_list
|
58
|
+
end
|
59
|
+
|
60
|
+
def environment_create(name)
|
61
|
+
configure
|
62
|
+
env = ::Chef::Environment.new
|
63
|
+
env.name(name)
|
64
|
+
env.description("created by Rig")
|
65
|
+
env.save
|
66
|
+
true
|
67
|
+
rescue => e
|
68
|
+
puts "*** chef exception: #{e.message}"
|
69
|
+
false
|
70
|
+
end
|
71
|
+
|
72
|
+
def environment_destroy(name)
|
73
|
+
configure
|
74
|
+
env = ::Chef::Environment.load(name) rescue nil
|
75
|
+
env.destroy if env
|
76
|
+
true
|
77
|
+
rescue => e
|
78
|
+
puts "*** chef exception: #{e.message}"
|
79
|
+
false
|
80
|
+
end
|
81
|
+
|
82
|
+
def client_delete(name)
|
83
|
+
configure
|
84
|
+
# TODO: better error handling
|
85
|
+
client = ::Chef::ApiClient.load(name) rescue nil
|
86
|
+
client.destroy if client
|
87
|
+
end
|
88
|
+
|
89
|
+
def client_list
|
90
|
+
configure
|
91
|
+
# TODO: better error handling
|
92
|
+
::Chef::ApiClient.list
|
93
|
+
end
|
94
|
+
|
95
|
+
def node_delete(name)
|
96
|
+
configure
|
97
|
+
# TODO: better error handling
|
98
|
+
node = ::Chef::Node.load(name) rescue nil
|
99
|
+
node.destroy if node
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'mongo'
|
2
|
+
|
3
|
+
module Rig
|
4
|
+
module Plugin
|
5
|
+
module Mongo
|
6
|
+
include Rig::Plugin::Base
|
7
|
+
|
8
|
+
#on "commands:loaded" do |args|
|
9
|
+
# command = args.shift
|
10
|
+
# command.subcommand "mongo", "manage mongodb databases", Rig::Command::Mongo::Main
|
11
|
+
#end
|
12
|
+
|
13
|
+
command "mongo", "manage mongodb databases" do
|
14
|
+
subcommand "list", "list all databases" do
|
15
|
+
def execute
|
16
|
+
list = Rig::Plugin::Mongo.all.sort
|
17
|
+
print_table(%w{Database Size}, list)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
subcommand "create", "create a database" do
|
21
|
+
parameter "NAME", "name of the database"
|
22
|
+
parameter "[USER]", "user to add to database"
|
23
|
+
parameter "[PASS]", "password of user to add to database"
|
24
|
+
|
25
|
+
def execute
|
26
|
+
db = Rig::Connection.database
|
27
|
+
db.create_database(name, user, pass) unless test?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
subcommand "destroy", "destroy a database" do
|
31
|
+
parameter "NAME", "name of the database"
|
32
|
+
|
33
|
+
def execute
|
34
|
+
db = Rig::Connection.database
|
35
|
+
db.destroy_database(name) unless test?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
self.default_subcommand = "list"
|
39
|
+
end
|
40
|
+
|
41
|
+
class << self
|
42
|
+
#def initialize(opts)
|
43
|
+
# @options = {
|
44
|
+
# :host => "localhost",
|
45
|
+
# :port => 27017,
|
46
|
+
# :user => nil,
|
47
|
+
# :pass => nil,
|
48
|
+
# :admin_user => nil,
|
49
|
+
# :admin_pass => nil
|
50
|
+
# }.merge(opts)
|
51
|
+
# connect
|
52
|
+
#end
|
53
|
+
|
54
|
+
## accessors
|
55
|
+
#def user; @options[:user]; end
|
56
|
+
#def host; @options[:host]; end
|
57
|
+
#def port; @options[:port]; end
|
58
|
+
#def pass; @options[:pass]; end
|
59
|
+
#def password; @options[:pass]; end
|
60
|
+
#def admin_user; @options[:admin_user]; end
|
61
|
+
#def admin_pass; @options[:admin_pass]; end
|
62
|
+
#def admin_password; @options[:admin_pass]; end
|
63
|
+
|
64
|
+
def connect
|
65
|
+
@options ||= config_for self
|
66
|
+
@cxn ||= begin
|
67
|
+
::Mongo::Connection.new(@options[:host], @options[:port])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def auth_admin
|
72
|
+
db = @cxn.db("admin")
|
73
|
+
db.authenticate(@options[:admin_user], @options[:admin_pass])
|
74
|
+
end
|
75
|
+
|
76
|
+
def all
|
77
|
+
begin
|
78
|
+
connect.database_info
|
79
|
+
rescue ::Mongo::OperationFailure => e
|
80
|
+
raise unless e.message =~ /need to login/
|
81
|
+
raise unless auth_admin
|
82
|
+
connect.database_info
|
83
|
+
rescue => e
|
84
|
+
puts "exception: <#{e.class}> #{e.message} at #{e.backtrace.first}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def create_database(name, user, pass)
|
89
|
+
db = connect.db("admin")
|
90
|
+
raise "failed to authenticate" unless db.authenticate(@options[:admin_user], @options[:admin_pass])
|
91
|
+
newdb = connect.db(name)
|
92
|
+
newdb.add_user(user, pass)
|
93
|
+
end
|
94
|
+
|
95
|
+
def destroy_database(name)
|
96
|
+
db = connect.db("admin")
|
97
|
+
raise "failed to authenticate" unless db.authenticate(@options[:admin_user], @options[:admin_pass])
|
98
|
+
connect.drop_database(name)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
module Command
|
105
|
+
module Mongo
|
106
|
+
class Main < Clamp::Command
|
107
|
+
subcommand "list", "list all databases" do
|
108
|
+
def execute
|
109
|
+
list = Rig::Plugin::Mongo.all.sort
|
110
|
+
print_table(%w{Database Size}, list)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
subcommand "create", "create a database" do
|
114
|
+
parameter "NAME", "name of the database"
|
115
|
+
parameter "[USER]", "user to add to database"
|
116
|
+
parameter "[PASS]", "password of user to add to database"
|
117
|
+
|
118
|
+
def execute
|
119
|
+
db = Rig::Connection.database
|
120
|
+
db.create_database(name, user, pass) unless test?
|
121
|
+
end
|
122
|
+
end
|
123
|
+
subcommand "destroy", "destroy a database" do
|
124
|
+
parameter "NAME", "name of the database"
|
125
|
+
|
126
|
+
def execute
|
127
|
+
db = Rig::Connection.database
|
128
|
+
db.destroy_database(name) unless test?
|
129
|
+
end
|
130
|
+
end
|
131
|
+
self.default_subcommand = "list"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -1,9 +1,12 @@
|
|
1
|
-
require 'mongo'
|
2
|
-
require 'awesome_print'
|
3
|
-
|
4
1
|
module Rig
|
2
|
+
module Plugin
|
3
|
+
class Mysql < Base
|
4
|
+
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
5
8
|
module Command
|
6
|
-
module
|
9
|
+
module Mysql
|
7
10
|
class List < Abstract
|
8
11
|
def execute
|
9
12
|
db = Rig::Connection.database
|
@@ -15,8 +18,9 @@ module Rig
|
|
15
18
|
|
16
19
|
class Create < Abstract
|
17
20
|
parameter "NAME", "name of the database"
|
18
|
-
parameter "[USER]", "user to add to database"
|
19
|
-
parameter "[PASS]", "password of user to add to database"
|
21
|
+
parameter "[USER]", "user to add to database"
|
22
|
+
parameter "[PASS]", "password of user to add to database"
|
23
|
+
|
20
24
|
def execute
|
21
25
|
db = Rig::Connection.database
|
22
26
|
db.create_database(name, user, pass) unless test?
|
@@ -25,6 +29,7 @@ module Rig
|
|
25
29
|
|
26
30
|
class Destroy < Abstract
|
27
31
|
parameter "NAME", "name of the database"
|
32
|
+
|
28
33
|
def execute
|
29
34
|
db = Rig::Connection.database
|
30
35
|
db.destroy_database(name) unless test?
|
@@ -39,5 +44,4 @@ module Rig
|
|
39
44
|
end
|
40
45
|
end
|
41
46
|
end
|
42
|
-
end
|
43
|
-
Rig::Command::Main.subcommand "database", "manage mongodb or mysql databases", Rig::Command::Database::Main
|
47
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'scout_api'
|
3
|
+
|
4
|
+
module Rig
|
5
|
+
module Plugin
|
6
|
+
module Scout
|
7
|
+
include Rig::Plugin::Base
|
8
|
+
|
9
|
+
#on "environment:create" do |_|
|
10
|
+
#end
|
11
|
+
|
12
|
+
#on "environment:destroy" do |_|
|
13
|
+
#end
|
14
|
+
|
15
|
+
#on "instance:create" do |args|
|
16
|
+
#end
|
17
|
+
|
18
|
+
on "instance:destroy" do |args|
|
19
|
+
instance = args.shift
|
20
|
+
tags = args.shift
|
21
|
+
name = tags["Name"]
|
22
|
+
unless name.nil? || name.empty?
|
23
|
+
self.instance_destroy(name)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
#on "commands:loaded" do |args|
|
28
|
+
# command = args.shift
|
29
|
+
# command.subcommand "scout", "test scout configuration", Rig::Command::Scout
|
30
|
+
#end
|
31
|
+
|
32
|
+
command "scout", "test scout configuration" do
|
33
|
+
def execute
|
34
|
+
list = Rig::Plugin::Scout.test
|
35
|
+
rows = []
|
36
|
+
list.each do |c|
|
37
|
+
rows << [c[:hostname], c[:checkup_status], c[:last_checkin]]
|
38
|
+
end
|
39
|
+
print_table(%w{Hostname Status LastCheckIn}, rows)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class << self
|
44
|
+
def configure
|
45
|
+
@config ||= config_for self
|
46
|
+
@scout ||= ::Scout::Account.new(@config[:account], @config[:email], @config[:secret])
|
47
|
+
end
|
48
|
+
|
49
|
+
def test
|
50
|
+
configure
|
51
|
+
::Scout::Server.all
|
52
|
+
end
|
53
|
+
|
54
|
+
def instance_destroy(name)
|
55
|
+
configure
|
56
|
+
server = ::Scout::Server.first(:name => name)
|
57
|
+
::Scout::Server.delete(server.id) if server
|
58
|
+
end
|
59
|
+
|
60
|
+
def environment_destroy(name)
|
61
|
+
configure
|
62
|
+
all = ::Scout::Server.all
|
63
|
+
list = all.select { |e| e.name =~ /\.#{name}\./ }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
#module Command
|
70
|
+
# class Scout < Clamp::Command
|
71
|
+
# def execute
|
72
|
+
# list = Rig::Plugin::Scout.test
|
73
|
+
# rows = []
|
74
|
+
# list.each do |c|
|
75
|
+
# rows << [c[:hostname], c[:checkup_status], c[:last_checkin]]
|
76
|
+
# end
|
77
|
+
# table(%w{Hostname Status LastCheckIn}, rows)
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
#end
|
81
|
+
end
|
@@ -60,4 +60,10 @@ cat << <%= local.upcase %> > <%= remote %>
|
|
60
60
|
<%= local.upcase %>
|
61
61
|
<% end %>
|
62
62
|
|
63
|
-
|
63
|
+
cat << BOOTCHEF > /root/boot-chef
|
64
|
+
#!/bin/bash
|
65
|
+
chef-client -N <%= @name %> <%= @environment ? "-E #@environment" : "" %> --once -j /etc/chef/bootstrap.json
|
66
|
+
BOOTCHEF
|
67
|
+
chmod 755 /root/boot-chef
|
68
|
+
|
69
|
+
/root/boot-chef
|