OpenStack client plugin for environment show
Adds the "openstack stack environment show" command. Depends-On: I7e3577dfc854018245d79afdfee45a9d250d73a7 Change-Id: I7ef4858738964198bc4614122be4bab8f49b1b5f Implements: blueprint environment-show
This commit is contained in:
parent
3f340cd818
commit
a503bfeff0
|
@ -512,6 +512,39 @@ class ListStack(lister.Lister):
|
||||||
return _list(client, args=parsed_args)
|
return _list(client, args=parsed_args)
|
||||||
|
|
||||||
|
|
||||||
|
class EnvironmentShowStack(format_utils.YamlFormat):
|
||||||
|
"""Show a stack's environment."""
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(EnvironmentShowStack, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'stack',
|
||||||
|
metavar='<NAME or ID>',
|
||||||
|
help=_('Name or ID of stack to query')
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
|
|
||||||
|
client = self.app.client_manager.orchestration
|
||||||
|
|
||||||
|
try:
|
||||||
|
template = client.stacks.environment(stack_id=parsed_args.stack)
|
||||||
|
except heat_exc.HTTPNotFound:
|
||||||
|
msg = _('Stack not found: %s') % parsed_args.stack
|
||||||
|
raise exc.CommandError(msg)
|
||||||
|
|
||||||
|
fields = ['parameters', 'resource_registry']
|
||||||
|
|
||||||
|
columns = [f for f in fields if f in template]
|
||||||
|
data = [template[c] for c in columns]
|
||||||
|
|
||||||
|
return columns, data
|
||||||
|
|
||||||
|
|
||||||
def _list(client, args=None):
|
def _list(client, args=None):
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
columns = [
|
columns = [
|
||||||
|
|
|
@ -1308,3 +1308,63 @@ class TestStackHookClear(TestStack):
|
||||||
data={'unset_hook': 'pre-delete'},
|
data={'unset_hook': 'pre-delete'},
|
||||||
resource_name='resource',
|
resource_name='resource',
|
||||||
stack_id='my_stack')
|
stack_id='my_stack')
|
||||||
|
|
||||||
|
|
||||||
|
class TestEnvironmentStackShow(TestStack):
|
||||||
|
|
||||||
|
SAMPLE_ENV = {
|
||||||
|
'parameters': {'p1': 'v1'},
|
||||||
|
'resource_registry': {'r1': 't1'}
|
||||||
|
}
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestEnvironmentStackShow, self).setUp()
|
||||||
|
self.cmd = stack.EnvironmentShowStack(self.app, None)
|
||||||
|
|
||||||
|
def test_stack_environment_show(self):
|
||||||
|
# Setup
|
||||||
|
self.stack_client.environment = mock.MagicMock(
|
||||||
|
return_value=self.SAMPLE_ENV
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test
|
||||||
|
parsed_args = self.check_parser(self.cmd, ['test-stack'], [])
|
||||||
|
columns, outputs = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
self.assertEqual(['parameters', 'resource_registry'], columns)
|
||||||
|
self.assertEqual({'p1': 'v1'}, outputs[0])
|
||||||
|
|
||||||
|
def test_stack_environment_show_no_parameters(self):
|
||||||
|
# Setup
|
||||||
|
sample_env = copy.deepcopy(self.SAMPLE_ENV)
|
||||||
|
sample_env.pop('parameters')
|
||||||
|
|
||||||
|
self.stack_client.environment = mock.MagicMock(
|
||||||
|
return_value=sample_env
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test
|
||||||
|
parsed_args = self.check_parser(self.cmd, ['test-stack'], [])
|
||||||
|
columns, outputs = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
self.assertEqual(['resource_registry'], columns)
|
||||||
|
self.assertEqual({'r1': 't1'}, outputs[0])
|
||||||
|
|
||||||
|
def test_stack_environment_show_no_registry(self):
|
||||||
|
# Setup
|
||||||
|
sample_env = copy.deepcopy(self.SAMPLE_ENV)
|
||||||
|
sample_env.pop('resource_registry')
|
||||||
|
|
||||||
|
self.stack_client.environment = mock.MagicMock(
|
||||||
|
return_value=sample_env
|
||||||
|
)
|
||||||
|
|
||||||
|
# Test
|
||||||
|
parsed_args = self.check_parser(self.cmd, ['test-stack'], [])
|
||||||
|
columns, outputs = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
self.assertEqual(['parameters'], columns)
|
||||||
|
self.assertEqual({'p1': 'v1'}, outputs[0])
|
||||||
|
|
|
@ -55,6 +55,7 @@ openstack.orchestration.v1 =
|
||||||
stack_delete = heatclient.osc.v1.stack:DeleteStack
|
stack_delete = heatclient.osc.v1.stack:DeleteStack
|
||||||
stack_event_list = heatclient.osc.v1.event:ListEvent
|
stack_event_list = heatclient.osc.v1.event:ListEvent
|
||||||
stack_event_show = heatclient.osc.v1.event:ShowEvent
|
stack_event_show = heatclient.osc.v1.event:ShowEvent
|
||||||
|
stack_environment_show = heatclient.osc.v1.stack:EnvironmentShowStack
|
||||||
stack_hook_clear = heatclient.osc.v1.stack:StackHookClear
|
stack_hook_clear = heatclient.osc.v1.stack:StackHookClear
|
||||||
stack_hook_poll = heatclient.osc.v1.stack:StackHookPoll
|
stack_hook_poll = heatclient.osc.v1.stack:StackHookPoll
|
||||||
stack_list = heatclient.osc.v1.stack:ListStack
|
stack_list = heatclient.osc.v1.stack:ListStack
|
||||||
|
|
Loading…
Reference in New Issue