1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-29 18:50:08 +03:00

Feature #3496: Disk/nic attach/detach actions create a new history record

This commit is contained in:
Carlos Martín 2015-04-21 15:35:07 +02:00
parent 3f0a7fc0cd
commit d3b9969c71
6 changed files with 171 additions and 24 deletions

View File

@ -57,7 +57,11 @@ public:
RESCHED_ACTION = 17,
UNRESCHED_ACTION = 18,
POWEROFF_ACTION = 19,
POWEROFF_HARD_ACTION = 20
POWEROFF_HARD_ACTION = 20,
DISK_ATTACH_ACTION = 21,
DISK_DETACH_ACTION = 22,
NIC_ATTACH_ACTION = 23,
NIC_DETACH_ACTION = 24
};
static string action_to_str(VMAction action)
@ -126,6 +130,18 @@ public:
case POWEROFF_HARD_ACTION:
st = "poweroff-hard";
break;
case DISK_ATTACH_ACTION:
st = "disk-attach";
break;
case DISK_DETACH_ACTION:
st = "disk-detach";
break;
case NIC_ATTACH_ACTION:
st = "nic-attach";
break;
case NIC_DETACH_ACTION:
st = "nic-detach";
break;
case NONE_ACTION:
st = "none";
break;
@ -216,6 +232,22 @@ public:
{
action = POWEROFF_HARD_ACTION;
}
else if (st == "disk-attach")
{
action = DISK_ATTACH_ACTION;
}
else if (st == "disk-detach")
{
action = DISK_DETACH_ACTION;
}
else if (st == "nic-attach")
{
action = NIC_ATTACH_ACTION;
}
else if (st == "nic-detach")
{
action = NIC_DETACH_ACTION;
}
else
{
action = NONE_ACTION;

View File

@ -61,6 +61,10 @@
UNRESCHED_ACTION = 18
POWEROFF_ACTION = 19
POWEROFF_HARD_ACTION = 20
DISK_ATTACH_ACTION = 21
DISK_DETACH_ACTION = 22
NIC_ATTACH_ACTION = 23
NIC_DETACH_ACTION = 24
-->
<xs:element name="ACTION" type="xs:integer"/>

View File

@ -165,6 +165,10 @@
UNRESCHED_ACTION = 18
POWEROFF_ACTION = 19
POWEROFF_HARD_ACTION = 20
DISK_ATTACH_ACTION = 21
DISK_DETACH_ACTION = 22
NIC_ATTACH_ACTION = 23
NIC_DETACH_ACTION = 24
-->
<xs:element name="ACTION" type="xs:integer"/>
</xs:sequence>

View File

@ -1149,17 +1149,40 @@ int DispatchManager::attach(int vid,
NebulaLog::log("DiM", Log::ERROR, error_str);
return -1;
}
else
{
vm->set_attach_disk(disk);
}
vmpool->update(vm);
// Set the VM info in the history before the disk is attached to the
// VM template
vm->set_vm_info();
vm->unlock();
vm->set_attach_disk(disk);
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
{
time_t the_time = time(0);
// Close current history record
vm->set_running_etime(the_time);
vm->set_etime(the_time);
vm->set_action(History::DISK_ATTACH_ACTION);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record
vm->cp_history();
vm->set_stime(the_time);
vm->set_running_stime(the_time);
vmpool->update_history(vm);
//-----------------------------------------------
vmm->trigger(VirtualMachineManager::ATTACH,vid);
}
else
@ -1167,6 +1190,10 @@ int DispatchManager::attach(int vid,
tm->trigger(TransferManager::PROLOG_ATTACH, vid);
}
vmpool->update(vm);
vm->unlock();
return 0;
}
@ -1220,32 +1247,54 @@ int DispatchManager::detach(
return -1;
}
vm->set_resched(false);
if ( vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
time_t the_time = time(0);
// Close current history record
vm->set_vm_info();
vm->set_running_etime(the_time);
vm->set_etime(the_time);
vm->set_action(History::DISK_DETACH_ACTION);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record
vm->cp_history();
vm->set_stime(the_time);
vm->set_running_stime(the_time);
vmpool->update_history(vm);
//---------------------------------------------------
vm->set_state(VirtualMachine::HOTPLUG);
vmm->trigger(VirtualMachineManager::DETACH,vid);
}
else
{
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::HOTPLUG_EPILOG_POWEROFF);
}
vm->set_resched(false);
tm->trigger(TransferManager::EPILOG_DETACH, vid);
}
vmpool->update(vm);
vm->unlock();
if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG )
{
vmm->trigger(VirtualMachineManager::DETACH,vid);
}
else
{
tm->trigger(TransferManager::EPILOG_DETACH, vid);
}
return 0;
}
@ -1573,13 +1622,40 @@ int DispatchManager::attach_nic(
return -1;
}
else
{
vm->set_attach_nic(nic, sg_rules);
}
// Set the VM info in the history before the nic is attached to the
// VM template
vm->set_vm_info();
vm->set_attach_nic(nic, sg_rules);
if (vm->get_lcm_state() == VirtualMachine::HOTPLUG_NIC)
{
time_t the_time = time(0);
// Close current history record
vm->set_running_etime(the_time);
vm->set_etime(the_time);
vm->set_action(History::NIC_ATTACH_ACTION);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record
vm->cp_history();
vm->set_stime(the_time);
vm->set_running_stime(the_time);
vmpool->update_history(vm);
//-----------------------------------------------
vmm->trigger(VirtualMachineManager::ATTACH_NIC,vid);
}
else
@ -1648,6 +1724,31 @@ int DispatchManager::detach_nic(
if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
time_t the_time = time(0);
// Close current history record
vm->set_vm_info();
vm->set_running_etime(the_time);
vm->set_etime(the_time);
vm->set_action(History::NIC_DETACH_ACTION);
vm->set_reason(History::USER);
vmpool->update_history(vm);
// Open a new history record
vm->cp_history();
vm->set_stime(the_time);
vm->set_running_stime(the_time);
vmpool->update_history(vm);
vm->set_state(VirtualMachine::HOTPLUG_NIC);
vm->set_resched(false);
@ -1656,6 +1757,8 @@ int DispatchManager::detach_nic(
vm->unlock();
//---------------------------------------------------
vmm->trigger(VirtualMachineManager::DETACH_NIC,vid);
}
else

View File

@ -164,7 +164,7 @@ module OpenNebula
HISTORY_ACTION=%w{none migrate live-migrate shutdown shutdown-hard
undeploy undeploy-hard hold release stop suspend resume boot delete
delete-recreate reboot reboot-hard resched unresched poweroff
poweroff-hard}
poweroff-hard disk-attach disk-detach nic-attach nic-detach}
EXTERNAL_IP_ATTRS = [
'GUEST_IP',

View File

@ -208,7 +208,11 @@ var OpenNebula = {
"resched",
"unresched",
"poweroff",
"poweroff-hard"][value]);
"poweroff-hard",
"disk-attach",
"disk-detach",
"nic-attach",
"nic-detach"][value]);
break;
default:
return value;