Sha256: 879df8b0d4d44a071af0657e9ad3ac83b3c7c64b957b2cda29be4666b9f32756

Contents?: true

Size: 1.8 KB

Versions: 13

Compression:

Stored size: 1.8 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 = connection.list_metadata(collection_name, @parent.id).body['metadata']
          metas = []
          metadata.each_pair {|k,v| metas << {"key" => k, "value" => v} }
          load(metas)
        end

        def get(key)
          requires :parent
          data = connection.get_meta(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
          connection.update_metadata(collection_name, @parent.id, meta_hash(data))
        end

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

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

        private
        def meta_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

13 entries across 13 versions & 7 rubygems

Version Path
fog-nirvanix-1.8.2 lib/fog/openstack/models/compute/metadata.rb
fog-nirvanix-1.8.1 lib/fog/openstack/models/compute/metadata.rb
fog-parser-fix-1.6.1 lib/fog/openstack/models/compute/metadata.rb
fog-test-again-1.6.0 lib/fog/openstack/models/compute/metadata.rb
fog-parser-fix-1.6.0 lib/fog/openstack/models/compute/metadata.rb
ey-vendored-backup-3.0.27 vendor/gems/fog/lib/fog/openstack/models/compute/metadata.rb
fog-sgonyea-1.8.1 lib/fog/openstack/models/compute/metadata.rb
fog-1.8.0 lib/fog/openstack/models/compute/metadata.rb
fog-maestrodev-1.7.0.20121114190951 lib/fog/openstack/models/compute/metadata.rb
fog-1.7.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.6.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.5.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.4.0 lib/fog/openstack/models/compute/metadata.rb