示例#1
0
文件: token.go 项目: angst/roscoe
func main() {
	options := struct {
		Debug   bool `goptions:"-x, --debug, description='Enable debugging'"`
		Verbose bool `goptions:"-v, --verbose, description='Be not quiet with output'"`
	}{
		Debug:   false,
		Verbose: false,
	}
	goptions.Parse(&options)

	// Propagate debug setting to packages
	client.Debug = &options.Debug

	// Get auth values from the environment
	var creds client.Credentials
	creds.AuthUrl = os.Getenv("OS_AUTH_URL")
	creds.OSAuth.TenantName = os.Getenv("OS_TENANT_NAME")
	creds.OSAuth.PasswordCredentials.Username = os.Getenv("OS_USERNAME")
	creds.OSAuth.PasswordCredentials.Password = os.Getenv("OS_PASSWORD")
	cacert = os.Getenv("OS_CACERT")

	// read cacert

	pool = NewCertPool()
	for j, root := range test.roots {
		ok := opts.Roots.AppendCertsFromPEM([]byte(root))
		if !ok {
			t.Errorf("#%d: failed to parse root #%d", i, j)
			return
		}
	}

	// Set up TLS config
	conf := &tls.Config{InsecureSkipVerify: true}

	c, err := client.NewClient(creds, conf)
	if err != nil {
		log.Fatal(err)
	}

	//osclib.GetVersions(c.Auth)

	if options.Verbose == true {
		fmt.Printf("Token.Id=%s\n", c.Token.Id)
		fmt.Printf("Token.Expires=%s\n", c.Token.Expires)
		fmt.Printf("Tenant.Id=%s\n", c.Token.Tenant.Id)
		fmt.Printf("Tenant.Name=%s\n", c.Token.Tenant.Name)
	} else {
		fmt.Printf("%s %s\n", c.Token.Id, c.Token.Expires)
	}
}
示例#2
0
文件: mystuff.go 项目: angst/roscoe
func main() {
	options := struct {
		Debug   bool `goptions:"-x, --debug, description='Enable debugging'"`
		Verbose bool `goptions:"-v, --verbose, description='Be not quiet with output'"`
	}{
		Debug:   false,
		Verbose: false,
	}
	goptions.Parse(&options)

	// Propagate debug setting to packages
	client.Debug = &options.Debug

	// Get auth values from the environment
	var creds osclib.Creds
	c, err := client.NewClient(creds)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Print("Servers: \n")
	servers, err := server.List(c, "")
	if err != nil {
		log.Fatal(err)
	}
	if servers != nil {
		if options.Verbose == true {
			fmt.Printf("c: %+v\n\n", *servers)
		} else {
			fmt.Printf("c: %+v\n\n", *servers)
		}
	}

	flavors, err := flavor.List(c, "")
	if err != nil {
		log.Fatal(err)
	}
	//    osclib.OutputData([]string{"a","b","c"}, []interface{}(flavors))
	for k, v := range flavors.Flavors {
		fmt.Printf("%d: %s\n", k, v.Id)
	}

}
示例#3
0
func TestNewClient(t *testing.T) {
	// Set env
	os.Setenv("OS_USERNAME", "ford")
	os.Setenv("OS_PASSWORD", "prefect")
	os.Setenv("OS_TENANT_NAME", "ccc-guide")
	os.Setenv("OS_AUTH_URL", "http://ccc.com:42")
	oscc, _ := client.NewClient(creds, nil)
	if oscc.Auth.OSAuth.PasswordCredentials.Username != "ford" {
		t.Error("NewCLient didn't pick up OS_USERNAME from environment")
	}
	if oscc.Auth.OSAuth.PasswordCredentials.Password != "prefect" {
		t.Error("NewCLient didn't pick up OS_PASSWORD from environment")
	}
	if oscc.Auth.OSAuth.TenantName != "ccc-guide" {
		t.Error("NewCLient didn't pick up OS_TENANT_NAME from environment")
	}
	if oscc.Auth.AuthUrl != "http://ccc.com:42" {
		t.Error("NewCLient didn't pick up OS_AUTH_URL from environment")
	}
}
示例#4
0
文件: osc.go 项目: angst/roscoe
func main() {
	var options OptType = OptType{
		Debug:   false,
		Verbose: false,
	}
	goptions.Parse(&options)

	// Propagate debug setting to packages
	client.Debug = &options.Debug

	if len(os.Args) <= 1 || options.Help {
		Usage()
	}

	// Get our credentials
	creds, err := GetAuthCreds(options)
	if err != nil {
		log.Fatal(err)
	}

	// Make a new client with these creds
	c, err := client.NewClient(creds, nil)
	if err != nil {
		log.Fatal(err)
	}

	if options.Debug {
		fmt.Printf("token: %s\n", c.Token)
		fmt.Printf("servcat: %s\n", c.ServCat)
	}

	fmt.Printf("verbs: %+v\n", options.Verbs)
	//    fmt.Printf("obj: %+v\n", options.Show.Verbs)

	switch options.Verbs {
	case "listflavors":
		fmt.Print("Args: ", os.Args[1:], "\n")
		if len(os.Args) > 1 {
			if f, ok := ListCmds["flavors"]; ok {
				err = f(c, &options.ListFlavors)
			} else {
				fmt.Printf("Unknown command: %s %s\n", options.Verbs, os.Args[1])
				fmt.Print("Args: ", os.Args[1:], "\n")
			}
		} else {
			Usage()
		}
		os.Exit(0)
	case "listservers":
		if len(os.Args) > 2 {
			if f, ok := ListCmds["servers"]; ok {
				err = f(c, &options.ListServers)
			} else {
				fmt.Printf("Unknown command: %s %s\n", options.Verbs, os.Args[3])
				fmt.Print("Args: ", os.Args[1:], "\n")
			}
		} else {
			Usage()
		}
		os.Exit(0)
	case "show":
		if len(os.Args) > 2 {
			if f, ok := ShowCmds[string(options.Show.Verbs)]; ok {
				err = f(c, &options.Show)
			} else {
				fmt.Printf("Unknown command: %s %s\n", options.Verbs, os.Args[3])
				fmt.Print("Args: ", os.Args[1:], "\n")
			}
		} else {
			Usage()
		}
		os.Exit(0)
	case "version":
		if options.Version.Identity {
			// Identity API versions
			//                osclib.GetVersions(c.Auth)
			os.Exit(0)
		} else {
			fmt.Printf("Version: %s\n", Version)
			os.Exit(0)
		}
	default:
		fmt.Printf("Unknown verb: %s\n", options.Verbs)
		Usage()
	}

	//    attr := make(server.Attr)
	//    attr["name"] = "npd01"
	//    servers, err := server.Show(c, attr)
	//    if err != nil {
	//        log.Fatal(err)
	//    }
	//    fmt.Printf("c: %+v\n\n", *servers)

}