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 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.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();
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;
}
}
}
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 getAllLocalSrForType.
/**
* This method will return a list of all local SRs.
* An SR is considered local if it meets all of the following criteria:
* <ul>
* <li> {@link Record#shared} is equal to false
* <li> The PBDs of the SR ({@link Record#PBDs}) are connected to host {@link #_host}
* <li> SR type is equal to the {@link SRType} sent as parameter
* </ul>
*/
protected List<SR> getAllLocalSrForType(Connection conn, SRType srType) throws XenAPIException, XmlRpcException {
List<SR> localSrs = new ArrayList<>();
Map<SR, SR.Record> allSrRecords = SR.getAllRecords(conn);
if (MapUtils.isEmpty(allSrRecords)) {
return localSrs;
}
for (Map.Entry<SR, SR.Record> entry : allSrRecords.entrySet()) {
SR.Record srRec = entry.getValue();
if (!srType.equals(srRec.type)) {
continue;
}
if (BooleanUtils.toBoolean(srRec.shared)) {
continue;
}
Set<PBD> pbds = srRec.PBDs;
if (CollectionUtils.isEmpty(pbds)) {
continue;
}
for (PBD pbd : pbds) {
Host host = pbd.getHost(conn);
if (!isRefNull(host) && StringUtils.equals(host.getUuid(conn), _host.getUuid())) {
if (!pbd.getCurrentlyAttached(conn)) {
s_logger.debug(String.format("PBD [%s] of local SR [%s] was unplugged, pluggin it now", pbd.getUuid(conn), srRec.uuid));
pbd.plug(conn);
}
s_logger.debug("Scanning local SR: " + srRec.uuid);
SR sr = entry.getKey();
sr.scan(conn);
localSrs.add(sr);
}
}
}
s_logger.debug(String.format("Found %d local storage of type [%s] for host [%s]", localSrs.size(), srType.toString(), _host.getUuid()));
return localSrs;
}
Aggregations