Skip to content

Commit

Permalink
feat: support deleting files in disk injects
Browse files Browse the repository at this point in the history
  • Loading branch information
glattercj committed Nov 23, 2024
1 parent 31ce034 commit bfe9380
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/go/tmpl/templates/minimega_script.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ ns add-host localhost
## DoNotBoot: {{ derefBool .General.DoNotBoot }} ##
{{- else }}
{{- if (derefBool .General.Snapshot) -}}
{{ $firstDrive := index .Hardware.Drives 0 }}
disk snapshot {{ $firstDrive.Image }} {{ $.SnapshotName .General.Hostname }}
{{ $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 }}
{{- end }}
Expand Down
4 changes: 1 addition & 3 deletions src/go/types/version/v0/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{} {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
4 changes: 3 additions & 1 deletion src/go/types/version/v1/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "-DELETE-" || inject.SrcF == "DELETE" || inject.SrcF == "TERMINATE" || 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)
Expand Down

0 comments on commit bfe9380

Please sign in to comment.