use of com.xensource.xenapi.PBD in project cloudstack by apache.
the class CitrixResourceBase method removeSR.
public void removeSR(final Connection conn, final SR sr) {
if (sr == null) {
return;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug(logX(sr, "Removing SR"));
}
for (int i = 0; i < 2; i++) {
try {
final Set<VDI> vdis = sr.getVDIs(conn);
for (final VDI vdi : vdis) {
vdi.forget(conn);
}
Set<PBD> pbds = sr.getPBDs(conn);
for (final PBD pbd : pbds) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(logX(pbd, "Unplugging pbd"));
}
// if (pbd.getCurrentlyAttached(conn)) {
pbd.unplug(conn);
// }
pbd.destroy(conn);
}
pbds = sr.getPBDs(conn);
if (pbds.size() == 0) {
if (s_logger.isDebugEnabled()) {
s_logger.debug(logX(sr, "Forgetting"));
}
sr.forget(conn);
return;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug(logX(sr, "There is still one or more PBDs attached."));
if (s_logger.isTraceEnabled()) {
for (final PBD pbd : pbds) {
s_logger.trace(logX(pbd, " Still attached"));
}
}
}
} catch (final XenAPIException e) {
s_logger.debug(logX(sr, "Catch XenAPIException: " + e.toString()));
} catch (final XmlRpcException e) {
s_logger.debug(logX(sr, "Catch Exception: " + e.getMessage()));
}
}
s_logger.warn(logX(sr, "Unable to remove SR"));
}
use of com.xensource.xenapi.PBD in project cloudstack by apache.
the class CitrixResourceBase method getNfsSR.
public SR getNfsSR(final Connection conn, final String poolid, final String uuid, final String server, String serverpath, final String pooldesc) {
final Map<String, String> deviceConfig = new HashMap<String, String>();
try {
serverpath = serverpath.replace("//", "/");
final Set<SR> srs = SR.getAll(conn);
if (srs != null && !srs.isEmpty()) {
for (final SR sr : srs) {
if (!SRType.NFS.equals(sr.getType(conn))) {
continue;
}
final Set<PBD> pbds = sr.getPBDs(conn);
if (pbds.isEmpty()) {
continue;
}
final PBD pbd = pbds.iterator().next();
final Map<String, String> dc = pbd.getDeviceConfig(conn);
if (dc == null) {
continue;
}
if (dc.get("server") == null) {
continue;
}
if (dc.get("serverpath") == null) {
continue;
}
if (server.equals(dc.get("server")) && serverpath.equals(dc.get("serverpath"))) {
throw new CloudRuntimeException("There is a SR using the same configuration server:" + dc.get("server") + ", serverpath:" + dc.get("serverpath") + " for pool " + uuid + " on host:" + _host.getUuid());
}
}
}
deviceConfig.put("server", server);
deviceConfig.put("serverpath", serverpath);
final Host host = Host.getByUuid(conn, _host.getUuid());
final Map<String, String> smConfig = new HashMap<String, String>();
smConfig.put("nosubdir", "true");
final SR sr = SR.create(conn, host, deviceConfig, new Long(0), uuid, poolid, SRType.NFS.toString(), "user", true, smConfig);
sr.scan(conn);
return sr;
} catch (final XenAPIException e) {
throw new CloudRuntimeException("Unable to create NFS SR " + pooldesc, e);
} catch (final XmlRpcException e) {
throw new CloudRuntimeException("Unable to create NFS SR " + pooldesc, e);
}
}
use of com.xensource.xenapi.PBD in project cloudstack by apache.
the class CitrixResourceBase method checkIfIscsiSrExisits.
private void checkIfIscsiSrExisits(Connection conn, String srNameLabel, String target, String targetiqn, String lunid) throws XenAPIException, XmlRpcException {
final Set<SR> srs = SR.getByNameLabel(conn, srNameLabel);
for (final SR sr : srs) {
if (!(SRType.LVMOISCSI.equals(sr.getType(conn)))) {
continue;
}
final Set<PBD> pbds = sr.getPBDs(conn);
if (pbds.isEmpty()) {
continue;
}
final PBD pbd = pbds.iterator().next();
final Map<String, String> dc = pbd.getDeviceConfig(conn);
if (dc == null) {
continue;
}
if (dc.get("target") == null) {
continue;
}
if (dc.get("targetIQN") == null) {
continue;
}
if (dc.get("lunid") == null) {
continue;
}
if (target.equals(dc.get("target")) && targetiqn.equals(dc.get("targetIQN")) && lunid.equals(dc.get("lunid"))) {
throw new CloudRuntimeException("There is a SR using the same configuration target:" + dc.get("target") + ", targetIQN:" + dc.get("targetIQN") + ", lunid:" + dc.get("lunid") + " for pool " + srNameLabel + "on host:" + _host.getUuid());
}
}
}
use of com.xensource.xenapi.PBD in project cloudstack by apache.
the class CitrixResourceBase method checkSR.
protected boolean checkSR(final Connection conn, final SR sr) {
try {
final SR.Record srr = sr.getRecord(conn);
final Set<PBD> pbds = sr.getPBDs(conn);
if (pbds.size() == 0) {
final String msg = "There is no PBDs for this SR: " + srr.nameLabel + " on host:" + _host.getUuid();
s_logger.warn(msg);
return false;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Checking " + srr.nameLabel + " or SR " + srr.uuid + " on " + _host);
}
if (srr.shared) {
if (SRType.NFS.equals(srr.type)) {
final Map<String, String> smConfig = srr.smConfig;
if (!smConfig.containsKey("nosubdir")) {
smConfig.put("nosubdir", "true");
sr.setSmConfig(conn, smConfig);
}
}
final Host host = Host.getByUuid(conn, _host.getUuid());
boolean found = false;
for (final PBD pbd : pbds) {
final PBD.Record pbdr = pbd.getRecord(conn);
if (host.equals(pbdr.host)) {
if (!pbdr.currentlyAttached) {
pbdPlug(conn, pbd, pbdr.uuid);
}
found = true;
break;
}
}
if (!found) {
final PBD.Record pbdr = srr.PBDs.iterator().next().getRecord(conn);
pbdr.host = host;
pbdr.uuid = "";
final PBD pbd = PBD.create(conn, pbdr);
pbdPlug(conn, pbd, pbd.getUuid(conn));
}
} else {
for (final PBD pbd : pbds) {
final PBD.Record pbdr = pbd.getRecord(conn);
if (!pbdr.currentlyAttached) {
pbdPlug(conn, pbd, pbdr.uuid);
}
}
}
} catch (final Exception e) {
final String msg = "checkSR failed host:" + _host + " due to " + e.toString();
s_logger.warn(msg, e);
return false;
}
return true;
}
use of com.xensource.xenapi.PBD in project cloudstack by apache.
the class CitrixResourceBase method prepareISO.
public void prepareISO(final Connection conn, final String vmName, List<String[]> vmDataList, String configDriveLabel) throws XmlRpcException, XenAPIException {
final Set<VM> vms = VM.getByNameLabel(conn, vmName);
if (vms == null || vms.size() != 1) {
throw new CloudRuntimeException("There are " + (vms == null ? "0" : vms.size()) + " VMs named " + vmName);
}
final VM vm = vms.iterator().next();
if (vmDataList != null) {
// create SR
SR sr = createLocalIsoSR(conn, _configDriveSRName + getHost().getIp());
// 1. create vm data files
createVmdataFiles(vmName, vmDataList, configDriveLabel);
// 2. copy config drive iso to host
copyConfigDriveIsoToHost(conn, sr, vmName);
}
final Set<VBD> vbds = vm.getVBDs(conn);
for (final VBD vbd : vbds) {
final VBD.Record vbdr = vbd.getRecord(conn);
if (vbdr.type == Types.VbdType.CD && vbdr.empty == false && vbdr.userdevice.equals(_attachIsoDeviceNum)) {
final VDI vdi = vbdr.VDI;
final SR sr = vdi.getSR(conn);
final Set<PBD> pbds = sr.getPBDs(conn);
if (pbds == null) {
throw new CloudRuntimeException("There is no pbd for sr " + sr);
}
for (final PBD pbd : pbds) {
final PBD.Record pbdr = pbd.getRecord(conn);
if (pbdr.host.getUuid(conn).equals(_host.getUuid())) {
return;
}
}
sr.setShared(conn, true);
final Host host = Host.getByUuid(conn, _host.getUuid());
final PBD.Record pbdr = pbds.iterator().next().getRecord(conn);
pbdr.host = host;
pbdr.uuid = "";
final PBD pbd = PBD.create(conn, pbdr);
pbdPlug(conn, pbd, pbd.getUuid(conn));
break;
}
}
}
Aggregations