diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2016-10-23 16:24:38 -0700 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2016-10-23 16:53:06 -0700 |
commit | 6b0a204e74144bb2adc42292ea0ca6379b3f739d (patch) | |
tree | e617a72d2990389ea836f207fb5089f4df2d0043 /cloud/profitbricks | |
parent | 79c7997952ec790f38caf027078bbcc294f928d1 (diff) | |
download | ansible-modules-extras-6b0a204e74144bb2adc42292ea0ca6379b3f739d.tar.gz |
Fix remaining python3 compile problems
Diffstat (limited to 'cloud/profitbricks')
-rw-r--r-- | cloud/profitbricks/profitbricks.py | 30 | ||||
-rw-r--r-- | cloud/profitbricks/profitbricks_volume.py | 21 |
2 files changed, 33 insertions, 18 deletions
diff --git a/cloud/profitbricks/profitbricks.py b/cloud/profitbricks/profitbricks.py index 7c9f23f6..caa1e0cc 100644 --- a/cloud/profitbricks/profitbricks.py +++ b/cloud/profitbricks/profitbricks.py @@ -206,6 +206,10 @@ try: except ImportError: HAS_PB_SDK = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.pycompat24 import get_exception + + LOCATIONS = ['us/las', 'de/fra', 'de/fkb'] @@ -325,7 +329,7 @@ def _startstop_machine(module, profitbricks, datacenter_id, server_id): return True except Exception as e: - module.fail_json(msg="failed to start or stop the virtual machine %s: %s" % (name, str(e))) + module.fail_json(msg="failed to start or stop the virtual machine %s at %s: %s" % (server_id, datacenter_id, str(e))) def _create_datacenter(module, profitbricks): @@ -390,7 +394,8 @@ def create_virtual_machine(module, profitbricks): try: name % 0 - except TypeError, e: + except TypeError: + e = get_exception() if e.message.startswith('not all'): name = '%s%%d' % name else: @@ -475,7 +480,8 @@ def remove_virtual_machine(module, profitbricks): # Remove the server try: server_response = profitbricks.delete_server(datacenter_id, server_id) - except Exception as e: + except Exception: + e = get_exception() module.fail_json(msg="failed to terminate the virtual server: %s" % str(e)) else: changed = True @@ -491,7 +497,8 @@ def _remove_boot_volume(module, profitbricks, datacenter_id, server_id): server = profitbricks.get_server(datacenter_id, server_id) volume_id = server['properties']['bootVolume']['id'] volume_response = profitbricks.delete_volume(datacenter_id, volume_id) - except Exception as e: + except Exception: + e = get_exception() module.fail_json(msg="failed to remove the server's boot volume: %s" % str(e)) @@ -609,8 +616,6 @@ def main(): subscription_user = module.params.get('subscription_user') subscription_password = module.params.get('subscription_password') - wait = module.params.get('wait') - wait_timeout = module.params.get('wait_timeout') profitbricks = ProfitBricksService( username=subscription_user, @@ -626,7 +631,8 @@ def main(): try: (changed) = remove_virtual_machine(module, profitbricks) module.exit_json(changed=changed) - except Exception as e: + except Exception: + e = get_exception() module.fail_json(msg='failed to set instance state: %s' % str(e)) elif state in ('running', 'stopped'): @@ -636,7 +642,8 @@ def main(): try: (changed) = startstop_machine(module, profitbricks, state) module.exit_json(changed=changed) - except Exception as e: + except Exception: + e = get_exception() module.fail_json(msg='failed to set instance state: %s' % str(e)) elif state == 'present': @@ -654,9 +661,10 @@ def main(): try: (machine_dict_array) = create_virtual_machine(module, profitbricks) module.exit_json(**machine_dict_array) - except Exception as e: + except Exception: + e = get_exception() module.fail_json(msg='failed to set instance state: %s' % str(e)) -from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() diff --git a/cloud/profitbricks/profitbricks_volume.py b/cloud/profitbricks/profitbricks_volume.py index 1cee9676..a6c3d069 100644 --- a/cloud/profitbricks/profitbricks_volume.py +++ b/cloud/profitbricks/profitbricks_volume.py @@ -135,7 +135,6 @@ EXAMPLES = ''' ''' import re -import uuid import time HAS_PB_SDK = True @@ -145,6 +144,10 @@ try: except ImportError: HAS_PB_SDK = False +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.pycompat24 import get_exception + + uuid_match = re.compile( '[\w]{8}-[\w]{4}-[\w]{4}-[\w]{4}-[\w]{12}', re.I) @@ -253,7 +256,8 @@ def create_volume(module, profitbricks): try: name % 0 - except TypeError, e: + except TypeError: + e = get_exception() if e.message.startswith('not all'): name = '%s%%d' % name else: @@ -354,7 +358,8 @@ def _attach_volume(module, profitbricks, datacenter, volume): try: return profitbricks.attach_volume(datacenter, server, volume) - except Exception as e: + except Exception: + e = get_exception() module.fail_json(msg='failed to attach volume: %s' % str(e)) @@ -403,7 +408,8 @@ def main(): try: (changed) = delete_volume(module, profitbricks) module.exit_json(changed=changed) - except Exception as e: + except Exception: + e = get_exception() module.fail_json(msg='failed to set volume state: %s' % str(e)) elif state == 'present': @@ -415,9 +421,10 @@ def main(): try: (volume_dict_array) = create_volume(module, profitbricks) module.exit_json(**volume_dict_array) - except Exception as e: + except Exception: + e = get_exception() module.fail_json(msg='failed to set volume state: %s' % str(e)) -from ansible.module_utils.basic import * -main() +if __name__ == '__main__': + main() |