rig 0.3.3 → 0.3.4

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.
@@ -1,14 +1,41 @@
1
+ # The region for this account.
2
+ # Each account can have a different region, so you can
3
+ # manage deployments in different regions easily.
4
+ region: us-east-1
1
5
 
6
+ # The DNS zone to manage.
7
+ # Generally this will be different for each account,
8
+ # but it is possible to have all of your accounts
9
+ # managed under a single zone... IF you are using
10
+ # the same DNS provider for all of your accounts.
11
+ dns_zone: blah.com
12
+
13
+ # this is the key that you will use to SSH to the server
14
+ keypair: keyname
15
+
16
+ # Common settings.
17
+ # In most cases, you will be using the same provider
18
+ # for all of the different components within your
19
+ # infrastructure (Compute, DNS, Balancers, etc).
20
+ # You can store the common keys and secrets here.
2
21
  common: &common
3
22
  aws_access_key_id: aws_key
4
23
  aws_secret_access_key: aws_secret
24
+
25
+ # Compute settings
26
+ # These are passed to Fog when creating a connection
5
27
  compute:
6
28
  <<: *common
7
29
  provider: AWS
8
- region: us-east-1
30
+ region: *region
31
+
32
+ # DNS settings
33
+ # These are passed to Fog when creating a connection
9
34
  dns:
10
35
  <<: *common
11
36
  provider: AWS
12
- zone: dns.zone.com
37
+
38
+ # Balancer settings
39
+ # These are passed to Fog when creating a connection
13
40
  balancer:
14
41
  <<: *common
@@ -11,7 +11,8 @@ rig:
11
11
 
12
12
  ssh:
13
13
  # user to connect as, when ssh'ing to server
14
- user: root
14
+ # AWS defaults to the user "ubuntu"
15
+ user: ubuntu
15
16
 
16
17
  # the account to use if one is not specified
17
18
  default_account: default
@@ -22,6 +23,28 @@ rig:
22
23
  # - default
23
24
  # - production
24
25
 
26
+ # configuration overrides
27
+ # these values override those in the templates
25
28
 
26
- # flavor_id: ami-8baa73e2 # ubuntu 11.10, non-ebs storage
27
- # key_name: keyname
29
+ # DNS zone to manage
30
+ # generally, this should be set in the account
31
+ #dns_zone: blah.com
32
+
33
+ # the default region to use
34
+ # accounts can specify different regions
35
+ # meaning you can have a different rig account
36
+ # file for each deployment region
37
+ region: us-east-1
38
+
39
+ # AWS images (AMI's) are different per region
40
+ # for ubuntu, go to: http://cloud.ubuntu.com/ami/
41
+ image:
42
+ us-east-1: ami-8baa73e2 # ubuntu 11.10, non-ebs storage
43
+
44
+ # this is the key that you will use to SSH to the server
45
+ # keypair in account takes precedence
46
+ keypair: keyname
47
+
48
+ # specifying a flavor here will force all instances to
49
+ # be that flavor, overrides flavor in template
50
+ #flavor: m1.large
@@ -3,7 +3,7 @@
3
3
  # host lists for capistrano to use.
4
4
 
5
5
  require 'rig'
6
- require 'rig/cloud'
6
+ require 'rig/model'
7
7
  require 'capistrano'
8
8
 
9
9
  module Rig
@@ -11,12 +11,12 @@ module Rig
11
11
  def servers
12
12
  env = ENV['ENVIRONMENT'] || Rig.config.environment
13
13
  role = ENV['ROLE'] || Rig.config.role
14
- servers = Rig::Cloud::Environment.find(env).servers
14
+ servers = Rig::Model::Environment.find(env).servers
15
15
  list = servers.select { |s| s.tags['Role'] == role }
16
16
 
17
17
  raise "Rig could not find any servers matching environment=#{env} and role=#{role}" unless list && list.count > 0
18
18
  list.each do |s|
19
- server "#{s.tags['Name']}.#{Rig.config.dns.zone}", :web, :app
19
+ server "#{s.tags['Name']}.#{Rig.get_config(:dns_zone)}", :web, :app
20
20
  end
21
21
  rescue => e
22
22
  puts "*** servers not found: #{e.message}"
@@ -34,8 +34,8 @@ configuration.load do
34
34
 
35
35
  puts " * reading rig information..."
36
36
 
37
- set :environments, Rig::Cloud::Environment.list
38
- set :servers, Rig::Cloud::Instance.running
37
+ set :environments, Rig::Model::Environment.list
38
+ set :servers, Rig::Model::Instance.running
39
39
  set :rigroles, servers.collect { |s| s.tags['Role'] }.compact
40
40
 
41
41
  Rig.config.environment = ARGV[0]
@@ -3,7 +3,7 @@ require 'clamp'
3
3
  require 'fog'
4
4
  require 'yaml'
5
5
 
6
- require 'rig/cloud'
6
+ require 'rig/model'
7
7
 
8
8
  require 'rig/command/abstract'
9
9
  require 'rig/command/options'
@@ -6,7 +6,7 @@ module Rig
6
6
  class Destroy < Abstract
7
7
  parameter "NAME", "name of load balancer"
8
8
  def execute
9
- Rig::Cloud::Balancer.destroy(name)
9
+ Rig::Model::Balancer.destroy(name)
10
10
  end
11
11
  end
12
12
  end
@@ -5,7 +5,7 @@ module Rig
5
5
  module Balancer
6
6
  class List < Abstract
7
7
  def execute
8
- list = Rig::Cloud::Balancer.all
8
+ list = Rig::Model::Balancer.all
9
9
  list.each do |lb|
10
10
  puts lb.id
11
11
  lb.instances.each do |inst|
@@ -9,7 +9,7 @@ module Rig
9
9
  parameter "NAME", "name of instance"
10
10
 
11
11
  def execute
12
- item = Rig::Cloud::Balancer.find(name)
12
+ item = Rig::Model::Balancer.find(name)
13
13
  puts item.attributes.to_yaml
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ module Rig
9
9
  parameter 'VALUE', 'where the name points to'
10
10
 
11
11
  def execute
12
- Rig::Cloud::Dns.create(name, value)
12
+ Rig::Model::Dns.create(name, value)
13
13
  end
14
14
  end
15
15
  end
@@ -6,7 +6,7 @@ module Rig
6
6
  class Destroy < Abstract
7
7
  parameter "NAME", "name of load balancer"
8
8
  def execute
9
- Rig::Cloud::Dns.destroy(name)
9
+ Rig::Model::Dns.destroy(name)
10
10
  end
11
11
  end
12
12
  end
@@ -9,8 +9,8 @@ module Rig
9
9
  parameter 'VALUE', 'where the name points to'
10
10
 
11
11
  def execute
12
- Rig::Cloud::Dns.destroy(name)
13
- Rig::Cloud::Dns.create(name, value)
12
+ Rig::Model::Dns.destroy(name)
13
+ Rig::Model::Dns.create(name, value)
14
14
  end
15
15
  end
16
16
  end
@@ -5,8 +5,8 @@ module Rig
5
5
  module Dns
6
6
  class List < Abstract
7
7
  def execute
8
- zone = Rig.config.dns.zone
9
- records = Rig::Cloud::Dns.records("#{zone}")
8
+ zone = Rig.get_config(:dns_zone)
9
+ records = Rig::Model::Dns.records("#{zone}")
10
10
  rows = []
11
11
  records.each do |record|
12
12
  rows << [zone, record.type, record.ttl, record.name, record.value]
@@ -12,8 +12,8 @@ module Rig
12
12
  parameter "TEMPLATE", "the template to use (solo, multi, etc)", :default => "solo"
13
13
 
14
14
  def execute
15
- #connection = Rig::Cloud.compute
16
- env = Rig::Cloud::Environment.create(name, template.to_sym)
15
+ #connection = Rig::Connection.compute
16
+ env = Rig::Model::Environment.create(name, template.to_sym)
17
17
  #ap env.servers
18
18
  end
19
19
  end
@@ -8,7 +8,7 @@ module Rig
8
8
  parameter "NAME", "name of the environment to destroy"
9
9
 
10
10
  def execute
11
- Rig::Cloud::Environment.destroy(name)
11
+ Rig::Model::Environment.destroy(name)
12
12
  end
13
13
  end
14
14
  end
@@ -9,14 +9,14 @@ module Rig
9
9
  option %w{-s --simple}, :flag, "just show list of names"
10
10
 
11
11
  def execute
12
- envs = Rig::Cloud::Environment.list
12
+ envs = Rig::Model::Environment.list
13
13
 
14
14
  if simple?
15
15
  print_table(%w{Name}, envs)
16
16
  else
17
17
  rows = []
18
18
  envs.each do |e|
19
- env = Rig::Cloud::Environment.find(e)
19
+ env = Rig::Model::Environment.find(e)
20
20
  rows << [env.name, env.template, env.region, env.servers.count, env.balancers.count]
21
21
  end
22
22
  print_table(%w{Name Template Region Servers# Balancers#}, rows)
@@ -9,8 +9,8 @@ module Rig
9
9
  parameter "NAME", "the name of the instance to connect to"
10
10
 
11
11
  def execute
12
- list = Rig::Cloud::Instance.find(name)
13
- Rig::Cloud::Instance.destroy(list)
12
+ list = Rig::Model::Instance.find(name)
13
+ Rig::Model::Instance.destroy(list)
14
14
  end
15
15
  end
16
16
  end
@@ -9,7 +9,7 @@ module Rig
9
9
  parameter "[ENV]", "environment"
10
10
 
11
11
  def execute
12
- connection = Rig::Cloud.compute
12
+ connection = Rig::Connection.compute
13
13
  filters = {}
14
14
  filters["instance-state-name"] = "running" unless showall?
15
15
  filters["tag:Environment"] = env if env
@@ -12,7 +12,7 @@ module Rig
12
12
  raise "Must set either instance name or instance id (-iname or -iid)"
13
13
  end
14
14
 
15
- connection = Rig::Cloud.compute
15
+ connection = Rig::Connection.compute
16
16
  if iid
17
17
  instance = connection.servers.get(iid)
18
18
  else
@@ -15,7 +15,7 @@ module Rig
15
15
  raise "Must set either instance name or instance id (-iname or -iid)"
16
16
  end
17
17
 
18
- connection = Rig::Cloud.compute
18
+ connection = Rig::Connection.compute
19
19
  if iid
20
20
  instance = connection.servers.get(iid)
21
21
  else
@@ -14,7 +14,7 @@ module Rig
14
14
  raise "Must set either instance name or instance id (-iname or -iid)"
15
15
  end
16
16
 
17
- connection = Rig::Cloud.compute
17
+ connection = Rig::Connection.compute
18
18
  if iid
19
19
  instance = connection.servers.get(iid)
20
20
  else
@@ -7,7 +7,7 @@ module Rig
7
7
  parameter "NAME", "name of instance"
8
8
 
9
9
  def execute
10
- list = Rig::Cloud::Instance.find(name)
10
+ list = Rig::Model::Instance.find(name)
11
11
  list.each do |item|
12
12
  puts item.attributes.to_yaml
13
13
  puts
@@ -3,7 +3,7 @@ module Rig
3
3
  module Keypair
4
4
  class List < Abstract
5
5
  def execute
6
- connection = Rig::Cloud.compute
6
+ connection = Rig::Connection.compute
7
7
  list = connection.key_pairs.all
8
8
  puts list.inspect
9
9
  end
@@ -11,13 +11,21 @@ module Rig
11
11
 
12
12
  subcommand "accounts", "show account list" do
13
13
  def execute
14
- list = Rig.account_list
14
+ list = Rig::Model::Account.list
15
15
  list.each do |n, f|
16
16
  puts " #{n} => #{f}"
17
17
  end
18
18
  end
19
19
  end
20
20
 
21
+ def merge_file(src, dest)
22
+ old = YAML.load_file(dest)
23
+ FileUtils.mv(dest, "#{dest}.bak.#{Time.now.to_i}")
24
+ new = YAML.load_file(src)
25
+ new.merge!(old)
26
+ File.open(dest, "w") {|f| f.write(new.to_yaml)}
27
+ end
28
+
21
29
  subcommand "init", "initialize configuration directory" do
22
30
  option %w{-f --force}, :flag, "force creation of files", :default => false
23
31
  option %w{-d --directory}, "DIRECTORY", "configuration directory", :default => "~/.rig"
@@ -9,7 +9,7 @@ module Rig
9
9
  exit(1)
10
10
  end
11
11
 
12
- list = Rig::Cloud::Instance.find_by_nick(name)
12
+ list = Rig::Model::Instance.find_by_nick(name)
13
13
  if list.count == 0
14
14
  puts "server not found."
15
15
  elsif list.count > 1
@@ -1,6 +1,10 @@
1
1
 
2
2
  module Rig
3
3
  class << self
4
+ @templates = []
5
+ @accounts = []
6
+ @cache_config = []
7
+
4
8
  def configdir
5
9
  @configdir ||= File.expand_path(ENV["RIG_CONFIG"] || "~/.rig")
6
10
  end
@@ -15,26 +19,16 @@ module Rig
15
19
  end
16
20
  end
17
21
 
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
22
+ def account(name=get_account)
23
+ Rig::Model::Account.load(name)
28
24
  end
29
25
 
30
- def account
31
- @account ||= begin
32
- Oconfig.load_yaml_file("#{configdir}/accounts/#{get_account}.yml")
33
- end
26
+ def get_config(name)
27
+ Rig.account[name] || Rig.config[name] || nil
34
28
  end
35
29
 
36
- def template(name)
37
- #TODO: implement getting template data from file
30
+ def get_template(name)
31
+ Rig::Model::Template.load(name)
38
32
  end
39
33
 
40
34
  def get_account
@@ -52,7 +46,7 @@ module Rig
52
46
  raise "Configuration not found: #{path} (#{file})" unless File.exists?(file)
53
47
  yaml = YAML.load_file(file)
54
48
  yaml = yaml[yaml.keys.first] if yaml.keys.count == 1
55
- Rig::Oconfig.new(yaml)
49
+ self.new(yaml)
56
50
  end
57
51
  end
58
52
 
@@ -0,0 +1,3 @@
1
+ require 'rig'
2
+
3
+ Dir["#{File.dirname(__FILE__)}/model/*.rb"].each {|file| require file.gsub(/\.rb/,'')}
@@ -0,0 +1,25 @@
1
+ module Rig
2
+ module Model
3
+ class Account < Rig::Oconfig
4
+ class << self
5
+ def load(name)
6
+ self.load_yaml_file("#{dir}/#{name}.yml")
7
+ end
8
+
9
+ def list
10
+ Dir["#{dir}/*"].inject({ }) do |h, e|
11
+ f = e.gsub("#{dir}/", "")
12
+ f = File.basename(f, ".yml")
13
+ h[f.to_sym] = e
14
+ h
15
+ end
16
+ end
17
+
18
+ private
19
+ def dir
20
+ "#{Rig.configdir}/accounts"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,14 +1,14 @@
1
1
 
2
2
  module Rig
3
- module Cloud
3
+ module Model
4
4
  class Balancer
5
5
  class << self
6
6
  def all
7
- Rig::Cloud.balancer.load_balancers.all
7
+ Rig::Connection.balancer.load_balancers.all
8
8
  end
9
9
 
10
10
  def new(name)
11
- Rig::Cloud.balancer.load_balancers.new({ :id => name })
11
+ Rig::Connection.balancer.load_balancers.new({ :id => name })
12
12
  end
13
13
 
14
14
  def create(name)
@@ -19,7 +19,7 @@ module Rig
19
19
  end
20
20
 
21
21
  def find(name)
22
- Rig::Cloud.balancer.load_balancers.get(name)
22
+ Rig::Connection.balancer.load_balancers.get(name)
23
23
  end
24
24
 
25
25
  def find_by_environment(name)
@@ -2,7 +2,7 @@ require 'rig'
2
2
  require 'fog'
3
3
 
4
4
  module Rig
5
- module Cloud
5
+ module Connection
6
6
  class << self
7
7
  def compute
8
8
  @compute ||= begin
@@ -2,15 +2,15 @@ require 'rig'
2
2
  require 'ipaddress'
3
3
 
4
4
  module Rig
5
- module Cloud
5
+ module Model
6
6
  class Dns
7
7
  class << self
8
8
  def all
9
- Rig::Cloud.dns.zones.all
9
+ Rig::Connection.dns.zones.all
10
10
  end
11
11
 
12
12
  def zone(zone)
13
- Rig::Cloud.dns.zones.find(zone).first
13
+ Rig::Connection.dns.zones.find(zone).first
14
14
  end
15
15
 
16
16
  def records(zone)
@@ -18,27 +18,27 @@ module Rig
18
18
  end
19
19
 
20
20
  def zone_create(name)
21
- Rig::Cloud.dns.zones.create(
21
+ Rig::Connection.dns.zones.create(
22
22
  :domain => name
23
23
  )
24
24
  end
25
25
 
26
26
  def create(name, value)
27
- zone = zone(Rig.config.dns.zone)
27
+ zone = zone(Rig.get_config(:dns_zone))
28
28
 
29
29
  if IPAddress.valid?(value)
30
30
  #A record
31
31
  o = {:name => name, :value => value, :type => 'A', :ttl => 86400}
32
32
  else
33
33
  #CNAME record
34
- #name = name.gsub(/\.#{Rig.config.dns.zone}/,'')
34
+ #name = name.gsub(/\.#{Rig.get_config(:dns_zone)}/,'')
35
35
  o = {:name => name, :value => value, :type => 'CNAME', :ttl => 300}
36
36
  end
37
37
  zone.records.create(o)
38
38
  end
39
39
 
40
40
  def destroy(name)
41
- zone = zone(Rig.config.dns.zone)
41
+ zone = zone(Rig.get_config(:dns_zone))
42
42
  name = name.gsub(/\.$/, '')
43
43
  # cant seem to make zone.records#get or zone.records#find work correctly
44
44
  list = zone.records.all.select {|e| e.attributes[:name] == "#{name}."}
@@ -1,10 +1,11 @@
1
1
  module Rig
2
- module Cloud
2
+ module Model
3
3
  class Environment
4
4
  attr_reader :servers
5
5
  attr_reader :balancers
6
6
  attr_reader :name
7
7
  attr_reader :template
8
+ attr_reader :template_name
8
9
  attr_reader :image
9
10
  attr_reader :region
10
11
  attr_reader :flavor
@@ -36,7 +37,7 @@ module Rig
36
37
  def list
37
38
  filters = { }
38
39
 
39
- list = Rig::Cloud.compute.servers.all(filters)
40
+ list = Rig::Connection.compute.servers.all(filters)
40
41
  list.inject([]) { |a, e| a << e.tags["Environment"] }.compact.uniq.sort
41
42
  end
42
43
 
@@ -70,51 +71,53 @@ module Rig
70
71
  :region => Rig.config.region,
71
72
  }.merge(opts)
72
73
 
73
- @name = name
74
- @template = template
75
- @region = @options[:region]
76
- #TODO: allow global config setting for image (in AWS, the ami)
77
- @image = @options[:image] # || Rig.config.compute.image[@region] || Rig.config.compute.image
78
- #TODO: allow global config setting for flavor (in AWS, the size, like: m1.large)
79
- @flavor = @options[:flavor] # || Rig.config.flavor[@region] || Rig.config.flavor
80
- @servers = []
81
- @balancers = []
74
+ @name = name
75
+ @template_name = template
76
+ #@region = @options[:region]
77
+ ##TODO: allow global config setting for image (in AWS, the ami)
78
+ #@image = @options[:image] # || Rig.config.compute.image[@region] || Rig.config.compute.image
79
+ ##TODO: allow global config setting for flavor (in AWS, the size, like: m1.large)
80
+ #@flavor = @options[:flavor] # || Rig.config.flavor[@region] || Rig.config.flavor
81
+ @servers = []
82
+ @balancers = []
82
83
  end
83
84
 
84
85
  def save
85
86
  puts "creating instances"
86
87
 
87
- template_name = @template.to_sym
88
- template = TEMPLATES[template_name]
89
- raise "unknown template #{template}" unless template
88
+ #@template = TEMPLATES[@template_name]
89
+ @template = Rig.get_template(@template_name)
90
+ raise "unknown template #{template}" unless @template
91
+ load_config
90
92
 
91
- template[:instances].each do |inst|
93
+ @template[:instances].each do |inst|
92
94
  setinstances = []
93
95
  inst.each do |role, tmpl|
94
- count = tmpl[:count]
95
- image = tmpl[:image] || @image
96
- flavor = tmpl[:flavor] || @flavor
97
- keypair = Rig.config.keypair
96
+ count = tmpl[:count] || 1
98
97
  count.times do |i|
99
98
  n = "#{role}#{i+1}.#{name}.env"
100
99
  chef = Rig.config.chef ? true : false
101
100
 
102
101
  o = {
103
- :image_id => image,
104
- :flavor_id => flavor,
105
- :key_name => keypair,
106
- :groups => tmpl[:groups] || template[:groups],
107
- :user_data => Rig::Cloud.userdata(n, role, name, :chef => chef)
102
+ :image_id => tmpl[:image] || @image,
103
+ :flavor_id => tmpl[:flavor] || @flavor,
104
+ :key_name => tmpl[:keypair] || @keypair,
105
+ :groups => tmpl[:groups] || @template[:groups] || @groups,
106
+ :user_data => Rig::Model::Userdata.create(n, role, name, :chef => chef)
108
107
  }
109
108
 
110
- server = Rig::Cloud::Instance.create(o, 'Name' => n, 'Environment' => name, 'Role' => role)
109
+ # throw this error, because Fog and AWS don't care if you don't set a keypair
110
+ # but you won't be able to easily connect to it
111
+ raise "No key_name (keypair) set." unless o[:key_name]
112
+
113
+ server = Rig::Model::Instance.create(o, 'Name' => n, 'Environment' => name, 'Role' => role)
111
114
  @servers << server
112
115
  setinstances << server
113
116
  end
114
117
 
115
118
  if tmpl[:balance]
116
119
  puts "creating balancer"
117
- balancer = Rig::Cloud::Balancer.create("#{name}-#{role}")
120
+ balancer = Rig::Model::Balancer.create("#{name}-#{role}")
118
121
  balancer.register_instances(setinstances.collect { |e| e.id })
119
122
  balancer.save
120
123
 
@@ -125,14 +128,14 @@ module Rig
125
128
  # if there are 3 servers with the harvester role
126
129
  # in the environment test
127
130
  # then the dns would be harvester.test.env.inqlabs.com
128
- puts ".. dns: #{role}.#{name}.env.#{Rig.config.dns.zone} #{balancer.attributes[:dns_name]}"
129
- Rig::Cloud::Dns.create("#{role}.#{name}.env.#{Rig.config.dns.zone}", balancer.attributes[:dns_name])
131
+ puts ".. dns: #{role}.#{name}.env.#@zone #{balancer.attributes[:dns_name]}"
132
+ Rig::Model::Dns.create("#{role}.#{name}.env.#@zone", balancer.attributes[:dns_name])
130
133
 
131
134
  # set primary dns for environment (<name>.env.inqlabs.com)
132
135
  # to point to this load balancer
133
136
  if tmpl[:primary]
134
- puts ".. primary: #{name}.env.#{Rig.config.dns.zone} #{balancer.attributes[:dns_name]}"
135
- Rig::Cloud::Dns.create("#{name}.env.#{Rig.config.dns.zone}", balancer.attributes[:dns_name])
137
+ puts ".. primary: #{name}.env.#@zone #{balancer.attributes[:dns_name]}"
138
+ Rig::Model::Dns.create("#{name}.env.#@zone", balancer.attributes[:dns_name])
136
139
  end
137
140
  end
138
141
  end
@@ -155,43 +158,43 @@ module Rig
155
158
 
156
159
  puts "associating servers' DNS"
157
160
  @servers.each do |server|
158
- record = "#{server.tags['Name']}.#{Rig.config.dns.zone}"
161
+ record = "#{server.tags['Name']}.#{Rig.get_config(:dns_zone)}"
159
162
  dns = server.attributes[:dns_name]
160
163
  ip = server.attributes[:public_ip_address]
161
164
 
162
165
  puts ".. #{record} dns=#{dns} ip=#{ip}"
163
166
  if dns
164
- Rig::Cloud::Dns.create(record, dns)
167
+ Rig::Model::Dns.create(record, dns)
165
168
  else
166
169
  puts "server #{server.id} doesn't have public_ip_address"
167
170
  end
168
171
  end
169
172
  rescue => e
170
- puts "error creating environment: #{e.message}"
173
+ puts "error creating environment:\n#{e.message} at #{e.backtrace.join("\n")}"
171
174
  destroy
172
- raise "error creating environment: #{e.message}"
175
+ raise "error creating environment: #{e.message} at #{e.backtrace.first}"
173
176
  end
174
177
 
175
178
  def destroy
176
179
  puts "removing dns from servers"
177
180
  @servers.each do |server|
178
- Rig::Cloud::Dns.destroy("#{server.tags['Name']}.#{Rig.config.dns.zone}") if server.tags['Name']
181
+ Rig::Model::Dns.destroy("#{server.tags['Name']}.#{Rig.get_config(:dns_zone)}") if server.tags['Name']
179
182
  end
180
183
 
181
- roles = @servers.collect {|s| s.tags['Role'] }.compact
184
+ roles = @servers.collect { |s| s.tags['Role'] }.compact
182
185
  roles.each do |r|
183
186
  puts "removing role balancer dns"
184
- Rig::Cloud::Dns.destroy("#{r}.#{name}.env.#{Rig.config.dns.zone}")
187
+ Rig::Model::Dns.destroy("#{r}.#{name}.env.#{Rig.get_config(:dns_zone)}")
185
188
  end
186
189
 
187
190
  puts "removing primary dns"
188
- Rig::Cloud::Dns.destroy("#{name}.env.#{Rig.config.dns.zone}")
191
+ Rig::Model::Dns.destroy("#{name}.env.#{Rig.get_config(:dns_zone)}")
189
192
 
190
193
  puts "destroying servers"
191
- Rig::Cloud::Instance.destroy(@servers)
194
+ Rig::Model::Instance.destroy(@servers)
192
195
 
193
196
  puts "destroying balancers"
194
- Rig::Cloud::Balancer.destroy(@balancers)
197
+ Rig::Model::Balancer.destroy(@balancers)
195
198
 
196
199
  if Rig.config.chef
197
200
  puts "destroying chef environment"
@@ -205,12 +208,35 @@ module Rig
205
208
  end
206
209
 
207
210
  private
211
+
212
+ def load_config
213
+ @region = @options[:region] ||
214
+ Rig.get_config(:region) ||
215
+ nil
216
+ @image = @options[:image] ||
217
+ Rig.account.image ||
218
+ Rig.config.image.kind_of?(Oconfig) ? Rig.config.image[@region] : Rig.config.image ||
219
+ nil
220
+ @flavor = @options[:flavor] ||
221
+ Rig.get_config(:flavor) ||
222
+ nil
223
+ @zone = @options[:dns_zone] ||
224
+ Rig.get_config(:dns_zone) ||
225
+ nil
226
+ @keypair = @options[:keypair] ||
227
+ Rig.get_config(:keypair) ||
228
+ nil
229
+ @groups = @options[:groups] ||
230
+ Rig.get_config(:groups) ||
231
+ nil
232
+ end
233
+
208
234
  def find_servers
209
- @servers = Rig::Cloud::Instance.find_by_environment(@name) || []
235
+ @servers = Rig::Model::Instance.find_by_environment(@name) || []
210
236
  end
211
237
 
212
238
  def find_balancers
213
- @balancers = Rig::Cloud::Balancer.find_by_environment(@name) || []
239
+ @balancers = Rig::Model::Balancer.find_by_environment(@name) || []
214
240
  end
215
241
  end
216
242
  end
@@ -1,11 +1,11 @@
1
1
  require 'fog'
2
2
 
3
3
  module Rig
4
- module Cloud
4
+ module Model
5
5
  class Instance
6
6
  class << self
7
7
  def all(filters={})
8
- Rig::Cloud.compute.servers.all(filters)
8
+ Rig::Connection.compute.servers.all(filters)
9
9
  end
10
10
 
11
11
  def running
@@ -14,18 +14,18 @@ module Rig
14
14
 
15
15
  def find(id)
16
16
  if id =~ /^i-/
17
- Rig::Cloud.compute.servers.find(id)
17
+ Rig::Connection.compute.servers.find(id)
18
18
  else
19
19
  # must be tag:Name
20
- Rig::Cloud.compute.servers.all({"tag:Name"=>id})
20
+ Rig::Connection.compute.servers.all({"tag:Name"=>id})
21
21
  end
22
22
  end
23
23
 
24
24
  def find_by_environment(env)
25
- Rig::Cloud.compute.servers.all({"tag:Environment"=>env})
25
+ Rig::Connection.compute.servers.all({"tag:Environment"=>env})
26
26
  end
27
27
  def find_by_role_and_environment(role, env)
28
- Rig::Cloud.compute.servers.all({"tag:Environment"=> env, "tag:Role" => role})
28
+ Rig::Connection.compute.servers.all({"tag:Environment"=> env, "tag:Role" => role})
29
29
  end
30
30
 
31
31
  def find_by_nick(name)
@@ -34,7 +34,7 @@ module Rig
34
34
  end
35
35
 
36
36
  def create(opts, tags={})
37
- fog = Rig::Cloud.compute
37
+ fog = Rig::Connection.compute
38
38
  server = fog.servers.create(opts)
39
39
  fog.create_tags(server.id, tags) if tags.count > 0
40
40
  puts ".. created: #{server.id}"
@@ -45,7 +45,7 @@ module Rig
45
45
  list = [*list]
46
46
 
47
47
  if list.count > 0
48
- compute = Rig::Cloud.compute
48
+ compute = Rig::Connection.compute
49
49
  ids = list.map {|e| e.kind_of?(String) ? e : e.id}
50
50
  puts ".. destroying: #{ids.inspect}"
51
51
 
@@ -0,0 +1,34 @@
1
+ module Rig
2
+ module Model
3
+ class Template
4
+ class << self
5
+ def load(name)
6
+ self.load_yaml_file("#{dir}/#{name}.yml")
7
+ end
8
+
9
+ def load_yaml_file(path)
10
+ file = File.expand_path(path)
11
+ raise "Configuration not found: #{path} (#{file})" unless File.exists?(file)
12
+ yaml = YAML.load_file(file)
13
+ yaml = yaml[yaml.keys.first] if yaml.keys.count == 1
14
+
15
+ yaml
16
+ end
17
+
18
+ def list
19
+ Dir["#{dir}/*"].inject({ }) do |h, e|
20
+ f = e.gsub("#{dir}/", "")
21
+ f = File.basename(f, ".yml")
22
+ h[f.to_sym] = e
23
+ h
24
+ end
25
+ end
26
+
27
+ private
28
+ def dir
29
+ "#{Rig.configdir}/templates"
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,20 +1,21 @@
1
1
  require 'erubis'
2
2
 
3
3
  module Rig
4
- module Cloud
5
- class << self
6
- def userdata(name, role, environment, opts={ })
7
- data = {
8
- :name => name,
9
- :role => role,
10
- :environment => environment,
11
- :zone => Rig.config.dns.zone,
12
- :dependencies => %w{ ruby1.9.3 ruby1.9.1-dev rubygems ruby-switch libopenssl-ruby1.9.1 rdoc1.9.1 ri1.9.1 irb1.9.1
4
+ module Model
5
+ class Userdata
6
+ class << self
7
+ def create(name, role, environment, opts={ })
8
+ data = {
9
+ :name => name,
10
+ :role => role,
11
+ :environment => environment,
12
+ :zone => Rig.get_config(:dns_zone),
13
+ :dependencies => %w{ ruby1.9.3 ruby1.9.1-dev rubygems ruby-switch libopenssl-ruby1.9.1 rdoc1.9.1 ri1.9.1 irb1.9.1
13
14
  build-essential wget ssl-cert curl },
14
- :gems => %w{chef},
15
- :chef => false,
16
- }.merge(opts)
17
- template = <<-EOF
15
+ :gems => %w{chef},
16
+ :chef => false,
17
+ }.merge(opts)
18
+ template = <<-EOF
18
19
  #!/bin/bash
19
20
  set -e -x
20
21
  exec > ~/userdata.log 2>&1
@@ -102,9 +103,10 @@ tRv2ngXlc2sYh9RbnlWSdaK0g+U7V8l2wSsQjcPQ1J2vbIGjwBHDSzjc
102
103
  VALID
103
104
 
104
105
  chef-client -N <%= @name %> <%= @chef && @environment ? "-E " + @environment : "" %> --once -j /etc/chef/bootstrap.json 2>&1
105
- EOF
106
- erb = Erubis::Eruby.new(template)
107
- out = erb.evaluate(data)
106
+ EOF
107
+ erb = Erubis::Eruby.new(template)
108
+ out = erb.evaluate(data)
109
+ end
108
110
  end
109
111
  end
110
112
  end
@@ -3,7 +3,7 @@ unless defined?(Rig::Version)
3
3
  module Version
4
4
  MAJOR = 0
5
5
  MINOR = 3
6
- TINY = 3
6
+ TINY = 4
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
9
9
  end
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: 21
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 3
10
- version: 0.3.3
9
+ - 4
10
+ version: 0.3.4
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-25 00:00:00 Z
18
+ date: 2012-04-26 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: clamp
@@ -124,13 +124,6 @@ files:
124
124
  - lib/rig.rb
125
125
  - lib/rig/capistrano.rb
126
126
  - lib/rig/chef.rb
127
- - lib/rig/cloud.rb
128
- - lib/rig/cloud/balancer.rb
129
- - lib/rig/cloud/connection.rb
130
- - lib/rig/cloud/dns.rb
131
- - lib/rig/cloud/environment.rb
132
- - lib/rig/cloud/instance.rb
133
- - lib/rig/cloud/userdata.rb
134
127
  - lib/rig/command.rb
135
128
  - lib/rig/command/abstract.rb
136
129
  - lib/rig/command/balancer/destroy.rb
@@ -161,6 +154,15 @@ files:
161
154
  - lib/rig/command/options.rb
162
155
  - lib/rig/command/ssh.rb
163
156
  - lib/rig/config.rb
157
+ - lib/rig/model.rb
158
+ - lib/rig/model/account.rb
159
+ - lib/rig/model/balancer.rb
160
+ - lib/rig/model/connection.rb
161
+ - lib/rig/model/dns.rb
162
+ - lib/rig/model/environment.rb
163
+ - lib/rig/model/instance.rb
164
+ - lib/rig/model/template.rb
165
+ - lib/rig/model/userdata.rb
164
166
  - lib/rig/version.rb
165
167
  - rig.gemspec
166
168
  homepage: https://github.com/shawncatz/rig
@@ -1,3 +0,0 @@
1
- require 'rig'
2
-
3
- Dir["#{File.dirname(__FILE__)}/cloud/*.rb"].each {|file| require file.gsub(/\.rb/,'')}