Sha256: 12a5bb3842aac7bc2d1cd0a31c17e487226465f170bc7d7e4ef6928ea0bb9890

Contents?: true

Size: 1.97 KB

Versions: 37

Compression:

Stored size: 1.97 KB

Contents

require 'fog/core/collection'
require 'fog/hp/models/compute_v2/meta_parent'
require 'fog/hp/models/compute_v2/meta'
require 'fog/hp/models/compute_v2/image'
require 'fog/hp/models/compute_v2/server'

module Fog
  module Compute
    class HPV2

      class Metadata < Fog::Collection

        model Fog::Compute::HPV2::Meta

        include Fog::Compute::HPV2::MetaParent

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

        def destroy(key)
          requires :parent
          service.delete_meta(collection_name, @parent.id, key)
        rescue Fog::Compute::HPV2::NotFound
          nil
        end

        def get(key)
          requires :parent
          data = service.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::HPV2::NotFound
          nil
        end

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

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

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


        private
        def meta_hash(data=nil)
          if data.nil?
            data={}
            self.each do |meta|
              if meta.is_a?(Fog::Compute::HPV2::Meta) 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

37 entries across 37 versions & 2 rubygems

Version Path
fog-1.22.0 lib/fog/hp/models/compute_v2/metadata.rb
fog-1.21.0 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/hp/models/compute_v2/metadata.rb
fog-1.20.0 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/hp/models/compute_v2/metadata.rb
fog-1.19.0 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/hp/models/compute_v2/metadata.rb
fog-maestrodev-1.18.0.20131209091424 lib/fog/hp/models/compute_v2/metadata.rb