# simple wrapper to access vultr api defvultr(method="GET", action="", data=None): api_endpoint = "https://api.vultr.com/v1/" return requests.request(method, "{}{}".format(api_endpoint, action), headers={"API-Key": API_KEY}, data=data)
# Get base info day = time.strftime("%Y-%m-%d", time.localtime())
# get snapshot list snapshot_list_raw = vultr("GET", "snapshot/list").json() snapshot_list = [v for k, v in snapshot_list_raw.items()] iflen(snapshot_list_raw) > 0else {}
# Get auto-backup snapshot list for SUBID in SUBID_LIST: backup_snapshot_list = list(filter(lambda x: re.search("{}-{}".format(BACKUP_TAG_PREFIX, SUBID), x["description"]), snapshot_list))
for s in to_remove_snapshot_list: vultr("POST", "snapshot/destroy", {"SNAPSHOTID": s["SNAPSHOTID"]}) # create new auto-backup-snapshot vultr("POST", "snapshot/create", {"SUBID": SUBID, "description": "{}-{}-{}".format(BACKUP_TAG_PREFIX, SUBID, day)})