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