add output-list and output-show
This patch adds the "output-list" and "output-show" commands to heat. The first prints a table of available outputs to stdout, and the second prints a single output_value to stdout. All outputs are serialized to JSON. This patch includes tests for the new commands as well as updated documentation. Implements blueprint: stack-outputs-in-shell Change-Id: Iaade16d043b2c42d14f642fde17419eaa07d0ab8 Closes-Bug: 1258622
This commit is contained in:
@@ -61,6 +61,14 @@ View stack information::
|
|||||||
|
|
||||||
heat stack-show mystack
|
heat stack-show mystack
|
||||||
|
|
||||||
|
List stack outputs::
|
||||||
|
|
||||||
|
heat output-list <stack name>
|
||||||
|
|
||||||
|
Show the value of a single output::
|
||||||
|
|
||||||
|
heat output-show <stack name> <output key>
|
||||||
|
|
||||||
List events::
|
List events::
|
||||||
|
|
||||||
heat event-list mystack
|
heat event-list mystack
|
||||||
|
|||||||
@@ -577,6 +577,51 @@ class ShellTestUserPass(ShellBase):
|
|||||||
abandon_resp = self.shell('stack-abandon teststack/1')
|
abandon_resp = self.shell('stack-abandon teststack/1')
|
||||||
self.assertEqual(abandoned_stack, jsonutils.loads(abandon_resp))
|
self.assertEqual(abandoned_stack, jsonutils.loads(abandon_resp))
|
||||||
|
|
||||||
|
def _output_fake_response(self):
|
||||||
|
self._script_keystone_client()
|
||||||
|
|
||||||
|
resp_dict = {"stack": {
|
||||||
|
"id": "1",
|
||||||
|
"stack_name": "teststack",
|
||||||
|
"stack_status": 'CREATE_COMPLETE',
|
||||||
|
"creation_time": "2012-10-25T01:58:47Z",
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"output_value": "value1",
|
||||||
|
"output_key": "output1",
|
||||||
|
"description": "test output 1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"output_value": ["output", "value", "2"],
|
||||||
|
"output_key": "output2",
|
||||||
|
"description": "test output 2",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"creation_time": "2012-10-25T01:58:47Z"
|
||||||
|
}}
|
||||||
|
|
||||||
|
resp = fakes.FakeHTTPResponse(
|
||||||
|
200,
|
||||||
|
'OK',
|
||||||
|
{'content-type': 'application/json'},
|
||||||
|
jsonutils.dumps(resp_dict))
|
||||||
|
|
||||||
|
http.HTTPClient.json_request(
|
||||||
|
'GET', '/stacks/teststack/1').AndReturn((resp, resp_dict))
|
||||||
|
|
||||||
|
self.m.ReplayAll()
|
||||||
|
|
||||||
|
def test_output_list(self):
|
||||||
|
self._output_fake_response()
|
||||||
|
list_text = self.shell('output-list teststack/1')
|
||||||
|
for r in ['output1', 'output2']:
|
||||||
|
self.assertRegexpMatches(list_text, r)
|
||||||
|
|
||||||
|
def test_output_show(self):
|
||||||
|
self._output_fake_response()
|
||||||
|
list_text = self.shell('output-show teststack/1 output1')
|
||||||
|
self.assertRegexpMatches(list_text, 'value1')
|
||||||
|
|
||||||
def test_template_show_cfn(self):
|
def test_template_show_cfn(self):
|
||||||
self._script_keystone_client()
|
self._script_keystone_client()
|
||||||
template_data = open(os.path.join(TEST_VAR_DIR,
|
template_data = open(os.path.join(TEST_VAR_DIR,
|
||||||
|
|||||||
@@ -323,6 +323,46 @@ def do_stack_list(hc, args=None):
|
|||||||
utils.print_list(stacks, fields, sortby=3)
|
utils.print_list(stacks, fields, sortby=3)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('id', metavar='<NAME or ID>',
|
||||||
|
help='Name or ID of stack to query.')
|
||||||
|
def do_output_list(hc, args):
|
||||||
|
'''Show available outputs.'''
|
||||||
|
try:
|
||||||
|
stack = hc.stacks.get(stack_id=args.id)
|
||||||
|
except exc.HTTPNotFound:
|
||||||
|
raise exc.CommandError('Stack not found: %s' % args.id)
|
||||||
|
else:
|
||||||
|
outputs = stack.to_dict()['outputs']
|
||||||
|
fields = ['output_key', 'description']
|
||||||
|
formatters = {
|
||||||
|
'output_key': lambda x: x['output_key'],
|
||||||
|
'description': lambda x: x['description'],
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.print_list(outputs, fields, formatters=formatters)
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('id', metavar='<NAME or ID>',
|
||||||
|
help='Name or ID of stack to query.')
|
||||||
|
@utils.arg('output', metavar='<OUTPUT NAME>',
|
||||||
|
help='Name of an output to display.')
|
||||||
|
def do_output_show(hc, args):
|
||||||
|
'''Show a specific stack output.'''
|
||||||
|
try:
|
||||||
|
stack = hc.stacks.get(stack_id=args.id)
|
||||||
|
except exc.HTTPNotFound:
|
||||||
|
raise exc.CommandError('Stack not found: %s' % args.id)
|
||||||
|
else:
|
||||||
|
for output in stack.to_dict().get('outputs', []):
|
||||||
|
if output['output_key'] == args.output:
|
||||||
|
value = output['output_value']
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
print (jsonutils.dumps(value, indent=2))
|
||||||
|
|
||||||
|
|
||||||
def do_resource_type_list(hc, args={}):
|
def do_resource_type_list(hc, args={}):
|
||||||
'''List the available resource types.'''
|
'''List the available resource types.'''
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user