Class: Profitbricks::DataCenter
- Inherits:
-
Model
- Object
- Model
- Profitbricks::DataCenter
- Defined in:
- lib/profitbricks/data_center.rb
Class Method Summary (collapse)
-
+ (Array <DataCenter>) all
Returns a list of all Virtual Data Centers created by the user, including ID, name and version number.
-
+ (DataCenter) create(options)
Creates and saves a new, empty Virtual Data Center.
-
+ (Object) find(options = {})
Finds a Virtual Data Center.
Instance Method Summary (collapse)
-
- (Object) clear
Removes all components from the current Virtual Data Center.
-
- (Object) create_load_balancer(options)
Creates a Load Balancer in the current Virtual Data Center, automatically sets the :data_center_id.
-
- (Object) create_server(options)
Creates a Server in the current Virtual Data Center, automatically sets the :data_center_id.
-
- (Object) create_storage(options)
Creates a Storage in the current Virtual Data Center, automatically sets the :data_center_id.
-
- (Boolean) delete
Deletes an empty Virtual Data Center.
-
- (Boolean) provisioned?
Checks if the Data Center was successfully provisioned.
-
- (DataCenter) rename(name)
(also: #name=)
Renames the Virtual Data Center.
-
- (String) update_state
This is a lightweight function for pooling the current provisioning state of the Virtual Data Center.
-
- (Object) wait_for_provisioning
Blocks until the Data Center is provisioned.
Methods inherited from Model
#attributes, belongs_to, has_many, #initialize, #reload
Constructor Details
This class inherits a constructor from Profitbricks::Model
Class Method Details
+ (Array <DataCenter>) all
Returns a list of all Virtual Data Centers created by the user, including ID, name and version number.
90 91 92 93 94 95 |
# File 'lib/profitbricks/data_center.rb', line 90 def all resp = Profitbricks.request :get_all_data_centers [resp].flatten.compact.collect do |dc| PB::DataCenter.find(:id => PB::DataCenter.new(dc).id) end end |
+ (DataCenter) create(options)
Creates and saves a new, empty Virtual Data Center.
103 104 105 106 107 108 |
# File 'lib/profitbricks/data_center.rb', line 103 def create() raise ArgumentError.new(":region has to be one of 'DEFAULT', 'NORTH_AMERICA', or 'EUROPE'") if [:region] and !['DEFAULT', 'EUROPE', 'NORTH_AMERICA'].include? [:region] [:data_center_name] = .delete :name response = Profitbricks.request :create_data_center, self.find(:id => response[:data_center_id] ) end |
+ (Object) find(options = {})
Finds a Virtual Data Center
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/profitbricks/data_center.rb', line 114 def find( = {}) if [:name] dc = PB::DataCenter.all().select { |d| d.name == [:name] }.first [:id] = dc.id if dc end raise "Unable to locate the datacenter named '#{[:name]}'" unless [:id] [:data_center_id] = .delete :id .delete :name response = Profitbricks.request :get_data_center, PB::DataCenter.new(response) end |
Instance Method Details
- (Object) clear
Removes all components from the current Virtual Data Center.
16 17 18 19 20 21 22 |
# File 'lib/profitbricks/data_center.rb', line 16 def clear response = Profitbricks.request :clear_data_center, data_center_id: self.id @provisioning_state = nil @servers = [] @storages = [] return self if response end |
- (Object) create_load_balancer(options)
Creates a Load Balancer in the current Virtual Data Center, automatically sets the :data_center_id
62 63 64 |
# File 'lib/profitbricks/data_center.rb', line 62 def create_load_balancer() LoadBalancer.create(.merge(data_center_id: self.id)) end |
- (Object) create_server(options)
Creates a Server in the current Virtual Data Center, automatically sets the :data_center_id
50 51 52 |
# File 'lib/profitbricks/data_center.rb', line 50 def create_server() Server.create(.merge(data_center_id: self.id)) end |
- (Object) create_storage(options)
Creates a Storage in the current Virtual Data Center, automatically sets the :data_center_id
56 57 58 |
# File 'lib/profitbricks/data_center.rb', line 56 def create_storage() Storage.create(.merge(data_center_id: self.id)) end |
- (Boolean) delete
Deletes an empty Virtual Data Center. All components must be removed first.
9 10 11 12 |
# File 'lib/profitbricks/data_center.rb', line 9 def delete response = Profitbricks.request :delete_data_center, data_center_id: self.id response ? true : false end |
- (Boolean) provisioned?
Checks if the Data Center was successfully provisioned
69 70 71 72 73 74 75 76 77 |
# File 'lib/profitbricks/data_center.rb', line 69 def provisioned? self.update_state if @provisioning_state == 'AVAILABLE' self.reload true else false end end |
- (DataCenter) rename(name) Also known as: name=
Renames the Virtual Data Center.
28 29 30 31 32 33 34 |
# File 'lib/profitbricks/data_center.rb', line 28 def rename(name) response = Profitbricks.request :update_data_center, data_center_id: self.id, data_center_name: name if response @name = name end self end |
- (String) update_state
This is a lightweight function for pooling the current provisioning state of the Virtual Data Center. It is recommended to use this function for large Virtual Data Centers to query request results.
42 43 44 45 46 |
# File 'lib/profitbricks/data_center.rb', line 42 def update_state response = Profitbricks.request :get_data_center_state, data_center_id: self.id @provisioning_state = response self.provisioning_state end |
- (Object) wait_for_provisioning
Blocks until the Data Center is provisioned
80 81 82 83 84 |
# File 'lib/profitbricks/data_center.rb', line 80 def wait_for_provisioning while !self.provisioned? sleep Profitbricks::Config.polling_interval end end |