Example #1
0
func APIGetInstanceFromPort(c web.C, w http.ResponseWriter, r *http.Request) {
	port := c.URLParams["port"]
	iport, err := strconv.Atoi(port)
	resp := common.InfoResponse{Status: "data"}
	if err != nil {
		resp.Status = "Client Error"
		resp.StatusMessage = "Invalid port integer passed. Use a valid port number"
	} else {
		name, err := actions.GetInstanceFromPort(iport)
		stop := returnUnhandledError(err, &w)
		if stop {
			return
		}
		sname := string(name)
		if len(sname) > 0 {
			resp.Data = sname
			resp.StatusMessage = "Mapping found"
		} else {
			resp.Data = ""
			resp.StatusMessage = "No mapping found"
		}
	}
	packed, _ := json.Marshal(resp)
	w.Write(packed)
}
Example #2
0
func APIGetPortFromInstance(c web.C, w http.ResponseWriter, r *http.Request) {
	id := c.URLParams["id"]
	resp := common.InfoResponse{Status: "data"}
	port, err := actions.GetPortFromInstance(id)
	stop := returnUnhandledError(err, &w)
	if stop {
		return
	}
	log.Printf("gat '%s' for port from call for '%s'", port, id)
	if len(port) > 0 {
		iport, err := strconv.Atoi(port)
		if err != nil {
			resp.Status = "Error"
			resp.StatusMessage = "Invalid port integer received from data store. Someone needs to investigate this RIGHT NOW."
			log.Printf("port: '%s'", port)
		} else {
			resp.Data = iport
			resp.StatusMessage = "Port found"
		}
	} else {
		resp.Data = 0
		resp.StatusMessage = "No Port found"
	}
	packed, _ := json.Marshal(resp)
	w.Write(packed)
}