From 94642763e6cdbf64a6cca15fdc23722511224d4b Mon Sep 17 00:00:00 2001 From: Craig Squire Date: Fri, 31 Aug 2018 07:56:49 -0500 Subject: [PATCH 1/3] Don't force connections to TLSv1 (#25) Forcing the connection to TLSv1 is actually downgrading connections that would otherwise be TLSv1_2. Cloudmonkey is better off auto-negotiating ssl/tls versions and versions should be enforced on the server side. Since the Go version is still alpha, it would be very useful to have the Python version play nice with TLSv1_2. --- CHANGES.md | 5 +++++ Dockerfile | 2 +- cloudmonkey/config.py | 2 +- cloudmonkey/requester.py | 4 ++-- docs/source/conf.py | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) 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/config.py b/cloudmonkey/config.py index c5faec26..47235ef0 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" 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 From db74764aacb46f83be3eb1fd851f82c42be135f2 Mon Sep 17 00:00:00 2001 From: Danilo Figueiredo Rocha Date: Tue, 5 Mar 2019 06:59:31 -0300 Subject: [PATCH 2/3] display: New display mode based on jmespath for 5.3 version. (#44) This add to cloudmonkey CLI the abilities to make a JMESPATH filter with following changes in version 5.3: Add new argument 'query'. Add new display type 'jmespath'. Import jmespath module. --- cloudmonkey/cloudmonkey.py | 28 ++++++++++++++++++++++++++-- cloudmonkey/config.py | 2 +- setup.py | 1 + 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py index b1063623..e8da4571 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__ @@ -234,7 +235,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 +278,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 +385,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 +477,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 +513,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 47235ef0..ac6daa1c 100644 --- a/cloudmonkey/config.py +++ b/cloudmonkey/config.py @@ -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/setup.py b/setup.py index 44223283..f3912fbe 100644 --- a/setup.py +++ b/setup.py @@ -29,6 +29,7 @@ from cloudmonkey import __project__, __projecturl__, __projectemail__ requires = [ + 'jmespath', 'Pygments>=1.5', 'argcomplete', 'dicttoxml', From 3169f6f8effa227551b512fc56090d482e1f28c4 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 13 Oct 2021 12:25:10 +0530 Subject: [PATCH 3/3] cloudmonkey: fix description for legacy cloudmonkey for pypi website Signed-off-by: Rohit Yadav --- cloudmonkey/cloudmonkey.py | 6 ++++-- setup.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cloudmonkey/cloudmonkey.py b/cloudmonkey/cloudmonkey.py index e8da4571..46396a6f 100644 --- a/cloudmonkey/cloudmonkey.py +++ b/cloudmonkey/cloudmonkey.py @@ -81,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 = [] diff --git a/setup.py b/setup.py index f3912fbe..099da640 100644 --- a/setup.py +++ b/setup.py @@ -55,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(),