Skip to content

Commit cab6b87

Browse files
authored
Merge pull request #19 from ckyrouac/shutdown-fix2
bug: Boot a shutdown libvirt VM via run
2 parents 873d784 + 6e0d067 commit cab6b87

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/vm/vm_linux.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ func (v *BootcVMLinux) Run(params RunVMParameters) (err error) {
131131
}
132132
}
133133

134+
if v.domain != nil {
135+
isRunning, err := v.IsRunning()
136+
if err != nil {
137+
return fmt.Errorf("unable to check if VM is running: %w", err)
138+
}
139+
140+
if !isRunning {
141+
logrus.Debugf("Deleting stopped VM %s\n", v.imageID)
142+
err = v.Delete()
143+
if err != nil {
144+
return fmt.Errorf("unable to delete stopped VM: %w", err)
145+
}
146+
} else {
147+
return errors.New("VM is already running")
148+
}
149+
}
150+
151+
//domain doesn't exist, create it
134152
logrus.Debugf("Creating VM %s\n", v.imageID)
135153

136154
domainXML, err := v.parseDomainTemplate()

0 commit comments

Comments
 (0)