# File lib/ovirt/vm.rb, line 28
    def self.to_xml( opts={})
      builder = Nokogiri::XML::Builder.new do
        vm{
          name_ opts[:name] || "i-#{Time.now.to_i}"
          if opts[:template]
            template_ :id => (opts[:template])
          elsif opts[:template_name]
            template_{ name_(opts[:template_name])}
          else
            template_{name_('Blank')}
          end
          if opts[:cluster]
            cluster_( :id => opts[:cluster])
          elsif opts[:cluster_name]
            cluster_{ name_(opts[:cluster_name])}
          end
          type_ opts[:hwp_id] || 'Server'
          memory opts[:memory] ? opts[:memory].to_s : (512*1024*1024).to_s
          cpu {
            topology( :cores => (opts[:cores] || '1'), :sockets => '1' )
          }
          os{
            boot(:dev=>'network')
            boot(:dev=>'hd')
          }
          display_{
            type_('vnc')
          }
          if(opts[:user_data] && !opts[:user_data].empty?)
            custom_properties {
              custom_property({
                :name => "floppyinject",
                :value => "#{OVIRT::FILEINJECT_PATH}:#{opts[:user_data]}",
                :regexp => "^([^:]+):(.*)$"})
            }
          end
        }
      end
      Nokogiri::XML(builder.to_xml).root.to_s
    end