예제 #1
0
파일: main.go 프로젝트: monchier/go-sandbox
func shutdown() {
	log.Println("Start shutdown (ie etcd cleanup)")
	option, err := ncsp.Config.GetOption("etcd.machines")
	ncsp.ErrCheckFatal(err, "Configuration error")
	machines := ncsp.ToEtcdMachinesList(option.([]interface{}))
	c := etcd.NewClient(machines)
	_, err = c.Get("/ncsp", false, false)
	if err != nil {
		if ncsp.EtcdErrorCode(err) != 100 {
			log.Fatal(err, "Get failed")
		}
	} else {
		_, err = c.Delete("/ncsp", true)
		ncsp.ErrCheckFatal(err, "Cannot delete")
	}
	log.Println("Shutdown done and etcd has been cleaned up")
}
예제 #2
0
파일: main.go 프로젝트: monchier/go-sandbox
func prepare() {
	// cleanup
	ncsp.Config.Init("conf.json")
	option, err := ncsp.Config.GetOption("etcd.machines")
	ncsp.ErrCheckFatal(err, "Configuration error")
	machines := ncsp.ToEtcdMachinesList(option.([]interface{}))
	c := etcd.NewClient(machines)
	err = c.SetConsistency(etcd.STRONG_CONSISTENCY) // TODO: is this valid for other clients as well?
	ncsp.ErrCheckFatal(err, "Consistency")
	_, err = c.Get("/ncsp", false, false)
	if err != nil {
		if ncsp.EtcdErrorCode(err) != 100 {
			log.Fatal(err, "Get failed")
		}
	} else {
		_, err = c.Delete("/ncsp", true)
		ncsp.ErrCheckFatal(err, "Cannot delete")
	}
	_, err = c.CreateDir("/ncsp/", 0)
	ncsp.ErrCheckFatal(err, "Creating root dir")
}