Exemple #1
0
/*
 *  Invoke the tegu_add_mirror or tegu_del_mirror command on a remote host in order to add/remove a mirror.
 */
func do_mirrorwiz(req json_action, broker *ssh_broker.Broker, path *string) {
	startt := time.Now().UnixNano()

	cstr := ""
	switch req.Qdata[0] {
	case "add":
		cstr = fmt.Sprintf(`PATH=%s:$PATH tegu_add_mirror %s %s %s`, *path, req.Qdata[1], req.Qdata[2], req.Qdata[3])
		if len(req.Qdata) > 4 {
			// If VLAN list is in the arguments, tack that on the end
			cstr += " " + req.Qdata[4]
		}

	case "del":
		cstr = fmt.Sprintf(`PATH=%s:$PATH tegu_del_mirror %s`, *path, req.Qdata[1])
	}
	if cstr != "" {
		sheep.Baa(1, "via broker on %s: %s", req.Hosts[0], cstr)
		_, stderr, err := broker.Run_cmd(req.Hosts[0], cstr)
		if err != nil {
			sheep.Baa(0, "ERR: send mirror cmd failed host=%s: %s	[TGUAGN005]", req.Hosts[0], err)
		} else {
			sheep.Baa(2, "mirror cmd succesfully sent: %s", cstr)
		}
		if sheep.Would_baa(2) || err != nil {
			dump_stderr(*stderr, "addmirror"+req.Hosts[0]) // always dump on error, or if chatty
		}
	} else {
		sheep.Baa(0, "Unrecognized mirror command: "+req.Qdata[0])
	}
	endt := time.Now().UnixNano()
	sheep.Baa(1, "do_mirrorwiz: %d ms elapsed", (endt-startt)/1000)
}
/*
	run a command --  run as a go routine to run multiple in parallel
*/
func test_cmd(broker *ssh_broker.Broker, ch chan int, host *string, cmd *string) {

	fmt.Fprintf(os.Stderr, "test_cmd: running command %s\n", *cmd)
	stdout, stderr, err := broker.Run_cmd(*host, *cmd)
	if err != nil {
		fmt.Fprintf(os.Stderr, "command failed: %s:  %s \n", *host, err)
		fmt.Fprintf(os.Stderr, "%s", stderr.String())
	} else {
		fmt.Fprintf(os.Stderr, "command was successful:\n")
		fmt.Printf("%s\n", stdout.String())
	}

	fmt.Fprintf(os.Stderr, "go routine done: %s \n", *cmd)
	ch <- 1

	return
}