rig 0.4.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/Gemfile +1 -0
  2. data/conf/accounts/default.yml +3 -3
  3. data/conf/config.yml +33 -6
  4. data/conf/plugins/chef.rb +105 -0
  5. data/conf/plugins/mongo.rb +135 -0
  6. data/{lib/rig/command/database.rb → conf/plugins/mysql.rb} +12 -8
  7. data/conf/plugins/scout.rb +81 -0
  8. data/conf/userdata/chef/userdata.sh.erb +7 -1
  9. data/lib/rig.rb +11 -1
  10. data/lib/rig/account.rb +43 -0
  11. data/lib/rig/command.rb +92 -41
  12. data/lib/rig/command/abstract.rb +1 -2
  13. data/lib/rig/command/balancer.rb +102 -0
  14. data/lib/rig/command/dns.rb +47 -0
  15. data/lib/rig/command/environment.rb +67 -0
  16. data/lib/rig/command/keypair.rb +15 -0
  17. data/lib/rig/command/server.rb +181 -0
  18. data/lib/rig/config.rb +35 -105
  19. data/lib/rig/log.rb +66 -0
  20. data/lib/rig/model/account.rb +1 -1
  21. data/lib/rig/model/connection.rb +13 -6
  22. data/lib/rig/model/environment.rb +12 -8
  23. data/lib/rig/model/instance.rb +3 -8
  24. data/lib/rig/model/template.rb +1 -1
  25. data/lib/rig/model/userdata.rb +1 -1
  26. data/lib/rig/plugin.rb +61 -0
  27. data/lib/rig/version.rb +2 -2
  28. metadata +15 -35
  29. data/lib/rig/chef.rb +0 -59
  30. data/lib/rig/command/balancer/destroy.rb +0 -16
  31. data/lib/rig/command/balancer/list.rb +0 -30
  32. data/lib/rig/command/balancer/listener.rb +0 -31
  33. data/lib/rig/command/balancer/main.rb +0 -40
  34. data/lib/rig/command/balancer/view.rb +0 -19
  35. data/lib/rig/command/dns/create.rb +0 -19
  36. data/lib/rig/command/dns/destroy.rb +0 -16
  37. data/lib/rig/command/dns/edit.rb +0 -20
  38. data/lib/rig/command/dns/list.rb +0 -21
  39. data/lib/rig/command/dns/main.rb +0 -13
  40. data/lib/rig/command/environment/create.rb +0 -21
  41. data/lib/rig/command/environment/destroy.rb +0 -18
  42. data/lib/rig/command/environment/list.rb +0 -31
  43. data/lib/rig/command/environment/main.rb +0 -15
  44. data/lib/rig/command/environment/protect.rb +0 -22
  45. data/lib/rig/command/instance/create.rb +0 -60
  46. data/lib/rig/command/instance/destroy.rb +0 -19
  47. data/lib/rig/command/instance/list.rb +0 -26
  48. data/lib/rig/command/instance/main.rb +0 -16
  49. data/lib/rig/command/instance/tag/get.rb +0 -20
  50. data/lib/rig/command/instance/tag/main.rb +0 -14
  51. data/lib/rig/command/instance/tag/remove.rb +0 -44
  52. data/lib/rig/command/instance/tag/set.rb +0 -46
  53. data/lib/rig/command/instance/view.rb +0 -20
  54. data/lib/rig/command/keypair/list.rb +0 -14
  55. data/lib/rig/command/keypair/main.rb +0 -11
  56. data/lib/rig/command/main.rb +0 -90
  57. data/lib/rig/model/database.rb +0 -23
  58. data/lib/rig/model/database/base.rb +0 -11
  59. data/lib/rig/model/database/mongodb.rb +0 -70
  60. data/lib/rig/model/database/mysql.rb +0 -12
@@ -1,19 +0,0 @@
1
- require 'rig'
2
-
3
- module Rig
4
- module Command
5
- module Instance
6
- class Destroy < Abstract
7
-
8
- parameter "NAME", "the name of the instance to connect to"
9
-
10
- def execute
11
- list = Rig::Model::Instance.find(name)
12
- Rig::Model::Instance.destroy(list)
13
- end
14
- end
15
- end
16
- end
17
- end
18
-
19
- Rig::Command::Instance::Main.subcommand 'destroy', 'destroy (terminate) instance', Rig::Command::Instance::Destroy
@@ -1,26 +0,0 @@
1
- require 'rig'
2
-
3
- module Rig
4
- module Command
5
- module Instance
6
- class List < Abstract
7
- include Options::ShowAll
8
-
9
- option %w{-l --long}, :flag, "show more information in table"
10
- parameter "[ENV]", "environment"
11
-
12
- def execute
13
- connection = Rig::Connection.compute
14
- filters = {}
15
- filters["instance-state-name"] = "running" unless showall?
16
- filters["tag:Environment"] = env if env
17
-
18
- list = connection.servers.all(filters)
19
- instance_list(list, long?)
20
- end
21
- end
22
- end
23
- end
24
- end
25
-
26
- Rig::Command::Instance::Main.subcommand 'list', 'List instances', Rig::Command::Instance::List
@@ -1,16 +0,0 @@
1
- module Rig
2
- module Command
3
- module Instance
4
- class Main < Abstract
5
- #subcommand 'list', 'List instances', InstanceList
6
- #subcommand 'create', 'Create an instance', InstanceCreate
7
- #subcommand 'ssh', 'Connect to instance', InstanceSsh
8
- #subcommand 'tag', 'Manage tags on instance', InstanceTag
9
- self.default_subcommand = "list"
10
- end
11
- end
12
- end
13
- end
14
-
15
- Rig::Command::Main.subcommand 'instance', 'Commands related to instances', Rig::Command::Instance::Main
16
-
@@ -1,20 +0,0 @@
1
- module Rig
2
- module Command
3
- module Instance
4
- module Tag
5
- class Get < Abstract
6
-
7
- parameter "NAME", "the name of the instance to get tags for"
8
-
9
- def execute
10
- instance = Rig::Model::Instance.find(name)
11
- raise "instance not found #{name}" unless instance
12
- puts "#{instance.tags.inspect}"
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end
19
-
20
- Rig::Command::Instance::Tag::Main.subcommand 'get', 'get tag(s) for this instance', Rig::Command::Instance::Tag::Get
@@ -1,14 +0,0 @@
1
- require 'rig'
2
-
3
- module Rig
4
- module Command
5
- module Instance
6
- module Tag
7
- class Main < Abstract
8
- end
9
- end
10
- end
11
- end
12
- end
13
-
14
- Rig::Command::Instance::Main.subcommand 'tag', 'Manage tags on instance', Rig::Command::Instance::Tag::Main
@@ -1,44 +0,0 @@
1
-
2
- module Rig
3
- module Command
4
- module Instance
5
- module Tag
6
- class Remove < Abstract
7
- include Options::Instance
8
- include Options::InstanceName
9
-
10
- parameter "TAG", "tag key to remove", :attribute_name => :raw_tag
11
-
12
- # TODO: fix this to use Model instead
13
- def execute
14
- unless iname || iid
15
- raise "Must set either instance name or instance id (-iname or -iid)"
16
- end
17
-
18
- connection = Rig::Connection.compute
19
- if iid
20
- instance = connection.servers.get(iid)
21
- else
22
- list = connection.servers.all({"tag:Name" => iname})
23
- if list.count > 1
24
- puts "there is more than one instance that matches:"
25
- instance_list(list)
26
- return
27
- end
28
- instance = list.first
29
- end
30
-
31
- unless instance
32
- puts "could not find instance"
33
- return
34
- end
35
-
36
- ap connection.delete_tags(instance.id, raw_tag => instance.tags[raw_tag])
37
- end
38
- end
39
- end
40
- end
41
- end
42
- end
43
-
44
- Rig::Command::Instance::Tag::Main.subcommand 'rm', 'remove tag(s) for this instance', Rig::Command::Instance::Tag::Remove
@@ -1,46 +0,0 @@
1
- module Rig
2
- module Command
3
- module Instance
4
- module Tag
5
- class Set < Abstract
6
- include Options::Instance
7
- include Options::InstanceName
8
-
9
- parameter "TAGS ...", "tags of the form key:value", :attribute_name => :raw_tags
10
-
11
- def execute
12
- unless iname || iid
13
- raise "Must set either instance name or instance id (-iname or -iid)"
14
- end
15
-
16
- connection = Rig::Connection.compute
17
- if iid
18
- instance = connection.servers.get(iid)
19
- else
20
- list = connection.servers.all({"tag:Name" => iname})
21
- if list.count > 1
22
- puts "there is more than one instance that matches:"
23
- instance_list(list)
24
- return
25
- end
26
- instance = list.first
27
- end
28
-
29
- unless instance
30
- puts "could not find instance"
31
- return
32
- end
33
-
34
- raw_tags.each do |s|
35
- (k,v) = s.split(':',2)
36
- #tags[k] = v if k && v
37
- connection.create_tags(instance.id, k => v)
38
- end
39
- end
40
- end
41
- end
42
- end
43
- end
44
- end
45
-
46
- Rig::Command::Instance::Tag::Main.subcommand 'set', 'set tag(s) for this instance', Rig::Command::Instance::Tag::Set
@@ -1,20 +0,0 @@
1
- module Rig
2
- module Command
3
- module Instance
4
- class View < Abstract
5
- include Options::ShowAll
6
-
7
- # TODO: something wrong here, view is showing all instances
8
- parameter "NAME", "name of instance"
9
-
10
- def execute
11
- list = Rig::Model::Instance.find(name)
12
- list.each do |item|
13
- ap item.attributes
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
20
- Rig::Command::Instance::Main.subcommand 'view', 'view instances', Rig::Command::Instance::View
@@ -1,14 +0,0 @@
1
- module Rig
2
- module Command
3
- module Keypair
4
- class List < Abstract
5
- def execute
6
- connection = Rig::Connection.compute
7
- list = connection.key_pairs.all
8
- puts list.inspect
9
- end
10
- end
11
- end
12
- end
13
- end
14
- Rig::Command::Keypair::Main.subcommand 'list', 'list keypairs', Rig::Command::Keypair::List
@@ -1,11 +0,0 @@
1
-
2
- module Rig
3
- module Command
4
- module Keypair
5
- class Main < Abstract
6
- self.default_subcommand = "list"
7
- end
8
- end
9
- end
10
- end
11
- Rig::Command::Main.subcommand 'keypair', 'Commands related to keypairs', Rig::Command::Keypair::Main
@@ -1,90 +0,0 @@
1
- require 'awesome_print'
2
-
3
- module Rig
4
- module Command
5
- class Main < Abstract
6
-
7
- subcommand "chef", "test chef configuration" do
8
- def execute
9
- raise "chef not configured" unless Rig.config[:chef]
10
-
11
- list = Rig::Chef.client_list
12
- rows = []
13
- list.each do |c|
14
- rows << c
15
- end
16
- print_table(%w{Name Location}, rows)
17
- end
18
- end
19
-
20
- def merge_file(src, dest)
21
- old = YAML.load_file(dest)
22
- FileUtils.mv(dest, "#{dest}.bak.#{Time.now.to_i}")
23
- new = YAML.load_file(src)
24
- new.merge!(old)
25
- File.open(dest, "w") {|f| f.write(new.to_yaml)}
26
- end
27
-
28
- subcommand "userdata", "test userdata" do
29
- parameter "NAME", "name of server"
30
- parameter "ROLE", "role of server"
31
- parameter "ENVIRONMENT", "environment of server"
32
-
33
- def execute
34
- userdata = Rig::Model::Userdata.create(name, role, environment)
35
- puts "USERDATA:\n#{userdata}"
36
- end
37
- end
38
-
39
- subcommand "init", "initialize configuration directory" do
40
- option %w{-f --force}, :flag, "force creation of files", :default => false
41
- option %w{-d --directory}, "DIRECTORY", "configuration directory", :default => "~/.rig"
42
-
43
- def execute
44
- dir = File.expand_path(ENV['RIG_CONFIG'] ? ENV['RIG_CONFIG'] : directory)
45
- back = "#{dir}.bak.#{Time.now.to_i}"
46
- conf = File.expand_path("../../../../conf", __FILE__)
47
-
48
- files = %w{
49
- config.yml
50
- accounts/default.yml
51
- templates/solo.yml
52
- templates/multi.yml
53
- userdata/default/userdata.sh.erb
54
- userdata/default/userdata.yml
55
- userdata/chef/userdata.sh.erb
56
- userdata/chef/userdata.yml
57
- userdata/chef/validation.pem
58
- }
59
-
60
- unless dir
61
- puts "directory could not be found: tried environment variables RIG_CONFIG (#{ENV['RIG_CONFIG']}) and HOME (#{ENV['HOME']}"
62
- exit(1)
63
- end
64
-
65
- if File.exists?(dir)
66
- unless File.directory?(dir)
67
- puts "moving old config #{dir} to #{back}"
68
- FileUtils.mv(dir, new)
69
- end
70
- end
71
-
72
- puts "[create] #{dir}/"
73
- FileUtils.mkdir_p(dir)
74
-
75
- files.each do |file|
76
- src = "#{conf}/#{file}"
77
- dest = "#{dir}/#{file}"
78
- FileUtils.mkdir_p(File.dirname(dest))
79
- if File.exists?(dest) && !force?
80
- puts "[skip] #{dest}"
81
- else
82
- puts "[create] #{dest}"
83
- FileUtils.copy(src, dest)
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end
90
- end
@@ -1,23 +0,0 @@
1
- require 'rig/model/database/base'
2
- require 'rig/model/database/mongodb'
3
- require 'rig/model/database/mysql'
4
-
5
- module Rig
6
- module Model
7
- module Database
8
- class << self
9
- def new(opts)
10
- provider = opts.delete(:provider)
11
- case provider.downcase
12
- when 'mongodb'
13
- Rig::Model::Database::MongoDB.new(opts)
14
- when 'mysql'
15
- Rig::Model::Database::MySQL.new(opts)
16
- else
17
- raise "unknown database #{provider.inspect}"
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,11 +0,0 @@
1
-
2
-
3
- module Rig
4
- module Model
5
- module Database
6
- class Base
7
-
8
- end
9
- end
10
- end
11
- end
@@ -1,70 +0,0 @@
1
- require 'rubygems'
2
- require 'mongo'
3
- require 'bson'
4
-
5
- module Rig
6
- module Model
7
- module Database
8
- class MongoDB
9
-
10
- def initialize(opts)
11
- @options = {
12
- :host => "localhost",
13
- :port => 27017,
14
- :user => nil,
15
- :pass => nil,
16
- :admin_user => nil,
17
- :admin_pass => nil
18
- }.merge(opts)
19
- connect
20
- end
21
-
22
- # accessors
23
- def user; @options[:user]; end
24
- def host; @options[:host]; end
25
- def port; @options[:port]; end
26
- def pass; @options[:pass]; end
27
- def password; @options[:pass]; end
28
- def admin_user; @options[:admin_user]; end
29
- def admin_pass; @options[:admin_pass]; end
30
- def admin_password; @options[:admin_pass]; end
31
-
32
- def connect
33
- @cxn ||= begin
34
- Mongo::Connection.new(@options[:host], @options[:port])
35
- end
36
- end
37
-
38
- def auth_admin
39
- db = @cxn.db("admin")
40
- db.authenticate(@options[:admin_user], @options[:admin_pass])
41
- end
42
-
43
- def all
44
- begin
45
- connect.database_info
46
- rescue Mongo::OperationFailure => e
47
- raise unless e.message =~ /need to login/
48
- raise unless auth_admin
49
- connect.database_info
50
- rescue => e
51
- puts "exception: <#{e.class}> #{e.message} at #{e.backtrace.first}"
52
- end
53
- end
54
-
55
- def create_database(name, user, pass)
56
- db = connect.db("admin")
57
- raise "failed to authenticate" unless db.authenticate(@options[:admin_user], @options[:admin_pass])
58
- newdb = connect.db(name)
59
- newdb.add_user(user, pass)
60
- end
61
-
62
- def destroy_database(name)
63
- db = connect.db("admin")
64
- raise "failed to authenticate" unless db.authenticate(@options[:admin_user], @options[:admin_pass])
65
- connect.drop_database(name)
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,12 +0,0 @@
1
-
2
-
3
-
4
- module Rig
5
- module Model
6
- module Database
7
- class MySQL < Base
8
-
9
- end
10
- end
11
- end
12
- end