2013-01-07 12:10:17 -05:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class RackspaceV2
|
|
|
|
module MetaParent
|
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# Parent of metadata
|
|
|
|
# @return [#parent] parent of metadata
|
2013-01-07 12:10:17 -05:00
|
|
|
def parent
|
|
|
|
@parent
|
|
|
|
end
|
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# Sets parent of metadata
|
|
|
|
# @param [#parent] new_parent of metadata
|
2013-01-07 12:10:17 -05:00
|
|
|
def parent=(new_parent)
|
|
|
|
@parent = new_parent
|
|
|
|
end
|
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# Collection type for parent
|
|
|
|
# @return [String] collection type
|
2013-03-27 10:50:30 -04:00
|
|
|
# @raise [RuntimeError] raises excpetion if collection type for parent is unknown
|
2013-01-07 12:10:17 -05:00
|
|
|
def collection_name
|
|
|
|
if parent.class == Fog::Compute::RackspaceV2::Image
|
|
|
|
return "images"
|
|
|
|
elsif parent.class == Fog::Compute::RackspaceV2::Server
|
|
|
|
return "servers"
|
|
|
|
else
|
|
|
|
raise "Metadata is not supported for this model type."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-01-30 10:05:10 -05:00
|
|
|
# Converts metadata to hash
|
|
|
|
# @return [Hash] hash containing key value pairs for metadata
|
2013-01-07 12:10:17 -05:00
|
|
|
def metas_to_hash(metas)
|
|
|
|
hash = {}
|
|
|
|
metas.each { |meta| hash[meta.key] = meta.value }
|
|
|
|
hash
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|