Class: OpenStack::Nova::Compute::Flavor
- Inherits:
-
BaseDetail
- Object
- ActiveResource::Base
- Base
- Common
- Base
- BaseDetail
- OpenStack::Nova::Compute::Flavor
- Defined in:
- lib/open_stack/nova/compute/flavor.rb
Overview
An OpenStack Floating Ip
Attributes
-
name
- The name of the flavor -
ram
- Amount of RAM (MBytes) -
disk
- Amount of storage (GBytes) -
swap
- Amount of swap storage (MBytes) -
vcpus
- Virtual CPUs -
rxtx_factor
- Traffic shaping (?) -
ephemeral_disk
- Ephemeral storage amount (GByte) -
is_public
- True if the flavor is public
Class Method Summary collapse
-
.applicable_for_image(image) ⇒ Object
Returns a list of Flavor that can be used with the given Image.
-
.applicable_for_quota_set(quota_set) ⇒ Object
Returns a list of Flavor that can be used with the given quota-set.
-
.find_all_by_name(name) ⇒ Object
Returns a list of Flavor for a given name.
-
.find_by_constraints(constraints = {}) ⇒ Object
Returns a list of Flavor that can be used with the given constraints.
-
.find_by_name(name) ⇒ Object
Returns the first Flavor for a given name.
Instance Method Summary collapse
-
#description ⇒ Object
Returns a human-friendly description for this Flavor.
-
#encode(options = {}) ⇒ Object
Overloads ActiveRecord::encode method.
-
#initialize(attributes = {}, persisted = false) ⇒ Flavor
constructor
:notnew:.
Methods inherited from BaseDetail
collection_path, collection_path_create, #collection_path_create
Methods inherited from Base
Methods inherited from Common
collection_path, custom_method_collection_url, element_path
Methods inherited from Base
Methods inherited from ActiveResource::Base
Constructor Details
#initialize(attributes = {}, persisted = false) ⇒ Flavor
:notnew:
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# 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 |
Class Method Details
.applicable_for_image(image) ⇒ Object
Returns a list of Flavor that can be used with the given Image
Attributes
-
image
- An OpenStack::Nova::Compute::Image instance or an Image id
152 153 154 155 156 157 158 159 160 |
# 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) ⇒ Object
Returns a list of Flavor that can be used with the given quota-set
Attributes
-
quota_set
- An OpenStack::Nova::Compute::QuotaSet instance
166 167 168 169 170 171 |
# 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) ⇒ Object
Returns a list of Flavor for a given name
Attributes
-
name
- A string
113 114 115 |
# 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 = {}) ⇒ Object
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
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# 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) ⇒ Object
Returns the first Flavor for a given name
Attributes
-
name
- A string
121 122 123 |
# File 'lib/open_stack/nova/compute/flavor.rb', line 121 def self.find_by_name(name) all.detect { |flavor| flavor.name == name } end |
Instance Method Details
#description ⇒ Object
Returns a human-friendly description for this Flavor
174 175 176 |
# File 'lib/open_stack/nova/compute/flavor.rb', line 174 def description "#{vcpus} vCPU - #{ram} MB RAM - #{disk} GB Disk" end |
#encode(options = {}) ⇒ Object
Overloads ActiveRecord::encode method
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/open_stack/nova/compute/flavor.rb', line 90 def encode(={}) # :nodoc: Custom encoding to deal with openstack API to_encode = { :flavor => { :name => name, :ram => ram, :disk => disk, :swap => swap, :vcpus => vcpus } } # Optional attributes (openstack will not accept empty attribute for update/create) to_encode[:flavor][:'OS-FLV-EXT-DATA:ephemeral'] = ephemeral_disk if ephemeral_disk.present? to_encode[:flavor][:'os-flavor-access:is_public'] = is_public if is_public.present? to_encode[:flavor][:rxtx_factor] = rxtx_factor if rxtx_factor.present? to_encode.send("to_#{self.class.format.extension}", ) end |