put host into maintenance, if the VM can not migrate, just stop it

This commit is contained in:
anthony 2011-03-23 16:50:21 -07:00
parent 1c9196f9af
commit d2dc0a504b
2 changed files with 22 additions and 13 deletions

View File

@ -2321,6 +2321,12 @@ public abstract class CitrixResourceBase implements ServerResource {
s_logger.warn("Can not fake PV driver for " + vmName);
}
}
if( ! isPVInstalled(conn, vm) ) {
String msg = "Migration failed due to PV drivers is not installed for " + vmName;
s_logger.warn(msg);
return new MigrateAnswer(cmd, false, msg, null);
}
Set<VBD> vbds = vm.getVBDs(conn);
for( VBD vbd : vbds) {
VBD.Record vbdRec = vbd.getRecord(conn);
@ -2329,16 +2335,8 @@ public abstract class CitrixResourceBase implements ServerResource {
break;
}
}
try {
vm.setAffinity(conn, dsthost);
vm.poolMigrate(conn, dsthost, new HashMap<String, String>());
} catch (Types.VmMissingPvDrivers e1) {
// if PV driver is missing, just shutdown the VM
s_logger.warn("VM " + vmName + " is stopped when trying to migrate it because PV driver is missing, Please install PV driver for this VM");
vm.hardShutdown(conn);
vm.destroy(conn);
}
vm.poolMigrate(conn, dsthost, new HashMap<String, String>());
vm.setAffinity(conn, dsthost);
state = State.Stopping;
}
return new MigrateAnswer(cmd, true, "migration succeeded", null);

View File

@ -1156,9 +1156,9 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
excludes.addHost(dest.getHost().getId());
VMInstanceVO vmInstance = null;
try {
vm = migrate(vm, srcHostId, dest);
vmInstance = migrate(vm, srcHostId, dest);
} catch (ResourceUnavailableException e) {
s_logger.debug("Unable to migrate to unavailable " + dest);
} catch (ConcurrentOperationException e) {
@ -1166,9 +1166,20 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
} catch (ManagementServerException e) {
s_logger.debug("Unable to migrate VM: " + e.getMessage());
}
if (vm != null) {
if (vmInstance != null) {
return true;
}
try {
boolean result = advanceStop(vm, true, _accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
return result;
} catch (ResourceUnavailableException e) {
s_logger.debug("Unable to stop VM due to " + e.getMessage());
} catch (ConcurrentOperationException e) {
s_logger.debug("Unable to stop VM due to " + e.getMessage());
} catch (OperationTimedoutException e) {
s_logger.debug("Unable to stop VM due to " + e.getMessage());
}
return false;
}
}