func Init() (env.Backend, error) { virt, err := virt.NewConn() if err != nil { return nil, fmt.Errorf("backend: Error connecting to libvirt: '%s'", err) } b := &backend{ redisPool: redis.NewPool(), virt: virt, } err = b.Redis().LoadScripts() if err != nil { return nil, err } go cmd.Listen(b, cmd.GlobalQueue) go cmd.Listen(b, cmd.QueueByClassAndID(cmd.Host, config.Conf.HostID.String())) go scheduler.Listen(b, model.GlobalClusterID) go b.monitor() return b, nil }
func addHostToCluster(backend env.Backend, params ClusterHostParams) (result interface{}, err error) { conn := backend.Redis() defer conn.Close() hostID := config.Conf.HostID.String() conn.Send("MULTI") conn.Send("SADD", "Cluster:"+params.ClusterID, hostID) conn.Send("SADD", "Host:"+hostID+":clusters", params.ClusterID) _, err = conn.Do("EXEC") go scheduler.Listen(backend, params.ClusterID) return "Added", err }