Class: CloudFlock::Target::Servers::Platform
- Inherits:
-
Object
- Object
- CloudFlock::Target::Servers::Platform
- Defined in:
- lib/cloudflock/target/servers/platform.rb,
lib/cloudflock/errstr.rb
Overview
Public: Map host specifications to Image and Flavor IDs in Rackspace Cloud.
Examples
platform = Platform.new(cpe, fog)
platform.get_appropriate_flavors
# => [<Fog::Compute::RackspaceV2::Flavor>, ...]
platform.to_s
# => "CentOS Linux 6.4"
Constant Summary collapse
- NOT_CPE =
'Expected a CPE object.'
- CPE_INCOMPLETE =
'CPE must contain at least vendor and version.'
Instance Method Summary collapse
-
#get_appropriate_flavors(resource_map = {}) ⇒ Object
Public: Given a resource map (e.g. generated by profiling a host), determine which flavors would be appropriate as migration targets.
-
#initialize(cpe, fog = nil) ⇒ Platform
constructor
Public: Initialize the Platform object.
-
#to_s ⇒ Object
Public: Generate a String describing the platform’s name/version.
Constructor Details
#initialize(cpe, fog = nil) ⇒ Platform
Public: Initialize the Platform object.
cpe - CPE object to use in determining image ID. fog - Fog Compute object used to obtain flavor and image maps.
(default: nil)
Raises ArgumentError if anything but a CPE object is passed. Raises KeyError if the CPE object doesn’t have vendor and version defined.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cloudflock/target/servers/platform.rb', line 26 def initialize(cpe, fog = nil) unless cpe.is_a?(CPE) raise(ArgumentError, Errstr::NOT_CPE) end if cpe.vendor.nil? or cpe.version.nil? raise(KeyError, Errstr::CPE_INCOMPLETE) end @cpe = cpe build_maps(fog) end |
Instance Method Details
#get_appropriate_flavors(resource_map = {}) ⇒ Object
Public: Given a resource map (e.g. generated by profiling a host), determine which flavors would be appropriate as migration targets.
resource_map - Hash containing memory and hard disk usage information
from the source host:
:ram - Hash containing memory usage information
:mem_used - Amount of memory used in MiB.
(default: 0)
:swapping? - Whether the source host is swapping.
(default: 0)
:hdd - Hash containing disk usage information:
:disk - Amount of disk used in GB. (default: 0)
Returns a Hash containing appropriate flavor IDs mapped to flavor names.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cloudflock/target/servers/platform.rb', line 60 def get_appropriate_flavors(resource_map = {}) resource_map[:ram] ||= {mem_used: 0, swapping?: false} resource_map[:hdd] ||= {disk: 0} ram = resource_map[:ram] * (resource_map[:ram][:swapping?] ? 2 : 1) disk = resource_map[:hdd][:disk] * 1.2 @flavor_map.select do |id| @flavor_map[e][:ram] >= ram && @flavor_map[e][:disk] >= disk end end |
#to_s ⇒ Object
Public: Generate a String describing the platform’s name/version.
Returns a String.
41 42 43 44 |
# File 'lib/cloudflock/target/servers/platform.rb', line 41 def to_s "#{@cpe.distro.capitalize} #{@cpe.product.gsub(/_/, ' ').capitalize} " \ "#{@cpe.version}" end |