Add actions listing command
As congress supports executing actions, we need a way to query available actions that a datasource driver can execute. Change-Id: I09469815ba8a071112acc7190175048d7f8b774c Implements-blueprint: add-action-listing
This commit is contained in:
parent
b0b5477b96
commit
0f699f8ee5
|
@ -98,6 +98,44 @@ class ShowDatasourceStatus(show.ShowOne):
|
|||
return zip(*sorted(six.iteritems(data)))
|
||||
|
||||
|
||||
class ShowDatasourceActions(lister.Lister):
|
||||
"""List supported actions for datasource."""
|
||||
|
||||
log = logging.getLogger(__name__ + '.ShowDatasourceActions')
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowDatasourceActions, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'datasource_name',
|
||||
metavar="<datasource-name>",
|
||||
help="Name of the datasource")
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug('take_action(%s)' % parsed_args)
|
||||
# as we know output it's long, limit column length here
|
||||
if parsed_args.max_width == 0:
|
||||
parsed_args.max_width = 40
|
||||
|
||||
client = self.app.client_manager.congressclient
|
||||
|
||||
results = client.list_datasources()
|
||||
datasource_id = utils.get_resource_id_from_name(
|
||||
parsed_args.datasource_name, results)
|
||||
|
||||
data = client.list_datasource_actions(datasource_id)
|
||||
formatters = {'args': utils.format_long_dict_list}
|
||||
newdata = [{'action': x['name'],
|
||||
'args': x['args'],
|
||||
'description': x['description']}
|
||||
for x in data['results']]
|
||||
columns = ['action', 'args', 'description']
|
||||
return (columns, (utils.get_dict_properties(s,
|
||||
columns,
|
||||
formatters=formatters)
|
||||
for s in newdata))
|
||||
|
||||
|
||||
class ShowDatasourceSchema(lister.Lister):
|
||||
"""Show schema for datasource."""
|
||||
|
||||
|
|
|
@ -98,6 +98,37 @@ class TestListDatasourceStatus(common.TestCongressBase):
|
|||
result)
|
||||
|
||||
|
||||
class TestShowDatasourceActions(common.TestCongressBase):
|
||||
def test_show_datasource_actions(self):
|
||||
datasource_name = 'fake'
|
||||
arglist = [
|
||||
datasource_name
|
||||
]
|
||||
verifylist = [
|
||||
('datasource_name', datasource_name)
|
||||
]
|
||||
response = {
|
||||
"results":
|
||||
[{'name': 'execute',
|
||||
'args': [{"name": "name", "description": "None"},
|
||||
{"name": "status", "description": "None"},
|
||||
{"name": "id", "description": "None"}],
|
||||
'description': 'execute action'}]
|
||||
}
|
||||
lister = mock.Mock(return_value=response)
|
||||
self.app.client_manager.congressclient.list_datasource_actions = lister
|
||||
self.app.client_manager.congressclient.list_datasources = mock.Mock()
|
||||
cmd = datasource.ShowDatasourceActions(self.app, self.namespace)
|
||||
|
||||
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
||||
with mock.patch.object(utils, "get_resource_id_from_name",
|
||||
return_value="id"):
|
||||
result = cmd.take_action(parsed_args)
|
||||
|
||||
lister.assert_called_once_with("id")
|
||||
self.assertEqual(['action', 'args', 'description'], result[0])
|
||||
|
||||
|
||||
class TestShowDatasourceSchema(common.TestCongressBase):
|
||||
def test_show_datasource_schema(self):
|
||||
datasource_name = 'neutron'
|
||||
|
|
|
@ -42,7 +42,6 @@ class Client(object):
|
|||
policy_table_path = '/v1/policies/%s/tables/%s'
|
||||
policy_rows = '/v1/policies/%s/tables/%s/rows'
|
||||
policy_rows_trace = '/v1/policies/%s/tables/%s/rows?trace=True'
|
||||
policy_rules = '/v1/policies/%s/rules'
|
||||
policies = '/v1/policies'
|
||||
policy_action = '/v1/policies/%s?%s'
|
||||
datasources = '/v1/data-sources'
|
||||
|
@ -50,6 +49,7 @@ class Client(object):
|
|||
datasource_tables = '/v1/data-sources/%s/tables'
|
||||
datasource_table_path = '/v1/data-sources/%s/tables/%s'
|
||||
datasource_status = '/v1/data-sources/%s/status'
|
||||
datasource_actions = '/v1/data-sources/%s/actions'
|
||||
datasource_schema = '/v1/data-sources/%s/schema'
|
||||
datasource_table_schema = '/v1/data-sources/%s/tables/%s/spec'
|
||||
datasource_rows = '/v1/data-sources/%s/tables/%s/rows'
|
||||
|
@ -143,6 +143,11 @@ class Client(object):
|
|||
datasource_name)
|
||||
return body
|
||||
|
||||
def list_datasource_actions(self, datasource_name):
|
||||
resp, body = self.httpclient.get(self.datasource_actions %
|
||||
datasource_name)
|
||||
return body
|
||||
|
||||
def show_datasource_schema(self, datasource_name):
|
||||
resp, body = self.httpclient.get(self.datasource_schema %
|
||||
datasource_name)
|
||||
|
|
|
@ -46,6 +46,7 @@ openstack.congressclient.v1 =
|
|||
congress_datasource_table_list = congressclient.osc.v1.datasource:ListDatasourceTables
|
||||
congress_datasource_row_list = congressclient.osc.v1.datasource:ListDatasourceRows
|
||||
congress_datasource_status_show = congressclient.osc.v1.datasource:ShowDatasourceStatus
|
||||
congress_datasource_actions_show= congressclient.osc.v1.datasource:ShowDatasourceActions
|
||||
congress_datasource_schema_show = congressclient.osc.v1.datasource:ShowDatasourceSchema
|
||||
congress_datasource_table_schema_show = congressclient.osc.v1.datasource:ShowDatasourceTableSchema
|
||||
congress_policy_table_show = congressclient.osc.v1.policy:ShowPolicyTable
|
||||
|
|
Loading…
Reference in New Issue