Esempio n. 1
0
func tryFullDetails(api gophercloud.CloudServersProvider) {
	servers, err := api.ListServers()
	if err != nil {
		panic(err)
	}

	if !*quiet {
		fmt.Println("Id,Name,AccessIPv4,Status,Progress")
		for _, s := range servers {
			fmt.Printf("%s,\"%s\",%s,%s,%d\n", s.Id, s.Name, s.AccessIPv4, s.Status, s.Progress)
		}
	}
}
Esempio n. 2
0
// locateAServer queries the set of servers owned by the user.  If at least one
// exists, the first found is picked, and its ID is returned.  Otherwise, a new
// server will be created, and its ID returned.
//
// deleteAfter will be true if the caller should schedule a call to DeleteServerById()
// to clean up.
func locateAServer(servers gophercloud.CloudServersProvider) (deleteAfter bool, id string, err error) {
	ss, err := servers.ListServers()
	if err != nil {
		return false, "", err
	}

	if len(ss) > 0 {
		// We could just cheat and dump the server details from ss[0].
		// But, that tests ListServers(), and not ServerById().  So, we
		// elect not to cheat.
		return false, ss[0].Id, nil
	}

	serverId, err := createServer(servers, "", "", "", "")
	if err != nil {
		return false, "", err
	}
	err = waitForServerState(servers, serverId, "ACTIVE")
	return true, serverId, err
}