return a proper result set for getmaster/getslave (#2595)
* return a proper result set for getmaster/getslave when not on a master/slave. This allows for a cleaner error handling. * A more uniform return of result keys for getmaster/slave
This commit is contained in:
parent
9a47088d67
commit
fc76455326
1 changed files with 12 additions and 10 deletions
|
@ -258,18 +258,20 @@ def main():
|
||||||
module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, e))
|
module.fail_json(msg="unable to find %s. Exception message: %s" % (config_file, e))
|
||||||
|
|
||||||
if mode in "getmaster":
|
if mode in "getmaster":
|
||||||
masterstatus = get_master_status(cursor)
|
status = get_master_status(cursor)
|
||||||
try:
|
if not isinstance(status, dict):
|
||||||
module.exit_json( **masterstatus )
|
status = dict(Is_Master=False, msg="Server is not configured as mysql master")
|
||||||
except TypeError:
|
else:
|
||||||
module.fail_json(msg="Server is not configured as mysql master")
|
status['Is_Master'] = True
|
||||||
|
module.exit_json(**status)
|
||||||
|
|
||||||
elif mode in "getslave":
|
elif mode in "getslave":
|
||||||
slavestatus = get_slave_status(cursor)
|
status = get_slave_status(cursor)
|
||||||
try:
|
if not isinstance(status, dict):
|
||||||
module.exit_json( **slavestatus )
|
status = dict(Is_Slave=False, msg="Server is not configured as mysql slave")
|
||||||
except TypeError, e:
|
else:
|
||||||
module.fail_json(msg="Server is not configured as mysql slave. ERROR: %s" % e)
|
status['Is_Slave'] = True
|
||||||
|
module.exit_json(**status)
|
||||||
|
|
||||||
elif mode in "changemaster":
|
elif mode in "changemaster":
|
||||||
chm=[]
|
chm=[]
|
||||||
|
|
Loading…
Add table
Reference in a new issue