func testDockerInspect() { var response cpmserverapi.DockerInspectResponse var err error request := &cpmserverapi.DockerInspectRequest{} request.ContainerName = "testpoo" response, err = cpmserverapi.DockerInspectClient("http://192.168.0.106:10001", request) if err != nil { fmt.Println(err.Error()) } fmt.Println("returned " + response.IPAddress + " " + response.RunningState) }
func GetAllNodesForServer(w rest.ResponseWriter, r *rest.Request) { dbConn, err := util.GetConnection(CLUSTERADMIN_DB) if err != nil { logit.Error.Println("BackupNow: error " + err.Error()) rest.Error(w, err.Error(), 400) return } defer dbConn.Close() err = secimpl.Authorize(dbConn, r.PathParam("Token"), "perm-read") if err != nil { logit.Error.Println("GetAllNodesForServer: validate token error " + err.Error()) rest.Error(w, err.Error(), http.StatusUnauthorized) return } serverID := r.PathParam("ServerID") if serverID == "" { logit.Error.Println("GetAllNodesForServer: error serverID required") rest.Error(w, "serverID required", http.StatusBadRequest) return } results, err := admindb.GetAllContainersForServer(dbConn, serverID) if err != nil { logit.Error.Println("GetAllNodesForServer:" + err.Error()) logit.Error.Println("error " + err.Error()) rest.Error(w, err.Error(), http.StatusBadRequest) return } server, err2 := admindb.GetServer(dbConn, serverID) if err2 != nil { logit.Error.Println("GetAllNodesForServer:" + err2.Error()) logit.Error.Println("error " + err2.Error()) rest.Error(w, err2.Error(), http.StatusBadRequest) return } var response cpmserverapi.DockerInspectResponse var e error var url string nodes := make([]ClusterNode, len(results)) i := 0 for i = range results { nodes[i].ID = results[i].ID nodes[i].Name = results[i].Name nodes[i].ClusterID = results[i].ClusterID nodes[i].ServerID = results[i].ServerID nodes[i].Role = results[i].Role nodes[i].Image = results[i].Image nodes[i].CreateDate = results[i].CreateDate nodes[i].ProjectID = results[i].ProjectID nodes[i].ProjectName = results[i].ProjectName nodes[i].ServerName = results[i].ServerName nodes[i].Status = "down" request := &cpmserverapi.DockerInspectRequest{} request.ContainerName = results[i].Name url = "http://" + server.IPAddress + ":10001" response, e = cpmserverapi.DockerInspectClient(url, request) logit.Info.Println("GetAllNodesForServer:" + results[i].Name + " " + response.IPAddress + " " + response.RunningState) if e != nil { logit.Error.Println("GetAllNodesForServer:" + e.Error()) logit.Error.Println(e.Error()) nodes[i].Status = "notfound" } else { logit.Info.Println("GetAllNodesForServer: setting " + results[i].Name + " to " + response.RunningState) nodes[i].Status = response.RunningState } i++ } w.WriteJson(&nodes) }