From dd6bcde65b3aea47faa5884d22846070b00cf6bd Mon Sep 17 00:00:00 2001 From: Jayapal Date: Mon, 23 Feb 2015 13:51:20 +0530 Subject: [PATCH] CLOUDSTACK-8298: Update copying large size VR config file in xenserver When there is large size VR configuration (aggregate commands) copying data to VR using vmops plugin was failed because of the ARG_MAX size limitation. The configuration data size is around 300KB. Updated this to create file in host by scp with file contents. This will create file in host. Then copy the file from the host to VR using hte vmops createFileInDomr method. In host file get created in /tmp/ with name VR-.cfg, once it copied to VR this file will be removed. (cherry picked from commit 619f0142555d2245e3fa90036f825525191b31bd) Signed-off-by: Rohit Yadav --- .../resource/CitrixResourceBase.java | 14 ++++++++++--- scripts/vm/hypervisor/xenserver/vmops | 21 ++++++++----------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java index f20017811dc..f24b214cd54 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java @@ -571,9 +571,17 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe @Override public ExecutionResult createFileInVR(String routerIp, String path, String filename, String content) { Connection conn = getConnection(); - String rc = callHostPlugin(conn, "vmops", "createFileInDomr", "domrip", routerIp, "filepath", path + filename, "filecontents", content); - s_logger.debug ("VR Config file " + filename + " got created in VR with ip " + routerIp + " with content \n" + content); - // Fail case would be start with "fail#" + String hostPath = "/tmp/"; + + s_logger.debug("Copying VR with ip " + routerIp +" config file into host "+ _host.ip ); + try { + SshHelper.scpTo(_host.ip, 22, _username, null, _password.peek(), hostPath, content.getBytes(), filename, null); + } catch (Exception e) { + s_logger.warn("scp VR config file into host " + _host.ip + " failed with exception " + e.getMessage().toString()); + } + + String rc = callHostPlugin(conn, "vmops", "createFileInDomr", "domrip", routerIp, "srcfilepath", hostPath + filename, "dstfilepath", path); + s_logger.debug ("VR Config file " + filename + " got created in VR, ip " + routerIp + " with content \n" + content); return new ExecutionResult(rc.startsWith("succ#"), rc.substring(5)); } diff --git a/scripts/vm/hypervisor/xenserver/vmops b/scripts/vm/hypervisor/xenserver/vmops index 59ede97b7d5..8abddff43b2 100755 --- a/scripts/vm/hypervisor/xenserver/vmops +++ b/scripts/vm/hypervisor/xenserver/vmops @@ -215,20 +215,17 @@ def createFile(session, args): @echo def createFileInDomr(session, args): - file_path = args['filepath'] - file_contents = args['filecontents'] + src_filepath = args['srcfilepath'] + dst_path = args['dstfilepath'] domrip = args['domrip'] + txt="" try: - tmpfile = util.pread2(['mktemp']).strip() - f = open(tmpfile, "w") - f.write(file_contents) - f.close() - target = "root@" + domrip + ":" + file_path - txt = util.pread2(['scp','-P','3922','-q','-o','StrictHostKeyChecking=no','-i','/root/.ssh/id_rsa.cloud',tmpfile, target]) - util.pread2(['rm',tmpfile]) + target = "root@" + domrip + ":" + dst_path + txt = util.pread2(['scp','-P','3922','-q','-o','StrictHostKeyChecking=no','-i','/root/.ssh/id_rsa.cloud',src_filepath, target]) + util.pread2(['rm',src_filepath]) txt = 'succ#' + txt except: - logging.debug("failed to create file " + file_path + " in VR, contain: " + file_contents) + logging.debug("failed to copy file " + src_filepath + " from host to VR with ip " + domrip) txt = 'fail#' + txt return txt @@ -1497,8 +1494,8 @@ if __name__ == "__main__": "destroy_network_rules_for_vm":destroy_network_rules_for_vm, "default_network_rules_systemvm":default_network_rules_systemvm, "network_rules_vmSecondaryIp":network_rules_vmSecondaryIp, - "get_rule_logs_for_vms":get_rule_logs_for_vms, - "add_to_VCPUs_params_live":add_to_VCPUs_params_live, + "get_rule_logs_for_vms":get_rule_logs_for_vms, + "add_to_VCPUs_params_live":add_to_VCPUs_params_live, "setLinkLocalIP":setLinkLocalIP, "cleanup_rules":cleanup_rules, "createFileInDomr":createFileInDomr,