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

Golang rackspace.NewComputeV2函数代码示例

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

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



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

示例1: NewRackspaceSDK

func NewRackspaceSDK(username, apiKey, SSHKeyName string) *RackspaceSDK {
	if SSHKeyName == "" {
		panic("Empty SSHKeyName of instance don't allow!")
	}
	sdk := &RackspaceSDK{
		Username:     username,
		APIKey:       apiKey,
		SSHKeyName:   SSHKeyName,
		Region:       "HKG",
		InstanceName: "kmg-RackspaceSDK-auto-build",
		ImageName:    "Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)",
		FlavorName:   "4 GB General Purpose v1",
	}
	ao := gophercloud.AuthOptions{
		Username: sdk.Username,
		APIKey:   sdk.APIKey,
	}
	provider, err := rackspace.AuthenticatedClient(ao)
	handleErr(err)
	serviceClient, err := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
		Region: sdk.Region,
	})
	handleErr(err)
	sdk.p = serviceClient
	return sdk
}
开发者ID:keysonZZZ,项目名称:kmg,代码行数:26,代码来源:SDKRackspace.go


示例2: newClient

func newClient() (*gophercloud.ServiceClient, error) {
	// Obtain credentials from the environment.
	options, err := rackspace.AuthOptionsFromEnv()
	if err != nil {
		return nil, err
	}
	options = tools.OnlyRS(options)
	region := os.Getenv("RS_REGION")

	if options.Username == "" {
		return nil, errors.New("Please provide a Rackspace username as RS_USERNAME.")
	}
	if options.APIKey == "" {
		return nil, errors.New("Please provide a Rackspace API key as RS_API_KEY.")
	}
	if region == "" {
		return nil, errors.New("Please provide a Rackspace region as RS_REGION.")
	}

	client, err := rackspace.AuthenticatedClient(options)
	if err != nil {
		return nil, err
	}

	return rackspace.NewComputeV2(client, gophercloud.EndpointOpts{
		Region: region,
	})
}
开发者ID:RomainVabre,项目名称:origin,代码行数:28,代码来源:compute_test.go


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


示例4: getComputeClient

func (rs *Rackspace) getComputeClient() (*gophercloud.ServiceClient, error) {
	client, err := rackspace.NewComputeV2(rs.provider, gophercloud.EndpointOpts{
		Region: rs.region,
	})
	if err != nil || client == nil {
		glog.Errorf("Unable to initialize nova client for region: %s", rs.region)
	}
	return client, nil
}
开发者ID:Cloven,项目名称:minikube,代码行数:9,代码来源:rackspace.go


示例5: newComputeClient

func newComputeClient() (*gophercloud.ServiceClient, error) {
	provider, err := newProvider()
	if err != nil {
		return nil, err
	}

	return rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
		Region: os.Getenv("RS_REGION"),
	})
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:10,代码来源:common.go


示例6: Instances

// Instances returns an implementation of Instances for Rackspace.
func (os *Rackspace) Instances() (cloudprovider.Instances, bool) {
	glog.V(2).Info("rackspace.Instances() called")

	compute, err := rackspace.NewComputeV2(os.provider, gophercloud.EndpointOpts{
		Region: os.region,
	})
	if err != nil {
		glog.Warningf("Failed to find compute endpoint: %v", err)
		return nil, false
	}
	glog.V(1).Info("Claiming to support Instances")

	return &Instances{compute}, true
}
开发者ID:ethernetdan,项目名称:kubernetes,代码行数:15,代码来源:rackspace.go


示例7: Get

// print list of cloud servers images to stdout
func Get(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, err := rackspace.NewComputeV2(provider, gophercloud.EndpointOpts{
		Region: region,
	})
	if err != nil {
		fmt.Println(err)
	}

	//opts3 := images.ListOpts{}
	cmdErr := images.ListDetail(serviceClient, nil).EachPage(func(page pagination.Page) (bool, error) {
		images, err := images.ExtractImages(page)
		if err != nil {
			fmt.Println(err)
		}
		// Use the page of []images.Image
		// https://github.com/rackspace/gophercloud/blob/master/openstack/compute/v2/images/results.go
		for _, i := range images {
			fmt.Println("Name: ", i.Name)
			fmt.Println("ID: ", i.ID)
			fmt.Println("Created: ", i.Created)
			fmt.Println("Updated: ", i.Updated)
			fmt.Println("MinDisk: ", i.MinDisk)
			fmt.Println("MinRAM: ", i.MinRAM)
			fmt.Println("Progress: ", i.Progress)
			fmt.Println("Status: ", i.Status)
			fmt.Println("\n")
		}
		return true, nil
	})
	if cmdErr != nil {
		fmt.Println(cmdErr)
	}
}
开发者ID:rackeric,项目名称:erack,代码行数:51,代码来源:list.go


示例8: Details

// print details of cloud servers instance to stdout
func Details(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	// server create specific options
	// check both options and arguments for server uuid
	serverid := c.Args().First()
	if c.String("uuid") != "" {
		serverid = c.String("uuid")
	}

	// 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)
	}

	// get cloud server
	s, id := servers.Get(serviceClient, serverid).Extract()
	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)
	if id != nil {
		fmt.Println(id)
	}
}
开发者ID:rackeric,项目名称:erack,代码行数:50,代码来源:details.go


示例9: Instances

// Instances returns an implementation of Instances for Rackspace.
func (os *Rackspace) Instances() (cloudprovider.Instances, bool) {
	glog.V(2).Info("rackspace.Instances() called")

	compute, err := rackspace.NewComputeV2(os.provider, gophercloud.EndpointOpts{
		Region: os.region,
	})
	if err != nil {
		glog.Warningf("Failed to find compute endpoint: %v", err)
		return nil, false
	}

	pager := flavors.ListDetail(compute, nil)

	flavor_to_resource := make(map[string]*api.NodeResources)
	err = pager.EachPage(func(page pagination.Page) (bool, error) {
		flavorList, err := flavors.ExtractFlavors(page)
		if err != nil {
			return false, err
		}
		for _, flavor := range flavorList {
			rsrc := api.NodeResources{
				Capacity: api.ResourceList{
					api.ResourceCPU:            *resource.NewMilliQuantity(int64(flavor.VCPUs*1000), resource.DecimalSI),
					api.ResourceMemory:         resource.MustParse(fmt.Sprintf("%dMi", flavor.RAM)),
					"openstack.org/disk":       resource.MustParse(fmt.Sprintf("%dG", flavor.Disk)),
					"openstack.org/rxTxFactor": *resource.NewQuantity(int64(flavor.RxTxFactor*1000), resource.DecimalSI),
					"openstack.org/swap":       resource.MustParse(fmt.Sprintf("%dMi", flavor.Swap)),
				},
			}
			flavor_to_resource[flavor.ID] = &rsrc
		}
		return true, nil
	})
	if err != nil {
		glog.Warningf("Failed to find compute flavors: %v", err)
		return nil, false
	}

	glog.V(2).Infof("Found %v compute flavors", len(flavor_to_resource))
	glog.V(1).Info("Claiming to support Instances")

	return &Instances{compute, flavor_to_resource}, true
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:44,代码来源:rackspace.go


示例10: Create

// create cloud servers instance and print out results to stdout (eg. password)
func Create(c *cli.Context) {
	// assign vars from cli args
	user := c.String("user")
	key := c.String("key")
	region := c.String("region")
	// server create specific options
	newservername := c.String("name")
	imageid := c.String("image")
	flavorid := c.String("flavor")

	// 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)
	}

	// create the cloud server
	server, err3 := servers.Create(serviceClient, servers.CreateOpts{
		Name:      newservername,
		ImageRef:  imageid,
		FlavorRef: flavorid,
	}).Extract()

	fmt.Println(server)
	if err3 != nil {
		fmt.Println(err3)
	}
}
开发者ID:rackeric,项目名称:erack,代码行数:42,代码来源:create.go


示例11: authFromScratch

func authFromScratch(ao gophercloud.AuthOptions, region, serviceType string) (*gophercloud.ServiceClient, error) {
	pc, err := rackspace.AuthenticatedClient(ao)
	if err != nil {
		return nil, err
	}
	var sc *gophercloud.ServiceClient
	switch serviceType {
	case "compute":
		sc, err = rackspace.NewComputeV2(pc, gophercloud.EndpointOpts{
			Region: region,
		})
		break
	case "object-store":
		sc, err = rackspace.NewObjectStorageV1(pc, gophercloud.EndpointOpts{
			Region: region,
		})
		break
	case "blockstorage":
		sc, err = rackspace.NewBlockStorageV1(pc, gophercloud.EndpointOpts{
			Region: region,
		})
		break
	case "network":
		sc, err = rackspace.NewNetworkV2(pc, gophercloud.EndpointOpts{
			Region: region,
		})
		break
	}
	if err != nil {
		return nil, err
	}
	if sc == nil {
		return nil, fmt.Errorf("Unable to create service client: Unknown service type: %s", serviceType)
	}
	sc.UserAgent.Prepend(util.UserAgent)
	return sc, nil
}
开发者ID:flazz,项目名称:rack,代码行数:37,代码来源:clients.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang servers.ExtractServers函数代码示例发布时间:2022-05-28
下一篇:
Golang rackspace.AuthenticatedClient函数代码示例发布时间: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