Example #1
0
func CreateMachineForUser(m *models.Machine, u *models.User) error {
	m.Users = []models.MachineUser{
		{Id: u.ObjectId, Sudo: true, Owner: true},
	}

	return CreateMachine(m)
}
Example #2
0
func (q *Queue) Check(s *provider.Stacker) error {
	var m models.Machine

	err := q.FetchProvider(s.Provider.Name, &m)
	if err != nil {
		// do not show an error if the query didn't find anything, that
		// means there is no such a document, which we don't care
		if err == mgo.ErrNotFound {
			return nil
		}

		q.Log.Debug("no running machines for %q provider found", s.Provider.Name)

		return fmt.Errorf("check %q provider error: %s", s.Provider.Name, err)
	}

	req := &kite.Request{
		Method: "internal",
	}

	if u := m.Owner(); u != nil {
		req.Username = u.Username
	}

	ctx := request.NewContext(context.Background(), req)

	bm, err := s.BuildBaseMachine(ctx, &m)
	if err != nil {
		return err
	}

	machine, err := s.BuildMachine(ctx, bm)
	if err != nil {
		return err
	}

	switch err := q.CheckUsage(s.Provider.Name, machine, bm, ctx); err {
	case nil:
		return nil
	case kite.ErrNoKitesAvailable, kontrol.ErrQueryFieldsEmpty, klient.ErrDialingFailed:
		return nil
	default:
		return fmt.Errorf("[%s] check usage of AWS klient kite [%s] err: %s", m.ObjectId.Hex(), m.IpAddress, err)
	}
}