Fix remaining python3 compile problems

This commit is contained in:
Toshio Kuratomi
2016-10-23 16:24:38 -07:00
committed by Matt Clay
parent 3901fe72d3
commit ea05c56a41
19 changed files with 279 additions and 196 deletions

View File

@@ -117,7 +117,6 @@ VIRT_FAILED = 1
VIRT_SUCCESS = 0
VIRT_UNAVAILABLE=2
import sys
try:
import libvirt
@@ -133,6 +132,9 @@ except ImportError:
else:
HAS_XML = True
from ansible.module_utils.basic import AnsibleModule
ALL_COMMANDS = []
ENTRY_COMMANDS = ['create', 'status', 'start', 'stop',
'undefine', 'destroy', 'get_xml', 'define',
@@ -345,7 +347,7 @@ class LibvirtConnection(object):
return self.conn.networkDefineXML(xml)
else:
try:
state = self.find_entry(entryid)
self.find_entry(entryid)
except:
return self.module.exit_json(changed=True)
@@ -428,17 +430,17 @@ class VirtNetwork(object):
try:
results[entry]["forward_mode"] = self.conn.get_forward(entry)
except ValueError as e:
except ValueError:
pass
try:
results[entry]["domain"] = self.conn.get_domain(entry)
except ValueError as e:
except ValueError:
pass
try:
results[entry]["macaddress"] = self.conn.get_macaddress(entry)
except ValueError as e:
except ValueError:
pass
facts = dict()
@@ -532,7 +534,7 @@ def core(module):
return VIRT_SUCCESS, res
else:
module.fail_json(msg="Command %s not recognized" % basecmd)
module.fail_json(msg="Command %s not recognized" % command)
if autostart is not None:
if not name:
@@ -580,7 +582,7 @@ def main():
rc = VIRT_SUCCESS
try:
rc, result = core(module)
except Exception, e:
except Exception as e:
module.fail_json(msg=str(e))
if rc != 0: # something went wrong emit the msg
@@ -589,6 +591,5 @@ def main():
module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import *
main()
if __name__ == '__main__':
main()

View File

@@ -128,8 +128,6 @@ VIRT_FAILED = 1
VIRT_SUCCESS = 0
VIRT_UNAVAILABLE=2
import sys
try:
import libvirt
except ImportError:
@@ -144,6 +142,9 @@ except ImportError:
else:
HAS_XML = True
from ansible.module_utils.basic import AnsibleModule
ALL_COMMANDS = []
ENTRY_COMMANDS = ['create', 'status', 'start', 'stop', 'build', 'delete',
'undefine', 'destroy', 'get_xml', 'define', 'refresh']
@@ -397,7 +398,7 @@ class LibvirtConnection(object):
return self.conn.storagePoolDefineXML(xml)
else:
try:
state = self.find_entry(entryid)
self.find_entry(entryid)
except:
return self.module.exit_json(changed=True)
@@ -514,23 +515,23 @@ class VirtStoragePool(object):
try:
results[entry]["host"] = self.conn.get_host(entry)
except ValueError as e:
except ValueError:
pass
try:
results[entry]["source_path"] = self.conn.get_source_path(entry)
except ValueError as e:
except ValueError:
pass
try:
results[entry]["format"] = self.conn.get_format(entry)
except ValueError as e:
except ValueError:
pass
try:
devices = self.conn.get_devices(entry)
results[entry]["devices"] = devices
except ValueError as e:
except ValueError:
pass
else:
@@ -642,7 +643,7 @@ def core(module):
return VIRT_SUCCESS, res
else:
module.fail_json(msg="Command %s not recognized" % basecmd)
module.fail_json(msg="Command %s not recognized" % command)
if autostart is not None:
if not name:
@@ -691,7 +692,7 @@ def main():
rc = VIRT_SUCCESS
try:
rc, result = core(module)
except Exception, e:
except Exception as e:
module.fail_json(msg=str(e))
if rc != 0: # something went wrong emit the msg
@@ -700,6 +701,5 @@ def main():
module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import *
main()
if __name__ == '__main__':
main()

View File

@@ -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()

View File

@@ -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()