@@ -430,12 +430,23 @@ protected boolean pingdomr(Connection conn, String host, String port) {
430430 }
431431
432432 protected boolean pingXenServer () {
433- Connection conn = getConnection ();
433+ Session slaveSession = null ;
434+ Connection slaveConn = null ;
434435 try {
435- callHostPlugin (conn , "echo" , "main" );
436+ URL slaveUrl = null ;
437+ slaveUrl = _connPool .getURL (_host .ip );
438+ slaveConn = new Connection (slaveUrl , 10 );
439+ slaveSession = _connPool .slaveLocalLoginWithPassword (slaveConn , _username , _password );
436440 return true ;
437441 } catch (Exception e ) {
438- s_logger .debug ("cannot ping host " + _host .ip + " due to " + e .toString (), e );
442+ } finally {
443+ if ( slaveSession != null ){
444+ try {
445+ Session .localLogout (slaveConn );
446+ } catch (Exception e ) {
447+ }
448+ slaveConn .dispose ();
449+ }
439450 }
440451 return false ;
441452 }
@@ -6053,9 +6064,9 @@ protected StorageSubsystemCommandHandler getStorageHandler() {
60536064 }
60546065
60556066 private void CheckXenHostInfo () throws ConfigurationException {
6056- Connection conn = _connPool .getConnect (_host .ip , _username , _password );
6067+ Connection conn = _connPool .slaveConnect (_host .ip , _username , _password );
60576068 if ( conn == null ) {
6058- throw new ConfigurationException ("Can not create connection to " + _host .ip );
6069+ throw new ConfigurationException ("Can not create slave connection to " + _host .ip );
60596070 }
60606071 try {
60616072 Host .Record hostRec = null ;
@@ -6075,7 +6086,7 @@ private void CheckXenHostInfo() throws ConfigurationException {
60756086 }
60766087 } finally {
60776088 try {
6078- Session .logout (conn );
6089+ Session .localLogout (conn );
60796090 } catch (Exception e ) {
60806091 }
60816092 }
@@ -7371,11 +7382,35 @@ protected Answer execute(PoolEjectCommand cmd) {
73717382
73727383 Host .Record hostr = poolr .master .getRecord (conn );
73737384 if (_host .uuid .equals (hostr .uuid )) {
7385+ boolean mastermigrated = false ;
73747386 Map <Host , Host .Record > hostMap = Host .getAllRecords (conn );
7375- if (hostMap .size () > 1 ) {
7376- String msg = "This host is XS master, please designate a new XS master throught XenCenter before you delete this host from CS" ;
7387+ if (hostMap .size () != 1 ) {
7388+ Host newMaster = null ;
7389+ Host .Record newMasterRecord = null ;
7390+ for (Map .Entry <Host , Host .Record > entry : hostMap .entrySet ()) {
7391+ if (_host .uuid .equals (entry .getValue ().uuid )) {
7392+ continue ;
7393+ }
7394+ newMaster = entry .getKey ();
7395+ newMasterRecord = entry .getValue ();
7396+ s_logger .debug ("New master for the XenPool is " + newMasterRecord .uuid + " : " + newMasterRecord .address );
7397+ try {
7398+ _connPool .switchMaster (_host .ip , _host .pool , conn , newMaster , _username , _password , _wait );
7399+ mastermigrated = true ;
7400+ break ;
7401+ } catch (Exception e ) {
7402+ s_logger .warn ("Unable to switch the new master to " + newMasterRecord .uuid + ": " + newMasterRecord .address + " due to " + e .toString ());
7403+ }
7404+ }
7405+ } else {
7406+ s_logger .debug ("This is last host to eject, so don't need to eject: " + hostuuid );
7407+ return new Answer (cmd );
7408+ }
7409+ if ( !mastermigrated ) {
7410+ String msg = "this host is master, and cannot designate a new master" ;
73777411 s_logger .debug (msg );
73787412 return new Answer (cmd , false , msg );
7413+
73797414 }
73807415 }
73817416
0 commit comments