MCPcopy
hub / github.com/purpleidea/mgmt / Res

Interface Res

engine/resources.go:256–297  ·  view source on GitHub ↗

Res is the minimum interface you need to implement to define a new resource.

Source from the content-addressed store, hash-verified

254
255// Res is the minimum interface you need to implement to define a new resource.
256type Res interface {
257 fmt.Stringer // String() string
258
259 KindedRes
260 NamedRes // TODO: consider making this optional in the future
261 MetaRes // All resources must have meta params.
262
263 // Default returns a struct with sane defaults for this resource.
264 Default() Res
265
266 // Validate determines if the struct has been defined in a valid state.
267 Validate() error
268
269 // Init initializes the resource and passes in some external information
270 // and data from the engine.
271 Init(*Init) error
272
273 // Cleanup is run by the engine to clean up after the resource is done.
274 Cleanup() error
275
276 // Watch is run by the engine to monitor for state changes. If it
277 // detects any, it notifies the engine which will usually run CheckApply
278 // in response. If the input context cancels, we must shutdown.
279 Watch(context.Context) error
280
281 // CheckApply determines if the state of the resource is correct and if
282 // asked to with the `apply` variable, applies the requested state. If
283 // the input context cancels, we must return as quickly as possible. We
284 // should never exit immediately if this would cause permanent
285 // corruption of some sort. However it doesn't mean that a resource was
286 // taken to the desired state. The input context is not guaranteed to
287 // cancel when you return from this function. If that's required for
288 // your code to free memory, make sure to wrap it, cancel it on return
289 // with a defer, and wait for any workers to exit with a waitgroup.
290 CheckApply(ctx context.Context, apply bool) (checkOK bool, err error)
291
292 // Cmp compares itself to another resource and returns an error if they
293 // are not equivalent. This is more strict than the Adapts method of the
294 // CompatibleRes interface which allows for equivalent differences if
295 // the have a compatible result in CheckApply.
296 Cmp(Res) error
297}
298
299// Repr returns a representation of a resource from its kind and name. This is
300// used as the definitive format so that it can be changed in one place.

Callers 40

NewResourceFunction · 0.65
TestResources2Function · 0.95
runServerMethod · 0.65
RegisterFunction · 0.65
ValidateFunction · 0.65
ValidateMethod · 0.65
getServerConfigMethod · 0.65
setupFunction · 0.65
InitMethod · 0.65

Implementers 15

AugeasResengine/resources/augeas.go
DHCPServerResengine/resources/dhcp.go
DHCPHostResengine/resources/dhcp.go
DHCPRangeResengine/resources/dhcp.go
TarResengine/resources/tar.go
ValueResengine/resources/value.go
MountResengine/resources/mount.go
HostnameResengine/resources/hostname.go
VirtBuilderResengine/resources/virt_builder.go
HTTPClientResengine/resources/http_client.go
HetznerVMResengine/resources/hetzner_vm.go
LineResengine/resources/line.go

Calls

no outgoing calls

Tested by

no test coverage detected