diff --git a/nova/api/openstack/compute/admin_actions.py b/nova/api/openstack/compute/admin_actions.py index 94d7973687a2..de85642dba55 100644 --- a/nova/api/openstack/compute/admin_actions.py +++ b/nova/api/openstack/compute/admin_actions.py @@ -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()) diff --git a/nova/api/openstack/compute/migrate_server.py b/nova/api/openstack/compute/migrate_server.py index 89983f0b8514..4b5b81d5d837 100644 --- a/nova/api/openstack/compute/migrate_server.py +++ b/nova/api/openstack/compute/migrate_server.py @@ -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: diff --git a/nova/api/openstack/compute/remote_consoles.py b/nova/api/openstack/compute/remote_consoles.py index da30c88df04b..ff4a71775fa9 100644 --- a/nova/api/openstack/compute/remote_consoles.py +++ b/nova/api/openstack/compute/remote_consoles.py @@ -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) diff --git a/nova/api/openstack/compute/security_groups.py b/nova/api/openstack/compute/security_groups.py index 9907a50d34dd..e6fc6abd8430 100644 --- a/nova/api/openstack/compute/security_groups.py +++ b/nova/api/openstack/compute/security_groups.py @@ -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, diff --git a/nova/api/openstack/compute/server_metadata.py b/nova/api/openstack/compute/server_metadata.py index cfe6bf546861..711135ef0300 100644 --- a/nova/api/openstack/compute/server_metadata.py +++ b/nova/api/openstack/compute/server_metadata.py @@ -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, diff --git a/nova/api/openstack/compute/suspend_server.py b/nova/api/openstack/compute/suspend_server.py index fa55b2551efe..ec3546b34619 100644 --- a/nova/api/openstack/compute/suspend_server.py +++ b/nova/api/openstack/compute/suspend_server.py @@ -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())