當前位置: 首頁>>代碼示例>>Golang>>正文


Golang CloudServersProvider.ListServers方法代碼示例

本文整理匯總了Golang中github.com/rackspace/gophercloud.CloudServersProvider.ListServers方法的典型用法代碼示例。如果您正苦於以下問題:Golang CloudServersProvider.ListServers方法的具體用法?Golang CloudServersProvider.ListServers怎麽用?Golang CloudServersProvider.ListServers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/rackspace/gophercloud.CloudServersProvider的用法示例。


在下文中一共展示了CloudServersProvider.ListServers方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: tryFullDetails

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)
		}
	}
}
開發者ID:WIZARD-CXY,項目名稱:golang-devops-stuff,代碼行數:13,代碼來源:02-list-servers.go

示例2: locateAServer

// 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
}
開發者ID:GeertJohan,項目名稱:gophercloud,代碼行數:26,代碼來源:03-get-server-details.go


注:本文中的github.com/rackspace/gophercloud.CloudServersProvider.ListServers方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。