Ejemplo n.º 1
0
// Init the first time the foreman operates on a new namespace.  It queries the currently
// running VMs for their previously assigned roles, and writes them to the database.
func Init(conn db.Conn) {
	for _, m := range minions {
		m.client.Close()
	}
	minions = map[string]*minion{}

	conn.Transact(func(view db.Database) error {
		machines := view.SelectFromMachine(func(m db.Machine) bool {
			return m.PublicIP != "" && m.PrivateIP != "" && m.CloudID != ""
		})

		updateMinionMap(machines)

		forEachMinion(func(m *minion) {
			var err error
			m.config, err = m.client.getMinion()
			m.connected = err == nil
		})

		for _, m := range minions {
			role := db.PBToRole(m.config.Role)
			if m.connected && role != db.None {
				m.machine.Role = role
				m.machine.Connected = m.connected
				view.Commit(m.machine)
			}
		}

		return nil
	})
}
Ejemplo n.º 2
0
func (s server) SetMinionConfig(ctx context.Context,
	msg *pb.MinionConfig) (*pb.Reply, error) {
	go s.Transact(func(view db.Database) error {
		minion, err := view.MinionSelf()
		if err != nil {
			log.Info("Received initial configuation.")
			minion = view.InsertMinion()
		}

		minion.Role = db.PBToRole(msg.Role)
		minion.PrivateIP = msg.PrivateIP
		minion.Spec = msg.Spec
		minion.Provider = msg.Provider
		minion.Size = msg.Size
		minion.Region = msg.Region
		minion.Self = true
		view.Commit(minion)

		return nil
	})

	return &pb.Reply{Success: true}, nil
}
Ejemplo n.º 3
0
func (fm *foreman) init() {
	fm.conn.Transact(func(view db.Database) error {
		machines := view.SelectFromMachine(func(m db.Machine) bool {
			return m.PublicIP != "" && m.PrivateIP != "" && m.CloudID != ""
		})

		fm.updateMinionMap(machines)

		fm.forEachMinion(func(m *minion) {
			var err error
			m.config, err = m.client.getMinion()
			m.connected = err == nil
		})

		for _, m := range fm.minions {
			if m.connected {
				m.machine.Role = db.PBToRole(m.config.Role)
				view.Commit(m.machine)
			}
		}

		return nil
	})
}