1 from starcluster.logger import log
2
3 from completers import ImageCompleter
4
5
7 """
8 removeimage [options] <imageid>
9
10 Deregister an EC2 image (AMI)
11
12 WARNING: This command, by default, will *permanently* remove an AMI from
13 EC2. This includes removing any AMI files in the S3-backed case and the
14 root volume snapshot in the EBS-backed case. Be careful!
15
16 Example:
17
18 $ starcluster removeimage ami-999999
19
20 If the image is S3-backed then the image files on S3 will be removed in
21 addition to deregistering the AMI.
22
23 If the image is EBS-backed then the image's snapshot on EBS will be removed
24 in addition to deregistering the AMI.
25
26 If you'd rather keep the S3 files/EBS Snapshot backing the image use the
27 --keep-image-data:
28
29 $ starcluster removeimage -k ami-999999
30
31 For S3-backed images this will leave the AMI's files on S3 instead of
32 deleting them. For EBS-backed images this will leave the root volume
33 snapshot on EBS instead of deleting it.
34 """
35 names = ['removeimage', 'ri']
36
38 parser.add_option("-p", "--pretend", dest="pretend",
39 action="store_true", default=False,
40 help="pretend run, do not actually remove anything")
41 parser.add_option("-c", "--confirm", dest="confirm",
42 action="store_true", default=False,
43 help="do not prompt for confirmation, "
44 "just remove the image")
45 parser.add_option("-k", "--keep-image-data", dest="keep_image_data",
46 action="store_true", default=False,
47 help="only deregister the AMI, do not remove files "
48 "from S3 or delete EBS snapshot")
49
51 if not args:
52 self.parser.error("no images specified. exiting...")
53 for arg in args:
54 imageid = arg
55 self.ec2.get_image(imageid)
56 confirmed = self.opts.confirm
57 pretend = self.opts.pretend
58 keep_image_data = self.opts.keep_image_data
59 if not confirmed:
60 if not pretend:
61 resp = raw_input("**PERMANENTLY** delete %s (y/n)? " %
62 imageid)
63 if resp not in ['y', 'Y', 'yes']:
64 log.info("Aborting...")
65 return
66 self.ec2.remove_image(imageid, pretend=pretend,
67 keep_image_data=keep_image_data)
68