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

Golang mcnutils.GenerateRandomID函数代码示例

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

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



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

示例1: Create

func (d *Driver) Create() error {
	d.KeyPairName = fmt.Sprintf("%s-%s", d.MachineName, mcnutils.GenerateRandomID())

	if err := d.resolveIds(); err != nil {
		return err
	}
	if err := d.createSSHKey(); err != nil {
		return err
	}
	if err := d.createMachine(); err != nil {
		return err
	}
	if err := d.waitForInstanceActive(); err != nil {
		return err
	}
	if d.FloatingIpPool != "" {
		if err := d.assignFloatingIp(); err != nil {
			return err
		}
	}
	if err := d.lookForIpAddress(); err != nil {
		return err
	}
	return nil
}
开发者ID:chuchengcao,项目名称:machine,代码行数:25,代码来源:openstack.go


示例2: PreCreateCheck

// PreCreateCheck does the network side validation
func (d *Driver) PreCreateCheck() error {
	client, err := d.getClient()
	if err != nil {
		return err
	}

	// Validate billing period
	log.Debug("Validating billing period")
	if d.BillingPeriod != "monthly" && d.BillingPeriod != "hourly" {
		return fmt.Errorf("Invalid billing period '%s'. Please select one of 'hourly', 'monthly'", d.BillingPeriod)
	}
	log.Debug("Selecting billing period", d.BillingPeriod)

	// Validate project id
	log.Debug("Validating project")
	if d.ProjectName != "" {
		project, err := client.GetProjectByName(d.ProjectName)
		if err != nil {
			return err
		}
		d.ProjectID = project.ID
	} else {
		projects, err := client.GetProjects()
		if err != nil {
			return err
		}

		// If there is only one project, take it
		if len(projects) == 1 {
			d.ProjectID = projects[0]
		} else if len(projects) == 0 {
			return fmt.Errorf("No Cloud project could be found. To create a new one, please visit %s", CustomerInterface)
		} else {
			// Build a list of project names to help choose one
			var projectNames []string
			for _, projectID := range projects {
				project, err := client.GetProject(projectID)
				if err != nil {
					projectNames = append(projectNames, projectID)
				} else {
					projectNames = append(projectNames, project.Name)
				}
			}

			return fmt.Errorf("Multiple Cloud project found (%s), to select one, use '--ovh-project' option", strings.Join(projectNames[:], ", "))
		}
	}
	log.Debug("Found project id ", d.ProjectID)

	// Validate region
	log.Debug("Validating region")
	regions, err := client.GetRegions(d.ProjectID)
	if err != nil {
		return err
	}
	var ok bool
	for _, region := range regions {
		if region == d.RegionName {
			ok = true
			break
		}
	}
	if ok != true {
		return fmt.Errorf("Invalid region %s. For a list of valid ovh regions, please visis %s", d.RegionName, CustomerInterface)
	}

	// Validate flavor
	log.Debug("Validating flavor")
	flavor, err := client.GetFlavorByName(d.ProjectID, d.RegionName, d.FlavorName)
	if err != nil {
		return err
	}
	d.FlavorID = flavor.ID
	log.Debug("Found flavor id ", d.FlavorID)

	// Validate image
	log.Debug("Validating image")
	image, err := client.GetImageByName(d.ProjectID, d.RegionName, d.ImageID)
	if err != nil {
		return err
	}
	d.ImageID = image.ID
	log.Debug("Found image id ", d.ImageID)

	// Use a common key or create a machine specific one
	keyPath := filepath.Join(d.StorePath, "sshkeys", d.KeyPairName)
	if len(d.KeyPairName) != 0 {
		if _, err := os.Stat(keyPath); err == nil {
			d.SSHKeyPath = keyPath
		} else {
			log.Debug("SSH key", keyPath, "does not exist. Assuming the key (", d.KeyPairName, ") is in '~/.ssh/' or in a SSH agent.")
		}
	} else {
		d.KeyPairName = fmt.Sprintf("%s-%s", d.MachineName, mcnutils.GenerateRandomID())
		d.SSHKeyPath = d.ResolveStorePath(d.KeyPairName)
	}

	return nil
}
开发者ID:yadutaf,项目名称:docker-machine-driver-ovh,代码行数:100,代码来源:driver.go


示例3: generateVMName

func generateVMName() string {
	randomID := mcnutils.TruncateID(mcnutils.GenerateRandomID())
	return fmt.Sprintf("docker-host-%s", randomID)
}
开发者ID:usmanismail,项目名称:machine,代码行数:4,代码来源:azure.go


示例4: PreCreateCheck

// PreCreateCheck does the network side validation
func (d *Driver) PreCreateCheck() error {
	client := d.getClient()

	// Validate project id
	log.Debug("Validating project")
	if d.ProjectName != "" {
		project, err := client.GetProjectByName(d.ProjectName)
		if err != nil {
			return err
		}
		d.ProjectID = project.Id
	} else {
		projects, err := client.GetProjects()
		if err != nil {
			return err
		}

		// If there is only one project, take it
		if len(projects) == 1 {
			d.ProjectID = projects[0]
		} else if len(projects) == 0 {
			return fmt.Errorf("No Cloud project could be found. To create a new one, please visit %s", CustomerInterface)
		} else {
			return fmt.Errorf("Multiple Cloud project found, to select one, use '--ovh-project' option")
		}
	}
	log.Debug("Found project id ", d.ProjectID)

	// Validate region
	log.Debug("Validating region")
	regions, err := client.GetRegions(d.ProjectID)
	if err != nil {
		return err
	}
	var ok bool
	for _, region := range regions {
		if region == d.RegionName {
			ok = true
			break
		}
	}
	if ok != true {
		return fmt.Errorf("Invalid region %s. For a list of valid ovh regions, please visis %s", d.RegionName, CustomerInterface)
	}

	// Validate flavor
	log.Debug("Validating flavor")
	flavor, err := client.GetFlavorByName(d.ProjectID, d.RegionName, d.FlavorName)
	if err != nil {
		return err
	}
	d.FlavorID = flavor.Id
	log.Debug("Found flavor id ", d.FlavorID)

	// Validate image
	log.Debug("Validating image")
	image, err := client.GetImageByName(d.ProjectID, d.RegionName, ImageName)
	if err != nil {
		return err
	}
	d.ImageID = image.Id
	log.Debug("Found image id ", d.ImageID)

	// Use a common key or create a machine specific one
	if len(d.KeyPairName) != 0 {
		d.SSHKeyPath = filepath.Join(d.StorePath, "sshkeys", d.KeyPairName)
	} else {
		d.KeyPairName = fmt.Sprintf("%s-%s", d.MachineName, mcnutils.GenerateRandomID())
	}

	return nil
}
开发者ID:thbkrkr,项目名称:docker-machine-driver-ovh,代码行数:73,代码来源:driver.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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