cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject cloudstack-cloudmonkey git commit: CLOUDSTACK-8396: Add a new XML display output mode
Date Thu, 23 Apr 2015 14:55:38 GMT
Repository: cloudstack-cloudmonkey
Updated Branches:
  refs/heads/master 6ac7f863e -> c0d734333


CLOUDSTACK-8396: Add a new XML display output mode

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/commit/c0d73433
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/tree/c0d73433
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/diff/c0d73433

Branch: refs/heads/master
Commit: c0d7343336928e31f386eeeef6d82299e150fafc
Parents: 6ac7f86
Author: Rohit Yadav <rohit.yadav@shapeblue.com>
Authored: Thu Apr 23 16:53:44 2015 +0200
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Thu Apr 23 16:53:44 2015 +0200

----------------------------------------------------------------------
 cloudmonkey/cloudmonkey.py | 21 ++++++++++++++++-----
 cloudmonkey/config.py      |  3 +++
 setup.py                   |  3 ++-
 3 files changed, 21 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/c0d73433/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py
index 1576ea4..d37b353 100644
--- a/cloudmonkey/cloudmonkey.py
+++ b/cloudmonkey/cloudmonkey.py
@@ -33,7 +33,9 @@ try:
 
     from cachemaker import loadcache, savecache, monkeycache, splitverbsubject
     from config import __version__, __description__, __projecturl__
+    from config import display_types
     from config import read_config, write_config, config_file, default_profile
+    from dicttoxml import dicttoxml
     from optparse import OptionParser
     from prettytable import PrettyTable
     from printer import monkeyprint
@@ -41,6 +43,7 @@ try:
     from requester import login
     from requester import logout
     from urlparse import urlparse
+    from xml.dom.minidom import parseString
 except ImportError, e:
     print("Import error in %s : %s" % (__name__, e))
     import sys
@@ -246,6 +249,11 @@ class CloudMonkeyShell(cmd.Cmd, object):
                                         ensure_ascii=False,
                                         separators=(',', ': ')))
 
+        def print_result_xml(result):
+            custom_root = "CloudStack-%s" % self.profile.replace(" ", "_")
+            xml = dicttoxml(result, attr_type=False, custom_root=custom_root)
+            self.monkeyprint(parseString(xml).toprettyxml())
+
         def print_result_tabular(result):
             def print_table(printer, toprow):
                 if printer:
@@ -293,6 +301,10 @@ class CloudMonkeyShell(cmd.Cmd, object):
             print_result_json(filtered_result)
             return
 
+        if self.display == "xml":
+            print_result_xml(filtered_result)
+            return
+
         if isinstance(filtered_result, dict):
             print_result_as_dict(filtered_result)
         elif isinstance(filtered_result, list):
@@ -608,7 +620,7 @@ class CloudMonkeyShell(cmd.Cmd, object):
         elif option == "profile":
             return [s for s in self.profile_names if s.startswith(value)]
         elif option == "display":
-            return [s for s in ["default", "table", "json"]
+            return [s for s in display_types
                     if s.startswith(value)]
         elif option in ["asyncblock", "color", "paramcompletion",
                         "verifysslcert"]:
@@ -734,7 +746,6 @@ class CloudMonkeyShell(cmd.Cmd, object):
 
 
 def main():
-    displayTypes = ["json", "table", "default"]
     parser = argparse.ArgumentParser(usage="cloudmonkey [options] [commands]",
                                      description=__description__,
                                      epilog="Try cloudmonkey [help|?]")
@@ -756,8 +767,8 @@ def main():
 
     parser.add_argument("-d", "--display-type",
                         dest="displayType", default=None,
-                        help="output display type, json, table or default",
-                        choices=tuple(displayTypes))
+                        help="output display type, json, xml, table or default",
+                        choices=tuple(display_types))
 
     parser.add_argument("-p", "--profile",
                         dest="serverProfile", default=None,
@@ -771,7 +782,7 @@ def main():
 
     shell = CloudMonkeyShell(sys.argv[0], args.configFile)
 
-    if args.displayType and args.displayType in displayTypes:
+    if args.displayType and args.displayType in display_types:
         shell.set_attr("display", args.displayType)
 
     if args.noblock_async:

http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/c0d73433/cloudmonkey/config.py
----------------------------------------------------------------------
diff --git a/cloudmonkey/config.py b/cloudmonkey/config.py
index c719bff..73b1d4e 100644
--- a/cloudmonkey/config.py
+++ b/cloudmonkey/config.py
@@ -38,6 +38,9 @@ param_type = ['boolean', 'date', 'float', 'integer', 'short', 'list',
 
 iterable_type = ['set', 'list', 'object']
 
+# cloudmonkey display types
+display_types = ["json", "xml", "table", "default"]
+
 config_dir = expanduser('~/.cloudmonkey')
 config_file = expanduser(config_dir + '/config')
 

http://git-wip-us.apache.org/repos/asf/cloudstack-cloudmonkey/blob/c0d73433/setup.py
----------------------------------------------------------------------
diff --git a/setup.py b/setup.py
index 3d0791a..4422328 100644
--- a/setup.py
+++ b/setup.py
@@ -30,10 +30,11 @@ from cloudmonkey import __project__, __projecturl__, __projectemail__
 
 requires = [
               'Pygments>=1.5',
+              'argcomplete',
+              'dicttoxml',
               'prettytable>=0.6',
               'requests',
               'requests-toolbelt',
-              'argcomplete'
             ]
 
 try:


Mime
View raw message