Fixed exception handeling for Python 2.4 and python 3 compatablity (#2364)
This commit is contained in:
parent
a0bd87f04e
commit
4f042c8cfa
3 changed files with 16 additions and 6 deletions
|
@ -101,6 +101,8 @@ try:
|
||||||
except:
|
except:
|
||||||
HAS_GITLAB_PACKAGE = False
|
HAS_GITLAB_PACKAGE = False
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import *
|
||||||
|
from ansible.module_utils.pycompat24 import get_exception
|
||||||
|
|
||||||
class GitLabGroup(object):
|
class GitLabGroup(object):
|
||||||
def __init__(self, module, git):
|
def __init__(self, module, git):
|
||||||
|
@ -187,7 +189,8 @@ def main():
|
||||||
git.login(user=login_user, password=login_password)
|
git.login(user=login_user, password=login_password)
|
||||||
else:
|
else:
|
||||||
git = gitlab.Gitlab(server_url, token=login_token, verify_ssl=verify_ssl)
|
git = gitlab.Gitlab(server_url, token=login_token, verify_ssl=verify_ssl)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failed to connect to Gitlab server: %s " % e)
|
module.fail_json(msg="Failed to connect to Gitlab server: %s " % e)
|
||||||
|
|
||||||
# Validate if group exists and take action based on "state"
|
# Validate if group exists and take action based on "state"
|
||||||
|
@ -209,7 +212,7 @@ def main():
|
||||||
module.exit_json(changed=True, result="Successfully created or updated the group %s" % group_name)
|
module.exit_json(changed=True, result="Successfully created or updated the group %s" % group_name)
|
||||||
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -163,6 +163,9 @@ try:
|
||||||
except:
|
except:
|
||||||
HAS_GITLAB_PACKAGE = False
|
HAS_GITLAB_PACKAGE = False
|
||||||
|
|
||||||
|
from ansible.module_utils.basic import *
|
||||||
|
from ansible.module_utils.pycompat24 import get_exception
|
||||||
|
|
||||||
|
|
||||||
class GitLabProject(object):
|
class GitLabProject(object):
|
||||||
def __init__(self, module, git):
|
def __init__(self, module, git):
|
||||||
|
@ -361,7 +364,8 @@ def main():
|
||||||
git.login(user=login_user, password=login_password)
|
git.login(user=login_user, password=login_password)
|
||||||
else:
|
else:
|
||||||
git = gitlab.Gitlab(server_url, token=login_token, verify_ssl=verify_ssl)
|
git = gitlab.Gitlab(server_url, token=login_token, verify_ssl=verify_ssl)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failed to connect to Gitlab server: %s " % e)
|
module.fail_json(msg="Failed to connect to Gitlab server: %s " % e)
|
||||||
|
|
||||||
# Validate if project exists and take action based on "state"
|
# Validate if project exists and take action based on "state"
|
||||||
|
@ -391,7 +395,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
module.exit_json(changed=False)
|
module.exit_json(changed=False)
|
||||||
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -137,6 +137,9 @@ try:
|
||||||
except:
|
except:
|
||||||
HAS_GITLAB_PACKAGE = False
|
HAS_GITLAB_PACKAGE = False
|
||||||
|
|
||||||
|
from ansible.module_utils.pycompat24 import get_exception
|
||||||
|
from ansible.module_utils.basic import *
|
||||||
|
|
||||||
|
|
||||||
class GitLabUser(object):
|
class GitLabUser(object):
|
||||||
def __init__(self, module, git):
|
def __init__(self, module, git):
|
||||||
|
@ -325,7 +328,8 @@ def main():
|
||||||
git.login(user=login_user, password=login_password)
|
git.login(user=login_user, password=login_password)
|
||||||
else:
|
else:
|
||||||
git = gitlab.Gitlab(server_url, token=login_token, verify_ssl=verify_ssl)
|
git = gitlab.Gitlab(server_url, token=login_token, verify_ssl=verify_ssl)
|
||||||
except Exception, e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json(msg="Failed to connect to Gitlab server: %s " % e)
|
module.fail_json(msg="Failed to connect to Gitlab server: %s " % e)
|
||||||
|
|
||||||
# Validate if group exists and take action based on "state"
|
# Validate if group exists and take action based on "state"
|
||||||
|
@ -342,7 +346,6 @@ def main():
|
||||||
user.createOrUpdateUser(user_name, user_username, user_password, user_email, user_sshkey_name, user_sshkey_file, group_name, access_level)
|
user.createOrUpdateUser(user_name, user_username, user_password, user_email, user_sshkey_name, user_sshkey_file, group_name, access_level)
|
||||||
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue