Skip to content

Commit

Permalink
Merge pull request #51013 from wanless-systems/fix_keyerror_name_proxmox
Browse files Browse the repository at this point in the history
Add multiple retries and timeout for getting vm resources in proxmox …
  • Loading branch information
dwoz authored Dec 31, 2018
2 parents 4d2a7f7 + 5c95330 commit 99966fc
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions salt/cloud/clouds/proxmox.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,42 @@ def get_resources_vms(call=None, resFilter=None, includeConfig=True):
salt-cloud -f get_resources_vms my-proxmox-config
'''
log.debug('Getting resource: vms.. (filter: %s)', resFilter)
resources = query('get', 'cluster/resources')

ret = {}
for resource in resources:
if 'type' in resource and resource['type'] in ['openvz', 'qemu', 'lxc']:
name = resource['name']
ret[name] = resource

if includeConfig:
# Requested to include the detailed configuration of a VM
ret[name]['config'] = get_vmconfig(
ret[name]['vmid'],
ret[name]['node'],
ret[name]['type']
)
timeoutTime = time.time() + 60
while True:
log.debug('Getting resource: vms.. (filter: %s)', resFilter)
resources = query('get', 'cluster/resources')
ret = {}
badResource = False
for resource in resources:
if 'type' in resource and resource['type'] in ['openvz', 'qemu',
'lxc']:
try:
name = resource['name']
except KeyError:
badResource = True
log.debug('No name in VM resource %s', repr(resource))
break

ret[name] = resource

if includeConfig:
# Requested to include the detailed configuration of a VM
ret[name]['config'] = get_vmconfig(
ret[name]['vmid'],
ret[name]['node'],
ret[name]['type']
)

if time.time() > timeoutTime:
raise SaltCloudExecutionTimeout('FAILED to get the proxmox '
'resources vms')

# Carry on if there wasn't a bad resource return from Proxmox
if not badResource:
break

time.sleep(0.5)

if resFilter is not None:
log.debug('Filter given: %s, returning requested '
Expand Down

0 comments on commit 99966fc

Please sign in to comment.