# Buggy code
def get_resources_vms(call=None, resFilter=None, includeConfig=True):
    """
    Retrieve all VMs available on this environment

    CLI Example:

    .. code-block:: bash

        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"]
                )

    if resFilter is not None:
        log.debug("Filter given: %s, returning requested resource: nodes", resFilter)
        return ret[resFilter]

    log.debug("Filter not given: %s, returning all resource: nodes", ret)
    return ret


# Traceback (KeyError)
18:11:40 [ERROR   ] Failed to create VM ams-nightly.eloquant.build. Configuration value u'name' needs to be set
18:11:40 Traceback (most recent call last):
18:11:40   File "/usr/lib/python2.7/dist-packages/salt/cloud/__init__.py", line 1284, in create
18:11:40     output = self.clouds[func](vm_)
18:11:40   File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/proxmox.py", line 579, in create
18:11:40     if not start(name, vmid, call='action'):
18:11:40   File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/proxmox.py", line 991, in start
18:11:40     if not set_vm_status('start', name, vmid=vmid):
18:11:40   File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/proxmox.py", line 924, in set_vm_status
18:11:40     vmobj = _get_vm_by_id(vmid)
18:11:40   File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/proxmox.py", line 210, in _get_vm_by_id
18:11:40     for vm_name, vm_details in six.iteritems(get_resources_vms(includeConfig=allDetails)):
18:11:40   File "/usr/lib/python2.7/dist-packages/salt/cloud/clouds/proxmox.py", line 329, in get_resources_vms
18:11:40     name = resource['name']
18:11:40 KeyError: u'name'

# Fixed code
def get_resources_vms(call=None, resFilter=None, includeConfig=True):
    """
    Retrieve all VMs available on this environment

    CLI Example:

    .. code-block:: bash

        salt-cloud -f get_resources_vms my-proxmox-config
    """
    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 resource: nodes", resFilter)
        return ret[resFilter]

    log.debug("Filter not given: %s, returning all resource: nodes", ret)
    return ret