Move get_instance() calls from try-except block
common.get_instance() raises a single exception HTTPNotFound only, so it is not necessary to call the method in try-except block on these cases. This patch moves these calls from the block so that we will be able to avoid digging what exceptions are raised on the method in the future (On Ie1fc20fe5e028dd53116d5549814442232ddfe49 review, we faced such situation). Change-Id: I7c3898f79dfdd069c52de9327b7f5ec45786c8d6
This commit is contained in:
@@ -44,8 +44,8 @@ class AdminActionsController(wsgi.Controller):
|
||||
"""Permit admins to reset networking on a server."""
|
||||
context = req.environ['nova.context']
|
||||
context.can(aa_policies.POLICY_ROOT % 'reset_network')
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
self.compute_api.reset_network(context, instance)
|
||||
except exception.InstanceUnknownCell as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
@@ -59,8 +59,8 @@ class AdminActionsController(wsgi.Controller):
|
||||
"""Permit admins to inject network info into a server."""
|
||||
context = req.environ['nova.context']
|
||||
context.can(aa_policies.POLICY_ROOT % 'inject_network_info')
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
self.compute_api.inject_network_info(context, instance)
|
||||
except exception.InstanceUnknownCell as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
|
||||
@@ -94,8 +94,8 @@ class MigrateServerController(wsgi.Controller):
|
||||
disk_over_commit = strutils.bool_from_string(disk_over_commit,
|
||||
strict=True)
|
||||
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
self.compute_api.live_migrate(context, instance, block_migration,
|
||||
disk_over_commit, host, force, async)
|
||||
except exception.InstanceUnknownCell as e:
|
||||
|
||||
@@ -49,8 +49,8 @@ class RemoteConsolesController(wsgi.Controller):
|
||||
# If type is not supplied or unknown, get_vnc_console below will cope
|
||||
console_type = body['os-getVNCConsole'].get('type')
|
||||
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
output = self.compute_api.get_vnc_console(context,
|
||||
instance,
|
||||
console_type)
|
||||
@@ -78,8 +78,8 @@ class RemoteConsolesController(wsgi.Controller):
|
||||
# If type is not supplied or unknown, get_spice_console below will cope
|
||||
console_type = body['os-getSPICEConsole'].get('type')
|
||||
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
output = self.compute_api.get_spice_console(context,
|
||||
instance,
|
||||
console_type)
|
||||
@@ -137,8 +137,8 @@ class RemoteConsolesController(wsgi.Controller):
|
||||
|
||||
# If type is not supplied or unknown get_serial_console below will cope
|
||||
console_type = body['os-getSerialConsole'].get('type')
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
output = self.compute_api.get_serial_console(context,
|
||||
instance,
|
||||
console_type)
|
||||
|
||||
@@ -343,9 +343,8 @@ class ServerSecurityGroupController(SecurityGroupControllerBase):
|
||||
|
||||
self.security_group_api.ensure_default(context)
|
||||
|
||||
instance = common.get_instance(self.compute_api, context, server_id)
|
||||
try:
|
||||
instance = common.get_instance(self.compute_api, context,
|
||||
server_id)
|
||||
groups = self.security_group_api.get_instance_security_groups(
|
||||
context, instance, True)
|
||||
except (exception.SecurityGroupNotFound,
|
||||
|
||||
@@ -105,8 +105,8 @@ class ServerMetadataController(wsgi.Controller):
|
||||
|
||||
def _update_instance_metadata(self, context, server_id, metadata,
|
||||
delete=False):
|
||||
server = common.get_instance(self.compute_api, context, server_id)
|
||||
try:
|
||||
server = common.get_instance(self.compute_api, context, server_id)
|
||||
return self.compute_api.update_instance_metadata(context,
|
||||
server,
|
||||
metadata,
|
||||
|
||||
@@ -35,8 +35,8 @@ class SuspendServerController(wsgi.Controller):
|
||||
def _suspend(self, req, id, body):
|
||||
"""Permit admins to suspend the server."""
|
||||
context = req.environ['nova.context']
|
||||
server = common.get_instance(self.compute_api, context, id)
|
||||
try:
|
||||
server = common.get_instance(self.compute_api, context, id)
|
||||
context.can(ss_policies.POLICY_ROOT % 'suspend',
|
||||
target={'user_id': server.user_id,
|
||||
'project_id': server.project_id})
|
||||
@@ -56,8 +56,8 @@ class SuspendServerController(wsgi.Controller):
|
||||
"""Permit admins to resume the server from suspend."""
|
||||
context = req.environ['nova.context']
|
||||
context.can(ss_policies.POLICY_ROOT % 'resume')
|
||||
server = common.get_instance(self.compute_api, context, id)
|
||||
try:
|
||||
server = common.get_instance(self.compute_api, context, id)
|
||||
self.compute_api.resume(context, server)
|
||||
except exception.InstanceUnknownCell as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
|
||||
Reference in New Issue
Block a user