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
This commit is contained in:
jiaopengju 2017-11-23 13:41:44 +08:00
parent 4897261d8a
commit 05be900d31
2 changed files with 11 additions and 3 deletions

View File

@ -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"]

View File

@ -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"]
}