Adding image_create, image_delete, image_show to openstack glance

This commit is contained in:
Joseph Hall 2012-11-10 15:05:54 -07:00
parent f53a760e6d
commit 37fc5a8b84

View File

@ -14,6 +14,7 @@ keystone.auth_url: 'http://127.0.0.1:5000/v2.0/'
has_glance = False
try:
from glanceclient import client
import glanceclient.v1.images
has_glance = True
except ImportError:
pass
@ -45,9 +46,96 @@ def _auth():
return nt
def image_list():
def image_create(**kwargs):
'''
Return a list of available images (nova images-list)
Create an image (nova image-create)
CLI Example::
salt '*' nova.image_create name=f16-jeos is_public=true \
disk_format=qcow2 container_format=ovf \
copy_from=http://berrange.fedorapeople.org/images/2012-02-29/f16-x86_64-openstack-sda.qcow2
For all possible values, run::
glance help image-create
'''
nt = _auth()
ret = {}
CREATE_PARAMS = glanceclient.v1.images.CREATE_PARAMS
fields = dict(filter(lambda x: x[0] in CREATE_PARAMS, kwargs.items()))
image = nt.images.create(**fields)
newimage = image_list(str(image.id))
return {newimage['name']: newimage}
def image_delete(id=None, name=None):
'''
Delete an image (nova image-delete)
CLI Examples::
salt '*' nova.image_delete c2eb2eb0-53e1-4a80-b990-8ec887eae7df
salt '*' nova.image_delete id=c2eb2eb0-53e1-4a80-b990-8ec887eae7df
salt '*' nova.image_delete name=f16-jeos
'''
nt = _auth()
if name:
for image in nt.images.list():
if image.name == name:
id = image.id
continue
if not id:
return {'Error': 'Unable to resolve image id'}
nt.images.delete(id)
ret = 'Deleted image with ID {0}'.format(id)
if name:
ret += ' ({0})'.format(name)
return ret
def image_show(id=None, name=None):
'''
Return details about a specific image (nova image-show)
CLI Example::
salt '*' nova.image_get
'''
nt = _auth()
ret = {}
if name:
for image in nt.images.list():
if image.name == name:
id = image.id
continue
if not id:
return {'Error': 'Unable to resolve image id'}
image = nt.images.get(id)
ret[image.name] = {
'id': image.id,
'name': image.name,
'checksum': image.checksum,
'container_format': image.container_format,
'created_at': image.created_at,
'deleted': image.deleted,
'disk_format': image.disk_format,
'is_public': image.is_public,
'min_disk': image.min_disk,
'min_ram': image.min_ram,
'owner': image.owner,
'protected': image.protected,
'size': image.size,
'status': image.status,
'updated_at': image.updated_at,
}
return ret
def image_list(id=None):
'''
Return a list of available images (nova image-list)
CLI Example::
@ -73,6 +161,8 @@ def image_list():
'status': image.status,
'updated_at': image.updated_at,
}
if id == image.id:
return ret[image.name]
return ret
@ -99,11 +189,7 @@ def _item_list():
The following is a list of functions that need to be incorporated in the
nova module. This list should be updated as functions are added.
image-create Create a new image.
image-delete Delete a specific image.
image-download Download a specific image.
image-list List images you can access.
image-show Describe a specific image.
image-update Update a specific image.
member-create Share a specific image with a tenant.
member-delete Remove a shared image from a tenant.