diff options
| author | Peter Stachowski <peter@tesora.com> | 2016-03-08 00:22:06 -0500 |
|---|---|---|
| committer | Peter Stachowski <peter@tesora.com> | 2016-03-11 18:10:50 -0500 |
| commit | 457360c69f651aea92769c9e543492d770b84595 (patch) | |
| tree | c9fb106454232e8372102b066d9b4a954d4c1c78 /troveclient/utils.py | |
| parent | 3c71e52b408bbd6c33fca85188db2c8f156fb341 (diff) | |
| download | python-troveclient-2.2.0.tar.gz | |
Client support for instance module feature2.2.0
This adds support in the python API and Trove CLI
for instance module commands. These commands include:
- module-apply
- module-remove
- module-query
- module-retrieve
- module-list-instance
The parsing of --instance was modified to allow multiple
modules to be specified. This was extended to 'nics' as well.
Partially Implements: blueprint module-management
Change-Id: If62f5e51d4628cc6a8b10303d5c3893b3bd5057e
Diffstat (limited to 'troveclient/utils.py')
| -rw-r--r-- | troveclient/utils.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/troveclient/utils.py b/troveclient/utils.py index c685ea2..8541753 100644 --- a/troveclient/utils.py +++ b/troveclient/utils.py @@ -16,6 +16,7 @@ from __future__ import print_function +import base64 import os import simplejson as json import sys @@ -301,3 +302,25 @@ def is_uuid_like(val): return str(uuid.UUID(val)) == val except (TypeError, ValueError, AttributeError): return False + + +def encode_data(data): + """Encode the data using the base64 codec.""" + + try: + # py27str - if we've got text data, this should encode it + # py27aa/py34aa - if we've got a bytearray, this should work too + encoded = str(base64.b64encode(data).decode('utf-8')) + except TypeError: + # py34str - convert to bytes first, then we can encode + data_bytes = bytes([ord(item) for item in data]) + encoded = base64.b64encode(data_bytes).decode('utf-8') + + return encoded + + +def decode_data(data): + """Encode the data using the base64 codec.""" + + # py27 & py34 seem to understand bytearray the same + return bytearray([item for item in base64.b64decode(data)]) |
