cloudster 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -6
- data/VERSION +1 -1
- data/cloudster.gemspec +1 -1
- data/lib/cloudster/cloud.rb +60 -25
- data/lib/cloudster/ec2.rb +0 -1
- data/spec/cloud_spec.rb +11 -11
- metadata +2 -2
data/README.md
CHANGED
@@ -25,7 +25,8 @@ Create AWS EC2 resources as shown here:
|
|
25
25
|
|
26
26
|
Create a stack out of the resources :
|
27
27
|
|
28
|
-
stack = Cloudster::Cloud.new(:
|
28
|
+
stack = Cloudster::Cloud.new(:access_key_id => 'accesskeyid',
|
29
|
+
:secret_access_key => 'topsecretaccesskey')
|
29
30
|
Now you can do stuff like :
|
30
31
|
|
31
32
|
- Get the CloudFormation template for a resource in Ruby Hash :
|
@@ -33,16 +34,13 @@ Now you can do stuff like :
|
|
33
34
|
app_server.template
|
34
35
|
- Get the CloudFormation template for the stack :
|
35
36
|
|
36
|
-
stack.template(:description => 'Description of the stack')
|
37
|
+
stack.template(:resources => [app_server, app_server_2], :description => 'Description of the stack')
|
37
38
|
|
38
39
|
And most importantly :
|
39
40
|
|
40
41
|
- Provision the stack :
|
41
42
|
|
42
|
-
stack.provision(:stack_name => '
|
43
|
-
:access_key_id => 'accesskeyid',
|
44
|
-
:secret_access_key => 'topsecretaccesskey')
|
45
|
-
|
43
|
+
stack.provision(:resources => [app_server, app_server_2], :stack_name => 'TestStack', :description => 'Description of the stack')
|
46
44
|
|
47
45
|
|
48
46
|
##License
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
1.0.0
|
data/cloudster.gemspec
CHANGED
data/lib/cloudster/cloud.rb
CHANGED
@@ -5,41 +5,52 @@ module Cloudster
|
|
5
5
|
# Initialize a Cloud instance
|
6
6
|
#
|
7
7
|
# ==== Notes
|
8
|
-
# options parameter must include values for :
|
8
|
+
# options parameter must include values for :access_key_id and
|
9
|
+
# :secret_access_key in order to create a connection
|
10
|
+
#
|
11
|
+
# ==== Parameters
|
12
|
+
# * options<~Hash>
|
13
|
+
# * :access_key_id : A string containing the AWS access key ID.
|
14
|
+
# * :secret_access_key : A string containing the AWS secret access key.
|
9
15
|
#
|
10
16
|
# ==== Examples
|
11
17
|
# cloud = Cloudster::Cloud.new(
|
12
|
-
# :
|
13
|
-
#
|
14
|
-
# ]
|
18
|
+
# :access_key_id => 'aws_access_key_id'
|
19
|
+
# :secret_access_key => 'aws_secret_access_key',
|
15
20
|
# )
|
16
|
-
#
|
17
|
-
# ==== Parameters
|
18
|
-
# * options<~Hash> - :resources : An array of Cloudster resource instances. Defaults to {}.
|
19
21
|
def initialize(options = {})
|
20
|
-
require_options(options, [:
|
21
|
-
|
22
|
+
require_options(options, [:access_key_id, :secret_access_key])
|
23
|
+
access_key_id = options[:access_key_id]
|
24
|
+
secret_access_key = options[:secret_access_key]
|
25
|
+
@cloud_formation = Fog::AWS::CloudFormation.new(:aws_access_key_id => access_key_id, :aws_secret_access_key => secret_access_key)
|
22
26
|
end
|
23
27
|
|
24
28
|
# Generates CloudFormation Template for the stack
|
25
29
|
#
|
26
30
|
# ==== Examples
|
27
31
|
# cloud = Cloudster::Cloud.new(
|
28
|
-
# :
|
29
|
-
#
|
30
|
-
# ]
|
32
|
+
# :access_key_id => 'aws_access_key_id'
|
33
|
+
# :secret_access_key => 'aws_secret_access_key',
|
31
34
|
# )
|
32
|
-
#
|
35
|
+
#
|
36
|
+
# cloud.template(:resources => [<AWS RESOURCES ARRAY>], :description => 'This is the description for the stack template')
|
37
|
+
#
|
38
|
+
# ==== Notes
|
39
|
+
# options parameter must include values for :resources
|
33
40
|
#
|
34
41
|
# ==== Parameters
|
35
|
-
# * options<~Hash> -
|
42
|
+
# * options<~Hash> -
|
43
|
+
# * :resources : An array of Cloudster resource instances. Defaults to {}.
|
44
|
+
# * :description : A string which will be used as the Description of the CloudFormation template.
|
36
45
|
#
|
37
46
|
# ==== Returns
|
38
47
|
# * JSON cloud formation template
|
39
48
|
def template(options = {})
|
49
|
+
require_options(options, [:resources])
|
50
|
+
resources = options[:resources]
|
40
51
|
description = options[:description] || 'This stack is created by Cloudster'
|
41
52
|
resource_template = {}
|
42
|
-
|
53
|
+
resources.each do |resource|
|
43
54
|
resource_template.merge!(resource.template['Resources'])
|
44
55
|
end
|
45
56
|
|
@@ -54,27 +65,51 @@ module Cloudster
|
|
54
65
|
#
|
55
66
|
# ==== Examples
|
56
67
|
# cloud = Cloudster::Cloud.new(
|
57
|
-
# :
|
58
|
-
#
|
59
|
-
# ]
|
68
|
+
# :access_key_id => 'aws_access_key_id'
|
69
|
+
# :secret_access_key => 'aws_secret_access_key',
|
60
70
|
# )
|
61
|
-
#
|
71
|
+
#
|
72
|
+
# cloud.provision(:resources => [<AWS RESOURCES ARRRAY>],
|
73
|
+
# :stack_name => 'Shitty Stack',
|
74
|
+
# :description => 'This is the description for the stack template')
|
62
75
|
#
|
63
76
|
# ==== Notes
|
64
|
-
# options parameter must include values for :
|
65
|
-
# :secret_access_key in order to create a connection
|
77
|
+
# options parameter must include values for :resources and :stack_name
|
66
78
|
#
|
67
79
|
# ==== Parameters
|
68
|
-
# * options<~Hash>
|
80
|
+
# * options<~Hash>
|
81
|
+
# * :resources : An array of Cloudster resource instances. Defaults to {}.
|
82
|
+
# * :stack_name : A string which will be used to name the CloudFormation stack.
|
83
|
+
# * :description : A string which will be used as the Description of the CloudFormation template.
|
69
84
|
#
|
70
85
|
# ==== Returns
|
71
86
|
# * response<~Excon::Response>:
|
72
87
|
# * body<~Hash>:
|
73
88
|
# * 'StackId'<~String> - Id of the new stack
|
74
89
|
def provision(options = {})
|
75
|
-
require_options(options, [:
|
76
|
-
cloud_formation
|
77
|
-
|
90
|
+
require_options(options, [:resources, :stack_name])
|
91
|
+
return @cloud_formation.create_stack(options[:stack_name], 'TemplateBody' => template(:resources => options[:resources],
|
92
|
+
:description => options[:description]))
|
93
|
+
end
|
94
|
+
|
95
|
+
# Get events related to a stack
|
96
|
+
#
|
97
|
+
# ==== Examples
|
98
|
+
# cloud = Cloudster::Cloud.new(
|
99
|
+
# :access_key_id => 'aws_access_key_id'
|
100
|
+
# :secret_access_key => 'aws_secret_access_key',
|
101
|
+
# )
|
102
|
+
# cloud.events(:stack_name => 'ShittyStack')
|
103
|
+
#
|
104
|
+
# ==== Parameters
|
105
|
+
# * options<~Hash>
|
106
|
+
# * :stack_name : A string which will contain the name of the stack for which the events will be fetched.
|
107
|
+
#
|
108
|
+
# ==== Returns
|
109
|
+
# * response<~Excon::Response>:
|
110
|
+
# * body<~Hash>:
|
111
|
+
def self.events(options = {})
|
112
|
+
return @cloud_formation.describe_stack_events(options[:stack_name])
|
78
113
|
end
|
79
114
|
|
80
115
|
end
|
data/lib/cloudster/ec2.rb
CHANGED
@@ -16,7 +16,6 @@ module Cloudster
|
|
16
16
|
#
|
17
17
|
# ==== Parameters
|
18
18
|
# * options<~Hash> -
|
19
|
-
# *Keys:
|
20
19
|
# * :name: String containing the name for the Ec2 resource
|
21
20
|
# * :key_name: String containing the name of the keypair to be used for SSH
|
22
21
|
# * :image_id: String containing the AMI image id to be used while creating the Ec2 resource
|
data/spec/cloud_spec.rb
CHANGED
@@ -3,34 +3,34 @@ require 'spec_helper'
|
|
3
3
|
describe Cloudster::Cloud do
|
4
4
|
describe 'initialize' do
|
5
5
|
it "should raise argument error if resources not provided" do
|
6
|
-
expect { Cloudster::Cloud.new() }.to raise_error(ArgumentError, 'Missing required argument:
|
6
|
+
expect { Cloudster::Cloud.new() }.to raise_error(ArgumentError, 'Missing required argument: access_key_id,secret_access_key')
|
7
7
|
end
|
8
8
|
it "should not raise argument error if all arguments are provided" do
|
9
|
-
expect { Cloudster::Cloud.new(:
|
9
|
+
expect { Cloudster::Cloud.new(:access_key_id => 'test', :secret_access_key => 'test') }.to_not raise_error
|
10
10
|
end
|
11
11
|
end
|
12
12
|
describe '#template' 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
|
-
cloud = Cloudster::Cloud.new(:
|
17
|
-
cloud.template(:description => 'test template').should == {"AWSTemplateFormatVersion"=>"2010-09-09", "Description"=>"test template", "Resources"=>{"name"=>{"Type"=>"AWS::EC2::Instance", "Properties"=>{"KeyName"=>"testkey", "ImageId"=>"image_id"}}, "name1"=>{"Type"=>"AWS::EC2::Instance", "Properties"=>{"KeyName"=>"testkey1", "ImageId"=>"image_id1"}}}}.to_json
|
16
|
+
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", "Description"=>"test template", "Resources"=>{"name"=>{"Type"=>"AWS::EC2::Instance", "Properties"=>{"KeyName"=>"testkey", "ImageId"=>"image_id"}}, "name1"=>{"Type"=>"AWS::EC2::Instance", "Properties"=>{"KeyName"=>"testkey1", "ImageId"=>"image_id1"}}}}.to_json
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe '#provision' do
|
22
22
|
it "should raise argument error if resources not provided" do
|
23
23
|
ec2 = Cloudster::Ec2.new(:key_name => 'testkey', :image_id => 'image_id', name: 'name')
|
24
|
-
cloud = Cloudster::Cloud.new(:
|
25
|
-
expect { cloud.provision() }.to raise_error(ArgumentError, 'Missing required argument: stack_name
|
24
|
+
cloud = Cloudster::Cloud.new(:access_key_id => 'test', :secret_access_key => 'test')
|
25
|
+
expect { cloud.provision(:description => 'test') }.to raise_error(ArgumentError, 'Missing required argument: resources,stack_name' )
|
26
26
|
end
|
27
27
|
it "should create an instance of cloud formation and trigger stack creation" do
|
28
|
-
ec2 = Cloudster::Ec2.new(:key_name => 'testkey', :image_id => 'image_id', name: 'name')
|
29
|
-
cloud = Cloudster::Cloud.new(:resources => [ec2])
|
30
28
|
cloud_formation = double('CloudFormation')
|
31
|
-
|
32
|
-
|
33
|
-
cloud.
|
29
|
+
Fog::AWS::CloudFormation.should_receive(:new).with(:aws_access_key_id => 'test', :aws_secret_access_key => 'test').and_return cloud_formation
|
30
|
+
ec2 = Cloudster::Ec2.new(:key_name => 'testkey', :image_id => 'image_id', name: 'name')
|
31
|
+
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')
|
34
34
|
end
|
35
35
|
end
|
36
36
|
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: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -162,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
162
162
|
version: '0'
|
163
163
|
segments:
|
164
164
|
- 0
|
165
|
-
hash:
|
165
|
+
hash: 814811471
|
166
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
167
|
none: false
|
168
168
|
requirements:
|