Beispiel #1
0
func main() {
	flag.Parse()

	switch *opF {
	case "create":
		create()
	case "remove":
		remove()
	case "view":
		view()
	case "change-profile":
		changeProfile()
	case "change-acl":
		changeACL()
	case "":
		cli.Fatal(
			"you must specify an operation with the -op flag, " +
				"use the -help flag for details")
	default:
		cli.Fatal(
			"unknown operation " + *opF + ", " +
				"use the -help flag for details")

	}
}
Beispiel #2
0
func login() {

	usr, pwd := "", ""

	if *usrF != "" && *pwdF != "" {
		usr = *usrF
		pwd = *pwdF
	} else {
		usr, pwd = getCreds()
	}

	cert, err := spi.Login(usr, pwd)
	if err != nil {
		cli.Fatal(fmt.Sprintf("login failed: %v", err))
	}

	localUser, err := user.Current()
	if err != nil {
		cli.Fatal(fmt.Sprintf("could not get current user: %v", err))
	}

	spiDir := localUser.HomeDir + "/.spi"
	os.MkdirAll(spiDir, 0755)

	ioutil.WriteFile(spiDir+"/spi.cert", cert, 0644)
	ioutil.WriteFile(spiDir+"/spi.user", []byte(usr), 0644)
}
Beispiel #3
0
func create() {

	if *xpF == "" {
		cli.Fatal(
			"you must specify an experiment name with the -xp flag, " +
				"use the -help flag for details")
	}

	if *srcF == "" {
		cli.Fatal(
			"you must specify a TopDL source file with the -src flag, " +
				"use the -help flag for details")
	}

	cli.PreRun()

	src, err := ioutil.ReadFile(*srcF)
	if err != nil {
		cli.Fatal(fmt.Sprintf("Failed to read source file '%s'", *srcF))
	}

	rsp, err := spi.CreateExperiment(*xpF, cli.User, string(src), false)
	if err != nil {
		cli.Fatal("create experiment failed")
	}

	if rsp.Return != true {
		cli.Fatal("create experiment returned false")
	}

}
Beispiel #4
0
func remove() {

	if *rzF == "" {
		cli.Fatal(
			"you must specify a realization name with the -rz flag, " +
				"use the -help flag for details")
	}

	cli.PreRun()

	rsp, err := spi.RemoveRealization(*rzF)
	if err != nil {
		cli.Fatal(fmt.Sprintf("remove realization failed: %v", err))
	}

	if rsp.Return != true {
		cli.Fatal("Removal of the realization failed")
	}

}
Beispiel #5
0
func remove() {

	cli.PreRun()

	if *xpF == "" {
		cli.Fatal(
			"you must specify an experiment name with the -xp flag, " +
				"use the -help flag for details")
	}

	rsp, err := spi.RemoveExperiment(*xpF)
	if err != nil {
		cli.Fatal(fmt.Sprintf("remove experiment failed: %v", err))
	}

	if rsp.Return != true {
		cli.Fatal("Removal of the experiment failed")
	}

}
Beispiel #6
0
func view() {

	cli.PreRun()

	rsp, err := spi.ViewRealizations(cli.User, ".*")
	if err != nil {
		cli.Fatal(fmt.Sprintf("view realizations failed: %v", err))
	}
	for _, x := range rsp.Return {
		fmt.Printf("%s : %s\n", x.Name, x.Status)
	}

}
Beispiel #7
0
func view() {

	cli.PreRun()

	rsp, err := spi.ViewExperiments(cli.User, ".*", !*verboseF)
	if err != nil {
		cli.Fatal(fmt.Sprintf("view experiments failed: %v", err))
	}
	for _, x := range rsp.Return {
		fmt.Println(x)
	}

}
Beispiel #8
0
func changeProfile() {

	if *xpF == "" {
		cli.Fatal(
			"you must specify an experiment name with the -xp flag, " +
				"use the -help flag for details")
	}
	if *nameF == "" {
		cli.Fatal(
			"you must specify an argument name with the -name flag, " +
				"use the -help flag for details")
	}
	if *valueF == "" {
		cli.Fatal(
			"you must specify an argument value with the -value flag, " +
				"use the -help flag for details")
	}

	cli.PreRun()

	attr := spi.ChangeAttribute{}
	attr.Name = *nameF
	attr.Value = *valueF
	attr.Delete = *deleteF

	attrs := []spi.ChangeAttribute{attr}

	rsp, err := spi.ChangeExperimentProfile(*xpF, attrs)

	if err != nil {
		cli.Fatal(fmt.Sprintf("change profile failed: %v", err))
	}
	for _, x := range rsp.Return {
		fmt.Println(x)
	}

}
Beispiel #9
0
func create() {

	if *rzF == "" {
		cli.Fatal(
			"you must specify a realization name with the -rz flag, " +
				"use the -help flag for details")
	}

	if *circF == "" {
		cli.Fatal(
			"you must specify a circle name with the -circle flag, " +
				"use the -help flag for details")
	}

	cli.PreRun()

	rsp, err := spi.RealizeExperiment(*rzF, *circF, cli.User)
	if err != nil {
		cli.Fatal("create realization failed")
	}

	fmt.Println(rsp)

}
Beispiel #10
0
func changeACL() {

	if *xpF == "" {
		cli.Fatal(
			"you must specify an experiment name with the -xp flag, " +
				"use the -help flag for details")
	}

	if *circF == "" {
		cli.Fatal(
			"you must specify a circle name with the -circle flag, " +
				"use the -help flag for details")
	}

	if *permF == "" {
		cli.Fatal(
			"you must specify a permission name with the -perm flag, " +
				"use the -help flag for details")
	}

	cli.PreRun()

	acm := spi.AccessMember{}
	acm.CircleId = *circF
	acm.Permissions = []string{*permF}

	rsp, err := spi.ChangeExperimentACL(*xpF, []spi.AccessMember{acm})

	if err != nil {
		cli.Fatal(fmt.Sprintf("change acl failed: %v", err))
	}
	for _, x := range rsp.Return {
		fmt.Println(x)
	}

}