From cbe1c6a21739fdeb8f60fa661fec682f86a20f54 Mon Sep 17 00:00:00 2001 From: aviau Date: Tue, 9 Jun 2015 20:43:55 -0400 Subject: [PATCH] Fixed issue where some properties would be None Change-Id: Ie3b4985ce2ff5066d97c91644de96364d6409852 --- surveilclient/common/utils.py | 4 ++-- surveilclient/v2_0/shell.py | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/surveilclient/common/utils.py b/surveilclient/common/utils.py index 3e7c59f..66752a3 100644 --- a/surveilclient/common/utils.py +++ b/surveilclient/common/utils.py @@ -84,8 +84,8 @@ def print_item(objs, properties): list.append({'prop': property, 'value': val_lines}) formatters = { - 'Property': lambda x: x['prop'], - 'Value': lambda x: x['value'] + 'Property': lambda x: x.get('prop', ''), + 'Value': lambda x: x.get('value', ''), } print_list(list, cols, formatters=formatters) diff --git a/surveilclient/v2_0/shell.py b/surveilclient/v2_0/shell.py index 0dd52aa..5cbdca6 100644 --- a/surveilclient/v2_0/shell.py +++ b/surveilclient/v2_0/shell.py @@ -41,8 +41,8 @@ def do_config_host_list(sc, args): ] formatters = { - 'host_name': lambda x: x['host_name'], - 'address': lambda x: x['address'], + 'host_name': lambda x: x.get('host_name', ''), + 'address': lambda x: x.get('address', '') } utils.print_list(hosts, cols, formatters=formatters) @@ -145,10 +145,10 @@ def do_config_service_list(sc, args): ] formatters = { - 'service_description': lambda x: x['service_description'], - 'host_name': lambda x: x['host_name'], - 'check_period': lambda x: x['check_period'], - 'contact_groups': lambda x: x['contact_groups'], + 'service_description': lambda x: x.get('service_description', ''), + 'host_name': lambda x: x.get('host_name', ''), + 'check_period': lambda x: x.get('check_period', ''), + 'contact_groups': lambda x: x.get('contact_groups', ''), } utils.print_list(services, cols, formatters=formatters) @@ -204,9 +204,10 @@ def do_config_checkmodulation_list(sc, args): ] formatters = { - 'check_command': lambda x: x['check_command'], - 'check_period': lambda x: x['check_period'], - 'checkmodulation_name': lambda x: x['checkmodulation_name'] + 'check_command': lambda x: x.get('check_command', ''), + 'check_period': lambda x: x.get('check_period', ''), + 'checkmodulation_name': lambda x: x.get('checkmodulation_name', + ''), } utils.print_list(checkmodulations, cols, formatters=formatters) @@ -242,8 +243,8 @@ def do_config_command_list(sc, args): ] formatters = { - 'command_name': lambda x: x['command_name'], - 'command_line': lambda x: x['command_line'] + 'command_name': lambda x: x.get('command_name', ''), + 'command_line': lambda x: x.get('command_line', ''), } utils.print_list(commands, cols, formatters=formatters)