diff --git a/CHANGES.md b/CHANGES.md index 013d837a..6d5f08a0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,11 @@ Apache CloudStack CloudMonkey Changelog --------------------------------------- +Version 5.3.4 +============= +This release includes +- Allow ssl version to be negotiated automatically + Version 5.3.3 ============= This release includes diff --git a/Dockerfile b/Dockerfile index 696974da..d36527ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ MAINTAINER "Apache CloudStack" LABEL Description="Apache CloudStack CloudMonkey; Python based CloudStack command line interface" LABEL Vendor="Apache.org" LABEL License=ApacheV2 -LABEL Version=5.3.3 +LABEL Version=5.3.4 COPY . /cloudstack-cloudmonkey RUN pip install requests diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py index b1063623..46396a6f 100644 --- a/cloudmonkey/cloudmonkey.py +++ b/cloudmonkey/cloudmonkey.py @@ -31,6 +31,7 @@ import sys import time import types + import jmespath from cachemaker import loadcache, savecache, monkeycache, splitverbsubject from config import __version__, __description__, __projecturl__ @@ -80,8 +81,10 @@ class CloudMonkeyShell(cmd.Cmd, object): - intro = ("☁ Apache CloudStack 🐵 cloudmonkey " + __version__ + - ". Type help or ? to list commands.\n") + intro = ("☁ Apache CloudStack 🐵 (legacy) cloudmonkey " + __version__ + ".\n" + + "Please switch to latest Go-based version https://github.com/apache/cloudstack-cloudmonkey/releases.\n" + + "For usage see https://github.com/apache/cloudstack-cloudmonkey/wiki.\n" + + "Type help or ? to list commands.\n") ruler = "=" config_options = [] profile_names = [] @@ -234,7 +237,7 @@ def monkeyprint(self, *args): else: print output - def print_result(self, result, result_filter=[]): + def print_result(self, result, result_filter=[], result_query=''): if not result or len(result) == 0: return @@ -277,6 +280,21 @@ def print_result_json(result): ensure_ascii=False, separators=(',', ': '))) + def print_result_jmespath(result, result_query): + try: + expression = jmespath.compile(result_query) + except Exception as e: + raise ValueError("Bad value for --query: %s \n\n %s" % (result_query, str(e))) + + try: + self.monkeyprint(json.dumps(expression.search(result), + sort_keys=True, + indent=2, + ensure_ascii=False, + separators=(',', ': '))) + except Exception as e: + raise ValueError("Bad formatted JSON for JMESPATH: %s \n\n %s" % (result, str(e))) + def print_result_xml(result): custom_root = "CloudStack-%s" % self.profile.replace(" ", "_") xml = dicttoxml(result, attr_type=False, custom_root=custom_root) @@ -369,6 +387,10 @@ def print_result_as_list(result): print_result_json(filtered_result) return + if self.display == "jmespath": + print_result_jmespath(filtered_result, result_query) + return + if self.display == "xml": print_result_xml(filtered_result) return @@ -457,6 +479,10 @@ def default(self, args): x.partition("=")[2]], args[1:])[x] for x in range(len(args) - 1)) + field_query = [] + if 'query' in args_dict: + field_query = args_dict.pop('query') + field_filter = [] if 'filter' in args_dict: field_filter = filter(lambda x: x.strip() != '', @@ -489,7 +515,7 @@ def default(self, args): try: responsekeys = filter(lambda x: 'response' in x, result.keys()) for responsekey in responsekeys: - self.print_result(result[responsekey], field_filter) + self.print_result(result[responsekey], field_filter, field_query) if apiname.startswith("list") and "id" not in args_dict: self.update_param_cache(apiname, result) except Exception as e: diff --git a/cloudmonkey/config.py b/cloudmonkey/config.py index c5faec26..ac6daa1c 100644 --- a/cloudmonkey/config.py +++ b/cloudmonkey/config.py @@ -16,7 +16,7 @@ # specific language governing permissions and limitations # under the License. -__version__ = "5.3.3" +__version__ = "5.3.4" __description__ = "Command Line Interface for Apache CloudStack" __maintainer__ = "The Apache CloudStack Team" __maintaineremail__ = "dev@cloudstack.apache.org" @@ -39,7 +39,7 @@ iterable_type = ['set', 'list', 'object'] # cloudmonkey display types -display_types = ["json", "xml", "csv", "table", "default"] +display_types = ["jmespath","json", "xml", "csv", "table", "default"] config_dir = expanduser('~/.cloudmonkey') config_file = expanduser(config_dir + '/config') diff --git a/cloudmonkey/requester.py b/cloudmonkey/requester.py index 914854fa..b4fed264 100644 --- a/cloudmonkey/requester.py +++ b/cloudmonkey/requester.py @@ -70,7 +70,7 @@ def login(url, username, password, domain="/", verifysslcert=False): sessionkey = '' session = requests.Session() - session.mount('https://', SSLAdapter(ssl.PROTOCOL_TLSv1)) + session.mount('https://', SSLAdapter()) try: resp = session.post(url, params=args, verify=verifysslcert) @@ -217,7 +217,7 @@ def sign_request(params, secret_key): args["signature"] = sign_request(args, credentials['secretkey']) session = requests.Session() - session.mount('https://', SSLAdapter(ssl.PROTOCOL_TLSv1)) + session.mount('https://', SSLAdapter()) try: response = session.get(url, params=args, verify=verifysslcert) diff --git a/docs/source/conf.py b/docs/source/conf.py index 9c30ccb3..e9e79a85 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -55,7 +55,7 @@ # built documents. # # The short X.Y version. -version = '5.3.3' +version = '5.3.4' # The full version, including alpha/beta/rc tags. release = version diff --git a/setup.py b/setup.py index 44223283..099da640 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,7 @@ from cloudmonkey import __project__, __projecturl__, __projectemail__ requires = [ + 'jmespath', 'Pygments>=1.5', 'argcomplete', 'dicttoxml', @@ -54,14 +55,14 @@ setup( name = 'cloudmonkey', - version = __version__, + version = '5.3.3.1', author = __project__, author_email = __projectemail__, maintainer = __maintainer__, maintainer_email = __maintaineremail__, url = __projecturl__, description = __description__, - long_description = "cloudmonkey is a CLI for Apache CloudStack", + long_description = "Legacy cloudmonkey is a CLI for Apache CloudStack. Please use the latest Go-based CLI from https://github.com/apache/cloudstack-cloudmonkey/releases. Refer to wiki for documentation https://github.com/apache/cloudstack-cloudmonkey/wiki", platforms = ("Any",), license = 'ASL 2.0', packages = find_packages(),