def image_json(self): image_id = self.request.matchdict.get('id') with boto_error_handler(self.request): image = self.conn.get_image(image_id) if image is None: return JSONResponse(status=400, message="image id not valid") platform = ImageView.get_platform(image) bdm_dict = {} bdm_object = image.block_device_mapping for key, device in bdm_object.items(): bdm_dict[key] = dict( is_root=True if panels.get_root_device_name(image) == key else False, volume_type=device.volume_type, virtual_name=device.ephemeral_name, snapshot_id=device.snapshot_id, size=device.size, delete_on_termination=device.delete_on_termination, ) return dict(results=(dict( architecture=image.architecture, description=image.description, id=image.id, name=image.name, location=image.location, block_device_mapping=bdm_dict, tagged_name=TaggedItemView.get_display_name(image, escapebraces=False), owner_alias=image.owner_alias, platform_name=ImageView.get_platform_name(platform), platform_key=ImageView.get_platform_key(platform), # Used in image picker widget root_device_type=image.root_device_type, root_device_name=image.root_device_name, )))
def images_deregister(self): image_id_param = self.request.params.get('image_id') image_ids = [image_id.strip() for image_id in image_id_param.split(',')] delete_snapshot_param = self.request.params.get('delete_snapshot') == 'y' snapshots_deleted = [] if self.deregister_form.validate(): with boto_error_handler(self.request): images = self.conn.get_all_images(image_ids=image_ids, owners='self') for image in images: delete_snapshot = False root_dev = None if image.root_device_type == 'ebs' and delete_snapshot_param: snapshot_id = ImageView.get_image_snapshot_id(image) registered_images = self.get_images_registered(snapshot_id) if len(registered_images) == 1: delete_snapshot = True root_dev = panels.get_root_device_name(image) self.conn.deregister_image(image.id, delete_snapshot=delete_snapshot) if delete_snapshot: for key in image.block_device_mapping: if root_dev and key == root_dev: self.conn.delete_snapshot(snapshot_id) snapshots_deleted.append(snapshot_id) break self.invalidate_images_cache() # clear images cache location = self.request.route_path('images') prefix = _(u'Successfully sent request to deregister image') msg = '{0} {1}'.format(prefix, ', '.join(image_ids)) if snapshots_deleted: snapshots_prefix = _(u'The following snapshots were deleted:') msg += '. {0} {1}'.format(snapshots_prefix, ', '.join(snapshots_deleted)) self.request.session.flash(msg, queue=Notification.SUCCESS) return HTTPFound(location=location) return self.render_dict
def image_json(self): image_id = self.request.matchdict.get('id') with boto_error_handler(self.request): image = self.conn.get_image(image_id) if image is None: return JSONResponse(status=400, message="image id not valid") platform = ImageView.get_platform(image) bdm_dict = {} bdm_object = image.block_device_mapping for key, device in bdm_object.items(): bdm_dict[key] = dict( is_root=True if panels.get_root_device_name(image) == key else False, volume_type=device.volume_type, virtual_name=device.ephemeral_name, snapshot_id=device.snapshot_id, size=device.size, delete_on_termination=device.delete_on_termination, ) return dict(results=(dict( architecture=image.architecture, description=image.description, id=image.id, name=image.name, location=image.location, block_device_mapping=bdm_dict, tagged_name=TaggedItemView.get_display_name(image, escapebraces=False), owner_alias=image.owner_alias, platform_name=ImageView.get_platform_name(platform), platform_key=ImageView.get_platform_key(platform), # Used in image picker widget root_device_type=image.root_device_type, root_device_name=image.root_device_name, )))
def images_deregister(self): image_id_param = self.request.params.get('image_id') image_ids = [image_id.strip() for image_id in image_id_param.split(',')] delete_snapshot_param = self.request.params.get('delete_snapshot') == 'y' snapshots_deleted = [] if self.deregister_form.validate(): with boto_error_handler(self.request): images = self.conn.get_all_images(image_ids=image_ids, owners='self') for image in images: delete_snapshot = False root_dev = None if image.root_device_type == 'ebs' and delete_snapshot_param: snapshot_id = ImageView.get_image_snapshot_id(image) registered_images = self.get_images_registered(snapshot_id) if len(registered_images) == 1: delete_snapshot = True root_dev = panels.get_root_device_name(image) self.conn.deregister_image(image.id, delete_snapshot=delete_snapshot) if delete_snapshot: for key in image.block_device_mapping: if root_dev and key == root_dev: self.conn.delete_snapshot(snapshot_id) snapshots_deleted.append(snapshot_id) break self.invalidate_images_cache() # clear images cache location = self.request.route_path('images') prefix = _(u'Successfully sent request to deregister image') msg = '{0} {1}'.format(prefix, ', '.join(image_ids)) if snapshots_deleted: snapshots_prefix = _(u'The following snapshots were deleted:') msg += '. {0} {1}'.format(snapshots_prefix, ', '.join(snapshots_deleted)) self.request.session.flash(msg, queue=Notification.SUCCESS) return HTTPFound(location=location) return self.render_dict
def get_images_registered(self, snap_id): ret = [] images = self.conn.get_all_images(owners='self') for img in images: if img.block_device_mapping is not None: vol = img.block_device_mapping.get(panels.get_root_device_name(img), None) if vol is not None and snap_id == vol.snapshot_id: ret.append(img) return ret or None
def get_images_registered(self, snap_id): ret = [] images = self.conn.get_all_images(owners='self') for img in images: if img.block_device_mapping is not None: vol = img.block_device_mapping.get(panels.get_root_device_name(img), None) if vol is not None and snap_id == vol.snapshot_id: ret.append(img) return ret or None
def image_deregister(self): if self.deregister_form.validate(): with boto_error_handler(self.request): delete_snapshot = False root_dev = None if self.image.root_device_type == 'ebs' and self.request.params.get('delete_snapshot') == 'y': delete_snapshot = True root_dev = panels.get_root_device_name(self.image) self.conn.deregister_image(self.image.id, delete_snapshot=delete_snapshot) if delete_snapshot: for key in self.image.block_device_mapping: if root_dev and key == root_dev: snapshot_id = self.image.block_device_mapping[key].snapshot_id self.conn.delete_snapshot(snapshot_id) break self.invalidate_images_cache() # clear images cache location = self.request.route_path('images') msg = _(u'Successfully sent request to deregistered image.') self.request.session.flash(msg, queue=Notification.SUCCESS) return HTTPFound(location=location) return self.render_dict
def image_deregister(self): if self.deregister_form.validate(): with boto_error_handler(self.request): delete_snapshot = False root_dev = None if self.image.root_device_type == 'ebs' and self.request.params.get('delete_snapshot') == 'y': delete_snapshot = True root_dev = panels.get_root_device_name(self.image) self.conn.deregister_image(self.image.id, delete_snapshot=delete_snapshot) if delete_snapshot: for key in self.image.block_device_mapping: if root_dev and key == root_dev: snapshot_id = self.image.block_device_mapping[key].snapshot_id self.conn.delete_snapshot(snapshot_id) break self.invalidate_images_cache() # clear images cache location = self.request.route_path('images') msg = _(u'Successfully sent request to deregistered image.') self.request.session.flash(msg, queue=Notification.SUCCESS) return HTTPFound(location=location) return self.render_dict