Sha256: dc04f43a8fc9dff0db0824aec9fc16481c0f6dca5c2f0e8dac089778b8e0604e

Contents?: true

Size: 973 Bytes

Versions: 8

Compression:

Stored size: 973 Bytes

Contents

require 'yao/resources/metadata_available'
module Yao::Resources
  class Image < Base
    friendly_attributes :name, :status, :progress, :metadata
    map_attribute_to_attribute minDisk: :min_disk
    map_attribute_to_attribute minRam: :min_ram

    # @param unit [String]
    # @return [Integer]
    def size(unit=nil)
      size = self["OS-EXT-IMG-SIZE:size"]
      case unit
      when 'K'
        size / 1024.0
      when 'M'
        size / 1024.0 / 1024.0
      when 'G'
        size / 1024.0 / 1024.0 / 1024.0
      else
        size
      end
    end

    self.service        = "image"
    self.api_version    = "v2"
    self.resource_name  = "image"
    self.resources_name = "images"

    extend MetadataAvailable

    class << self
      private

      # override Yao::Resources::RestfullyAccessible.resource_from_json
      # @param json [Hash]
      # @return [Yao::Resources::*]
      def resource_from_json(json)
        new(json)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
yao-0.21.0 lib/yao/resources/image.rb
yao-0.20.0 lib/yao/resources/image.rb
yao-0.19.0 lib/yao/resources/image.rb
yao-0.18.0 lib/yao/resources/image.rb
yao-0.17.0 lib/yao/resources/image.rb
yao-0.16.0 lib/yao/resources/image.rb
yao-0.15.0 lib/yao/resources/image.rb
yao-0.14.0 lib/yao/resources/image.rb