@Override public boolean downloadTemplate() { String mountSrcUuid = UUID.randomUUID().toString(); String mount = String.format(mountCommand, srcHost + ":" + srcPath, "/mnt/" + mountSrcUuid); Script.runSimpleBashScript(mount); String downloadDir = getDestPoolPath() + File.separator + getDirectDownloadTempPath(getTemplateId()); setDownloadedFilePath(downloadDir + File.separator + getFileNameFromUrl()); Script.runSimpleBashScript("cp /mnt/" + mountSrcUuid + srcPath + " " + getDownloadedFilePath()); Script.runSimpleBashScript("umount /mnt/" + mountSrcUuid); return true; } }
public NfsDirectTemplateDownloader(String url, String destPool, Long templateId, String checksum) { super(url, destPool, templateId, checksum); parseUrl(); }
/** * Parse url and set srcHost and srcPath */ private void parseUrl() { URI uri = null; String url = getUrl(); try { uri = new URI(UriUtils.encodeURIComponent(url)); if (uri.getScheme() != null && uri.getScheme().equalsIgnoreCase("nfs")) { srcHost = uri.getHost(); srcPath = uri.getPath(); } } catch (URISyntaxException e) { throw new CloudRuntimeException("Invalid NFS url " + url + " caused error: " + e.getMessage()); } }
/** * Get direct template downloader from direct download command and destination pool */ private DirectTemplateDownloader getDirectTemplateDownloaderFromCommand(DirectDownloadCommand cmd, KVMStoragePool destPool) { if (cmd instanceof HttpDirectDownloadCommand) { return new HttpDirectTemplateDownloader(cmd.getUrl(), cmd.getTemplateId(), destPool.getLocalPath(), cmd.getChecksum(), cmd.getHeaders()); } else if (cmd instanceof HttpsDirectDownloadCommand) { return new HttpsDirectTemplateDownloader(cmd.getUrl(), cmd.getTemplateId(), destPool.getLocalPath(), cmd.getChecksum(), cmd.getHeaders()); } else if (cmd instanceof NfsDirectDownloadCommand) { return new NfsDirectTemplateDownloader(cmd.getUrl(), destPool.getLocalPath(), cmd.getTemplateId(), cmd.getChecksum()); } else if (cmd instanceof MetalinkDirectDownloadCommand) { return new MetalinkDirectTemplateDownloader(cmd.getUrl(), destPool.getLocalPath(), cmd.getTemplateId(), cmd.getChecksum(), cmd.getHeaders()); } else { throw new IllegalArgumentException("Unsupported protocol, please provide HTTP(S), NFS or a metalink"); } }