func initFunc(root, cfgName string, config map[string]string) (objectstore.ObjectStoreDriver, error) { b := &S3ObjectStoreDriver{} if cfgName != "" { if util.ConfigExists(root, cfgName) { err := util.LoadConfig(root, cfgName, b) if err != nil { return nil, err } return b, nil } else { return nil, fmt.Errorf("Wrong configuration file for S3 objectstore driver") } } b.Service.Keys.AccessKey = config[S3_ACCESS_KEY] b.Service.Keys.SecretKey = config[S3_SECRET_KEY] b.Service.Region = config[S3_REGION] b.Service.Bucket = config[S3_BUCKET] b.Path = config[S3_PATH] if b.Service.Keys.AccessKey == "" || b.Service.Keys.SecretKey == "" || b.Service.Region == "" || b.Service.Bucket == "" || b.Path == "" { return nil, fmt.Errorf("Cannot find all required fields: %v %v %v %v %v", S3_ACCESS_KEY, S3_SECRET_KEY, S3_REGION, S3_BUCKET, S3_PATH) } if strings.HasPrefix(b.Path, "/") { return nil, fmt.Errorf("Slash '/' is not allowed at beginning of path: %v", b.Path) } //Test connection if _, err := b.List(""); err != nil { return nil, err } return b, nil }
func loadServerConfig(c *cli.Context) (*Server, error) { config := Config{} root := c.String("root") if root == "" { return nil, genRequiredMissingError("root") } log.Debug("Ignore command line opts, loading server config from ", root) err := util.LoadConfig(root, getCfgName(), &config) if err != nil { return nil, fmt.Errorf("Failed to load config:", err.Error()) } driver, err := drivers.GetDriver(config.Driver, config.Root, nil) if err != nil { return nil, fmt.Errorf("Failed to load driver:", err.Error()) } server := &Server{ Config: config, StorageDriver: driver, NameVolumeMap: make(map[string]string), } server.updateNameVolumeMap() return server, nil }
func getObjectStoreCfgAndDriver(root, objectstoreUUID string) (*ObjectStore, ObjectStoreDriver, error) { b := &ObjectStore{} err := util.LoadConfig(root, getCfgName(objectstoreUUID), b) if err != nil { return nil, nil, err } driver, err := GetObjectStoreDriver(b.Kind, root, getDriverCfgName(b.Kind, objectstoreUUID), nil) if err != nil { return nil, nil, err } log.Debug("Loaded configure for objectstore ", objectstoreUUID) return b, driver, nil }
func (config *Config) loadVolume(uuid string) *Volume { cfgName, err := getVolumeCfgName(uuid) if err != nil { return nil } if !util.ConfigExists(config.Root, cfgName) { return nil } volume := &Volume{} if err := util.LoadConfig(config.Root, cfgName, volume); err != nil { log.Error("Failed to load volume json ", cfgName) return nil } return volume }
func Deregister(root, id string) error { b := &ObjectStore{} err := util.LoadConfig(root, getCfgName(id), b) if err != nil { return err } err = removeDriverConfigFile(root, b.Kind, id) if err != nil { return err } err = removeConfigFile(root, id) if err != nil { return err } log.Debug("Deregistered block store ", id) return nil }
func (device *Device) loadImage(uuid string) *Image { if uuid == "" { return nil } cfgName, err := getImageCfgName(uuid) if err != nil { return nil } if !util.ConfigExists(device.Root, cfgName) { return nil } image := &Image{} if err := util.LoadConfig(device.Root, cfgName, image); err != nil { log.Error("Failed to load volume json ", cfgName) return nil } return image }
func initFunc(root, cfgName string, config map[string]string) (objectstore.ObjectStoreDriver, error) { b := &VfsObjectStoreDriver{} if cfgName != "" { if util.ConfigExists(root, cfgName) { err := util.LoadConfig(root, cfgName, b) if err != nil { return nil, err } return b, nil } else { return nil, fmt.Errorf("Wrong configuration file for VFS objectstore driver") } } //return temporily driver for loading objectstore config b.Path = config[VFS_PATH] if b.Path == "" { return nil, fmt.Errorf("Cannot find required field %v", VFS_PATH) } if _, err := b.List(""); err != nil { return nil, fmt.Errorf("VFS path %v doesn't exist or is not a directory", b.Path) } return b, nil }
func Init(root, cfgName string, config map[string]string) (drivers.Driver, error) { devicemapper.LogInitVerbose(1) devicemapper.LogInit(&DMLogger{}) if supported := devicemapper.UdevSetSyncSupport(true); !supported { return nil, fmt.Errorf("Udev sync is not supported. Cannot proceed.") } if util.ConfigExists(root, cfgName) { dev := Device{} err := util.LoadConfig(root, cfgName, &dev) d := &Driver{ Mutex: &sync.Mutex{}, } if err != nil { return d, err } d.Device = dev d.configName = cfgName d.root = root if err := d.activatePool(); err != nil { return d, err } return d, nil } dev, err := verifyConfig(config) if err != nil { return nil, err } dev.Root = root dataDev, err := os.Open(dev.DataDevice) if err != nil { return nil, err } defer dataDev.Close() metadataDev, err := os.Open(dev.MetadataDevice) if err != nil { return nil, err } defer metadataDev.Close() thinpSize, err := devicemapper.GetBlockDeviceSize(dataDev) if err != nil { return nil, err } dev.ThinpoolSize = int64(thinpSize) dev.LastDevID = 0 err = createPool(filepath.Base(dev.ThinpoolDevice), dataDev, metadataDev, uint32(dev.ThinpoolBlockSize)) if err != nil { return nil, err } err = util.SaveConfig(root, cfgName, &dev) if err != nil { return nil, err } d := &Driver{ root: root, configName: cfgName, Device: *dev, Mutex: &sync.Mutex{}, } log.Debug("Init done") return d, nil }