diff --git a/client-cli/cli_lib/ceph.py b/client-cli/cli_lib/ceph.py index f6e6088f..c81f52e6 100644 --- a/client-cli/cli_lib/ceph.py +++ b/client-cli/cli_lib/ceph.py @@ -114,7 +114,7 @@ def ceph_status(config): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ceph_util(config): """ @@ -129,7 +129,7 @@ def ceph_util(config): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def format_raw_output(status_data): ainformation = list() @@ -155,7 +155,7 @@ def ceph_osd_info(config, osd): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ceph_osd_list(config, limit): """ @@ -174,7 +174,7 @@ def ceph_osd_list(config, limit): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ceph_osd_add(config, node, device, weight): """ @@ -196,7 +196,7 @@ def ceph_osd_add(config, node, device, weight): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ceph_osd_remove(config, osdid): """ @@ -216,7 +216,7 @@ def ceph_osd_remove(config, osdid): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ceph_osd_state(config, osdid, state): """ @@ -236,7 +236,7 @@ def ceph_osd_state(config, osdid, state): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ceph_osd_option(config, option, action): """ @@ -257,7 +257,7 @@ def ceph_osd_option(config, option, action): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def getOutputColoursOSD(osd_information): # Set the UP status @@ -541,7 +541,7 @@ def ceph_pool_info(config, pool): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ceph_pool_list(config, limit): """ @@ -560,7 +560,7 @@ def ceph_pool_list(config, limit): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ceph_pool_add(config, pool, pgs, replcfg): """ @@ -582,7 +582,7 @@ def ceph_pool_add(config, pool, pgs, replcfg): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ceph_pool_remove(config, pool): """ @@ -602,7 +602,7 @@ def ceph_pool_remove(config, pool): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def format_list_pool(pool_list): # Handle empty list @@ -819,7 +819,7 @@ def ceph_volume_info(config, pool, volume): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ceph_volume_list(config, limit, pool): """ @@ -840,7 +840,7 @@ def ceph_volume_list(config, limit, pool): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ceph_volume_add(config, pool, volume, size): """ @@ -862,7 +862,7 @@ def ceph_volume_add(config, pool, volume, size): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ceph_volume_upload(config, pool, volume, image_format, image_file): """ @@ -897,7 +897,7 @@ def ceph_volume_upload(config, pool, volume, image_format, image_file): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ceph_volume_remove(config, pool, volume): """ @@ -914,7 +914,7 @@ def ceph_volume_remove(config, pool, volume): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ceph_volume_modify(config, pool, volume, new_name=None, new_size=None): """ @@ -938,7 +938,7 @@ def ceph_volume_modify(config, pool, volume, new_name=None, new_size=None): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ceph_volume_clone(config, pool, volume, new_volume): """ @@ -958,7 +958,7 @@ def ceph_volume_clone(config, pool, volume, new_volume): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def format_list_volume(volume_list): # Handle empty list @@ -1091,7 +1091,7 @@ def ceph_snapshot_info(config, pool, volume, snapshot): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ceph_snapshot_list(config, limit, volume, pool): """ @@ -1114,7 +1114,7 @@ def ceph_snapshot_list(config, limit, volume, pool): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ceph_snapshot_add(config, pool, volume, snapshot): """ @@ -1136,7 +1136,7 @@ def ceph_snapshot_add(config, pool, volume, snapshot): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ceph_snapshot_remove(config, pool, volume, snapshot): """ @@ -1153,7 +1153,7 @@ def ceph_snapshot_remove(config, pool, volume, snapshot): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ceph_snapshot_modify(config, pool, volume, snapshot, new_name=None): """ @@ -1175,7 +1175,7 @@ def ceph_snapshot_modify(config, pool, volume, snapshot, new_name=None): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def format_list_snapshot(snapshot_list): # Handle empty list diff --git a/client-cli/cli_lib/cluster.py b/client-cli/cli_lib/cluster.py index 370e0163..8cb08600 100644 --- a/client-cli/cli_lib/cluster.py +++ b/client-cli/cli_lib/cluster.py @@ -40,7 +40,7 @@ def initialize(config): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def maintenance_mode(config, state): """ @@ -60,7 +60,7 @@ def maintenance_mode(config, state): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def get_info(config): """ @@ -75,7 +75,7 @@ def get_info(config): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def format_info(cluster_information, oformat): if oformat == 'json': diff --git a/client-cli/cli_lib/network.py b/client-cli/cli_lib/network.py index fa85dd1d..dffa9a56 100644 --- a/client-cli/cli_lib/network.py +++ b/client-cli/cli_lib/network.py @@ -68,7 +68,7 @@ def net_info(config, net): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def net_list(config, limit): """ @@ -87,7 +87,7 @@ def net_list(config, limit): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def net_add(config, vni, description, nettype, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, dhcp4_flag, dhcp4_start, dhcp4_end): """ @@ -118,7 +118,7 @@ def net_add(config, vni, description, nettype, domain, name_servers, ip4_network else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def net_modify(config, net, description, domain, name_servers, ip4_network, ip4_gateway, ip6_network, ip6_gateway, dhcp4_flag, dhcp4_start, dhcp4_end): """ @@ -157,7 +157,7 @@ def net_modify(config, net, description, domain, name_servers, ip4_network, ip4_ else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def net_remove(config, net): """ @@ -174,7 +174,7 @@ def net_remove(config, net): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') # # DHCP lease functions @@ -192,7 +192,7 @@ def net_dhcp_info(config, net, mac): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def net_dhcp_list(config, net, limit, only_static=False): """ @@ -216,7 +216,7 @@ def net_dhcp_list(config, net, limit, only_static=False): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def net_dhcp_add(config, net, ipaddr, macaddr, hostname): """ @@ -238,7 +238,7 @@ def net_dhcp_add(config, net, ipaddr, macaddr, hostname): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def net_dhcp_remove(config, net, mac): """ @@ -255,7 +255,7 @@ def net_dhcp_remove(config, net, mac): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') # # ACL functions @@ -273,7 +273,7 @@ def net_acl_info(config, net, description): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def net_acl_list(config, net, limit, direction): """ @@ -294,7 +294,7 @@ def net_acl_list(config, net, limit, direction): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def net_acl_add(config, net, direction, description, rule, order): """ @@ -318,7 +318,7 @@ def net_acl_add(config, net, direction, description, rule, order): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def net_acl_remove(config, net, description): """ @@ -335,7 +335,7 @@ def net_acl_remove(config, net, description): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') # diff --git a/client-cli/cli_lib/node.py b/client-cli/cli_lib/node.py index 93338dd7..aa4c5acf 100644 --- a/client-cli/cli_lib/node.py +++ b/client-cli/cli_lib/node.py @@ -44,7 +44,7 @@ def node_coordinator_state(config, node, action): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def node_domain_state(config, node, action, wait): """ @@ -65,7 +65,7 @@ def node_domain_state(config, node, action, wait): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def node_info(config, node): """ @@ -80,7 +80,7 @@ def node_info(config, node): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def node_list(config, limit, target_daemon_state, target_coordinator_state, target_domain_state): """ @@ -105,7 +105,7 @@ def node_list(config, limit, target_daemon_state, target_coordinator_state, targ if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') # # Output display functions diff --git a/client-cli/cli_lib/provisioner.py b/client-cli/cli_lib/provisioner.py index 6b8bd9d3..3946f6cd 100644 --- a/client-cli/cli_lib/provisioner.py +++ b/client-cli/cli_lib/provisioner.py @@ -46,7 +46,7 @@ def template_info(config, template, template_type): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def template_list(config, limit, template_type=None): """ @@ -68,7 +68,7 @@ def template_list(config, limit, template_type=None): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def template_add(config, params, template_type=None): """ @@ -85,7 +85,7 @@ def template_add(config, params, template_type=None): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def template_modify(config, params, name, template_type): """ @@ -102,7 +102,7 @@ def template_modify(config, params, name, template_type): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def template_remove(config, name, template_type): """ @@ -119,7 +119,7 @@ def template_remove(config, name, template_type): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def template_element_add(config, name, element_id, params, element_type=None, template_type=None): """ @@ -136,7 +136,7 @@ def template_element_add(config, name, element_id, params, element_type=None, te else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def template_element_remove(config, name, element_id, element_type=None, template_type=None): """ @@ -153,7 +153,7 @@ def template_element_remove(config, name, element_id, element_type=None, templat else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def userdata_info(config, userdata): """ @@ -168,7 +168,7 @@ def userdata_info(config, userdata): if response.status_code == 200: return True, response.json()[0] else: - return False, response.json()['message'] + return False, response.json().get('message', '') def userdata_list(config, limit): """ @@ -187,7 +187,7 @@ def userdata_list(config, limit): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def userdata_show(config, name): """ @@ -202,7 +202,7 @@ def userdata_show(config, name): if response.status_code == 200: return True, response.json()[0]['userdata'] else: - return False, response.json()['message'] + return False, response.json().get('message', '') def userdata_add(config, params): """ @@ -228,7 +228,7 @@ def userdata_add(config, params): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def userdata_modify(config, name, params): """ @@ -253,7 +253,7 @@ def userdata_modify(config, name, params): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def userdata_remove(config, name): """ @@ -270,7 +270,7 @@ def userdata_remove(config, name): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def script_info(config, script): """ @@ -285,7 +285,7 @@ def script_info(config, script): if response.status_code == 200: return True, response.json()[0] else: - return False, response.json()['message'] + return False, response.json().get('message', '') def script_list(config, limit): """ @@ -304,7 +304,7 @@ def script_list(config, limit): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def script_show(config, name): """ @@ -319,7 +319,7 @@ def script_show(config, name): if response.status_code == 200: return True, response.json()[0]['script'] else: - return False, response.json()['message'] + return False, response.json().get('message', '') def script_add(config, params): """ @@ -345,7 +345,7 @@ def script_add(config, params): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def script_modify(config, name, params): """ @@ -370,7 +370,7 @@ def script_modify(config, name, params): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def script_remove(config, name): """ @@ -387,7 +387,7 @@ def script_remove(config, name): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def ova_info(config, name): """ @@ -402,7 +402,7 @@ def ova_info(config, name): if response.status_code == 200: return True, response.json()[0] else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ova_list(config, limit): """ @@ -421,7 +421,7 @@ def ova_list(config, limit): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def ova_upload(config, name, ova_file, params): """ @@ -453,7 +453,7 @@ def ova_upload(config, name, ova_file, params): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def ova_remove(config, name): """ @@ -470,7 +470,7 @@ def ova_remove(config, name): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def profile_info(config, profile): """ @@ -485,7 +485,7 @@ def profile_info(config, profile): if response.status_code == 200: return True, response.json()[0] else: - return False, response.json()['message'] + return False, response.json().get('message', '') def profile_list(config, limit): """ @@ -504,7 +504,7 @@ def profile_list(config, limit): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def profile_add(config, params): """ @@ -521,7 +521,7 @@ def profile_add(config, params): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def profile_modify(config, name, params): """ @@ -538,7 +538,7 @@ def profile_modify(config, name, params): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def profile_remove(config, name): """ @@ -555,7 +555,7 @@ def profile_remove(config, name): else: retvalue = False - return retvalue, response.json()['message'] + return retvalue, response.json().get('message', '') def vm_create(config, name, profile, wait_flag, define_flag, start_flag, script_args): """ @@ -583,7 +583,7 @@ def vm_create(config, name, profile, wait_flag, define_flag, start_flag, script_ retdata = response.json()['task_id'] else: retvalue = False - retdata = response.json()['message'] + retdata = response.json().get('message', '') return retvalue, retdata @@ -631,7 +631,7 @@ def task_status(config, task_id=None, is_watching=False): ) else: retvalue = False - retdata = response.json()['message'] + retdata = response.json().get('message', '') else: retvalue = True task_data_raw = response.json() diff --git a/client-cli/cli_lib/vm.py b/client-cli/cli_lib/vm.py index 4ef94e96..2dc3fcae 100644 --- a/client-cli/cli_lib/vm.py +++ b/client-cli/cli_lib/vm.py @@ -55,7 +55,7 @@ def vm_info(config, vm): return True, response return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def vm_list(config, limit, target_node, target_state): """ @@ -78,7 +78,7 @@ def vm_list(config, limit, target_node, target_state): if response.status_code == 200: return True, response.json() else: - return False, response.json()['message'] + return False, response.json().get('message', '') def vm_define(config, xml, node, node_limit, node_selector, node_autostart): """ @@ -104,7 +104,7 @@ def vm_define(config, xml, node, node_limit, node_selector, node_autostart): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def vm_modify(config, vm, xml, restart): """ @@ -127,7 +127,7 @@ def vm_modify(config, vm, xml, restart): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def vm_metadata(config, vm, node_limit, node_selector, node_autostart, provisioner_profile): """ @@ -160,7 +160,7 @@ def vm_metadata(config, vm, node_limit, node_selector, node_autostart, provision else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def vm_remove(config, vm, delete_disks=False): """ @@ -180,7 +180,7 @@ def vm_remove(config, vm, delete_disks=False): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def vm_state(config, vm, target_state, wait=False): """ @@ -201,7 +201,7 @@ def vm_state(config, vm, target_state, wait=False): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def vm_node(config, vm, target_node, action, force=False, wait=False, force_live=False): """ @@ -225,7 +225,7 @@ def vm_node(config, vm, target_node, action, force=False, wait=False, force_live else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def vm_locks(config, vm): """ @@ -242,7 +242,7 @@ def vm_locks(config, vm): else: retstatus = False - return retstatus, response.json()['message'] + return retstatus, response.json().get('message', '') def view_console_log(config, vm, lines=100): """ @@ -258,7 +258,7 @@ def view_console_log(config, vm, lines=100): response = call_api(config, 'get', '/vm/{vm}/console'.format(vm=vm), params=params) if response.status_code != 200: - return False, response.json()['message'] + return False, response.json().get('message', '') console_log = response.json()['data'] @@ -282,7 +282,7 @@ def follow_console_log(config, vm, lines=10): response = call_api(config, 'get', '/vm/{vm}/console'.format(vm=vm), params=params) if response.status_code != 200: - return False, response.json()['message'] + return False, response.json().get('message', '') # Shrink the log buffer to length lines console_log = response.json()['data']