use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method getLowestAvailableVIFDeviceNum.
public String getLowestAvailableVIFDeviceNum(final Connection conn, final VM vm) {
String vmName = "";
try {
vmName = vm.getNameLabel(conn);
final List<Integer> usedDeviceNums = new ArrayList<Integer>();
final Set<VIF> vifs = vm.getVIFs(conn);
final Iterator<VIF> vifIter = vifs.iterator();
while (vifIter.hasNext()) {
final VIF vif = vifIter.next();
try {
final String deviceId = vif.getDevice(conn);
if (vm.getIsControlDomain(conn) || vif.getCurrentlyAttached(conn)) {
usedDeviceNums.add(Integer.valueOf(deviceId));
} else {
s_logger.debug("Found unplugged VIF " + deviceId + " in VM " + vmName + " destroy it");
vif.destroy(conn);
}
} catch (final NumberFormatException e) {
final String msg = "Obtained an invalid value for an allocated VIF device number for VM: " + vmName;
s_logger.debug(msg, e);
throw new CloudRuntimeException(msg);
}
}
for (Integer i = 0; i < _maxNics; i++) {
if (!usedDeviceNums.contains(i)) {
s_logger.debug("Lowest available Vif device number: " + i + " for VM: " + vmName);
return i.toString();
}
}
} catch (final XmlRpcException e) {
final String msg = "Caught XmlRpcException: " + e.getMessage();
s_logger.warn(msg, e);
} catch (final XenAPIException e) {
final String msg = "Caught XenAPIException: " + e.toString();
s_logger.warn(msg, e);
}
throw new CloudRuntimeException("Could not find available VIF slot in VM with name: " + vmName);
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method introduceAndPlugIscsiSr.
private SR introduceAndPlugIscsiSr(Connection conn, String pooluuid, String srNameLabel, String type, Map<String, String> smConfig, Map<String, String> deviceConfig, boolean ignoreIntroduceException) throws XmlRpcException, XenAPIException {
SR sr = null;
try {
sr = SR.introduce(conn, pooluuid, srNameLabel, srNameLabel, type, "user", true, smConfig);
} catch (final XenAPIException ex) {
if (ignoreIntroduceException) {
return sr;
}
throw ex;
}
final Set<Host> setHosts = Host.getAll(conn);
if (setHosts == null) {
final String msg = "Unable to create iSCSI SR " + deviceConfig + " due to hosts not available.";
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
for (final Host currentHost : setHosts) {
final PBD.Record rec = new PBD.Record();
rec.deviceConfig = deviceConfig;
rec.host = currentHost;
rec.SR = sr;
final PBD pbd = PBD.create(conn, rec);
pbd.plug(conn);
}
return sr;
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class XenServerConnectionPool method loginWithPassword.
protected Session loginWithPassword(Connection conn, String username, Queue<String> password, String version) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.loginWithPassword(conn, username, password.peek(), APIVersion.latest().toString());
logged_in = true;
} catch (BadServerResponse e) {
logged_in = false;
ex = e;
} catch (XenAPIException e) {
logged_in = false;
ex = e;
} catch (XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
}
}
}
return s;
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class XenServerConnectionPool method slaveLocalLoginWithPassword.
protected Session slaveLocalLoginWithPassword(Connection conn, String username, Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.slaveLocalLoginWithPassword(conn, username, password.peek());
logged_in = true;
} catch (BadServerResponse e) {
logged_in = false;
ex = e;
} catch (XenAPIException e) {
logged_in = false;
ex = e;
} catch (XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
break;
}
}
}
return s;
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method callHostPluginThroughMaster.
protected String callHostPluginThroughMaster(final Connection conn, final String plugin, final String cmd, final String... params) {
final Map<String, String> args = new HashMap<String, String>();
try {
final Map<Pool, Pool.Record> poolRecs = Pool.getAllRecords(conn);
if (poolRecs.size() != 1) {
throw new CloudRuntimeException("There are " + poolRecs.size() + " pool for host :" + _host.getUuid());
}
final Host master = poolRecs.values().iterator().next().master;
for (int i = 0; i < params.length; i += 2) {
args.put(params[i], params[i + 1]);
}
if (s_logger.isTraceEnabled()) {
s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args));
}
final String result = master.callPlugin(conn, plugin, cmd, args);
if (s_logger.isTraceEnabled()) {
s_logger.trace("callHostPlugin Result: " + result);
}
return result.replace("\n", "");
} catch (final Types.HandleInvalid e) {
s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle);
} catch (final XenAPIException e) {
s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e);
} catch (final XmlRpcException e) {
s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage(), e);
}
return null;
}
Aggregations