func Init(params volume.DriverParams) (volume.VolumeDriver, error) { inst := &driver{ IoNotSupported: &volume.IoNotSupported{}, DefaultEnumerator: volume.NewDefaultEnumerator(Name, kvdb.Instance()), } inst.buseDevices = make(map[string]*buseDev) if err := os.MkdirAll(BuseMountPath, 0744); err != nil { return nil, err } volumeInfo, err := inst.DefaultEnumerator.Enumerate( &api.VolumeLocator{}, nil, ) if err == nil { for _, info := range volumeInfo { if info.Status == api.VolumeStatus_VOLUME_STATUS_NONE { info.Status = api.VolumeStatus_VOLUME_STATUS_UP inst.UpdateVol(info) } } } else { dlog.Println("Could not enumerate Volumes, ", err) } c, err := cluster.Inst() if err != nil { dlog.Println("BUSE initializing in single node mode") } else { dlog.Println("BUSE initializing in clustered mode") c.AddEventListener(inst) } dlog.Println("BUSE initialized and driver mounted at: ", BuseMountPath) return inst, nil }
func (c *clusterApi) status(w http.ResponseWriter, r *http.Request) { method := "status" inst, err := cluster.Inst() if err != nil { c.sendError(name, method, w, err.Error(), http.StatusInternalServerError) return } resp := inst.GetState() json.NewEncoder(w).Encode(resp) }
func (c *clusterApi) disableGossip(w http.ResponseWriter, r *http.Request) { method := "disablegossip" inst, err := cluster.Inst() if err != nil { c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError) return } inst.DisableUpdates() clusterResponse := &api.ClusterResponse{} json.NewEncoder(w).Encode(clusterResponse) }
func (c *clusterApi) enumerate(w http.ResponseWriter, r *http.Request) { method := "enumerate" inst, err := cluster.Inst() if err != nil { c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError) return } cluster, err := inst.Enumerate() if err != nil { c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError) return } json.NewEncoder(w).Encode(cluster) }
func (c *clusterApi) disableGossip(w http.ResponseWriter, r *http.Request) { method := "disablegossip" inst, err := cluster.Inst() if err != nil { c.sendError(name, method, w, err.Error(), http.StatusInternalServerError) return } inst.DisableUpdates() json.NewEncoder(w).Encode(&clusterResponse{ Status: "OK", Version: clusterApiVersion, }) }
func (c *clusterApi) setSize(w http.ResponseWriter, r *http.Request) { method := "set size" inst, err := cluster.Inst() if err != nil { c.sendError(c.name, method, w, err.Error(), http.StatusInternalServerError) return } params := r.URL.Query() size := params["size"] if size == nil { c.sendError(c.name, method, w, "Missing size param", http.StatusBadRequest) return } sz, _ := strconv.Atoi(size[0]) err = inst.SetSize(sz) clusterResponse := &api.ClusterResponse{Error: err.Error()} json.NewEncoder(w).Encode(clusterResponse) }
func start(c *cli.Context) { if !osdcli.DaemonMode(c) { cli.ShowAppHelp(c) return } datastores := []string{mem.Name, etcd.Name, consul.Name} // We are in daemon mode. file := c.String("file") if file == "" { dlog.Warnln("OSD configuration file not specified. Visit openstorage.org for an example.") return } cfg, err := config.Parse(file) if err != nil { dlog.Errorln(err) return } kvdbURL := c.String("kvdb") u, err := url.Parse(kvdbURL) scheme := u.Scheme u.Scheme = "http" kv, err := kvdb.New(scheme, "openstorage", []string{u.String()}, nil) if err != nil { dlog.Warnf("Failed to initialize KVDB: %v (%v)", scheme, err) dlog.Warnf("Supported datastores: %v", datastores) return } err = kvdb.SetInstance(kv) if err != nil { dlog.Warnf("Failed to initialize KVDB: %v", err) return } // Start the cluster state machine, if enabled. clusterInit := false if cfg.Osd.ClusterConfig.NodeId != "" && cfg.Osd.ClusterConfig.ClusterId != "" { dlog.Infof("OSD enabling cluster mode.") if err := cluster.Init(cfg.Osd.ClusterConfig); err != nil { dlog.Errorln("Unable to init cluster server: %v", err) return } clusterInit = true if err := server.StartClusterAPI(config.ClusterAPIBase); err != nil { dlog.Warnf("Unable to start cluster API server: %v", err) return } } // Start the volume drivers. for d, v := range cfg.Osd.Drivers { dlog.Infof("Starting volume driver: %v", d) if _, err := volume.New(d, v); err != nil { dlog.Warnf("Unable to start volume driver: %v, %v", d, err) return } if err := server.StartPluginAPI(d, config.DriverAPIBase, config.PluginAPIBase); err != nil { dlog.Warnf("Unable to start volume plugin: %v", err) return } } if err := server.StartFlexVolumeAPI(config.FlexVolumePort); err != nil { dlog.Warnf("Unable to start flexvolume API: %v", err) return } // Start the graph drivers. for d, _ := range cfg.Osd.GraphDrivers { dlog.Infof("Starting graph driver: %v", d) if err := server.StartGraphAPI(d, config.PluginAPIBase); err != nil { dlog.Warnf("Unable to start graph plugin: %v", err) return } } if clusterInit { cm, err := cluster.Inst() if err != nil { dlog.Warnf("Unable to find cluster instance: %v", err) return } if err := cm.Start(); err != nil { dlog.Warnf("Unable to start cluster manager: %v", err) return } } // Daemon does not exit. select {} }