SR poolsr = null;
Set<SR> srs = SR.getByNameLabel(conn, poolName);
if (srs.size() != 1) {
String msg = "There are " + srs.size() + " SRs with same name: " + poolName;
s_logger.warn(msg);
return new PrimaryStorageDownloadAnswer(msg);
} else {
poolsr = srs.iterator().next();
}
String pUuid = poolsr.getUuid(conn);
boolean isISCSI = IsISCSI(poolsr.getType(conn));
String uuid = copy_vhd_from_secondarystorage(conn, tmplpath, pUuid, wait);
VDI tmpl = getVDIbyUuid(conn, uuid);
VDI snapshotvdi = tmpl.snapshot(conn, new HashMap<String, String>());
String snapshotUuid = snapshotvdi.getUuid(conn);
snapshotvdi.setNameLabel(conn, "Template " + cmd.getName());
String parentuuid = getVhdParent(conn, pUuid, snapshotUuid, isISCSI);
VDI parent = getVDIbyUuid(conn, parentuuid);
Long phySize = parent.getPhysicalUtilisation(conn);
tmpl.destroy(conn);
poolsr.scan(conn);
try{
Thread.sleep(5000);
} catch (Exception e) {
}
return new PrimaryStorageDownloadAnswer(snapshotvdi.getUuid(conn), phySize);
} catch (Exception e) {
String msg = "Catch Exception " + e.getClass().getName() + " on host:" + _host.uuid + " for template: "
+ tmplturl + " due to " + e.toString();
s_logger.warn(msg, e);
return new PrimaryStorageDownloadAnswer(msg);
}
}