You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.6 KiB
75 lines
1.6 KiB
package ceph |
|
|
|
import ( |
|
"io/fs" |
|
"log" |
|
|
|
"asciigoat.org/ini/basic" |
|
|
|
"darvaza.org/core" |
|
) |
|
|
|
var sectionMap = map[string]func(*Config, *basic.Section) error{ |
|
"global": loadGlobalConfSection, |
|
} |
|
|
|
func loadConfSection(out *Config, src *basic.Section) error { |
|
h, ok := sectionMap[src.Key] |
|
if !ok { |
|
return core.Wrap(fs.ErrInvalid, "unknown section %q", src.Key) |
|
} |
|
|
|
return h(out, src) |
|
} |
|
|
|
func loadGlobalConfSection(out *Config, src *basic.Section) error { |
|
var cfg GlobalConfig |
|
|
|
for _, field := range src.Fields { |
|
if err := loadGlobalConfField(&cfg, field); err != nil { |
|
return core.Wrap(err, "global") |
|
} |
|
} |
|
|
|
out.Global = cfg |
|
return nil |
|
} |
|
|
|
func loadGlobalConfField(cfg *GlobalConfig, field basic.Field) error { |
|
log.Printf("%s[%q] = %q", "global", field.Key, field.Value) |
|
|
|
key, value := field.Key, field.Value |
|
|
|
switch key { |
|
case "fsid": |
|
return configFieldHandler(&cfg.FSID, key, value) |
|
case "mon_host": |
|
return configFieldHandler(&cfg.MonitorsAddr, key, value) |
|
case "mon_initial_members": |
|
return configFieldHandler(&cfg.Monitors, key, value) |
|
case "cluster_network": |
|
return configFieldHandler(&cfg.ClusterNetwork, key, value) |
|
default: |
|
return core.Wrap(fs.ErrNotExist, "field %q unknown", key) |
|
} |
|
} |
|
|
|
func configFieldHandler(vi any, key, value string) error |
|
|
|
func newConfigFromDocument(doc *basic.Document) (*Config, error) { |
|
var out Config |
|
|
|
if len(doc.Global) > 0 { |
|
err := core.Wrap(fs.ErrInvalid, "fields before the first section") |
|
return nil, err |
|
} |
|
|
|
for i := range doc.Sections { |
|
src := &doc.Sections[i] |
|
if err := loadConfSection(&out, src); err != nil { |
|
return nil, err |
|
} |
|
} |
|
|
|
return &out, nil |
|
}
|
|
|