Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added DataCenter#provisioned? method

  • Loading branch information...
commit aaf5a58e62d9d75e833d3c90b13c52656cccefc2 1 parent 1cdc956
Dominik Sander authored January 21, 2013
2  lib/profitbricks.rb
@@ -13,7 +13,7 @@
13 13
 require 'profitbricks/rule'
14 14
 
15 15
 module Profitbricks
16  
-  VERSION = '0.9.2'
  16
+  VERSION = '0.9.3'
17 17
 end
18 18
 
19 19
 PB = Profitbricks
19  lib/profitbricks/data_center.rb
@@ -52,13 +52,24 @@ def create_server(options)
52 52
       Server.create(options.merge(:data_center_id => self.id))
53 53
     end
54 54
 
55  
-    def wait_for_provisioning
  55
+    # Checks if the Data Center is successfully provisioned
  56
+    #
  57
+    # @return [Boolean] true if the Data Center is provisioned
  58
+    def provisioned?
56 59
       self.update_state
57  
-      while @provisioning_state != 'AVAILABLE'
58  
-        self.update_state
  60
+      if @provisioning_state == 'AVAILABLE'
  61
+        self.reload
  62
+        true
  63
+      else
  64
+        false
  65
+      end
  66
+    end
  67
+
  68
+    # Blocks until the Data Center is provisioned
  69
+    def wait_for_provisioning
  70
+      while !self.provisioned?
59 71
         sleep 1
60 72
       end
61  
-      self.reload
62 73
     end
63 74
 
64 75
     class << self
8  spec/profitbricks/data_center_spec.rb
@@ -54,6 +54,14 @@
54 54
     dc.provisioning_state.should == 'AVAILABLE'
55 55
   end
56 56
 
  57
+  it "should return true on provisioned?" do
  58
+    savon.expects(:get_data_center).returns(:two_servers_with_storage)
  59
+    dc = Profitbricks::DataCenter.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")
  60
+    savon.expects(:get_data_center_state).returns(:success)
  61
+    savon.expects(:get_data_center).returns(:two_servers_with_storage)
  62
+    dc.provisioned?.should == true
  63
+  end
  64
+  
57 65
   it "should wait for provisioning to finish" do
58 66
     savon.expects(:get_data_center).returns(:two_servers_with_storage)
59 67
     dc = Profitbricks::DataCenter.find(:id => "b3eebede-5c78-417c-b1bc-ff5de01a0602")

0 notes on commit aaf5a58

Please sign in to comment.
Something went wrong with that request. Please try again.