Example #1
0
// mountFromShortcut gets the machine list and matches the users entry to a valid
// machine. Printing otherwise if unable to do so.
func (c *Command) mountFromShortcut() error {
	shortcutter := shortcut.NewMachineShortcut(c.Klient)
	machineInfo, err := shortcutter.GetMachineInfoFromShortcut(c.Options.MountName)
	switch {
	case err == shortcut.ErrMachineNotFound:
		c.Stdout.Printlnf(errormessages.MachineNotFound)
		return err
	case err != nil:
		c.Stdout.Printlnf(errormessages.GenericInternalErrorNoMsg)
		return fmt.Errorf("Failed to get list of machines on mount. err:%s", err)
	}

	c.Options.MountName = machineInfo.VMName

	var foundMountInfo bool
	for _, mountInfo := range machineInfo.Mounts {
		if mountInfo.MountName == c.Options.MountName {
			foundMountInfo = true
			c.mountInfo = mountInfo
			break
		}
	}

	if !foundMountInfo {
		c.Stdout.Printlnf(errormessages.MountNotFound)
		return fmt.Errorf("No mount found for name %q", c.Options.MountName)
	}

	return nil
}
Example #2
0
func (s *SSHCommand) Run(machine string) error {
	if !s.KeysExist() && s.Ask {
		util.MustConfirm("'ssh' command needs to create public/private rsa key pair. Continue? [Y|n]")
	}

	machine, err := shortcut.NewMachineShortcut(s.Klient).GetNameFromShortcut(machine)
	if err != nil {
		return err
	}

	userhost, port, err := s.GetSSHAddr(machine)
	if err != nil {
		return err
	}

	if err := s.PrepareForSSH(machine); err != nil {
		s.Log.Debug("PrepareForSSH returned err: %s", err)

		if strings.Contains(err.Error(), "user: unknown user") {
			return ErrCannotFindUser
		}

		// TODO: We're unable to log the meaningful error returned from klient, so we're
		// leaking possibly meaningful data here. This will be resolved once SSH gets
		// updated to the new (final) format. Fix this.
		if klientctlerrors.IsMachineNotValidYetErr(err) {
			return ErrMachineNotValidYet
		}

		if klientctlerrors.IsDialFailedErr(err) {
			return ErrRemoteDialingFailed
		}

		return ErrFailedToGetSSHKey
	}

	args := []string{
		"-i", s.PrivateKeyPath(),
		"-o", "ServerAliveInterval=300",
		"-o", "ServerAliveCountMax=3",
		"-o", "ConnectTimeout=7",
		"-o", "ConnectionAttempts=1",
		userhost,
	}

	if port != "" {
		args = append(args, "-p", port)
	}

	s.Log.Debug("SSHing with command: ssh %s", strings.Join(args, " "))
	cmd := exec.Command("ssh", args...)
	cmd.Stdin = os.Stdin
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr

	return cmd.Run()
}
Example #3
0
// getMachineFromShortcut gets the machine list and matches the users entry to a valid
// machine. Printing otherwise if unable to do so.
func (c *Command) machineFromShortcut(s string) (string, error) {
	shortcutter := shortcut.NewMachineShortcut(c.Klient)
	machineInfo, err := shortcutter.GetMachineInfoFromShortcut(s)
	switch {
	case err == shortcut.ErrMachineNotFound:
		c.Stdout.Printlnf(errormessages.MachineNotFound)
		return "", err
	case err != nil:
		c.Stdout.Printlnf(errormessages.GenericInternalErrorNoMsg)
		return "", fmt.Errorf("Failed to get list of machines on mount. err:%s", err)
	}

	return machineInfo.VMName, nil
}
Example #4
0
// findMachineName gets the machine list and matches the users entry to a valid
// machine. Printing otherwise if unable to do so.
func (c *MountCommand) findMachineName() error {
	shortcutter := shortcut.NewMachineShortcut(c.Klient)
	machineName, err := shortcutter.GetNameFromShortcut(c.Options.Name)
	switch {
	case err == shortcut.ErrMachineNotFound:
		c.printfln(MachineNotFound)
		return err
	case err != nil:
		c.printfln(GenericInternalError)
		return fmt.Errorf("Failed to get list of machines on mount. err:%s", err)
	}

	c.Options.Name = machineName

	return nil
}