示例#1
0
func main() {
	flag.Parse()

	ctx := ipc.NewTrustedContext(seesaw.SCLocalCLI)

	var err error
	seesawConn, err = conn.NewSeesawIPC(ctx)
	if err != nil {
		fatalf("Failed to connect to engine: %v", err)
	}
	if err := seesawConn.Dial(*engineSocket); err != nil {
		fatalf("Failed to connect to engine: %v", err)
	}
	defer seesawConn.Close()
	seesawCLI = cli.NewSeesawCLI(seesawConn, exit)

	if *command == "" {
		interactive()
		exit()
	}

	if err := seesawCLI.Execute(*command); err != nil {
		fatalf("%v", err)
	}
}
示例#2
0
// sendBatch sends a batch of notifications to the Seesaw Engine.
func (s *Server) sendBatch(batch []*Notification) error {
	engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
	if err != nil {
		return err
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var reply int
	ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
	return engine.Call("SeesawEngine.HealthState", &HealthState{ctx, batch}, &reply)
}
示例#3
0
// HAUpdate informs the Seesaw Engine of the current HAStatus.
// The Seesaw Engine may request a failover in response.
func (e *EngineClient) HAUpdate(status seesaw.HAStatus) (bool, error) {
	engineConn, err := net.DialTimeout("unix", e.Socket, engineTimeout)
	if err != nil {
		return false, fmt.Errorf("HAUpdate: Dial failed: %v", err)
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var failover bool
	ctx := ipc.NewTrustedContext(seesaw.SCHA)
	if err := engine.Call("SeesawEngine.HAUpdate", &ipc.HAStatus{ctx, status}, &failover); err != nil {
		return false, fmt.Errorf("HAUpdate: SeesawEngine.HAUpdate failed: %v", err)
	}
	return failover, nil
}
示例#4
0
// HAState informs the Seesaw Engine of the current HAState.
func (e *EngineClient) HAState(state seesaw.HAState) error {
	engineConn, err := net.DialTimeout("unix", e.Socket, engineTimeout)
	if err != nil {
		return fmt.Errorf("HAState: Dial failed: %v", err)
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var reply int
	ctx := ipc.NewTrustedContext(seesaw.SCHA)
	if err := engine.Call("SeesawEngine.HAState", &ipc.HAState{ctx, state}, &reply); err != nil {
		return fmt.Errorf("HAState: SeesawEngine.HAState failed: %v", err)
	}
	return nil
}
示例#5
0
// HAConfig requests the HAConfig from the Seesaw Engine.
func (e *EngineClient) HAConfig() (*seesaw.HAConfig, error) {
	engineConn, err := net.DialTimeout("unix", e.Socket, engineTimeout)
	if err != nil {
		return nil, fmt.Errorf("HAConfig: Dial failed: %v", err)
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var config seesaw.HAConfig
	ctx := ipc.NewTrustedContext(seesaw.SCHA)
	if err := engine.Call("SeesawEngine.HAConfig", ctx, &config); err != nil {
		return nil, fmt.Errorf("HAConfig: SeesawEngine.HAConfig failed: %v", err)
	}
	return &config, nil
}
示例#6
0
// getHealthchecks attempts to get the current healthcheck configurations from
// the Seesaw Engine.
func (s *Server) getHealthchecks() (*Checks, error) {
	engineConn, err := net.DialTimeout("unix", s.config.EngineSocket, engineTimeout)
	if err != nil {
		return nil, fmt.Errorf("Dial failed: %v", err)
	}
	engineConn.SetDeadline(time.Now().Add(engineTimeout))
	engine := rpc.NewClient(engineConn)
	defer engine.Close()

	var checks Checks
	ctx := ipc.NewTrustedContext(seesaw.SCHealthcheck)
	if err := engine.Call("SeesawEngine.Healthchecks", ctx, &checks); err != nil {
		return nil, fmt.Errorf("SeesawEngine.Healthchecks failed: %v", err)
	}

	return &checks, nil
}
示例#7
0
// update attempts to update the cached statistics from the Seesaw Engine.
func (e *ecuStats) update() error {
	// TODO(jsing): Make this untrusted.
	ctx := ipc.NewTrustedContext(seesaw.SCECU)
	seesawConn, err := conn.NewSeesawIPC(ctx)
	if err != nil {
		return fmt.Errorf("Failed to connect to engine: %v", err)
	}
	if err := seesawConn.Dial(e.ecu.cfg.EngineSocket); err != nil {
		return fmt.Errorf("Failed to connect to engine: %v", err)
	}
	defer seesawConn.Close()

	clusterStatus, err := seesawConn.ClusterStatus()
	if err != nil {
		return fmt.Errorf("Failed to get cluster status: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.ClusterStatus = *clusterStatus
	e.stats.lock.Unlock()

	configStatus, err := seesawConn.ConfigStatus()
	if err != nil {
		return fmt.Errorf("Failed to get config status: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.ConfigStatus = *configStatus
	e.stats.lock.Unlock()

	ha, err := seesawConn.HAStatus()
	if err != nil {
		return fmt.Errorf("Failed to get HA status: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.HAStatus = *ha
	e.stats.lock.Unlock()

	neighbors, err := seesawConn.BGPNeighbors()
	if err != nil {
		return fmt.Errorf("Failed to get BGP neighbors: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.neighbors = neighbors
	e.stats.lock.Unlock()

	vlans, err := seesawConn.VLANs()
	if err != nil {
		return fmt.Errorf("Failed to get VLANs: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.vlans = vlans.VLANs
	e.stats.lock.Unlock()

	vservers, err := seesawConn.Vservers()
	if err != nil {
		return fmt.Errorf("Failed to get vservers: %v", err)
	}
	e.stats.lock.Lock()
	e.stats.vservers = vservers
	e.stats.lock.Unlock()

	return nil
}