
Currently there is no way to get data onto a volume through the dashboard without taking manual steps in a guest. It's possible to create a volume from a snapshot, but there's no way to get data onto a volume to create the snapshot in the first place. Creating a volume from an image is particularly useful when booting from a volume. This was implemented in cinder and nova-volume in Folsom. Expose this to dashboard users as well. Create a new action for this on the images panel, reusing the 'Create Volume' form. Also make this possible from the volumes panel, by adding a 'source type' field to the 'Create Volume' form. This lets users choose among no source (the default), snapshot, and image, hiding the lists of snapshots and images when the corresponding source type is not selected, similar to the 'image type' field in the 'Launch Instance' workflow. Use the same infrastructure as creating from a snapshot to update the size and name based on the image size and name. Extract the image listing code out of the instance panel, into a generic utility module. Also add a size conversion function, since image sizes are reported by glance in bytes, while volumes are specified in gigabytes. Change-Id: I8314ab011734d80d5f611b338ed6e2538e6bab7e Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from horizon import exceptions
|
|
|
|
from openstack_dashboard.api import glance
|
|
|
|
|
|
def get_available_images(request, project_id=None, images_cache=None):
|
|
"""
|
|
Returns a list of images that are public or owned by the given
|
|
project_id. If project_id is not specified, only public images
|
|
are returned.
|
|
|
|
:param images_cache:
|
|
An optional dict-like object in which to
|
|
cache public and per-project id image metadata.
|
|
"""
|
|
if images_cache is None:
|
|
images_cache = {}
|
|
public_images = images_cache.get('public_images', [])
|
|
images_by_project = images_cache.get('images_by_project', {})
|
|
if 'public_images' not in images_cache:
|
|
public = {"is_public": True,
|
|
"status": "active"}
|
|
try:
|
|
images, _more = glance.image_list_detailed(
|
|
request, filters=public)
|
|
[public_images.append(image) for image in images]
|
|
images_cache['public_images'] = public_images
|
|
except:
|
|
exceptions.handle(request,
|
|
_("Unable to retrieve public images."))
|
|
|
|
# Preempt if we don't have a project_id yet.
|
|
if project_id is None:
|
|
images_by_project[project_id] = []
|
|
|
|
if project_id not in images_by_project:
|
|
owner = {"property-owner_id": project_id,
|
|
"status": "active"}
|
|
try:
|
|
owned_images, _more = glance.image_list_detailed(
|
|
request, filters=owner)
|
|
except:
|
|
exceptions.handle(request,
|
|
_("Unable to retrieve images for "
|
|
"the current project."))
|
|
images_by_project[project_id] = owned_images
|
|
if 'images_by_project' not in images_cache:
|
|
images_cache['images_by_project'] = images_by_project
|
|
|
|
owned_images = images_by_project[project_id]
|
|
images = owned_images + public_images
|
|
|
|
# Remove duplicate images
|
|
image_ids = []
|
|
final_images = []
|
|
for image in images:
|
|
if image.id not in image_ids:
|
|
image_ids.append(image.id)
|
|
final_images.append(image)
|
|
return [image for image in final_images
|
|
if image.container_format not in ('aki', 'ari')]
|