Class: Fog::Compute::OpenStack::Metadata
- Inherits:
-
Fog::Collection
- Object
- Fog::Collection
- Fog::Compute::OpenStack::Metadata
show all
- Includes:
- MetaParent
- Defined in:
- lib/fog/openstack/models/compute/metadata.rb
Instance Method Summary
collapse
Methods included from MetaParent
#collection_name, #metas_to_hash, #parent, #parent=
Instance Method Details
#all ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/fog/openstack/models/compute/metadata.rb', line 15
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
|
#get(key) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/fog/openstack/models/compute/metadata.rb', line 23
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
|
#new(attributes = {}) ⇒ Object
43
44
45
46
|
# File 'lib/fog/openstack/models/compute/metadata.rb', line 43
def new(attributes = {})
requires :parent
super({ :parent => @parent }.merge!(attributes))
end
|
#set(data = nil) ⇒ Object
38
39
40
41
|
# File 'lib/fog/openstack/models/compute/metadata.rb', line 38
def set(data=nil)
requires :parent
service.set_metadata(collection_name, @parent.id, to_hash(data))
end
|
#to_hash(data = nil) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/fog/openstack/models/compute/metadata.rb', line 48
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
|
#update(data = nil) ⇒ Object
33
34
35
36
|
# File 'lib/fog/openstack/models/compute/metadata.rb', line 33
def update(data=nil)
requires :parent
service.update_metadata(collection_name, @parent.id, to_hash(data))
end
|