cloudster 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -44,10 +44,18 @@ Now you can do stuff like :
44
44
 
45
45
  stack.provision(:resources => [app_server, app_server_2, load_balancer], :stack_name => 'TestStack', :description => 'Description of the stack')
46
46
 
47
+ - Update the stack :
48
+
49
+ stack.update(:resources => [app_server, app_server_2], :stack_name => 'TestStack', :description => 'Description of the stack')
50
+
47
51
  - You can get the events of a stack using :
48
52
 
49
53
  stack.events(:stack_name => 'TestStack')
50
54
 
55
+ - You can delete the stack and it's attached resources :
56
+
57
+ stack.delete(:stack_name => 'TestStack')
58
+
51
59
 
52
60
  ##License
53
61
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "cloudster"
8
- s.version = "2.3.0"
8
+ s.version = "2.4.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-30"
12
+ s.date = "2012-10-31"
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 = [
@@ -31,9 +31,11 @@ Gem::Specification.new do |s|
31
31
  "lib/cloudster/ec2.rb",
32
32
  "lib/cloudster/elb.rb",
33
33
  "lib/cloudster/options_manager.rb",
34
+ "lib/cloudster/rds.rb",
34
35
  "spec/cloud_spec.rb",
35
36
  "spec/ec2_spec.rb",
36
37
  "spec/elb_spec.rb",
38
+ "spec/rds_spec.rb",
37
39
  "spec/spec_helper.rb"
38
40
  ]
39
41
  s.homepage = "http://github.com/emilsoman/cloudster"
@@ -6,4 +6,5 @@ require 'cloudster/options_manager'
6
6
  include OptionsManager
7
7
  require 'cloudster/ec2'
8
8
  require 'cloudster/elb'
9
+ require 'cloudster/rds'
9
10
  require 'cloudster/cloud'
@@ -143,5 +143,26 @@ module Cloudster
143
143
  return @cloud_formation.describe_stack_events(options[:stack_name])
144
144
  end
145
145
 
146
+ # Deletes a stack and the attached resources
147
+ #
148
+ # ==== Examples
149
+ # cloud = Cloudster::Cloud.new(
150
+ # :access_key_id => 'aws_access_key_id'
151
+ # :secret_access_key => 'aws_secret_access_key',
152
+ # )
153
+ # cloud.delete(:stack_name => 'ShittyStack')
154
+ #
155
+ # ==== Parameters
156
+ # * options<~Hash>
157
+ # * :stack_name : A string which will contain the name of the stack for which will be deleted
158
+ #
159
+ # ==== Returns
160
+ # * response<~Excon::Response>:
161
+ # * body<~Hash>:
162
+ def delete(options = {})
163
+ require_options(options, [:stack_name])
164
+ return @cloud_formation.delete_stack(options[:stack_name])
165
+ end
166
+
146
167
  end
147
168
  end
@@ -0,0 +1,114 @@
1
+ module Cloudster
2
+ #==Rds resource
3
+ class Rds
4
+
5
+ # Initialize an Rds instance
6
+ #
7
+ # ==== Notes
8
+ # options parameter must include values for :name, :storage_size
9
+ #
10
+ # ==== Examples
11
+ # rds = Cloudster::Rds.new(
12
+ # :name => 'MySqlDB',
13
+ # :instance_class => 'db.t1.micro',
14
+ # :storage_class => '100',
15
+ # :username => 'admin',
16
+ # :password => 'admin123',
17
+ # :engine => 'MySQL'
18
+ # )
19
+ #
20
+ # ==== Parameters
21
+ # * options<~Hash> -
22
+ # *Keys:
23
+ # * :name: String containing the name for the Rds resource. Mandatory option.
24
+ # * :instance_class: String containing the name of the compute and memory capacity class of the DB instance. Default: 'db.t1.micro'
25
+ # * :storage_size: String containing the allocated storage size specified in gigabytes. Mandatory option.
26
+ # * :username: String containing the master username for the DB instance. Default: 'root'
27
+ # * :password: String containing the master password for the DB instance. Default: 'root'
28
+ # * :engine: String containing the name of the database engine to be used for this DB instance. Default: 'MySQL'
29
+ # Valid values : MySQL | oracle-se1 | oracle-se | oracle-ee | sqlserver-ee | sqlserver-se | sqlserver-ex | sqlserver-web
30
+ def initialize(options = {})
31
+ require_options(options, [:name, :storage_size])
32
+ options[:username] ||= 'root'
33
+ options[:password] ||= 'root'
34
+ options[:engine] ||= 'MySQL'
35
+ options[:instance_class] ||= 'db.t1.micro'
36
+ @name = options[:name]
37
+ @storage_size = options[:storage_size]
38
+ @username = options[:username]
39
+ @password = options[:password]
40
+ @engine = options[:engine]
41
+ @instance_class = options[:instance_class]
42
+ end
43
+
44
+ # Returns a Ruby hash version of the Cloud Formation template for the resource instance
45
+ #
46
+ # ==== Examples
47
+ # rds = Cloudster::Rds.new(
48
+ # :name => 'MySqlDB',
49
+ # :instance_class => 'db.t1.micro',
50
+ # :storage_class => '100',
51
+ # :username => 'admin',
52
+ # :password => 'admin123',
53
+ # :engine => 'MySQL'
54
+ # )
55
+ # rds.template
56
+ #
57
+ # ==== Returns
58
+ # * Ruby hash version of the Cloud Formation template for the resource instance
59
+ def template
60
+ Rds.template({:name =>@name, :instance_class => @instance_class, :storage_size => @storage_size, :username => @username, :password => @password, :engine => @engine})
61
+ end
62
+
63
+ # Class method that returns a Ruby hash version of the Cloud Formation template
64
+ #
65
+ # ==== Notes
66
+ # options parameter must include values for :name, :storage_size
67
+ #
68
+ # ==== Examples
69
+ # template = Cloudster::Rds.template(
70
+ # :name => 'MySqlDB',
71
+ # :instance_class => 'db.t1.micro',
72
+ # :storage_class => '100',
73
+ # :username => 'admin',
74
+ # :password => 'admin123',
75
+ # :engine => 'MySQL'
76
+ # )
77
+ #
78
+ # ==== Parameters
79
+ # * options<~Hash> -
80
+ # *Keys:
81
+ # * :name: String containing the name for the Rds resource. Mandatory option.
82
+ # * :instance_class: String containing the name of the compute and memory capacity class of the DB instance. Default: 'db.t1.micro'
83
+ # * :storage_size: String containing the allocated storage size specified in gigabytes. Mandatory option.
84
+ # * :username: String containing the master username for the DB instance. Default: 'root'
85
+ # * :password: String containing the master password for the DB instance. Default: 'root'
86
+ # * :engine: String containing the name of the database engine to be used for this DB instance. Default: 'MySQL'
87
+ # Valid values : MySQL | oracle-se1 | oracle-se | oracle-ee | sqlserver-ee | sqlserver-se | sqlserver-ex | sqlserver-web
88
+ #
89
+ # ==== Returns
90
+ # * Ruby hash version of the Cloud Formation template
91
+ def self.template(options = {})
92
+ require_options(options, [:name, :storage_size])
93
+ options[:username] ||= 'root'
94
+ options[:password] ||= 'root'
95
+ options[:engine] ||= 'MySQL'
96
+ options[:instance_class] ||= 'db.t1.micro'
97
+ template = {'Resources' => {
98
+ options[:name] => {
99
+ "Type" => "AWS::RDS::DBInstance",
100
+ "Properties" => {
101
+ "Engine" => options[:engine],
102
+ "MasterUsername" => options[:username],
103
+ "MasterUserPassword" => options[:password],
104
+ "DBInstanceClass" => options[:instance_class],
105
+ "AllocatedStorage" => options[:storage_size]
106
+ }
107
+ }
108
+ }
109
+ }
110
+ return template
111
+ end
112
+
113
+ end
114
+ end
@@ -13,9 +13,10 @@ 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
+ rds = Cloudster::Rds.new(:name => 'MySqlDB', :storage_size => '10')
16
17
  elb = Cloudster::Elb.new(:name => 'ELB', :instance_names => ['name','name1'])
17
18
  cloud = Cloudster::Cloud.new(:access_key_id => 'test', :secret_access_key => 'test')
18
- cloud.template(:resources => [ec2, ec2_1, elb], :description => 'test template').should == {"AWSTemplateFormatVersion"=>"2010-09-09",
19
+ cloud.template(:resources => [ec2, ec2_1, rds, elb], :description => 'test template').should == {"AWSTemplateFormatVersion"=>"2010-09-09",
19
20
  "Description"=>"test template",
20
21
  "Resources"=>{
21
22
  "name"=>{
@@ -31,6 +32,16 @@ describe Cloudster::Cloud do
31
32
  "ImageId"=>"image_id1"
32
33
  }
33
34
  },
35
+ 'MySqlDB' => {
36
+ "Type" => "AWS::RDS::DBInstance",
37
+ "Properties" => {
38
+ "Engine" => 'MySQL',
39
+ "MasterUsername" => 'root',
40
+ "MasterUserPassword" => 'root',
41
+ "DBInstanceClass" => 'db.t1.micro',
42
+ "AllocatedStorage" => '10'
43
+ }
44
+ },
34
45
  "ELB" => {
35
46
  "Type" => "AWS::ElasticLoadBalancing::LoadBalancer",
36
47
  "Properties" => {
@@ -68,9 +79,10 @@ describe Cloudster::Cloud do
68
79
  Fog::AWS::CloudFormation.should_receive(:new).with(:aws_access_key_id => 'test', :aws_secret_access_key => 'test').and_return cloud_formation
69
80
  ec2 = Cloudster::Ec2.new(:key_name => 'testkey', :image_id => 'image_id', name: 'name')
70
81
  elb = Cloudster::Elb.new(:name => 'ELB', :instance_names => ['name','name1'])
82
+ rds = Cloudster::Rds.new(:name => 'MySqlDB', :storage_size => '10')
71
83
  cloud = Cloudster::Cloud.new(:access_key_id => 'test', :secret_access_key => 'test')
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')
84
+ cloud_formation.should_receive('create_stack').with('stack_name', 'TemplateBody' => cloud.template(:resources => [ec2, elb, rds], :description => 'testDescription'))
85
+ cloud.provision(:resources => [ec2, elb, rds], :stack_name => 'stack_name', :description => 'testDescription')
74
86
  end
75
87
  end
76
88
 
@@ -80,7 +92,7 @@ describe Cloudster::Cloud do
80
92
  cloud = Cloudster::Cloud.new(:access_key_id => 'test', :secret_access_key => 'test')
81
93
  expect { cloud.update(:description => 'test') }.to raise_error(ArgumentError, 'Missing required argument: resources,stack_name' )
82
94
  end
83
- it "should trigger stack creation" do
95
+ it "should trigger stack update" do
84
96
  cloud_formation = double('CloudFormation')
85
97
  Fog::AWS::CloudFormation.should_receive(:new).with(:aws_access_key_id => 'test', :aws_secret_access_key => 'test').and_return cloud_formation
86
98
  ec2 = Cloudster::Ec2.new(:key_name => 'testkey', :image_id => 'image_id', name: 'name')
@@ -99,4 +111,18 @@ describe Cloudster::Cloud do
99
111
  cloud.events(:stack_name => 'stack_name')
100
112
  end
101
113
  end
114
+
115
+ describe '#delete' do
116
+ it "should raise argument error if resources not provided" do
117
+ cloud = Cloudster::Cloud.new(:access_key_id => 'test', :secret_access_key => 'test')
118
+ expect { cloud.delete() }.to raise_error(ArgumentError, 'Missing required argument: stack_name')
119
+ end
120
+ it "should trigger 'delete stack' request" do
121
+ cloud_formation = double('CloudFormation')
122
+ Fog::AWS::CloudFormation.should_receive(:new).with(:aws_access_key_id => 'test', :aws_secret_access_key => 'test').and_return cloud_formation
123
+ cloud = Cloudster::Cloud.new(:access_key_id => 'test', :secret_access_key => 'test')
124
+ cloud_formation.should_receive('delete_stack').with('stack_name')
125
+ cloud.delete(:stack_name => 'stack_name')
126
+ end
127
+ end
102
128
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cloudster::Rds do
4
+ describe 'initialize' do
5
+ it "should raise argument error if no argument is not provided" do
6
+ expect { Cloudster::Rds.new() }.to raise_error(ArgumentError, 'Missing required argument: name,storage_size')
7
+ end
8
+ it "should not raise argument error if all arguments are provided" do
9
+ expect { Cloudster::Rds.new(:name => 'MySqlDB', :storage_size => '10') }.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
+ rds = Cloudster::Rds.new(:name => 'MySqlDB', :storage_size => '10')
15
+ template = {'Resources' => {
16
+ 'MySqlDB' => {
17
+ "Type" => "AWS::RDS::DBInstance",
18
+ "Properties" => {
19
+ "Engine" => 'MySQL',
20
+ "MasterUsername" => 'root',
21
+ "MasterUserPassword" => 'root',
22
+ "DBInstanceClass" => 'db.t1.micro',
23
+ "AllocatedStorage" => '10'
24
+ }
25
+ }
26
+ }
27
+ }
28
+ rds.template.should == template
29
+ end
30
+ end
31
+ describe '.template' do
32
+ it "should raise argument error if no argument is not provided" do
33
+ expect { Cloudster::Rds.template() }.to raise_error(ArgumentError, 'Missing required argument: name,storage_size')
34
+ end
35
+ it "should return a ruby hash for the resource cloudformation template" do
36
+ hash = Cloudster::Rds.template(:name => 'MySqlDB', :storage_size => '10')
37
+ template = {'Resources' => {
38
+ 'MySqlDB' => {
39
+ "Type" => "AWS::RDS::DBInstance",
40
+ "Properties" => {
41
+ "Engine" => 'MySQL',
42
+ "MasterUsername" => 'root',
43
+ "MasterUserPassword" => 'root',
44
+ "DBInstanceClass" => 'db.t1.micro',
45
+ "AllocatedStorage" => '10'
46
+ }
47
+ }
48
+ }
49
+ }
50
+ hash.should == template
51
+ end
52
+ end
53
+ 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.3.0
4
+ version: 2.4.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-30 00:00:00.000000000 Z
12
+ date: 2012-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -145,9 +145,11 @@ files:
145
145
  - lib/cloudster/ec2.rb
146
146
  - lib/cloudster/elb.rb
147
147
  - lib/cloudster/options_manager.rb
148
+ - lib/cloudster/rds.rb
148
149
  - spec/cloud_spec.rb
149
150
  - spec/ec2_spec.rb
150
151
  - spec/elb_spec.rb
152
+ - spec/rds_spec.rb
151
153
  - spec/spec_helper.rb
152
154
  homepage: http://github.com/emilsoman/cloudster
153
155
  licenses:
@@ -164,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
166
  version: '0'
165
167
  segments:
166
168
  - 0
167
- hash: -954846317
169
+ hash: -380344941
168
170
  required_rubygems_version: !ruby/object:Gem::Requirement
169
171
  none: false
170
172
  requirements: