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

Golang vmware.VmrunWrapper类代码示例

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

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



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

示例1: Stop

// Stop tries to start all associated VMs
func Stop(
	buffer *bytes.Buffer,
	vmrun vmware.VmrunWrapper,
	config *util.LCMConfiguration) error {

	// Get all existing clones
	clones, err := getClones(vmrun, config)
	if err != nil {
		return err
	}

	util.TryWrite2Columns(buffer, 20, "Clones", fmt.Sprint(len(clones)))
	util.TryWriteln(buffer, "")
	for _, clone := range clones {
		if !clone.running {
			continue
		}
		err := vmrun.Stop(clone.path, true)
		if err != nil {
			return err
		}
		vmName := tryVMNameExtraction(clone.path)
		util.TryWrite2Columns(buffer, 20, "  Stopped Clone", vmName)
	}
	util.TryWriteln(buffer, "")

	return nil
}
开发者ID:ankoh,项目名称:vmlcm,代码行数:29,代码来源:power.go


示例2: getTemplateSnapshots

// getRunningVMPaths returns the paths of running VMs
func getTemplateSnapshots(
	vmrun vmware.VmrunWrapper,
	config *util.LCMConfiguration) ([]string, error) {
	list, err := vmrun.ListSnapshots(config.TemplatePath)
	if err != nil {
		return nil, err
	}
	lines := strings.Split(list, "\n")

	// Check if at least one line is there
	if len(lines) < 1 {
		return nil, fmt.Errorf("Failed to parse the listSnapshots command")
	}
	// Then remove the first line
	lines = lines[1:]
	var result []string

	// Now remove empty lines
	for _, line := range lines {
		if len(line) == 0 {
			continue
		}
		result = append(result, line)
	}
	return result, nil
}
开发者ID:ankoh,项目名称:vmlcm,代码行数:27,代码来源:snapshots.go


示例3: cloneUpTo

// cloneUpTo clones the template up to <<use>> times
func cloneUpTo(
	vmrun vmware.VmrunWrapper,
	config *util.LCMConfiguration,
	clones []*virtualMachine,
	use int) ([]string, error) {
	// Assert use greater zero
	if use <= 0 {
		return []string{}, nil
	}

	// First get available mac addresses
	availableAddresses := getAvailableMacAddresses(clones, config)

	// calculate how many clones need to be created
	diff := math.Max(0, float64(use-len(clones)))
	toCreate := int(math.Min(float64(len(availableAddresses)), diff))
	if toCreate <= 0 {
		return []string{}, nil
	}

	// Get snapshot for the clones
	snapshot, err := prepareTemplateSnapshot(vmrun, config)
	if err != nil {
		return nil, fmt.Errorf("Failed to prepare snapshot\n%s", err.Error())
	}
	var created []string

	// Now fire the clone command for each of the addresses
	for i := 0; i < toCreate; i++ {
		address := availableAddresses[i]
		vmID := util.MacAddressToVMId(address)
		vmName := fmt.Sprintf("%s-%s", config.Prefix, vmID)
		vmxPath := fmt.Sprintf(
			"%s%s.vmwarevm/%s.vmx",
			config.ClonesDirectory,
			vmName, vmName)

		// First create the linked clone
		err := vmrun.CloneLinked(
			config.TemplatePath,
			config.ClonesDirectory,
			vmName, snapshot)
		if err != nil {
			return nil, fmt.Errorf("Failed to clone vm %s\n%s", vmName, err.Error())
		}

		// Then configure that clone with the mac address
		err = util.UpdateVMX(vmxPath, vmxPath, address)
		if err != nil {
			return nil, fmt.Errorf("Failed to configure the linked clone %s\n%s",
				vmName, err.Error())
		}

		created = append(created, vmName)
	}
	return created, nil
}
开发者ID:ankoh,项目名称:vmlcm,代码行数:58,代码来源:clones.go


示例4: getRunningVMPaths

// getRunningVMPaths returns the paths of running VMs
func getRunningVMPaths(
	vmrun vmware.VmrunWrapper) ([]string, error) {
	list, err := vmrun.List()
	if err != nil {
		return nil, err
	}
	matches := listVMPaths.FindAllString(list, -1)
	return matches, nil
}
开发者ID:ankoh,项目名称:vmlcm,代码行数:10,代码来源:vms.go


示例5: createTemplateSnapshot

// createTemplateSnapshot creates a prefixed snapshot of the template
func createTemplateSnapshot(
	vmrun vmware.VmrunWrapper,
	config *util.LCMConfiguration) (string, error) {
	timestamp := int(time.Now().Unix())

	// Create snapshot name
	snapshotName := fmt.Sprintf("%s-%d", config.Prefix, timestamp)
	err := vmrun.Snapshot(config.TemplatePath, snapshotName)

	if err != nil {
		return "", err
	}
	return snapshotName, nil
}
开发者ID:ankoh,项目名称:vmlcm,代码行数:15,代码来源:snapshots.go


示例6: getVmrunVersion

// getVmrunVersion returns version information of the used vmrun executable
func getVmrunVersion(
	vmrun vmware.VmrunWrapper) (*vmrunVersion, error) {
	help, err := vmrun.Help()
	if err != nil {
		return nil, err
	}

	matches := helpVmrunVersion.FindStringSubmatch(help)
	if len(matches) < 3 {
		return nil, fmt.Errorf("Could not parse vmrun version information")
	}
	result := new(vmrunVersion)
	// index 0 is the whole match itself
	result.version = matches[1]
	result.build = matches[2]
	return result, nil
}
开发者ID:ankoh,项目名称:vmlcm,代码行数:18,代码来源:status.go


示例7: getRunningVMNumber

// getRunningVMNumber returns the number of running vms
func getRunningVMNumber(
	vmrun vmware.VmrunWrapper) (int, error) {
	list, err := vmrun.List()
	if err != nil {
		return 0, err
	}

	matches := listVMNumber.FindStringSubmatch(list)
	if len(matches) < 2 {
		return 0, fmt.Errorf("Could not parse vm number information")
	}
	number, err := strconv.Atoi(matches[1])
	if err != nil {
		return 0, fmt.Errorf("Could not parse regex match as integer")
	}

	return number, nil
}
开发者ID:ankoh,项目名称:vmlcm,代码行数:19,代码来源:status.go


示例8: deleteUpTo

// Deletes up to <<use>> clones
func deleteUpTo(
	vmrun vmware.VmrunWrapper,
	config *util.LCMConfiguration,
	clones []*virtualMachine,
	use int) ([]string, error) {

	// First order the clones by status
	clonesOrdered := orderClonesByRunning(clones)
	toDelete := int(math.Min(
		float64(len(clonesOrdered)),
		math.Abs(float64(len(clones)-use))))

	var deletedClones []string

	// Then shutdown target clones
	for i := 0; i < toDelete; i++ {
		clone := clones[i]

		// First try to stop the clone if it is running
		if clone.running {
			// First try a soft stop
			err := vmrun.Stop(clone.path, false)
			if err != nil {
				// then try a hard stop
				err = vmrun.Stop(clone.path, true)
				if err != nil {
					return nil, err
				}
			}
		}

		// Run Vmrun delete
		err := vmrun.Delete(clone.path)
		if err != nil {
			return nil, err
		}

		// Try to find the vmName
		vmxMatch := vmxName.FindStringSubmatch(clone.path)
		if len(vmxMatch) != 2 {
			deletedClones = append(deletedClones, clone.path)
		} else {
			vmName := strings.TrimSuffix(vmxMatch[1], ".vmx")
			deletedClones = append(deletedClones, vmName)
		}
	}

	return deletedClones, nil
}
开发者ID:ankoh,项目名称:vmlcm,代码行数:50,代码来源:clones.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang httprouter.Params类代码示例发布时间:2022-05-24
下一篇:
Golang model.Project类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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