Esempio n. 1
0
func (d *daemon) registerService() {
	// Create an objdb client
	objdbClient := client.NewClient()

	// Get the address to be used for local communication
	localIP, err := objdbClient.GetLocalAddr()
	if err != nil {
		log.Fatalf("Error getting locla IP address. Err: %v", err)
	}

	// service info
	srvInfo := objdb.ServiceInfo{
		ServiceName: "netmaster",
		HostAddr:    localIP,
		Port:        9999,
	}

	// Register the node with service registry
	err = objdbClient.RegisterService(srvInfo)
	if err != nil {
		log.Fatalf("Error registering service. Err: %v", err)
	}

	log.Infof("Registered netmaster service with registry")
}
Esempio n. 2
0
func clusterInit(netplugin *plugin.NetPlugin, opts cliOpts) error {
	// Create an objdb client
	objdbClient := client.NewClient()

	// Register ourselves
	registerService(objdbClient, opts)

	// Start peer discovery loop
	go peerDiscoveryLoop(netplugin, objdbClient)

	return nil
}
Esempio n. 3
0
// Init initializes the cluster module
func Init(netplugin *plugin.NetPlugin, localIP string) error {
	// Create an objdb client
	objdbClient := client.NewClient()

	// Register ourselves
	registerService(objdbClient, localIP)

	// Start peer discovery loop
	go peerDiscoveryLoop(netplugin, objdbClient, localIP)

	return nil
}
Esempio n. 4
0
// GetLocalAddr gets local address to be used
func GetLocalAddr() (string, error) {
	// Get objdb's client IP
	clientIP, err := client.NewClient().GetLocalAddr()
	if err != nil {
		log.Warnf("Error getting local address from objdb. Returning first local address. Err: %v", err)

		return netutils.GetFirstLocalAddr()
	}

	// Make sure the ip address is local
	if netutils.IsAddrLocal(clientIP) {
		return clientIP, nil
	}

	// Return first available address if client IP is not local
	return netutils.GetFirstLocalAddr()
}
Esempio n. 5
0
}

func RemoveLinkSet(linkSet *(map[string]Link), obj ModelObj) error {
	// check is linkset is nil
	if *linkSet == nil {
		return nil
	}

	// remove the link from map
	delete(*linkSet, obj.GetKey())

	return nil
}

// persistent database
var cdb = client.NewClient()

func WriteObj(objType, objKey string, value interface{}) error {
	key := "/modeldb/" + objType + "/" + objKey
	err := cdb.SetObj(key, value)
	if err != nil {
		log.Errorf("Error storing object %s. Err: %v", key, err)
		return err
	}

	return nil
}

func ReadObj(objType, objKey string, retVal interface{}) error {
	key := "/modeldb/" + objType + "/" + objKey
	err := cdb.GetObj(key, retVal)