Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support deleting files in disk injects #198

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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