F #4393: Added resize operation for running VMs

This commit is contained in:
Ruben S. Montero committed 2016-12-17 19:30:11 +01:00
1 parent 6f3066ddd1
commit 43df8151ff
7 files changed
+176 -12

No files matched your search

+1 -1
View File
@@ -2176,7 +2176,7 @@ int DispatchManager::disk_resize(
vmpool->update_history(vm);
// vmm->trigger(VirtualMachineManager::DISK_SNAPSHOT_CREATE, vid);
vmm->trigger(VirtualMachineManager::DISK_RESIZE, vid);
break;
default: break;
+119
View File
@@ -203,6 +203,10 @@ void VirtualMachineManager::trigger(Actions action, int _vid)
aname = "DISK_SNAPSHOT_CREATE";
break;
case DISK_RESIZE:
aname = "DISK_RESIZE";
break;
default:
delete vid;
return;
@@ -322,6 +326,10 @@ void VirtualMachineManager::do_action(const string &action, void * arg)
{
disk_snapshot_create_action(vid);
}
else if (action == "DISK_RESIZE")
{
disk_resize_action(vid);
}
else if (action == ACTION_TIMER)
{
timer_action();
@@ -2298,6 +2306,117 @@ error_common:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManager::disk_resize_action(int vid)
{
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
VirtualMachineDisk * disk;
ostringstream os;
string vm_tmpl;
string* drv_msg;
string resize_cmd;
string disk_path;
Nebula& nd = Nebula::instance();
TransferManager * tm = nd.get_tm();
vm = vmpool->get(vid,true);
if (vm == 0)
{
return;
}
if (!vm->hasHistory())
{
goto error_history;
}
vmd = get(vm->get_vmm_mad());
if ( vmd == 0 )
{
goto error_driver;
}
disk = vm->get_resize_disk();
if ( disk == 0 )
{
goto error_disk;
}
tm->resize_command(vm, disk, os);
resize_cmd = os.str();
os.str("");
if ( resize_cmd.empty() )
{
goto error_no_tm_command;
}
os << vm->get_system_dir() << "/disk." << disk->get_disk_id();
disk_path = os.str();
// Invoke driver method
drv_msg = format_message(
vm->get_hostname(),
"",
vm->get_deploy_id(),
"",
"",
"",
resize_cmd,
"",
disk_path,
vm->to_xml(vm_tmpl),
vm->get_ds_id(),
-1);
vmd->disk_resize(vid, *drv_msg);
vm->unlock();
delete drv_msg;
return;
error_disk:
os << "disk_snapshot_create, could not find disk to take snapshot";
goto error_common;
error_history:
os << "disk_snapshot_create, VM has no history";
goto error_common;
error_driver:
os << "disk_snapshot_create, error getting driver " << vm->get_vmm_mad();
goto error_common;
error_no_tm_command:
os << "Cannot set disk for snapshot.";
goto error_common;
error_common:
Nebula &ne = Nebula::instance();
LifeCycleManager * lcm = ne.get_lcm();
lcm->trigger(LifeCycleManager::DISK_SNAPSHOT_FAILURE, vid);
vm->log("VMM", Log::ERROR, os);
vm->unlock();
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManager::attach_nic_action(
int vid)
{
+16
View File
@@ -622,6 +622,22 @@ void VirtualMachineManagerDriver::protocol(const string& message) const
lcm->trigger(LifeCycleManager::DISK_SNAPSHOT_FAILURE, id);
}
}
else if ( action == "RESIZEDISK" )
{
if ( result == "SUCCESS" )
{
vm->log("VMM", Log::INFO, "VM disk successfully resized");
lcm->trigger(LifeCycleManager::DISK_RESIZE_SUCCESS, id);
}
else
{
log_error(vm, os, is, "Error resizing disk");
vmpool->update(vm);
lcm->trigger(LifeCycleManager::DISK_RESIZE_FAILURE, id);
}
}
else if ( action == "CLEANUP" )
{
if ( result == "SUCCESS" )
+6 -3
View File
@@ -789,13 +789,16 @@ class ExecDriver < VirtualMachineDriver
tm_command = ensure_xpath(xml_data, id, action, 'TM_COMMAND') || return
size = xml_data.elements['SIZE'].text.strip
disk_id = xml_data.elements['DISK_ID'].text.strip
size_xpath = "VM/TEMPLATE/DISK[RESIZE='YES']/SIZE"
size = ensure_xpath(xml_data, id, action, size_xpath) || return
disk_id_xpath = "VM/TEMPLATE/DISK[RESIZE='YES']/DISK_ID"
disk_id = ensure_xpath(xml_data, id, action, disk_id_xpath) || return
action = VmmAction.new(self, id, :resize_disk, drv_message)
steps = [
# Perform a PROLOG on the disk
# Perform the resize command
{
:driver => :tm,
:action => :tm_resize,
+1 -1
View File
@@ -1,4 +1,4 @@
#!/bin/bash -x
#!/bin/bash
# -------------------------------------------------------------------------- #
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #