cloudster 2.2.0 → 2.3.0
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.md +6 -7
- data/VERSION +1 -1
- data/cloudster.gemspec +4 -2
- data/lib/cloudster.rb +1 -0
- data/lib/cloudster/elb.rb +94 -0
- data/spec/cloud_spec.rb +43 -3
- data/spec/elb_spec.rb +27 -0
- metadata +5 -3
data/README.md
CHANGED
@@ -19,10 +19,13 @@ Create AWS EC2 resources as shown here:
|
|
19
19
|
:image_id => 'ami_image_id',
|
20
20
|
:instance_type => 't1.micro'
|
21
21
|
)
|
22
|
-
app_server_2 = Cloudster::Ec2.new(:name => '
|
22
|
+
app_server_2 = Cloudster::Ec2.new(:name => 'AppServer2',
|
23
23
|
:key_name => 'mykey',
|
24
24
|
:image_id => 'ami_image_id'
|
25
25
|
)
|
26
|
+
load_balancer = Cloudster::Elb.new(:name => 'LoadBalancer',
|
27
|
+
:instance_names => ['AppServer', 'AppServer2']
|
28
|
+
)
|
26
29
|
|
27
30
|
Create a stack out of the resources :
|
28
31
|
|
@@ -35,15 +38,11 @@ Now you can do stuff like :
|
|
35
38
|
app_server.template
|
36
39
|
- Get the CloudFormation template for the stack :
|
37
40
|
|
38
|
-
stack.template(:resources => [app_server, app_server_2], :description => 'Description of the stack')
|
41
|
+
stack.template(:resources => [app_server, app_server_2, load_balancer], :description => 'Description of the stack')
|
39
42
|
|
40
43
|
- Provision the stack :
|
41
44
|
|
42
|
-
stack.provision(:resources => [app_server, app_server_2], :stack_name => 'TestStack', :description => 'Description of the stack')
|
43
|
-
|
44
|
-
- Update the stack :
|
45
|
-
|
46
|
-
stack.update(:resources => [app_server, app_server_2], :stack_name => 'TestStack', :description => 'Description of the stack')
|
45
|
+
stack.provision(:resources => [app_server, app_server_2, load_balancer], :stack_name => 'TestStack', :description => 'Description of the stack')
|
47
46
|
|
48
47
|
- You can get the events of a stack using :
|
49
48
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.0
|
data/cloudster.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "cloudster"
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Emil Soman"]
|
12
|
-
s.date = "2012-10-
|
12
|
+
s.date = "2012-10-30"
|
13
13
|
s.description = "Cloudster uses the AWS APIs to provision stacks on Amazon Cloud."
|
14
14
|
s.email = "emil.soman@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,9 +29,11 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/cloudster.rb",
|
30
30
|
"lib/cloudster/cloud.rb",
|
31
31
|
"lib/cloudster/ec2.rb",
|
32
|
+
"lib/cloudster/elb.rb",
|
32
33
|
"lib/cloudster/options_manager.rb",
|
33
34
|
"spec/cloud_spec.rb",
|
34
35
|
"spec/ec2_spec.rb",
|
36
|
+
"spec/elb_spec.rb",
|
35
37
|
"spec/spec_helper.rb"
|
36
38
|
]
|
37
39
|
s.homepage = "http://github.com/emilsoman/cloudster"
|
data/lib/cloudster.rb
CHANGED
@@ -0,0 +1,94 @@
|
|
1
|
+
module Cloudster
|
2
|
+
#==Elb resource
|
3
|
+
class Elb
|
4
|
+
|
5
|
+
# Initialize an Elb instance
|
6
|
+
#
|
7
|
+
# ==== Notes
|
8
|
+
# options parameter must include values for :name, :instance_names
|
9
|
+
#
|
10
|
+
# ==== Examples
|
11
|
+
# elb = Cloudster::Elb.new(
|
12
|
+
# :name => 'LoadBalancer',
|
13
|
+
# :instance_names => ['AppServer1','AppServer2']
|
14
|
+
# )
|
15
|
+
#
|
16
|
+
# ==== Parameters
|
17
|
+
# * options<~Hash> -
|
18
|
+
# * :name: String containing the name for the Elb resource
|
19
|
+
# * :instance_names: Array containing the names of the Ec2 resources which will be added under the ELB
|
20
|
+
def initialize(options = {})
|
21
|
+
require_options(options, [:name, :instance_names])
|
22
|
+
@name = options[:name]
|
23
|
+
@instance_names = options[:instance_names]
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns a Ruby hash version of the Cloud Formation template for the resource instance
|
27
|
+
#
|
28
|
+
# ==== Examples
|
29
|
+
# elb = Cloudster::Elb.new(
|
30
|
+
# :name => 'LoadBalancer',
|
31
|
+
# :instance_names => ['AppServer1','AppServer2']
|
32
|
+
# )
|
33
|
+
# elb.template
|
34
|
+
#
|
35
|
+
# ==== Returns
|
36
|
+
# * Ruby hash version of the Cloud Formation template for the resource instance
|
37
|
+
def template
|
38
|
+
Elb.template({:name =>@name, :instance_names => @instance_names})
|
39
|
+
end
|
40
|
+
|
41
|
+
# Class method that returns a Ruby hash version of the Cloud Formation template
|
42
|
+
#
|
43
|
+
# ==== Examples
|
44
|
+
# template = Cloudster::Elb.template(
|
45
|
+
# :name => 'LoadBalances',
|
46
|
+
# :instance_names => ['AppServer1', 'AppServer2']
|
47
|
+
# )
|
48
|
+
#
|
49
|
+
# ==== Parameters
|
50
|
+
# * options<~Hash> -
|
51
|
+
# *Keys:
|
52
|
+
# * :name: String containing the name for the Elb resource
|
53
|
+
# * :instance_names: Array containing the names of the Ec2 resources which will be added under the ELB
|
54
|
+
#
|
55
|
+
# ==== Returns
|
56
|
+
# * Ruby hash version of the Cloud Formation template
|
57
|
+
def self.template(options = {})
|
58
|
+
require_options(options, [:name, :instance_names])
|
59
|
+
properties = {"AvailabilityZones" => { "Fn::GetAZs" => "" },
|
60
|
+
"Listeners" => [{ "LoadBalancerPort" => "80",
|
61
|
+
"InstancePort" => "80",
|
62
|
+
"Protocol" => "HTTP"
|
63
|
+
}],
|
64
|
+
"HealthCheck" => {
|
65
|
+
"Target" => { "Fn::Join" => [ "", ["HTTP:", "80", "/"]]},
|
66
|
+
"HealthyThreshold" => "3",
|
67
|
+
"UnhealthyThreshold" => "5",
|
68
|
+
"Interval" => "30",
|
69
|
+
"Timeout" => "5"
|
70
|
+
}
|
71
|
+
}
|
72
|
+
properties.merge!({"Instances" => get_instance_name_list_for_template(options[:instance_names])})
|
73
|
+
template = {'Resources' => {
|
74
|
+
options[:name] => {
|
75
|
+
'Type' => 'AWS::ElasticLoadBalancing::LoadBalancer',
|
76
|
+
'Properties' => properties
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}
|
80
|
+
return template
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
#Gets the instance names in a format expected by the Template for ELB
|
85
|
+
def self.get_instance_name_list_for_template(instance_names)
|
86
|
+
instance_list = []
|
87
|
+
instance_names.each do |instance_name|
|
88
|
+
instance_list << {'Ref' => instance_name}
|
89
|
+
end
|
90
|
+
return instance_list
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
data/spec/cloud_spec.rb
CHANGED
@@ -13,8 +13,47 @@ describe Cloudster::Cloud do
|
|
13
13
|
it "should return a ruby hash for the stack cloudformation template" do
|
14
14
|
ec2 = Cloudster::Ec2.new(:key_name => 'testkey', :image_id => 'image_id', name: 'name')
|
15
15
|
ec2_1 = Cloudster::Ec2.new(:key_name => 'testkey1', :image_id => 'image_id1', name: 'name1')
|
16
|
+
elb = Cloudster::Elb.new(:name => 'ELB', :instance_names => ['name','name1'])
|
16
17
|
cloud = Cloudster::Cloud.new(:access_key_id => 'test', :secret_access_key => 'test')
|
17
|
-
cloud.template(:resources => [ec2, ec2_1], :description => 'test template').should == {"AWSTemplateFormatVersion"=>"2010-09-09",
|
18
|
+
cloud.template(:resources => [ec2, ec2_1, elb], :description => 'test template').should == {"AWSTemplateFormatVersion"=>"2010-09-09",
|
19
|
+
"Description"=>"test template",
|
20
|
+
"Resources"=>{
|
21
|
+
"name"=>{
|
22
|
+
"Type"=>"AWS::EC2::Instance",
|
23
|
+
"Properties"=>{
|
24
|
+
"KeyName"=>"testkey",
|
25
|
+
"ImageId"=>"image_id"}
|
26
|
+
},
|
27
|
+
"name1"=>{
|
28
|
+
"Type"=>"AWS::EC2::Instance",
|
29
|
+
"Properties"=>{
|
30
|
+
"KeyName"=>"testkey1",
|
31
|
+
"ImageId"=>"image_id1"
|
32
|
+
}
|
33
|
+
},
|
34
|
+
"ELB" => {
|
35
|
+
"Type" => "AWS::ElasticLoadBalancing::LoadBalancer",
|
36
|
+
"Properties" => {
|
37
|
+
"AvailabilityZones" => {
|
38
|
+
"Fn::GetAZs" => ""
|
39
|
+
},
|
40
|
+
"Listeners" => [{
|
41
|
+
"LoadBalancerPort" => "80",
|
42
|
+
"InstancePort" => "80",
|
43
|
+
"Protocol" => "HTTP"
|
44
|
+
}],
|
45
|
+
"HealthCheck" => {
|
46
|
+
"Target" => {
|
47
|
+
"Fn::Join" => ["",["HTTP:","80","/"]]
|
48
|
+
},
|
49
|
+
"HealthyThreshold" => "3",
|
50
|
+
"UnhealthyThreshold" => "5",
|
51
|
+
"Interval" => "30", "Timeout" => "5"
|
52
|
+
},
|
53
|
+
"Instances" => [{ "Ref" => "name"}, {"Ref" => "name1"}]}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}.to_json
|
18
57
|
end
|
19
58
|
end
|
20
59
|
|
@@ -28,9 +67,10 @@ describe Cloudster::Cloud do
|
|
28
67
|
cloud_formation = double('CloudFormation')
|
29
68
|
Fog::AWS::CloudFormation.should_receive(:new).with(:aws_access_key_id => 'test', :aws_secret_access_key => 'test').and_return cloud_formation
|
30
69
|
ec2 = Cloudster::Ec2.new(:key_name => 'testkey', :image_id => 'image_id', name: 'name')
|
70
|
+
elb = Cloudster::Elb.new(:name => 'ELB', :instance_names => ['name','name1'])
|
31
71
|
cloud = Cloudster::Cloud.new(:access_key_id => 'test', :secret_access_key => 'test')
|
32
|
-
cloud_formation.should_receive('create_stack').with('stack_name', 'TemplateBody' => cloud.template(:resources => [ec2], :description => 'testDescription'))
|
33
|
-
cloud.provision(:resources => [ec2], :stack_name => 'stack_name', :description => 'testDescription')
|
72
|
+
cloud_formation.should_receive('create_stack').with('stack_name', 'TemplateBody' => cloud.template(:resources => [ec2, elb], :description => 'testDescription'))
|
73
|
+
cloud.provision(:resources => [ec2, elb], :stack_name => 'stack_name', :description => 'testDescription')
|
34
74
|
end
|
35
75
|
end
|
36
76
|
|
data/spec/elb_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cloudster::Elb do
|
4
|
+
describe 'initialize' do
|
5
|
+
it "should raise argument error if no argument is not provided" do
|
6
|
+
expect { Cloudster::Elb.new() }.to raise_error(ArgumentError, 'Missing required argument: name,instance_names')
|
7
|
+
end
|
8
|
+
it "should not raise argument error if all arguments are provided" do
|
9
|
+
expect { Cloudster::Elb.new(:name => 'LoadBalancer', :instance_names => ['AppServer', 'AppServer2']) }.to_not raise_error
|
10
|
+
end
|
11
|
+
end
|
12
|
+
describe '#template' do
|
13
|
+
it "should return a ruby hash for the resource cloudformation template" do
|
14
|
+
elb = Cloudster::Elb.new(:name => 'LoadBalancer', :instance_names => ['AppServer', 'AppServer2'])
|
15
|
+
elb.template.should == {"Resources" => {"LoadBalancer"=>{"Type"=>"AWS::ElasticLoadBalancing::LoadBalancer", "Properties"=>{"AvailabilityZones"=>{"Fn::GetAZs"=>""}, "Listeners"=>[{"LoadBalancerPort"=>"80", "InstancePort"=>"80", "Protocol"=>"HTTP"}], "HealthCheck"=>{"Target"=>{"Fn::Join"=>["", ["HTTP:", "80", "/"]]}, "HealthyThreshold"=>"3", "UnhealthyThreshold"=>"5", "Interval"=>"30", "Timeout"=>"5"}, "Instances"=>[{"Ref"=>"AppServer"}, {"Ref"=>"AppServer2"}]}}}}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
describe '.template' do
|
19
|
+
it "should raise argument error if no argument is not provided" do
|
20
|
+
expect { Cloudster::Elb.template() }.to raise_error(ArgumentError, 'Missing required argument: name,instance_names')
|
21
|
+
end
|
22
|
+
it "should return a ruby hash for the resource cloudformation template" do
|
23
|
+
hash = Cloudster::Elb.template(:name => 'LoadBalancer', :instance_names => ['AppServer', 'AppServer2'])
|
24
|
+
hash.should == {"Resources" => {"LoadBalancer"=>{"Type"=>"AWS::ElasticLoadBalancing::LoadBalancer", "Properties"=>{"AvailabilityZones"=>{"Fn::GetAZs"=>""}, "Listeners"=>[{"LoadBalancerPort"=>"80", "InstancePort"=>"80", "Protocol"=>"HTTP"}], "HealthCheck"=>{"Target"=>{"Fn::Join"=>["", ["HTTP:", "80", "/"]]}, "HealthyThreshold"=>"3", "UnhealthyThreshold"=>"5", "Interval"=>"30", "Timeout"=>"5"}, "Instances"=>[{"Ref"=>"AppServer"}, {"Ref"=>"AppServer2"}]}}}}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fog
|
@@ -143,9 +143,11 @@ files:
|
|
143
143
|
- lib/cloudster.rb
|
144
144
|
- lib/cloudster/cloud.rb
|
145
145
|
- lib/cloudster/ec2.rb
|
146
|
+
- lib/cloudster/elb.rb
|
146
147
|
- lib/cloudster/options_manager.rb
|
147
148
|
- spec/cloud_spec.rb
|
148
149
|
- spec/ec2_spec.rb
|
150
|
+
- spec/elb_spec.rb
|
149
151
|
- spec/spec_helper.rb
|
150
152
|
homepage: http://github.com/emilsoman/cloudster
|
151
153
|
licenses:
|
@@ -162,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
164
|
version: '0'
|
163
165
|
segments:
|
164
166
|
- 0
|
165
|
-
hash: -
|
167
|
+
hash: -954846317
|
166
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
169
|
none: false
|
168
170
|
requirements:
|