Пример #1
0
func freeAlloc(alloc int64) (err error) {
	bs := new(fnet.BuildServer)
	allocfree, err := cli.NewClient()
	cli.PrintError("Failed to create a new client", err)
	bs, err = allocfree.SetupClient("heckle")
	cli.PrintError("Falied to setup heckle as a client", err)

	_, err = bs.PostServer("/freeAllocation", alloc)
	if err != nil {
		return
	}

	return
}
Пример #2
0
func init() {
	var error error
	flag.BoolVar(&help, "h", false, "Print usage of command.")
	flag.IntVar(&numNodes, "n", 0, "Request an arbitrary number of nodes.")
	flag.IntVar(&timeIncrease, "t", 0, "Increase current allocation by this many hours.")
	flag.StringVar(&image, "i", "ubuntu-maverick-amd64", "Image to be loaded on to the nodes.")

	flag.Parse()

	if hallocC, error = hclient.NewClient(); error != nil {
		fmt.Fprintf(os.Stderr, "Failed to get new client from client package in halloc.\n")
		os.Exit(1)
	}

	allocationNumber = uint64(0)
	allocationList = flag.Args()
}
Пример #3
0
func init() {
	var err error
	if hstat, err = cli.NewClient(); err != nil {
		fmt.Fprintf(os.Stderr, "Failed to get new client.\n")
		os.Exit(1)
	}

	if bs, err = hstat.SetupClient("heckle"); err != nil {
		cli.PrintError("Failed to setup client in halloc.", errors.New("Client Setup Failed"))
		os.Exit(1)
	}

	flag.BoolVar(&help, "h", false, "Print usage of command.")
	flag.StringVar(&user, "u", " ", "Find user")
	flag.StringVar(&node, "n", " ", "Find nodes")
	flag.StringVar(&alloc, "a", " ", "Find alloc")
	flag.StringVar(&image, "i", " ", "Find image")
}
Пример #4
0
func commPower(nodes []string, cmd string) (outletStatus map[string]States, err error) {
	var powerCommand string
	if cmd == "status" {
		powerCommand = "/status"
	} else {
		powerCommand = "/command/" + cmd
	}

	powerServ, err := cli.NewClient()
	if err != nil {
		cli.PrintError("Unable to set up communication to power", err)
		return
	}

	client, err := powerServ.SetupClient("power")
	if err != nil {
		cli.PrintError("Unable to lookup power", err)
		return
	}

	statusRet, err := client.PostServer(powerCommand, nodes)

	if err != nil {
		cli.PrintError("Unable to post", err)
		return
	}

	switch cmd {
	case "on", "off", "reboot":
		outletStatus = nil
		break
	case "status":
		err = json.Unmarshal(statusRet, &outletStatus)
		if err != nil {
			cli.PrintError("Unable to unmarsahll status", err)
		}
		break
	}
	return

}
Пример #5
0
func main() {
	flag.Parse()
	if help || minutesTimeout < 1 {
		fclient.Usage()
		os.Exit(0)
	}

	comm, err := fclient.NewClient()
	if err != nil {
		fclient.PrintError("Failed to setup communcation", err)
		os.Exit(1)
	}

	secondsTimeout := minutesTimeout * 60 * 1000000000
	cancelTime := time.Now().Add(time.Duration(secondsTimeout))
	addresses := flag.Args()

	bs, err := comm.SetupClient("flunky")

	bs.DebugLog(fmt.Sprintf("Allocating hosts: %s", flag.Args()))

	if image == "" {
		fclient.PrintError("-i option is required\n", errors.New("wrong arg"))
		fclient.Usage()
		os.Exit(1)
	}

	cm := new(ctlmsg)
	cm.Image = image
	cm.Addresses = addresses
	// FIXME: need to add in extradata
	_, err = bs.PostServer("/ctl", cm)
	if err != nil {
		fclient.PrintError("Failed to allocate node", err)
		os.Exit(1)
	}

	pollForMessages(cancelTime, addresses, bs)
	fmt.Fprintf(os.Stdout, "Done allocating your nodes. Report failed builds to your system administrator.\n")
}
Пример #6
0
func main() {
	flag.Parse()
	clientList := make(map[string]*fnet.BuildServer)

	if help {
		fmt.Println(fmt.Sprintf("Command syntax -- %s daemon1 daemon2 ...daemonN", os.Args[0]))
		fclient.Usage()
		os.Exit(0)
	}

	if len(os.Args) <= 1 {
		fclient.PrintError("No arguments provided", errors.New("no args"))
		fmt.Println(fmt.Sprintf("Command syntax -- %s daemon1 daemon2 ...daemonN", os.Args[0]))
		fclient.Usage()
		os.Exit(1)
	}

	components := flag.Args()
	if len(components) == 0 {
		fclient.PrintError("No clients specified", errors.New("no client"))
		os.Exit(1)
	}

	for _, name := range components {
		comm, err := fclient.NewClient()
		if err != nil {
			fclient.PrintError("Failed to setup communication", err)
			os.Exit(1)
		}
		client, err := comm.SetupClient(name)
		if err != nil {
			fclient.PrintError(fmt.Sprintf("Failed to lookup component %s", name), err)
			os.Exit(1)
		}
		clientList[name] = client
	}

	if stat {
		var statusType Status
		respList := make(map[string]Status)
		for name, client := range clientList {
			resp, err := client.Get("daemon")
			if err != nil {
				fclient.PrintError("Could not get daemon status", err)
				os.Exit(1)
			}
			err = json.Unmarshal(resp, &statusType)
			if err != nil {
				fclient.PrintError(err.Error(), err)
			}
			respList[name] = statusType
		}
		printStatus(respList)
	}

	if dump {
		for name, client := range clientList {
			resp, err := client.Get("dump")
			if err != nil {
				fclient.PrintError(fmt.Sprintf("Failed to contact component %s", name), err)
				os.Exit(1)
			}
			fmt.Println(string(resp))
		}
	}

	if log {
		for name, _ := range clientList {
			logging := logs(name)
			fmt.Println(logging)
		}
	}

	if error_ {
		for name, _ := range clientList {
			errorLogging := logs(name)
			if len(errorLogging) <= 0 {
				fmt.Println(fmt.Sprintf("No errors exsist in the logs for %s", name))
			} else {
				fmt.Println(errorLogging)
			}
		}
	}

}