bguthrie-awsymandias 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -45,7 +45,9 @@ This should allow you to re-launch and deploy that AWS stack from any one of sev
45
45
 
46
46
  == Contributors
47
47
 
48
- * Paul Gross (pgross@gmail.com)
48
+ * {Paul Gross}[http://www.pgrs.net] {github}[http://github.com/pgr0ss] {email}[mailto:pgross@gmail.com]
49
+ * Rob Sweet (rob@ldg.net)
50
+ * Kris Hicks (krishicks at gmail dot com)
49
51
 
50
52
  == License
51
53
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/awsymandias.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{awsymandias}
5
- s.version = "0.2.0"
5
+ s.version = "0.2.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Brian Guthrie"]
9
- s.date = %q{2009-07-14}
9
+ s.date = %q{2009-07-15}
10
10
  s.description = %q{A library for helping you set up, track, and tear down complicated deployment configurations in Amazon EC2.}
11
11
  s.email = %q{btguthrie@gmail.com}
12
12
  s.extra_rdoc_files = [
data/lib/awsymandias.rb CHANGED
@@ -5,6 +5,7 @@ require 'aws_sdb'
5
5
  require 'money'
6
6
  require 'activesupport'
7
7
  require 'activeresource'
8
+ require 'net/telnet'
8
9
 
9
10
  module Awsymandias
10
11
  class << self
@@ -97,14 +98,6 @@ module Awsymandias
97
98
  def public_dns; dns_name; end
98
99
  def private_dns; private_dns_name; end
99
100
 
100
- def public_ip
101
- dns_to_ip(public_dns)
102
- end
103
-
104
- def private_ip
105
- dns_to_ip(private_dns)
106
- end
107
-
108
101
  def pending?
109
102
  instance_state.name == "pending"
110
103
  end
@@ -112,7 +105,11 @@ module Awsymandias
112
105
  def running?
113
106
  instance_state.name == "running"
114
107
  end
115
-
108
+
109
+ def port_open?(port)
110
+ Net::Telnet.new("Host" => public_dns, "Port" => port) && true rescue false
111
+ end
112
+
116
113
  def terminated?
117
114
  instance_state.name == "terminated"
118
115
  end
@@ -203,13 +200,6 @@ module Awsymandias
203
200
  find(instance_id)
204
201
  end
205
202
  end
206
-
207
- private
208
-
209
- def dns_to_ip(dns)
210
- match = dns.match(/(ec2|ip)-(\d+)-(\d+)-(\d+)-(\d+)/)
211
- match.captures[1..-1].join(".")
212
- end
213
203
  end
214
204
 
215
205
  # Goal:
@@ -284,6 +274,10 @@ module Awsymandias
284
274
  launched? && @instances.values.all?(&:running?)
285
275
  end
286
276
 
277
+ def port_open?(port)
278
+ @instances.values.all? { |instance| instance.port_open?(port) }
279
+ end
280
+
287
281
  def running_cost
288
282
  return Money.new(0) unless launched?
289
283
  @instances.values.sum { |instance| instance.running_cost }
@@ -327,7 +321,8 @@ module Awsymandias
327
321
  def connection(opts={})
328
322
  @connection ||= ::AwsSdb::Service.new({
329
323
  :access_key_id => Awsymandias.access_key_id || ENV['AMAZON_ACCESS_KEY_ID'],
330
- :secret_access_key => Awsymandias.secret_access_key || ENV['AMAZON_SECRET_ACCESS_KEY']
324
+ :secret_access_key => Awsymandias.secret_access_key || ENV['AMAZON_SECRET_ACCESS_KEY'],
325
+ :logger => Logger.new("/dev/null")
331
326
  }.merge(opts))
332
327
  end
333
328
 
@@ -428,13 +428,6 @@ describe Awsymandias do
428
428
  end
429
429
  end
430
430
 
431
- describe "public_ip" do
432
- it "should parse the public dns to get the public IP address" do
433
- stub_connection_with DESCRIBE_INSTANCES_SINGLE_RESULT_RUNNING_XML
434
- Awsymandias::EC2::Instance.find("i-some-instance").public_ip.should == "174.129.118.52"
435
- end
436
- end
437
-
438
431
  describe "private_dns" do
439
432
  it "should return the private dns from the xml" do
440
433
  stub_connection_with DESCRIBE_INSTANCES_SINGLE_RESULT_RUNNING_XML
@@ -442,13 +435,6 @@ describe Awsymandias do
442
435
  end
443
436
  end
444
437
 
445
- describe "private_ip" do
446
- it "should parse the private dns to get the private IP address" do
447
- stub_connection_with DESCRIBE_INSTANCES_SINGLE_RESULT_RUNNING_XML
448
- Awsymandias::EC2::Instance.find("i-some-instance").private_ip.should == "10.244.226.239"
449
- end
450
- end
451
-
452
438
  describe "running_cost" do
453
439
  it "should be zero if the instance has not yet been launched" do
454
440
  stub_connection_with DESCRIBE_INSTANCES_SINGLE_RESULT_PENDING_XML
@@ -487,6 +473,24 @@ describe Awsymandias do
487
473
  instance.running_cost.should == expected_cost
488
474
  end
489
475
  end
476
+
477
+ describe "port_open?" do
478
+ it "should return true if telnet does not raise" do
479
+ stub_connection_with DESCRIBE_INSTANCES_SINGLE_RESULT_RUNNING_XML
480
+ instance = Awsymandias::EC2::Instance.find("i-some-instance")
481
+ Net::Telnet.should_receive(:new).with("Host" => "ec2-174-129-118-52.compute-1.amazonaws.com",
482
+ "Port" => 100).and_return(true)
483
+ instance.port_open?(100).should be_true
484
+ end
485
+
486
+ it "should return false if telnet does raise" do
487
+ stub_connection_with DESCRIBE_INSTANCES_SINGLE_RESULT_RUNNING_XML
488
+ instance = Awsymandias::EC2::Instance.find("i-some-instance")
489
+ Net::Telnet.should_receive(:new).with("Host" => "ec2-174-129-118-52.compute-1.amazonaws.com",
490
+ "Port" => 100).and_raise(Timeout::Error)
491
+ instance.port_open?(100).should be_false
492
+ end
493
+ end
490
494
  end
491
495
 
492
496
  describe ApplicationStack = Awsymandias::EC2::ApplicationStack do
@@ -704,6 +708,65 @@ describe Awsymandias do
704
708
  s.should be_running
705
709
  end
706
710
  end
711
+
712
+ describe "port_open?" do
713
+ it "should return true if there is one instance with the port open" do
714
+ s = ApplicationStack.new("test") do |s|
715
+ s.role "app1", :instance_type => Awsymandias::EC2::InstanceTypes::C1_XLARGE
716
+ end
717
+
718
+ instance = stub_instance
719
+ instance.should_receive(:port_open?).with(100).and_return(true)
720
+ Instance.stub!(:launch).and_return(instance)
721
+
722
+ s.launch
723
+ s.port_open?(100).should be_true
724
+ end
725
+
726
+ it "should return false if there is one instance with the port closed" do
727
+ s = ApplicationStack.new("test") do |s|
728
+ s.role "app1", :instance_type => Awsymandias::EC2::InstanceTypes::C1_XLARGE
729
+ end
730
+
731
+ instance = stub_instance
732
+ instance.should_receive(:port_open?).with(100).and_return(false)
733
+ Instance.stub!(:launch).and_return(instance)
734
+
735
+ s.launch
736
+ s.port_open?(100).should be_false
737
+ end
738
+
739
+ it "should return true if there are multiple instances all with the port open" do
740
+ s = ApplicationStack.new("test") do |s|
741
+ s.role "app1", :instance_type => Awsymandias::EC2::InstanceTypes::C1_XLARGE
742
+ s.role "app2", :instance_type => Awsymandias::EC2::InstanceTypes::C1_XLARGE
743
+ end
744
+
745
+ instance1, instance2 = [stub_instance, stub_instance]
746
+ instance1.should_receive(:port_open?).with(100).and_return(true)
747
+ instance2.should_receive(:port_open?).with(100).and_return(true)
748
+ Instance.stub!(:launch).and_return(instance1, instance2)
749
+
750
+ s.launch
751
+ s.port_open?(100).should be_true
752
+ end
753
+
754
+ it "should return false if there are multiple instances with at least one port closed" do
755
+ s = ApplicationStack.new("test") do |s|
756
+ s.role "app1", :instance_type => Awsymandias::EC2::InstanceTypes::C1_XLARGE
757
+ s.role "app2", :instance_type => Awsymandias::EC2::InstanceTypes::C1_XLARGE
758
+ end
759
+
760
+ instance1, instance2 = [stub_instance, stub_instance]
761
+ instance1.should_receive(:port_open?).with(100).and_return(true)
762
+ instance2.should_receive(:port_open?).with(100).and_return(false)
763
+ Instance.stub!(:launch).and_return(instance1, instance2)
764
+
765
+ s.launch
766
+ s.port_open?(100).should be_false
767
+ end
768
+
769
+ end
707
770
 
708
771
  describe "terminate!" do
709
772
  it "should not do anything if not running" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bguthrie-awsymandias
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Guthrie
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-14 00:00:00 -07:00
12
+ date: 2009-07-15 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency