Sha256: f8c01cc80b66a33751f39063e9e86833d6d186e5346e7d19676b180018810802

Contents?: true

Size: 1.79 KB

Versions: 23

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

23 entries across 23 versions & 4 rubygems

Version Path
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-1.32.0/lib/fog/openstack/models/compute/metadata.rb
fog-1.32.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.31.0 lib/fog/openstack/models/compute/metadata.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/openstack/models/compute/metadata.rb
fog-1.30.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.29.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.28.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.27.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.26.0 lib/fog/openstack/models/compute/metadata.rb
fog-1.25.0 lib/fog/openstack/models/compute/metadata.rb
nsidc-fog-1.24.1 lib/fog/openstack/models/compute/metadata.rb
fog-1.24.0 lib/fog/openstack/models/compute/metadata.rb
ns-fog-1.22.11 lib/fog/openstack/models/compute/metadata.rb
ns-fog-1.22.10 lib/fog/openstack/models/compute/metadata.rb
ns-fog-1.22.9 lib/fog/openstack/models/compute/metadata.rb
ns-fog-1.22.8 lib/fog/openstack/models/compute/metadata.rb
ns-fog-1.22.7 lib/fog/openstack/models/compute/metadata.rb
ns-fog-1.22.6 lib/fog/openstack/models/compute/metadata.rb
fog-1.23.0 lib/fog/openstack/models/compute/metadata.rb
ns-fog-1.22.4 lib/fog/openstack/models/compute/metadata.rb