3
0
Fork 0
forked from mirrors/nixpkgs

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 96904915d9)
This commit is contained in:
Rob Vermaas 2015-01-05 09:34:34 +01:00
parent 1a4164b71d
commit bc09e53343

View file

@ -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()