use of com.xensource.xenapi.SR in project cloudstack by apache.
the class CitrixResourceBase method getLocalEXTSR.
protected SR getLocalEXTSR(final Connection conn) {
try {
final Map<SR, SR.Record> map = SR.getAllRecords(conn);
if (map != null && !map.isEmpty()) {
for (final Map.Entry<SR, SR.Record> entry : map.entrySet()) {
final SR.Record srRec = entry.getValue();
if (SRType.FILE.equals(srRec.type) || SRType.EXT.equals(srRec.type)) {
final Set<PBD> pbds = srRec.PBDs;
if (pbds == null) {
continue;
}
for (final PBD pbd : pbds) {
final Host host = pbd.getHost(conn);
if (!isRefNull(host) && host.getUuid(conn).equals(_host.getUuid())) {
if (!pbd.getCurrentlyAttached(conn)) {
pbd.plug(conn);
}
final SR sr = entry.getKey();
sr.scan(conn);
return sr;
}
}
}
}
}
} catch (final XenAPIException e) {
final String msg = "Unable to get local EXTSR in host:" + _host.getUuid() + e.toString();
s_logger.warn(msg);
} catch (final XmlRpcException e) {
final String msg = "Unable to get local EXTSR in host:" + _host.getUuid() + e.getCause();
s_logger.warn(msg);
}
return null;
}
use of com.xensource.xenapi.SR in project cloudstack by apache.
the class CitrixResourceBase method probeScisiId.
private String probeScisiId(Connection conn, Host host, Map<String, String> deviceConfig, String type, String srNameLabel, String lunid, Map<String, String> smConfig) throws XenAPIException, XmlRpcException {
SR sr = null;
String scsiid = null;
try {
sr = SR.create(conn, host, deviceConfig, new Long(0), srNameLabel, srNameLabel, type, "user", true, smConfig);
} catch (final XenAPIException e) {
final String errmsg = e.toString();
if (errmsg.contains("SR_BACKEND_FAILURE_107")) {
final String[] lun = errmsg.split("<LUN>");
boolean found = false;
for (int i = 1; i < lun.length; i++) {
final int blunindex = lun[i].indexOf("<LUNid>") + 7;
final int elunindex = lun[i].indexOf("</LUNid>");
String ilun = lun[i].substring(blunindex, elunindex);
ilun = ilun.trim();
if (ilun.equals(lunid)) {
final int bscsiindex = lun[i].indexOf("<SCSIid>") + 8;
final int escsiindex = lun[i].indexOf("</SCSIid>");
scsiid = lun[i].substring(bscsiindex, escsiindex);
scsiid = scsiid.trim();
found = true;
break;
}
}
if (!found) {
final String msg = "can not find LUN " + lunid + " in " + errmsg;
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
} else {
final String msg = "Unable to create Iscsi SR " + deviceConfig + " due to " + e.toString();
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
}
}
return scsiid;
}
use of com.xensource.xenapi.SR in project cloudstack by apache.
the class XenServerStorageProcessor method execute.
protected Answer execute(final AttachPrimaryDataStoreCmd cmd) {
final String dataStoreUri = cmd.getDataStore();
final Connection conn = hypervisorResource.getConnection();
try {
final DecodedDataObject obj = Decoder.decode(dataStoreUri);
final DecodedDataStore store = obj.getStore();
final SR sr = hypervisorResource.getStorageRepository(conn, store.getUuid());
hypervisorResource.setupHeartbeatSr(conn, sr, false);
final long capacity = sr.getPhysicalSize(conn);
final long available = capacity - sr.getPhysicalUtilisation(conn);
if (capacity == -1) {
final String msg = "Pool capacity is -1! pool: ";
s_logger.warn(msg);
return new Answer(cmd, false, msg);
}
final AttachPrimaryDataStoreAnswer answer = new AttachPrimaryDataStoreAnswer(cmd);
answer.setCapacity(capacity);
answer.setUuid(sr.getUuid(conn));
answer.setAvailable(available);
return answer;
} catch (final XenAPIException e) {
final String msg = "AttachPrimaryDataStoreCmd add XenAPIException:" + e.toString();
s_logger.warn(msg, e);
return new Answer(cmd, false, msg);
} catch (final Exception e) {
final String msg = "AttachPrimaryDataStoreCmd failed:" + e.getMessage();
s_logger.warn(msg, e);
return new Answer(cmd, false, msg);
}
}
use of com.xensource.xenapi.SR in project cloudstack by apache.
the class XenServerStorageProcessor method getSRByNameLabel.
protected SR getSRByNameLabel(final Connection conn, final String nameLabel) throws BadServerResponse, XenAPIException, XmlRpcException {
final Set<SR> srs = SR.getByNameLabel(conn, nameLabel);
if (srs.size() != 1) {
throw new CloudRuntimeException("storage uuid: " + nameLabel + " is not unique");
}
final SR poolsr = srs.iterator().next();
return poolsr;
}
use of com.xensource.xenapi.SR in project cloudstack by apache.
the class XenServerStorageProcessor method createVolumeFromSnapshot2.
protected Answer createVolumeFromSnapshot2(final CopyCommand cmd) {
try {
final Connection conn = hypervisorResource.getConnection();
final Map<String, String> srcOptions = cmd.getOptions();
final String src_iScsiName = srcOptions.get(DiskTO.IQN);
final String srcStorageHost = srcOptions.get(DiskTO.STORAGE_HOST);
final String srcChapInitiatorUsername = srcOptions.get(DiskTO.CHAP_INITIATOR_USERNAME);
final String srcChapInitiatorSecret = srcOptions.get(DiskTO.CHAP_INITIATOR_SECRET);
final SR srcSr = hypervisorResource.getIscsiSR(conn, src_iScsiName, srcStorageHost, src_iScsiName, srcChapInitiatorUsername, srcChapInitiatorSecret, false);
final Map<String, String> destOptions = cmd.getOptions2();
final String dest_iScsiName = destOptions.get(DiskTO.IQN);
final String destStorageHost = destOptions.get(DiskTO.STORAGE_HOST);
final String destChapInitiatorUsername = destOptions.get(DiskTO.CHAP_INITIATOR_USERNAME);
final String destChapInitiatorSecret = destOptions.get(DiskTO.CHAP_INITIATOR_SECRET);
final SR destSr = hypervisorResource.getIscsiSR(conn, dest_iScsiName, destStorageHost, dest_iScsiName, destChapInitiatorUsername, destChapInitiatorSecret, false);
// there should only be one VDI in this SR
final VDI srcVdi = srcSr.getVDIs(conn).iterator().next();
final VDI vdiCopy = srcVdi.copy(conn, destSr);
final VolumeObjectTO newVol = new VolumeObjectTO();
newVol.setSize(vdiCopy.getVirtualSize(conn));
newVol.setPath(vdiCopy.getUuid(conn));
newVol.setFormat(ImageFormat.VHD);
hypervisorResource.removeSR(conn, srcSr);
hypervisorResource.removeSR(conn, destSr);
return new CopyCmdAnswer(newVol);
} catch (final Exception ex) {
s_logger.warn("Failed to copy snapshot to volume: " + ex.toString(), ex);
return new CopyCmdAnswer(ex.getMessage());
}
}
Aggregations