use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method migrateVM.
public void migrateVM(final Connection conn, final Host destHost, final VM vm, final String vmName) throws Exception {
Task task = null;
try {
final Map<String, String> other = new HashMap<String, String>();
other.put("live", "true");
task = vm.poolMigrateAsync(conn, destHost, other);
try {
// poll every 1 seconds
final long timeout = _migratewait * 1000L;
waitForTask(conn, task, 1000, timeout);
checkForSuccess(conn, task);
} catch (final Types.HandleInvalid e) {
if (vm.getResidentOn(conn).equals(destHost)) {
task = null;
return;
}
throw new CloudRuntimeException("migrate VM catch HandleInvalid and VM is not running on dest host");
}
} catch (final XenAPIException e) {
final String msg = "Unable to migrate VM(" + vmName + ") from host(" + _host.getUuid() + ")";
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg);
} finally {
if (task != null) {
try {
task.destroy(conn);
} catch (final Exception e1) {
s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString());
}
}
}
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method destroyPatchVbd.
public void destroyPatchVbd(final Connection conn, final String vmName) throws XmlRpcException, XenAPIException {
try {
if (!vmName.startsWith("r-") && !vmName.startsWith("s-") && !vmName.startsWith("v-")) {
return;
}
final Set<VM> vms = VM.getByNameLabel(conn, vmName);
for (final VM vm : vms) {
final Set<VBD> vbds = vm.getVBDs(conn);
for (final VBD vbd : vbds) {
if (vbd.getType(conn) == Types.VbdType.CD) {
vbd.eject(conn);
vbd.destroy(conn);
break;
}
}
}
} catch (final Exception e) {
s_logger.debug("Cannot destory CD-ROM device for VM " + vmName + " due to " + e.toString(), e);
}
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method callHostPlugin.
public String callHostPlugin(final Connection conn, final String plugin, final String cmd, final String... params) {
final Map<String, String> args = new HashMap<String, String>();
String msg;
try {
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 Host host = Host.getByUuid(conn, _host.getUuid());
final String result = host.callPlugin(conn, plugin, cmd, args);
if (s_logger.isTraceEnabled()) {
s_logger.trace("callHostPlugin Result: " + result);
}
return result.replace("\n", "");
} catch (final XenAPIException e) {
msg = "callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString();
s_logger.warn(msg);
} catch (final XmlRpcException e) {
msg = "callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage();
s_logger.debug(msg);
}
throw new CloudRuntimeException(msg);
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method getIscsiSR.
public SR getIscsiSR(final Connection conn, final String srNameLabel, final String target, String path, final String chapInitiatorUsername, final String chapInitiatorPassword, final boolean resignature, final String srType, final boolean ignoreIntroduceException) {
synchronized (srNameLabel.intern()) {
final Map<String, String> deviceConfig = new HashMap<String, String>();
try {
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
final String[] tmp = path.split("/");
if (tmp.length != 3) {
final String msg = "Wrong iscsi path " + path + " it should be /targetIQN/LUN";
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
final String targetiqn = tmp[1].trim();
final String lunid = tmp[2].trim();
String scsiid = "";
//Throws an exception if SR already exists and is attached
checkIfIscsiSrExisits(conn, srNameLabel, target, targetiqn, lunid);
// We now know the SR is not attached to the XenServer. We probe the
// LUN to see if an SR was already exists on it, if so, we just
// attach it or else we create a brand new SR
deviceConfig.put("target", target);
deviceConfig.put("targetIQN", targetiqn);
if (StringUtils.isNotBlank(chapInitiatorUsername) && StringUtils.isNotBlank(chapInitiatorPassword)) {
deviceConfig.put("chapuser", chapInitiatorUsername);
deviceConfig.put("chappassword", chapInitiatorPassword);
}
final Host host = Host.getByUuid(conn, _host.getUuid());
final Map<String, String> smConfig = new HashMap<String, String>();
SR sr = null;
String pooluuid = null;
if (SRType.LVMOISCSI.equals(srType)) {
scsiid = probeScisiId(conn, host, deviceConfig, srType, srNameLabel, lunid, smConfig);
deviceConfig.put("SCSIid", scsiid);
String result = SR.probe(conn, host, deviceConfig, srType, smConfig);
if (result.indexOf("<UUID>") != -1) {
pooluuid = result.substring(result.indexOf("<UUID>") + 6, result.indexOf("</UUID>")).trim();
}
}
if (pooluuid == null || pooluuid.length() != 36) {
sr = SR.create(conn, host, deviceConfig, new Long(0), srNameLabel, srNameLabel, srType, "user", true, smConfig);
} else {
if (resignature) {
// We resignature the SR for managed storage if needed. At the end of this
// we have an SR which is ready to be attached. For VHDoISCSI SR,
// we don't need to resignature
pooluuid = resignatureIscsiSr(conn, host, deviceConfig, srNameLabel, smConfig);
}
sr = introduceAndPlugIscsiSr(conn, pooluuid, srNameLabel, srType, smConfig, deviceConfig, ignoreIntroduceException);
}
sr.scan(conn);
return sr;
} catch (final XenAPIException e) {
final String msg = "Unable to create Iscsi SR " + deviceConfig + " due to " + e.toString();
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
} catch (final Exception e) {
final String msg = "Unable to create Iscsi SR " + deviceConfig + " due to " + e.getMessage();
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
}
}
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method cleanupTemplateSR.
public void cleanupTemplateSR(final Connection conn) {
Set<PBD> pbds = null;
try {
final Host host = Host.getByUuid(conn, _host.getUuid());
pbds = host.getPBDs(conn);
} catch (final XenAPIException e) {
s_logger.warn("Unable to get the SRs " + e.toString(), e);
throw new CloudRuntimeException("Unable to get SRs " + e.toString(), e);
} catch (final Exception e) {
throw new CloudRuntimeException("Unable to get SRs " + e.getMessage(), e);
}
for (final PBD pbd : pbds) {
SR sr = null;
SR.Record srRec = null;
try {
sr = pbd.getSR(conn);
srRec = sr.getRecord(conn);
} catch (final Exception e) {
s_logger.warn("pbd.getSR get Exception due to ", e);
continue;
}
final String type = srRec.type;
if (srRec.shared) {
continue;
}
if (SRType.NFS.equals(type) || SRType.ISO.equals(type) && srRec.nameDescription.contains("template")) {
try {
pbd.unplug(conn);
pbd.destroy(conn);
sr.forget(conn);
} catch (final Exception e) {
s_logger.warn("forget SR catch Exception due to ", e);
}
}
}
}
Aggregations