}
if ( mConn == null ) {
try {
Connection conn = new Connection(getURL(ipAddress), 5);
Session sess = loginWithPassword(conn, username, password, APIVersion.latest().toString());
Host host = sess.getThisHost(conn);
Boolean hostenabled = host.getEnabled(conn);
if( sess != null ){
try{
Session.logout(conn);
} catch (Exception e) {
}
conn.dispose();
}
if (!hostenabled) {
String msg = "Unable to create master connection, due to master Host " + ipAddress + " is not enabled";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
mConn = new XenServerConnection(getURL(ipAddress), ipAddress, username, password, _retries, _interval, wait);
loginWithPassword(mConn, username, password, APIVersion.latest().toString());
} catch (Types.HostIsSlave e) {
String maddress = e.masterIPAddress;
mConn = new XenServerConnection(getURL(maddress), maddress, username, password, _retries, _interval, wait);
try {
Session session = loginWithPassword(mConn, username, password, APIVersion.latest().toString());
Host host = session.getThisHost(mConn);
if (!host.getEnabled(mConn)) {
String msg = "Unable to create master connection, due to master Host " + maddress + " is not enabled";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}