@@ -5,8 +5,11 @@ import (
55 "encoding/json"
66 "errors"
77 "fmt"
8+ "io/ioutil"
89 "os"
10+ "path"
911 "path/filepath"
12+ "strings"
1013
1114 "github.com/gluster/glusterd2/glusterd2/brick"
1215 "github.com/gluster/glusterd2/glusterd2/gdctx"
@@ -22,6 +25,7 @@ import (
2225
2326 "github.com/pborman/uuid"
2427 log "github.com/sirupsen/logrus"
28+ config "github.com/spf13/viper"
2529 "golang.org/x/sys/unix"
2630)
2731
@@ -302,8 +306,43 @@ func undoStoreVolume(c transaction.TxnCtx) error {
302306 return storeVolInfo (c , "oldvolinfo" )
303307}
304308
305- // LoadDefaultGroupOptions loads the default group option map into the store
306- func LoadDefaultGroupOptions () error {
309+ func loadDefaultGroupOptions () error {
310+ defaultProfilesPath := path .Join (config .GetString ("localstatedir" ), "templates" , "profiles.json" )
311+ // If directory not exists, create the directory and then generate default templates
312+ _ , err := os .Stat (defaultProfilesPath )
313+ if os .IsNotExist (err ) {
314+ content , err := json .MarshalIndent (defaultGroupOptions , "" , " " )
315+ if err != nil {
316+ return err
317+ }
318+
319+ err = os .MkdirAll (path .Dir (defaultProfilesPath ), os .ModeDir | os .ModePerm )
320+ if err != nil {
321+ return err
322+ }
323+ return ioutil .WriteFile (defaultProfilesPath , content , 0640 )
324+ } else if err == nil {
325+ content , err := ioutil .ReadFile (defaultProfilesPath )
326+ if err != nil {
327+ return err
328+ }
329+ var grpOpts map [string ]* api.OptionGroup
330+ err = json .Unmarshal (content , & grpOpts )
331+ if err != nil {
332+ return err
333+ }
334+ defaultGroupOptions = grpOpts
335+ return nil
336+ }
337+ return err
338+ }
339+
340+ // InitDefaultGroupOptions loads the default group option map into the store
341+ func InitDefaultGroupOptions () error {
342+ err := loadDefaultGroupOptions ()
343+ if err != nil {
344+ return err
345+ }
307346 groupOptions , err := json .Marshal (defaultGroupOptions )
308347 if err != nil {
309348 return err
@@ -380,3 +419,23 @@ func txnGenerateBrickVolfiles(c transaction.TxnCtx) error {
380419 }
381420 return nil
382421}
422+
423+ func containsReservedGroupProfile (opts interface {}) bool {
424+ pfx := "profile.default."
425+ switch value := opts .(type ) {
426+ case map [string ]string :
427+ for k := range value {
428+ if strings .HasPrefix (k , pfx ) {
429+ return true
430+ }
431+ }
432+ case []string :
433+ for _ , v := range value {
434+ if strings .HasPrefix (v , pfx ) {
435+ return true
436+ }
437+ }
438+ }
439+
440+ return false
441+ }
0 commit comments