snapshots: Handle as separate components
This commit is contained in:
parent
698f04e13e
commit
3b112f1b8e
27 changed files with 960 additions and 789 deletions
29
internal/component/extras/bookkeeping.go
Normal file
29
internal/component/extras/bookkeeping.go
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package extras
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
)
|
||||
|
||||
type Bookkeeping struct {
|
||||
component.ComponentBase
|
||||
}
|
||||
|
||||
func (Bookkeeping) Name() string { return "bookkeeping" }
|
||||
|
||||
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
|
||||
func (Bookkeeping) SnapshotNeedsRunning() bool { return false }
|
||||
|
||||
// SnapshotName returns a new name to be used as an argument for path.
|
||||
func (Bookkeeping) SnapshotName() string { return "bookkeeping.txt" }
|
||||
|
||||
// Snapshot creates a snapshot of this instance
|
||||
func (*Bookkeeping) Snapshot(wisski models.Instance, context component.StagingContext) error {
|
||||
return context.AddFile(".", func(file io.Writer) error {
|
||||
_, err := fmt.Fprintf(file, "%#v\n", wisski)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ type Config struct {
|
|||
component.ComponentBase
|
||||
}
|
||||
|
||||
func (Config) Name() string { return "extra-config" }
|
||||
func (Config) Name() string { return "config" }
|
||||
|
||||
func (*Config) BackupName() string {
|
||||
return "config"
|
||||
|
|
|
|||
24
internal/component/extras/filesystem.go
Normal file
24
internal/component/extras/filesystem.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package extras
|
||||
|
||||
import (
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
)
|
||||
|
||||
// Filesystem implements snapshotting an instnace filesystem
|
||||
type Filesystem struct {
|
||||
component.ComponentBase
|
||||
}
|
||||
|
||||
func (Filesystem) Name() string { return "filesystem" }
|
||||
|
||||
// SnapshotNeedsRunning returns if this Snapshotable requires a running instance.
|
||||
func (Filesystem) SnapshotNeedsRunning() bool { return false }
|
||||
|
||||
// SnapshotName returns a new name to be used as an argument for path.
|
||||
func (Filesystem) SnapshotName() string { return "data" }
|
||||
|
||||
// Snapshot creates a snapshot of this instance
|
||||
func (*Filesystem) Snapshot(wisski models.Instance, context component.StagingContext) error {
|
||||
return context.CopyDirectory(".", wisski.FilesystemBase)
|
||||
}
|
||||
39
internal/component/extras/pathbuilders.go
Normal file
39
internal/component/extras/pathbuilders.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package extras
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/component/instances"
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
)
|
||||
|
||||
type Pathbuilders struct {
|
||||
component.ComponentBase
|
||||
Instances *instances.Instances
|
||||
}
|
||||
|
||||
func (Pathbuilders) Name() string { return "pathbuilders" }
|
||||
|
||||
func (Pathbuilders) SnapshotNeedsRunning() bool { return true }
|
||||
|
||||
func (Pathbuilders) SnapshotName() string { return "pathbuilders" }
|
||||
|
||||
func (pbs *Pathbuilders) Snapshot(wisski models.Instance, context component.StagingContext) error {
|
||||
return context.AddDirectory(".", func() error {
|
||||
builders, err := pbs.Instances.Instance(wisski).AllPathbuilders()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for name, bytes := range builders {
|
||||
if err := context.AddFile(name+".xml", func(file io.Writer) error {
|
||||
_, err := file.Write([]byte(bytes))
|
||||
return err
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue