Sha256: eda1dd6d96b2cd287fac2d083b26fbebd370fdcd011d4e743715de9270aebed1

Contents?: true

Size: 1.77 KB

Versions: 19

Compression:

Stored size: 1.77 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} }
          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

19 entries across 19 versions & 6 rubygems

Version Path
cifrado-0.2.1 vendor/fog/lib/fog/openstack/models/compute/metadata.rb
cifrado-0.2.0 vendor/fog/lib/fog/openstack/models/compute/metadata.rb
gapinc-fog-1.12.1.1 lib/fog/openstack/models/compute/metadata.rb
gapinc-fog-1.12.1a lib/fog/openstack/models/compute/metadata.rb
gapinc-fog-1.12.1 lib/fog/openstack/models/compute/metadata.rb
fog-1.12.1 lib/fog/openstack/models/compute/metadata.rb
fog-1.12.0 lib/fog/openstack/models/compute/metadata.rb
hpfog-0.0.20 lib/fog/openstack/models/compute/metadata.rb
vagrant-shell-0.2.6 vendor/bundle/gems/fog-1.10.1/lib/fog/openstack/models/compute/metadata.rb
vagrant-shell-0.2.5 vendor/bundle/gems/fog-1.10.1/lib/fog/openstack/models/compute/metadata.rb
fog-1.11.1 lib/fog/openstack/models/compute/metadata.rb
fog-1.11.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.10.1 lib/fog/openstack/models/compute/metadata.rb
fog-test-me-1.10.0 lib/fog/openstack/models/compute/metadata.rb
cifrado-0.1.3 vendor/fog/lib/fog/openstack/models/compute/metadata.rb
fog-1.10.0 lib/fog/openstack/models/compute/metadata.rb
cifrado-0.1.2 vendor/fog/lib/fog/openstack/models/compute/metadata.rb
cifrado-0.1.1 vendor/fog/lib/fog/openstack/models/compute/metadata.rb
cifrado-0.1 vendor/fog/lib/fog/openstack/models/compute/metadata.rb