Adds item-get, item-put, item-delete commands
This commit is contained in:
parent
b1eebe96e1
commit
2a13f76441
|
@ -319,6 +319,9 @@ class MagnetoDBCommand(command.OpenStackCommand):
|
|||
api = 'keyvalue'
|
||||
log = logging.getLogger(__name__ + '.MagnetoDBCommand')
|
||||
values_specs = []
|
||||
excluded_rows = ()
|
||||
_formatters = {}
|
||||
resource_path = ()
|
||||
json_indent = None
|
||||
|
||||
def get_client(self):
|
||||
|
@ -365,6 +368,7 @@ class CreateCommand(MagnetoDBCommand, show.ShowOne):
|
|||
api = 'keyvalue'
|
||||
resource = None
|
||||
log = None
|
||||
success_message = _('Created a new %s:')
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateCommand, self).get_parser(prog_name)
|
||||
|
@ -389,13 +393,16 @@ class CreateCommand(MagnetoDBCommand, show.ShowOne):
|
|||
self.values_specs)
|
||||
body = self.args2body(parsed_args)
|
||||
obj_creator = getattr(magnetodb_client, self.method)
|
||||
data = obj_creator(body)
|
||||
if parsed_args.name:
|
||||
data = obj_creator(parsed_args.name, body)
|
||||
else:
|
||||
data = obj_creator(body)
|
||||
resource = self._get_resource(data)
|
||||
self.format_output_data(resource)
|
||||
self.exclude_rows(resource)
|
||||
|
||||
if resource:
|
||||
print(_('Created a new %s:') % self.resource,
|
||||
print(self.success_message % self.resource,
|
||||
file=self.app.stdout)
|
||||
else:
|
||||
resource = {'': ''}
|
||||
|
@ -486,7 +493,6 @@ class ListCommand(MagnetoDBCommand, lister.Lister):
|
|||
api = 'keyvalue'
|
||||
resource = None
|
||||
log = None
|
||||
_formatters = {}
|
||||
list_columns = []
|
||||
unknown_parts_flag = True
|
||||
pagination_support = False
|
||||
|
@ -582,7 +588,6 @@ class ShowCommand(MagnetoDBCommand, show.ShowOne):
|
|||
|
||||
api = 'keyvalue'
|
||||
resource = None
|
||||
_formatters = {}
|
||||
log = None
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
|
@ -607,9 +612,16 @@ class ShowCommand(MagnetoDBCommand, show.ShowOne):
|
|||
|
||||
_name = parsed_args.name
|
||||
|
||||
body = self.args2body(parsed_args)
|
||||
obj_shower = getattr(magnetodb_client, self.method)
|
||||
data = obj_shower(_name)
|
||||
resource = self._get_resource(data, parsed_args)
|
||||
self.format_output_data(resource)
|
||||
self.exclude_rows(resource)
|
||||
if body:
|
||||
data = obj_shower(_name, body)
|
||||
else:
|
||||
data = obj_shower(_name)
|
||||
if data:
|
||||
resource = self._get_resource(data, parsed_args)
|
||||
self.format_output_data(resource)
|
||||
self.exclude_rows(resource)
|
||||
else:
|
||||
resource = {'': ''}
|
||||
return zip(*sorted(resource.iteritems()))
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
# Copyright 2012 OpenStack Foundation.
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import logging
|
||||
|
||||
from magnetodbclient.common import exceptions
|
||||
from magnetodbclient.common import utils
|
||||
from magnetodbclient.magnetodb import v1 as magnetodbv1
|
||||
from magnetodbclient.openstack.common.gettextutils import _
|
||||
|
||||
|
||||
def _format_table_name(table):
|
||||
try:
|
||||
return table['href']
|
||||
except Exception:
|
||||
return ''
|
||||
|
||||
|
||||
def _get_lsi_names(indexes):
|
||||
index_names = []
|
||||
for index in indexes:
|
||||
index_names.append(index['index_name'])
|
||||
return index_names
|
||||
|
||||
|
||||
class GetItem(magnetodbv1.ShowCommand):
|
||||
"""Gets item from a given table by key."""
|
||||
|
||||
resource = 'item'
|
||||
resource_path = ('item',)
|
||||
method = 'get_item'
|
||||
log = logging.getLogger(__name__ + '.GetItem')
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
help_str = _('Name of table to look up')
|
||||
parser.add_argument(
|
||||
'name', metavar='TABLE_NAME',
|
||||
help=help_str)
|
||||
parser.add_argument(
|
||||
'--request-file', metavar='FILE', dest='request_file_name',
|
||||
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)
|
||||
|
||||
|
||||
class PutItem(magnetodbv1.CreateCommand):
|
||||
"""Puts item to a given table."""
|
||||
|
||||
resource = 'item'
|
||||
resource_path = ()
|
||||
method = 'put_item'
|
||||
log = logging.getLogger(__name__ + '.PutItem')
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
help_str = _('Name of table to put item in')
|
||||
parser.add_argument(
|
||||
'name', metavar='TABLE_NAME',
|
||||
help=help_str)
|
||||
parser.add_argument(
|
||||
'--request-file', metavar='FILE', dest='request_file_name',
|
||||
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)
|
||||
|
||||
|
||||
class DeleteItem(magnetodbv1.CreateCommand):
|
||||
"""Deletes item from a given table."""
|
||||
|
||||
resource = 'item'
|
||||
method = 'delete_item'
|
||||
resource_path = ('attributes',)
|
||||
success_message = _('Deleted %s:')
|
||||
log = logging.getLogger(__name__ + '.DeleteItem')
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
help_str = _('Name of table to delete item from')
|
||||
parser.add_argument(
|
||||
'name', metavar='TABLE_NAME',
|
||||
help=help_str)
|
||||
parser.add_argument(
|
||||
'--request-file', metavar='FILE', dest='request_file_name',
|
||||
help=_('File that contains item key description'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return utils.get_file_contents(parsed_args.request_file_name)
|
|
@ -50,7 +50,6 @@ class ListTable(magnetodbv1.ListCommand):
|
|||
def add_known_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--limit',
|
||||
type=int,
|
||||
help=_('A maximum number of the items to return'))
|
||||
parser.add_argument(
|
||||
'--start-table-name',
|
||||
|
|
|
@ -31,6 +31,7 @@ from cliff import commandmanager
|
|||
from magnetodbclient.common import clientmanager
|
||||
from magnetodbclient.common import exceptions as exc
|
||||
from magnetodbclient.common import utils
|
||||
from magnetodbclient.magnetodb.v1 import item
|
||||
from magnetodbclient.magnetodb.v1 import table
|
||||
from magnetodbclient.openstack.common.gettextutils import _
|
||||
from magnetodbclient.openstack.common import strutils
|
||||
|
@ -75,6 +76,9 @@ COMMAND_V1 = {
|
|||
'index-list': table.ListIndex,
|
||||
'table-describe': table.ShowTable,
|
||||
'index-describe': table.ShowIndex,
|
||||
'item-put': item.PutItem,
|
||||
'item-get': item.GetItem,
|
||||
'item-delete': item.DeleteItem,
|
||||
}
|
||||
|
||||
COMMANDS = {'1': COMMAND_V1}
|
||||
|
|
Loading…
Reference in New Issue