mirror of https://github.com/apache/cloudstack.git
Bug 10197: if VM is already running, just return the host it is running on
This commit is contained in:
parent
595f9250b7
commit
93244b5b62
|
|
@ -25,6 +25,7 @@ import com.cloud.agent.api.to.VirtualMachineTO;
|
|||
|
||||
public class StartAnswer extends Answer {
|
||||
VirtualMachineTO vm;
|
||||
String host_guid;
|
||||
|
||||
protected StartAnswer() {
|
||||
}
|
||||
|
|
@ -42,9 +43,20 @@ public class StartAnswer extends Answer {
|
|||
public StartAnswer(StartCommand cmd) {
|
||||
super(cmd, true, null);
|
||||
this.vm = cmd.getVirtualMachine();
|
||||
this.host_guid = null;
|
||||
}
|
||||
|
||||
public StartAnswer(StartCommand cmd, String msg, String guid) {
|
||||
super(cmd, true, msg);
|
||||
this.vm = cmd.getVirtualMachine();
|
||||
this.host_guid = guid;
|
||||
}
|
||||
|
||||
public VirtualMachineTO getVirtualMachine() {
|
||||
return vm;
|
||||
}
|
||||
|
||||
public String getHost_guid() {
|
||||
return host_guid;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1034,13 +1034,17 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
|
|||
State state = State.Stopped;
|
||||
VM vm = null;
|
||||
try {
|
||||
|
||||
Set<VM> vms = VM.getByNameLabel(conn, vmName);
|
||||
if ( vms != null ) {
|
||||
for ( VM v : vms ) {
|
||||
VM.Record vRec = v.getRecord(conn);
|
||||
if ( vRec.powerState == VmPowerState.HALTED ) {
|
||||
v.destroy(conn);
|
||||
} else if ( vRec.powerState == VmPowerState.RUNNING ) {
|
||||
String host = vRec.residentOn.getUuid(conn);
|
||||
String msg = "VM " + vmName + " is runing on host " + host;
|
||||
s_logger.debug(msg);
|
||||
return new StartAnswer(cmd, msg, host);
|
||||
} else {
|
||||
String msg = "There is already a VM having the same name " + vmName + " vm record " + vRec.toString();
|
||||
s_logger.warn(msg);
|
||||
|
|
|
|||
|
|
@ -88,12 +88,7 @@ public interface HostDao extends GenericDao<HostVO, Long> {
|
|||
HostVO findByStorageIpAddressInDataCenter(long dcId, String privateIpAddress);
|
||||
HostVO findByPrivateIpAddressInDataCenter(long dcId, String privateIpAddress);
|
||||
|
||||
/**
|
||||
* find a host by its mac address
|
||||
* @param macAddress
|
||||
* @return HostVO or null if not found.
|
||||
*/
|
||||
public HostVO findByGuid(String macAddress);
|
||||
public HostVO findByGuid(String guid);
|
||||
|
||||
public HostVO findByName(String name);
|
||||
|
||||
|
|
|
|||
|
|
@ -720,8 +720,16 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
|||
|
||||
_agentMgr.send(destHostId, cmds);
|
||||
_workDao.updateStep(work, Step.Started);
|
||||
Answer startAnswer = cmds.getAnswer(StartAnswer.class);
|
||||
StartAnswer startAnswer = cmds.getAnswer(StartAnswer.class);
|
||||
if (startAnswer != null && startAnswer.getResult()) {
|
||||
String host_guid = startAnswer.getHost_guid();
|
||||
if( host_guid != null ) {
|
||||
HostVO finalHost = _hostDao.findByGuid(host_guid);
|
||||
if ( finalHost == null ) {
|
||||
throw new CloudRuntimeException("Host Guid " + host_guid + " doesn't exist in DB, something wrong here");
|
||||
}
|
||||
destHostId = finalHost.getId();
|
||||
}
|
||||
if (vmGuru.finalizeStart(vmProfile, destHostId, cmds, ctx)) {
|
||||
if (!changeState(vm, Event.OperationSucceeded, destHostId, work, Step.Done)) {
|
||||
throw new ConcurrentOperationException("Unable to transition to a new state.");
|
||||
|
|
|
|||
Loading…
Reference in New Issue