当前位置: 首页>>代码示例>>Golang>>正文


Golang VmrunWrapper.Stop方法代码示例

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


在下文中一共展示了VmrunWrapper.Stop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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.Stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。