Class: Fog::Compute::HP::Metadata

Inherits:
Fog::Collection
  • Object
show all
Includes:
MetaParent
Defined in:
lib/fog/hp/models/compute/metadata.rb

Instance Method Summary collapse

Methods included from MetaParent

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

Instance Method Details

#allObject


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

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

#destroy(key) ⇒ Object


25
26
27
28
29
30
# File 'lib/fog/hp/models/compute/metadata.rb', line 25

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

#get(key) ⇒ Object


32
33
34
35
36
37
38
39
40
# File 'lib/fog/hp/models/compute/metadata.rb', line 32

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::HP::NotFound
  nil
end

#new(attributes = {}) ⇒ Object


42
43
44
45
# File 'lib/fog/hp/models/compute/metadata.rb', line 42

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

#set(data = nil) ⇒ Object


47
48
49
50
# File 'lib/fog/hp/models/compute/metadata.rb', line 47

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

#update(data = nil) ⇒ Object


52
53
54
55
# File 'lib/fog/hp/models/compute/metadata.rb', line 52

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