def RemoveEntries()

in bulkprovision/bulkmonitor/__init__.py [0:0]


    def RemoveEntries(self, status_arr=None):
        '''
        the function will clean up entries in Dynamo. use this mainly to remove TERMINATED status entries
        '''
        if status_arr is None:
            status_arr = self._status
        count = 0
        errors = 0
        total = 0
        
        prov_items = self.dynamo_query_multi("status",status_arr)
        total=len(prov_items)
        logger.info("Found {} items to remove with status {}".format(len(prov_items), status_arr))
        failed = False
        for drow in prov_items:
            dbstatus = drow["status"] 
            guidkey = drow["guidkey"]
            try:
                key = {
                    "guidkey": guidkey,
                    "status":  dbstatus
                }  
                self.dynamo_delete_item(key)
            except ClientError as ce:
                msg = ce.response['Error']['Message']
                logger.error("ClientError: {}".format(msg))
                failed = True
            except Exception as e:
                # Something else wrong?
                logger.error(e)
                failed = True
            else:
                count += 1
            
            if failed:
                errors += 1
                    
        if total > 0:
            logger.info("Removed {} of {} entries with {} errors using status:{}".format(count, total, errors, status_arr))
        return(self.generate_return(count))