Skip to content

Commit 94474af

Browse files
ustcweizhouDaanHoogland
authored andcommitted
consoleproxy: Enable console for vms in Stopping/Migrating state (#3640)
1 parent d981edb commit 94474af

4 files changed

Lines changed: 23 additions & 18 deletions

File tree

server/src/main/java/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,10 @@ public ConsoleProxyVO doAssignProxy(long dataCenterId, long vmId) {
401401
return null;
402402
}
403403

404-
if (vm != null && vm.getState() != State.Starting && vm.getState() != State.Running) {
404+
if (vm != null && vm.getState() != State.Starting && vm.getState() != State.Running
405+
&& vm.getState() != State.Stopping && vm.getState() != State.Migrating) {
405406
if (s_logger.isInfoEnabled()) {
406-
s_logger.info("Detected that vm : " + vmId + " is not currently in starting or running state, we will fail the proxy assignment for it");
407+
s_logger.info("Detected that vm : " + vmId + " is not currently in starting or running or stopping or migrating state, we will fail the proxy assignment for it");
407408
}
408409
return null;
409410
}

server/src/main/java/com/cloud/server/ManagementServerImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2392,7 +2392,12 @@ public Pair<String, Integer> getVncPort(final VirtualMachine vm) {
23922392
s_logger.trace("Trying to retrieve VNC port from agent about VM " + vm.getHostName());
23932393
}
23942394

2395-
final GetVncPortAnswer answer = (GetVncPortAnswer)_agentMgr.easySend(vm.getHostId(), new GetVncPortCommand(vm.getId(), vm.getInstanceName()));
2395+
GetVncPortAnswer answer = null;
2396+
if (vm.getState() == State.Migrating && vm.getLastHostId() != null) {
2397+
answer = (GetVncPortAnswer)_agentMgr.easySend(vm.getLastHostId(), new GetVncPortCommand(vm.getId(), vm.getInstanceName()));
2398+
} else {
2399+
answer = (GetVncPortAnswer)_agentMgr.easySend(vm.getHostId(), new GetVncPortCommand(vm.getId(), vm.getInstanceName()));
2400+
}
23962401
if (answer != null && answer.getResult()) {
23972402
return new Pair<String, Integer>(answer.getAddress(), answer.getPort());
23982403
}

ui/scripts/instances.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,16 +3711,18 @@
37113711
allowedActions.push("resetSSHKeyForVirtualMachine");
37123712
} else if (jsonObj.state == 'Starting') {
37133713
// allowedActions.push("stop");
3714-
if (isAdmin()) {
3715-
allowedActions.push("viewConsole");
3716-
}
37173714
} else if (jsonObj.state == 'Error') {
37183715
allowedActions.push("destroy");
37193716
} else if (jsonObj.state == 'Expunging') {
37203717
if (g_allowUserExpungeRecoverVm) {
37213718
allowedActions.push("expunge");
37223719
}
37233720
}
3721+
3722+
if (jsonObj.state == 'Starting' || jsonObj.state == 'Stopping' || jsonObj.state == 'Migrating') {
3723+
allowedActions.push("viewConsole");
3724+
}
3725+
37243726
return allowedActions;
37253727
}
37263728

ui/scripts/system.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22071,10 +22071,6 @@
2207122071
allowedActions.push("migrate");
2207222072
allowedActions.push("diagnostics");
2207322073
}
22074-
} else if (jsonObj.state == 'Starting') {
22075-
if (isAdmin()) {
22076-
allowedActions.push("viewConsole");
22077-
}
2207822074
} else if (jsonObj.state == 'Stopped') {
2207922075
allowedActions.push("start");
2208022076

@@ -22083,6 +22079,9 @@
2208322079

2208422080
allowedActions.push("remove");
2208522081
}
22082+
if (jsonObj.state == 'Starting' || jsonObj.state == 'Stopping' || jsonObj.state == 'Migrating') {
22083+
allowedActions.push("viewConsole");
22084+
}
2208622085
return allowedActions;
2208722086
}
2208822087

@@ -22095,13 +22094,12 @@
2209522094
allowedActions.push("viewConsole");
2209622095
if (isAdmin())
2209722096
allowedActions.push("migrate");
22098-
} else if (jsonObj.state == 'Starting') {
22099-
if (isAdmin()) {
22100-
allowedActions.push("viewConsole");
22101-
}
2210222097
} else if (jsonObj.state == 'Stopped') {
2210322098
allowedActions.push("start");
2210422099
}
22100+
if (jsonObj.state == 'Starting' || jsonObj.state == 'Stopping' || jsonObj.state == 'Migrating') {
22101+
allowedActions.push("viewConsole");
22102+
}
2210522103
return allowedActions;
2210622104
}
2210722105

@@ -22124,10 +22122,6 @@
2212422122
allowedActions.push("migrate");
2212522123
allowedActions.push("diagnostics");
2212622124
}
22127-
} else if (jsonObj.state == 'Starting') {
22128-
if (isAdmin()) {
22129-
allowedActions.push("viewConsole");
22130-
}
2213122125
} else if (jsonObj.state == 'Stopped') {
2213222126
allowedActions.push("start");
2213322127

@@ -22138,6 +22132,9 @@
2213822132
} else if (jsonObj.state == 'Error') {
2213922133
allowedActions.push("remove");
2214022134
}
22135+
if (jsonObj.state == 'Starting' || jsonObj.state == 'Stopping' || jsonObj.state == 'Migrating') {
22136+
allowedActions.push("viewConsole");
22137+
}
2214122138
return allowedActions;
2214222139
}
2214322140

0 commit comments

Comments
 (0)