本文整理汇总了Golang中github.com/rackspace/gophercloud/rackspace/compute/v2/servers.ExtractServers函数的典型用法代码示例。如果您正苦于以下问题:Golang ExtractServers函数的具体用法?Golang ExtractServers怎么用?Golang ExtractServers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ExtractServers函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: List
func (i *Instances) List(name_filter string) ([]string, error) {
glog.V(2).Infof("rackspace List(%v) called", name_filter)
opts := osservers.ListOpts{
Name: name_filter,
Status: "ACTIVE",
}
pager := servers.List(i.compute, opts)
ret := make([]string, 0)
err := pager.EachPage(func(page pagination.Page) (bool, error) {
sList, err := servers.ExtractServers(page)
if err != nil {
return false, err
}
for _, server := range sList {
ret = append(ret, server.Name)
}
return true, nil
})
if err != nil {
return nil, err
}
glog.V(2).Infof("Found %v entries: %v", len(ret), ret)
return ret, nil
}
开发者ID:ethernetdan,项目名称:kubernetes,代码行数:28,代码来源:rackspace.go
示例2: getServerByAddress
func getServerByAddress(client *gophercloud.ServiceClient, name string) (*osservers.Server, error) {
pager := servers.List(client, nil)
serverList := make([]osservers.Server, 0, 1)
err := pager.EachPage(func(page pagination.Page) (bool, error) {
s, err := servers.ExtractServers(page)
if err != nil {
return false, err
}
for _, v := range s {
if serverHasAddress(v, name) {
serverList = append(serverList, v)
}
}
if len(serverList) > 1 {
return false, ErrMultipleResults
}
return true, nil
})
if err != nil {
return nil, err
}
if len(serverList) == 0 {
return nil, ErrNotFound
} else if len(serverList) > 1 {
return nil, ErrMultipleResults
}
return &serverList[0], nil
}
开发者ID:ethernetdan,项目名称:kubernetes,代码行数:32,代码来源:rackspace.go
示例3: Execute
func (command *commandList) Execute(resource *handler.Resource) {
opts := resource.Params.(*paramsList).opts
allPages := resource.Params.(*paramsList).allPages
pager := servers.List(command.Ctx.ServiceClient, opts)
if allPages {
pages, err := pager.AllPages()
if err != nil {
resource.Err = err
return
}
info, err := servers.ExtractServers(pages)
if err != nil {
resource.Err = err
return
}
result := make([]map[string]interface{}, len(info))
for j, server := range info {
result[j] = serverSingle(&server)
}
resource.Result = result
} else {
limit := opts.Limit
err := pager.EachPage(func(page pagination.Page) (bool, error) {
info, err := servers.ExtractServers(page)
if err != nil {
return false, err
}
result := make([]map[string]interface{}, len(info))
for j, server := range info {
result[j] = serverSingle(&server)
}
resource.Result = result
if len(info) >= limit {
return false, nil
}
limit -= len(info)
command.Ctx.WaitGroup.Add(1)
command.Ctx.Results <- resource
return true, nil
})
if err != nil {
resource.Err = err
return
}
}
}
开发者ID:flazz,项目名称:rack,代码行数:46,代码来源:list.go
示例4: GetList
func GetList(c *cli.Context) {
// assign vars from cli args
user := c.String("user")
key := c.String("key")
region := c.String("region")
// step 1, set up auth options
ao := gophercloud.AuthOptions{
Username: user,
APIKey: key,
}
// step 2, rax auth to get back provider instance
provider, err := rackspace.AuthenticatedClient(ao)
if err != nil {
fmt.Println(err)
}
// set rax region
serviceClient, err2 := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
Region: region,
})
if err2 != nil {
fmt.Println(err2)
}
// Retrieve a pager (i.e. a paginated collection)
server_pager := servers.List(serviceClient, nil)
// Define an anonymous function to be executed on each page's iteration
err6 := server_pager.EachPage(func(page pagination.Page) (bool, error) {
serverList, err7 := servers.ExtractServers(page)
if err7 != nil {
fmt.Println(err7)
}
for _, s := range serverList {
// "s" will be a servers.Server
// https://github.com/rackspace/gophercloud/blob/master/openstack/compute/v2/servers/results.go
fmt.Println("Name: ", s.Name)
fmt.Println("UUID: ", s.ID)
fmt.Println("Created: ", s.Created)
fmt.Println("Updated: ", s.Updated)
fmt.Println("Progress: ", s.Progress)
fmt.Println("HostID: ", s.HostID)
fmt.Println("Image: ", s.Image["id"])
fmt.Println("Flavor ID: ", s.Flavor["id"])
fmt.Println("Status: ", s.Status)
fmt.Println("Access: ", s.AccessIPv4)
fmt.Println("Public: ", s.Addresses["public"])
fmt.Println("Addresses: ", s.Addresses)
fmt.Println("\n")
}
return true, nil
})
if err6 != nil {
fmt.Println(err6)
}
}
开发者ID:rackeric,项目名称:erack,代码行数:57,代码来源:list.go
示例5: findServer
func findServer(t *testing.T) string {
var serverIP string
client, err := newComputeClient()
th.AssertNoErr(t, err)
err = servers.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
sList, err := servers.ExtractServers(page)
th.AssertNoErr(t, err)
for _, s := range sList {
serverIP = s.AccessIPv4
t.Logf("Found an existing server: ID [%s] Public IP [%s]", s.ID, serverIP)
break
}
return true, nil
})
th.AssertNoErr(t, err)
if serverIP == "" {
t.Log("No server found, creating one")
imageRef := os.Getenv("RS_IMAGE_ID")
if imageRef == "" {
t.Fatalf("OS var RS_IMAGE_ID undefined")
}
flavorRef := os.Getenv("RS_FLAVOR_ID")
if flavorRef == "" {
t.Fatalf("OS var RS_FLAVOR_ID undefined")
}
opts := &servers.CreateOpts{
Name: tools.RandomString("lb_test_", 5),
ImageRef: imageRef,
FlavorRef: flavorRef,
DiskConfig: diskconfig.Manual,
}
s, err := servers.Create(client, opts).Extract()
th.AssertNoErr(t, err)
serverIP = s.AccessIPv4
t.Logf("Created server %s, waiting for it to build", s.ID)
err = servers.WaitForStatus(client, s.ID, "ACTIVE", 300)
th.AssertNoErr(t, err)
t.Logf("Server created successfully.")
}
return serverIP
}
开发者ID:RomainVabre,项目名称:origin,代码行数:51,代码来源:node_test.go
示例6: ListAllInstance
func (sdk *RackspaceSDK) ListAllInstance() (idInstanceMap map[string]Instance) {
idInstanceMap = map[string]Instance{}
err := servers.List(sdk.p, nil).EachPage(func(p pagination.Page) (quit bool, err error) {
serverSlice, err := servers.ExtractServers(p)
for _, server := range serverSlice {
idInstanceMap[server.ID] = Instance{
Ip: server.AccessIPv4,
Id: server.ID,
Name: server.Name,
BelongToSDK: sdk,
}
}
return true, err
})
handleErr(err)
return
}
开发者ID:keysonZZZ,项目名称:kmg,代码行数:17,代码来源:SDKRackspace.go
示例7: listServers
func listServers(t *testing.T, client *gophercloud.ServiceClient) {
t.Logf("> servers.List")
count := 0
err := servers.List(client, nil).EachPage(func(page pagination.Page) (bool, error) {
count++
t.Logf("--- Page %02d ---", count)
s, err := servers.ExtractServers(page)
th.AssertNoErr(t, err)
for index, server := range s {
logServer(t, &server, index)
}
return true, nil
})
th.AssertNoErr(t, err)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:18,代码来源:servers_test.go
示例8: ListAllRunningInstance
func (sdk *RackspaceSDK) ListAllRunningInstance() (ipInstanceMap map[string]Instance) {
ipInstanceMap = map[string]Instance{}
err := servers.List(sdk.p, nil).EachPage(func(p pagination.Page) (quit bool, err error) {
serverSlice, err := servers.ExtractServers(p)
for _, server := range serverSlice {
if server.Status != string(RackspaceInstanceStatusACTIVE) {
fmt.Println(logPrefixRackspace, server.ID, server.AccessIPv4, server.Status)
continue
}
ipInstanceMap[server.AccessIPv4] = Instance{
Ip: server.AccessIPv4,
Id: server.ID,
Name: server.Name,
BelongToSDK: sdk,
}
}
return true, err
})
handleErr(err)
return
}
开发者ID:keysonZZZ,项目名称:kmg,代码行数:21,代码来源:SDKRackspace.go
示例9: getServerByName
func getServerByName(client *gophercloud.ServiceClient, name string) (*osservers.Server, error) {
if net.ParseIP(name) != nil {
// we're an IP, so we'll have to walk the full list of servers to
// figure out which one we are.
return getServerByAddress(client, name)
}
opts := osservers.ListOpts{
Name: fmt.Sprintf("^%s$", regexp.QuoteMeta(name)),
Status: "ACTIVE",
}
pager := servers.List(client, opts)
serverList := make([]osservers.Server, 0, 1)
err := pager.EachPage(func(page pagination.Page) (bool, error) {
s, err := servers.ExtractServers(page)
if err != nil {
return false, err
}
serverList = append(serverList, s...)
if len(serverList) > 1 {
return false, ErrMultipleResults
}
return true, nil
})
if err != nil {
return nil, err
}
if len(serverList) == 0 {
return nil, ErrNotFound
} else if len(serverList) > 1 {
return nil, ErrMultipleResults
}
return &serverList[0], nil
}
开发者ID:ethernetdan,项目名称:kubernetes,代码行数:37,代码来源:rackspace.go
注:本文中的github.com/rackspace/gophercloud/rackspace/compute/v2/servers.ExtractServers函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论