From 05be900d3127fbc2fa680e6a6e0072721fd4a6de Mon Sep 17 00:00:00 2001 From: jiaopengju Date: Thu, 23 Nov 2017 13:41:44 +0800 Subject: [PATCH] Fix server restore failed if network rebuild Currently, server restore can only use the networks in checkpoint metadata. When the network was deleted or rebuilded, the restore will fail. So this patch add a new restore parameter to specify the restore network id. Change-Id: I003c68de094b8d11bbdd7dd07bec0c1d1e580652 Closes-Bug: #1713887 --- .../protection_plugins/server/nova_protection_plugin.py | 9 ++++++--- .../protection_plugins/server/server_plugin_schemas.py | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py b/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py index 55933e26..8c388976 100644 --- a/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py +++ b/karbor/services/protection/protection_plugins/server/nova_protection_plugin.py @@ -229,10 +229,11 @@ class RestoreOperation(protection_plugin.Operation): new_resources = kwargs.get("new_resources") # restore server instance + restore_net_id = parameters.get("restore_net_id", None) new_server_id = self._restore_server_instance( nova_client, new_resources, original_server_id, parameters.get("restore_name", "karbor-restore-server"), - resource_definition) + restore_net_id, resource_definition) update_method = partial(utils.update_resource_restore_result, kwargs.get('restore'), resource.type, @@ -269,7 +270,7 @@ class RestoreOperation(protection_plugin.Operation): ) def _restore_server_instance(self, nova_client, new_resources, - original_id, restore_name, + original_id, restore_name, restore_net_id, resource_definition): server_metadata = resource_definition["server_metadata"] properties = { @@ -312,7 +313,9 @@ class RestoreOperation(protection_plugin.Operation): for security_group in server_metadata["security_groups"] ] - if server_metadata.get("networks"): + if restore_net_id is not None: + properties["nics"] = [{'net-id': restore_net_id}] + elif server_metadata.get("networks"): properties["nics"] = [ {'net-id': network} for network in server_metadata["networks"] diff --git a/karbor/services/protection/protection_plugins/server/server_plugin_schemas.py b/karbor/services/protection/protection_plugins/server/server_plugin_schemas.py index 7410f6b2..bf2b054a 100644 --- a/karbor/services/protection/protection_plugins/server/server_plugin_schemas.py +++ b/karbor/services/protection/protection_plugins/server/server_plugin_schemas.py @@ -26,6 +26,11 @@ RESTORE_SCHEMA = { "title": "Restore Server Name", "description": "The name of the restore server", }, + "restore_net_id": { + "type": "string", + "title": "Restore Server Net Id", + "description": "The net id of the restore server" + } }, "required": ["restore_name"] }