From 97477b914bc43e9cd1baa0972e27353c05a9d6a5 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 30 Sep 2010 23:29:02 +0200 Subject: [PATCH 1/3] Bug: remove unneeded touch form kvm save action --- src/vmm_mad/remotes/kvm/save | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vmm_mad/remotes/kvm/save b/src/vmm_mad/remotes/kvm/save index f9bf8888f8..94cd276dc7 100755 --- a/src/vmm_mad/remotes/kvm/save +++ b/src/vmm_mad/remotes/kvm/save @@ -21,5 +21,4 @@ source $(dirname $0)/kvmrc deploy_id=$1 file=$2 -touch $file virsh --connect $LIBVIRT_URI save $deploy_id $file From d487e496ec70c9bf953c4d204faa249c905b2d3d Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 1 Oct 2010 00:17:45 +0200 Subject: [PATCH 2/3] better touch in kvm save action --- src/vmm_mad/remotes/kvm/save | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/vmm_mad/remotes/kvm/save b/src/vmm_mad/remotes/kvm/save index 94cd276dc7..c6f996dc22 100755 --- a/src/vmm_mad/remotes/kvm/save +++ b/src/vmm_mad/remotes/kvm/save @@ -21,4 +21,9 @@ source $(dirname $0)/kvmrc deploy_id=$1 file=$2 +if [ ! -f $file ]; then + touch $file + chmod 666 $file +fi + virsh --connect $LIBVIRT_URI save $deploy_id $file From 5446e5737e71f17744d1cb9122f9f19b64ae49e1 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 1 Oct 2010 17:12:13 +0200 Subject: [PATCH 3/3] feature #199: split KVM and VMware description file generators --- include/LibVirtDriver.h | 56 +-- .../{LibVirtDriver.cc => LibVirtDriverKVM.cc} | 351 +---------------- src/vmm/LibVirtDriverVMware.cc | 356 ++++++++++++++++++ src/vmm/SConstruct | 3 +- 4 files changed, 394 insertions(+), 372 deletions(-) rename src/vmm/{LibVirtDriver.cc => LibVirtDriverKVM.cc} (64%) create mode 100644 src/vmm/LibVirtDriverVMware.cc diff --git a/include/LibVirtDriver.h b/include/LibVirtDriver.h index 5f4e085d53..974aba5831 100644 --- a/include/LibVirtDriver.h +++ b/include/LibVirtDriver.h @@ -1,18 +1,18 @@ -/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ /* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ -/* not use this file except in compliance with the License. You may obtain */ -/* a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ -/* See the License for the specific language governing permissions and */ -/* limitations under the License. */ -/* -------------------------------------------------------------------------- */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ #ifndef LIBVIRT_DRIVER_H_ #define LIBVIRT_DRIVER_H_ @@ -41,17 +41,31 @@ public: private: int deployment_description( - const VirtualMachine * vm, - const string& file_name) const; - + const VirtualMachine * vm, + const string& file_name) const + { + int rc = -1; + + if (emulator == "kvm") + { + rc = deployment_description_kvm(vm,file_name); + } + else if (emulator == "vmware") + { + rc = deployment_description_vmware(vm,file_name); + } + + return rc; + } + int deployment_description_kvm( - const VirtualMachine * vm, + const VirtualMachine * vm, const string& file_name) const; - + int deployment_description_vmware( - const VirtualMachine * vm, + const VirtualMachine * vm, const string& file_name) const; - + const string emulator; }; diff --git a/src/vmm/LibVirtDriver.cc b/src/vmm/LibVirtDriverKVM.cc similarity index 64% rename from src/vmm/LibVirtDriver.cc rename to src/vmm/LibVirtDriverKVM.cc index 516fec36aa..f40ebbca98 100644 --- a/src/vmm/LibVirtDriver.cc +++ b/src/vmm/LibVirtDriverKVM.cc @@ -21,23 +21,6 @@ #include #include -int LibVirtDriver::deployment_description( - const VirtualMachine * vm, - const string& file_name) const -{ - int rc = -1; - if (emulator == "kvm") - { - rc = deployment_description_kvm(vm,file_name); - } - else if (emulator == "vmware") - { - rc = deployment_description_vmware(vm,file_name); - } - - return rc; -} - int LibVirtDriver::deployment_description_kvm( const VirtualMachine * vm, const string& file_name) const @@ -600,340 +583,8 @@ error_boot: return -1; error_disk: - vm->log("VMM", Log::ERROR, "Wrong target value in DISK."); - file.close(); - return -1; -} - -int LibVirtDriver::deployment_description_vmware( - const VirtualMachine * vm, - const string& file_name) const -{ - ofstream file; - - int num; - vector attrs; - - string vcpu; - string memory; - - int memory_in_kb = 0; - - string arch = ""; - - const VectorAttribute * disk; - - string type = ""; - string target = ""; - string bus = ""; - string ro = ""; - string source = ""; - string datastore = ""; - bool readonly; - - const VectorAttribute * nic; - - string mac = ""; - string bridge = ""; - string script = ""; - string model = ""; - - const VectorAttribute * raw; - string data; - - // ------------------------------------------------------------------------ - - file.open(file_name.c_str(), ios::out); - - if (file.fail() == true) - { - goto error_vmware_file; - } - - // ------------------------------------------------------------------------ - // Starting XML document - // ------------------------------------------------------------------------ - - file << "" << endl; - - // ------------------------------------------------------------------------ - // Domain name - // ------------------------------------------------------------------------ - - file << "\tone-" << vm->get_oid() << "" << endl; - - // ------------------------------------------------------------------------ - // CPU - // ------------------------------------------------------------------------ - - vm->get_template_attribute("VCPU", vcpu); - - if(vcpu.empty()) - { - get_default("VCPU", vcpu); - } - - if (!vcpu.empty()) - { - file << "\t" << vcpu << "" << endl; - } - - // ------------------------------------------------------------------------ - // Memory - // ------------------------------------------------------------------------ - - vm->get_template_attribute("MEMORY",memory); - - if (memory.empty()) - { - get_default("MEMORY",memory); - } - - if (!memory.empty()) - { - memory_in_kb = atoi(memory.c_str()) * 1024; - - file << "\t" << memory_in_kb << "" << endl; - } - else - { - goto error_vmware_memory; - } - - // ------------------------------------------------------------------------ - // OS and boot options - // ------------------------------------------------------------------------ - - num = vm->get_template_attribute("OS",attrs); - - // Get values & defaults - if ( num > 0 ) - { - const VectorAttribute * os; - - os = dynamic_cast(attrs[0]); - - if( os != 0 ) - { - arch = os->vector_value("ARCHITECTURE"); - } - } - - - // Start writing to the file with the info we got - - file << "\t" << endl; - - - if ( arch.empty() ) - { - get_default("OS","ARCH",arch); - } - - if (arch.empty()) - { - goto error_vmware_arch; - } - - file << "\t\thvm" << endl; - - file << "\t" << endl; - - attrs.clear(); - - // ------------------------------------------------------------------------ - // Disks - // ------------------------------------------------------------------------ - - file << "\t" << endl; - - num = vm->get_template_attribute("DISK",attrs); - - if (num!=0) - { - get_default("DATASTORE", datastore); - } - - for (int i=0; i < num ;i++) - { - disk = dynamic_cast(attrs[i]); - - if ( disk == 0 ) - { - continue; - } - - type = disk->vector_value("TYPE"); - target = disk->vector_value("TARGET"); - ro = disk->vector_value("READONLY"); - bus = disk->vector_value("BUS"); - source = disk->vector_value("SOURCE"); - - if (target.empty()) - { - goto error_vmware_disk; - } - - readonly = false; - - if ( !ro.empty() ) - { - transform(ro.begin(),ro.end(),ro.begin(),(int(*)(int))toupper); - - if ( ro == "YES" ) - { - readonly = true; - } - } - - if (type.empty() == false) - { - transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper); - } - - if ( type == "BLOCK" ) - { - file << "\t\t" << endl; - file << "\t\t\t" << endl; - } - else if ( type == "CDROM" ) - { - file << "\t\t" << endl; - file << "\t\t\t" << endl; - } - else - { - file << "\t\t" << endl - << "\t\t\t" << endl; - } - - file << "\t\t\t" << endl; - } - else - { - file << "/>" << 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]); - - if ( nic == 0 ) - { - continue; - } - - bridge = nic->vector_value("BRIDGE"); - mac = nic->vector_value("MAC"); - target = nic->vector_value("TARGET"); - script = nic->vector_value("SCRIPT"); - model = nic->vector_value("MODEL"); - - if ( bridge.empty() ) - { - file << "\t\t" << endl; - } - else - { - file << "\t\t" << endl; - file << "\t\t\t" << endl; - } - - if( !mac.empty() ) - { - file << "\t\t\t" << endl; - } - - if( !target.empty() ) - { - file << "\t\t\t" << endl; - } - - if( !script.empty() ) - { - file << "\t\t\t