mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Pep8 fixes for ejabberd_user and jboss (#24586)
* PEP* Fixes * Refactor code Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
894b86a467
commit
677a6c2982
3 changed files with 32 additions and 31 deletions
|
@ -79,12 +79,14 @@ EXAMPLES = '''
|
||||||
|
|
||||||
import syslog
|
import syslog
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
from ansible.module_utils.pycompat24 import get_exception
|
||||||
from ansible.module_utils.basic import *
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
class EjabberdUserException(Exception):
|
class EjabberdUserException(Exception):
|
||||||
""" Base exception for EjabberdUser class object """
|
""" Base exception for EjabberdUser class object """
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class EjabberdUser(object):
|
class EjabberdUser(object):
|
||||||
""" This object represents a user resource for an ejabberd server. The
|
""" This object represents a user resource for an ejabberd server. The
|
||||||
object manages user creation and deletion using ejabberdctl. The following
|
object manages user creation and deletion using ejabberdctl. The following
|
||||||
|
@ -181,22 +183,23 @@ class EjabberdUser(object):
|
||||||
(rc, out, err) = (1, None, "required attribute(s) missing")
|
(rc, out, err) = (1, None, "required attribute(s) missing")
|
||||||
return (rc, out, err)
|
return (rc, out, err)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
host=dict(default=None, type='str'),
|
host=dict(default=None, type='str'),
|
||||||
username=dict(default=None, type='str'),
|
username=dict(default=None, type='str'),
|
||||||
password=dict(default=None, type='str', no_log=True),
|
password=dict(default=None, type='str', no_log=True),
|
||||||
state=dict(default='present', choices=['present', 'absent']),
|
state=dict(default='present', choices=['present', 'absent']),
|
||||||
logging=dict(default=False, type='bool')
|
logging=dict(default=False, type='bool')
|
||||||
),
|
),
|
||||||
supports_check_mode = True
|
supports_check_mode=True
|
||||||
)
|
)
|
||||||
|
|
||||||
obj = EjabberdUser(module)
|
obj = EjabberdUser(module)
|
||||||
|
|
||||||
rc = None
|
rc = None
|
||||||
result = dict()
|
result = dict(changed=False)
|
||||||
|
|
||||||
if obj.state == 'absent':
|
if obj.state == 'absent':
|
||||||
if obj.exists:
|
if obj.exists:
|
||||||
|
|
|
@ -77,36 +77,39 @@ EXAMPLES = """
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import time
|
import time
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
def is_deployed(deploy_path, deployment):
|
def is_deployed(deploy_path, deployment):
|
||||||
return os.path.exists(os.path.join(deploy_path, "%s.deployed"%(deployment)))
|
return os.path.exists(os.path.join(deploy_path, "%s.deployed" % deployment))
|
||||||
|
|
||||||
|
|
||||||
def is_undeployed(deploy_path, deployment):
|
def is_undeployed(deploy_path, deployment):
|
||||||
return os.path.exists(os.path.join(deploy_path, "%s.undeployed"%(deployment)))
|
return os.path.exists(os.path.join(deploy_path, "%s.undeployed" % deployment))
|
||||||
|
|
||||||
|
|
||||||
def is_failed(deploy_path, deployment):
|
def is_failed(deploy_path, deployment):
|
||||||
return os.path.exists(os.path.join(deploy_path, "%s.failed"%(deployment)))
|
return os.path.exists(os.path.join(deploy_path, "%s.failed" % deployment))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
src=dict(),
|
src=dict(type='path'),
|
||||||
deployment=dict(required=True),
|
deployment=dict(required=True),
|
||||||
deploy_path=dict(default='/var/lib/jbossas/standalone/deployments'),
|
deploy_path=dict(type='path', default='/var/lib/jbossas/standalone/deployments'),
|
||||||
state=dict(choices=['absent', 'present'], default='present'),
|
state=dict(choices=['absent', 'present'], default='present'),
|
||||||
),
|
),
|
||||||
|
required_if=[('state', 'present', ('src',))]
|
||||||
)
|
)
|
||||||
|
|
||||||
changed = False
|
result = dict(changed=False)
|
||||||
|
|
||||||
src = module.params['src']
|
src = module.params['src']
|
||||||
deployment = module.params['deployment']
|
deployment = module.params['deployment']
|
||||||
deploy_path = module.params['deploy_path']
|
deploy_path = module.params['deploy_path']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
|
||||||
if state == 'present' and not src:
|
|
||||||
module.fail_json(msg="Argument 'src' required.")
|
|
||||||
|
|
||||||
if not os.path.exists(deploy_path):
|
if not os.path.exists(deploy_path):
|
||||||
module.fail_json(msg="deploy_path does not exist.")
|
module.fail_json(msg="deploy_path does not exist.")
|
||||||
|
|
||||||
|
@ -114,44 +117,41 @@ def main():
|
||||||
|
|
||||||
if state == 'present' and not deployed:
|
if state == 'present' and not deployed:
|
||||||
if not os.path.exists(src):
|
if not os.path.exists(src):
|
||||||
module.fail_json(msg='Source file %s does not exist.'%(src))
|
module.fail_json(msg='Source file %s does not exist.' % src)
|
||||||
if is_failed(deploy_path, deployment):
|
if is_failed(deploy_path, deployment):
|
||||||
### Clean up old failed deployment
|
# Clean up old failed deployment
|
||||||
os.remove(os.path.join(deploy_path, "%s.failed"%(deployment)))
|
os.remove(os.path.join(deploy_path, "%s.failed" % deployment))
|
||||||
|
|
||||||
shutil.copyfile(src, os.path.join(deploy_path, deployment))
|
shutil.copyfile(src, os.path.join(deploy_path, deployment))
|
||||||
while not deployed:
|
while not deployed:
|
||||||
deployed = is_deployed(deploy_path, deployment)
|
deployed = is_deployed(deploy_path, deployment)
|
||||||
if is_failed(deploy_path, deployment):
|
if is_failed(deploy_path, deployment):
|
||||||
module.fail_json(msg='Deploying %s failed.'%(deployment))
|
module.fail_json(msg='Deploying %s failed.' % deployment)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
changed = True
|
result['changed'] = True
|
||||||
|
|
||||||
if state == 'present' and deployed:
|
if state == 'present' and deployed:
|
||||||
if module.sha1(src) != module.sha1(os.path.join(deploy_path, deployment)):
|
if module.sha1(src) != module.sha1(os.path.join(deploy_path, deployment)):
|
||||||
os.remove(os.path.join(deploy_path, "%s.deployed"%(deployment)))
|
os.remove(os.path.join(deploy_path, "%s.deployed" % deployment))
|
||||||
shutil.copyfile(src, os.path.join(deploy_path, deployment))
|
shutil.copyfile(src, os.path.join(deploy_path, deployment))
|
||||||
deployed = False
|
deployed = False
|
||||||
while not deployed:
|
while not deployed:
|
||||||
deployed = is_deployed(deploy_path, deployment)
|
deployed = is_deployed(deploy_path, deployment)
|
||||||
if is_failed(deploy_path, deployment):
|
if is_failed(deploy_path, deployment):
|
||||||
module.fail_json(msg='Deploying %s failed.'%(deployment))
|
module.fail_json(msg='Deploying %s failed.' % deployment)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
changed = True
|
result['changed'] = True
|
||||||
|
|
||||||
if state == 'absent' and deployed:
|
if state == 'absent' and deployed:
|
||||||
os.remove(os.path.join(deploy_path, "%s.deployed"%(deployment)))
|
os.remove(os.path.join(deploy_path, "%s.deployed" % deployment))
|
||||||
while deployed:
|
while deployed:
|
||||||
deployed = not is_undeployed(deploy_path, deployment)
|
deployed = not is_undeployed(deploy_path, deployment)
|
||||||
if is_failed(deploy_path, deployment):
|
if is_failed(deploy_path, deployment):
|
||||||
module.fail_json(msg='Undeploying %s failed.'%(deployment))
|
module.fail_json(msg='Undeploying %s failed.' % deployment)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
changed = True
|
result['changed'] = True
|
||||||
|
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(**result)
|
||||||
|
|
||||||
# import module snippets
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -570,5 +570,3 @@ lib/ansible/modules/utilities/helper/_accelerate.py
|
||||||
lib/ansible/modules/utilities/logic/async_status.py
|
lib/ansible/modules/utilities/logic/async_status.py
|
||||||
lib/ansible/modules/utilities/logic/async_wrapper.py
|
lib/ansible/modules/utilities/logic/async_wrapper.py
|
||||||
lib/ansible/modules/utilities/logic/wait_for.py
|
lib/ansible/modules/utilities/logic/wait_for.py
|
||||||
lib/ansible/modules/web_infrastructure/ejabberd_user.py
|
|
||||||
lib/ansible/modules/web_infrastructure/jboss.py
|
|
||||||
|
|
Loading…
Reference in a new issue