DaanHoogland commented on a change in pull request #3350: Get Diagnostics:
Download logs and diagnostics data from SSVM, CPVM, Router
URL: https://github.com/apache/cloudstack/pull/3350#discussion_r357233903
##########
File path:
plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
##########
@@ -5604,4 +5607,67 @@ public boolean attachConfigDriveToMigratedVm(Connection
conn, String vmName, Str
}
+ /**
+ * Get Diagnostics Data API
+ * Copy zip file from system vm and copy file directly to secondary storage
+ */
+ public Answer copyDiagnosticsFileToSecondaryStorage(Connection conn,
CopyToSecondaryStorageCommand cmd) {
+ String secondaryStorageUrl = cmd.getSecondaryStorageUrl();
+ String vmIP = cmd.getSystemVmIp();
+ String diagnosticsZipFile = cmd.getFileName();
+
+ String localDir = null;
+ boolean success;
+
+ // Mount Secondary storage
+ String secondaryStorageMountPath = null;
+ try {
+ URI uri = new URI(secondaryStorageUrl);
+ secondaryStorageMountPath = uri.getHost() + ":" + uri.getPath();
+ localDir = "/var/cloud_mount/" +
UUID.nameUUIDFromBytes(secondaryStorageMountPath.getBytes());
+ String mountPoint = mountNfs(conn, secondaryStorageMountPath,
localDir);
+ if (org.apache.commons.lang.StringUtils.isBlank(mountPoint)) {
+ return new CopyToSecondaryStorageAnswer(cmd, false, "Could not
mount secondary storage " + secondaryStorageMountPath + " on host " + localDir);
+ }
+
+ String dataDirectoryInSecondaryStore = localDir + "/" +
DiagnosticsService.DIAGNOSTICS_DIRECTORY;
+ final CopyToSecondaryStorageAnswer answer;
+ final String scpResult = callHostPlugin(conn, "vmops",
"secureCopyToHost", "hostfilepath", dataDirectoryInSecondaryStore,
+ "srcip", vmIP, "srcfilepath",
cmd.getFileName()).toLowerCase();
+
+ if (scpResult.contains("success")) {
+ answer = new CopyToSecondaryStorageAnswer(cmd, true, "File
copied to secondary storage successfully.");
+ } else {
+ answer = new CopyToSecondaryStorageAnswer(cmd, false, "Zip
file " + diagnosticsZipFile.replace("/root/", "") + "could not be copied to
secondary storage due to " + scpResult);
+ }
+ umountNfs(conn, secondaryStorageMountPath, localDir);
+ localDir = null;
+ return answer;
+ } catch (Exception e) {
+ String msg = "Exception caught zip file copy to secondary storage
URI: " + secondaryStorageUrl + "Exception : " + e;
+ s_logger.error(msg);
+ return new CopyToSecondaryStorageAnswer(cmd, false, msg);
+ } finally {
+ if (localDir != null) umountNfs(conn, secondaryStorageMountPath,
localDir);
+ }
+ }
+
+ private String mountNfs(Connection conn, String remoteDir, String
localDir) {
+ if (localDir == null) {
+ localDir = "/var/cloud_mount/" +
UUID.nameUUIDFromBytes(remoteDir.getBytes());
Review comment:
please factor out this hardcoded path segment
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services