本文整理汇总了Golang中github.com/ankoh/vmlcm/vmware.VmrunWrapper.Delete方法的典型用法代码示例。如果您正苦于以下问题:Golang VmrunWrapper.Delete方法的具体用法?Golang VmrunWrapper.Delete怎么用?Golang VmrunWrapper.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ankoh/vmlcm/vmware.VmrunWrapper
的用法示例。
在下文中一共展示了VmrunWrapper.Delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}