'Use the ec2 http service to introspect the instance. This adds latency if not running on EC2'

@staticmethod
def get_metadata(agentConfig):

    if (not agentConfig['collect_instance_metadata']):
        log.info('Instance    metadata    collection    is    disabled.    Not    collecting    it.')
        return {}
    for k in ('instance-id', 'hostname', 'local-hostname', 'public-hostname', 'ami-id', 'local-ipv4', 'public-keys/', 'public-ipv4', 'reservation-id', 'security-groups'):
        try:
            url = ((EC2.METADATA_URL_BASE + '/') + unicode(k))
            r = requests.get(url, timeout=EC2.TIMEOUT)
            r.raise_for_status()
            v = r.content.strip()
            assert ((type(v) in (types.StringType, types.UnicodeType)) and (len(v) > 0)), ('%s    is    not    a    string' % v)
            EC2.metadata[k.rstrip('/')] = v
        except Exception as e:
            log.debug('Collecting    EC2    Metadata    failed    %s', str(e))
            pass
    return EC2.metadata.copy()
