auser-poolparty 0.2.62 → 0.2.63

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/Manifest.txt CHANGED
@@ -224,6 +224,7 @@ lib/poolparty/monitors/monitors/web_monitor.rb
224
224
  lib/poolparty/net/messenger.rb
225
225
  lib/poolparty/net/remote.rb
226
226
  lib/poolparty/net/remote_bases/ec2.rb
227
+ lib/poolparty/net/remote_bases/ec2/ec2_response_object.rb
227
228
  lib/poolparty/net/remote_instance.rb
228
229
  lib/poolparty/net/remoter.rb
229
230
  lib/poolparty/net/remoter_base.rb
data/README.txt CHANGED
@@ -43,6 +43,7 @@ sudo gem install auser-poolparty
43
43
  * Refactor provisioning to use erlang
44
44
  * Move the building of the resource tree on read to on resolve
45
45
  * Add queuing of tasks on the messenger
46
+ * Add security group as listing
46
47
 
47
48
  == LICENSE:
48
49
 
data/bin/cloud-provision CHANGED
@@ -24,9 +24,7 @@ o.loaded_clouds.each do |cloud|
24
24
  Provisioner.provision_slaves(self, testing)
25
25
  else
26
26
  vputs "Provisioning master"
27
- provisioning_in_progress
28
- verbose ? Provisioner.provision_master(self, testing) : hide_output { Provisioner.provision_master(self, testing) }
29
- provisioning_complete
27
+ (verbose || testing) ? Provisioner.provision_master(self, testing) : hide_output { Provisioner.provision_master(self, testing) }
30
28
  end
31
29
  end
32
30
 
data/bin/cloud-start CHANGED
@@ -9,7 +9,7 @@ end
9
9
 
10
10
  o.loaded_clouds.each do |cloud|
11
11
  with_cloud(cloud) do
12
- vputs header("Starting cloud")
12
+ vputs header("Starting cloud #{name}")
13
13
  vputs "#{list_of_running_instances.size} running instances (#{minimum_instances} - #{maximum_instances})"
14
14
  if list_of_running_instances.size <= 1
15
15
  puts "Starting the master instance"
@@ -2,10 +2,10 @@ module PoolParty
2
2
  module Provisioner
3
3
  class Master < ProvisionerBase
4
4
 
5
- def initialize(cloud=self, os=:ubuntu)
6
- raise MasterException.new(:no_ip) unless cloud.master && cloud.master.ip
7
- super(cloud.master, cloud, os)
8
- @master_ip = cloud.master.ip
5
+ def initialize(cl=self, os=:ubuntu)
6
+ raise MasterException.new(:no_ip) unless cl.master && cl.master.ip
7
+ super(cl.master, cl, os)
8
+ @master_ip = cl.master.ip
9
9
  end
10
10
 
11
11
  def valid?
@@ -133,12 +133,10 @@ wget http://github.com/auser/poolparty/tree/master%2Fpkg%2Fpoolparty.gem?raw=tru
133
133
  def restart_puppetmaster
134
134
  <<-EOS
135
135
  echo "(Re)starting poolparty"
136
- # . /etc/profile
136
+ . /etc/profile
137
137
  # /etc/init.d/puppetmaster stop #{unix_hide_string}
138
- # ps aux | grep puppetmaster | awk '{print $2}' | xargs kill #{unix_hide_string} # just in case
139
- # rm -rf /etc/puppet/ssl
138
+ ps aux | grep puppetmaster | awk '{print $2}' | xargs kill;rm -rf /etc/puppet/ssl;puppetmasterd --verbose
140
139
  # # Start it back up
141
- # # puppetmasterd --verbose
142
140
  /etc/init.d/puppetmaster start
143
141
  EOS
144
142
  end
@@ -0,0 +1,52 @@
1
+ class EC2ResponseObject
2
+ def self.get_descriptions(resp)
3
+ rs = get_response_from(resp)
4
+
5
+ # puts rs.methods.sort - rs.ancestors.methods
6
+ out = begin
7
+ if rs.respond_to?(:instancesSet)
8
+ [EC2ResponseObject.get_hash_from_response(rs.instancesSet.item)]
9
+ else
10
+ rs.collect {|r|
11
+ if r.instancesSet.item.class == Array
12
+ r.instancesSet.item.map {|t| EC2ResponseObject.get_hash_from_response(t)}
13
+ else
14
+ [EC2ResponseObject.get_hash_from_response(r.instancesSet.item)]
15
+ end
16
+ }.flatten.reject {|a| a.nil? }
17
+ end
18
+ rescue Exception => e
19
+ # Really weird bug with amazon's ec2 gem
20
+ rs.collect {|r| EC2ResponseObject.get_hash_from_response(r)}.reject {|a| a.nil? } rescue []
21
+ end
22
+
23
+ out
24
+ end
25
+ def self.get_response_from(resp)
26
+ begin
27
+ rs = resp.reservationSet.item unless resp.reservationSet.nil?
28
+ rs ||= resp.DescribeInstancesResponse.reservationSet.item
29
+ rs ||= rs.respond_to?(:instancesSet) ? rs.instancesSet : rs
30
+ rs.reject! {|a| a.nil? || a.empty? }
31
+ rescue Exception => e
32
+ resp
33
+ end
34
+ rs
35
+ end
36
+ def self.get_hash_from_response(resp)
37
+ begin
38
+ {
39
+ :instance_id => resp.instanceId,
40
+ :name => resp.instanceId,
41
+ :ip => resp.dnsName || "not-assigned",
42
+ :status => resp.instanceState.name,
43
+ :launching_time => resp.launchTime.parse_datetime,
44
+ :internal_ip => resp.privateDnsName,
45
+ :keypair => resp.keyName
46
+ # :security_group => resp.groupSet.item[0].groupId
47
+ }
48
+ rescue Exception => e
49
+ nil
50
+ end
51
+ end
52
+ end
@@ -1,6 +1,9 @@
1
+ require "date"
2
+ require "#{::File.dirname(__FILE__)}/ec2/ec2_response_object"
3
+
1
4
  begin
2
5
  require 'EC2'
3
- require "date"
6
+
4
7
  class String
5
8
  def convert_from_ec2_to_ip
6
9
  self.gsub(/.compute-1.amazonaws.com*/, '').gsub(/ec2-/, '').gsub(/-/, '.')
@@ -21,7 +24,8 @@ begin
21
24
  :maxCount => num,
22
25
  :key_name => (keypair || Base.keypair),
23
26
  :availability_zone => nil,
24
- :size => "#{size || Base.size}")
27
+ :size => "#{size || Base.size}",
28
+ :group_id => ["#{security_group || 'default'}"])
25
29
  begin
26
30
  h = EC2ResponseObject.get_hash_from_response(instance)
27
31
  h = instance.instancesSet.item.first
@@ -85,6 +89,13 @@ begin
85
89
  Kernel.system "ec2-add-keypair #{keypair} > #{new_keypair_path} && chmod 600 #{new_keypair_path}"
86
90
  end
87
91
  end
92
+
93
+ # wrapper for remote base to perform a snapshot backup for the ebs volume
94
+ def create_snapshot
95
+ return nil if ebs_volume_id.nil?
96
+ ec2.create_snapshot(:volume_id => ebs_volume_id)
97
+ end
98
+
88
99
  # EC2 connections
89
100
  def ec2
90
101
  @ec2 ||= EC2::Base.new( :access_key_id => (access_key || Base.access_key),
@@ -117,59 +128,6 @@ begin
117
128
  end
118
129
  register_remote_base :Ec2
119
130
  end
120
-
121
- # Provides a simple class to wrap around the amazon responses
122
- class EC2ResponseObject
123
- def self.get_descriptions(resp)
124
- rs = get_response_from(resp)
125
-
126
- # puts rs.methods.sort - rs.ancestors.methods
127
- out = begin
128
- if rs.respond_to?(:instancesSet)
129
- [EC2ResponseObject.get_hash_from_response(rs.instancesSet.item)]
130
- else
131
- rs.collect {|r|
132
- if r.instancesSet.item.class == Array
133
- r.instancesSet.item.map {|t| EC2ResponseObject.get_hash_from_response(t)}
134
- else
135
- [EC2ResponseObject.get_hash_from_response(r.instancesSet.item)]
136
- end
137
- }.flatten.reject {|a| a.nil? }
138
- end
139
- rescue Exception => e
140
- # Really weird bug with amazon's ec2 gem
141
- rs.collect {|r| EC2ResponseObject.get_hash_from_response(r)}.reject {|a| a.nil? } rescue []
142
- end
143
-
144
- out
145
- end
146
- def self.get_response_from(resp)
147
- begin
148
- rs = resp.reservationSet.item unless resp.reservationSet.nil?
149
- rs ||= resp.DescribeInstancesResponse.reservationSet.item
150
- rs ||= rs.respond_to?(:instancesSet) ? rs.instancesSet : rs
151
- rs.reject! {|a| a.nil? || a.empty? }
152
- rescue Exception => e
153
- resp
154
- end
155
- rs
156
- end
157
- def self.get_hash_from_response(resp)
158
- begin
159
- {
160
- :instance_id => resp.instanceId,
161
- :name => resp.instanceId,
162
- :ip => resp.dnsName || "not-assigned",
163
- :status => resp.instanceState.name,
164
- :launching_time => resp.launchTime.parse_datetime,
165
- :internal_ip => resp.privateDnsName,
166
- :keypair => resp.keyName
167
- }
168
- rescue Exception => e
169
- nil
170
- end
171
- end
172
- end
173
131
  rescue LoadError
174
132
  puts <<-EOM
175
133
  Error: In order to use ec2, you need to install the amazon-ec2 gem
@@ -28,7 +28,8 @@ module PoolParty
28
28
  # EC2 Options
29
29
  :ami => "ami-1cd73375",
30
30
  # Options that should not be touched pretty much ever
31
- :manifest_path => "/etc/puppet/manifests"
31
+ :manifest_path => "/etc/puppet/manifests",
32
+ :security_group => ["default"]
32
33
  })
33
34
 
34
35
  # Class methods
@@ -172,7 +172,7 @@ module PoolParty
172
172
  # to be saved on the remote "master" machine
173
173
  def minimum_runnable_options
174
174
  [
175
- :keypair, :minimum_instances, :maximum_instances, :ami,
175
+ :keypair, :minimum_instances, :maximum_instances, :ami, :security_group,
176
176
  :expand_when, :contract_when, :set_master_ip_to
177
177
  ]
178
178
  end
@@ -2,7 +2,7 @@ module PoolParty
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 62
5
+ TINY = 63
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/poolparty.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poolparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.62
4
+ version: 0.2.63
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Lerner
@@ -334,6 +334,7 @@ files:
334
334
  - lib/poolparty/net/messenger.rb
335
335
  - lib/poolparty/net/remote.rb
336
336
  - lib/poolparty/net/remote_bases/ec2.rb
337
+ - lib/poolparty/net/remote_bases/ec2/ec2_response_object.rb
337
338
  - lib/poolparty/net/remote_instance.rb
338
339
  - lib/poolparty/net/remoter.rb
339
340
  - lib/poolparty/net/remoter_base.rb
@@ -6,6 +6,7 @@ class TestClass
6
6
  include PoolParty::Remote::RemoterBase
7
7
  include Ec2
8
8
  include CloudResourcer
9
+ include CloudDsl
9
10
 
10
11
  def keypair
11
12
  "fake_keypair"
@@ -27,7 +28,7 @@ describe "ec2 remote base" do
27
28
  stub_remoter_for(@tr)
28
29
  @tr.stub!(:get_instances_description).and_return response_list_of_instances
29
30
  end
30
- %w(launch_new_instance! terminate_instance! describe_instance describe_instances).each do |method|
31
+ %w(launch_new_instance! terminate_instance! describe_instance describe_instances create_snapshot).each do |method|
31
32
  eval <<-EOE
32
33
  it "should have the method #{method}" do
33
34
  @tr.respond_to?(:#{method}).should == true
@@ -56,6 +57,15 @@ describe "ec2 remote base" do
56
57
  @tr.ec2.should_receive(:run_instances).and_return true
57
58
  @tr.launch_new_instance!
58
59
  end
60
+ it "should use a specific security group if one is specified" do
61
+ @tr.stub!(:security_group).and_return "web"
62
+ @tr.ec2.should_receive(:run_instances).with(hash_including(:group_id => ['web'])).and_return true
63
+ @tr.launch_new_instance!
64
+ end
65
+ it "should use the default security group if none is specified" do
66
+ @tr.ec2.should_receive(:run_instances).with(hash_including(:group_id => ['default'])).and_return true
67
+ @tr.launch_new_instance!
68
+ end
59
69
  it "should get the hash response from EC2ResponseObject" do
60
70
  EC2ResponseObject.should_receive(:get_hash_from_response).and_return true
61
71
  @tr.launch_new_instance!
@@ -106,4 +116,18 @@ describe "ec2 remote base" do
106
116
  @tr.create_keypair
107
117
  end
108
118
  end
119
+ describe "create_snapshot" do
120
+ # We can assume that create_snapshot on the ec2 gem works
121
+ before(:each) do
122
+ @tr.ec2.stub!(:create_snapshot).and_return nil
123
+ end
124
+ it "should create a snapshot of the current EBS volume" do
125
+ @tr.ec2.stub!(:create_snapshot).and_return {{"snapshotId" => "snap-123"}}
126
+ @tr.stub!(:ebs_volume_id).and_return "vol-123"
127
+ @tr.create_snapshot.should == {"snapshotId" => "snap-123"}
128
+ end
129
+ it "should not create a snapshot if there is no EBS volume" do
130
+ @tr.create_snapshot.should == nil
131
+ end
132
+ end
109
133
  end
@@ -49,6 +49,7 @@ describe "Script" do
49
49
  ami "ami-123456"
50
50
 
51
51
  cloud :app do
52
+ security_group "app"
52
53
  expand_when "cpu > 90", "memory > 80"
53
54
  contract_when "cpu < 10", "memory < 10"
54
55
 
@@ -63,6 +64,9 @@ describe "Script" do
63
64
  it "should save the ami" do
64
65
  @saved.should =~ /ami 'ami-123456'/
65
66
  end
67
+ it "should save the security group" do
68
+ @saved.should =~ /security_group 'app'/
69
+ end
66
70
  it "should save the expansions" do
67
71
  @saved.should =~ /expand_when 'cpu>90', 'memory>80'/
68
72
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auser-poolparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.62
4
+ version: 0.2.63
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ari Lerner
@@ -334,6 +334,7 @@ files:
334
334
  - lib/poolparty/net/messenger.rb
335
335
  - lib/poolparty/net/remote.rb
336
336
  - lib/poolparty/net/remote_bases/ec2.rb
337
+ - lib/poolparty/net/remote_bases/ec2/ec2_response_object.rb
337
338
  - lib/poolparty/net/remote_instance.rb
338
339
  - lib/poolparty/net/remoter.rb
339
340
  - lib/poolparty/net/remoter_base.rb