本文整理匯總了Golang中github.com/vmware/vic/pkg/vsphere/vm.VirtualMachine.Destroy方法的典型用法代碼示例。如果您正苦於以下問題:Golang VirtualMachine.Destroy方法的具體用法?Golang VirtualMachine.Destroy怎麽用?Golang VirtualMachine.Destroy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/vmware/vic/pkg/vsphere/vm.VirtualMachine
的用法示例。
在下文中一共展示了VirtualMachine.Destroy方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: deleteVM
func (d *Dispatcher) deleteVM(vm *vm.VirtualMachine, force bool) error {
defer trace.End(trace.Begin(""))
var err error
power, err := vm.PowerState(d.ctx)
if err != nil || power != types.VirtualMachinePowerStatePoweredOff {
if err != nil {
log.Warnf("Failed to get vm power status %s: %s", vm.Reference(), err)
}
if !force {
if err != nil {
return err
}
name, err := vm.Name(d.ctx)
if err != nil {
log.Errorf("VM name is not found, %s", err)
}
if name != "" {
err = errors.Errorf("VM %s is powered on", name)
} else {
err = errors.Errorf("VM %s is powered on", vm.Reference())
}
return err
}
if _, err = tasks.WaitForResult(d.ctx, func(ctx context.Context) (tasks.ResultWaiter, error) {
return vm.PowerOff(ctx)
}); err != nil {
log.Debugf("Failed to power off existing appliance for %s, try to remove anyway", err)
}
}
// get the actual folder name before we delete it
folder, err := vm.FolderName(d.ctx)
if err != nil {
log.Warnf("Failed to get actual folder name for VM. Will not attempt to delete additional data files in VM directory: %s", err)
}
_, err = tasks.WaitForResult(d.ctx, func(ctx context.Context) (tasks.ResultWaiter, error) {
return vm.Destroy(ctx)
})
if err != nil {
err = errors.Errorf("Failed to destroy vm %s: %s", vm.Reference(), err)
return err
}
if _, err = d.deleteDatastoreFiles(d.session.Datastore, folder, true); err != nil {
log.Warnf("VM path %s is not removed, %s", folder, err)
}
return nil
}