Class: Fog::OpenStack::Compute::Metadata
Instance Attribute Summary
#response
Instance Method Summary
collapse
Methods included from MetaParent
#collection_name, #metas_to_hash, #parent, #parent=
#destroy, #find_by_id, #load_response, #summary
Instance Method Details
#all ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/fog/openstack/compute/models/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
24
25
26
27
28
29
30
31
32
|
# File 'lib/fog/openstack/compute/models/metadata.rb', line 24
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::OpenStack::Compute::NotFound
nil
end
|
#new(attributes = {}) ⇒ Object
44
45
46
47
|
# File 'lib/fog/openstack/compute/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/openstack/compute/models/metadata.rb', line 39
def set(data = nil)
requires :parent
service.set_metadata(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/openstack/compute/models/metadata.rb', line 49
def to_hash(data = nil)
if data.nil?
data = {}
each do |meta|
if meta.kind_of?(Fog::OpenStack::Compute::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/openstack/compute/models/metadata.rb', line 34
def update(data = nil)
requires :parent
service.update_metadata(collection_name, @parent.id, to_hash(data))
end
|