Remove duplication on stack resource operations
Move resource existence and availability check to a single place to avoid duplication. This is prep work for the blueprint detailed-resource-show. Change-Id: Ie923516d11307fc5efdbfbe728fb842137915b28
This commit is contained in:
parent
4f095c5688
commit
201d208361
@ -1072,6 +1072,15 @@ class EngineService(service.Service):
|
|||||||
access_key = ec2_creds.get('access')
|
access_key = ec2_creds.get('access')
|
||||||
return stack.access_allowed(access_key, resource_name)
|
return stack.access_allowed(access_key, resource_name)
|
||||||
|
|
||||||
|
def _verify_stack_resource(self, stack, resource_name):
|
||||||
|
if resource_name not in stack:
|
||||||
|
raise exception.ResourceNotFound(resource_name=resource_name,
|
||||||
|
stack_name=stack.name)
|
||||||
|
|
||||||
|
resource = stack[resource_name]
|
||||||
|
if resource.id is None:
|
||||||
|
raise exception.ResourceNotAvailable(resource_name=resource_name)
|
||||||
|
|
||||||
@request_context
|
@request_context
|
||||||
def describe_stack_resource(self, cnxt, stack_identity, resource_name):
|
def describe_stack_resource(self, cnxt, stack_identity, resource_name):
|
||||||
s = self._get_stack(cnxt, stack_identity)
|
s = self._get_stack(cnxt, stack_identity)
|
||||||
@ -1082,13 +1091,7 @@ class EngineService(service.Service):
|
|||||||
LOG.warn(_LW("Access denied to resource %s"), resource_name)
|
LOG.warn(_LW("Access denied to resource %s"), resource_name)
|
||||||
raise exception.Forbidden()
|
raise exception.Forbidden()
|
||||||
|
|
||||||
if resource_name not in stack:
|
self._verify_stack_resource(stack, resource_name)
|
||||||
raise exception.ResourceNotFound(resource_name=resource_name,
|
|
||||||
stack_name=stack.name)
|
|
||||||
|
|
||||||
resource = stack[resource_name]
|
|
||||||
if resource.id is None:
|
|
||||||
raise exception.ResourceNotAvailable(resource_name=resource_name)
|
|
||||||
|
|
||||||
return api.format_stack_resource(stack[resource_name])
|
return api.format_stack_resource(stack[resource_name])
|
||||||
|
|
||||||
@ -1101,14 +1104,7 @@ class EngineService(service.Service):
|
|||||||
# signal doesn't have permission to read the secret key of
|
# signal doesn't have permission to read the secret key of
|
||||||
# the user associated with the cfn-credentials file
|
# the user associated with the cfn-credentials file
|
||||||
stack = parser.Stack.load(cnxt, stack=s, use_stored_context=True)
|
stack = parser.Stack.load(cnxt, stack=s, use_stored_context=True)
|
||||||
|
self._verify_stack_resource(stack, resource_name)
|
||||||
if resource_name not in stack:
|
|
||||||
raise exception.ResourceNotFound(resource_name=resource_name,
|
|
||||||
stack_name=stack.name)
|
|
||||||
|
|
||||||
resource = stack[resource_name]
|
|
||||||
if resource.id is None:
|
|
||||||
raise exception.ResourceNotAvailable(resource_name=resource_name)
|
|
||||||
|
|
||||||
if callable(stack[resource_name].signal):
|
if callable(stack[resource_name].signal):
|
||||||
stack[resource_name].signal(details)
|
stack[resource_name].signal(details)
|
||||||
@ -1121,7 +1117,7 @@ class EngineService(service.Service):
|
|||||||
if res.name != resource_name and res.id is not None:
|
if res.name != resource_name and res.id is not None:
|
||||||
res.metadata_update()
|
res.metadata_update()
|
||||||
|
|
||||||
return resource.metadata_get()
|
return stack[resource_name].metadata_get()
|
||||||
|
|
||||||
@request_context
|
@request_context
|
||||||
def find_physical_resource(self, cnxt, physical_resource_id):
|
def find_physical_resource(self, cnxt, physical_resource_id):
|
||||||
|
Loading…
Reference in New Issue
Block a user