From ee5748eca6350222051125b5e2313f78da00efbe Mon Sep 17 00:00:00 2001 From: Ritu Sood Date: Tue, 3 Mar 2020 00:44:52 -0800 Subject: Adding function to Query cluster based on label Add Query endpoint and implements returning list of clusters with label. Issue-ID: MULTICLOUD-922 Signed-off-by: Ritu Sood Signed-off-by: Eric Multanen Change-Id: I879b5e9002a0cbc9191abb99f1e164ee2b1c6581 --- src/ncm/api/clusterhandler.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/ncm/api/clusterhandler.go') diff --git a/src/ncm/api/clusterhandler.go b/src/ncm/api/clusterhandler.go index cb147a8a..8c50f720 100644 --- a/src/ncm/api/clusterhandler.go +++ b/src/ncm/api/clusterhandler.go @@ -194,6 +194,23 @@ func (h clusterHandler) getClusterHandler(w http.ResponseWriter, r *http.Request provider := vars["provider-name"] name := vars["name"] + label := r.URL.Query().Get("label") + if len(label) != 0 { + ret, err := h.client.GetClustersWithLabel(provider, label) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + err = json.NewEncoder(w).Encode(ret) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + return + } + // handle the get all clusters case - return a list of only the json parts if len(name) == 0 { var retList []moduleLib.Cluster -- cgit 1.2.3-korg