def __ami_delete(self, region, selector): """Implements the deletion function of the ami command """ if not selector.has_selection(): return ec2_conn = self.get_ec2_conn(region) if selector.is_explicit(): ami_id_list = selector.resource_id_list else: ami_list = ec2_conn.get_all_images( owners=['self'], filters=selector.get_filter_dict()) ami_id_list = [ami.id for ami in ami_list] if not confirm_aggr("Will delete:", ami_id_list): return for ami_id in ami_id_list: ec2_conn.deregister_image(ami_id) self.cache_remove(region, [ami_id])
def __vol_delete_cmd(self, region, selector): """Implements the volume deletion functionality """ if not selector.has_selection(): return ec2_conn = self.get_ec2_conn(region) if selector.is_explicit(): vol_id_list = selector.resource_id_list else: volume_list = ec2_conn.get_all_volumes( volume_ids=selector.resource_id_list, filters=selector.get_filter_dict()) matching_volumes = selector.filter_resources(volume_list) vol_id_list = [vol.id for vol in matching_volumes] if not vol_id_list: return if not confirm_aggr("Will delete:", vol_id_list): return for vol_id in vol_id_list: ec2_conn.delete_volume(vol_id) self.cache_remove(region, [vol_id])
def __vol_detach_cmd(self, region, instance_id, selector): """Implements the volume detach functionality """ vol_id_list = [] arg_list = selector.resource_id_list for arg in arg_list: if arg.startswith("i-"): instance_id = arg elif arg.startswith("vol-"): vol_id_list.append(arg) ec2_conn = self.get_ec2_conn(region) if not vol_id_list: volume_list = ec2_conn.get_all_volumes( filters=selector.get_filter_dict()) matching_volumes = selector.filter_resources(volume_list) vol_id_list = [vol.id for vol in matching_volumes] if not vol_id_list: return if not confirm_aggr("Will detach:", vol_id_list): return for vol_id in vol_id_list: ec2_conn.detach_volume(vol_id, instance_id=instance_id)
def __snap_delete(self, region, selector): """Implements the snapshot deletion functionality """ if not selector.has_selection(): return ec2_conn = self.get_ec2_conn(region) if selector.is_explicit(): snapshot_id_list = selector.resource_id_list else: snapshot_list = ec2_conn.get_all_snapshots(owner='self', filters=selector.get_filter_dict()) matching_snapshots = selector.filter_resources(snapshot_list) snapshot_id_list = [snapshot.id for snapshot in matching_snapshots] if not snapshot_id_list: return if not confirm_aggr("Will delete:", snapshot_id_list): return for snapshot_id in snapshot_id_list: if selector.match_pattern: print "Deleting snapshot: %s" % (snapshot_id,) ec2_conn.delete_snapshot(snapshot_id) self.cache_remove(region, [snapshot_id])