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

Golang gophercloud.CloudServersProvider类代码示例

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

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



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

示例1: createServer

// createServer creates a new server in a manner compatible with acceptance testing.
// In particular, it ensures that the name of the server always starts with "ACPTTEST--",
// which the delete servers acceptance test relies on to identify servers to delete.
// Passing in empty image and flavor references will force the use of reasonable defaults.
// An empty name string will result in a dynamically created name prefixed with "ACPTTEST--".
// A blank admin password will cause a password to be automatically generated; however,
// at present no means of recovering this password exists, as no acceptance tests yet require
// this data.
func createServer(servers gophercloud.CloudServersProvider, imageRef, flavorRef, name, adminPass string) (string, error) {
	if imageRef == "" {
		imageRef = aSuitableImage(servers)
	}

	if flavorRef == "" {
		flavorRef = aSuitableFlavor(servers)
	}

	if len(name) < 1 {
		name = randomString("ACPTTEST", 16)
	}

	if (len(name) < 8) || (name[0:8] != "ACPTTEST") {
		name = fmt.Sprintf("ACPTTEST--%s", name)
	}

	newServer, err := servers.CreateServer(gophercloud.NewServer{
		Name:      name,
		ImageRef:  imageRef,
		FlavorRef: flavorRef,
		AdminPass: adminPass,
	})

	if err != nil {
		return "", err
	}

	return newServer.Id, nil
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:38,代码来源:libargs.go


示例2: withServer

func withServer(api gophercloud.CloudServersProvider, f func(string)) {
	id, err := createServer(api, "", "", "", "")
	if err != nil {
		panic(err)
	}

	for {
		s, err := api.ServerById(id)
		if err != nil {
			panic(err)
		}
		if s.Status == "ACTIVE" {
			break
		}
		time.Sleep(10 * time.Second)
	}

	f(id)

	// I've learned that resizing an instance can fail if a delete request
	// comes in prior to its completion.  This ends up leaving the server
	// in an error state, and neither the resize NOR the delete complete.
	// This is a bug in OpenStack, as far as I'm concerned, but thankfully,
	// there's an easy work-around -- just wait for your server to return to
	// active state first!
	waitForServerState(api, id, "ACTIVE")
	err = api.DeleteServerById(id)
	if err != nil {
		panic(err)
	}
}
开发者ID:GeertJohan,项目名称:gophercloud,代码行数:31,代码来源:09-resize-server.go


示例3: SSHAddress

// SSHAddress returns a function that can be given to the SSH communicator
// for determining the SSH address based on the server AccessIPv4 setting..
func SSHAddress(csp gophercloud.CloudServersProvider, port int) func(multistep.StateBag) (string, error) {
	return func(state multistep.StateBag) (string, error) {
		s := state.Get("server").(*gophercloud.Server)

		if ip := state.Get("access_ip").(gophercloud.FloatingIp); ip.Ip != "" {
			return fmt.Sprintf("%s:%d", ip.Ip, port), nil
		}

		ip_pools, err := s.AllAddressPools()
		if err != nil {
			return "", errors.New("Error parsing SSH addresses")
		}
		for pool, addresses := range ip_pools {
			if pool != "" {
				for _, address := range addresses {
					if address.Addr != "" && address.Version == 4 {
						return fmt.Sprintf("%s:%d", address.Addr, port), nil
					}
				}
			}
		}

		serverState, err := csp.ServerById(s.Id)

		if err != nil {
			return "", err
		}

		state.Put("server", serverState)
		time.Sleep(1 * time.Second)

		return "", errors.New("couldn't determine IP address for server")
	}
}
开发者ID:JNPRAutomate,项目名称:packer,代码行数:36,代码来源:ssh.go


示例4: tryLinksOnly

func tryLinksOnly(api gophercloud.CloudServersProvider) {
	servers, err := api.ListServersLinksOnly()
	if err != nil {
		panic(err)
	}

	if !*quiet {
		fmt.Println("Id,Name")
		for _, s := range servers {
			if s.AccessIPv4 != "" {
				panic("IPv4 not expected")
			}

			if s.Status != "" {
				panic("Status not expected")
			}

			if s.Progress != 0 {
				panic("Progress not expected")
			}

			fmt.Printf("%s,\"%s\"\n", s.Id, s.Name)
		}
	}
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:25,代码来源:02-list-servers.go


示例5: ServerStateRefreshFunc

// ServerStateRefreshFunc returns a StateRefreshFunc that is used to watch
// an openstacn server.
func ServerStateRefreshFunc(csp gophercloud.CloudServersProvider, s *gophercloud.Server) StateRefreshFunc {
	return func() (interface{}, string, int, error) {
		resp, err := csp.ServerById(s.Id)
		if err != nil {
			log.Printf("Error on ServerStateRefresh: %s", err)
			return nil, "", 0, err
		}

		return resp, resp.Status, resp.Progress, nil
	}
}
开发者ID:ramonvanalteren,项目名称:packer,代码行数:13,代码来源:server.go


示例6: WaitForServerState

func WaitForServerState(api gophercloud.CloudServersProvider, id string) resource.StateRefreshFunc {

	return func() (interface{}, string, error) {
		s, err := api.ServerById(id)
		if err != nil {
			return nil, "", err
		}

		return nil, s.Status, nil

	}
}
开发者ID:haklop,项目名称:terraform,代码行数:12,代码来源:resource_openstack_compute.go


示例7: waitForImageState

// waitForImageState polls, every 10 seconds, for a given image to appear in the indicated state.
// This call will block forever if it never appears in the desired state, so if a timeout is required,
// make sure to call this function in a goroutine.
func waitForImageState(api gophercloud.CloudServersProvider, id, state string) error {
	for {
		s, err := api.ImageById(id)
		if err != nil {
			return err
		}
		if s.Status == state {
			return nil
		}
		time.Sleep(10 * time.Second)
	}
	panic("Impossible")
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:16,代码来源:libargs.go


示例8: tryAddressesByNetwork

func tryAddressesByNetwork(networkLabel string, id string, api gophercloud.CloudServersProvider) {
	log("Getting list of addresses on", networkLabel, "network...")
	network, err := api.ListAddressesByNetwork(id, networkLabel)
	if (err != nil) && (err != gophercloud.WarnUnauthoritative) {
		panic(err)
	}
	if err == gophercloud.WarnUnauthoritative {
		log("Uh oh -- got a response back, but it's not authoritative for some reason.")
	}
	for _, addr := range network[networkLabel] {
		log("Address:", addr.Addr, "  IPv", addr.Version)
	}
}
开发者ID:GeertJohan,项目名称:gophercloud,代码行数:13,代码来源:14-list-addresses.go


示例9: 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


示例10: tryAllAddresses

func tryAllAddresses(id string, api gophercloud.CloudServersProvider) {
	log("Getting list of all addresses...")
	addresses, err := api.ListAddresses(id)
	if (err != nil) && (err != gophercloud.WarnUnauthoritative) {
		panic(err)
	}
	if err == gophercloud.WarnUnauthoritative {
		log("Uh oh -- got a response back, but it's not authoritative for some reason.")
	}
	if !*quiet {
		fmt.Println("Addresses:")
		fmt.Printf("%+v\n", addresses)
	}
}
开发者ID:GeertJohan,项目名称:gophercloud,代码行数:14,代码来源:14-list-addresses.go


示例11: WaitForImage

// WaitForImage waits for the given Image ID to become ready.
func WaitForImage(csp gophercloud.CloudServersProvider, imageId string) error {
	for {
		image, err := csp.ImageById(imageId)
		if err != nil {
			return err
		}

		if image.Status == "ACTIVE" {
			return nil
		}

		log.Printf("Waiting for image creation status: %s (%d%%)", image.Status, image.Progress)
		time.Sleep(2 * time.Second)
	}
}
开发者ID:JNPRAutomate,项目名称:packer,代码行数:16,代码来源:step_create_image.go


示例12: resizeAcceptTest

// Perform the resize test, but accept the resize request.
func resizeAcceptTest(api gophercloud.CloudServersProvider, done chan bool) {
	withServer(api, func(id string) {
		newFlavorId := findAlternativeFlavor()
		err := api.ResizeServer(id, randomString("ACPTTEST", 24), newFlavorId, "")
		if err != nil {
			panic(err)
		}

		waitForServerState(api, id, "VERIFY_RESIZE")

		err = api.ConfirmResize(id)
		if err != nil {
			panic(err)
		}
	})
	done <- true
}
开发者ID:GeertJohan,项目名称:gophercloud,代码行数:18,代码来源:09-resize-server.go


示例13: ServerStateRefreshFunc

// ServerStateRefreshFunc returns a StateRefreshFunc that is used to watch
// an openstack server.
func ServerStateRefreshFunc(csp gophercloud.CloudServersProvider, s *gophercloud.Server) StateRefreshFunc {
	return func() (interface{}, string, int, error) {
		resp, err := csp.ServerById(s.Id)
		if err != nil {
			urce, ok := err.(*perigee.UnexpectedResponseCodeError)
			if ok && (urce.Actual == 404) {
				log.Printf("404 on ServerStateRefresh, returning DELETED")

				return nil, "DELETED", 0, nil
			} else {
				log.Printf("Error on ServerStateRefresh: %s", err)
				return nil, "", 0, err
			}
		}
		return resp, resp.Status, resp.Progress, nil
	}
}
开发者ID:JNPRAutomate,项目名称:packer,代码行数:19,代码来源:server.go


示例14: aSuitableImage

// aSuitableImage finds a minimal image for use in dynamically creating servers.
// If none can be found, this function will panic.
func aSuitableImage(api gophercloud.CloudServersProvider) string {
	images, err := api.ListImages()
	if err != nil {
		panic(err)
	}

	// TODO(sfalvo):
	// Works for Rackspace, might not work for your provider!
	// Need to figure out why ListImages() provides 0 values for
	// Ram and Disk fields.
	//
	// Until then, just return Ubuntu 12.04 LTS.
	for i := 0; i < len(images); i++ {
		if strings.Contains(images[i].Name, "Ubuntu 12.04 LTS") {
			return images[i].Id
		}
	}
	panic("Image for Ubuntu 12.04 LTS not found.")
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:21,代码来源:libargs.go


示例15: aSuitableImage

// aSuitableImage finds a minimal image for use in dynamically creating servers.
// If none can be found, this function will panic.
func aSuitableImage(api gophercloud.CloudServersProvider) string {
	images, err := api.ListImages()
	if err != nil {
		panic(err)
	}

	// TODO(sfalvo):
	// Works for Rackspace, might not work for your provider!
	// Need to figure out why ListImages() provides 0 values for
	// Ram and Disk fields.
	//
	// Until then, just return Ubuntu 12.04 LTS.
	for i := 0; i < len(images); i++ {
		if images[i].Id == "23b564c9-c3e6-49f9-bc68-86c7a9ab5018" {
			return images[i].Id
		}
	}
	panic("Image 23b564c9-c3e6-49f9-bc68-86c7a9ab5018 (Ubuntu 12.04 LTS) not found.")
}
开发者ID:philips,项目名称:gophercloud,代码行数:21,代码来源:libargs.go


示例16: aSuitableFlavor

// aSuitableFlavor finds the minimum flavor capable of running the test image
// chosen by aSuitableImage.  If none can be found, this function will panic.
func aSuitableFlavor(api gophercloud.CloudServersProvider) string {
	flavors, err := api.ListFlavors()
	if err != nil {
		panic(err)
	}

	// TODO(sfalvo):
	// Works for Rackspace, might not work for your provider!
	// Need to figure out why ListFlavors() provides 0 values for
	// Ram and Disk fields.
	//
	// Until then, just return Ubuntu 12.04 LTS.
	for i := 0; i < len(flavors); i++ {
		if flavors[i].Id == "2" {
			return flavors[i].Id
		}
	}
	panic("Flavor 2 (512MB 1-core 20GB machine) not found.")
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:21,代码来源:libargs.go


示例17: SSHAddress

// SSHAddress returns a function that can be given to the SSH communicator
// for determining the SSH address based on the server AccessIPv4 setting..
func SSHAddress(csp gophercloud.CloudServersProvider, port int) func(multistep.StateBag) (string, error) {
	return func(state multistep.StateBag) (string, error) {
		for j := 0; j < 2; j++ {
			s := state.Get("server").(*gophercloud.Server)
			if s.AccessIPv4 != "" {
				return fmt.Sprintf("%s:%d", s.AccessIPv4, port), nil
			}
			serverState, err := csp.ServerById(s.Id)

			if err != nil {
				return "", err
			}

			state.Put("server", serverState)
			time.Sleep(1 * time.Second)
		}

		return "", errors.New("couldn't determine IP address for server")
	}
}
开发者ID:prognostikos,项目名称:packer,代码行数:22,代码来源:ssh.go


示例18: 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


示例19: tryAllAddresses

func tryAllAddresses(id string, api gophercloud.CloudServersProvider) {
	log("Getting the server instance")
	s, err := api.ServerById(id)
	if err != nil {
		panic(err)
	}

	log("Getting the complete set of pools")
	ps, err := s.AllAddressPools()
	if err != nil {
		panic(err)
	}

	log("Listing IPs for each pool")
	for k, v := range ps {
		log(fmt.Sprintf("  Pool %s", k))
		for _, a := range v {
			log(fmt.Sprintf("    IP: %s, Version: %d", a.Addr, a.Version))
		}
	}
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:21,代码来源:19-list-addresses-0.1.go


示例20: getServerByName

func getServerByName(api gophercloud.CloudServersProvider, name string) (*gophercloud.Server, error) {
	filter := url.Values{}
	filter.Set("name", fmt.Sprintf("^%s$", regexp.QuoteMeta(name)))
	filter.Set("status", "ACTIVE")

	servers, err := api.ListServersByFilter(filter)
	if err != nil {
		return nil, err
	}

	if len(servers) == 0 {
		return nil, ErrServerNotFound
	} else if len(servers) > 1 {
		return nil, ErrMultipleServersFound
	}

	return &servers[0], nil
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:18,代码来源:openstack.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang gophercloud.EndpointOpts类代码示例发布时间:2022-05-28
下一篇:
Golang gophercloud.AuthOptions类代码示例发布时间: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