mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
B #5024: Implements recover actions for system snapshots. Sets name of
KVM snapshots to OpenNebula's snapshot ID
This commit is contained in:
parent
fc7e809f28
commit
226531e09d
@ -1544,15 +1544,24 @@ public:
|
||||
*
|
||||
* @return 0 on success
|
||||
*/
|
||||
int set_active_snapshot(int snap_id);
|
||||
int set_revert_snapshot(int snap_id);
|
||||
|
||||
int set_delete_snapshot(int snap_id);
|
||||
|
||||
/**
|
||||
* @return the on-going ACTION associated to the ACTIVE snapshot
|
||||
*/
|
||||
string get_snapshot_action();
|
||||
|
||||
/**
|
||||
* Replaces HYPERVISOR_ID for the active SNAPSHOT
|
||||
*
|
||||
* @param hypervisor_id Id returned by the hypervisor for the newly
|
||||
* created snapshot
|
||||
* created snapshot. The no hypervisor_id version uses the snap_id.
|
||||
*/
|
||||
void update_snapshot_id(string& hypervisor_id);
|
||||
void update_snapshot_id(const string& hypervisor_id);
|
||||
|
||||
void update_snapshot_id();
|
||||
|
||||
/**
|
||||
* Cleans the ACTIVE = YES attribute from the snapshots
|
||||
|
@ -1428,8 +1428,7 @@ int DispatchManager::snapshot_revert(int vid, int snap_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
rc = vm->set_active_snapshot(snap_id);
|
||||
rc = vm->set_revert_snapshot(snap_id);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
@ -1492,7 +1491,7 @@ int DispatchManager::snapshot_delete(int vid, int snap_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = vm->set_active_snapshot(snap_id);
|
||||
rc = vm->set_delete_snapshot(snap_id);
|
||||
|
||||
if ( rc == -1 )
|
||||
{
|
||||
|
@ -1166,6 +1166,7 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose,
|
||||
void LifeCycleManager::recover(VirtualMachine * vm, bool success,
|
||||
const RequestAttributes& ra)
|
||||
{
|
||||
string action;
|
||||
LCMAction::Actions lcm_action = LCMAction::NONE;
|
||||
|
||||
switch (vm->get_lcm_state())
|
||||
@ -1350,7 +1351,42 @@ void LifeCycleManager::recover(VirtualMachine * vm, bool success,
|
||||
|
||||
//This is for all snapshot actions (create, delete & revert)
|
||||
case VirtualMachine::HOTPLUG_SNAPSHOT:
|
||||
lcm_action = LCMAction::SNAPSHOT_CREATE_FAILURE;
|
||||
action = vm->get_snapshot_action();
|
||||
|
||||
if ( success )
|
||||
{
|
||||
if ( action == "CREATE" )
|
||||
{
|
||||
vm->update_snapshot_id();
|
||||
|
||||
vmpool->update(vm);
|
||||
|
||||
lcm_action = LCMAction::SNAPSHOT_CREATE_SUCCESS;
|
||||
}
|
||||
else if ( action == "REVERT" )
|
||||
{
|
||||
lcm_action = LCMAction::SNAPSHOT_REVERT_SUCCESS;
|
||||
}
|
||||
else if ( action == "DELETE" )
|
||||
{
|
||||
lcm_action = LCMAction::SNAPSHOT_DELETE_SUCCESS;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( action == "CREATE" )
|
||||
{
|
||||
lcm_action = LCMAction::SNAPSHOT_CREATE_FAILURE;
|
||||
}
|
||||
else if ( action == "REVERT" )
|
||||
{
|
||||
lcm_action = LCMAction::SNAPSHOT_REVERT_FAILURE;
|
||||
}
|
||||
else if ( action == "DELETE" )
|
||||
{
|
||||
lcm_action = LCMAction::SNAPSHOT_DELETE_FAILURE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case VirtualMachine::DISK_SNAPSHOT_POWEROFF:
|
||||
|
@ -62,6 +62,7 @@ int VirtualMachine::new_snapshot(string& name, int& snap_id)
|
||||
snap->replace("HYPERVISOR_ID", "");
|
||||
|
||||
snap->replace("ACTIVE", "YES");
|
||||
snap->replace("ACTION", "CREATE");
|
||||
|
||||
obj_template->set(snap);
|
||||
|
||||
@ -71,20 +72,21 @@ int VirtualMachine::new_snapshot(string& name, int& snap_id)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VirtualMachine::set_active_snapshot(int snap_id)
|
||||
int set_active_snapshot(int snap_id, const string& action,
|
||||
vector<VectorAttribute *>& snaps)
|
||||
{
|
||||
int s_id;
|
||||
|
||||
vector<VectorAttribute *> snaps;
|
||||
int num_snaps = obj_template->get("SNAPSHOT", snaps);
|
||||
vector<VectorAttribute *>::iterator it;
|
||||
|
||||
for(int i=0; i<num_snaps; i++)
|
||||
for ( it = snaps.begin() ; it != snaps.end() ; ++it )
|
||||
{
|
||||
snaps[i]->vector_value("SNAPSHOT_ID", s_id);
|
||||
(*it)->vector_value("SNAPSHOT_ID", s_id);
|
||||
|
||||
if ( s_id == snap_id )
|
||||
{
|
||||
snaps[i]->replace("ACTIVE", "YES");
|
||||
(*it)->replace("ACTIVE", "YES");
|
||||
(*it)->replace("ACTION", action);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -92,19 +94,57 @@ int VirtualMachine::set_active_snapshot(int snap_id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachine::update_snapshot_id(string& hypervisor_id)
|
||||
int VirtualMachine::set_revert_snapshot(int snap_id)
|
||||
{
|
||||
vector<VectorAttribute *> snaps;
|
||||
int num_snaps = obj_template->get("SNAPSHOT", snaps);
|
||||
vector<VectorAttribute *> snaps;
|
||||
|
||||
for(int i=0; i<num_snaps; i++)
|
||||
obj_template->get("SNAPSHOT", snaps);
|
||||
|
||||
return set_active_snapshot(snap_id, "REVERT", snaps);
|
||||
}
|
||||
|
||||
int VirtualMachine::set_delete_snapshot(int snap_id)
|
||||
{
|
||||
vector<VectorAttribute *> snaps;
|
||||
|
||||
obj_template->get("SNAPSHOT", snaps);
|
||||
|
||||
return set_active_snapshot(snap_id, "DELETE", snaps);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachine::update_snapshot_id(const string& hypervisor_id)
|
||||
{
|
||||
vector<VectorAttribute *> snaps;
|
||||
vector<VectorAttribute *>::iterator it;
|
||||
|
||||
obj_template->get("SNAPSHOT", snaps);
|
||||
|
||||
for ( it = snaps.begin() ; it != snaps.end() ; ++it )
|
||||
{
|
||||
if ( snaps[i]->vector_value("ACTIVE") == "YES" )
|
||||
if ( (*it)->vector_value("ACTIVE") == "YES" )
|
||||
{
|
||||
snaps[i]->replace("HYPERVISOR_ID", hypervisor_id);
|
||||
(*it)->replace("HYPERVISOR_ID", hypervisor_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualMachine::update_snapshot_id()
|
||||
{
|
||||
vector<VectorAttribute *> snaps;
|
||||
vector<VectorAttribute *>::iterator it;
|
||||
|
||||
obj_template->get("SNAPSHOT", snaps);
|
||||
|
||||
for ( it = snaps.begin() ; it != snaps.end() ; ++it )
|
||||
{
|
||||
if ( (*it)->vector_value("ACTIVE") == "YES" )
|
||||
{
|
||||
string snap_id = (*it)->vector_value("SNAPSHOT_ID");
|
||||
(*it)->replace("HYPERVISOR_ID", snap_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -113,17 +153,43 @@ void VirtualMachine::update_snapshot_id(string& hypervisor_id)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
string VirtualMachine::get_snapshot_action()
|
||||
{
|
||||
string action;
|
||||
|
||||
vector<VectorAttribute *> snaps;
|
||||
vector<VectorAttribute *>::iterator it;
|
||||
|
||||
obj_template->get("SNAPSHOT", snaps);
|
||||
|
||||
for ( it = snaps.begin() ; it != snaps.end() ; ++it )
|
||||
{
|
||||
if ( (*it)->vector_value("ACTIVE") == "YES" )
|
||||
{
|
||||
action = (*it)->vector_value("ACTION");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualMachine::clear_active_snapshot()
|
||||
{
|
||||
vector<VectorAttribute *> snaps;
|
||||
vector<VectorAttribute *> snaps;
|
||||
vector<VectorAttribute *>::iterator it;
|
||||
|
||||
int num_snaps = obj_template->get("SNAPSHOT", snaps);
|
||||
obj_template->get("SNAPSHOT", snaps);
|
||||
|
||||
for(int i=0; i<num_snaps; i++)
|
||||
for ( it = snaps.begin() ; it != snaps.end() ; ++it )
|
||||
{
|
||||
if ( snaps[i]->vector_value("ACTIVE") == "YES" )
|
||||
if ( (*it)->vector_value("ACTIVE") == "YES" )
|
||||
{
|
||||
snaps[i]->remove("ACTIVE");
|
||||
(*it)->remove("ACTIVE");
|
||||
(*it)->remove("ACTION");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -135,13 +201,15 @@ void VirtualMachine::clear_active_snapshot()
|
||||
void VirtualMachine::delete_active_snapshot()
|
||||
{
|
||||
vector<VectorAttribute *> snaps;
|
||||
int num_snaps = obj_template->get("SNAPSHOT", snaps);
|
||||
vector<VectorAttribute *>::iterator it;
|
||||
|
||||
for(int i=0; i<num_snaps; i++)
|
||||
obj_template->get("SNAPSHOT", snaps);
|
||||
|
||||
for ( it = snaps.begin() ; it != snaps.end() ; ++it )
|
||||
{
|
||||
if ( snaps[i]->vector_value("ACTIVE") == "YES" )
|
||||
if ( (*it)->vector_value("ACTIVE") == "YES" )
|
||||
{
|
||||
delete obj_template->remove(snaps[i]);
|
||||
delete obj_template->remove(*it);
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ source $(dirname $0)/../../scripts_common.sh
|
||||
DOMAIN="$1"
|
||||
SNAP_ID="$2"
|
||||
|
||||
data=`virsh --connect $LIBVIRT_URI snapshot-create-as $DOMAIN`
|
||||
data=`virsh --connect $LIBVIRT_URI snapshot-create-as $DOMAIN --name $SNAP_ID`
|
||||
|
||||
if [ "$?" = "0" ]; then
|
||||
echo "$data" | awk '{print $3}'
|
||||
|
Loading…
Reference in New Issue
Block a user