Class: Fog::Compute::OpenStack::Metadata

Inherits:
OpenStack::Collection show all
Includes:
MetaParent
Defined in:
lib/fog/compute/openstack/models/metadata.rb

Instance Attribute Summary

Attributes inherited from OpenStack::Collection

#response

Instance Method Summary collapse

Methods included from MetaParent

#collection_name, #metas_to_hash, #parent, #parent=

Methods inherited from OpenStack::Collection

#destroy, #find_by_id, #load_response, #summary

Instance Method Details

#allObject



15
16
17
18
19
20
21
22
# File 'lib/fog/compute/openstack/models/metadata.rb', line 15

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

#get(key) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/fog/compute/openstack/models/metadata.rb', line 24

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

#new(attributes = {}) ⇒ Object



44
45
46
47
# File 'lib/fog/compute/openstack/models/metadata.rb', line 44

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

#set(data = nil) ⇒ Object



39
40
41
42
# File 'lib/fog/compute/openstack/models/metadata.rb', line 39

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

#to_hash(data = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fog/compute/openstack/models/metadata.rb', line 49

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

#update(data = nil) ⇒ Object



34
35
36
37
# File 'lib/fog/compute/openstack/models/metadata.rb', line 34

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