bigbang 0.0.5 → 0.0.6

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.
data/README.rdoc CHANGED
@@ -42,40 +42,47 @@ of the instance.
42
42
 
43
43
  Consider the following universe file:
44
44
 
45
- universe do
46
- config do |c|
47
- c.access_key_id = "YOUR-AMAZON-ACCESS_KEY"
48
- c.secret_key = "YOUR-AMAZON-SECRET_KEY"
45
+ universe do
46
+ config do |c|
47
+ c.access_key_id = "YOUR-AMAZON-ACCESS_KEY"
48
+ c.secret_key = "YOUR-AMAZON-SECRET_KEY"
49
49
 
50
- c.dns :provider => 'Zerigo',
51
- :zerigo_email => "example@example.com",
52
- :zerigo_token => 'xxxxxxxxxxxxx'
53
-
54
- c.domain = "example.com"
55
- end
50
+ c.dns :provider => 'Zerigo',
51
+ :zerigo_email => "example@example.com",
52
+ :zerigo_token => 'xxxxxxxxxxxxx'
53
+
54
+ c.domain = "example.com"
55
+ end
56
56
 
57
- # describe your instance
58
- instance "ubuntu" do |i|
59
- i.ami = "ami-e2af508b"
60
- i.key_name = "dev"
61
- i.type = "m1.small"
62
- i.bootstrap_repo = "git://github.com/giorgenes/ec2-chef-bootstrap.git"
63
- end
64
-
65
- # run a single instance
66
- run_single_instance("ubuntu") do |r|
67
- r.domain = ["db"]
68
- r.wildcard_domain = true
69
- r.elastic_ip = true
70
- end
57
+ # describe your instance
58
+ instance "ubuntu" do |i|
59
+ i.ami = "ami-e2af508b"
60
+ i.key_name = "dev"
61
+ i.type = "m1.small"
62
+ i.bootstrap_repo = "git://github.com/giorgenes/ec2-chef-bootstrap.git"
63
+ end
64
+
65
+ # run a single instance
66
+ run_single_instance("ubuntu") do |r|
67
+ r.domain = ["db"]
68
+ r.wildcard_domain = true
69
+ r.elastic_ip = true
70
+ end
71
71
 
72
- # runs a cluster of db instances
73
- run_cluster("ubuntu") do |r|
74
- r.domain = ["app"]
75
- availability_zone "us-east-1a" => 1
76
- availability_zone "us-east-1b" => 1
77
- end
78
- end
72
+ # runs a cluster of db instances
73
+ run_cluster("ubuntu") do |r|
74
+ r.domain = ["app"]
75
+ availability_zone "us-east-1a" => 1
76
+ availability_zone "us-east-1b" => 1
77
+ r.load_balancer("app") do |lb|
78
+ lb.domains = ["app"]
79
+ lb.listeners = [
80
+ { :protocol => 'http', :load_balancer_port => 80, :instance_port => 80 }
81
+ ]
82
+ lb.availability_zones = ["us-east-1a", "us-east-1b"]
83
+ end
84
+ end
85
+ end
79
86
 
80
87
  In this example we have a single instance of "ubuntu" AND a cluster of "ubuntu".
81
88
  So if you run for example "bigbang explode live" it will do the following:
@@ -89,24 +96,27 @@ So if you run for example "bigbang explode live" it will do the following:
89
96
  - create 2 ec2 instances on the specified availability zones.
90
97
  - clone the repo in the boxes and install chef
91
98
  - create DNS records to the boxes: live.app0.example.com and live.app1.example.com
99
+ - create a load balancer called "app" for the http protocol mapping ports 80 to 80.
100
+ - assign the cluster instances to the created load balancer
101
+ - create a CNAME record for the load balancer: live.app.example.com
92
102
 
93
103
  == Commands
94
104
 
95
105
  - creates a universe called <universe-name>
96
106
 
97
- bigbang explode <universe-name>
107
+ bigbang explode <universe-name>
98
108
 
99
109
  - list universes
100
110
 
101
- bigbang list
111
+ bigbang list
102
112
 
103
113
  - kill a universe
104
114
 
105
- bigbang kill <universe-name>
115
+ bigbang kill <universe-name>
106
116
 
107
117
  - test configuration
108
118
 
109
- bigbang test
119
+ bigbang test
110
120
 
111
121
  = IMPORTANT
112
122
 
@@ -1,8 +1,10 @@
1
1
  require 'bigbang/run'
2
+ require 'bigbang/lb'
2
3
 
3
4
  module BigBang
4
5
  class ClusterRun < Run
5
-
6
+ attr_accessor :lb
7
+
6
8
  def initialize(name, instances)
7
9
  super(name, instances)
8
10
  end
@@ -10,5 +12,10 @@ module BigBang
10
12
  def availability_zone(h)
11
13
  @zone_sizes.merge!(h)
12
14
  end
15
+
16
+ def load_balancer(name, &block)
17
+ @lb = LoadBalancer.new(name)
18
+ @lb.instance_eval(&block)
19
+ end
13
20
  end
14
21
  end
@@ -48,18 +48,15 @@ module BigBang
48
48
  (avail_ips - black_ips).to_a[0,ninstances]
49
49
  end
50
50
 
51
-
52
-
53
51
  def wait_for_running(instances)
54
52
  ids = instances.collect { |i| i.instanceId }.to_set
55
- print "Waiting for all instances to be in running state. "
56
- STDOUT.flush
57
- while running_instances_count(ids) < instances.size
58
- print "."
59
- sleep(5)
60
- STDOUT.flush
53
+ notify("Waiting for all instances to be in running state. ") do
54
+ while running_instances_count(ids) < instances.size
55
+ print "."
56
+ STDOUT.flush
57
+ sleep(5)
58
+ end
61
59
  end
62
- puts
63
60
  end
64
61
 
65
62
  def tag_instance(instance, ec2_instance, name)
@@ -71,8 +68,8 @@ module BigBang
71
68
  end
72
69
 
73
70
  def run_instance(instance, userdata, zone, size)
74
- puts "launching #{size} instance(s) on availability zone '#{zone}'"
75
- provider.ec2.run_instances(
71
+ notify("launching #{size} instance(s) on availability zone '#{zone}'") do
72
+ provider.ec2.run_instances(
76
73
  :image_id => instance.ami,
77
74
  :key_name => instance.key_name,
78
75
  :instance_type => instance.type,
@@ -80,7 +77,8 @@ module BigBang
80
77
  :availability_zone => zone,
81
78
  :min_count => size,
82
79
  :max_count => size
83
- )
80
+ )
81
+ end
84
82
  end
85
83
 
86
84
  def run_instances(name)
@@ -117,16 +115,26 @@ module BigBang
117
115
  end
118
116
  end
119
117
 
120
- def create_dns_entry_for(instance, universe_name, domain, addr, wildcard)
118
+ def dns_entry_for(instance, universe_name, domain, addr, wildcard)
119
+ entries = []
121
120
  domain = "#{universe_name}.#{domain}"
122
- puts "creating domain #{domain}.#{@config.domain} to #{addr}"
123
- provider.create_dns(domain, addr)
121
+ entries << {:domain => domain, :value => addr, :type => 'A'}
124
122
  if wildcard == true
125
- provider.create_dns("*.#{domain}", addr)
123
+ entries << {:domain => "*.#{domain}", :value => addr, :type => 'A'}
124
+ end
125
+ entries
126
+ end
127
+
128
+ def create_dns_entries(entries)
129
+ entries.each do |entry|
130
+ notify("creating domain #{entry[:domain]}.#{@config.domain} => #{entry[:value]}") do
131
+ provider.create_dns(entry[:domain], entry[:value], entry[:type])
132
+ end
126
133
  end
127
134
  end
128
135
 
129
- def create_dns_entries(universe_name)
136
+ def instance_dns_entries(universe_name)
137
+ entries = []
130
138
  instances_map = get_instances_map
131
139
  @runs.each do |r|
132
140
  addsufix = false
@@ -152,11 +160,50 @@ module BigBang
152
160
  if addsufix
153
161
  domain = "#{domain}#{sufix}"
154
162
  end
155
- create_dns_entry_for(instance, universe_name, domain, addr, r.wildcard_domain)
163
+ entries += dns_entry_for(instance, universe_name, domain, addr, r.wildcard_domain)
156
164
  end
157
165
  sufix += 1
158
166
  end
159
167
  end
168
+ entries
169
+ end
170
+
171
+ def create_lb(lb)
172
+ p = notify("creating ELB #{lb.name}") do
173
+ provider.elb.create_load_balancer(
174
+ :load_balancer_name => lb.name,
175
+ :listeners => lb.listeners,
176
+ :availability_zones => lb.availability_zones)
177
+ end
178
+ p
179
+ end
180
+
181
+ def create_load_balancers
182
+ @runs.each do |r|
183
+ next unless r.is_a?(ClusterRun)
184
+ next if r.lb.nil?
185
+
186
+ r.lb.ec2_elb = create_lb(r.lb)
187
+
188
+ notify("registering instances to ELB #{r.lb.name}") do
189
+ provider.elb.register_instances_with_load_balancer(
190
+ :load_balancer_name => r.lb.name,
191
+ :instances => r.ec2_instances
192
+ )
193
+ end
194
+ end
195
+ end
196
+
197
+ def elb_dns_entries(universe_name)
198
+ entries = []
199
+ configured_elbs.each do |lb|
200
+ lb.domains.each do |domain|
201
+ subdomain = "#{universe_name}.#{domain}"
202
+ cname = lb.ec2_elb.CreateLoadBalancerResult.DNSName
203
+ entries << { :domain => subdomain, :value => cname, :type => "CNAME" }
204
+ end
205
+ end
206
+ entries
160
207
  end
161
208
 
162
209
  def explode(name)
@@ -168,7 +215,10 @@ module BigBang
168
215
  assign_addresses(free_eips)
169
216
  end
170
217
  end
171
- create_dns_entries(name)
218
+ create_load_balancers
219
+ dns_entries = elb_dns_entries(name)
220
+ dns_entries += instance_dns_entries(name)
221
+ create_dns_entries(dns_entries)
172
222
  end
173
223
  end
174
224
  end
data/lib/bigbang/kill.rb CHANGED
@@ -2,8 +2,9 @@ module BigBang
2
2
  module KillCmd
3
3
  def kill_instance(instance)
4
4
  confirm("kill instance #{instance.instanceId}") do
5
- provider.ec2.terminate_instances(:instance_id => [instance.instanceId])
6
- puts "sent termination signal to #{instance.instanceId}"
5
+ notify("sending termination signal to #{instance.instanceId}") do
6
+ provider.ec2.terminate_instances(:instance_id => [instance.instanceId])
7
+ end
7
8
  end
8
9
  end
9
10
 
@@ -42,7 +43,20 @@ module BigBang
42
43
  end
43
44
  end
44
45
 
46
+
47
+
48
+ def kill_elb
49
+ configured_elbs.each do |lb|
50
+ confirm("Delete ELB #{lb.name}") do
51
+ notify("deleting ELB #{lb.name}") do
52
+ provider.elb.delete_load_balancer(:load_balancer_name => lb.name)
53
+ end
54
+ end
55
+ end
56
+ end
57
+
45
58
  def kill(name)
59
+ kill_elb
46
60
  running = running_instances
47
61
  instances = universe_running_instances(running, universe_tags(name))
48
62
  addresses = get_addresses
data/lib/bigbang/lb.rb ADDED
@@ -0,0 +1,10 @@
1
+ module BigBang
2
+ class LoadBalancer
3
+ attr_accessor :domains, :name, :listeners, :availability_zones
4
+ attr_accessor :ec2_elb
5
+
6
+ def initialize(name)
7
+ @name = name
8
+ end
9
+ end
10
+ end
@@ -11,6 +11,13 @@ module BigBang
11
11
  :secret_access_key => @config.secret_key)
12
12
  end
13
13
 
14
+ def elb
15
+ return @elb unless @elb.nil?
16
+ @elb = AWS::ELB::Base.new(
17
+ :access_key_id => @config.access_key_id,
18
+ :secret_access_key => @config.secret_key)
19
+ end
20
+
14
21
  def dns
15
22
  return @dns unless @dns.nil?
16
23
  @dns = Fog::DNS.new(@config.dns_opts)
@@ -20,11 +27,11 @@ module BigBang
20
27
  dns.zones.find { |z| z.domain == @config.domain }
21
28
  end
22
29
 
23
- def create_dns(domain, addr)
30
+ def create_dns(domain, value, type)
24
31
  configured_zone.records.create(
25
- :value => addr,
32
+ :value => value,
26
33
  :name => domain,
27
- :type => "A")
34
+ :type => type)
28
35
  end
29
36
 
30
37
  def eips
data/lib/bigbang/test.rb CHANGED
@@ -38,10 +38,16 @@ module BigBang
38
38
  end
39
39
  end
40
40
 
41
+ def test_elb
42
+ ap provider.elb.describe_load_balancers
43
+ puts "elb access OK"
44
+ end
45
+
41
46
  def test
42
47
  get_instances
43
48
  puts "ec2 access OK"
44
49
 
50
+ test_elb
45
51
  test_availability_zones
46
52
  test_amis
47
53
  test_dns
@@ -53,10 +53,20 @@ module BigBang
53
53
  map
54
54
  end
55
55
 
56
+ def configured_elbs
57
+ lbs = []
58
+ @runs.each do |r|
59
+ next unless r.is_a?(ClusterRun)
60
+ next if r.lb.nil?
61
+ lbs << r.lb
62
+ end
63
+ lbs
64
+ end
65
+
56
66
  def get_addresses
57
- items = provider.ec2.describe_addresses.addressesSet.item
58
- items = [] if items.nil?
59
- items
67
+ aset = provider.ec2.describe_addresses.addressesSet
68
+ return [] if aset.nil?
69
+ aset.item
60
70
  end
61
71
 
62
72
  def running_instances
@@ -105,6 +115,19 @@ module BigBang
105
115
  return false
106
116
  end
107
117
  end
118
+
119
+ def notify(msg)
120
+ print "#{msg}: "
121
+ STDOUT.flush
122
+ begin
123
+ r = yield
124
+ puts "\033[01;32mOK\033[00m"
125
+ return r
126
+ rescue => e
127
+ puts "\033[01;31mERROR\033[00m"
128
+ raise
129
+ end
130
+ end
108
131
 
109
132
  def instance_tags(tags = nil)
110
133
  tags = get_tags if tags.nil?
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigbang
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Giorgenes Gelatti
@@ -72,6 +72,7 @@ files:
72
72
  - lib/bigbang/kill.rb
73
73
  - lib/bigbang/config.rb
74
74
  - lib/bigbang/cluster_run.rb
75
+ - lib/bigbang/lb.rb
75
76
  has_rdoc: true
76
77
  homepage: http://github.com/giorgenes/bigbang/
77
78
  licenses: []