diff options
author | Daniil Baturin <daniil@baturin.org> | 2020-12-30 02:22:32 +0700 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2020-12-30 02:36:46 +0700 |
commit | c846984fd748aaa75ecd0cb9f34737034aa35e55 (patch) | |
tree | acb1fcf5557c711c1f2a547b39e84b37a5ea15bc /scripts | |
parent | 2b96666a1127e5a7a3670d1fe67536e47f7628b5 (diff) | |
download | community.vyos.net-c846984fd748aaa75ecd0cb9f34737034aa35e55.tar.gz community.vyos.net-c846984fd748aaa75ecd0cb9f34737034aa35e55.zip |
Add a script for retrieving a list of rolling release snapshosts from S3.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/list-snapshots.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/list-snapshots.py b/scripts/list-snapshots.py new file mode 100755 index 0000000..b98ab37 --- /dev/null +++ b/scripts/list-snapshots.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 + +# Requires the following environment variables: +# SNAPSHOTS_BUCKET +# AWS_ACCESS_KEY_ID +# AWS_SECRET_ACCESS_KEY + +import os +import re +import json + +import boto3 + +bucket = os.getenv("SNAPSHOTS_BUCKET") + +def make_link(s, f): + f = re.sub(r'\s+', '+', f) + return "https://s3.amazonaws.com/{0}/snapshot/{1}/{2}".format(bucket, s, f) + +s3 = boto3.client('s3') +object_listing = s3.list_objects_v2(Bucket=bucket, Prefix='snapshot') +data = object_listing['Contents'] + +files = [] +for f in data: + files.append(f['Key']) + +snapshot_names = set(map(lambda s: re.sub(r'snapshot/(.*?)/.*', r'\1', s), files)) + +snapshots = [] + + +for name in snapshot_names: + snapshot = {} + snapshot['name'] = name + snapshot['files'] = list(filter(lambda s: re.search(name, s), files)) + + snapshot_files = list(filter(lambda s: re.search(name, s), files)) + snapshot_files = list(map(lambda f: {'name': os.path.basename(f), 'platform': os.path.basename(os.path.dirname(f)), 'link': make_link(name, f)}, snapshot_files)) + + snapshot['files'] = snapshot_files + + snapshots.append(snapshot) + +print(json.dumps(snapshots, indent=4)) |