aboutsummaryrefslogtreecommitdiffstats
path: root/src/dcm/api
diff options
context:
space:
mode:
authorIgor D.C <igor.duarte.cardoso@intel.com>2020-09-25 22:31:11 +0000
committerIgor D.C <igor.duarte.cardoso@intel.com>2020-09-25 23:24:29 +0000
commit8c0cc1278cc4d84863b076b2014b9bc9d8805218 (patch)
tree6f2274560030252710464db5b6ae93da8a0dce2e /src/dcm/api
parent425795c7d4e6ce81932918aca2a1462384d4507f (diff)
Implement Terminate operation in DCM
Also makes minor changes to non-terminate code as a side-effect of supporting the new Terminate operation (such as including tagContext in the LogicalCloudClient implementation of LogicalCloudManager interface). These changes are/will also be leveraged by other operations. Issue-ID: MULTICLOUD-1143 Change-Id: Idbd2ec9f6cf0e5584a0f51cf4c16144db56d9fa0 Signed-off-by: Igor D.C <igor.duarte.cardoso@intel.com>
Diffstat (limited to 'src/dcm/api')
-rw-r--r--src/dcm/api/api.go4
-rw-r--r--src/dcm/api/logicalCloudHandler.go48
2 files changed, 52 insertions, 0 deletions
diff --git a/src/dcm/api/api.go b/src/dcm/api/api.go
index de1d5c97..0f68a517 100644
--- a/src/dcm/api/api.go
+++ b/src/dcm/api/api.go
@@ -44,6 +44,7 @@ func NewRouter(
quotaClient = module.NewQuotaClient()
}
+ // Set up Logical Cloud API
logicalCloudHandler := logicalCloudHandler{client: logicalCloudClient,
clusterClient: clusterClient,
quotaClient: quotaClient,
@@ -67,6 +68,9 @@ func NewRouter(
lcRouter.HandleFunc(
"/logical-clouds/{logical-cloud-name}/apply",
logicalCloudHandler.applyHandler).Methods("POST")
+ lcRouter.HandleFunc(
+ "/logical-clouds/{logical-cloud-name}/terminate",
+ logicalCloudHandler.terminateHandler).Methods("POST")
// To Do
// get kubeconfig
/*lcRouter.HandleFunc(
diff --git a/src/dcm/api/logicalCloudHandler.go b/src/dcm/api/logicalCloudHandler.go
index 36ec4e05..2e1811b7 100644
--- a/src/dcm/api/logicalCloudHandler.go
+++ b/src/dcm/api/logicalCloudHandler.go
@@ -25,6 +25,7 @@ import (
"github.com/gorilla/mux"
"github.com/onap/multicloud-k8s/src/dcm/pkg/module"
+ pkgerrors "github.com/pkg/errors"
)
// logicalCloudHandler is used to store backend implementations objects
@@ -212,3 +213,50 @@ func (h logicalCloudHandler) applyHandler(w http.ResponseWriter, r *http.Request
return
}
+
+func (h logicalCloudHandler) terminateHandler(w http.ResponseWriter, r *http.Request) {
+ vars := mux.Vars(r)
+ project := vars["project-name"]
+ name := vars["logical-cloud-name"]
+
+ // Get logical cloud
+ lc, err := h.client.Get(project, name)
+ if err != nil {
+ if err.Error() == "Logical Cloud does not exist" {
+ http.Error(w, err.Error(), http.StatusNotFound)
+ return
+ }
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ _, ctxVal, err := h.client.GetLogicalCloudContext(name)
+ if ctxVal == "" {
+ err = pkgerrors.New("Logical Cloud hasn't been applied yet")
+ http.Error(w, err.Error(), http.StatusConflict)
+ return
+ }
+
+ // Get Clusters
+ clusters, err := h.clusterClient.GetAllClusters(project, name)
+
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ //Get Quotas
+ quotas, err := h.quotaClient.GetAllQuotas(project, name)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ err = module.DestroyEtcdContext(lc, clusters, quotas)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+
+ return
+}