class OpenStack::Nova::Compute::Flavor

An OpenStack Floating Ip

Attributes

Public Class Methods

applicable_for_image(image) click to toggle source

Returns a list of Flavor that can be used with the given Image

Attributes

# File lib/open_stack/nova/compute/flavor.rb, line 152
def self.applicable_for_image(image)
  image_instance = image.is_a?(OpenStack::Nova::Compute::Image) ? image : Image.find(image)

  constraints = {}
  constraints[:min_ram] = image.min_ram if image_instance.min_ram > 0
  constraints[:min_disk] = image.min_disk if image_instance.min_disk > 0

  find_by_constraints constraints
end
applicable_for_quota_set(quota_set) click to toggle source

Returns a list of Flavor that can be used with the given quota-set

Attributes

# File lib/open_stack/nova/compute/flavor.rb, line 166
def self.applicable_for_quota_set(quota_set)
  constraints = {}
  constraints[:max_ram] = quota_set.ram

  find_by_constraints constraints
end
find_all_by_name(name) click to toggle source

Returns a list of Flavor for a given name

Attributes

  • name - A string

# File lib/open_stack/nova/compute/flavor.rb, line 113
def self.find_all_by_name(name)
  all.reject { |flavor| flavor.name != name }
end
find_by_constraints(constraints = {}) click to toggle source

Returns a list of Flavor that can be used with the given constraints

Attributes

  • constraints - Hash of constraints. Valid keys are: :min_ram, :min_vcpus, :min_disk, :max_ram, :max_vcpus, :max_disk

# File lib/open_stack/nova/compute/flavor.rb, line 129
def self.find_by_constraints(constraints = {})
  constraints = constraints.with_indifferent_access
  constraints[:min_ram] ||= -1.0/0.0
  constraints[:min_vcpus] ||= -1.0/0.0
  constraints[:min_disk] ||= -1.0/0.0
  constraints[:max_ram] ||= +1.0/0.0
  constraints[:max_vcpus] ||= +1.0/0.0
  constraints[:max_disk] ||= +1.0/0.0

  self.all.select do |flavor|
      flavor.ram >= constraints[:min_ram] and
      flavor.vcpus >= constraints[:min_vcpus] and
      flavor.disk >= constraints[:min_disk] and
      flavor.ram <= constraints[:max_ram] and
      flavor.vcpus <= constraints[:max_vcpus] and
      flavor.disk <= constraints[:max_disk]
  end
end
find_by_name(name) click to toggle source

Returns the first Flavor for a given name

Attributes

  • name - A string

# File lib/open_stack/nova/compute/flavor.rb, line 121
def self.find_by_name(name)
  all.detect { |flavor| flavor.name == name }
end

Public Instance Methods

description() click to toggle source

Returns a human-friendly description for this Flavor

# File lib/open_stack/nova/compute/flavor.rb, line 174
def description
  "#{vcpus} vCPU - #{ram} MB RAM - #{disk} GB Disk"
end

Protected Instance Methods

initialize(attributes = {}, persisted = false) click to toggle source
Calls superclass method
# File lib/open_stack/nova/compute/flavor.rb, line 71
def initialize(attributes = {}, persisted = false) # :notnew:
  attributes = attributes.with_indifferent_access
  new_attributes = {
      :id => attributes[:id],
      :name => attributes[:name],
      :ram => attributes[:ram],
      :disk => attributes[:disk],
      :swap => attributes[:swap],
      :vcpus => attributes[:vcpus],
      :rxtx_factor => attributes[:rxtx_factor],
      :ephemeral_disk => attributes[:'OS-FLV-EXT-DATA:ephemeral'] || attributes[:ephemeral_disk],
      :is_public => attributes[:'os-flavor-access:is_public'] || attributes[:is_public]
  }
  super(new_attributes, persisted)

  self
end