def create_vm(template_id, opts={})
opts ||= {}
builder = Nokogiri::XML::Builder.new do
vm {
name opts[:name] || "i-#{Time.now.to_i}"
template_(:id => template_id)
cluster(:id => opts[:realm_id] || clusters.first.id)
type_ opts[:hwp_id] || 'desktop'
memory opts[:hwp_memory] ? (opts[:hwp_memory].to_i*1024*1024).to_s : (512*1024*1024).to_s
cpu {
topology( :cores => (opts[:hwp_cpu] || '1'), :sockets => '1' )
}
}
end
headers = opts[:headers] || {}
headers.merge!({
:content_type => 'application/xml',
:accept => 'application/xml',
})
headers.merge!(auth_header)
vm = RHEVM::client(@api_entrypoint)["/vms"].post(Nokogiri::XML(builder.to_xml).root.to_s, headers)
RHEVM::VM::new(self, Nokogiri::XML(vm).root)
end