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,59 +0,0 @@
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 Chef
11
- class << self
12
- def configure
13
- @chef ||= ::Chef::Config.from_file(File.expand_path(Rig.config[:chef][:knife]))
14
- end
15
-
16
- def environment_create(name)
17
- configure
18
- env = ::Chef::Environment.new
19
- env.name(name)
20
- env.description("created by Rig")
21
- env.save
22
- true
23
- rescue => e
24
- puts "*** chef exception: #{e.message}"
25
- false
26
- end
27
-
28
- def environment_destroy(name)
29
- configure
30
- env = ::Chef::Environment.load(name) rescue nil
31
- env.destroy if env
32
- true
33
- rescue => e
34
- puts "*** chef exception: #{e.message}"
35
- false
36
- end
37
-
38
- def client_delete(name)
39
- configure
40
- # TODO: better error handling
41
- client = ::Chef::ApiClient.load(name) rescue nil
42
- client.destroy if client
43
- end
44
-
45
- def client_list
46
- configure
47
- # TODO: better error handling
48
- ::Chef::ApiClient.list
49
- end
50
-
51
- def node_delete(name)
52
- configure
53
- # TODO: better error handling
54
- node = ::Chef::Node.load(name) rescue nil
55
- node.destroy if node
56
- end
57
- end
58
- end
59
- end
@@ -1,16 +0,0 @@
1
- require 'rig'
2
-
3
- module Rig
4
- module Command
5
- module Balancer
6
- class Destroy < Abstract
7
- parameter "NAME", "name of load balancer"
8
- def execute
9
- Rig::Model::Balancer.destroy(name)
10
- end
11
- end
12
- end
13
- end
14
- end
15
-
16
- Rig::Command::Balancer::Main.subcommand 'destroy', 'destroy load balancer', Rig::Command::Balancer::Destroy
@@ -1,30 +0,0 @@
1
- require 'rig'
2
-
3
- module Rig
4
- module Command
5
- module Balancer
6
- class List < Abstract
7
- def execute
8
- list = Rig::Model::Balancer.all
9
- list.each do |lb|
10
- puts lb.id
11
- puts "- listeners"
12
- lb.listeners.each do |l|
13
- puts " - #{l.protocol}:#{l.lb_port} => #{l.instance_protocol}:#{l.instance_port}"
14
- end
15
- puts "- instances"
16
- lb.instances.each do |inst|
17
- puts " - #{inst}"
18
- end
19
- puts "- zones"
20
- lb.availability_zones.each do |z|
21
- puts " - #{z}"
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
28
- end
29
-
30
- Rig::Command::Balancer::Main.subcommand 'list', 'list load balancers', Rig::Command::Balancer::List
@@ -1,31 +0,0 @@
1
- module Rig
2
- module Command
3
- module Listener
4
- class Main < Abstract
5
- subcommand "add", "add a listener to a balancer" do
6
- parameter "BALANCER", "balancer name"
7
- parameter "LISTENER", "listener data PROTO:PORT/PROTO:PORT"
8
- parameter "[CERT]", "arn for server certificate"
9
- parameter "[POLICY] ...", "policy names"
10
-
11
- def execute
12
- (from, to) = listener.split('/')
13
- #newlist = elb.listeners.create()
14
- Rig::Model::Balancer.add_listener(balancer, from, to, cert, policy_list)
15
- end
16
- end
17
-
18
- subcommand "rm", "remove a listener from a balancer" do
19
- parameter "BALANCER", "balancer name"
20
- parameter "LISTENER", "listener data PROTO:PORT (just the elb side)"
21
-
22
- def execute
23
- Rig::Model::Balancer.destroy_listener(balancer, listener)
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
-
31
- Rig::Command::Balancer::Main.subcommand "listener", "manage balancer listeners (protocols and ports", Rig::Command::Listener::Main
@@ -1,40 +0,0 @@
1
- require 'rig'
2
- require 'rest-client'
3
-
4
- module Rig
5
- module Command
6
- module Balancer
7
- class Main < Abstract
8
- self.default_subcommand = 'list'
9
- subcommand 'test', 'test a load balancer' do
10
- option %w{-c --count}, "COUNT", "number of times to loop", :default => 100
11
- option %w{-p --poll}, "POLL", "poll time", :default => 10
12
- parameter "NAME", "name of the load balancer to test"
13
-
14
- def execute
15
- elb = Rig::Model::Balancer.find(name)
16
- raise "elb #{name} not found" unless elb
17
-
18
- dns = elb.dns_name
19
- count.times do |i|
20
- puts "### loop #{i}"
21
- ips = `host #{dns}`.split(/\n/).collect { |e| e.split.last }
22
- ips.each do |ip|
23
- val = begin
24
- RestClient.get("http://#{ip}")
25
- rescue => e
26
- e.message
27
- end
28
- print ".. #{ip} - #{val}"
29
- puts
30
- end
31
- sleep poll
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
-
40
- Rig::Command::Main.subcommand 'balancer', 'view load balancers', Rig::Command::Balancer::Main
@@ -1,19 +0,0 @@
1
- require 'awesome_print'
2
-
3
- module Rig
4
- module Command
5
- module Balancer
6
- class View < Abstract
7
- include Options::ShowAll
8
-
9
- parameter "NAME", "name of instance"
10
-
11
- def execute
12
- item = Rig::Model::Balancer.find(name)
13
- puts item.attributes.to_yaml
14
- end
15
- end
16
- end
17
- end
18
- end
19
- Rig::Command::Balancer::Main.subcommand 'view', 'view instances', Rig::Command::Balancer::View
@@ -1,19 +0,0 @@
1
- require 'rig'
2
- require 'ipaddress'
3
-
4
- module Rig
5
- module Command
6
- module Dns
7
- class Create < Abstract
8
- parameter 'NAME', 'the name to create'
9
- parameter 'VALUE', 'where the name points to'
10
-
11
- def execute
12
- Rig::Model::Dns.create(name, value)
13
- end
14
- end
15
- end
16
- end
17
- end
18
-
19
- Rig::Command::Dns::Main.subcommand 'create', 'create dns name', Rig::Command::Dns::Create
@@ -1,16 +0,0 @@
1
- require 'rig'
2
-
3
- module Rig
4
- module Command
5
- module Dns
6
- class Destroy < Abstract
7
- parameter "NAME", "name of load balancer"
8
- def execute
9
- Rig::Model::Dns.destroy(name)
10
- end
11
- end
12
- end
13
- end
14
- end
15
-
16
- Rig::Command::Dns::Main.subcommand 'destroy', 'destroy dns record', Rig::Command::Dns::Destroy
@@ -1,20 +0,0 @@
1
- require 'rig'
2
- require 'ipaddress'
3
-
4
- module Rig
5
- module Command
6
- module Dns
7
- class Edit < Abstract
8
- parameter 'NAME', 'the name to create'
9
- parameter 'VALUE', 'where the name points to'
10
-
11
- def execute
12
- Rig::Model::Dns.destroy(name)
13
- Rig::Model::Dns.create(name, value)
14
- end
15
- end
16
- end
17
- end
18
- end
19
-
20
- Rig::Command::Dns::Main.subcommand 'edit', 'edit dns name', Rig::Command::Dns::Edit
@@ -1,21 +0,0 @@
1
- require 'rig'
2
-
3
- module Rig
4
- module Command
5
- module Dns
6
- class List < Abstract
7
- def execute
8
- zone = Rig.get_config(:dns_zone)
9
- records = Rig::Model::Dns.records("#{zone}")
10
- rows = []
11
- records.each do |record|
12
- rows << [zone, record.type, record.ttl, record.name, [*record.value].join(",")]
13
- end
14
- print_table(%w{Domain Type TTL Name Value}, rows)
15
- end
16
- end
17
- end
18
- end
19
- end
20
-
21
- Rig::Command::Dns::Main.subcommand 'list', 'list dns', Rig::Command::Dns::List
@@ -1,13 +0,0 @@
1
- require 'rig'
2
-
3
- module Rig
4
- module Command
5
- module Dns
6
- class Main < Abstract
7
- self.default_subcommand = 'list'
8
- end
9
- end
10
- end
11
- end
12
-
13
- Rig::Command::Main.subcommand 'dns', 'view dns zones', Rig::Command::Dns::Main
@@ -1,21 +0,0 @@
1
- require 'rig'
2
- require 'fog'
3
-
4
- module Rig
5
- module Command
6
- module Environment
7
- class Create < Abstract
8
- parameter "NAME", "the name of the environment"
9
- parameter "TEMPLATE", "the template to use (solo, multi, etc)", :default => "solo"
10
-
11
- def execute
12
- #connection = Rig::Connection.compute
13
- env = Rig::Model::Environment.create(name, template.to_sym)
14
- #ap env.servers
15
- end
16
- end
17
- end
18
- end
19
- end
20
-
21
- Rig::Command::Environment::Main.subcommand 'create', 'create environment', Rig::Command::Environment::Create
@@ -1,18 +0,0 @@
1
- require 'rig'
2
- require 'fog'
3
-
4
- module Rig
5
- module Command
6
- module Environment
7
- class Destroy < Abstract
8
- parameter "NAME", "name of the environment to destroy"
9
-
10
- def execute
11
- Rig::Model::Environment.destroy(name)
12
- end
13
- end
14
- end
15
- end
16
- end
17
-
18
- Rig::Command::Environment::Main.subcommand 'destroy', 'destroy environment', Rig::Command::Environment::Destroy
@@ -1,31 +0,0 @@
1
- require 'rig'
2
- require 'fog'
3
-
4
- module Rig
5
- module Command
6
- module Environment
7
- class List < Abstract
8
-
9
- option %w{-s --simple}, :flag, "just show list of names"
10
-
11
- def execute
12
- envs = Rig::Model::Environment.list
13
-
14
- if simple?
15
- print_table(%w{Name}, envs)
16
- else
17
- rows = []
18
- envs.each do |e|
19
- env = Rig::Model::Environment.find(e)
20
- zones = env.servers.collect {|e| e.availability_zone }
21
- rows << [env.name, env.template, env.region, env.servers.count, env.balancers.count, env.protected?, zones]
22
- end
23
- print_table(%w{Name Template Region Servers# Balancers# Protected? AZs}, rows)
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
-
31
- Rig::Command::Environment::Main.subcommand 'list', 'List environments', Rig::Command::Environment::List
@@ -1,15 +0,0 @@
1
- require 'clamp'
2
- require 'rig'
3
-
4
- module Rig
5
- module Command
6
- module Environment
7
- class Main < Abstract
8
- self.default_subcommand = "list"
9
- end
10
- end
11
- end
12
- end
13
-
14
- Rig::Command::Main.subcommand 'environment', 'Commands related to environments', Rig::Command::Environment::Main
15
-
@@ -1,22 +0,0 @@
1
- module Rig
2
- module Command
3
- module Environment
4
- class Protect < Abstract
5
- option ["-u","--undo"], :flag, "disable protection instead of enabling"
6
- parameter "NAME", "the environment to protect"
7
-
8
- def execute
9
- env = Rig::Model::Environment.find(name)
10
- raise "Environment #{name} not found" if env.nil?
11
- connection = Rig::Connection.compute
12
- val = undo? ? "false" : "true"
13
-
14
- env.servers.each do |s|
15
- connection.create_tags(s.id, "Protected" => val)
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
22
- Rig::Command::Environment::Main.subcommand "protect", "[un]set protection on environment, preventing termination", Rig::Command::Environment::Protect
@@ -1,60 +0,0 @@
1
- require 'rig'
2
- require 'awesome_print'
3
-
4
- module Rig
5
- module Command
6
- module Instance
7
- class Create < Abstract
8
- option %w{-i --image}, "IMAGE", "the image / ami to use, default: your account image"
9
- option %w{-f --flavor}, "FLAVOR", "the flavor / size to use"
10
- option %w{-k --keypair}, "KEYPAIR", "the key pair / name to use, default: your account keypair"
11
- option %w{-g --groups}, "GROUPS", "comma separated list of groups, default: your account groups"
12
- option %w{-r --region}, "GROUPS", "the region, default: your account region"
13
- option %w{--add}, :flag, "add this to the existing instances of this role and environment"
14
- option "--[no-]chef", :flag, "use chef to bootstrap", :default => true
15
-
16
- parameter "ENVIRONMENT", "the environment this instance should belong to"
17
- parameter "ROLE", "the instance role", :default => 'solo'
18
-
19
- def execute
20
- name = role
21
- # figure out if there are others of this role, if there are add a number to name to distinguish.
22
- n = "#{name}.#{environment}.env"
23
- chef = Rig.config[:chef] ? true : false
24
-
25
- unless flavor
26
- raise "must specify flavor"
27
- end
28
-
29
- o = {
30
- :image_id => image,
31
- :flavor_id => flavor,
32
- :key_name => keypair,
33
- :groups => groups.split(','),
34
- :user_data => Rig::Model::Userdata.create(n, role, environment, :chef => chef)
35
- }
36
- tags = {'Name' => n, 'Environment' => environment, 'Role' => role}
37
- server = Rig::Model::Instance.create(o, tags)
38
- puts "created: #{server.id}"
39
- rescue => e
40
- puts "error: #{e.message}"
41
- raise Clamp::HelpWanted, self
42
- end
43
-
44
- def default_image
45
- Rig.account[:image].is_a?(Hash) ? Rig.account[:image].first.last : Rig.account[:image]
46
- end
47
-
48
- def default_keypair
49
- Rig.account[:keypair]
50
- end
51
-
52
- def default_groups
53
- Rig.account[:groups].join(",")
54
- end
55
- end
56
- end
57
- end
58
- end
59
-
60
- Rig::Command::Instance::Main.subcommand 'create', 'Create an instance', Rig::Command::Instance::Create