Example #1
0
func (cmd *disconnect) Disconnect(ctx context.Context, host *object.HostSystem) error {
	task, err := host.Disconnect(ctx)
	if err != nil {
		return err
	}

	logger := cmd.ProgressLogger(fmt.Sprintf("%s disconnecting... ", host.InventoryPath))
	defer logger.Wait()

	_, err = task.WaitForResult(ctx, logger)
	return err
}
Example #2
0
// vSphereRemoveHost disconnects an ESXi host from the
// vCenter server and then removes it.
func vSphereRemoveHost(ctx context.Context, obj *object.HostSystem) error {
	disconnectTask, err := obj.Disconnect(ctx)
	if err != nil {
		return err
	}

	if err := disconnectTask.Wait(ctx); err != nil {
		return err
	}

	destroyTask, err := obj.Destroy(ctx)
	if err != nil {
		return err
	}

	return destroyTask.Wait(ctx)
}