Use .get for JSON message responses

This commit is contained in:
Joshua Boniface 2020-07-20 12:30:53 -04:00
parent 9f86f12f1a
commit 6fe74b34b2
6 changed files with 85 additions and 85 deletions

View File

@ -114,7 +114,7 @@ def ceph_status(config):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ceph_util(config): def ceph_util(config):
""" """
@ -129,7 +129,7 @@ def ceph_util(config):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def format_raw_output(status_data): def format_raw_output(status_data):
ainformation = list() ainformation = list()
@ -155,7 +155,7 @@ def ceph_osd_info(config, osd):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ceph_osd_list(config, limit): def ceph_osd_list(config, limit):
""" """
@ -174,7 +174,7 @@ def ceph_osd_list(config, limit):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ceph_osd_add(config, node, device, weight): def ceph_osd_add(config, node, device, weight):
""" """
@ -196,7 +196,7 @@ def ceph_osd_add(config, node, device, weight):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def ceph_osd_remove(config, osdid): def ceph_osd_remove(config, osdid):
""" """
@ -216,7 +216,7 @@ def ceph_osd_remove(config, osdid):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def ceph_osd_state(config, osdid, state): def ceph_osd_state(config, osdid, state):
""" """
@ -236,7 +236,7 @@ def ceph_osd_state(config, osdid, state):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def ceph_osd_option(config, option, action): def ceph_osd_option(config, option, action):
""" """
@ -257,7 +257,7 @@ def ceph_osd_option(config, option, action):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def getOutputColoursOSD(osd_information): def getOutputColoursOSD(osd_information):
# Set the UP status # Set the UP status
@ -541,7 +541,7 @@ def ceph_pool_info(config, pool):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ceph_pool_list(config, limit): def ceph_pool_list(config, limit):
""" """
@ -560,7 +560,7 @@ def ceph_pool_list(config, limit):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ceph_pool_add(config, pool, pgs, replcfg): def ceph_pool_add(config, pool, pgs, replcfg):
""" """
@ -582,7 +582,7 @@ def ceph_pool_add(config, pool, pgs, replcfg):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def ceph_pool_remove(config, pool): def ceph_pool_remove(config, pool):
""" """
@ -602,7 +602,7 @@ def ceph_pool_remove(config, pool):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def format_list_pool(pool_list): def format_list_pool(pool_list):
# Handle empty list # Handle empty list
@ -819,7 +819,7 @@ def ceph_volume_info(config, pool, volume):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ceph_volume_list(config, limit, pool): def ceph_volume_list(config, limit, pool):
""" """
@ -840,7 +840,7 @@ def ceph_volume_list(config, limit, pool):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ceph_volume_add(config, pool, volume, size): def ceph_volume_add(config, pool, volume, size):
""" """
@ -862,7 +862,7 @@ def ceph_volume_add(config, pool, volume, size):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def ceph_volume_upload(config, pool, volume, image_format, image_file): 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: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def ceph_volume_remove(config, pool, volume): def ceph_volume_remove(config, pool, volume):
""" """
@ -914,7 +914,7 @@ def ceph_volume_remove(config, pool, volume):
else: else:
retstatus = False 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): 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: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def ceph_volume_clone(config, pool, volume, new_volume): def ceph_volume_clone(config, pool, volume, new_volume):
""" """
@ -958,7 +958,7 @@ def ceph_volume_clone(config, pool, volume, new_volume):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def format_list_volume(volume_list): def format_list_volume(volume_list):
# Handle empty list # Handle empty list
@ -1091,7 +1091,7 @@ def ceph_snapshot_info(config, pool, volume, snapshot):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ceph_snapshot_list(config, limit, volume, pool): 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: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ceph_snapshot_add(config, pool, volume, snapshot): def ceph_snapshot_add(config, pool, volume, snapshot):
""" """
@ -1136,7 +1136,7 @@ def ceph_snapshot_add(config, pool, volume, snapshot):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def ceph_snapshot_remove(config, pool, volume, snapshot): def ceph_snapshot_remove(config, pool, volume, snapshot):
""" """
@ -1153,7 +1153,7 @@ def ceph_snapshot_remove(config, pool, volume, snapshot):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def ceph_snapshot_modify(config, pool, volume, snapshot, new_name=None): 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: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def format_list_snapshot(snapshot_list): def format_list_snapshot(snapshot_list):
# Handle empty list # Handle empty list

View File

@ -40,7 +40,7 @@ def initialize(config):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def maintenance_mode(config, state): def maintenance_mode(config, state):
""" """
@ -60,7 +60,7 @@ def maintenance_mode(config, state):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def get_info(config): def get_info(config):
""" """
@ -75,7 +75,7 @@ def get_info(config):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def format_info(cluster_information, oformat): def format_info(cluster_information, oformat):
if oformat == 'json': if oformat == 'json':

View File

@ -68,7 +68,7 @@ def net_info(config, net):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def net_list(config, limit): def net_list(config, limit):
""" """
@ -87,7 +87,7 @@ def net_list(config, limit):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: 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): 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: else:
retstatus = False 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): 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: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def net_remove(config, net): def net_remove(config, net):
""" """
@ -174,7 +174,7 @@ def net_remove(config, net):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
# #
# DHCP lease functions # DHCP lease functions
@ -192,7 +192,7 @@ def net_dhcp_info(config, net, mac):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def net_dhcp_list(config, net, limit, only_static=False): 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: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def net_dhcp_add(config, net, ipaddr, macaddr, hostname): def net_dhcp_add(config, net, ipaddr, macaddr, hostname):
""" """
@ -238,7 +238,7 @@ def net_dhcp_add(config, net, ipaddr, macaddr, hostname):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def net_dhcp_remove(config, net, mac): def net_dhcp_remove(config, net, mac):
""" """
@ -255,7 +255,7 @@ def net_dhcp_remove(config, net, mac):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
# #
# ACL functions # ACL functions
@ -273,7 +273,7 @@ def net_acl_info(config, net, description):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def net_acl_list(config, net, limit, direction): 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: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def net_acl_add(config, net, direction, description, rule, order): 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: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def net_acl_remove(config, net, description): def net_acl_remove(config, net, description):
""" """
@ -335,7 +335,7 @@ def net_acl_remove(config, net, description):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
# #

View File

@ -44,7 +44,7 @@ def node_coordinator_state(config, node, action):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def node_domain_state(config, node, action, wait): def node_domain_state(config, node, action, wait):
""" """
@ -65,7 +65,7 @@ def node_domain_state(config, node, action, wait):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def node_info(config, node): def node_info(config, node):
""" """
@ -80,7 +80,7 @@ def node_info(config, node):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: 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): 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: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
# #
# Output display functions # Output display functions

View File

@ -46,7 +46,7 @@ def template_info(config, template, template_type):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def template_list(config, limit, template_type=None): 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: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def template_add(config, params, template_type=None): def template_add(config, params, template_type=None):
""" """
@ -85,7 +85,7 @@ def template_add(config, params, template_type=None):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def template_modify(config, params, name, template_type): def template_modify(config, params, name, template_type):
""" """
@ -102,7 +102,7 @@ def template_modify(config, params, name, template_type):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def template_remove(config, name, template_type): def template_remove(config, name, template_type):
""" """
@ -119,7 +119,7 @@ def template_remove(config, name, template_type):
else: else:
retvalue = False 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): 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: else:
retvalue = False 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): 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: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def userdata_info(config, userdata): def userdata_info(config, userdata):
""" """
@ -168,7 +168,7 @@ def userdata_info(config, userdata):
if response.status_code == 200: if response.status_code == 200:
return True, response.json()[0] return True, response.json()[0]
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def userdata_list(config, limit): def userdata_list(config, limit):
""" """
@ -187,7 +187,7 @@ def userdata_list(config, limit):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def userdata_show(config, name): def userdata_show(config, name):
""" """
@ -202,7 +202,7 @@ def userdata_show(config, name):
if response.status_code == 200: if response.status_code == 200:
return True, response.json()[0]['userdata'] return True, response.json()[0]['userdata']
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def userdata_add(config, params): def userdata_add(config, params):
""" """
@ -228,7 +228,7 @@ def userdata_add(config, params):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def userdata_modify(config, name, params): def userdata_modify(config, name, params):
""" """
@ -253,7 +253,7 @@ def userdata_modify(config, name, params):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def userdata_remove(config, name): def userdata_remove(config, name):
""" """
@ -270,7 +270,7 @@ def userdata_remove(config, name):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def script_info(config, script): def script_info(config, script):
""" """
@ -285,7 +285,7 @@ def script_info(config, script):
if response.status_code == 200: if response.status_code == 200:
return True, response.json()[0] return True, response.json()[0]
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def script_list(config, limit): def script_list(config, limit):
""" """
@ -304,7 +304,7 @@ def script_list(config, limit):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def script_show(config, name): def script_show(config, name):
""" """
@ -319,7 +319,7 @@ def script_show(config, name):
if response.status_code == 200: if response.status_code == 200:
return True, response.json()[0]['script'] return True, response.json()[0]['script']
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def script_add(config, params): def script_add(config, params):
""" """
@ -345,7 +345,7 @@ def script_add(config, params):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def script_modify(config, name, params): def script_modify(config, name, params):
""" """
@ -370,7 +370,7 @@ def script_modify(config, name, params):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def script_remove(config, name): def script_remove(config, name):
""" """
@ -387,7 +387,7 @@ def script_remove(config, name):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def ova_info(config, name): def ova_info(config, name):
""" """
@ -402,7 +402,7 @@ def ova_info(config, name):
if response.status_code == 200: if response.status_code == 200:
return True, response.json()[0] return True, response.json()[0]
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ova_list(config, limit): def ova_list(config, limit):
""" """
@ -421,7 +421,7 @@ def ova_list(config, limit):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def ova_upload(config, name, ova_file, params): def ova_upload(config, name, ova_file, params):
""" """
@ -453,7 +453,7 @@ def ova_upload(config, name, ova_file, params):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def ova_remove(config, name): def ova_remove(config, name):
""" """
@ -470,7 +470,7 @@ def ova_remove(config, name):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def profile_info(config, profile): def profile_info(config, profile):
""" """
@ -485,7 +485,7 @@ def profile_info(config, profile):
if response.status_code == 200: if response.status_code == 200:
return True, response.json()[0] return True, response.json()[0]
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def profile_list(config, limit): def profile_list(config, limit):
""" """
@ -504,7 +504,7 @@ def profile_list(config, limit):
if response.status_code == 200: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def profile_add(config, params): def profile_add(config, params):
""" """
@ -521,7 +521,7 @@ def profile_add(config, params):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def profile_modify(config, name, params): def profile_modify(config, name, params):
""" """
@ -538,7 +538,7 @@ def profile_modify(config, name, params):
else: else:
retvalue = False retvalue = False
return retvalue, response.json()['message'] return retvalue, response.json().get('message', '')
def profile_remove(config, name): def profile_remove(config, name):
""" """
@ -555,7 +555,7 @@ def profile_remove(config, name):
else: else:
retvalue = False 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): 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'] retdata = response.json()['task_id']
else: else:
retvalue = False retvalue = False
retdata = response.json()['message'] retdata = response.json().get('message', '')
return retvalue, retdata return retvalue, retdata
@ -631,7 +631,7 @@ def task_status(config, task_id=None, is_watching=False):
) )
else: else:
retvalue = False retvalue = False
retdata = response.json()['message'] retdata = response.json().get('message', '')
else: else:
retvalue = True retvalue = True
task_data_raw = response.json() task_data_raw = response.json()

View File

@ -55,7 +55,7 @@ def vm_info(config, vm):
return True, response return True, response
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def vm_list(config, limit, target_node, target_state): 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: if response.status_code == 200:
return True, response.json() return True, response.json()
else: else:
return False, response.json()['message'] return False, response.json().get('message', '')
def vm_define(config, xml, node, node_limit, node_selector, node_autostart): 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: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def vm_modify(config, vm, xml, restart): def vm_modify(config, vm, xml, restart):
""" """
@ -127,7 +127,7 @@ def vm_modify(config, vm, xml, restart):
else: else:
retstatus = False 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): 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: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def vm_remove(config, vm, delete_disks=False): def vm_remove(config, vm, delete_disks=False):
""" """
@ -180,7 +180,7 @@ def vm_remove(config, vm, delete_disks=False):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def vm_state(config, vm, target_state, wait=False): def vm_state(config, vm, target_state, wait=False):
""" """
@ -201,7 +201,7 @@ def vm_state(config, vm, target_state, wait=False):
else: else:
retstatus = False 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): 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: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def vm_locks(config, vm): def vm_locks(config, vm):
""" """
@ -242,7 +242,7 @@ def vm_locks(config, vm):
else: else:
retstatus = False retstatus = False
return retstatus, response.json()['message'] return retstatus, response.json().get('message', '')
def view_console_log(config, vm, lines=100): 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) response = call_api(config, 'get', '/vm/{vm}/console'.format(vm=vm), params=params)
if response.status_code != 200: if response.status_code != 200:
return False, response.json()['message'] return False, response.json().get('message', '')
console_log = response.json()['data'] 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) response = call_api(config, 'get', '/vm/{vm}/console'.format(vm=vm), params=params)
if response.status_code != 200: if response.status_code != 200:
return False, response.json()['message'] return False, response.json().get('message', '')
# Shrink the log buffer to length lines # Shrink the log buffer to length lines
console_log = response.json()['data'] console_log = response.json()['data']