Class: Fog::Brightbox::Compute::ImageSelector
- Inherits:
-
Object
- Object
- Fog::Brightbox::Compute::ImageSelector
- Defined in:
- lib/fog/brightbox/compute/image_selector.rb
Overview
This selects the preferred image to use based on a number of conditions
Instance Method Summary collapse
-
#initialize(images) ⇒ ImageSelector
constructor
Prepares a selector with the API output.
-
#latest_ubuntu ⇒ String, NilClass
Returns current identifier of the latest version of Ubuntu.
Constructor Details
#initialize(images) ⇒ ImageSelector
Prepares a selector with the API output
13 14 15 |
# File 'lib/fog/brightbox/compute/image_selector.rb', line 13 def initialize(images) @images = images end |
Instance Method Details
#latest_ubuntu ⇒ String, NilClass
Note:
This performs a live query against the API
Returns current identifier of the latest version of Ubuntu
The order of preference is:
-
Only Official Brightbox images
-
Only Ubuntu images
-
Latest by name (alphanumeric sort)
-
Latest by creation date
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/brightbox/compute/image_selector.rb', line 30 def latest_ubuntu @images.select do |img| img["official"] == true && img["arch"] == "i686" && img["name"] =~ /ubuntu/i end.sort do |a,b| # Reverse sort so "raring" > "precise" and "13.10" > "13.04" b["name"].downcase <=> a["name"].downcase end.first["id"] rescue nil end |