'Make calls to Collins and saves the output in a cache'

def update_cache(self):

    self.cache = dict()
    self.inventory = dict()
    try:
        server_assets = self.find_assets()
    except:
        self.log.error(('Error    while    locating    assets    from    Collins:\n%s' % traceback.format_exc()))
        return False
    for asset in server_assets:
        if self._asset_has_attribute(asset, 'ANSIBLE_IP_INDEX'):
            ip_index = self._asset_get_attribute(asset, 'ANSIBLE_IP_INDEX')
            try:
                ip_index = int(ip_index)
            except:
                self.log.error('ANSIBLE_IP_INDEX    attribute    on    asset    %s    not    an    integer:    %s', asset, ip_index)
        else:
            ip_index = self.ip_address_index
        asset['COLLINS'] = {}
        if (self.prefer_hostnames and self._asset_has_attribute(asset, 'HOSTNAME')):
            asset_identifier = self._asset_get_attribute(asset, 'HOSTNAME')
        elif ('ADDRESSES' not in asset):
            self.log.warning(("No    IP    addresses    found    for    asset    '%s',    skipping" % asset))
            continue
        elif (len(asset['ADDRESSES']) < (ip_index + 1)):
            self.log.warning("No    IP    address    found    at    index    %s    for    asset    '%s',    skipping", ip_index, asset)
            continue
        else:
            asset_identifier = asset['ADDRESSES'][ip_index]['ADDRESS']
        if (('STATE' in asset['ASSET']) and asset['ASSET']['STATE']):
            state_inventory_key = self.to_safe(('STATE-%s' % asset['ASSET']['STATE']['NAME']))
            self.push(self.inventory, state_inventory_key, asset_identifier)
        if ('ATTRIBS' in asset):
            for attrib_block in asset['ATTRIBS'].keys():
                for attrib in asset['ATTRIBS'][attrib_block].keys():
                    asset['COLLINS'][attrib] = asset['ATTRIBS'][attrib_block][attrib]
                    attrib_key = self.to_safe(('%s-%s' % (attrib, asset['ATTRIBS'][attrib_block][attrib])))
                    self.push(self.inventory, attrib_key, asset_identifier)
        for attribute in asset['ASSET'].keys():
            if (attribute not in CollinsDefaults.SPECIAL_ATTRIBUTES):
                attribute_val = asset['ASSET'][attribute]
                if (attribute_val is not None):
                    attrib_key = self.to_safe(('%s-%s' % (attribute, attribute_val)))
                    self.push(self.inventory, attrib_key, asset_identifier)
        if ('HARDWARE' in asset):
            if ('PRODUCT' in asset['HARDWARE']['BASE']):
                product = asset['HARDWARE']['BASE']['PRODUCT']
                if product:
                    product_key = self.to_safe(('HARDWARE-PRODUCT-%s' % asset['HARDWARE']['BASE']['PRODUCT']))
                    self.push(self.inventory, product_key, asset_identifier)
        self.cache[asset_identifier] = asset
    try:
        self.write_to_cache(self.cache, self.cache_path_cache)
        self.write_to_cache(self.inventory, self.cache_path_inventory)
    except:
        self.log.error('Error    while    writing    to    cache:\n%s', traceback.format_exc())
        return False
    return True
