]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[cloud] Add ability to generate Dokuwiki table of AMI images
authorMichael Brown <mcb30@ipxe.org>
Sat, 1 May 2021 20:33:38 +0000 (21:33 +0100)
committerMichael Brown <mcb30@ipxe.org>
Sat, 1 May 2021 20:36:19 +0000 (21:36 +0100)
Add an option to generate the amilist.txt list of current AMI images
as included in the EC2 documentation at https://ipxe.org/howto/ec2

Signed-off-by: Michael Brown <mcb30@ipxe.org>
contrib/cloud/aws-import

index 9ee53e7041a88cc8aa59efc6258be5a91a991323..a93a00843bfd6537ac7f2d6736e070a177cc174e 100755 (executable)
@@ -65,6 +65,12 @@ def import_image(region, name, architecture, image, public):
     return image_id
 
 
+def launch_link(region, image_id):
+    """Construct a web console launch link"""
+    return ("https://console.aws.amazon.com/ec2/v2/home?"
+            "region=%s#LaunchInstanceWizard:ami=%s" % (region, image_id))
+
+
 # Parse command-line arguments
 parser = argparse.ArgumentParser(description="Import AWS EC2 image (AMI)")
 parser.add_argument('--architecture', '-a', default='x86_64',
@@ -75,6 +81,8 @@ parser.add_argument('--public', '-p', action='store_true',
                     help="Make image public")
 parser.add_argument('--region', '-r', action='append',
                     help="AWS region(s)")
+parser.add_argument('--wiki', '-w', metavar='FILE',
+                    help="Generate Dokuwiki table")
 parser.add_argument('image', help="iPXE disk image")
 args = parser.parse_args()
 
@@ -95,6 +103,18 @@ with ThreadPoolExecutor(max_workers=len(args.region)) as executor:
     results = {futures[future]: future.result()
                for future in as_completed(futures)}
 
+# Construct Dokuwiki table
+wikitab = ["^ AWS region  ^ CPU architecture  ^ AMI ID  ^\n"] + list(
+    "| ''%s''  | ''%s''  | ''[[%s|%s]]''  |\n" % (
+        region,
+        args.architecture,
+        launch_link(region, results[region]),
+        results[region],
+    ) for region in args.region)
+if args.wiki:
+    with open(args.wiki, 'wt') as fh:
+        fh.writelines(wikitab)
+
 # Show created images
 for region in args.region:
     print("%s: %s" % (region, results[region]))