Sha256: f93efbf398bd85c8d123e3823d783abc8f1fc63f4da0c9df5364ab3577f69b65

Contents?: true

Size: 1.3 KB

Versions: 46

Compression:

Stored size: 1.3 KB

Contents

module Fog
  module Brightbox
    module Compute
      #
      # This selects the preferred image to use based on a number of
      # conditions
      #
      class ImageSelector
        # Prepares a selector with the API output
        #
        # @param [Array<Hash>] images hash matching API output for {Fog::Compute::Brightbox#list_images}
        #
        def initialize(images)
          @images = images
        end

        # 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
        #
        # @note This performs a live query against the API
        #
        # @return [String] if image matches containing the identifier
        # @return [NilClass] if no image matches
        #
        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
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 4 rubygems

Version Path
fog-brightbox-0.10.1 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.10.0 lib/fog/brightbox/compute/image_selector.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-brightbox-0.9.0/lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.9.0 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.8.0 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.7.2 lib/fog/brightbox/compute/image_selector.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-brightbox-0.7.1/lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.7.1 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.7.0 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.6.1 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.6.0 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.5.1 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.5.0 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.4.1 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.4.0 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.3.0 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.2.0 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.1.1 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.1.0 lib/fog/brightbox/compute/image_selector.rb
fog-brightbox-0.1.0.dev2 lib/fog/brightbox/compute/image_selector.rb