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

+ (Array<Image>) all

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



39
40
41
42
43
44
# File 'lib/profitbricks/image.rb', line 39

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

+ (Image) find(options = {})

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



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

def find(options = {})
  image = nil
  if options[:name]
    image = PB::Image.all().select { |d| d.name == options[:name] }.first
    options[:id] = image.id if image
  end
  raise "Unable to locate the image named '#{options[:name]}'" unless options[:id]
  image
  # This does not work for public images
  #response = Profitbricks.request :get_image, "<imageId>#{options[:id]}</imageId>"
  #PB::Image.new(response.to_hash[:get_image_response][:return])
end

Instance Method Details

- (Image) set_os_type(type) 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)


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

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