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)
This commit is contained in:
parent
1a4164b71d
commit
bc09e53343
|
@ -12,7 +12,7 @@ from nixops.statefile import StateFile, get_default_state_file
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Create an EBS-backed NixOS AMI')
|
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('--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('--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('--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")
|
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:
|
except Exception:
|
||||||
depl = db.create_deployment()
|
depl = db.create_deployment()
|
||||||
depl.name = "ebs-creator"
|
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")]
|
depl.nix_exprs = [os.path.abspath("./ebs-creator.nix"), os.path.abspath("./ebs-creator-config.nix")]
|
||||||
if not args.keep: depl.destroy_resources()
|
if not args.keep: depl.destroy_resources()
|
||||||
depl.deploy(allow_reboot=True)
|
depl.deploy(allow_reboot=True)
|
||||||
|
@ -140,6 +140,7 @@ common_args = dict(
|
||||||
)
|
)
|
||||||
if not args.hvm:
|
if not args.hvm:
|
||||||
common_args['kernel_id']=aki.id
|
common_args['kernel_id']=aki.id
|
||||||
|
|
||||||
ami_id = m._conn.register_image(**common_args)
|
ami_id = m._conn.register_image(**common_args)
|
||||||
|
|
||||||
print >> sys.stderr, "registered AMI {0}".format(ami_id)
|
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")
|
test_depl.machines['machine'].run_command("nixos-version")
|
||||||
|
|
||||||
# Log the AMI ID.
|
# Log the AMI ID.
|
||||||
f = open("{0}.{1}.ami-id".format(args.region, image_type), "w")
|
f = open("ec2-amis.nix".format(args.region, image_type), "w")
|
||||||
f.write("{0}".format(ami_id))
|
f.write("{\n")
|
||||||
f.close()
|
|
||||||
|
|
||||||
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']:
|
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:
|
if args.region != dest:
|
||||||
print >> sys.stderr, "copying image from region {0} to {1}".format(args.region, dest)
|
try:
|
||||||
conn = boto.ec2.connect_to_region(dest)
|
print >> sys.stderr, "copying image from region {0} to {1}".format(args.region, dest)
|
||||||
copy_image = conn.copy_image(args.region, ami_id, ami_name, description=None, client_token=None)
|
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.
|
# Log the AMI ID.
|
||||||
f = open("{0}.{1}.ami-id".format(dest, image_type), "w")
|
if copy_image != None:
|
||||||
f.write("{0}".format(copy_image.image_id))
|
f.write(' "{0}"."{1}".{2} = "{3}";\n'.format(args.channel,dest,"hvm" if args.hvm else "ebs",copy_image.image_id))
|
||||||
f.close()
|
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:
|
if not args.keep:
|
||||||
|
test_depl.logger.set_autoresponse("y")
|
||||||
test_depl.destroy_resources()
|
test_depl.destroy_resources()
|
||||||
test_depl.delete()
|
test_depl.delete()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue