def do_event_show(service, args): """Describe the event.""" try: event = service.get_event(args.id) except sdk_exc.ResourceNotFound: raise exc.CommandError(_("Event not found: %s") % args.id) utils.print_dict(event.to_dict())
def do_event_show(service, args): """Describe the event.""" try: event = service.get_event(args.id) except exc.HTTPNotFound as ex: raise exc.CommandError(str(ex)) utils.print_dict(event.to_dict())
def _show_cluster(service, cluster_id): try: cluster = service.get_cluster(cluster_id) except sdk_exc.ResourceNotFound: raise exc.CommandError(_('Cluster not found: %s') % cluster_id) formatters = { 'metadata': utils.json_formatter, 'nodes': utils.list_formatter, } utils.print_dict(cluster.to_dict(), formatters=formatters)
def _show_policy(service, policy_id): try: policy = service.get_policy(policy_id) except sdk_exc.ResourceNotFound: raise exc.CommandError(_('Policy not found: %s') % policy_id) formatters = { 'metadata': utils.json_formatter, 'spec': utils.json_formatter, } utils.print_dict(policy.to_dict(), formatters=formatters)
def test_print_dict(self): data = {'foo': 'fake_foo', 'bar': 'fake_bar'} with CaptureStdout() as cso: utils.print_dict(data) # Output should be sorted by the Property self.assertEqual("""\ +----------+----------+ | Property | Value | +----------+----------+ | bar | fake_bar | | foo | fake_foo | +----------+----------+ """, cso.read())
def _show_receiver(service, receiver_id): try: receiver = service.get_receiver(receiver_id) except sdk_exc.ResourceNotFound: raise exc.CommandError(_('Receiver not found: %s') % receiver_id) formatters = { 'actor': utils.json_formatter, 'params': utils.json_formatter, 'channel': utils.json_formatter, } utils.print_dict(receiver.to_dict(), formatters=formatters)
def do_build_info(service, args=None): """Retrieve build information. :param sc: Instance of senlinclient. :param args: Additional command line arguments, if any. """ result = service.get_build_info() formatters = { 'api': utils.json_formatter, 'engine': utils.json_formatter, } utils.print_dict(result, formatters=formatters)
def _show_profile(service, profile_id): try: profile = service.get_profile(profile_id) except sdk_exc.ResourceNotFound: raise exc.CommandError(_('Profile not found: %s') % profile_id) formatters = { 'metadata': utils.json_formatter, } formatters['spec'] = utils.nested_dict_formatter( ['type', 'version', 'properties'], ['property', 'value']) utils.print_dict(profile.to_dict(), formatters=formatters)
def do_action_show(service, args): """Show detailed info about the specified action.""" try: action = service.get_action(args.id) except exc.HTTPNotFound: msg = _('Action %(id)s is not found') % {'id': args.id} raise exc.CommandError(msg) formatters = { 'inputs': utils.json_formatter, 'outputs': utils.json_formatter, 'metadata': utils.json_formatter, 'data': utils.json_formatter, } utils.print_dict(action.to_dict(), formatters=formatters)
def do_action_show(service, args): """Show detailed info about the specified action.""" try: action = service.get_action(args.id) except sdk_exc.ResourceNotFound: raise exc.CommandError(_('Action not found: %s') % args.id) formatters = { 'inputs': utils.json_formatter, 'outputs': utils.json_formatter, 'metadata': utils.json_formatter, 'data': utils.json_formatter, 'depends_on': utils.list_formatter, 'depended_by': utils.list_formatter, } utils.print_dict(action.to_dict(), formatters=formatters)
def _show_node(service, node_id, show_details=False): """Show detailed info about the specified node.""" args = {'show_details': True} if show_details else None try: node = service.get_node(node_id, args=args) except sdk_exc.ResourceNotFound: raise exc.CommandError(_('Node not found: %s') % node_id) formatters = { 'metadata': utils.json_formatter, 'data': utils.json_formatter, } data = node.to_dict() if show_details: formatters['details'] = utils.nested_dict_formatter( list(node['details'].keys()), ['property', 'value']) utils.print_dict(data, formatters=formatters)
def do_cluster_policy_show(service, args): """Show a specific policy that is bound to the specified cluster.""" binding = service.get_cluster_policy(args.policy, args.id) utils.print_dict(binding.to_dict())