From e0e559695190800e7073df6e3ed404039894e6a0 Mon Sep 17 00:00:00 2001 From: glattercj Date: Fri, 22 Nov 2024 05:15:27 -0700 Subject: [PATCH] feat: support deleting files in disk injects --- src/go/tmpl/templates/minimega_script.tmpl | 2 +- src/go/types/version/v0/node.go | 4 +--- src/go/types/version/v1/node.go | 4 +++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/go/tmpl/templates/minimega_script.tmpl b/src/go/tmpl/templates/minimega_script.tmpl index 6044107c..e34ce986 100644 --- a/src/go/tmpl/templates/minimega_script.tmpl +++ b/src/go/tmpl/templates/minimega_script.tmpl @@ -31,7 +31,7 @@ ns add-host localhost ## DoNotBoot: {{ derefBool .General.DoNotBoot }} ## {{- else }} {{- if (derefBool .General.Snapshot) -}} - {{ $firstDrive := index .Hardware.Drives 0 }} + {{ $firstDrive := index .Hardware.Drives 0 }} disk snapshot {{ $firstDrive.Image }} {{ $.SnapshotName .General.Hostname }} {{- if gt (len .Injections) 0 }} disk inject {{ $.SnapshotName .General.Hostname }}:{{ $firstDrive.GetInjectPartition }} files {{ .FileInjects $basedir }} diff --git a/src/go/types/version/v0/node.go b/src/go/types/version/v0/node.go index 2798f5a7..91402b8e 100644 --- a/src/go/types/version/v0/node.go +++ b/src/go/types/version/v0/node.go @@ -18,7 +18,6 @@ type Node struct { HardwareF *Hardware `json:"hardware" yaml:"hardware" structs:"hardware" mapstructure:"hardware"` NetworkF *Network `json:"network" yaml:"network" structs:"network" mapstructure:"network"` InjectionsF []*Injection `json:"injections" yaml:"injections" structs:"injections" mapstructure:"injections"` - } func (this Node) Annotations() map[string]interface{} { @@ -169,7 +168,6 @@ type General struct { VMTypeF string `json:"vm_type" yaml:"vm_type" structs:"vm_type" mapstructure:"vm_type"` SnapshotF *bool `json:"snapshot" yaml:"snapshot" structs:"snapshot" mapstructure:"snapshot"` DoNotBootF *bool `json:"do_not_boot" yaml:"do_not_boot" structs:"do_not_boot" mapstructure:"do_not_boot"` - } func (this General) Hostname() string { @@ -187,7 +185,7 @@ func (this General) VMType() string { func (this General) Snapshot() *bool { return this.SnapshotF } -func (this *General) SetSnapshot(b bool) { +func (this *General) SetSnapshot(b bool) { this.SnapshotF = &b } diff --git a/src/go/types/version/v1/node.go b/src/go/types/version/v1/node.go index d19ef391..0ef9a5cf 100644 --- a/src/go/types/version/v1/node.go +++ b/src/go/types/version/v1/node.go @@ -555,7 +555,9 @@ func (this Node) FileInjects(baseDir string) string { injects := make([]string, len(this.InjectionsF)) for i, inject := range this.InjectionsF { - if strings.HasPrefix(inject.SrcF, "/") { + if inject.SrcF == "TERMINATED" { + injects[i] = fmt.Sprintf(`"-DELETE-":"%s"`, inject.DstF) + } else if strings.HasPrefix(inject.SrcF, "/") { injects[i] = fmt.Sprintf(`"%s":"%s"`, inject.SrcF, inject.DstF) } else { injects[i] = fmt.Sprintf(`"%s/%s":"%s"`, baseDir, inject.SrcF, inject.DstF)