From 1aa4d0c2dd8c9cbb090f1d96159df7323ced5f60 Mon Sep 17 00:00:00 2001 From: Rene Moser Date: Sun, 28 Jun 2015 12:52:05 +0200 Subject: [PATCH] cloudstack: update code to match best practice * Remove catchall exception * use `if __name__ == '__main__':` --- lib/ansible/modules/extras/cloud/cloudstack/cs_account.py | 6 ++---- .../modules/extras/cloud/cloudstack/cs_affinitygroup.py | 6 ++---- lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py | 6 ++---- lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py | 6 ++---- .../modules/extras/cloud/cloudstack/cs_instancegroup.py | 6 ++---- lib/ansible/modules/extras/cloud/cloudstack/cs_iso.py | 6 ++---- lib/ansible/modules/extras/cloud/cloudstack/cs_network.py | 6 ++---- .../modules/extras/cloud/cloudstack/cs_portforward.py | 6 ++---- lib/ansible/modules/extras/cloud/cloudstack/cs_project.py | 6 ++---- .../modules/extras/cloud/cloudstack/cs_securitygroup.py | 6 ++---- .../extras/cloud/cloudstack/cs_securitygroup_rule.py | 6 ++---- .../modules/extras/cloud/cloudstack/cs_sshkeypair.py | 6 ++---- lib/ansible/modules/extras/cloud/cloudstack/cs_template.py | 6 ++---- .../modules/extras/cloud/cloudstack/cs_vmsnapshot.py | 6 ++---- 14 files changed, 28 insertions(+), 56 deletions(-) diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py index cc487af5e5..d130285445 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_account.py @@ -400,11 +400,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py index 2052300ff0..6d37878dcb 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_affinitygroup.py @@ -245,11 +245,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py index 211b6c04e9..5d77e3be04 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_firewall.py @@ -450,11 +450,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py index f9f7c54bea..e08d85eea9 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_instance.py @@ -852,11 +852,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_instancegroup.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_instancegroup.py index 478748aeec..7280ceff5e 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_instancegroup.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_instancegroup.py @@ -223,11 +223,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_iso.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_iso.py index f907c0d193..308633edd6 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_iso.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_iso.py @@ -353,11 +353,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py index b602b34567..50dd2981e7 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_network.py @@ -627,11 +627,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py index 8606f6329d..3cdc801746 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_portforward.py @@ -427,11 +427,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py index 0f391bc500..f09c42f589 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_project.py @@ -332,11 +332,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py index c9a72c15d5..5e85a6f56e 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup.py @@ -188,11 +188,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py index a62447ff6c..6fde5a71cd 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_securitygroup_rule.py @@ -428,11 +428,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py index 180e96ca6a..28c6b3802b 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_sshkeypair.py @@ -249,11 +249,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py index 1cd245d2b5..8e56aafaa7 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_template.py @@ -623,11 +623,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py b/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py index c487dd0b4c..15a5725bb8 100644 --- a/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py +++ b/lib/ansible/modules/extras/cloud/cloudstack/cs_vmsnapshot.py @@ -316,11 +316,9 @@ def main(): except CloudStackException, e: module.fail_json(msg='CloudStackException: %s' % str(e)) - except Exception, e: - module.fail_json(msg='Exception: %s' % str(e)) - module.exit_json(**result) # import module snippets from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main()