Class: Profitbricks::Image

Inherits:
Model
  • Object
show all
Defined in:
lib/profitbricks/image.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

.allArray<Image>

Outputs a list of all HDD and/or CD-ROM/DVD images existing on or uploaded to the Profit-Bricks FTP server.

Returns:

  • (Array<Image>)

    List of all available Images



37
38
39
40
41
42
# File 'lib/profitbricks/image.rb', line 37

def all
  resp = Profitbricks.request :get_all_images
  resp.collect do |dc|
    PB::Image.new(dc)
  end
end

.find(options = {}) ⇒ Image

Returns information about a HDD or CD-ROM/DVD (ISO) image.

Parameters:

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

    either name or id of the Image

Options Hash (options):

  • :name (String)

    The name of the Image

  • :id (String)

    The id of the Image

Returns:

  • (Image)

    The found Image Object



24
25
26
27
28
29
30
31
32
# File 'lib/profitbricks/image.rb', line 24

def find(options = {})
  image = nil
  if options[:name]
    image = PB::Image.all().select { |d| d.name == options[:name] && (options[:region] ? d.region == options[:region] : true) }.first
    options[:id] = image.id if image
  end
  raise "Unable to locate the image named '#{options[:name]}'" unless options[:id]
  image
end

Instance Method Details

#set_os_type(type) ⇒ Image Also known as: os_type=

Sets the OS Type of an individual HDD and/or CD-ROM/DVD image that has been uploaded on the ProfitBricks FTP server.

Parameters:

  • OS (String)

    Type of the target HDD or CD-ROM/DVD image (WINDOWS, OTHER)

Returns:

  • (Image)

    Updated Image Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
# File 'lib/profitbricks/image.rb', line 9

def set_os_type(type)
  raise ArgumentError.new(":os_type has to be either 'WINDOWS' or 'OTHER'") if !['WINDOWS', 'OTHER'].include? type
  response = Profitbricks.request :set_image_os_type, image_id: self.id, os_type: type
  @os_type = type
  self
end