Class: OpenStack::Compute::Metadata
- Inherits:
-
Object
- Object
- OpenStack::Compute::Metadata
- Defined in:
- lib/openstack/compute/metadata.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #clear ⇒ Object
- #clear! ⇒ Object
- #delete(keys) ⇒ Object
- #delete!(keys) ⇒ Object
- #each ⇒ Object
- #each_pair ⇒ Object
- #has_key?(key) ⇒ Boolean
-
#initialize(compute, parent_url, metadata = nil) ⇒ Metadata
constructor
A new instance of Metadata.
- #refresh(keys = nil) ⇒ Object
- #save ⇒ Object
- #size ⇒ Object
- #store(key, value) ⇒ Object
- #update(keys = nil) ⇒ Object
Constructor Details
#initialize(compute, parent_url, metadata = nil) ⇒ Metadata
Returns a new instance of Metadata.
6 7 8 9 10 |
# File 'lib/openstack/compute/metadata.rb', line 6 def initialize(compute, parent_url, =nil) @compute = compute @base_url = "#{parent_url}/metadata" = end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 15 |
# File 'lib/openstack/compute/metadata.rb', line 12 def [](key) refresh if .nil? [key] end |
#[]=(key, value) ⇒ Object
17 18 19 20 |
# File 'lib/openstack/compute/metadata.rb', line 17 def []=(key, value) = {} if .nil? [key] = value end |
#clear ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/openstack/compute/metadata.rb', line 95 def clear if .nil? = {} else .clear end end |
#clear! ⇒ Object
103 104 105 106 |
# File 'lib/openstack/compute/metadata.rb', line 103 def clear! clear save end |
#delete(keys) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/openstack/compute/metadata.rb', line 81 def delete(keys) return if .nil? keys.each { |key| .delete(key) } end |
#delete!(keys) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/openstack/compute/metadata.rb', line 88 def delete!(keys) keys.each { |key| @compute.connection.req('DELETE', "#{@base_url}/#{key}") .delete(key) if not .nil? } end |
#each ⇒ Object
39 40 41 42 |
# File 'lib/openstack/compute/metadata.rb', line 39 def each refresh if .nil? .each end |
#each_pair ⇒ Object
27 28 29 30 31 32 |
# File 'lib/openstack/compute/metadata.rb', line 27 def each_pair = {} if .nil? .each_pair do |k,v| yield k, v end end |
#has_key?(key) ⇒ Boolean
108 109 110 111 |
# File 'lib/openstack/compute/metadata.rb', line 108 def has_key?(key) return False if .nil? return .has_key?(key) end |
#refresh(keys = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/openstack/compute/metadata.rb', line 66 def refresh(keys=nil) if keys.nil? response = @compute.connection.req('GET', @base_url) = JSON.parse(response.body)['metadata'] else = {} if == nil keys.each { |key| response = @compute.connection.req('GET', "#{@base_url}/#{key}") next if response.code == "404" = JSON.parse(response.body)['meta'] .each { |k, v| [k] = v } } end end |
#save ⇒ Object
44 45 46 47 48 49 |
# File 'lib/openstack/compute/metadata.rb', line 44 def save return if .nil? json = JSON.generate(:metadata => ) response = @compute.connection.req('PUT', @base_url, :data => json) = JSON.parse(response.body)['metadata'] end |
#size ⇒ Object
34 35 36 37 |
# File 'lib/openstack/compute/metadata.rb', line 34 def size = {} if .nil? .size end |
#store(key, value) ⇒ Object
22 23 24 25 |
# File 'lib/openstack/compute/metadata.rb', line 22 def store(key, value) = {} if .nil? [key] = value end |
#update(keys = nil) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/openstack/compute/metadata.rb', line 51 def update(keys=nil) return if .nil? if keys.nil? json = JSON.generate(:metadata => ) response = @compute.connection.req('POST', @base_url, :data => json) = JSON.parse(response.body)['metadata'] else keys.each { |key| next if not .has_key?(key) json = JSON.generate(:meta => { key => [key] }) @compute.connection.req('PUT', "#{@base_url}/#{key}", :data => json) } end end |