예제 #1
0
파일: status.go 프로젝트: koding/koding
// MachineStatus dials the given machine name, pings it, and returns ok or not.
// Custom type errors for any problems encountered.
func (s *Status) MachineStatus(name string) error {
	machine, err := s.MachineGetter.GetMachine(name)
	if err != nil {
		return err
	}

	// Try and ping it directly via http. This lets us know if the machine is
	// reachable, without dealing with any kite issues.
	if _, err := s.HTTPClient.Get(fmt.Sprintf("http://%s:56789/kite", machine.IP)); err != nil {
		return util.KiteErrorf(
			kiteerrortypes.MachineUnreachable,
			"Machine unreachable. host:%s, err:%s",
			machine.IP, err,
		)
	}

	if err := machine.DialOnce(); err != nil {
		return s.handleKiteErr(err)
	}

	// We have to use klient.info here, because we're trying to catch the
	// TokenIsNotValidYet error. kite.ping does not use auth, and does not show
	// that error as a result. klient.info does use auth, and doesn't reset klient
	// usage. So it seems like an okay method for this.
	//
	// In the future, we should probably add auth'd ping to klient, to avoid side
	// effects.
	if _, err := machine.Tell("klient.info"); err != nil {
		return s.handleKiteErr(err)
	}

	return nil
}
예제 #2
0
파일: remote.go 프로젝트: koding/koding
// GetValidDialedMachine calls GetValidMachine, and then dials it.
//
// Note that if you just want a dialed machine, but don't explicitly need a Valid
// machine, just get the machine and dial it yourself.
func (r *Remote) GetDialedMachine(name string) (*machine.Machine, error) {
	machine, err := r.GetValidMachine(name)
	if err != nil {
		return nil, err
	}

	if err := machine.DialOnce(); err != nil {
		return nil, err
	}

	return machine, nil
}