• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang servers.ExtractServers函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/rackspace/gophercloud/openstack/compute/v2/servers.ExtractServers函数的典型用法代码示例。如果您正苦于以下问题:Golang ExtractServers函数的具体用法?Golang ExtractServers怎么用?Golang ExtractServers使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ExtractServers函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: getServerByName

func getServerByName(client *gophercloud.ServiceClient, name types.NodeName) (*servers.Server, error) {
	opts := servers.ListOpts{
		Name:   fmt.Sprintf("^%s$", regexp.QuoteMeta(mapNodeNameToServerName(name))),
		Status: "ACTIVE",
	}
	pager := servers.List(client, opts)

	serverList := make([]servers.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:alex-mohr,项目名称:kubernetes,代码行数:32,代码来源:openstack.go


示例2: List

func (i *Instances) List(name_filter string) ([]string, error) {
	glog.V(4).Infof("openstack List(%v) called", name_filter)

	opts := servers.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(3).Infof("Found %v instances matching %v: %v",
		len(ret), name_filter, ret)

	return ret, nil
}
开发者ID:RyanBinfeng,项目名称:kubernetes,代码行数:29,代码来源:openstack.go


示例3: TestListServers

func TestListServers(t *testing.T) {
	client, err := newClient()
	if err != nil {
		t.Fatalf("Unable to create a compute client: %v", err)
	}

	t.Logf("ID\tRegion\tName\tStatus\tIPv4\tIPv6")

	pager := servers.List(client, servers.ListOpts{})
	count, pages := 0, 0
	pager.EachPage(func(page pagination.Page) (bool, error) {
		pages++
		t.Logf("---")

		servers, err := servers.ExtractServers(page)
		if err != nil {
			return false, err
		}

		for _, s := range servers {
			t.Logf("%s\t%s\t%s\t%s\t%s\t\n", s.ID, s.Name, s.Status, s.AccessIPv4, s.AccessIPv6)
			count++
		}

		return true, nil
	})

	t.Logf("--------\n%d servers listed on %d pages.\n", count, pages)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:29,代码来源:servers_test.go


示例4: findServer

func findServer(t *testing.T, client *gophercloud.ServiceClient) (string, bool) {
	var serverID string
	var needsDeletion bool

	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 {
			serverID = s.ID
			needsDeletion = false

			t.Logf("Found an existing server: ID [%s]", serverID)
			break
		}

		return true, nil
	})
	th.AssertNoErr(t, err)

	if serverID == "" {
		t.Log("No server found, creating one")

		choices, err := ComputeChoicesFromEnv()
		th.AssertNoErr(t, err)

		opts := &servers.CreateOpts{
			Name:      tools.RandomString("secgroup_test_", 5),
			ImageRef:  choices.ImageID,
			FlavorRef: choices.FlavorID,
		}

		s, err := servers.Create(client, opts).Extract()
		th.AssertNoErr(t, err)
		serverID = s.ID

		t.Logf("Created server %s, waiting for it to build", s.ID)
		err = servers.WaitForStatus(client, serverID, "ACTIVE", 300)
		th.AssertNoErr(t, err)

		needsDeletion = true
	}

	return serverID, needsDeletion
}
开发者ID:RomainVabre,项目名称:origin,代码行数:45,代码来源:secgroup_test.go


示例5: foreachServer

func foreachServer(client *gophercloud.ServiceClient, opts servers.ListOptsBuilder, handler func(*servers.Server) (bool, error)) error {
	pager := servers.List(client, opts)

	err := pager.EachPage(func(page pagination.Page) (bool, error) {
		s, err := servers.ExtractServers(page)
		if err != nil {
			return false, err
		}
		for _, server := range s {
			ok, err := handler(&server)
			if !ok || err != nil {
				return false, err
			}
		}
		return true, nil
	})
	return err
}
开发者ID:alex-mohr,项目名称:kubernetes,代码行数:18,代码来源:openstack.go


示例6: main

func main() {
	// step-1
	var authUsername string = "your_auth_username"
	var authPassword string = "your_auth_password"
	var authUrl string = "http://controller:5000"
	var projectName string = "your_project_id"
	var regionName string = "your_region_name"

	authOpts := gophercloud.AuthOptions{
		IdentityEndpoint: authUrl,
		Username:         authUsername,
		Password:         authPassword,
		TenantID:         projectName,
	}
	provider, _ := openstack.AuthenticatedClient(authOpts)
	client, _ := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{
		Region: regionName,
	})

	// step-2
	pager := images.ListDetail(client, images.ListOpts{})
	page, _ := pager.AllPages()
	imageList, _ := images.ExtractImages(page)
	fmt.Println(imageList)

	// step-3
	pager = flavors.ListDetail(client, flavors.ListOpts{})
	page, _ = pager.AllPages()
	flavorList, _ := flavors.ExtractFlavors(page)
	fmt.Println(flavorList)

	// step-4
	imageID := "74e6d1ec-9a08-444c-8518-4f232446386d"
	image, _ := images.Get(client, imageID).Extract()
	fmt.Println(image)

	// step-5
	flavorID := "1"
	flavor, _ := flavors.Get(client, flavorID).Extract()
	fmt.Println(flavor)

	// step-6
	instanceName := "testing"
	testingInstance, _ := servers.Create(client, servers.CreateOpts{
		Name:      instanceName,
		ImageRef:  imageID,
		FlavorRef: flavorID,
	}).Extract()
	fmt.Println(testingInstance)

	// step-7
	pager = servers.List(client, servers.ListOpts{})
	page, _ = pager.AllPages()
	serverList, _ := servers.ExtractServers(page)
	fmt.Println(serverList)

	// step-8
	servers.Delete(client, testingInstance.ID)

	// step-9
	fmt.Println("Checking for existing SSH key pair...")
	keyPairName := "demokey"
	pubKeyFile := "~/.ssh/id_rsa.pub"
	keyPairExists := false

	pager = keypairs.List(client)
	page, _ = pager.AllPages()
	keypairList, _ := keypairs.ExtractKeyPairs(page)
	for _, k := range keypairList {
		if k.Name == keyPairName {
			keyPairExists = true
			break
		}
	}

	if keyPairExists {
		fmt.Println("Keypair " + keyPairName + " already exists. Skipping import.")
	} else {
		fmt.Println("adding keypair...")
		bs, _ := ioutil.ReadFile(pubKeyFile)
		keypairs.Create(client, keypairs.CreateOpts{
			Name:      keyPairName,
			PublicKey: string(bs),
		}).Extract()
	}

	pager = keypairs.List(client)
	page, _ = pager.AllPages()
	keypairList, _ = keypairs.ExtractKeyPairs(page)
	fmt.Println(keypairList)

	// step-10
	fmt.Println("Checking for existing security group...")
	var allInOneSecurityGroup secgroups.SecurityGroup
	securityGroupName := "all-in-one"
	securityGroupExists := false

	pager = secgroups.List(client)
	page, _ = pager.AllPages()
	secgroupList, _ := secgroups.ExtractSecurityGroups(page)
//.........这里部分代码省略.........
开发者ID:Tesora,项目名称:tesora-api-site,代码行数:101,代码来源:getting_started.go


示例7: Run

func Run() error {
	var configPath string
	var commitsToFile bool
	var target string
	var verbose bool
	var showsVersion bool
	var randomDelay int

	flag.BoolVar(&commitsToFile, "w", false, "Write to file")
	flag.StringVar(&target, "t", "/etc/hosts", "Target file to write hosts")
	flag.BoolVar(&verbose, "V", false, "Verbose mode")
	flag.StringVar(&configPath, "c", "/etc/monkfish.ini", "Config path")
	flag.BoolVar(&showsVersion, "version", false, "Just show version and quit")
	flag.IntVar(&randomDelay, "random-delay", 0, "Random delay before to access OpenStack API, in second")
	flag.Parse()

	if showsVersion {
		showVersion()
	}

	loggerf := newLoggerf(verbose)

	conf := &MonkConf{}
	if err := conf.Parse(configPath); err != nil {
		return err
	}

	if randomDelay > 0 {
		hostname, _ := os.Hostname()
		ha := hash.Checksum([]byte(hostname))
		rand.Seed(time.Now().UnixNano() + int64(ha))
		delay := rand.Intn(randomDelay)
		loggerf("Sleeping in %d seconds...", delay)
		time.Sleep(time.Duration(delay) * time.Second)
	}

	auth, err := openstack.AuthenticatedClient(gophercloud.AuthOptions{
		IdentityEndpoint: conf.authUrl,
		Username:         conf.username,
		Password:         conf.password,
		TenantName:       conf.tenantName,
	})
	if err != nil {
		return err
	}
	cli, err := openstack.NewComputeV2(auth, gophercloud.EndpointOpts{Region: conf.region})
	if err != nil {
		return err
	}

	res, err := servers.List(cli, &servers.ListOpts{Status: "ACTIVE"}).AllPages()
	if err != nil {
		return err
	}
	svs, err := servers.ExtractServers(res)
	if err != nil {
		return err
	}

	var targetIo io.Writer
	if commitsToFile {
		targetIo, err = ioutil.TempFile("", "monkfish-work--")
		if err != nil {
			return err
		}
	} else {
		targetIo = os.Stdout
	}

	src, err := os.Open("/etc/hosts.base")
	if err == nil {
		data, _ := ioutil.ReadAll(src)
		targetIo.Write(data)
		targetIo.Write([]byte("\n"))
	}

	for _, i := range svs {
		if i.Name == "" {
			loggerf("skip: [%s]%s\n", i.ID, i.Name)
			continue
		}
		loggerf("name: %s\n", i.Name)
		var name string
		if conf.useOnlyHostname {
			name = strings.Split(i.Name, ".")[0]
		} else {
			name = i.Name
		}

		if wan := findWanIP(i.Addresses); wan != "" {
			fmt.Fprintf(
				targetIo,
				"%s\t\t%s.%s\n",
				wan,
				name,
				conf.domain,
			)
		}
		if lan := findLanIP(i.Addresses, conf.lanIPPrefix); lan != "" {
			fmt.Fprintf(
//.........这里部分代码省略.........
开发者ID:udzura,项目名称:monkfish,代码行数:101,代码来源:monkfish.go


示例8: ExtractServers

// ExtractServers interprets the results of a single page from a List() call, producing a slice of Server entities.
func ExtractServers(page pagination.Page) ([]os.Server, error) {
	return os.ExtractServers(page)
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:4,代码来源:delegate.go



注:本文中的github.com/rackspace/gophercloud/openstack/compute/v2/servers.ExtractServers函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang servers.Get函数代码示例发布时间:2022-05-28
下一篇:
Golang servers.Delete函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap