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


Golang object.Task类代码示例

本文整理汇总了Golang中github.com/vmware/govmomi/object.Task的典型用法代码示例。如果您正苦于以下问题:Golang Task类的具体用法?Golang Task怎么用?Golang Task使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Task类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Run

func (cmd *power) Run(f *flag.FlagSet) error {
	vms, err := cmd.VirtualMachines(f.Args())
	if err != nil {
		return err
	}

	for _, vm := range vms {
		var task *object.Task

		switch {
		case cmd.On:
			fmt.Fprintf(cmd, "Powering on %s... ", vm.Reference())
			task, err = vm.PowerOn(context.TODO())
		case cmd.Off:
			fmt.Fprintf(cmd, "Powering off %s... ", vm.Reference())
			task, err = vm.PowerOff(context.TODO())
		case cmd.Reset:
			fmt.Fprintf(cmd, "Reset %s... ", vm.Reference())
			task, err = vm.Reset(context.TODO())
		case cmd.Suspend:
			fmt.Fprintf(cmd, "Suspend %s... ", vm.Reference())
			task, err = vm.Suspend(context.TODO())
		case cmd.Reboot:
			fmt.Fprintf(cmd, "Reboot guest %s... ", vm.Reference())
			err = vm.RebootGuest(context.TODO())

			if err != nil && cmd.Force && isToolsUnavailable(err) {
				task, err = vm.Reset(context.TODO())
			}
		case cmd.Shutdown:
			fmt.Fprintf(cmd, "Shutdown guest %s... ", vm.Reference())
			err = vm.ShutdownGuest(context.TODO())

			if err != nil && cmd.Force && isToolsUnavailable(err) {
				task, err = vm.PowerOff(context.TODO())
			}
		}

		if err != nil {
			return err
		}

		if task != nil {
			err = task.Wait(context.TODO())
		}
		if err == nil {
			fmt.Fprintf(cmd, "OK\n")
			continue
		}

		if cmd.Force {
			fmt.Fprintf(cmd, "Error: %s\n", err)
			continue
		}

		return err
	}

	return nil
}
开发者ID:hickeng,项目名称:govmomi,代码行数:60,代码来源:power.go

示例2: Run

func (cmd *revert) Run(ctx context.Context, f *flag.FlagSet) error {
	if f.NArg() > 1 {
		return flag.ErrHelp
	}

	vm, err := cmd.VirtualMachine()
	if err != nil {
		return err
	}

	if vm == nil {
		return flag.ErrHelp
	}

	var task *object.Task

	if f.NArg() == 1 {
		task, err = vm.RevertToSnapshot(ctx, f.Arg(0), cmd.suppressPowerOn)
	} else {
		task, err = vm.RevertToCurrentSnapshot(ctx, cmd.suppressPowerOn)
	}

	if err != nil {
		return err
	}

	return task.Wait(ctx)
}
开发者ID:vmware,项目名称:vic,代码行数:28,代码来源:revert.go

示例3: Run

func (cmd *massSnapshotCreate) Run(ctx context.Context, f *flag.FlagSet) error {
	if f.NArg() != 1 {
		return flag.ErrHelp
	}

	_, err := cmd.Client()
	if err != nil {
		return err
	}

	vms, err := cmd.VirtualMachines(f.Args())
	if err != nil {
		if _, ok := err.(*find.NotFoundError); ok {
			// Continue with empty VM slice
		} else {
			return err
		}
	}

	var t *object.Task
	//refs := make([]types.ManagedObjectReference, 0, len(vms))
	for _, vm := range vms {
		fmt.Printf("Making a snapshot")
		t, err = vm.CreateSnapshot(ctx, "mysnapshot", "description", cmd.memory, cmd.quiesce)
		if err != nil {
			return err
		}
		t.Wait(ctx)
		//refs = append(refs, vm.Reference())
	}
	return nil
}
开发者ID:frapposelli,项目名称:govmomi,代码行数:32,代码来源:create.go

示例4: Run

func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error {
	if f.NArg() != 1 {
		return flag.ErrHelp
	}

	vm, err := cmd.VirtualMachine()
	if err != nil {
		return err
	}

	if vm == nil {
		return flag.ErrHelp
	}

	var task *object.Task

	if f.Arg(0) == "*" {
		task, err = vm.RemoveAllSnapshot(ctx, &cmd.consolidate)
	} else {
		task, err = vm.RemoveSnapshot(ctx, f.Arg(0), cmd.recursive, &cmd.consolidate)
	}

	if err != nil {
		return err
	}

	return task.Wait(ctx)
}
开发者ID:frapposelli,项目名称:govmomi,代码行数:28,代码来源:remove.go

示例5: Run

func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error {
	args := f.Args()
	if len(args) == 0 {
		return errors.New("missing operand")
	}

	c, err := cmd.Client()
	if err != nil {
		return err
	}

	var dc *object.Datacenter
	dc, err = cmd.Datacenter()
	if err != nil {
		return err
	}

	if cmd.isNamespace {
		path := args[0]

		nm := object.NewDatastoreNamespaceManager(c)
		err = nm.DeleteDirectory(ctx, dc, path)
	} else {
		var path string
		var task *object.Task

		// TODO(PN): Accept multiple args
		path, err = cmd.DatastorePath(args[0])
		if err != nil {
			return err
		}

		m := object.NewFileManager(c)
		task, err = m.DeleteDatastoreFile(ctx, path, dc)
		if err != nil {
			return err
		}

		err = task.Wait(ctx)
	}

	if err != nil {
		if types.IsFileNotFound(err) && cmd.force {
			// Ignore error
			return nil
		}
	}

	return err
}
开发者ID:hmahmood,项目名称:govmomi,代码行数:50,代码来源:rm.go

示例6: Mark

func (cmd *mark) Mark(ctx context.Context, ss *object.HostStorageSystem, uuid string) error {
	var err error
	var task *object.Task

	if cmd.ssd != nil {
		if *cmd.ssd {
			task, err = ss.MarkAsSsd(ctx, uuid)
		} else {
			task, err = ss.MarkAsNonSsd(ctx, uuid)
		}

		if err != nil {
			return err
		}

		err = task.Wait(ctx)
		if err != nil {
			return err
		}
	}

	if cmd.local != nil {
		if *cmd.local {
			task, err = ss.MarkAsLocal(ctx, uuid)
		} else {
			task, err = ss.MarkAsNonLocal(ctx, uuid)
		}

		if err != nil {
			return err
		}

		err = task.Wait(ctx)
		if err != nil {
			return err
		}
	}

	return nil
}
开发者ID:vmware,项目名称:vic,代码行数:40,代码来源:mark.go

示例7: Run

func (cmd *power) Run(ctx context.Context, f *flag.FlagSet) error {
	vapps, err := cmd.VirtualApps(f.Args())
	if err != nil {
		return err
	}

	for _, vapp := range vapps {
		var task *object.Task

		switch {
		case cmd.On:
			fmt.Fprintf(cmd, "Powering on %s... ", vapp.Reference())
			task, err = vapp.PowerOnVApp_Task(ctx)
		case cmd.Off:
			fmt.Fprintf(cmd, "Powering off %s... ", vapp.Reference())
			task, err = vapp.PowerOffVApp_Task(ctx, cmd.Force)
		case cmd.Suspend:
			fmt.Fprintf(cmd, "Suspend %s... ", vapp.Reference())
			task, err = vapp.SuspendVApp_Task(ctx)
		}

		if err != nil {
			return err
		}

		if task != nil {
			err = task.Wait(ctx)
		}
		if err == nil {
			fmt.Fprintf(cmd, "OK\n")
			continue
		}

		return err
	}

	return nil
}
开发者ID:vmware,项目名称:vic,代码行数:38,代码来源:power.go

示例8: setupVirtualMachine


//.........这里部分代码省略.........
				ipSetting.SubnetMask = subnetMask
			}

			ipv6Spec := &types.CustomizationIPSettingsIpV6AddressSpec{}
			if network.ipv6Address == "" {
				ipv6Spec.Ip = []types.BaseCustomizationIpV6Generator{
					&types.CustomizationDhcpIpV6Generator{},
				}
			} else {
				log.Printf("[DEBUG] ipv6 gateway: %v\n", network.ipv6Gateway)
				log.Printf("[DEBUG] ipv6 address: %v\n", network.ipv6Address)
				log.Printf("[DEBUG] ipv6 prefix length: %v\n", network.ipv6PrefixLength)

				ipv6Spec.Ip = []types.BaseCustomizationIpV6Generator{
					&types.CustomizationFixedIpV6{
						IpAddress:  network.ipv6Address,
						SubnetMask: int32(network.ipv6PrefixLength),
					},
				}
				ipv6Spec.Gateway = []string{network.ipv6Gateway}
			}
			ipSetting.IpV6Spec = ipv6Spec

			// network config
			config := types.CustomizationAdapterMapping{
				Adapter: ipSetting,
			}
			networkConfigs = append(networkConfigs, config)
		}
	}
	log.Printf("[DEBUG] network devices: %v", networkDevices)
	log.Printf("[DEBUG] network configs: %v", networkConfigs)

	var task *object.Task
	if vm.template == "" {
		var mds mo.Datastore
		if err = datastore.Properties(context.TODO(), datastore.Reference(), []string{"name"}, &mds); err != nil {
			return err
		}
		log.Printf("[DEBUG] datastore: %#v", mds.Name)
		scsi, err := object.SCSIControllerTypes().CreateSCSIController("scsi")
		if err != nil {
			log.Printf("[ERROR] %s", err)
		}

		configSpec.DeviceChange = append(configSpec.DeviceChange, &types.VirtualDeviceConfigSpec{
			Operation: types.VirtualDeviceConfigSpecOperationAdd,
			Device:    scsi,
		})

		configSpec.Files = &types.VirtualMachineFileInfo{VmPathName: fmt.Sprintf("[%s]", mds.Name)}

		task, err = folder.CreateVM(context.TODO(), configSpec, resourcePool, nil)
		if err != nil {
			log.Printf("[ERROR] %s", err)
		}

		err = task.Wait(context.TODO())
		if err != nil {
			log.Printf("[ERROR] %s", err)
		}

	} else {

		relocateSpec, err := buildVMRelocateSpec(resourcePool, datastore, template, vm.linkedClone, vm.hardDisks[0].initType)
		if err != nil {
开发者ID:ack,项目名称:terraform,代码行数:67,代码来源:resource_vsphere_virtual_machine.go


注:本文中的github.com/vmware/govmomi/object.Task类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。