本文整理汇总了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
}
示例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
}