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


Golang servers.ExtractServers函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。