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, 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.
61 62 63 64 65 66 |
# File 'lib/profitbricks/storage.rb', line 61 def create( = {}) raise ArgumentError.new("You must provide a :data_center_id") if [:data_center_id].nil? [:storage_name] = .delete :name if [:name] response = Profitbricks.request :create_storage, self.find(:id => response[:storage_id]) end |
.find(options = {}) ⇒ Storage
Finds a storage device
73 74 75 76 77 |
# File 'lib/profitbricks/storage.rb', line 73 def find( = {}) raise "Unable to locate the storage named '#{[:name]}'" unless [:id] response = Profitbricks.request :get_storage, storage_id: [:id] Profitbricks::Storage.new(response) end |
Instance Method Details
#connect(options = {}) ⇒ Boolean
Connects a virtual storage device to an existing server.
19 20 21 22 23 24 |
# File 'lib/profitbricks/storage.rb', line 19 def connect( = {}) raise ArgumentError.new(":bus_type has to be either 'IDE' or 'VIRTIO'") if [:bus_type] and !['IDE', 'VIRTIO'].include? [:bus_type] response = Profitbricks.request :connect_storage_to_server, .merge(:storage_id => self.id) update_attributes_from_hash return true end |
#delete ⇒ Boolean
Deletes an existing virtual storage device.
7 8 9 10 |
# File 'lib/profitbricks/storage.rb', line 7 def delete Profitbricks.request :delete_storage, storage_id: self.id return true end |
#disconnect(options = {}) ⇒ Boolean
Disconnects a virtual storage device from a connected server.
31 32 33 34 |
# File 'lib/profitbricks/storage.rb', line 31 def disconnect( = {}) Profitbricks.request :disconnect_storage_from_server, storage_id: self.id, server_id: [:server_id] return true end |
#update(options = {}) ⇒ Boolean
Updates parameters of an existing virtual storage device.
43 44 45 46 47 48 |
# File 'lib/profitbricks/storage.rb', line 43 def update( = {}) update_attributes_from_hash [:storage_name] = .delete :name if [:name] Profitbricks.request :update_storage, .merge(:storage_id => self.id) return true end |