Example #1
0
File: ui.go Project: kjplatz/vic
func (p *Plugin) Remove(cli *cli.Context) error {
	var err error
	if err = p.processRemoveParams(); err != nil {
		return err
	}
	if p.Debug.Debug > 0 {
		log.SetLevel(log.DebugLevel)
		trace.Logger.Level = log.DebugLevel
	}

	if len(cli.Args()) > 0 {
		log.Error("Remove cannot continue: invalid CLI arguments")
		log.Errorf("Unknown argument: %s", cli.Args()[0])
		return errors.New("invalid CLI arguments")
	}

	if p.Force {
		log.Info("Ignoring --force")
	}

	log.Infof("### Removing UI Plugin ####")

	pInfo := &plugin.Info{
		Key: p.Key,
	}

	pl, err := plugin.NewPluginator(context.TODO(), p.Target.URL, pInfo)
	if err != nil {
		return err
	}
	reg, err := pl.IsRegistered(pInfo.Key)
	if err != nil {
		return err
	}
	if reg {
		log.Infof("Found target plugin: %s", pInfo.Key)
	} else {
		msg := fmt.Sprintf("failed to find target plugin (%s)", pInfo.Key)
		log.Errorf("Remove failed: %s", msg)
		return errors.New(msg)
	}

	log.Info("Removing plugin")
	err = pl.Unregister(pInfo.Key)
	if err != nil {
		return err
	}

	reg, err = pl.IsRegistered(pInfo.Key)
	if err != nil {
		return err
	}
	if reg {
		msg := fmt.Sprintf("post-remove check found %s still registered", pInfo.Key)
		log.Errorf("Remove failed: %s", msg)
		return errors.New(msg)
	}

	log.Info("Removed UI plugin")
	return nil
}
Example #2
0
File: ui.go Project: kjplatz/vic
func (p *Plugin) Install(cli *cli.Context) error {
	var err error
	if err = p.processInstallParams(); err != nil {
		return err
	}

	if p.Debug.Debug > 0 {
		log.SetLevel(log.DebugLevel)
		trace.Logger.Level = log.DebugLevel
	}

	if len(cli.Args()) > 0 {
		log.Error("Install cannot continue: invalid CLI arguments")
		log.Errorf("Unknown argument: %s", cli.Args()[0])
		return errors.New("invalid CLI arguments")
	}

	log.Infof("### Installing UI Plugin ####")

	pInfo := &plugin.Info{
		Company:               p.Company,
		Key:                   p.Key,
		Name:                  p.Name,
		ServerThumbprint:      p.ServerThumbprint,
		ShowInSolutionManager: !p.HideInSolutionManager,
		Summary:               p.Summary,
		Type:                  "vsphere-client-serenity",
		URL:                   p.URL,
		Version:               p.Version,
	}

	pl, err := plugin.NewPluginator(context.TODO(), p.Target.URL, pInfo)
	if err != nil {
		return err
	}

	reg, err := pl.IsRegistered(pInfo.Key)
	if err != nil {
		return err
	}
	if reg {
		if p.Force {
			log.Info("Removing existing plugin to force install")
			err = pl.Unregister(pInfo.Key)
			if err != nil {
				return err
			}
			log.Info("Removed existing plugin")
		} else {
			msg := fmt.Sprintf("plugin (%s) is already registered", pInfo.Key)
			log.Errorf("Install failed: %s", msg)
			return errors.New(msg)
		}
	}

	log.Info("Installing plugin")
	err = pl.Register()
	if err != nil {
		return err
	}

	reg, err = pl.IsRegistered(pInfo.Key)
	if err != nil {
		return err
	}
	if !reg {
		msg := fmt.Sprintf("post-install check failed to find %s registered", pInfo.Key)
		log.Errorf("Install failed: %s", msg)
		return errors.New(msg)
	}

	log.Info("Installed UI plugin")
	return nil
}