String volumeUUID = null;
SR snapshotSR = null;
if (secondaryStorageUrl == null) {
details += " because the URL passed: " + secondaryStorageUrl + " is invalid.";
return new CreateVolumeFromSnapshotAnswer(cmd, result, details, volumeUUID);
}
try {
SR primaryStorageSR = getSRByNameLabelandHost(conn, primaryStorageNameLabel);
if (primaryStorageSR == null) {
throw new InternalErrorException("Could not create volume from snapshot because the primary Storage SR could not be created from the name label: "
+ primaryStorageNameLabel);
}
// Get the absolute path of the snapshot on the secondary storage.
URI snapshotURI = new URI(secondaryStorageUrl + "/snapshots/" + accountId + "/" + volumeId);
String filename = backedUpSnapshotUuid;
if ( !filename.startsWith("VHD-") && !filename.endsWith(".vhd")) {
filename = backedUpSnapshotUuid + ".vhd";
}
String snapshotPath = snapshotURI.getHost() + ":" + snapshotURI.getPath() + "/" + filename;
String srUuid = primaryStorageSR.getUuid(conn);
volumeUUID = copy_vhd_from_secondarystorage(conn, snapshotPath, srUuid, wait);
result = true;
} catch (XenAPIException e) {
details += " due to " + e.toString();
s_logger.warn(details, e);
} catch (Exception e) {
details += " due to " + e.getMessage();
s_logger.warn(details, e);
} finally {
// In all cases, if the temporary SR was created, forget it.
if (snapshotSR != null) {
removeSR(conn, snapshotSR);
}
}
if (!result) {
// Is this logged at a higher level?
s_logger.error(details);
}
// In all cases return something.
return new CreateVolumeFromSnapshotAnswer(cmd, result, details, volumeUUID);
}