Class: Profitbricks::Storage

Inherits:
Model
  • Object
show all
Defined in:
lib/profitbricks/storage.rb

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • options (Hash) (defaults to: {})

    Parameters for the new Storage

Options Hash (options):

  • Storage (:size)

    size (in GiB) (required)

  • Defines (:data_center_id)

    the data center wherein the storage is to be created. If left empty, the storage will be created in a new data center

  • Name (:name)

    of the storage to be created

  • Specifies (:mount_image_id)

    the image to be assigned to the storage by its ID. Either choose a HDD or a CD-ROM/DVD (ISO) image

Returns:

  • (Storage)

    The created Storage

Raises:

  • (ArgumentError)


63
64
65
66
67
68
69
70
# File 'lib/profitbricks/storage.rb', line 63

def create(options = {})
  raise ArgumentError.new("You must provide a :data_center_id") if options[:data_center_id].nil?
  xml = "<arg0>"
  xml += get_xml_and_update_attributes options, [: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

Parameters:

  • options (Hash) (defaults to: {})

    currently just :id is supported

Options Hash (options):

  • The (String)

    id of the storage to locate

Returns:



77
78
79
80
81
# File 'lib/profitbricks/storage.rb', line 77

def find(options = {})
  raise "Unable to locate the storage named '#{options[:name]}'" unless options[:id]
  response = Profitbricks.request :get_storage, "<storageId>#{options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    Parameters to connect the Storage

Options Hash (options):

  • Identifier (:server_id)

    of the target virtual server (required)

  • Bus (:bus_type)

    type to which the storage will be connected. Type can be IDE, SCSI or VIRTIO (required)

  • Defines (:device_number)

    the device number of the virtual storage. If no device number is set, a device number will be automatically assigned

Returns:

  • (Boolean)

    true on success, false otherwise



19
20
21
22
23
24
25
# File 'lib/profitbricks/storage.rb', line 19

def connect(options = {})
  xml = "<arg0>"
  xml += get_xml_and_update_attributes options.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

#deleteBoolean

Deletes an existing virtual storage device.

Returns:

  • (Boolean)

    true on success, false otherwise



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.

Parameters:

  • options (Hash) (defaults to: {})

    Parameters to disconnect the Storage

Options Hash (options):

  • Identifier (:server_id)

    of the connected virtual server (required)

Returns:

  • (Boolean)

    true on success, false otherwise



32
33
34
35
36
# File 'lib/profitbricks/storage.rb', line 32

def disconnect(options = {})
  response = Profitbricks.request :disconnect_storage_from_server, 
                  "<storageId>#{self.id}</storageId><serverId>#{options[: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.

Parameters:

  • options (Hash) (defaults to: {})

    Parameters to update the Storage

Options Hash (options):

  • Storage (:size)

    size (in GiB)

  • Name (:name)

    of the storage to be created

  • Specifies (:mount_image_id)

    the image to be assigned to the storage by its ID. Either choose a HDD or a CD-ROM/DVD (ISO) image

Returns:

  • (Boolean)

    true on success, false otherwise



45
46
47
48
49
50
51
# File 'lib/profitbricks/storage.rb', line 45

def update(options = {})
  xml = "<arg0>"
  xml += get_xml_and_update_attributes options.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