Py3 compatibility fixes

This commit is contained in:
Pedro Algarvio 2014-11-22 12:21:53 +00:00
parent 84955b4605
commit 2ebc8a1a9f

View File

@ -25,9 +25,9 @@ Set up the cloud configuration at ``/etc/salt/cloud.providers`` or
:depends: requests >= 2.2.1
:depends: IPy >= 0.81
'''
from __future__ import absolute_import
# Import python libs
from __future__ import absolute_import
import copy
import time
import pprint
@ -45,6 +45,9 @@ from salt.exceptions import (
SaltCloudExecutionTimeout
)
# Import 3rd-party libs
import salt.ext.six as six
# Get logging started
log = logging.getLogger(__name__)
@ -182,7 +185,7 @@ def _getVmById(vmid, allDetails=False):
'''
Retrieve a VM based on the ID.
'''
for vm_name, vm_details in get_resources_vms(includeConfig=allDetails).items():
for vm_name, vm_details in six.iteritems(get_resources_vms(includeConfig=allDetails)):
if str(vm_details['vmid']) == str(vmid):
return vm_details
@ -204,7 +207,7 @@ def _check_ip_available(ip_addr):
This function can be used to prevent VMs being created with duplicate
IP's or to generate a warning.
'''
for vm_name, vm_details in get_resources_vms(includeConfig=True).items():
for vm_name, vm_details in six.iteritems(get_resources_vms(includeConfig=True)):
vm_config = vm_details['config']
if ip_addr in vm_config['ip_address'] or vm_config['ip_address'] == ip_addr:
log.debug('IP "{0}" is already defined'.format(ip_addr))
@ -383,7 +386,7 @@ def avail_images(call=None, location='local'):
)
ret = {}
for host_name, host_details in avail_locations().items():
for host_name, host_details in six.iteritems(avail_locations()):
for item in query('get', 'nodes/{0}/storage/{1}/content'.format(host_name, location)):
ret[item['volid']] = item
return ret
@ -405,7 +408,7 @@ def list_nodes(call=None):
)
ret = {}
for vm_name, vm_details in get_resources_vms(includeConfig=True).items():
for vm_name, vm_details in six.iteritems(get_resources_vms(includeConfig=True)):
log.debug('VM_Name: {0}'.format(vm_name))
log.debug('vm_details: {0}'.format(vm_details))
@ -760,7 +763,7 @@ def get_vmconfig(vmid, node=None, node_type='openvz'):
'''
if node is None:
# We need to figure out which node this VM is on.
for host_name, host_details in avail_locations().items():
for host_name, host_details in six.iteritems(avail_locations()):
for item in query('get', 'nodes/{0}/{1}'.format(host_name, node_type)):
if item['vmid'] == vmid:
node = host_name