From 0875bef8338a7deaa098a78c6bd3eb2fc56628ae Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Mon, 11 Jun 2012 12:16:14 +0200 Subject: [PATCH] feature #1288 #1284: Memory and CPU are now mandatory for VMs. Default values have been removed from the driver configuration files --- src/vm/VirtualMachine.cc | 33 +++++++++++++++++++++++---- src/vmm/LibVirtDriverKVM.cc | 5 ---- src/vmm/LibVirtDriverVMware.cc | 5 ---- src/vmm/XenDriver.cc | 5 ---- src/vmm_mad/exec/vmm_exec_kvm.conf | 3 --- src/vmm_mad/exec/vmm_exec_vmware.conf | 7 +++--- src/vmm_mad/exec/vmm_exec_xen.conf | 7 +++--- 7 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index f3db0feb78..b384a27adc 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -203,8 +203,8 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) int rc; string name; - string value; - ostringstream oss; + string value; + ostringstream oss; // ------------------------------------------------------------------------ // Set a name if the VM has not got one and VM_ID @@ -232,6 +232,24 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) this->name = name; + // ------------------------------------------------------------------------ + // Check for CPU and MEMORY attributes + // ------------------------------------------------------------------------ + + get_template_attribute("MEMORY", value); + + if ( value.empty()) + { + goto error_no_memory; + } + + get_template_attribute("CPU", value); + + if ( value.empty()) + { + goto error_no_cpu; + } + // ------------------------------------------------------------------------ // Get network leases // ------------------------------------------------------------------------ @@ -312,9 +330,16 @@ error_leases_rollback: release_network_leases(); goto error_common; +error_no_cpu: + error_str = "CPU attribute missing."; + goto error_common; + +error_no_memory: + error_str = "MEMORY attribute missing."; + goto error_common; + error_name_length: - oss << "NAME is too long; max length is 128 chars."; - error_str = oss.str(); + error_str = "NAME is too long; max length is 128 chars."; goto error_common; error_common: diff --git a/src/vmm/LibVirtDriverKVM.cc b/src/vmm/LibVirtDriverKVM.cc index 4952f733f6..b307f96103 100644 --- a/src/vmm/LibVirtDriverKVM.cc +++ b/src/vmm/LibVirtDriverKVM.cc @@ -131,11 +131,6 @@ int LibVirtDriver::deployment_description_kvm( vm->get_template_attribute("MEMORY",memory); - if (memory.empty()) - { - get_default("MEMORY",memory); - } - if (!memory.empty()) { memory_in_kb = atoi(memory.c_str()) * 1024; diff --git a/src/vmm/LibVirtDriverVMware.cc b/src/vmm/LibVirtDriverVMware.cc index 5161011caf..05b4cff863 100644 --- a/src/vmm/LibVirtDriverVMware.cc +++ b/src/vmm/LibVirtDriverVMware.cc @@ -119,11 +119,6 @@ int LibVirtDriver::deployment_description_vmware( vm->get_template_attribute("MEMORY",memory); - if (memory.empty()) - { - get_default("MEMORY",memory); - } - if (!memory.empty()) { memory_in_kb = atoi(memory.c_str()) * 1024; diff --git a/src/vmm/XenDriver.cc b/src/vmm/XenDriver.cc index 0add29a1d9..7ffa4fa944 100644 --- a/src/vmm/XenDriver.cc +++ b/src/vmm/XenDriver.cc @@ -109,11 +109,6 @@ int XenDriver::deployment_description( vm->get_template_attribute("MEMORY",memory); - if (memory.empty()) - { - get_default("MEMORY",memory); - } - if (!memory.empty()) { file << "memory = '" << memory << "'" << endl; diff --git a/src/vmm_mad/exec/vmm_exec_kvm.conf b/src/vmm_mad/exec/vmm_exec_kvm.conf index e3984f7971..5f3ef0d752 100644 --- a/src/vmm_mad/exec/vmm_exec_kvm.conf +++ b/src/vmm_mad/exec/vmm_exec_kvm.conf @@ -19,8 +19,6 @@ # be overridden in each VM template. Valid atributes are: # - emulator # - os [kernel,initrd,boot,root,kernel_cmd,arch] -# - memory -# - cpu # - vcpu # - features [acpi, pae] # - disk [driver, cache] @@ -29,7 +27,6 @@ #EMULATOR = /usr/libexec/qemu-kvm #VCPU = 1 -#MEMORY = 128 OS = [ boot = "hd", arch = "i686" ] FEATURES = [ PAE = "no", ACPI = "yes" ] diff --git a/src/vmm_mad/exec/vmm_exec_vmware.conf b/src/vmm_mad/exec/vmm_exec_vmware.conf index 5d15d9d114..f0e3e1040e 100644 --- a/src/vmm_mad/exec/vmm_exec_vmware.conf +++ b/src/vmm_mad/exec/vmm_exec_vmware.conf @@ -17,14 +17,13 @@ # Default configuration attributes for the VMware driver # (all domains will use these values as defaults) # Valid atributes: -# - memory -# - cpu +# - vcpu # - os[arch] # - disk[dirver] # - datastore -CPU = 1 -MEMORY = 256 +#VCPU = 1 + OS = [ ARCH = i686 ] DISK = [ DRIVER = file ] diff --git a/src/vmm_mad/exec/vmm_exec_xen.conf b/src/vmm_mad/exec/vmm_exec_xen.conf index d818abbe23..3d4ac94fba 100644 --- a/src/vmm_mad/exec/vmm_exec_xen.conf +++ b/src/vmm_mad/exec/vmm_exec_xen.conf @@ -19,12 +19,11 @@ # be overridden in each VM template. Valid atributes are: # - credit # - os [kernel,initrd,root,kernel_cmd] -# - memory # - vcpu # - disk[driver] -#VCPU = 1 -#MEMORY = 128 -#OS = [ kernel="/vmlinuz", initrd="/initrd.img", root="sda1", kernel_cmd="ro" ] +#VCPU = 1 +#OS = [ kernel="/vmlinuz", initrd="/initrd.img", root="sda1", kernel_cmd="ro" ] + CREDIT = 256 DISK = [ driver = "tap:aio:" ]