Пример #1
0
func NewManager(c *vim25.Client) *Manager {
	m := Manager{
		object.NewCommon(c, *c.ServiceContent.ViewManager),
	}

	return &m
}
Пример #2
0
func (cmd *rename) Run(ctx context.Context, f *flag.FlagSet) error {
	if f.NArg() != 2 {
		return flag.ErrHelp
	}

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

	objs, err := cmd.ManagedObjects(ctx, f.Args()[:1])
	if err != nil {
		return err
	}

	task, err := object.NewCommon(c, objs[0]).Rename(ctx, f.Arg(1))
	if err != nil {
		return err
	}

	logger := cmd.ProgressLogger(fmt.Sprintf("renaming %s... ", objs[0]))
	_, err = task.WaitForResult(ctx, logger)
	logger.Wait()

	return err
}
Пример #3
0
func (cmd *destroy) Run(ctx context.Context, f *flag.FlagSet) error {
	if f.NArg() == 0 {
		return flag.ErrHelp
	}

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

	objs, err := cmd.ManagedObjects(ctx, f.Args())
	if err != nil {
		return err
	}

	for _, obj := range objs {
		task, err := object.NewCommon(c, obj).Destroy(ctx)
		if err != nil {
			return err
		}

		logger := cmd.ProgressLogger(fmt.Sprintf("destroying %s... ", obj))
		_, err = task.WaitForResult(ctx, logger)
		logger.Wait()
		if err != nil {
			return err
		}
	}

	return nil
}
Пример #4
0
func NewManager(c *vim25.Client) *Manager {
	m := Manager{
		Common: object.NewCommon(c, *c.ServiceContent.EventManager),

		eventCategory:   make(map[string]string),
		eventCategoryMu: new(sync.Mutex),
		maxObjects:      10,
	}

	return &m
}
Пример #5
0
func (m Manager) AssignmentManager(ctx context.Context) (*AssignmentManager, error) {
	var mlm mo.LicenseManager

	err := m.Properties(ctx, m.Reference(), []string{"licenseAssignmentManager"}, &mlm)
	if err != nil {
		return nil, err
	}

	if mlm.LicenseAssignmentManager == nil {
		return nil, object.ErrNotSupported
	}

	am := AssignmentManager{
		object.NewCommon(m.Client(), *mlm.LicenseAssignmentManager),
	}

	return &am, nil
}
Пример #6
0
Файл: vm.go Проект: vmware/vic
// FixInvalidState fix vm invalid state issue through unregister & register
func (vm *VirtualMachine) FixInvalidState(ctx context.Context) error {
	log.Debugf("Fix invalid state VM: %s", vm.Reference())
	folders, err := vm.Session.Datacenter.Folders(ctx)
	if err != nil {
		log.Errorf("Unable to get vm folder: %s", err)
		return err
	}

	properties := []string{"config.files", "summary.config", "summary.runtime", "resourcePool", "parentVApp"}
	log.Debugf("Get vm properties %s", properties)
	var mvm mo.VirtualMachine
	if err = vm.Properties(ctx, vm.Reference(), properties, &mvm); err != nil {
		log.Errorf("Unable to get vm properties: %s", err)
		return err
	}

	name := mvm.Summary.Config.Name
	log.Debugf("Unregister VM %s", name)
	if err := vm.Unregister(ctx); err != nil {
		log.Errorf("Unable to unregister vm %q: %s", name, err)
		return err
	}

	task, err := vm.registerVM(ctx, mvm.Config.Files.VmPathName, name, mvm.ParentVApp, mvm.ResourcePool, mvm.Summary.Runtime.Host, folders.VmFolder)
	if err != nil {
		log.Errorf("Unable to register VM %q back: %s", name, err)
		return err
	}
	info, err := task.WaitForResult(ctx, nil)
	if err != nil {
		return err
	}
	// re-register vm will change vm reference, so reset the object reference here
	if info.Error != nil {
		return errors.New(info.Error.LocalizedMessage)
	}

	// set new registered vm attribute back
	newRef := info.Result.(types.ManagedObjectReference)
	common := object.NewCommon(vm.Vim25(), newRef)
	common.InventoryPath = vm.InventoryPath
	vm.Common = common
	return nil
}