bigbang 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,7 +42,7 @@ of the instance.
42
42
 
43
43
  Consider the following universe file:
44
44
 
45
- universe do
45
+ BigBang::DSL::Universe.new do
46
46
  config do |c|
47
47
  c.access_key_id = "YOUR-AMAZON-ACCESS_KEY"
48
48
  c.secret_key = "YOUR-AMAZON-SECRET_KEY"
@@ -9,37 +9,30 @@ end
9
9
 
10
10
  $universe = nil
11
11
 
12
- def self.universe(&block)
13
- dsl = BigBang::DSL.new
14
- dsl.instance_eval(&block)
15
- $universe = BigBang::Universe.new(dsl)
16
- end
17
-
18
12
  if ARGV.empty?
19
13
  help
20
14
  exit 1
21
15
  end
22
16
 
17
+ universe = eval(File.new('./universe.rb').read, binding)
18
+ $universe = BigBang::Universe.new(universe)
19
+
23
20
  case ARGV[0]
24
21
  when 'test':
25
- load './universe.rb'
26
22
  $universe.test
27
23
  when 'explode':
28
24
  if ARGV.size < 2 then
29
25
  puts "#{$0} explode <universe name>"
30
26
  exit 1
31
27
  end
32
- require 'universe.rb'
33
28
  $universe.explode(ARGV[1])
34
29
  when 'list':
35
- require 'universe.rb'
36
30
  $universe.list
37
31
  when 'kill':
38
32
  if ARGV.size < 2 then
39
33
  puts "#{$0} kill <universe name>"
40
34
  exit 1
41
35
  end
42
- require 'universe.rb'
43
36
  $universe.kill(ARGV[1])
44
37
  else
45
38
  puts "unknown command #{ARGV[0]}"
@@ -1 +1,2 @@
1
1
  require 'bigbang/universe'
2
+ require 'bigbang/dsl/dsl'
@@ -0,0 +1,23 @@
1
+ require 'bigbang/dsl/run'
2
+ require 'bigbang/dsl/lb'
3
+
4
+ module BigBang
5
+ module DSL
6
+ class ClusterRun < Run
7
+ attr_accessor :lb
8
+
9
+ def initialize(name, instances)
10
+ super(name, instances)
11
+ end
12
+
13
+ def availability_zone(h)
14
+ @zone_sizes.merge!(h)
15
+ end
16
+
17
+ def load_balancer(name, &block)
18
+ @lb = LoadBalancer.new(name)
19
+ @lb.instance_eval(&block)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module BigBang
2
+ module DSL
3
+ class Config
4
+ attr_accessor :access_key_id, :secret_key, :dns_opts, :domain, :region
5
+ def dns(d) @dns_opts = d; end
6
+
7
+ def initialize
8
+ self.region = "us-east-1"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ require 'bigbang/dsl/config'
2
+ require 'bigbang/dsl/instance'
3
+ require 'bigbang/dsl/cluster_run'
4
+ require 'bigbang/dsl/run'
5
+ require 'bigbang/dsl/universe'
@@ -0,0 +1,14 @@
1
+ module BigBang
2
+ module DSL
3
+ class Instance
4
+ def initialize(name)
5
+ @name = name
6
+ end
7
+
8
+ attr_accessor :ami, :key_name, :type,
9
+ :name,
10
+ :bootstrap_repo,
11
+ :bootstrap_params
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module BigBang
2
+ module DSL
3
+ class LoadBalancer
4
+ attr_accessor :domains, :name, :listeners, :availability_zones
5
+ attr_accessor :ec2_elb
6
+
7
+ def initialize(name)
8
+ @name = name
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ module BigBang
2
+ module DSL
3
+ class Run
4
+ attr_accessor :instance, :domain, :wildcard_domain, :elastic_ip
5
+ attr_accessor :zone_sizes
6
+ attr_accessor :ec2_instances
7
+ attr_accessor :assigned_ips
8
+
9
+ def initialize(name, instances)
10
+ @zone_sizes = {}
11
+ @ec2_instances = []
12
+ @assigned_ips = {}
13
+ @instance = instances.find { |i| i.name == name }
14
+ raise "instance #{name} not found" if @instance.nil?
15
+ end
16
+
17
+ def zones
18
+ return @zone_sizes unless @zone_sizes.empty?
19
+
20
+ { nil => 1 }
21
+ end
22
+
23
+ def instances_count
24
+ zones.values.inject(0) { |m,v| m += v }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ module BigBang
2
+ module DSL
3
+ class Universe
4
+ attr_accessor :instances, :conf, :runs
5
+
6
+ def initialize(&block)
7
+ @instances = []
8
+ @runs = []
9
+ self.instance_eval(&block)
10
+ end
11
+
12
+ def instance(name, &block)
13
+ @instances << Instance.new(name).tap do |i|
14
+ i.instance_eval(&block)
15
+ end
16
+ end
17
+
18
+ def config(&block)
19
+ @conf = Config.new.tap do |c|
20
+ c.instance_eval(&block)
21
+ end
22
+ end
23
+
24
+ def run_single_instance(name, &block)
25
+ @runs << Run.new(name, @instances).tap do |r|
26
+ r.instance_eval(&block)
27
+ end
28
+ end
29
+
30
+ def run_cluster(name, &block)
31
+ @runs << ClusterRun.new(name, @instances).tap do |r|
32
+ r.instance_eval(&block)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -4,18 +4,31 @@ module BigBang
4
4
  @config = config
5
5
  end
6
6
 
7
+ def aws_server_config
8
+ {
9
+ :access_key_id => @config.access_key_id,
10
+ :secret_access_key => @config.secret_key,
11
+ }
12
+ end
13
+
14
+ def elb_server_config
15
+ aws_server_config.merge(
16
+ :server => "elasticloadbalancing.#{@config.region}.amazonaws.com")
17
+ end
18
+
19
+ def ec2_server_config
20
+ aws_server_config.merge(
21
+ :server => "ec2.#{@config.region}.amazonaws.com")
22
+ end
23
+
7
24
  def ec2
8
25
  return @ec2 unless @ec2.nil?
9
- @ec2 = AWS::EC2::Base.new(
10
- :access_key_id => @config.access_key_id,
11
- :secret_access_key => @config.secret_key)
26
+ @ec2 = AWS::EC2::Base.new(ec2_server_config)
12
27
  end
13
28
 
14
29
  def elb
15
30
  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)
31
+ @elb = AWS::ELB::Base.new(elb_server_config)
19
32
  end
20
33
 
21
34
  def dns
@@ -15,8 +15,6 @@ module BigBang
15
15
  raise "zone '#{zone}' not found"
16
16
  end
17
17
  end
18
-
19
- puts "Availability zones OK"
20
18
  end
21
19
 
22
20
  def test_amis
@@ -24,33 +22,33 @@ module BigBang
24
22
  begin
25
23
  provider.ec2.describe_images(:image_id => [ami])
26
24
  rescue AWS::InvalidAMIIDNotFound => e
27
- puts "ami #{ami} not found"
25
+ raise "ami #{ami} not found"
28
26
  end
29
27
  end
30
- puts "AMI's OK"
31
28
  end
32
29
 
33
30
  def test_dns
34
31
  if provider.configured_zone.nil?
35
- puts "Configured DNS domain zone not found"
36
- else
37
- puts "DNS domain OK"
32
+ raise "Configured DNS domain zone not found"
38
33
  end
39
34
  end
40
35
 
41
- def test_elb
42
- ap provider.elb.describe_load_balancers
43
- puts "elb access OK"
44
- end
45
-
46
36
  def test
47
- get_instances
48
- puts "ec2 access OK"
37
+ notify("Testing EC2 access") do
38
+ get_instances
39
+ end
49
40
 
50
- test_elb
51
- test_availability_zones
52
- test_amis
53
- test_dns
41
+ notify("Testing configured availability zones") do
42
+ test_availability_zones
43
+ end
44
+
45
+ notify("Testing configured AMI's") do
46
+ test_amis
47
+ end
48
+
49
+ notify("Testing DNS API access") do
50
+ test_dns
51
+ end
54
52
  end
55
53
  end
56
54
  end
@@ -4,8 +4,7 @@ require 'ap'
4
4
  require 'set'
5
5
  require 'fog'
6
6
  require 'bigbang/provider'
7
- require 'bigbang/instance'
8
- require 'bigbang/dsl'
7
+ require 'bigbang/dsl/dsl'
9
8
  require 'bigbang/ec2-git-bootstrap'
10
9
  require 'bigbang/kill'
11
10
  require 'bigbang/test'
@@ -124,8 +123,8 @@ module BigBang
124
123
  puts "\033[01;32mOK\033[00m"
125
124
  return r
126
125
  rescue => e
127
- puts "\033[01;31mERROR\033[00m"
128
- raise
126
+ puts "\033[01;31mERROR"
127
+ puts "#{e.to_s}\033[00m"
129
128
  end
130
129
  end
131
130
 
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Giorgenes Gelatti
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-16 00:00:00 +01:00
18
+ date: 2011-07-18 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -62,17 +62,18 @@ files:
62
62
  - README.rdoc
63
63
  - lib/bigbang.rb
64
64
  - lib/bigbang/explode.rb
65
- - lib/bigbang/instance.rb
66
65
  - lib/bigbang/provider.rb
67
- - lib/bigbang/dsl.rb
68
- - lib/bigbang/run.rb
69
66
  - lib/bigbang/universe.rb
70
67
  - lib/bigbang/test.rb
71
68
  - lib/bigbang/ec2-git-bootstrap.rb
72
69
  - lib/bigbang/kill.rb
73
- - lib/bigbang/config.rb
74
- - lib/bigbang/cluster_run.rb
75
- - lib/bigbang/lb.rb
70
+ - lib/bigbang/dsl/instance.rb
71
+ - lib/bigbang/dsl/dsl.rb
72
+ - lib/bigbang/dsl/run.rb
73
+ - lib/bigbang/dsl/universe.rb
74
+ - lib/bigbang/dsl/config.rb
75
+ - lib/bigbang/dsl/cluster_run.rb
76
+ - lib/bigbang/dsl/lb.rb
76
77
  has_rdoc: true
77
78
  homepage: http://github.com/giorgenes/bigbang/
78
79
  licenses: []
@@ -1,21 +0,0 @@
1
- require 'bigbang/run'
2
- require 'bigbang/lb'
3
-
4
- module BigBang
5
- class ClusterRun < Run
6
- attr_accessor :lb
7
-
8
- def initialize(name, instances)
9
- super(name, instances)
10
- end
11
-
12
- def availability_zone(h)
13
- @zone_sizes.merge!(h)
14
- end
15
-
16
- def load_balancer(name, &block)
17
- @lb = LoadBalancer.new(name)
18
- @lb.instance_eval(&block)
19
- end
20
- end
21
- end
@@ -1,6 +0,0 @@
1
- module BigBang
2
- class Config
3
- attr_accessor :access_key_id, :secret_key, :dns_opts, :domain
4
- def dns(d) @dns_opts = d; end
5
- end
6
- end
@@ -1,39 +0,0 @@
1
- require 'bigbang/config'
2
- require 'bigbang/instance'
3
- require 'bigbang/cluster_run'
4
- require 'bigbang/run'
5
-
6
- module BigBang
7
- class DSL
8
- attr_accessor :instances, :conf, :runs
9
-
10
- def initialize
11
- @instances = []
12
- @runs = []
13
- end
14
-
15
- def instance(name, &block)
16
- @instances << Instance.new(name).tap do |i|
17
- i.instance_eval(&block)
18
- end
19
- end
20
-
21
- def config(&block)
22
- @conf = Config.new.tap do |c|
23
- c.instance_eval(&block)
24
- end
25
- end
26
-
27
- def run_single_instance(name, &block)
28
- @runs << Run.new(name, @instances).tap do |r|
29
- r.instance_eval(&block)
30
- end
31
- end
32
-
33
- def run_cluster(name, &block)
34
- @runs << ClusterRun.new(name, @instances).tap do |r|
35
- r.instance_eval(&block)
36
- end
37
- end
38
- end
39
- end
@@ -1,12 +0,0 @@
1
- module BigBang
2
- class Instance
3
- def initialize(name)
4
- @name = name
5
- end
6
-
7
- attr_accessor :ami, :key_name, :type,
8
- :name,
9
- :bootstrap_repo,
10
- :bootstrap_params
11
- end
12
- end
@@ -1,10 +0,0 @@
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
@@ -1,26 +0,0 @@
1
- module BigBang
2
- class Run
3
- attr_accessor :instance, :domain, :wildcard_domain, :elastic_ip
4
- attr_accessor :zone_sizes
5
- attr_accessor :ec2_instances
6
- attr_accessor :assigned_ips
7
-
8
- def initialize(name, instances)
9
- @zone_sizes = {}
10
- @ec2_instances = []
11
- @assigned_ips = {}
12
- @instance = instances.find { |i| i.name == name }
13
- raise "instance #{name} not found" if @instance.nil?
14
- end
15
-
16
- def zones
17
- return @zone_sizes unless @zone_sizes.empty?
18
-
19
- { nil => 1 }
20
- end
21
-
22
- def instances_count
23
- zones.values.inject(0) { |m,v| m += v }
24
- end
25
- end
26
- end