Class: Profitbricks::Storage
Class Method Summary collapse
-
.create(options = {}) ⇒ Storage
Creates a virtual storage within an existing virtual data center.
-
.find(options = {}) ⇒ Storage
Finds a storage device.
Instance Method Summary collapse
-
#connect(options = {}) ⇒ Boolean
Connects a virtual storage device to an existing server.
-
#delete ⇒ Boolean
Deletes an existing virtual storage device.
-
#disconnect(options = {}) ⇒ Boolean
Disconnects a virtual storage device from a connected server.
-
#update(options = {}) ⇒ Boolean
Updates parameters of an existing virtual storage device.
Methods inherited from Model
#attributes, belongs_to, get_xml_and_update_attributes, #get_xml_and_update_attributes, has_many, #initialize, #reload
Constructor Details
This class inherits a constructor from Profitbricks::Model
Class Method Details
.create(options = {}) ⇒ Storage
Creates a virtual storage within an existing virtual data center. Additional parameters can be specified, e.g. for assigning a HDD image to the storage.
63 64 65 66 67 68 69 70 |
# File 'lib/profitbricks/storage.rb', line 63 def create( = {}) raise ArgumentError.new("You must provide a :data_center_id") if [:data_center_id].nil? xml = "<arg0>" xml += get_xml_and_update_attributes , [:data_center_id, :name, :size, :mount_image_id] xml += "</arg0>" response = Profitbricks.request :create_storage, xml self.find(:id => response.to_hash[:create_storage_return][:return][:storage_id]) end |
.find(options = {}) ⇒ Storage
Finds a storage device
77 78 79 80 81 |
# File 'lib/profitbricks/storage.rb', line 77 def find( = {}) raise "Unable to locate the storage named '#{[:name]}'" unless [:id] response = Profitbricks.request :get_storage, "<storageId>#{[:id]}</storageId>" Profitbricks::Storage.new(response.to_hash[:get_storage_response][:return]) end |
Instance Method Details
#connect(options = {}) ⇒ Boolean
Connects a virtual storage device to an existing server.
19 20 21 22 23 24 25 |
# File 'lib/profitbricks/storage.rb', line 19 def connect( = {}) xml = "<arg0>" xml += get_xml_and_update_attributes .merge(:storage_id => self.id), [:server_id, :storage_id, :bus_type, :device_number] xml += "</arg0>" response = Profitbricks.request :connect_storage_to_server, xml return true if response.to_hash[:connect_storage_to_server_response][:return] end |
#delete ⇒ Boolean
Deletes an existing virtual storage device.
7 8 9 10 |
# File 'lib/profitbricks/storage.rb', line 7 def delete response = Profitbricks.request :delete_storage, "<storageId>#{self.id}</storageId>" return true if response.to_hash[:delete_storage_response][:return] end |
#disconnect(options = {}) ⇒ Boolean
Disconnects a virtual storage device from a connected server.
32 33 34 35 36 |
# File 'lib/profitbricks/storage.rb', line 32 def disconnect( = {}) response = Profitbricks.request :disconnect_storage_from_server, "<storageId>#{self.id}</storageId><serverId>#{[:server_id]}</serverId>" return true if response.to_hash[:disconnect_storage_from_server_response][:return] end |
#update(options = {}) ⇒ Boolean
Updates parameters of an existing virtual storage device.
45 46 47 48 49 50 51 |
# File 'lib/profitbricks/storage.rb', line 45 def update( = {}) xml = "<arg0>" xml += get_xml_and_update_attributes .merge(:storage_id => self.id), [:storage_id, :name, :size, :mount_image_id] xml += "</arg0>" response = Profitbricks.request :update_storage, xml return true if response.to_hash[:update_storage_response][:return] end |