Sha256: 218e6d662f3d14445b26386d886021b637eff79928c08d78de2444f755b2620c

Contents?: true

Size: 1.79 KB

Versions: 48

Compression:

Stored size: 1.79 KB

Contents

require 'fog/core/collection'
require 'fog/openstack/models/meta_parent'
require 'fog/openstack/models/compute/metadatum'
require 'fog/openstack/models/compute/image'
require 'fog/openstack/models/compute/server'

module Fog
  module Compute
    class OpenStack

      class Metadata < Fog::Collection

        model Fog::Compute::OpenStack::Metadatum

        include Fog::Compute::OpenStack::MetaParent

        def all
          requires :parent
          metadata = service.list_metadata(collection_name, @parent.id).body['metadata']
          metas = []
          metadata.each_pair {|k,v| metas << {"key" => k, "value" => v} } unless metadata.nil?
          load(metas)
        end

        def get(key)
          requires :parent
          data = service.get_metadata(collection_name, @parent.id, key).body["meta"]
          metas = []
          data.each_pair {|k,v| metas << {"key" => k, "value" => v} }
          new(metas[0])
        rescue Fog::Compute::OpenStack::NotFound
          nil
        end

        def update(data=nil)
          requires :parent
          service.update_metadata(collection_name, @parent.id, to_hash(data))
        end

        def set(data=nil)
          requires :parent
          service.set_metadata(collection_name, @parent.id, to_hash(data))
        end

        def new(attributes = {})
          requires :parent
          super({ :parent => @parent }.merge!(attributes))
        end

        def to_hash(data=nil)
          if data.nil?
            data={}
            self.each do |meta|
              if meta.is_a?(Fog::Compute::OpenStack::Metadatum) then
                data.store(meta.key, meta.value)
              else
                data.store(meta["key"], meta["value"])
              end
            end
          end
          data
        end

      end

    end
  end
end

Version data entries

48 entries across 48 versions & 3 rubygems

Version Path
fog-maestrodev-1.18.0.20131209090811 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131206115947 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131205181604 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131127194823 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131126183714 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131126122111 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131125111730 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131125083406 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131123105121 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131122203507 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131121075022 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131118164830 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131115184302 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131114200144 lib/fog/openstack/models/compute/metadata.rb
gapinc-fog-1.12.1.2.1 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131112185232 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.18.0.20131111203459 lib/fog/openstack/models/compute/metadata.rb
fog-1.18.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.17.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.16.0 lib/fog/openstack/models/compute/metadata.rb