Create DescribeImageAttribute api method
This commit is contained in:
parent
6ad8e8f8a6
commit
64f4238740
|
@ -531,6 +531,30 @@ class CloudController(object):
|
|||
|
||||
return defer.succeed({'imageId': image_id})
|
||||
|
||||
def describe_image_attribute(self, context, image_id, attribute, **kwargs):
|
||||
if attribute != 'launchPermission':
|
||||
raise exception.ApiError('attribute not supported: %s' % attribute)
|
||||
try:
|
||||
image = images.list(context, image_id)[0]
|
||||
except IndexError:
|
||||
raise exception.ApiError('invalid id: %s' % image_id)
|
||||
result = { 'image_id': image_id, 'launchPermission': [] }
|
||||
if image['isPublic']:
|
||||
result['launchPermission'].append({ 'group': 'all' })
|
||||
|
||||
return defer.succeed(result)
|
||||
|
||||
def modify_image_attribute(self, context, image_id, attribute, operation_type, **kwargs):
|
||||
# TODO(devcamcar): Support users and groups other than 'all'.
|
||||
if attribute != 'launchPermission':
|
||||
raise exception.ApiError('attribute not supported: %s' % attribute)
|
||||
if len(kwargs['user_group']) != 1 and kwargs['user_group'][0] != 'all':
|
||||
raise exception.ApiError('only group "all" is supported')
|
||||
if not operation_type in ['add', 'remove']:
|
||||
raise exception.ApiError('operation_type must be add or remove')
|
||||
result = images.modify(context, image_id, operation_type)
|
||||
return defer.succeed(result)
|
||||
|
||||
def modify_image_attribute(self, context, image_id, attribute, operation_type, **kwargs):
|
||||
if attribute != 'launchPermission':
|
||||
raise exception.ApiError('only launchPermission is supported')
|
||||
|
|
Loading…
Reference in New Issue