Skip to content

Commit 310453f

Browse files
author
Kelven Yang
committed
Use the correct XenServer console streaming URL via XAPI
1 parent 90ec0a6 commit 310453f

4 files changed

Lines changed: 26 additions & 19 deletions

File tree

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyPasswordBasedEncryptor.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import java.security.InvalidKeyException;
1616
import java.security.NoSuchAlgorithmException;
17-
import java.util.UUID;
1817

1918
import javax.crypto.BadPaddingException;
2019
import javax.crypto.Cipher;

‎console-proxy/src/com/cloud/consoleproxy/ConsoleProxyVncClient.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ public void run() {
8383
client.connectTo(getClientHostAddress(), getClientHostPort(), getClientHostPassword());
8484
}
8585
} catch (UnknownHostException e) {
86-
s_logger.error("Unexpected exception: ", e);
86+
s_logger.error("Unexpected exception", e);
87+
break;
8788
} catch (IOException e) {
88-
s_logger.error("Unexpected exception: ", e);
89+
s_logger.error("Unexpected exception (will retry until timeout) ", e);
90+
} catch (Throwable e) {
91+
s_logger.error("Unexpected exception (will retry until timeout) ", e);
8992
}
9093

9194
try {

‎console-proxy/src/com/cloud/consoleproxy/vnc/VncClient.java‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ private void doConnect(String password) throws IOException {
154154
handshake();
155155
authenticate(password);
156156
initialize();
157+
158+
s_logger.info("Connecting to VNC server succeeded, start session");
157159

158160
// Run client-to-server packet sender
159161
sender = new VncClientPacketSender(os, screen, this);
@@ -219,8 +221,10 @@ private void handshake() throws IOException {
219221
String rfbProtocol = new String(buf);
220222

221223
// Server should use RFB protocol 3.x
222-
if (!rfbProtocol.contains(RfbConstants.RFB_PROTOCOL_VERSION_MAJOR))
224+
if (!rfbProtocol.contains(RfbConstants.RFB_PROTOCOL_VERSION_MAJOR)) {
225+
s_logger.error("Cannot handshake with VNC server. Unsupported protocol version: \"" + rfbProtocol + "\".");
223226
throw new RuntimeException("Cannot handshake with VNC server. Unsupported protocol version: \"" + rfbProtocol + "\".");
227+
}
224228

225229
// Send response: we support RFB 3.3 only
226230
String ourProtocolString = RfbConstants.RFB_PROTOCOL_VERSION + "\n";
@@ -243,7 +247,8 @@ private void authenticate(String password) throws IOException {
243247
byte[] buf = new byte[length];
244248
is.readFully(buf);
245249
String reason = new String(buf, RfbConstants.CHARSET);
246-
250+
251+
s_logger.error("Authentication to VNC server is failed. Reason: " + reason);
247252
throw new RuntimeException("Authentication to VNC server is failed. Reason: " + reason);
248253
}
249254

@@ -253,11 +258,13 @@ private void authenticate(String password) throws IOException {
253258
}
254259

255260
case RfbConstants.VNC_AUTH: {
261+
s_logger.info("VNC server requires password authentication");
256262
doVncAuth(password);
257263
break;
258264
}
259265

260266
default:
267+
s_logger.error("Unsupported VNC protocol authorization scheme, scheme code: " + authType + ".");
261268
throw new RuntimeException("Unsupported VNC protocol authorization scheme, scheme code: " + authType + ".");
262269
}
263270
}
@@ -276,6 +283,7 @@ private void doVncAuth(String password) throws IOException {
276283
try {
277284
response = encodePassword(challenge, password);
278285
} catch (Exception e) {
286+
s_logger.error("Cannot encrypt client password to send to server: " + e.getMessage());
279287
throw new RuntimeException("Cannot encrypt client password to send to server: " + e.getMessage());
280288
}
281289

@@ -293,12 +301,15 @@ private void doVncAuth(String password) throws IOException {
293301
}
294302

295303
case RfbConstants.VNC_AUTH_TOO_MANY:
304+
s_logger.error("Connection to VNC server failed: too many wrong attempts.");
296305
throw new RuntimeException("Connection to VNC server failed: too many wrong attempts.");
297306

298307
case RfbConstants.VNC_AUTH_FAILED:
308+
s_logger.error("Connection to VNC server failed: wrong password.");
299309
throw new RuntimeException("Connection to VNC server failed: wrong password.");
300310

301311
default:
312+
s_logger.error("Connection to VNC server failed, reason code: " + authResult);
302313
throw new RuntimeException("Connection to VNC server failed, reason code: " + authResult);
303314
}
304315
}

‎core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@
219219
import com.xensource.xenapi.Task;
220220
import com.xensource.xenapi.Types;
221221
import com.xensource.xenapi.Types.BadServerResponse;
222+
import com.xensource.xenapi.Types.ConsoleProtocol;
222223
import com.xensource.xenapi.Types.IpConfigurationMode;
223224
import com.xensource.xenapi.Types.VmPowerState;
224225
import com.xensource.xenapi.Types.XenAPIException;
@@ -2733,17 +2734,20 @@ record = vm.getRecord(conn);
27332734
protected String getVncUrl(Connection conn, VM vm) {
27342735
VM.Record record;
27352736
Console c;
2736-
String consoleurl;
27372737
try {
27382738
record = vm.getRecord(conn);
27392739
Set<Console> consoles = record.consoles;
2740+
27402741
if (consoles.isEmpty()) {
27412742
s_logger.warn("There are no Consoles available to the vm : " + record.nameDescription);
27422743
return null;
27432744
}
27442745
Iterator<Console> i = consoles.iterator();
2745-
c = i.next();
2746-
consoleurl = c.getLocation(conn);
2746+
while(i.hasNext()) {
2747+
c = i.next();
2748+
if(c.getProtocol(conn) == ConsoleProtocol.RFB)
2749+
return c.getLocation(conn);
2750+
}
27472751
} catch (XenAPIException e) {
27482752
String msg = "Unable to get console url due to " + e.toString();
27492753
s_logger.warn(msg, e);
@@ -2753,18 +2757,8 @@ record = vm.getRecord(conn);
27532757
s_logger.warn(msg, e);
27542758
return null;
27552759
}
2756-
2757-
if (consoleurl.isEmpty())
2758-
return null;
2759-
else
2760-
return consoleurl;
2761-
2762-
2763-
2760+
return null;
27642761
}
2765-
2766-
2767-
27682762

27692763
@Override
27702764
public RebootAnswer execute(RebootCommand cmd) {

0 commit comments

Comments
 (0)