Class: HP::Cloud::Metadata
- Inherits:
-
Object
- Object
- HP::Cloud::Metadata
- Defined in:
- lib/hpcloud/metadata.rb
Instance Attribute Summary collapse
-
#cstatus ⇒ Object
readonly
Returns the value of attribute cstatus.
-
#hsh ⇒ Object
readonly
Returns the value of attribute hsh.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(mta = nil) ⇒ Metadata
constructor
A new instance of Metadata.
- #remove_metadata(key) ⇒ Object
- #set_metadata(value) ⇒ Object
- #to_array ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#cstatus ⇒ Object (readonly)
Returns the value of attribute cstatus.
27 28 29 |
# File 'lib/hpcloud/metadata.rb', line 27 def cstatus @cstatus end |
#hsh ⇒ Object (readonly)
Returns the value of attribute hsh.
27 28 29 |
# File 'lib/hpcloud/metadata.rb', line 27 def hsh @hsh end |
Class Method Details
.get_keys ⇒ Object
29 30 31 |
# File 'lib/hpcloud/metadata.rb', line 29 def self.get_keys() return [ "key", "value" ] end |
Instance Method Details
#remove_metadata(key) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/hpcloud/metadata.rb', line 85 def (key) pair = nil if ! @fog_metadata.nil? pair = @fog_metadata.get(key) end if pair.nil? @cstatus = CliStatus.new("Metadata key '#{key}' not found", :not_found) else begin pair.destroy rescue Exception => e @cstatus = CliStatus.new("Error deleting metadata '#{key}': " + e.) end end if @cstatus.is_success? return true end return false end |
#set_metadata(value) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/hpcloud/metadata.rb', line 50 def (value) if value.nil? return true end if value.empty? @hsh = {} return true end begin hshstr = '{"' + value.gsub('=', '"=>"').gsub(',', '","') + '"}' hsh = eval(hshstr) if (hsh.kind_of? Hash) @hsh = hsh unless @fog_metadata.nil? @hsh.each { |k,v| pair = @fog_metadata.get(k) if pair.nil? pair = @fog_metadata.new pair.key = k pair.value = v else pair.value = v end pair.save } end return true end rescue SyntaxError => se rescue NameError => ne end @cstatus = CliStatus.new("Invalid metadata '#{value}' should be in the form 'k1=v1,k2=v2,...'", :incorrect_usage) return false end |
#to_array ⇒ Object
43 44 45 46 47 48 |
# File 'lib/hpcloud/metadata.rb', line 43 def to_array() ray = [] @hsh.each { |k,v| ray << {"key"=>k,"value"=>v} } ray.sort!{|a, b| a["key"] <=> b["key"]} return ray end |
#to_s ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/hpcloud/metadata.rb', line 105 def to_s found=false ="" ray = to_array() ray.each { |val| << "," unless found == false << val["key"].to_s + "=" + val["value"].to_s found = true } return end |