def clean_up_table()

in ansible_image_validation/cleanup-azure-table.py [0:0]


    def clean_up_table(self, args):
        """
        Fetches all the images from Azure Table Storage.
        Marks the images as deleted if the image is not present
        in Azure Marketplace
        """
        allimages = open(args.all_image_list, 'r')
        images_in_marketplace = allimages.readlines()
        
        imagequeryresult = self.table_service.query_entities(args.table_name, 
            filter="IsDeleted eq 0",
            accept='application/json;odata=minimalmetadata')
        
        print("Creating list of images")
        list_of_images_to_clean_up = []
        for image in imagequeryresult:
            disk_version = image.PartitionKey.split('-')[-1]
            
            l = [image_name for image_name in images_in_marketplace if disk_version in image_name]
            if l == None or len(l) is 0:
                list_of_images_to_clean_up.append(image)            

        print("Updating", len(list_of_images_to_clean_up))
        self.mark_deleted(list_of_images_to_clean_up, args.table_name)