Skip to content

Commit 5322e7c

Browse files
glattercjactiveshadow
authored andcommitted
feat: support deletion of files in disk images
In addition to injecting files present on the phenix head node into a disk image, this capability adds support for deleting files already present inside a disk image using a new `deletions` key in the topology node schema. Relies on a minimega feature added in sandia-minimega/minimega@9f867b3
1 parent bb4d18e commit 5322e7c

File tree

8 files changed

+140
-12
lines changed

8 files changed

+140
-12
lines changed

.github/workflows/docker.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
context: .
3131
file: docker/Dockerfile
3232
build-args: |
33-
MM_MIN_REV=da0b90c
33+
MM_MIN_REV=9f867b3
3434
PHENIX_COMMIT=${{ env.sha }}
3535
PHENIX_TAG=${{ env.branch }}
3636
APPS_REPO=github.com/${{ github.event_name == 'repository_dispatch' && github.event.client_payload.repo || 'sandialabs/sceptre-phenix-apps' }}

.github/workflows/minimega.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ jobs:
2828
context: docker
2929
file: docker/Dockerfile.minimega
3030
build-args: |
31-
MM_REV=da0b90c
31+
MM_REV=9f867b3
3232
PHENIX_REVISION=${{ env.sha }}
3333
push: true
3434
tags: |
35-
ghcr.io/${{ github.repository }}/minimega:da0b90c
35+
ghcr.io/${{ github.repository }}/minimega:9f867b3
3636
ghcr.io/${{ github.repository }}/minimega:${{ env.sha }}
3737
ghcr.io/${{ github.repository }}/minimega:${{ env.branch }}

docker/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Update GitHub workflow config to change the minimum version of minimega
22
# required for use with phenix. This build stage is needed for making sure the
33
# latest version of the minimega Python module is installed.
4-
ARG MM_MIN_REV=c8e20a3
4+
ARG MM_MIN_REV=9f867b3
55
FROM ghcr.io/activeshadow/minimega/minimega:${MM_MIN_REV} AS minimega
66

77

@@ -170,7 +170,7 @@ COPY --from=gobuilder /phenix/src/go/bin/phenix-tunneler-* /opt/phenix/downloads
170170

171171
# Update GitHub workflow config to change the minimum version of minimega
172172
# required for use with phenix.
173-
ARG MM_MIN_REV=c8e20a3
173+
ARG MM_MIN_REV=9f867b3
174174
LABEL gov.sandia.phenix.minimega-min-revision="ghcr.io/sandialabs/sceptre-phenix/minimega:${MM_MIN_REV}"
175175

176176
WORKDIR /opt/phenix

docker/docker-compose.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ services:
1414
context: ../
1515
dockerfile: docker/Dockerfile
1616
args:
17-
MM_MIN_REV: da0b90c
17+
MM_MIN_REV: 9f867b3
1818
PHENIX_WEB_AUTH: disabled
1919
APPS_REPO: github.com/activeshadow/phenix-apps
2020
APPS_BRANCH: caldera
@@ -46,7 +46,7 @@ services:
4646
context: .
4747
dockerfile: Dockerfile.minimega
4848
args:
49-
MM_REV: da0b90c
49+
MM_REV: 9f867b3
5050
image: minimega
5151
container_name: minimega
5252
privileged: true

src/go/tmpl/templates/minimega_script.tmpl

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ ns add-host localhost
3131
## DoNotBoot: {{ derefBool .General.DoNotBoot }} ##
3232
{{- else }}
3333
{{- if (derefBool .General.Snapshot) -}}
34-
{{ $firstDrive := index .Hardware.Drives 0 }}
35-
disk snapshot {{ $firstDrive.Image }} {{ $.SnapshotName .General.Hostname }}
34+
{{ $firstDrive := index .Hardware.Drives 0 }}
35+
disk snapshot {{ $firstDrive.Image }} {{ $.SnapshotName .General.Hostname }}
3636
{{- if gt (len .Injections) 0 }}
3737
disk inject {{ $.SnapshotName .General.Hostname }}:{{ $firstDrive.GetInjectPartition }} files {{ .FileInjects $basedir }}
3838
{{- end }}
39+
{{- if gt (len .Deletions) 0 }}
40+
disk inject {{ $.SnapshotName .General.Hostname }}:{{ $firstDrive.GetInjectPartition }} delete files {{ .FileDeletions }}
41+
{{- end }}
3942
{{- end }}
4043
clear vm config
4144
{{- if ne (index $.Schedules .General.Hostname) "" }}

src/go/types/interfaces/topology.go

+8
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ type NodeSpec interface {
2929
Hardware() NodeHardware
3030
Network() NodeNetwork
3131
Injections() []NodeInjection
32+
Deletions() []NodeDeletion
3233
Delay() NodeDelay
3334
Advanced() map[string]string
3435
Overrides() map[string]string
3536
Commands() []string
3637
External() bool
3738

3839
SetInjections([]NodeInjection)
40+
SetDeletions([]NodeDeletion)
3941
SetType(string)
4042
SetLabels(map[string]string)
4143

@@ -87,6 +89,7 @@ type NodeSpec interface {
8789
// - network: 75.75.0.0/16
8890
AddNetworkOSPF(routerID string, dead, hello, retrans int, areas map[int][]string)
8991
AddInject(string, string, string, string)
92+
AddDeletion(string, string)
9093

9194
SetAdvanced(map[string]string)
9295
AddAdvanced(string, string)
@@ -254,6 +257,11 @@ type NodeInjection interface {
254257
Permissions() string
255258
}
256259

260+
type NodeDeletion interface {
261+
Path() string
262+
Description() string
263+
}
264+
257265
type NodeDelay interface {
258266
Timer() time.Duration
259267
User() bool

src/go/types/version/v0/node.go

+52-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Node struct {
1818
HardwareF *Hardware `json:"hardware" yaml:"hardware" structs:"hardware" mapstructure:"hardware"`
1919
NetworkF *Network `json:"network" yaml:"network" structs:"network" mapstructure:"network"`
2020
InjectionsF []*Injection `json:"injections" yaml:"injections" structs:"injections" mapstructure:"injections"`
21-
21+
DeletionsF []*Deletion `json:"deletions" yaml:"deletions" structs:"deletions" mapstructure:"deletions"`
2222
}
2323

2424
func (this Node) Annotations() map[string]interface{} {
@@ -55,6 +55,16 @@ func (this Node) Injections() []ifaces.NodeInjection {
5555
return injects
5656
}
5757

58+
func (this Node) Deletions() []ifaces.NodeDeletion {
59+
deletions := make([]ifaces.NodeDeletion, len(this.DeletionsF))
60+
61+
for i, j := range this.DeletionsF {
62+
deletions[i] = j
63+
}
64+
65+
return deletions
66+
}
67+
5868
func (this Node) Delay() ifaces.NodeDelay {
5969
return new(Delay)
6070
}
@@ -85,6 +95,16 @@ func (this *Node) SetInjections(injections []ifaces.NodeInjection) {
8595
this.InjectionsF = injects
8696
}
8797

98+
func (this *Node) SetDeletions(deletions []ifaces.NodeDeletion) {
99+
deletionList := make([]*Deletion, len(deletions))
100+
101+
for i, j := range deletions {
102+
deletionList[i] = j.(*Deletion)
103+
}
104+
105+
this.DeletionsF = deletionList
106+
}
107+
88108
func (this *Node) SetType(t string) {
89109
this.TypeF = t
90110
}
@@ -182,6 +202,13 @@ func (this *Node) AddInject(src, dst, perms, desc string) {
182202
})
183203
}
184204

205+
func (this *Node) AddDeletion(path, desc string) {
206+
this.DeletionsF = append(this.DeletionsF, &Deletion{
207+
PathF: path,
208+
DescriptionF: desc,
209+
})
210+
}
211+
185212
func (Node) SetAdvanced(map[string]string) {}
186213
func (Node) AddAdvanced(string, string) {}
187214
func (Node) AddOverride(string, string) {}
@@ -211,7 +238,6 @@ type General struct {
211238
VMTypeF string `json:"vm_type" yaml:"vm_type" structs:"vm_type" mapstructure:"vm_type"`
212239
SnapshotF *bool `json:"snapshot" yaml:"snapshot" structs:"snapshot" mapstructure:"snapshot"`
213240
DoNotBootF *bool `json:"do_not_boot" yaml:"do_not_boot" structs:"do_not_boot" mapstructure:"do_not_boot"`
214-
215241
}
216242

217243
func (this General) Hostname() string {
@@ -229,7 +255,7 @@ func (this General) VMType() string {
229255
func (this General) Snapshot() *bool {
230256
return this.SnapshotF
231257
}
232-
func (this *General) SetSnapshot(b bool) {
258+
func (this *General) SetSnapshot(b bool) {
233259
this.SnapshotF = &b
234260
}
235261

@@ -353,6 +379,19 @@ func (this Injection) Permissions() string {
353379
return this.PermissionsF
354380
}
355381

382+
type Deletion struct {
383+
PathF string `json:"path" yaml:"path" structs:"path" mapstructure:"path"`
384+
DescriptionF string `json:"description" yaml:"description" structs:"description" mapstructure:"description"`
385+
}
386+
387+
func (this Deletion) Path() string {
388+
return this.PathF
389+
}
390+
391+
func (this Deletion) Description() string {
392+
return this.DescriptionF
393+
}
394+
356395
type Delay struct{}
357396

358397
func (this Delay) Timer() time.Duration {
@@ -423,6 +462,16 @@ func (this Node) FileInjects(baseDir string) string {
423462
return strings.Join(injects, " ")
424463
}
425464

465+
func (this Node) FileDeletions() string {
466+
deletions := make([]string, len(this.DeletionsF))
467+
468+
for i, deletion := range this.DeletionsF {
469+
deletions[i] = fmt.Sprintf(`"%s"`, deletion.PathF)
470+
}
471+
472+
return strings.Join(deletions, ",")
473+
}
474+
426475
func (this Node) RouterName() string {
427476
if !strings.EqualFold(this.TypeF, "router") {
428477
return this.GeneralF.HostnameF

src/go/types/version/v1/node.go

+68
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Node struct {
1818
HardwareF *Hardware `json:"hardware" yaml:"hardware" structs:"hardware" mapstructure:"hardware"`
1919
NetworkF *Network `json:"network" yaml:"network" structs:"network" mapstructure:"network"`
2020
InjectionsF []*Injection `json:"injections" yaml:"injections" structs:"injections" mapstructure:"injections"`
21+
DeletionsF []*Deletion `json:"deletions" yaml:"deletions" structs:"deletions" mapstructure:"deletions"`
2122
AdvancedF map[string]string `json:"advanced" yaml:"advanced" structs:"advanced" mapstructure:"advanced"`
2223
OverridesF map[string]string `json:"overrides" yaml:"overrides" structs:"overrides" mapstructure:"overrides"`
2324
DelayF *Delay `json:"delay" yaml:"delay" structs:"delay" mapstructure:"delay"`
@@ -59,6 +60,16 @@ func (this Node) Injections() []ifaces.NodeInjection {
5960
return injects
6061
}
6162

63+
func (this Node) Deletions() []ifaces.NodeDeletion {
64+
deletions := make([]ifaces.NodeDeletion, len(this.DeletionsF))
65+
66+
for i, j := range this.DeletionsF {
67+
deletions[i] = j
68+
}
69+
70+
return deletions
71+
}
72+
6273
func (this Node) Delay() ifaces.NodeDelay {
6374
if this.DelayF == nil {
6475
return new(Delay)
@@ -102,6 +113,16 @@ func (this *Node) SetInjections(injections []ifaces.NodeInjection) {
102113
this.InjectionsF = injects
103114
}
104115

116+
func (this *Node) SetDeletions(deletions []ifaces.NodeDeletion) {
117+
deletionList := make([]*Deletion, len(deletions))
118+
119+
for i, j := range deletions {
120+
deletionList[i] = j.(*Deletion)
121+
}
122+
123+
this.DeletionsF = deletionList
124+
}
125+
105126
func (this *Node) SetType(t string) {
106127
this.TypeF = t
107128
}
@@ -243,6 +264,30 @@ func (this *Node) AddInject(src, dst, perms, desc string) {
243264
}
244265
}
245266

267+
func (this *Node) AddDeletion(path, desc string) {
268+
if _, ok := this.LabelsF["disable-injects"]; ok {
269+
return
270+
}
271+
272+
var exists bool
273+
274+
for _, deletion := range this.DeletionsF {
275+
if deletion.PathF == path {
276+
deletion.DescriptionF = desc
277+
278+
exists = true
279+
break
280+
}
281+
}
282+
283+
if !exists {
284+
this.DeletionsF = append(this.DeletionsF, &Deletion{
285+
PathF: path,
286+
DescriptionF: desc,
287+
})
288+
}
289+
}
290+
246291
func (this *Node) SetAdvanced(adv map[string]string) {
247292
this.AdvancedF = adv
248293
}
@@ -512,6 +557,19 @@ func (this Injection) Permissions() string {
512557
return this.PermissionsF
513558
}
514559

560+
type Deletion struct {
561+
PathF string `json:"path" yaml:"path" structs:"path" mapstructure:"path"`
562+
DescriptionF string `json:"description" yaml:"description" structs:"description" mapstructure:"description"`
563+
}
564+
565+
func (this Deletion) Path() string {
566+
return this.PathF
567+
}
568+
569+
func (this Deletion) Description() string {
570+
return this.DescriptionF
571+
}
572+
515573
func (this Node) validate() error {
516574
if this.ExternalF == nil {
517575
return nil
@@ -636,6 +694,16 @@ func (this Node) FileInjects(baseDir string) string {
636694
return strings.Join(injects, " ")
637695
}
638696

697+
func (this Node) FileDeletions() string {
698+
deletions := make([]string, len(this.DeletionsF))
699+
700+
for i, deletion := range this.DeletionsF {
701+
deletions[i] = fmt.Sprintf(`"%s"`, deletion.PathF)
702+
}
703+
704+
return strings.Join(deletions, ",")
705+
}
706+
639707
func (this Node) RouterName() string {
640708
if !strings.EqualFold(this.TypeF, "router") {
641709
return this.GeneralF.HostnameF

0 commit comments

Comments
 (0)