diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/clients/kubernetes_client.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/clients/kubernetes_client.py index a2b556e2..ea54cff8 100644 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/clients/kubernetes_client.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/clients/kubernetes_client.py @@ -108,3 +108,17 @@ def untaint_node(node_name, effect, key): response = kube_client.patch_node(node_name, body) return Result(response) + + +def delete_node(node_name): + """ + Delete a node + """ + # Get the client. + kube_client = get_client() + + # Delete the node + body = kubernetes.client.V1DeleteOptions() + response = kube_client.delete_node(node_name, body) + + return Result(response) diff --git a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py index c3bca7b4..a9b9b72f 100755 --- a/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py +++ b/nfv/nfv-plugins/nfv_plugins/nfvi_plugins/nfvi_infrastructure_api.py @@ -1078,6 +1078,19 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): if httplib.NOT_FOUND != e.http_status_code: raise + if self._host_supports_kubernetes(host_personality): + response['reason'] = 'failed to delete kubernetes services' + + # Send the delete request to kubernetes. + future.work(kubernetes_client.delete_node, host_name) + future.result = (yield) + + if not future.result.is_complete(): + DLOG.error("Kubernetes delete_node failed, operation " + "did not complete, host_uuid=%s, host_name=%s." + % (host_uuid, host_name)) + return + response['completed'] = True response['reason'] = '' @@ -1148,6 +1161,21 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): self._platform_token = future.result.data + if self._host_supports_kubernetes(host_personality): + response['reason'] = 'failed to enable kubernetes services' + + # To enable kubernetes we remove the NoExecute taint from the + # node. This allows new pods to be scheduled on the node. + future.work(kubernetes_client.untaint_node, + host_name, "NoExecute", "services") + future.result = (yield) + + if not future.result.is_complete(): + DLOG.error("Kubernetes untaint_node failed, operation " + "did not complete, host_uuid=%s, host_name=%s." + % (host_uuid, host_name)) + return + if self._host_supports_neutron(host_personality): response['reason'] = 'failed to get neutron extensions' @@ -1223,21 +1251,6 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI): "did not complete, host_uuid=%s, host_name=%s." % (host_uuid, host_name)) - if self._host_supports_kubernetes(host_personality): - response['reason'] = 'failed to enable kubernetes services' - - # To enable kubernetes we remove the NoExecute taint from the - # node. This allows new pods to be scheduled on the node. - future.work(kubernetes_client.untaint_node, - host_name, "NoExecute", "services") - future.result = (yield) - - if not future.result.is_complete(): - DLOG.error("Kubernetes untaint_node failed, operation " - "did not complete, host_uuid=%s, host_name=%s." - % (host_uuid, host_name)) - return - response['completed'] = True response['reason'] = ''