in ansible_image_validation/azure-table-data.py [0:0]
def select_images_to_validate(self, args):
"""
This function iterates over all the entries in the Azure Table Storage
and selects at max 'args.max_vm_to_validate' images which should get validated
during this run.
"""
max_vms_to_validate_at_a_time = int(args.max_vm_to_validate )
validation_period = int(args.validation_period)
allimages = open(args.all_image_list, 'r')
Lines = allimages.readlines()
imagequeryresult = self.table_service.query_entities(args.table_name,
filter="IsDeleted eq '0'",
accept='application/json;odata=minimalmetadata')
entries = []
list_of_images_to_validate = []
current_date_time = datetime.datetime.now(datetime.timezone.utc)
for image in imagequeryresult:
entries.append(image)
for line in Lines:
publisher = line.split(':')[0]
offer = line.split(':')[1]
sku = line.split(':')[2]
disk_version = line.split(':')[3].replace('\n', '')
image_name = offer.replace("_", "-") + "-" + sku.replace("_", "-") + "-" + disk_version
image_entry_exists = False
for image in entries:
# if the image entry exists and it was last validated 2 days ago,
# add it to the list to be validated
if image.PartitionKey == image_name:
image_entry_exists = True
if image.ValidationResult == 'NA' or (current_date_time - image.Timestamp).days > validation_period:
list_of_images_to_validate.append(line)
break
if not image_entry_exists:
list_of_images_to_validate.append(line)
## insert the entry as well
args.image_name = image_name
args.validation_result = 'NA'
self.insert_data(args)
i = 0
with open(args.filtered_image_list, 'w') as filteredimagefile:
filteredimagefile.write("")
for image in list_of_images_to_validate:
if i == max_vms_to_validate_at_a_time:
break
filteredimagefile.write("%s" % image)
i += 1