2013-01-07 11:10:17 -06:00
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class RackspaceV2
|
|
|
|
module MetaParent
|
|
|
|
|
2013-01-30 09:05:10 -06:00
|
|
|
# Parent of metadata
|
|
|
|
# @return [#parent] parent of metadata
|
2013-01-07 11:10:17 -06:00
|
|
|
def parent
|
|
|
|
@parent
|
|
|
|
end
|
|
|
|
|
2013-01-30 09:05:10 -06:00
|
|
|
# Sets parent of metadata
|
|
|
|
# @param [#parent] new_parent of metadata
|
2013-01-07 11:10:17 -06:00
|
|
|
def parent=(new_parent)
|
|
|
|
@parent = new_parent
|
|
|
|
end
|
|
|
|
|
2013-01-30 09:05:10 -06:00
|
|
|
# Collection type for parent
|
|
|
|
# @return [String] collection type
|
|
|
|
# @raise [RuntimeException] raises excpetion if collection type for parent is unknown
|
2013-01-07 11:10:17 -06: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 09:05:10 -06:00
|
|
|
# Converts metadata to hash
|
|
|
|
# @return [Hash] hash containing key value pairs for metadata
|
2013-01-07 11:10:17 -06:00
|
|
|
def metas_to_hash(metas)
|
|
|
|
hash = {}
|
|
|
|
metas.each { |meta| hash[meta.key] = meta.value }
|
|
|
|
hash
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|