Adds checking of '--request-file' param
This commit is contained in:
parent
8f2684731a
commit
659f54d744
|
@ -328,6 +328,13 @@ class MagnetoDBCommand(command.OpenStackCommand):
|
|||
def get_client(self):
|
||||
return self.app.client_manager.magnetodb
|
||||
|
||||
def check_required_args(self, parsed_args):
|
||||
for arg in self.required_args:
|
||||
if not getattr(parsed_args, arg):
|
||||
param_name = '--%s' % arg.replace('_', '-')
|
||||
msg = _("'%s' is a required parameter") % param_name
|
||||
raise exceptions.MagnetoDBCLIError(message=msg)
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(MagnetoDBCommand, self).get_parser(prog_name)
|
||||
self.add_known_arguments(parser)
|
||||
|
@ -379,10 +386,6 @@ class CreateCommand(MagnetoDBCommand, show.ShowOne):
|
|||
success_message = _('Created a new %s:')
|
||||
default_info = {'': ''}
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateCommand, self).get_parser(prog_name)
|
||||
return parser
|
||||
|
||||
def format_output_data(self, info):
|
||||
for k, v in info.iteritems():
|
||||
if k in self._formatters:
|
||||
|
@ -391,6 +394,7 @@ class CreateCommand(MagnetoDBCommand, show.ShowOne):
|
|||
|
||||
def get_data(self, parsed_args):
|
||||
self.log.debug('get_data(%s)' % parsed_args)
|
||||
self.check_required_args(parsed_args)
|
||||
magnetodb_client = self.get_client()
|
||||
_extra_values = parse_args_to_dict(self.values_specs)
|
||||
_merge_args(self, parsed_args, _extra_values,
|
||||
|
@ -421,6 +425,7 @@ class UpdateCommand(MagnetoDBCommand, show.ShowOne):
|
|||
|
||||
def run(self, parsed_args):
|
||||
self.log.debug('run(%s)', parsed_args)
|
||||
self.check_required_args(parsed_args)
|
||||
magnetodb_client = self.get_client()
|
||||
body = self.args2body(parsed_args)
|
||||
obj_updator = getattr(magnetodb_client, self.method)
|
||||
|
@ -454,6 +459,7 @@ class DeleteCommand(MagnetoDBCommand):
|
|||
|
||||
def run(self, parsed_args):
|
||||
self.log.debug('run(%s)', parsed_args)
|
||||
self.check_required_args(parsed_args)
|
||||
magnetodb_client = self.get_client()
|
||||
obj_deleter = getattr(magnetodb_client, self.method)
|
||||
_name = parsed_args.name
|
||||
|
@ -490,6 +496,7 @@ class ListCommand(MagnetoDBCommand, lister.Lister):
|
|||
|
||||
def args2search_opts(self, parsed_args):
|
||||
search_opts = {}
|
||||
self.check_required_args(parsed_args)
|
||||
fields = parsed_args.fields
|
||||
if parsed_args.fields:
|
||||
search_opts.update({'fields': fields})
|
||||
|
@ -551,6 +558,7 @@ class ListCommand(MagnetoDBCommand, lister.Lister):
|
|||
|
||||
def get_data(self, parsed_args):
|
||||
self.log.debug('get_data(%s)', parsed_args)
|
||||
self.check_required_args(parsed_args)
|
||||
data = self.retrieve_list(parsed_args)
|
||||
info = self._get_info(data)
|
||||
if self.success_message:
|
||||
|
@ -587,8 +595,8 @@ class ShowCommand(MagnetoDBCommand, show.ShowOne):
|
|||
|
||||
def get_data(self, parsed_args):
|
||||
self.log.debug('get_data(%s)', parsed_args)
|
||||
self.check_required_args(parsed_args)
|
||||
magnetodb_client = self.get_client()
|
||||
|
||||
_name = getattr(parsed_args, 'name', None)
|
||||
body = self.args2body(parsed_args)
|
||||
data = self.call_server(magnetodb_client, _name, parsed_args, body)
|
||||
|
|
|
@ -30,6 +30,7 @@ class GetItem(magnetodbv1.ShowCommand):
|
|||
resource = 'item'
|
||||
resource_path = ('item',)
|
||||
method = 'get_item'
|
||||
required_args = ('request_file',)
|
||||
log = logging.getLogger(__name__ + '.GetItem')
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
|
@ -37,11 +38,11 @@ class GetItem(magnetodbv1.ShowCommand):
|
|||
'name', metavar='TABLE_NAME',
|
||||
help=_('Name of table to look up'))
|
||||
parser.add_argument(
|
||||
'--request-file', metavar='FILE', dest='request_file_name',
|
||||
'--request-file', metavar='FILE',
|
||||
help=_('File that contains item description to put in table'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return utils.get_file_contents(parsed_args.request_file_name)
|
||||
return utils.get_file_contents(parsed_args.request_file)
|
||||
|
||||
def call_server(self, magnetodb_client, name, parsed_args, body):
|
||||
obj_shower = getattr(magnetodb_client, self.method)
|
||||
|
@ -55,6 +56,7 @@ class PutItem(magnetodbv1.CreateCommand):
|
|||
resource = 'item'
|
||||
resource_path = ('attributes',)
|
||||
method = 'put_item'
|
||||
required_args = ('request_file',)
|
||||
log = logging.getLogger(__name__ + '.PutItem')
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
|
@ -62,11 +64,11 @@ class PutItem(magnetodbv1.CreateCommand):
|
|||
'name', metavar='TABLE_NAME',
|
||||
help=_('Name of table to put item in'))
|
||||
parser.add_argument(
|
||||
'--request-file', metavar='FILE', dest='request_file_name',
|
||||
'--request-file', metavar='FILE',
|
||||
help=_('File that contains item description to put in table'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return utils.get_file_contents(parsed_args.request_file_name)
|
||||
return utils.get_file_contents(parsed_args.request_file)
|
||||
|
||||
|
||||
class DeleteItem(magnetodbv1.CreateCommand):
|
||||
|
@ -83,11 +85,11 @@ class DeleteItem(magnetodbv1.CreateCommand):
|
|||
'name', metavar='TABLE_NAME',
|
||||
help=_('Name of table to delete item from'))
|
||||
parser.add_argument(
|
||||
'--request-file', metavar='FILE', dest='request_file_name',
|
||||
'--request-file', metavar='FILE', dest='request_file',
|
||||
help=_('File that contains item key description'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return utils.get_file_contents(parsed_args.request_file_name)
|
||||
return utils.get_file_contents(parsed_args.request_file)
|
||||
|
||||
|
||||
class UpdateItem(magnetodbv1.UpdateCommand):
|
||||
|
@ -108,11 +110,11 @@ class UpdateItem(magnetodbv1.UpdateCommand):
|
|||
'name', metavar='TABLE_NAME',
|
||||
help=_('Name of table to update item'))
|
||||
parser.add_argument(
|
||||
'--request-file', metavar='FILE', dest='request_file_name',
|
||||
'--request-file', metavar='FILE',
|
||||
help=_('File that contains item update description'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return utils.get_file_contents(parsed_args.request_file_name)
|
||||
return utils.get_file_contents(parsed_args.request_file)
|
||||
|
||||
|
||||
class Query(magnetodbv1.ListCommand):
|
||||
|
@ -121,6 +123,7 @@ class Query(magnetodbv1.ListCommand):
|
|||
resource = 'item'
|
||||
resource_path = ('items',)
|
||||
method = 'query'
|
||||
required_args = ('request_file',)
|
||||
log = logging.getLogger(__name__ + '.Query')
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
|
@ -128,11 +131,11 @@ class Query(magnetodbv1.ListCommand):
|
|||
'name', metavar='TABLE_NAME',
|
||||
help=_('Name of table to query'))
|
||||
parser.add_argument(
|
||||
'--request-file', metavar='FILE', dest='request_file_name',
|
||||
'--request-file', metavar='FILE', dest='request_file',
|
||||
help=_('File that contains query request description'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return utils.get_file_contents(parsed_args.request_file_name)
|
||||
return utils.get_file_contents(parsed_args.request_file)
|
||||
|
||||
def call_server(self, magnetodb_client, search_opts, parsed_args, body):
|
||||
obj_lister = getattr(magnetodb_client, self.method)
|
||||
|
@ -143,8 +146,6 @@ class Query(magnetodbv1.ListCommand):
|
|||
class Scan(Query):
|
||||
"""Scan table that belong to a given tenant."""
|
||||
|
||||
resource = 'item'
|
||||
resource_path = ('items',)
|
||||
method = 'scan'
|
||||
log = logging.getLogger(__name__ + '.Scan')
|
||||
|
||||
|
@ -154,17 +155,18 @@ class BatchWrite(magnetodbv1.ListCommand):
|
|||
|
||||
resource_path = ('unprocessed_items',)
|
||||
method = 'batch_write_item'
|
||||
required_args = ('request_file',)
|
||||
log = logging.getLogger(__name__ + '.GetItem')
|
||||
success_message = _("Unprocessed items:")
|
||||
list_columns = ['Table Name', 'Request Type', 'Request']
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--request-file', metavar='FILE', dest='request_file_name',
|
||||
'--request-file', metavar='FILE',
|
||||
help=_('File that contains item description to put in table'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return utils.get_file_contents(parsed_args.request_file_name)
|
||||
return utils.get_file_contents(parsed_args.request_file)
|
||||
|
||||
def call_server(self, magnetodb_client, name, parsed_args, body):
|
||||
obj_shower = getattr(magnetodb_client, self.method)
|
||||
|
|
|
@ -128,17 +128,18 @@ class CreateTable(magnetodbv1.CreateCommand):
|
|||
resource = 'table'
|
||||
resource_path = ('table_description',)
|
||||
method = 'create_table'
|
||||
required_args = ('request_file',)
|
||||
excluded_rows = ('links',)
|
||||
_formatters = {'local_secondary_indexes': _get_lsi_names}
|
||||
log = logging.getLogger(__name__ + '.CreateTable')
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--request-file', metavar='FILE', dest='request_file_name',
|
||||
'--request-file', metavar='FILE',
|
||||
help=_('File that contains table description to create'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return utils.get_file_contents(parsed_args.request_file_name)
|
||||
return utils.get_file_contents(parsed_args.request_file)
|
||||
|
||||
|
||||
class DeleteTable(magnetodbv1.DeleteCommand):
|
||||
|
|
Loading…
Reference in New Issue