use of com.xensource.xenapi.SR in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method getLocalLVMSR.
protected SR getLocalLVMSR(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.LVM.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 LVMSR in host:" + _host.getUuid() + e.toString();
s_logger.warn(msg);
} catch (final XmlRpcException e) {
final String msg = "Unable to get local LVMSR in host:" + _host.getUuid() + e.getCause();
s_logger.warn(msg);
}
return null;
}
use of com.xensource.xenapi.SR in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method createAndAttachConfigDriveIsoForVM.
public boolean createAndAttachConfigDriveIsoForVM(final Connection conn, final VM vm, final List<String[]> vmDataList, final String configDriveLabel) throws XenAPIException, XmlRpcException {
final String vmName = vm.getNameLabel(conn);
// create SR
final SR sr = createLocalIsoSR(conn, _configDriveSRName + _host.getIp());
if (sr == null) {
s_logger.debug("Failed to create local SR for the config drive");
return false;
}
s_logger.debug("Creating vm data files in config drive for vm " + vmName);
// 1. create vm data files
if (!createVmdataFiles(vmName, vmDataList, configDriveLabel)) {
s_logger.debug("Failed to create vm data files in config drive for vm " + vmName);
return false;
}
// 2. copy config drive iso to host
if (!copyConfigDriveIsoToHost(conn, sr, vmName)) {
return false;
}
// 3. attachIsoToVM
if (!attachConfigDriveIsoToVm(conn, vm)) {
return false;
}
return true;
}
use of com.xensource.xenapi.SR in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method getSRByNameLabel.
protected SR getSRByNameLabel(final Connection conn, final String name) throws BadServerResponse, XenAPIException, XmlRpcException {
final Set<SR> srs = SR.getByNameLabel(conn, name);
SR ressr = null;
for (final SR sr : srs) {
final Set<PBD> pbds;
pbds = sr.getPBDs(conn);
for (final PBD pbd : pbds) {
final PBD.Record pbdr = pbd.getRecord(conn);
if (pbdr.host != null) {
ressr = sr;
break;
}
}
}
return ressr;
}
use of com.xensource.xenapi.SR in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method createIsoSRbyURI.
protected SR createIsoSRbyURI(final Connection conn, final URI uri, final String vmName, final boolean shared) {
try {
final Map<String, String> deviceConfig = new HashMap<>();
String path = uri.getPath();
path = path.replace("//", "/");
deviceConfig.put("location", uri.getHost() + ":" + path);
final Host host = Host.getByUuid(conn, _host.getUuid());
final SR sr = SR.create(conn, host, deviceConfig, new Long(0), uri.getHost() + path, "iso", "iso", "iso", shared, new HashMap<>());
sr.setNameLabel(conn, vmName + "-ISO");
sr.setNameDescription(conn, deviceConfig.get("location"));
sr.scan(conn);
return sr;
} catch (final XenAPIException e) {
final String msg = "createIsoSRbyURI failed! mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.toString();
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
} catch (final Exception e) {
final String msg = "createIsoSRbyURI failed! mountpoint: " + uri.getHost() + uri.getPath() + " due to " + e.getMessage();
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
}
}
use of com.xensource.xenapi.SR in project cosmic by MissionCriticalCloud.
the class CitrixResourceBase method prepareManagedStorage.
protected VDI prepareManagedStorage(final Connection conn, final Map<String, String> details, final String path, final String vdiNameLabel) throws Exception {
final SR sr = prepareManagedSr(conn, details);
VDI vdi = getVDIbyUuid(conn, path, false);
final Long volumeSize = Long.parseLong(details.get(DiskTO.VOLUME_SIZE));
if (vdi == null) {
vdi = createVdi(sr, vdiNameLabel, volumeSize);
} else {
// if VDI is not null, it must have already been created, so check
// whether a resize of the volume was performed
// if true, resize the VDI to the volume size
s_logger.info("checking for the resize of the datadisk");
final long vdiVirtualSize = vdi.getVirtualSize(conn);
if (vdiVirtualSize != volumeSize) {
s_logger.info("resizing the data disk (vdi) from vdiVirtualsize: " + vdiVirtualSize + " to volumeSize: " + volumeSize);
try {
vdi.resize(conn, volumeSize);
} catch (final Exception e) {
s_logger.warn("Unable to resize volume", e);
}
}
}
return vdi;
}
Aggregations