diff options
author | Rob Vermaas <rob.vermaas@gmail.com> | 2015-01-05 09:34:34 +0100 |
---|---|---|
committer | Rob Vermaas <rob.vermaas@gmail.com> | 2015-01-05 09:35:48 +0100 |
commit | bc09e53343857c9e52a480e0acd95f5995d77568 (patch) | |
tree | bcd0b7a0021303eaebccd13da6c29716d53fd437 /nixos/maintainers | |
parent | 1a4164b71d6fe97664c1fa025275d9af111cfe5c (diff) |
Minor fixes to EC2 image generation script. Set autoresponder, so no interaction is necessary. Write output in a format that can be easily included in ec2-amis.nix of nixops.
(cherry picked from commit 96904915d9e3e5f69b0c5bf58db1a0f0130a977a)
Diffstat (limited to 'nixos/maintainers')
-rwxr-xr-x | nixos/maintainers/scripts/ec2/create-ebs-amis.py | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/nixos/maintainers/scripts/ec2/create-ebs-amis.py b/nixos/maintainers/scripts/ec2/create-ebs-amis.py index 8c686139fef8..44af56c4091b 100755 --- a/nixos/maintainers/scripts/ec2/create-ebs-amis.py +++ b/nixos/maintainers/scripts/ec2/create-ebs-amis.py @@ -12,7 +12,7 @@ from nixops.statefile import StateFile, get_default_state_file parser = argparse.ArgumentParser(description='Create an EBS-backed NixOS AMI') parser.add_argument('--region', dest='region', required=True, help='EC2 region to create the image in') -parser.add_argument('--channel', dest='channel', default="13.10", help='Channel to use') +parser.add_argument('--channel', dest='channel', default="14.12", help='Channel to use') parser.add_argument('--keep', dest='keep', action='store_true', help='Keep NixOps machine after use') parser.add_argument('--hvm', dest='hvm', action='store_true', help='Create HVM image') parser.add_argument('--key', dest='key_name', action='store_true', help='Keypair used for HVM instance creation', default="rob") @@ -54,7 +54,7 @@ try: except Exception: depl = db.create_deployment() depl.name = "ebs-creator" -depl.auto_response = "y" +depl.logger.set_autoresponse("y") depl.nix_exprs = [os.path.abspath("./ebs-creator.nix"), os.path.abspath("./ebs-creator-config.nix")] if not args.keep: depl.destroy_resources() depl.deploy(allow_reboot=True) @@ -140,6 +140,7 @@ common_args = dict( ) if not args.hvm: common_args['kernel_id']=aki.id + ami_id = m._conn.register_image(**common_args) print >> sys.stderr, "registered AMI {0}".format(ami_id) @@ -185,23 +186,31 @@ test_depl.deploy(create_only=True) test_depl.machines['machine'].run_command("nixos-version") # Log the AMI ID. -f = open("{0}.{1}.ami-id".format(args.region, image_type), "w") -f.write("{0}".format(ami_id)) -f.close() +f = open("ec2-amis.nix".format(args.region, image_type), "w") +f.write("{\n") for dest in [ 'us-east-1', 'us-west-1', 'us-west-2', 'eu-west-1', 'eu-central-1', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1', 'sa-east-1']: + copy_image = None if args.region != dest: - print >> sys.stderr, "copying image from region {0} to {1}".format(args.region, dest) - conn = boto.ec2.connect_to_region(dest) - copy_image = conn.copy_image(args.region, ami_id, ami_name, description=None, client_token=None) + try: + print >> sys.stderr, "copying image from region {0} to {1}".format(args.region, dest) + conn = boto.ec2.connect_to_region(dest) + copy_image = conn.copy_image(args.region, ami_id, ami_name, description=None, client_token=None) + except : + print >> sys.stderr, "FAILED!" # Log the AMI ID. - f = open("{0}.{1}.ami-id".format(dest, image_type), "w") - f.write("{0}".format(copy_image.image_id)) - f.close() + if copy_image != None: + f.write(' "{0}"."{1}".{2} = "{3}";\n'.format(args.channel,dest,"hvm" if args.hvm else "ebs",copy_image.image_id)) + else: + f.write(' "{0}"."{1}".{2} = "{3}";\n'.format(args.channel,args.region,"hvm" if args.hvm else "ebs",ami_id)) +f.write("}\n") +f.close() + if not args.keep: + test_depl.logger.set_autoresponse("y") test_depl.destroy_resources() test_depl.delete() |