add --name option to assign name to job-binary-internal

In CLI command(job-binary-data-create)
job-binary-internal is automatically named by creation-date.
This fix add --name for job-binary-data-create
to assign name to job-binary-internal.
If we do not use --name, job-binary-internal named
basename of args.filename.
If we use stdin, job-binary-internal named by creation-date
the same as bofore.
Examples:
sahara job-binary-data-create --file /tmp/fuga.txt  --name hoge
 => job-binary-internal is named  hoge
sahara job-binary-data-create --file /tmp/fuga.txt
 => job-binary-internal is named filename(fuga.txt)
sahara job-binary-data-create < stdin
 => job-binary-internal is named creation-date

Change-Id: I368b8c82bc87962d69dda175e410e230e0d3beab
Closes-Bug: #1428537
This commit is contained in:
yuhara.motoki
2015-03-19 14:16:26 +09:00
parent 3fa0e0e798
commit 67b4e76be8
2 changed files with 15 additions and 3 deletions

View File

@@ -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):

View File

@@ -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 <file>]
# job-binary-data-create [--file <file>] [--name <name>]
#
# job-binary-data-delete --id <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()),)
)