Ejemplo n.º 1
0
func (r *RPC) CheckPodAuth(podname string, resp *map[string]bool) error {
	pod, err := r.constellation.GetPod(podname)
	if err != nil || pod == nil {
		log.Print("No pod. Error: ", err)
		return err
	}
	psresults := make(map[string]bool)
	if pod.Master == nil {
		mnode, err := actions.LoadNodeFromHostPort(pod.Master.Address, pod.Master.Port, pod.AuthToken)
		if err != nil {
			log.Print("Connection error: ", err)
			return errors.New("Unable to connect to master nod at all. Check server logs for why")
		}
		pod.Master = mnode
	}
	mres := pod.Master.Ping()
	psresults[pod.Master.Name] = mres
	for _, slave := range pod.Master.Slaves {
		log.Printf("Checking ping/auth for slave %s", slave.Name)
		sres := slave.Ping()
		psresults[slave.Name] = sres
	}
	*resp = psresults
	return nil
}
Ejemplo n.º 2
0
// AddSlaveHTMLProcessor is the action target for the AddSlaveHTML form
func AddSlaveHTMLProcessor(c web.C, w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	log.Print("add slave processor called")
	podname := c.URLParams["podName"]
	context, err := NewPageContext()
	checkContextError(err, &w)
	pod, _ := context.Constellation.GetPod(podname)
	context.Title = "Pod Slave Result"
	context.ViewTemplate = "slave-added"
	context.Pod = pod
	context.Refresh = true
	context.RefreshURL = fmt.Sprintf("/pod/%s", pod.Name)
	context.RefreshTime = 5
	address := r.FormValue("host")
	sname := r.FormValue("sname")
	portstr := r.FormValue("port")
	slaveauth := r.FormValue("authtoken")
	port, _ := strconv.Atoi(portstr)

	type results struct {
		PodName      string
		SlaveName    string
		SlaveAddress string
		SlavePort    int
		Error        string
		HasError     bool
		PodURL       string
	}
	res := results{PodName: podname, SlaveName: sname, SlaveAddress: address, SlavePort: port}
	name := fmt.Sprintf("%s:%d", address, port)
	slave_target, err := client.DialWithConfig(&client.DialConfig{Address: name, Password: slaveauth})
	defer slave_target.ClosePool()
	if err != nil {
		log.Print("ERR: Dialing slave -", err)
		context.Data = err
		render(w, context)
		return
	}
	err = slave_target.SlaveOf(pod.Info.IP, fmt.Sprintf("%d", pod.Info.Port))
	if err != nil {
		log.Printf("Err: %v", err)
	} else {
		log.Printf("Slave added success")
		slave_target.ConfigSet("masterauth", pod.AuthToken)
		slave_target.ConfigSet("requirepass", pod.AuthToken)
		slave, err := actions.LoadNodeFromHostPort(address, port, pod.AuthToken)
		if err != nil {
			log.Printf("In AddSlaveHTMLProcessor, unable to get new slave node")
		} else {
			pod.Master.Slaves = append(pod.Master.Slaves, slave)
		}
	}
	context.Data = res
	render(w, context)

}