# Buggy code
def queue_instances(instances):
    """
    Queue a set of instances to be provisioned later. Expects a list.

    Currently this only queries node data, and then places it in the cloud
    cache (if configured). If the salt-cloud-reactor is being used, these
    instances will be automatically provisioned using that.

    For more information about the salt-cloud-reactor, see:

    https://github.com/saltstack-formulas/salt-cloud-reactor
    """
    for instance_id in instances:
        node = _get_node(instance_id=instance_id)
        salt.utils.cloud.cache_node(node, __active_provider_name__, __opts__)


# Traceback (KeyError)
# salt-call --local cloud.has_instance jmoney-git-ec2-amazon-6
[INFO    ] Starting new HTTPS connection (1): api.digitalocean.com
[INFO    ] Starting new HTTPS connection (1): ec2.us-east-1.amazonaws.com
[INFO    ] Starting new HTTPS connection (1): identity.api.rackspacecloud.com
[INFO    ] Starting new HTTPS connection (1): ec2.us-east-1.amazonaws.com
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
KeyError: 'name'
Traceback (most recent call last):
File "/usr/local/bin/salt-call", line 6, in <module>
exec(compile(open(__file__).read(), __file__, 'exec'))
File "/root/salt/scripts/salt-call", line 11, in <module>
salt_call()
File "/root/salt/salt/scripts.py", line 341, in salt_call
client.run()
File "/root/salt/salt/cli/call.py", line 53, in run
caller.run()
File "/root/salt/salt/cli/caller.py", line 133, in run
ret = self.call()
File "/root/salt/salt/cli/caller.py", line 196, in call
ret['return'] = func(*args, **kwargs)
File "/root/salt/salt/modules/cloud.py", line 149, in has_instance
data = get_instance(name, provider)
File "/root/salt/salt/modules/cloud.py", line 175, in get_instance
data = action(fun='show_instance', names=[name], provider=provider)
File "/root/salt/salt/modules/cloud.py", line 234, in action
info = client.action(fun, cloudmap, names, provider, instance, kwargs)
File "/root/salt/salt/cloud/__init__.py", line 482, in action
return mapper.do_action(names, kwargs)
File "/root/salt/salt/cloud/__init__.py", line 1511, in do_action
vm_name, call='action'
File "/root/salt/salt/cloud/clouds/ec2.py", line 3171, in show_instance
salt.utils.cloud.cache_node(node, __active_provider_name__, __opts__)
File "/root/salt/salt/utils/cloud.py", line 2821, in cache_node
path = os.path.join(prov_dir, '{0}.p'.format(node['name']))
KeyError: 'name'

# Fixed code
def queue_instances(instances):
    """
    Queue a set of instances to be provisioned later. Expects a list.

    Currently this only queries node data, and then places it in the cloud
    cache (if configured). If the salt-cloud-reactor is being used, these
    instances will be automatically provisioned using that.

    For more information about the salt-cloud-reactor, see:

    https://github.com/saltstack-formulas/salt-cloud-reactor
    """
    for instance_id in instances:
        node = _get_node(instance_id=instance_id)
        for name in node:
            if instance_id == node[name]["instanceId"]:
                salt.utils.cloud.cache_node(
                    node[name], __active_provider_name__, __opts__
                )