diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index 335b63a03a..330c6602b3 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -42,6 +42,8 @@ class VirtualMachineDriver < OpenNebulaDriver :log => "LOG", :attach_disk => "ATTACHDISK", :detach_disk => "DETACHDISK", + :attach_nic => "ATTACHNIC", + :detach_nic => "DETACHNIC", } POLL_ATTRIBUTE = { @@ -89,6 +91,8 @@ class VirtualMachineDriver < OpenNebulaDriver register_action(ACTION[:poll].to_sym, method("poll")) register_action(ACTION[:attach_disk].to_sym, method("attach_disk")) register_action(ACTION[:detach_disk].to_sym, method("detach_disk")) + register_action(ACTION[:attach_nic].to_sym, method("attach_nic")) + register_action(ACTION[:detach_nic].to_sym, method("detach_nic")) end # Decodes the encoded XML driver message received from the core @@ -168,6 +172,16 @@ class VirtualMachineDriver < OpenNebulaDriver send_message(ACTION[:detach_disk],RESULT[:failure],id,error) end + def attach_nic(id, drv_message) + error = "Action not implemented by driver #{self.class}" + send_message(ACTION[:attach_nic],RESULT[:failure],id,error) + end + + def detach_nic(id, drv_message) + error = "Action not implemented by driver #{self.class}" + send_message(ACTION[:detach_nic],RESULT[:failure],id,error) + end + private # Interface to handle the pending events from the ActionManager Interface def delete_running_action(action_id) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 28d65f55b3..dcc2e60af2 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1411,7 +1411,7 @@ void VirtualMachine::get_disk_info(int& max_disk_id, int disk_id; int num_disks; - max_disk_id = 0; + max_disk_id = -1; num_disks = obj_template->get("DISK", disks); @@ -1679,7 +1679,7 @@ void VirtualMachine::get_nic_info(int& max_nic_id) int nic_id; int num_nics; - max_nic_id = 0; + max_nic_id = -1; num_nics = obj_template->get("NIC", nics); diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index 89cfd80b2d..f343053521 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -373,6 +373,44 @@ void VirtualMachineManagerDriver::protocol( lcm->trigger(LifeCycleManager::DETACH_FAILURE, id); } } + else if ( action == "ATTACHNIC" ) + { + Nebula &ne = Nebula::instance(); + LifeCycleManager *lcm = ne.get_lcm(); + + if ( result == "SUCCESS" ) + { + vm->log("VMM", Log::ERROR, "VM NIC Successfully attached."); + + lcm->trigger(LifeCycleManager::ATTACH_NIC_SUCCESS, id); + } + else + { + log_error(vm, os, is, "Error attaching new VM NIC"); + vmpool->update(vm); + + lcm->trigger(LifeCycleManager::ATTACH_NIC_FAILURE, id); + } + } + else if ( action == "DETACHNIC" ) + { + Nebula &ne = Nebula::instance(); + LifeCycleManager *lcm = ne.get_lcm(); + + if ( result == "SUCCESS" ) + { + vm->log("VMM",Log::ERROR,"VM NIC Successfully detached."); + + lcm->trigger(LifeCycleManager::DETACH_NIC_SUCCESS, id); + } + else + { + log_error(vm,os,is,"Error detaching VM NIC"); + vmpool->update(vm); + + lcm->trigger(LifeCycleManager::DETACH_NIC_FAILURE, id); + } + } else if ( action == "POLL" ) { if (result == "SUCCESS") diff --git a/src/vmm_mad/dummy/one_vmm_dummy.rb b/src/vmm_mad/dummy/one_vmm_dummy.rb index 6ada53fcfc..eceb97d040 100755 --- a/src/vmm_mad/dummy/one_vmm_dummy.rb +++ b/src/vmm_mad/dummy/one_vmm_dummy.rb @@ -128,6 +128,18 @@ class DummyDriver < VirtualMachineDriver send_message(ACTION[:detach_disk],result,id) end + def attach_nic(id, drv_message) + result = retrieve_result("attach_nic") + + send_message(ACTION[:attach_nic],result,id) + end + + def detach_nic(id, drv_message) + result = retrieve_result("detach_nic") + + send_message(ACTION[:detach_nic],result,id) + end + def poll(id, drv_message) result = retrieve_result("poll")