From e5ccb4206f6958ea8796ab86f02aaa4c3ad72f9f Mon Sep 17 00:00:00 2001 From: Kamil Swiatkowski Date: Fri, 25 Oct 2013 13:18:17 +0200 Subject: [PATCH 1/2] pass arguments to wsman as xml file to allow list arguments --- wsman/provider/wsmancli.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/wsman/provider/wsmancli.py b/wsman/provider/wsmancli.py index 249a1f1..664e2bb 100644 --- a/wsman/provider/wsmancli.py +++ b/wsman/provider/wsmancli.py @@ -23,6 +23,7 @@ # along with WSManAPI. If not, see . import sys +import tempfile from wsman import WSManProvider @@ -735,11 +736,22 @@ def invoke(self, reference, command, arguments, remote=None, raw=False): if isinstance(arguments, basestring): get_command += "--input=\"%s\"" % arguments elif isinstance(arguments, dict): + input_file = tempfile.NamedTemporaryFile() + input_file.write('\n' % (command, reference.resource_uri)) for k,v in arguments.items(): - get_command += '-k \"%s=%s\" ' % (k,v) - + if isinstance(v, list): + for vitem in v: + input_file.write('%s\n' % (k, vitem, k)) + else: + input_file.write('%s\n' % (k, v, k)) + input_file.write('\n' % command) + get_command += '--input \"%s\" ' % input_file.name + + log.debug ("Executing command %s" % get_command) output = self.get_transport().execute(get_command) - + if input_file: + input_file.close() + if raw: return output else: From bf78f777a15beeead96f34c91fc661d38d8f3dc2 Mon Sep 17 00:00:00 2001 From: Kamil Swiatkowski Date: Fri, 25 Oct 2013 14:15:15 +0200 Subject: [PATCH 2/2] debug message with xml file contents --- wsman/provider/wsmancli.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wsman/provider/wsmancli.py b/wsman/provider/wsmancli.py index 664e2bb..62700e1 100644 --- a/wsman/provider/wsmancli.py +++ b/wsman/provider/wsmancli.py @@ -745,10 +745,13 @@ def invoke(self, reference, command, arguments, remote=None, raw=False): else: input_file.write('%s\n' % (k, v, k)) input_file.write('\n' % command) + input_file.seek(0) get_command += '--input \"%s\" ' % input_file.name log.debug ("Executing command %s" % get_command) + log.debug ("XML input file %s content:\n%s" % (input_file.name, input_file.read())) output = self.get_transport().execute(get_command) + if input_file: input_file.close()