Class/Module Index [+]

Quicksearch

Fog::Compute::RackspaceV2::Metadata

Public Instance Methods

[](key) click to toggle source

Retrieve specific value for key from Metadata.

@param [key] key @return [value]

# File lib/fog/rackspace/models/compute_v2/metadata.rb, line 51
def [](key)
  return super(key) if key.is_a?(Integer)
  return nil unless key
  datum = self.find {|datum| datum.key == key || datum.key == key.to_sym }
  datum ? datum.value : nil
end
[]=(key, value) click to toggle source

Set value for key.

@param [key] key @return [String]

# File lib/fog/rackspace/models/compute_v2/metadata.rb, line 63
def []=(key, value)
  return super(key,value) if key.is_a?(Integer)          
  return nil unless key
  datum = self.find {|datum| datum.key == key || datum.key == key.to_sym }
  if datum
    datum.value = value
  else
    self << Fog::Compute::RackspaceV2::Metadatum.new(:key => key, :value => value, :service => service, :parent => parent)
  end
  value
end
all() click to toggle source

Retrieves all of the metadata from server @return [Fog::Compute::RackspaceV2::Metadatum] list of metadatum @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError]

# File lib/fog/rackspace/models/compute_v2/metadata.rb, line 23
def all
  requires :parent
  return unless parent.identity
  data = service.list_metadata(collection_name, parent.id).body['metadata']
  from_hash(data)
end
from_hash(hash) click to toggle source

Resets metadata using data from hash @param hash hash containing key value pairs used to populate metadata. @note This will remove existing data

# File lib/fog/rackspace/models/compute_v2/metadata.rb, line 94
def from_hash(hash)
  return unless hash
  metas = []
  hash.each_pair {|k,v| metas << {:key => k, :value => v} }
  load(metas)
end
get(key) click to toggle source

Retrieves specific metadata from server @param [String] key for metadatum @return [Fog::Compute::RackspaceV2::Metadatum] metadatum @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError]

# File lib/fog/rackspace/models/compute_v2/metadata.rb, line 37
def get(key)
  requires :parent
  data = service.get_metadata_item(collection_name, parent.id, key).body["meta"]          
  datum = data.first
  new(:key => datum[0], :value => datum[1])
rescue Fog::Compute::RackspaceV2::NotFound
  nil 
end
new(attributes = {}) click to toggle source

Creates new metadata

# File lib/fog/rackspace/models/compute_v2/metadata.rb, line 86
def new(attributes = {})
  requires :parent
  super({ :parent => parent }.merge!(attributes))
end
save() click to toggle source

Saves the current metadata on server @raise [Fog::Compute::RackspaceV2::NotFound] - HTTP 404 @raise [Fog::Compute::RackspaceV2::BadRequest] - HTTP 400 @raise [Fog::Compute::RackspaceV2::InternalServerError] - HTTP 500 @raise [Fog::Compute::RackspaceV2::ServiceError]

# File lib/fog/rackspace/models/compute_v2/metadata.rb, line 80
def save
  requires :parent
  service.set_metadata(collection_name, parent.id, to_hash)          
end
to_hash() click to toggle source

Converts metadata object to hash @return [Hash] hash of metadata key value pairs

# File lib/fog/rackspace/models/compute_v2/metadata.rb, line 103
def to_hash
  h = {}
  self.each { |datum| h[datum.key] = datum.value }
  h
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.