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, 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.

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

  • Sets (:profit_bricks_image_password)

    the VM image root login password to the specified value. Only supported for generic Profitbricks HDD images. User images are expected to be preconfigured with a password. If no password is supplied, one is automatically created. Please see error codes for password syntax rules.]

Raises:

  • (ArgumentError)


61
62
63
64
65
66
# File 'lib/profitbricks/storage.rb', line 61

def create(options = {})
  raise ArgumentError.new("You must provide a :data_center_id") if options[:data_center_id].nil?
  options[:storage_name] = options.delete :name if options[:name]
  response = Profitbricks.request :create_storage, options
  self.find(:id => response[:storage_id])
end

.find(options = {}) ⇒ Storage

Finds a storage device

Options Hash (options):

  • The (String)

    id of the storage to locate



73
74
75
76
77
# File 'lib/profitbricks/storage.rb', line 73

def find(options = {})
  raise "Unable to locate the storage named '#{options[:name]}'" unless options[:id]
  response = Profitbricks.request :get_storage, storage_id: options[:id]
  Profitbricks::Storage.new(response)
end

Instance Method Details

#connect(options = {}) ⇒ Boolean

Connects a virtual storage device to an existing server.

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 or VIRTIO. Default: VIRTIO

  • Defines (:device_number)

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

Raises:

  • (ArgumentError)


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

def connect(options = {})
  raise ArgumentError.new(":bus_type has to be either 'IDE' or 'VIRTIO'") if options[:bus_type] and !['IDE', 'VIRTIO'].include? options[:bus_type]
  response = Profitbricks.request :connect_storage_to_server, options.merge(:storage_id => self.id)
  update_attributes_from_hash options
  return true
end

#deleteBoolean

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.

Options Hash (options):

  • Identifier (:server_id)

    of the connected virtual server (required)



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

def disconnect(options = {})
  Profitbricks.request :disconnect_storage_from_server, storage_id: self.id, server_id: options[:server_id]
  return true
end

#update(options = {}) ⇒ Boolean

Updates parameters of an existing virtual storage device.

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



43
44
45
46
47
48
# File 'lib/profitbricks/storage.rb', line 43

def update(options = {})
  update_attributes_from_hash options
  options[:storage_name] = options.delete :name if options[:name]
  Profitbricks.request :update_storage, options.merge(:storage_id => self.id)
  return true
end