Documentation
¶
Index ¶
- Variables
- func EvaluatedString(v any) string
- func InstallFile(src, dst string) error
- func ValidateReferrer(dst string, referrer Referrer) error
- type Alert
- type AlertKind
- type AlertLevel
- type Alerts
- type Base
- type ErrPostponedRef
- type Evaluated
- type RefJudge
- type Referrer
- type T
- func (t T) Changed() bool
- func (t *T) Commit() error
- func (t *T) CommitData(configData rawconfig.T) error
- func (t *T) CommitDataTo(configData rawconfig.T, configPath string) error
- func (t *T) CommitDataToInvalid(configData rawconfig.T, configPath string) error
- func (t *T) CommitInvalid() error
- func (t *T) CommitTo(configPath string) error
- func (t *T) CommitToInvalid(configPath string) error
- func (t *T) DeleteSections(sections ...string) error
- func (t *T) DereferenceAs(ref, section, impersonate string) (string, error)
- func (t *T) DriverGroupSet(op keyop.T) error
- func (t *T) Dump() ([]byte, error)
- func (t *T) Eval(k key.T) (interface{}, error)
- func (t *T) EvalAs(k key.T, impersonate string) (interface{}, error)
- func (t *T) EvalKeywordAs(k key.T, kw *keywords.Keyword, impersonate string) (interface{}, error)
- func (t *T) EvalNoConv(k key.T) (string, error)
- func (t *T) EvalNoConvAs(k key.T, impersonate string) (string, error)
- func (t *T) EvalStrictAs(k key.T, impersonate string, judge RefJudge) (interface{}, error)
- func (t *T) EvaluatedText(k key.T, v any) string
- func (t *T) Get(k key.T) string
- func (t *T) GetBool(k key.T) bool
- func (t *T) GetBoolStrict(k key.T) (bool, error)
- func (t *T) GetDuration(k key.T) *time.Duration
- func (t *T) GetDurationStrict(k key.T) (*time.Duration, error)
- func (t *T) GetInt(k key.T) int
- func (t *T) GetIntStrict(k key.T) (int, error)
- func (t *T) GetSet(k key.T) *set.Set
- func (t *T) GetSetStrict(k key.T) (*set.Set, error)
- func (t *T) GetSize(k key.T) *int64
- func (t *T) GetSizeStrict(k key.T) (*int64, error)
- func (t *T) GetStrict(k key.T) (string, error)
- func (t *T) GetString(k key.T) string
- func (t *T) GetStringAs(k key.T, impersonate string) string
- func (t *T) GetStringStrict(k key.T) (string, error)
- func (t *T) GetStringStrictAs(k key.T, impersonate string) (string, error)
- func (t *T) GetStrings(k key.T) []string
- func (t *T) GetStringsStrict(k key.T) ([]string, error)
- func (t *T) HasKey(k key.T) bool
- func (t *T) HasKeyMatchingOp(kop keyop.T) bool
- func (t T) HasSectionString(s string) bool
- func (t *T) IsInDRPNodes(impersonate string) (bool, error)
- func (t *T) IsInEncapNodes(impersonate string) (bool, error)
- func (t *T) IsInNodes(impersonate string) (bool, error)
- func (t T) KeyList() key.L
- func (t *T) Keys(section string) []string
- func (t *T) LoadRaw(configData rawconfig.T) error
- func (t *T) MaterializeDefaultSection()
- func (t T) ModTime() time.Time
- func (t T) NewAlertCandidates(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertCapabilities(k key.T, did driver.ID) Alert
- func (t T) NewAlertConfigure(section string, did driver.ID, err error, disabled bool) Alert
- func (t T) NewAlertDeprecated(k key.T, did driver.ID, release, replacedBy string) Alert
- func (t T) NewAlertDeprecatedValue(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertEval(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertIgnoredKeyword(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertInvalidSection(section string, err error) Alert
- func (t T) NewAlertKeySource(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertMissingKeyword(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertMissingStrategy(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertMoved(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertReferenceGroup(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertScoping(k key.T, did driver.ID) Alert
- func (t T) NewAlertStrategies(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertUnknown(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertUnknownDriver(k key.T, did driver.ID) Alert
- func (t T) NewAlertUnknownResource(k key.T, did driver.ID, comment string) Alert
- func (t T) NewAlertUnknownSection(section string) Alert
- func (t T) NewAlertUnsupportedSection(section, sectionType string) Alert
- func (t *T) NewEvaluated(k key.T, v any) Evaluated
- func (t T) Ops() []string
- func (t *T) PrepareDeleteSections(sections ...string) error
- func (t *T) PrepareSet(kops ...keyop.T) error
- func (t *T) PrepareUnset(ks ...key.T) error
- func (t *T) PrepareUpdate(deleteSections []string, unsetKeys []key.T, keyOps []keyop.T) error
- func (t T) Raw() rawconfig.T
- func (t T) RawEvaluated() (rawconfig.T, error)
- func (t T) RawEvaluatedAs(impersonate string) (rawconfig.T, error)
- func (t *T) Recommit() error
- func (t *T) RecommitInvalid() error
- func (t *T) RegisterPostCommit(fn func() error)
- func (t T) Reload() error
- func (t T) SectionMap(section string) map[string]string
- func (t T) SectionMapStrict(section string) (map[string]string, error)
- func (t T) SectionSig(section string) string
- func (t T) SectionStrings() []string
- func (t *T) SectionType(k key.T) string
- func (t *T) Set(ops ...keyop.T) error
- func (t *T) SetBase(base Base)
- func (t *T) Unset(ks ...key.T) error
- func (t *T) UnsetRecorded()
- func (t *T) Update(deleteSections []string, unsetKeys []key.T, keyOps []keyop.T) error
- func (t T) Validate() (Alerts, error)
- type TNodesConverter
- type TPeersConverter
Constants ¶
This section is empty.
Variables ¶
var ( NodesConverter converters.Converter = TNodesConverter{} PeersConverter converters.Converter = TPeersConverter{} )
NodesConverter and PeersConverter are the singletons the keyword definitions must reference. They are hosted here instead of the converters package because they depend on the node selector.
var ( RegexpOperation = regexp.MustCompile(`(\$\(\(.+\)\))`) RegexpIndex = regexp.MustCompile(`.+\[(?P<Index>[0-9]+)\]`) ErrExist = errors.New("configuration does not exist") ErrInfiniteDeferenceRecursion = errors.New("infinite dereference recursion") ErrNoKeyword = errors.New("keyword does not exist") ErrType = errors.New("type error") ErrUnknownReference = errors.New("unknown reference") // ErrRefNotAvailable is the error of a strict evaluation naming a // reference its RefJudge refused. ErrRefNotAvailable = errors.New("reference not available") DriverGroups = set.New("ip", "volume", "disk", "fs", "share", "container", "app", "sync", "task") )
var ( // ErrConfigChanged is a write refused because the configuration file // is no longer the Base it was checked against. ErrConfigChanged = errors.New("the configuration changed while the write was checked") )
var ErrUnknownType = errors.New("unknown type")
ErrUnknownType is the error of a write setting the type of a section to a driver om does not know.
Functions ¶
func EvaluatedString ¶
EvaluatedString renders an evaluated keyword value the way the configuration spells it.
Evaluating a keyword returns what its converter makes of it, and that is not always a string: a size is an *int64, a duration a *time.Duration, a list a []string. Asking for such a keyword as a string used to assert it was one, so declaring a converter on a keyword any of the many GetString callers happens to read took the process down with it.
A list joins on spaces, which is how a configuration writes one: fmt prints it inside brackets, and a value spelled "[a b]" matches neither a list of allowed values nor a shape a rule refuses. A pointer is followed, fmt printing the address rather than what a converter put behind it.
func InstallFile ¶
InstallFile replaces the configuration file at dst with the file at src, under the lock every writer of dst takes. It is how a configuration made elsewhere, as one fetched from a peer, is installed.
func ValidateReferrer ¶
Types ¶
type Alert ¶
type Alert struct {
Path naming.Path `json:"path"`
Level AlertLevel `json:"level"`
Kind AlertKind `json:"kind"`
Key key.T `json:"key"`
Driver driver.ID `json:"driver"`
Comment string `json:"comment"`
}
func (Alert) StringWithoutMeta ¶
func (Alert) Unstructured ¶
type AlertKind ¶
type AlertKind int
func (AlertKind) MarshalJSON ¶
func (*AlertKind) UnmarshalJSON ¶
UnmarshalJSON unmashals a quoted json string to the enum value
type AlertLevel ¶
type AlertLevel int
func (AlertLevel) MarshalJSON ¶
func (t AlertLevel) MarshalJSON() ([]byte, error)
func (AlertLevel) String ¶
func (t AlertLevel) String() string
func (*AlertLevel) UnmarshalJSON ¶
func (t *AlertLevel) UnmarshalJSON(b []byte) error
UnmarshalJSON unmashals a quoted json string to the enum value
type Alerts ¶
type Alerts []Alert
func (Alerts) Errors ¶
Errors are the alerts that make a configuration invalid, as opposed to the warnings that only have something to say about it.
func (Alerts) StringWithoutMeta ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base is the configuration file a write was checked against, as read before the checks.
A write is checked, by whoever writes, against the configuration read before it, and lands as a whole file. A file another writer changed in between is replaced by one checked against its predecessor, which puts back what the other write changed, without its checks. A write given a Base lands only if the file is still that Base.
func ReadBase ¶
ReadBase reads the configuration file at p as the Base of a write, before the write is checked. A file missing is a Base too: the write lands only if nobody created the file meanwhile.
func (Base) Landing ¶
Landing returns the base with fn run as the write lands: under the lock of the file, once the file is found to be the base, before it is replaced. What fn does is then done by the write that lands alone, never by one refused, as one losing a race with another. An error of fn refuses the write. done, if any, is run once the write is over, saying whether the file was replaced, on an error of fn too, for what fn did before failing.
A base given several runs them in the order given, one failing refusing the write without the next run, and every done of those run is run.
type ErrPostponedRef ¶
func NewErrPostponedRef ¶
func NewErrPostponedRef(ref string, rid string) ErrPostponedRef
func (ErrPostponedRef) Error ¶
func (t ErrPostponedRef) Error() string
type Evaluated ¶
Evaluated is a value EvalAs answered, with its text: printed, it is the text a person reads, and in json the value a program reads.
func (Evaluated) MarshalJSON ¶
type RefJudge ¶
RefJudge judges a reference a strict evaluation resolved: ref is the reference, without its braces, modifier or index, and val and err what it evaluated to. It returns the reason the evaluation must fail, or nil to go on with val, or err.
type Referrer ¶
type Referrer interface {
KeywordLookup(key.T, string) *keywords.Keyword
IsVolatile() bool
Config() *T
ConfigData() any
// for reference private to the referrer. ex: path for an object
Dereference(string) (string, error)
// for scoping
Nodes() ([]string, error)
DRPNodes() ([]string, error)
}
Referrer is the interface implemented by node and object to provide a reference resolver using their private attributes.
type T ¶
type T struct {
ConfigFilePath string
Path naming.Path
Referrer Referrer
NodeReferrer Referrer
// contains filtered or unexported fields
}
T exposes methods to read and write configurations.
func NewObject ¶
NewObject configures and returns a T instance pointer. The first argument is the path of the configuration file to write to.
The path must be repeated as one of the following sources to read it. Accepted sources are []byte in ini format or a configuration file path containing ini formatted data.
func (*T) CommitDataToInvalid ¶
func (*T) CommitInvalid ¶
func (*T) CommitToInvalid ¶
func (*T) DeleteSections ¶
DeleteSections deletes sections from the config and commit changes
func (*T) DereferenceAs ¶
DereferenceAs returns the value of ref, a reference as a keyword value writes it between braces, evaluated in section for the node impersonate, and an error for a reference that resolves to nothing.
func (*T) EvalAs ¶
EvalAs returns a key value,
- contextualized for a node (by default the local node, customized by the impersonate option)
- dereferenced
- evaluated
func (*T) EvalKeywordAs ¶
func (*T) EvalNoConvAs ¶
EvalNoConvAs is EvalNoConv as the node given evaluates it.
func (*T) EvalStrictAs ¶
EvalStrictAs returns the value of the key k as EvalAs does, and fails with ErrRefNotAvailable where judge refuses a reference the value names, rather than leave the reference, or what it evaluated to, in the value: a command is not run with a path left empty.
func (*T) EvaluatedText ¶
EvaluatedText writes a value EvalAs answered for the key the way a configuration writes it: a duration as 2m, a size as 5g, a list as its words. The converter of the keyword writes it, so a value computed by an arithmetic, which is a count of bytes before it is converted, reads as a size too.
func (*T) GetInt ¶
GetInt returns the evaluated integer value associated with a key k. On errors returns 0.
func (*T) GetIntStrict ¶
GetIntStrict returns the evaluated integer value associated with a key k. On errors returns 0 and an appropriate error.
func (*T) GetStringStrictAs ¶
func (T) HasSectionString ¶
func (*T) MaterializeDefaultSection ¶
func (t *T) MaterializeDefaultSection()
MaterializeDefaultSection gives the DEFAULT section a header, so the configuration is written with the "[DEFAULT]" line and the keywords of that section are visibly grouped under it instead of floating above the first driver section header.
This is what the create codepaths do, so a new object configuration looks like the OpenSVC v2 ones. A configuration that already has the header is left untouched.
func (T) NewAlertCandidates ¶
func (T) NewAlertConfigure ¶
NewAlertConfigure says the resource of section refused its configuration when the object loaded it, by a check its driver makes beyond the keywords, as a network no cni configuration and no cluster network names: the resource is not configured, its status is undef, and its start is refused. A disabled resource is never started, so it is a warning.
func (T) NewAlertDeprecated ¶
func (T) NewAlertDeprecatedValue ¶
NewAlertDeprecatedValue says a keyword holds a value om still accepts and no longer recommends, and what to write instead.
It is not the keyword that is deprecated, which is what the alert beside it says: the keyword is the one to use, and one of the forms it takes is on its way out.
func (T) NewAlertIgnoredKeyword ¶
NewAlertIgnoredKeyword says a keyword is set where a condition it depends on does not hold, as a flex_min of a failover service: what reads it does not, and the value is ignored.
func (T) NewAlertInvalidSection ¶
NewAlertUnknownSection says a section is neither a resource nor a section an object reads, so nothing uses it: the status has no resource to show it by, and the validation is the only place it is reported. NewAlertInvalidSection says a section is named with a character no resource id is made of. Its resource is not configured, and it is an error, so a write naming it is refused rather than ignored.
func (T) NewAlertKeySource ¶
NewAlertKeySource says a keyword names a key of a datastore with a source the object can not seed it from: a key another keyword seeds from another source, or a key of a datastore of another namespace.
func (T) NewAlertMissingKeyword ¶
NewAlertMissingKeyword says a section following a strategy misses a keyword the strategy requires, as a static address naming no device of the node.
func (T) NewAlertMissingStrategy ¶
NewAlertMissingStrategy says a section follows none of the strategies of a group it must follow one of, as an ip naming neither an address nor a network: no start can build it.
func (T) NewAlertMoved ¶
NewAlertMoved says a keyword is one a driver no longer reads, and what to write for om to do again what it did.
It is not an unknown keyword, which is what the alert beside it says of a keyword nothing has ever heard of: this one was read once, and what it asked for is written elsewhere now.
func (T) NewAlertReferenceGroup ¶
NewAlertReferenceGroup says a keyword names a resource of a driver group it does not take, as a netns naming a fs: no section of that name can ever be what the keyword asks for.
func (T) NewAlertStrategies ¶
NewAlertStrategies says a section sets keywords of two strategies of a group of keywords that exclude each other, as an address and the network to draw one from: one of the two is not used as its writer expects.
It is a warning, the resource doing with the keywords what its driver does.
func (T) NewAlertUnknownResource ¶
NewAlertUnknownResource says a keyword names a resource the configuration has no section of, as a netns naming a container not configured: the resource using it fails its action.
It is a warning, as a configuration may be written in steps, the resource named added after the one naming it.
func (T) NewAlertUnknownSection ¶
func (T) NewAlertUnsupportedSection ¶
NewAlertUnsupportedSection says a section is a resource of a driver group this agent does not have, in the words the instance status says it: the status warns of a resource it ignores, and the validation of the configuration is where what to fix is looked for.
The section has no driver to name in the alert, so the group it names is in the comment.
func (*T) NewEvaluated ¶
NewEvaluated returns the value EvalAs answered for the key, with its text.
func (T) Ops ¶
Ops returns the list of <section>.<option>[@<scope>]=<value> This format is used by the volume pools framework.
func (*T) PrepareDeleteSections ¶
PrepareDeleteSections deletes sections from the config without committing changes.
func (*T) PrepareSet ¶
PrepareSet applies key operations to config without committing changes.
func (*T) PrepareUnset ¶
PrepareUnset unsets keywords from config without committing changes.
func (*T) PrepareUpdate ¶
PrepareUpdate applies:
1- delete sections 2- unset keywords 3- apply key operations
without committing changes.
func (*T) RecommitInvalid ¶
func (*T) RegisterPostCommit ¶
func (T) SectionSig ¶
func (T) SectionStrings ¶
SectionStrings returns list of section names.
func (*T) SetBase ¶
SetBase makes the next write of the configuration land only over base, and fail with ErrConfigChanged otherwise.
func (*T) UnsetRecorded ¶
func (t *T) UnsetRecorded()
Unset deletes keys and commits. UnsetRecorded drops the keywords that name what this configuration was made with, which a configuration copied to make another thing must not carry: the id the object was created with, the uuid of an md array it holds.
They are written again, for the copy, when the copy makes what they name.
type TNodesConverter ¶
type TNodesConverter struct{}
TNodesConverter is the type of converter used for the nodes keyword, which makes sure the local nodename is in the resulting []string.
func (TNodesConverter) Convert ¶
func (t TNodesConverter) Convert(s string) (interface{}, error)
func (TNodesConverter) String ¶
func (t TNodesConverter) String() string
type TPeersConverter ¶
type TPeersConverter struct{}
TPeersConverter is the type of converter used for the drpnodes and encapnodes keyword, which accepts to return an empty list.
func (TPeersConverter) Convert ¶
func (t TPeersConverter) Convert(s string) (interface{}, error)
func (TPeersConverter) String ¶
func (t TPeersConverter) String() string