diff --git a/saharaclient/api/job_binary_internals.py b/saharaclient/api/job_binary_internals.py index c92cd4de..26489c12 100644 --- a/saharaclient/api/job_binary_internals.py +++ b/saharaclient/api/job_binary_internals.py @@ -13,6 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from six.moves.urllib import parse as urlparse + from saharaclient.api import base @@ -24,7 +26,8 @@ class JobBinaryInternalsManager(base.ResourceManager): resource_class = JobBinaryInternal def create(self, name, data): - return self._update('/job-binary-internals/%s' % name, data, + return self._update('/job-binary-internals/%s' % + urlparse.quote(name.encode('utf-8')), data, 'job_binary_internal', dump_json=False) def list(self, search_opts=None): diff --git a/saharaclient/api/shell.py b/saharaclient/api/shell.py index a3507403..47692fbd 100644 --- a/saharaclient/api/shell.py +++ b/saharaclient/api/shell.py @@ -17,6 +17,7 @@ import argparse import datetime import inspect import json +import os.path import sys from saharaclient.openstack.common.apiclient import exceptions @@ -547,7 +548,7 @@ def do_data_source_delete(cs, args): # ~~~~~~~~~~~~~~~~~~~~ # job-binary-data-list # -# job-binary-data-create [--file ] +# job-binary-data-create [--file ] [--name ] # # job-binary-data-delete --id # @@ -561,15 +562,23 @@ def do_job_binary_data_list(cs, args): default=sys.stdin, type=argparse.FileType('r'), help='Data to store.') +@utils.arg('--name', + help="Name of the job binary internal.") def do_job_binary_data_create(cs, args): """Store data in the internal DB. Use 'swift upload' instead of this command. Use this command only if Swift is not available. """ + if args.name: + name = args.name + elif args.file is not sys.stdin: + name = os.path.basename(args.file.name) + else: + name = datetime.datetime.now().strftime('d%Y%m%d%H%M%S') # Should be %F-%T except for type validation errors _show_job_binary_data((cs.job_binary_internals.create( - datetime.datetime.now().strftime('d%Y%m%d%H%M%S'), + name, args.file.read()),) )