Use the correct XenServer console streaming URL via XAPI

This commit is contained in:
Kelven Yang 2012-05-02 14:03:20 -07:00
parent 90ec0a6300
commit 310453f993
4 changed files with 26 additions and 19 deletions

View File

@ -14,7 +14,6 @@ package com.cloud.consoleproxy;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;

View File

@ -83,9 +83,12 @@ public class ConsoleProxyVncClient extends ConsoleProxyClientBase {
client.connectTo(getClientHostAddress(), getClientHostPort(), getClientHostPassword());
}
} catch (UnknownHostException e) {
s_logger.error("Unexpected exception: ", e);
s_logger.error("Unexpected exception", e);
break;
} catch (IOException e) {
s_logger.error("Unexpected exception: ", e);
s_logger.error("Unexpected exception (will retry until timeout) ", e);
} catch (Throwable e) {
s_logger.error("Unexpected exception (will retry until timeout) ", e);
}
try {

View File

@ -154,6 +154,8 @@ public class VncClient {
handshake();
authenticate(password);
initialize();
s_logger.info("Connecting to VNC server succeeded, start session");
// Run client-to-server packet sender
sender = new VncClientPacketSender(os, screen, this);
@ -219,8 +221,10 @@ public class VncClient {
String rfbProtocol = new String(buf);
// Server should use RFB protocol 3.x
if (!rfbProtocol.contains(RfbConstants.RFB_PROTOCOL_VERSION_MAJOR))
if (!rfbProtocol.contains(RfbConstants.RFB_PROTOCOL_VERSION_MAJOR)) {
s_logger.error("Cannot handshake with VNC server. Unsupported protocol version: \"" + rfbProtocol + "\".");
throw new RuntimeException("Cannot handshake with VNC server. Unsupported protocol version: \"" + rfbProtocol + "\".");
}
// Send response: we support RFB 3.3 only
String ourProtocolString = RfbConstants.RFB_PROTOCOL_VERSION + "\n";
@ -243,7 +247,8 @@ public class VncClient {
byte[] buf = new byte[length];
is.readFully(buf);
String reason = new String(buf, RfbConstants.CHARSET);
s_logger.error("Authentication to VNC server is failed. Reason: " + reason);
throw new RuntimeException("Authentication to VNC server is failed. Reason: " + reason);
}
@ -253,11 +258,13 @@ public class VncClient {
}
case RfbConstants.VNC_AUTH: {
s_logger.info("VNC server requires password authentication");
doVncAuth(password);
break;
}
default:
s_logger.error("Unsupported VNC protocol authorization scheme, scheme code: " + authType + ".");
throw new RuntimeException("Unsupported VNC protocol authorization scheme, scheme code: " + authType + ".");
}
}
@ -276,6 +283,7 @@ public class VncClient {
try {
response = encodePassword(challenge, password);
} catch (Exception e) {
s_logger.error("Cannot encrypt client password to send to server: " + e.getMessage());
throw new RuntimeException("Cannot encrypt client password to send to server: " + e.getMessage());
}
@ -293,12 +301,15 @@ public class VncClient {
}
case RfbConstants.VNC_AUTH_TOO_MANY:
s_logger.error("Connection to VNC server failed: too many wrong attempts.");
throw new RuntimeException("Connection to VNC server failed: too many wrong attempts.");
case RfbConstants.VNC_AUTH_FAILED:
s_logger.error("Connection to VNC server failed: wrong password.");
throw new RuntimeException("Connection to VNC server failed: wrong password.");
default:
s_logger.error("Connection to VNC server failed, reason code: " + authResult);
throw new RuntimeException("Connection to VNC server failed, reason code: " + authResult);
}
}

View File

@ -219,6 +219,7 @@ import com.xensource.xenapi.Session;
import com.xensource.xenapi.Task;
import com.xensource.xenapi.Types;
import com.xensource.xenapi.Types.BadServerResponse;
import com.xensource.xenapi.Types.ConsoleProtocol;
import com.xensource.xenapi.Types.IpConfigurationMode;
import com.xensource.xenapi.Types.VmPowerState;
import com.xensource.xenapi.Types.XenAPIException;
@ -2733,17 +2734,20 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
protected String getVncUrl(Connection conn, VM vm) {
VM.Record record;
Console c;
String consoleurl;
try {
record = vm.getRecord(conn);
Set<Console> consoles = record.consoles;
if (consoles.isEmpty()) {
s_logger.warn("There are no Consoles available to the vm : " + record.nameDescription);
return null;
}
Iterator<Console> i = consoles.iterator();
c = i.next();
consoleurl = c.getLocation(conn);
while(i.hasNext()) {
c = i.next();
if(c.getProtocol(conn) == ConsoleProtocol.RFB)
return c.getLocation(conn);
}
} catch (XenAPIException e) {
String msg = "Unable to get console url due to " + e.toString();
s_logger.warn(msg, e);
@ -2753,18 +2757,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
s_logger.warn(msg, e);
return null;
}
if (consoleurl.isEmpty())
return null;
else
return consoleurl;
return null;
}
@Override
public RebootAnswer execute(RebootCommand cmd) {