@@ -328,15 +328,21 @@ static public Ternary<String, String, String> parseHostInfo(String hostInfo) {
328328
329329 s_logger .info ("Parse host info returned from executing GetVNCPortCommand. host info: " + hostInfo );
330330
331- if (hostInfo != null && hostInfo .startsWith ("consoleurl" )) {
332- String tokens [] = hostInfo .split ("&" );
333-
334- if (hostInfo .length () > 19 && hostInfo .indexOf ('/' , 19 ) > 19 ) {
335- host = hostInfo .substring (19 , hostInfo .indexOf ('/' , 19 )).trim ();
336- tunnelUrl = tokens [0 ].substring ("consoleurl=" .length ());
337- tunnelSession = tokens [1 ].split ("=" )[1 ];
331+ if (hostInfo != null ) {
332+ if (hostInfo .startsWith ("consoleurl" )) {
333+ String tokens [] = hostInfo .split ("&" );
334+
335+ if (hostInfo .length () > 19 && hostInfo .indexOf ('/' , 19 ) > 19 ) {
336+ host = hostInfo .substring (19 , hostInfo .indexOf ('/' , 19 )).trim ();
337+ tunnelUrl = tokens [0 ].substring ("consoleurl=" .length ());
338+ tunnelSession = tokens [1 ].split ("=" )[1 ];
339+ } else {
340+ host = "" ;
341+ }
342+ } else if (hostInfo .startsWith ("instanceId" )) {
343+ host = hostInfo .substring (hostInfo .indexOf ('=' ) + 1 );
338344 } else {
339- host = "" ;
345+ host = hostInfo ;
340346 }
341347 } else {
342348 host = hostInfo ;
@@ -389,28 +395,49 @@ private String composeThumbnailUrl(String rootUrl, VirtualMachine vm, HostVO hos
389395 private String composeConsoleAccessUrl (String rootUrl , VirtualMachine vm , HostVO hostVo ) {
390396 StringBuffer sb = new StringBuffer (rootUrl );
391397 String host = hostVo .getPrivateIpAddress ();
398+ String username = _ms .findDetail (hostVo .getId (), "username" ).getValue ();
399+ String password = _ms .findDetail (hostVo .getId (), "password" ).getValue ();
392400
393401 Pair <String , Integer > portInfo = _ms .getVncPort (vm );
394402 if (s_logger .isDebugEnabled ())
395403 s_logger .debug ("Port info " + portInfo .first ());
396404
397405 Ternary <String , String , String > parsedHostInfo = parseHostInfo (portInfo .first ());
406+ int port = -1 ;
407+ String sid ;
408+
409+ if (portInfo .second () == -9 ) {
410+ //for hyperv
411+ port = 2179 ;
412+ } else {
413+ port = portInfo .second ();
414+ }
398415
416+ sid = vm .getVncPassword ();
399417 UserVmDetailVO details = _userVmDetailsDao .findDetail (vm .getId (), "keyboard" );
400- String sid = vm . getVncPassword ();
418+
401419 String tag = vm .getUuid ();
402- String ticket = genAccessTicket (host , String .valueOf (portInfo .second ()), sid , tag );
420+
421+ String ticket = genAccessTicket (parsedHostInfo .first (), String .valueOf (port ), sid , tag );
403422 ConsoleProxyPasswordBasedEncryptor encryptor = new ConsoleProxyPasswordBasedEncryptor (getEncryptorPassword ());
404423 ConsoleProxyClientParam param = new ConsoleProxyClientParam ();
405424 param .setClientHostAddress (parsedHostInfo .first ());
406- param .setClientHostPort (portInfo . second () );
425+ param .setClientHostPort (port );
407426 param .setClientHostPassword (sid );
408427 param .setClientTag (tag );
409428 param .setTicket (ticket );
429+
410430 if (details != null ) {
411431 param .setLocale (details .getValue ());
412432 }
413- if (parsedHostInfo .second () != null && parsedHostInfo .third () != null ) {
433+
434+ if (portInfo .second () == -9 ) {
435+ //For Hyperv Clinet Host Address will send Instance id
436+ param .setHypervHost (host );
437+ param .setUsername (username );
438+ param .setPassword (password );
439+ }
440+ if (parsedHostInfo .second () != null && parsedHostInfo .third () != null ) {
414441 param .setClientTunnelUrl (parsedHostInfo .second ());
415442 param .setClientTunnelSession (parsedHostInfo .third ());
416443 }
0 commit comments