module Fog
module Generators
module Compute
module VcloudDirector
# {:metadata=>
# {"buenas si"=>"no tanto ya",
# "hola"=>"adios"},
# :type=>"application/vnd.vmware.vcloud.metadata+xml",
# :href=>
# "https://example.com/api/vApp/vm-18545e82-d919-4071-ae7e-d1300d9d8112/metadata",
# :id=>"vm-18545e82-d919-4071-ae7e-d1300d9d8112"}
#
# This is what it generates:
#
#
#
# buenas si
# no tanto ya
#
#
# hola
# adios
#
#
#
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/types/MetadataType.html
class MetadataBase
attr_reader :attrs
def initialize(attrs={})
@attrs = attrs
end
def generate_xml
output = ""
output << header
attrs[:metadata].each_pair do |k,v|
output << metadata_entry(k,v)
end
output << tail
output
end
def add_item(k,v)
@attrs[:metadata].merge!(Hash[k,v])
end
# 1.5
def header
<<-END
END
end
def metadata_entry
raise "This is an abstract class. Use the appropriate subclass"
end
# 5.1
#def header
# ''
#end
def tail
<<-END
END
end
end
class MetadataV51 < MetadataBase
def metadata_entry(key, value)
<<-END
#{key}
#{value}
END
end
end
class MetadataV15 < MetadataBase
def metadata_entry(key, value)
<<-END
#{key}
#{value}
END
end
end
end
end
end
end