# File lib/deltacloud/drivers/rhevm/rhevm_client.rb, line 115
    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' )
          }
          if opts[:user_data] and not opts[:user_data].empty?
            custom_properties {
              #
              # FIXME: 'regexp' parameter is just a temporary workaround. This
              # is a reported and verified bug and should be fixed in next
              # RHEV-M release.
              #
              custom_property({
                :name => "floppyinject",
                :value => "#{RHEVM::FILEINJECT_PATH}:#{opts[:user_data]}",
                :regexp => "^([^:]+):(.*)$"})
            }
          end
        }
      end
      headers = opts[:headers] || {}
      headers.merge!({
        :content_type => 'application/xml',
        :accept => 'application/xml',
      })
      headers.merge!(auth_header)
      begin
        vm = RHEVM::client(@api_entrypoint)["/vms"].post(Nokogiri::XML(builder.to_xml).root.to_s, headers)
      rescue
        if $!.respond_to?(:http_body)
          fault = (Nokogiri::XML($!.http_body)/'/fault/detail').first
          fault = fault.text.gsub(/\[|\]/, '') if fault
        end
        fault ||= $!.message
        raise RHEVMBackendException::new(fault)
      end
      RHEVM::VM::new(self, Nokogiri::XML(vm).root)
    end