From 1e63cb63c1c8e0179f298d4857af89b81c1d5816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Font=C3=A1n=20Mui=C3=B1os?= Date: Wed, 1 Apr 2009 16:34:45 +0000 Subject: [PATCH] Reindentation and cosmetic changes git-svn-id: http://svn.opennebula.org/one/trunk@443 3034c82b-c49b-4eb3-8279-a7acafdc01c0 --- src/vmm/LibVirtDriver.cc | 696 +++++++++++++------------ src/vmm/SConstruct | 10 +- src/vmm/VirtualMachineManager.cc | 47 +- src/vmm/VirtualMachineManagerDriver.cc | 102 ++-- src/vmm/XMLDriver.cc | 6 +- src/vmm/XenDriver.cc | 178 +++---- 6 files changed, 522 insertions(+), 517 deletions(-) diff --git a/src/vmm/LibVirtDriver.cc b/src/vmm/LibVirtDriver.cc index e53dfdea49..4c4530a40e 100644 --- a/src/vmm/LibVirtDriver.cc +++ b/src/vmm/LibVirtDriver.cc @@ -27,294 +27,295 @@ int LibVirtDriver::deployment_description( const string& file_name) const { - ofstream file; + ofstream file; - int num; - vector attrs; + int num; + vector attrs; - string vcpu; - string memory; + string vcpu; + string memory; - int memory_in_kb = 0; + int memory_in_kb = 0; - string kernel = ""; - string initrd = ""; - string boot = ""; - string root = ""; - string kernel_cmd = ""; - string bootloader = ""; + string kernel = ""; + string initrd = ""; + string boot = ""; + string root = ""; + string kernel_cmd = ""; + string bootloader = ""; - const VectorAttribute * disk; - const VectorAttribute * context; + const VectorAttribute * disk; + const VectorAttribute * context; - string type = ""; - string target = ""; - string bus = ""; - string ro = ""; - bool readonly; + string type = ""; + string target = ""; + string bus = ""; + string ro = ""; + bool readonly; - const VectorAttribute * nic; + const VectorAttribute * nic; - string mac = ""; - string bridge = ""; - string script = ""; + string mac = ""; + string bridge = ""; + string script = ""; - const VectorAttribute * graphics; + const VectorAttribute * graphics; - string listen = ""; - string port = ""; - string passwd = ""; + string listen = ""; + string port = ""; + string passwd = ""; - const VectorAttribute * input; + const VectorAttribute * input; - const VectorAttribute * features; + const VectorAttribute * features; - string pae = ""; - string acpi = ""; + string pae = ""; + string acpi = ""; - const VectorAttribute * raw; - string data; + const VectorAttribute * raw; + string data; - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ - file.open(file_name.c_str(), ios::out); + file.open(file_name.c_str(), ios::out); - if (file.fail() == true) - { - goto error_file; - } + if (file.fail() == true) + { + goto error_file; + } - // ------------------------------------------------------------------------ - // Starting XML document - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // Starting XML document + // ------------------------------------------------------------------------ - file << "" << endl; + file << "" << endl; - // ------------------------------------------------------------------------ - // Domain name - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // Domain name + // ------------------------------------------------------------------------ - file << "\tone-" << vm->get_oid() << "" << endl; + file << "\tone-" << vm->get_oid() << "" << endl; - // ------------------------------------------------------------------------ - // CPU - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // CPU + // ------------------------------------------------------------------------ - vm->get_template_attribute("VCPU", vcpu); + vm->get_template_attribute("VCPU", vcpu); - if(vcpu.empty()) - { - get_default("VCPU", vcpu); - } + if(vcpu.empty()) + { + get_default("VCPU", vcpu); + } - if (!vcpu.empty()) - { - file << "\t" << vcpu << "" << endl; - } + if (!vcpu.empty()) + { + file << "\t" << vcpu << "" << endl; + } - // ------------------------------------------------------------------------ - // Memory - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // Memory + // ------------------------------------------------------------------------ - vm->get_template_attribute("MEMORY",memory); + vm->get_template_attribute("MEMORY",memory); - if (memory.empty()) - { - get_default("MEMORY",memory); - } + if (memory.empty()) + { + get_default("MEMORY",memory); + } - if (!memory.empty()) - { + if (!memory.empty()) + { memory_in_kb = atoi(memory.c_str()) * 1024; - file << "\t" << memory_in_kb << "" << endl; - } - else - { - goto error_memory; - } + file << "\t" << memory_in_kb << "" << endl; + } + else + { + goto error_memory; + } - // ------------------------------------------------------------------------ - // OS and boot options - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // OS and boot options + // ------------------------------------------------------------------------ - file << "\t" << endl; + file << "\t" << endl; - if (emulator == "kvm") - { - file << "\t\thvm" << endl; - } + if (emulator == "kvm") + { + file << "\t\thvm" << endl; + } - num = vm->get_template_attribute("OS",attrs); + num = vm->get_template_attribute("OS",attrs); - // Get values & defaults + // Get values & defaults - if ( num > 0 ) - { - const VectorAttribute * os; + if ( num > 0 ) + { + const VectorAttribute * os; - os = dynamic_cast(attrs[0]); + os = dynamic_cast(attrs[0]); - if( os != 0 ) - { - kernel = os->vector_value("KERNEL"); - initrd = os->vector_value("INITRD"); - boot = os->vector_value("BOOT"); - root = os->vector_value("ROOT"); - kernel_cmd = os->vector_value("KERNEL_CMD"); - bootloader = os->vector_value("BOOTLOADER"); - } - } - - if ( kernel.empty() ) - { - get_default("OS","KERNEL",kernel); - } - - if ( initrd.empty() ) - { - get_default("OS","INITRD",initrd); - } - - if ( bootloader.empty() ) - { - get_default("OS","BOOTLOADER",bootloader); - } - - if ( boot.empty() ) - { - get_default("OS","BOOT",boot); - - if ( boot.empty() ) + if( os != 0 ) { - goto error_boot; + kernel = os->vector_value("KERNEL"); + initrd = os->vector_value("INITRD"); + boot = os->vector_value("BOOT"); + root = os->vector_value("ROOT"); + kernel_cmd = os->vector_value("KERNEL_CMD"); + bootloader = os->vector_value("BOOTLOADER"); } - } + } - if ( root.empty() ) - { - get_default("OS","ROOT",root); - } + if ( kernel.empty() ) + { + get_default("OS","KERNEL",kernel); + } - if ( kernel_cmd.empty() ) - { - get_default("OS","KERNEL_CMD",kernel_cmd); - } + if ( initrd.empty() ) + { + get_default("OS","INITRD",initrd); + } - // Start writing to the file with the info we got + if ( bootloader.empty() ) + { + get_default("OS","BOOTLOADER",bootloader); + } - if ( !kernel.empty() ) - { - file << "\t\t" << kernel << "" << endl; + if ( boot.empty() ) + { + get_default("OS","BOOT",boot); + + if ( boot.empty() ) + { + goto error_boot; + } + } + + if ( root.empty() ) + { + get_default("OS","ROOT",root); + } + + if ( kernel_cmd.empty() ) + { + get_default("OS","KERNEL_CMD",kernel_cmd); + } + + // Start writing to the file with the info we got + + if ( !kernel.empty() ) + { + file << "\t\t" << kernel << "" << endl; if ( !initrd.empty() ) { - file << "\t\t" << initrd << "" << endl; + file << "\t\t" << initrd << "" << endl; } if ( !root.empty() ) { - kernel_cmd = "root=/dev/" + root + " " + kernel_cmd; + kernel_cmd = "root=/dev/" + root + " " + kernel_cmd; } if (!kernel_cmd.empty()) { - file << "\t\t" << kernel_cmd << "" << endl; + file << "\t\t" << kernel_cmd << "" << endl; } - } - else if ( !bootloader.empty() ) - { - file << "\t\t" << bootloader << "" << endl; - } + } + else if ( !bootloader.empty() ) + { + file << "\t\t" << bootloader << "" << endl; + } - file << "\t\t" << endl; + file << "\t\t" << endl; - file << "\t" << endl; + file << "\t" << endl; - attrs.clear(); + attrs.clear(); - // ------------------------------------------------------------------------ - // Disks - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------ + // Disks + // ------------------------------------------------------------------------ - file << "\t" << endl; + file << "\t" << endl; - if (emulator == "kvm") - { - file << "\t\t/usr/bin/kvm" << endl; - } + if (emulator == "kvm") + { + file << "\t\t/usr/bin/kvm" << endl; + } - num = vm->get_template_attribute("DISK",attrs); + num = vm->get_template_attribute("DISK",attrs); - for (int i=0; i < num ;i++,target="",ro="") - { - disk = dynamic_cast(attrs[i]); + for (int i=0; i < num ;i++,target="",ro="") + { + disk = dynamic_cast(attrs[i]); - if ( disk == 0 ) - { - continue; - } + if ( disk == 0 ) + { + continue; + } - type = disk->vector_value("TYPE"); - target = disk->vector_value("TARGET"); - ro = disk->vector_value("READONLY"); - bus = disk->vector_value("BUS"); + type = disk->vector_value("TYPE"); + target = disk->vector_value("TARGET"); + ro = disk->vector_value("READONLY"); + bus = disk->vector_value("BUS"); - if (target.empty()) - { - goto error_disk; - } + if (target.empty()) + { + goto error_disk; + } - readonly = false; + readonly = false; - if ( !ro.empty() ) - { - transform(ro.begin(),ro.end(),ro.begin(),(int(*)(int))toupper); + if ( !ro.empty() ) + { + transform(ro.begin(),ro.end(),ro.begin(),(int(*)(int))toupper); - if ( ro == "YES" ) - { + if ( ro == "YES" ) + { readonly = true; - } - } + } + } - if ( type.empty() ) - { - type = "disk"; - } - else - { + if ( type.empty() ) + { + type = "disk"; + } + else + { string type_=type; - transform(type_.begin(),type_.end(),type_.begin(),(int(*)(int))toupper); + transform(type_.begin(),type_.end(), + type_.begin(),(int(*)(int))toupper); if ( type_ == "SWAP" ) { type="disk"; } - } + } - file << "\t\t" << endl; - file << "\t\t\t" << endl; - file << "\t\t\t" << endl; + file << "\t\t\t" << endl; + file << "\t\t\t" << endl; - } - else - { - file << "/>" << endl; - } + if (!bus.empty()) + { + file << " bus='" << bus << "'/>" << endl; + } + else + { + file << "/>" << endl; + } - if (readonly) - { - file << "\t\t\t" << endl; - } + if (readonly) + { + file << "\t\t\t" << endl; + } - file << "\t\t" << endl; - } + file << "\t\t" << endl; + } - attrs.clear(); + attrs.clear(); // ------------------------------------------------------------------------ // Context Device @@ -347,213 +348,214 @@ int LibVirtDriver::deployment_description( // Network interfaces // ------------------------------------------------------------------------ - num = vm->get_template_attribute("NIC",attrs); + num = vm->get_template_attribute("NIC",attrs); - for(int i=0; i(attrs[i]); + for(int i=0; i(attrs[i]); - if ( nic == 0 ) - { - continue; - } + if ( nic == 0 ) + { + continue; + } - bridge = nic->vector_value("BRIDGE"); + bridge = nic->vector_value("BRIDGE"); - if ( bridge.empty() ) - { - file << "\t\t" << endl; - } - else - { - file << "\t\t" << endl; - file << "\t\t\t" << endl; - } + if ( bridge.empty() ) + { + file << "\t\t" << endl; + } + else + { + file << "\t\t" << endl; + file << "\t\t\t" << endl; + } - mac = nic->vector_value("MAC"); + mac = nic->vector_value("MAC"); - if( !mac.empty() ) - { - file << "\t\t\t" << endl; - } + if( !mac.empty() ) + { + file << "\t\t\t" << endl; + } - target = nic->vector_value("TARGET"); + target = nic->vector_value("TARGET"); - if( !target.empty() ) - { - file << "\t\t\t" << endl; - } + if( !target.empty() ) + { + file << "\t\t\t" << endl; + } - script = nic->vector_value("SCRIPT"); + script = nic->vector_value("SCRIPT"); - if( !script.empty() ) - { - file << "\t\t\t