diff --git a/src/vmm/LibVirtDriver.cc b/src/vmm/LibVirtDriver.cc index e91a5fb8fb..74b266a4b0 100644 --- a/src/vmm/LibVirtDriver.cc +++ b/src/vmm/LibVirtDriver.cc @@ -21,12 +21,457 @@ #include #include + int LibVirtDriver::deployment_description( const VirtualMachine * vm, const string& file_name) const { - vm->log("VMM", Log::ERROR, "KVM Driver not yet supported. Work in progress.\n."); - - return 0; + ofstream file; + + int num; + vector attrs; + + string cpu; + string memory; + + string kernel = ""; + string initrd = ""; + string boot = ""; + string root = ""; + + const VectorAttribute * disk; + + string type = ""; + string source = ""; + string target = ""; + string bus = ""; + string ro = ""; + bool readonly; + + const VectorAttribute * nic; + + string mac = ""; + string bridge = ""; + string script = ""; + + const VectorAttribute * graphics; + + string listen = ""; + string port = ""; + string passwd = ""; + + const VectorAttribute * input; + + const VectorAttribute * features; + + string pae = ""; + string acpi = ""; + + const VectorAttribute * raw; + string data; + + // ------------------------------------------------------------------------ + + file.open(file_name.c_str(), ios::out); + + if (file.fail() == true) + { + goto error_file; + } + + // ------------------------------------------------------------------------ + // Starting XML document + // ------------------------------------------------------------------------ + + file << "" << endl; + + // ------------------------------------------------------------------------ + // Domain name + // ------------------------------------------------------------------------ + + file << "\tone-" << vm->get_oid() << "" << endl; + + // ------------------------------------------------------------------------ + // CPU + // ------------------------------------------------------------------------ + + + vm->get_template_attribute("CPU", cpu); + + if(cpu.empty()) + { + get_default("CPU",cpu); + } + + if (!cpu.empty()) + { + file << "\tone-" << cpu << "" << endl; + } + else + { + goto error_cpu; + } + + // ------------------------------------------------------------------------ + // Memory + // ------------------------------------------------------------------------ + + vm->get_template_attribute("MEMORY",memory); + + if (memory.empty()) + { + get_default("MEMORY",memory); + } + + if (!memory.empty()) + { + file << "\t" << memory << "" << endl; + } + else + { + goto error_memory; + } + + // ------------------------------------------------------------------------ + // OS and boot options + // ------------------------------------------------------------------------ + + file << "\t" << endl; + + num = vm->get_template_attribute("OS",attrs); + + if ( num >= 0 ) + { + const VectorAttribute * os; + + os = static_cast(attrs[0]); + + kernel = os->vector_value("KERNEL"); + initrd = os->vector_value("INITRD"); + boot = os->vector_value("BOOT"); + root = os->vector_value("ROOT"); + } + + if ( kernel.empty() ) + { + get_default("OS","KERNEL",kernel); + } + + if ( initrd.empty() ) + { + get_default("OS","INITRD",initrd); + } + + if ( boot.empty() ) + { + get_default("OS","BOOT",boot); + } + + if ( root.empty() ) + { + get_default("OS","ROOT",root); + } + + if ( kernel.empty() ) + { + goto error_kernel; + } + else + { + file << "\t\t" << kernel << "" << endl; + } + + if ( boot.empty() ) + { + goto error_boot; + } + + if ( root.empty() ) + { + goto error_root; + } + else + { + file << "\t\t" << endl; // TODO decide what boot is going to be + file << "\t\troot = /dev/" << root << " ro" << endl; + } + + if ( !initrd.empty() ) + { + file << "\t\t" << initrd << "" << endl; + } + + file << "\t" << endl; + + attrs.clear(); + + // ------------------------------------------------------------------------ + // Disks + // ------------------------------------------------------------------------ + + file << "\t" << endl; + + if (emulator == "kvm") + { + file << "\t\t/usr/bin/kvm" << endl; + } + + num = vm->get_template_attribute("DISK",attrs); + + for (int i=0; i < num ;i++,source="",target="",ro="") + { + disk = static_cast(attrs[i]); + + type = disk->vector_value("TYPE"); + source = disk->vector_value("SOURCE"); + target = disk->vector_value("TARGET"); + ro = disk->vector_value("READONLY"); + bus = disk->vector_value("BUS"); + + if ( source.empty() | target.empty()) + { + goto error_disk; + } + + readonly = false; + + if ( !ro.empty() ) + { + transform(ro.begin(),ro.end(),ro.begin(),(int(*)(int))toupper); + + if ( ro == "YES" ) + { + readonly = true; + } + } + + file << "\t\t" << endl; + file << "\t\t\t" << endl; + file << "\t\t\t" << endl; + + if (!bus.empty()) + { + file << "\t\t\t" << endl; + } + + if (readonly) + { + file << "\t\t\t" << endl; + } + + file << "\t\t" << endl; + } + + attrs.clear(); + + // ------------------------------------------------------------------------ + // Network interfaces + // ------------------------------------------------------------------------ + + num = vm->get_template_attribute("NIC",attrs); + + for(int i=0; i(attrs[i]); + + bridge = nic->vector_value("BRIDGE"); + + if ( bridge.empty() ) + { + file << "\t\t" << endl; + } + else + { + file << "\t\t" << endl; + file << "\t\t\t" << endl; + } + + mac = nic->vector_value("MAC"); + + if( !mac.empty() ) + { + file << "\t\t\t" << endl; + } + + target = nic->vector_value("TARGET"); + + if( !target.empty() ) + { + file << "\t\t\t" << endl; + } + + script = nic->vector_value("SCRIPT"); + + if( !script.empty() ) + { + file << "\t\t\t