Skip to content
Open
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
26 changes: 23 additions & 3 deletions images/virt-launcher/vlctl/cmd/vlctl/app/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ import (
"github.com/spf13/cobra"
)

const xmlDir = "/var/run/libvirt/qemu"
const (
xmlDir = "/var/run/libvirt/qemu"
xmlDirNonRoot = "/var/run/libvirt/qemu/run"
)

func NewDomainCommand() *cobra.Command {
var fromFile bool
Expand Down Expand Up @@ -55,13 +58,19 @@ func runDomainCommand(opts BaseOptions, fromFile bool) error {
if opts.Output != outputXml {
return fmt.Errorf("output format must be xml when reading from file")
}
entries, err := os.ReadDir(xmlDir)

dir, err := resolveXMLDir()
if err != nil {
return fmt.Errorf("failed to resolve xml dir: %w", err)
}

entries, err := os.ReadDir(dir)
if err != nil {
return fmt.Errorf("failed to read domain xml dir: %w", err)
}
for _, entry := range entries {
if strings.HasSuffix(entry.Name(), ".xml") {
b, err := os.ReadFile(filepath.Join(xmlDir, entry.Name()))
b, err := os.ReadFile(filepath.Join(dir, entry.Name()))
if err != nil {
return fmt.Errorf("failed to read domain xml file: %w", err)
}
Expand Down Expand Up @@ -94,6 +103,17 @@ func runDomainCommand(opts BaseOptions, fromFile bool) error {
return marshalAndPrintOutput(&opts, domain.Spec)
}

func resolveXMLDir() (string, error) {
_, err := os.Stat(xmlDirNonRoot)
if err == nil {
return xmlDirNonRoot
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return xmlDirNonRoot
return xmlDirNonRoot, nil

}
if os.IsNotExist(err) {
return xmlDir, nil
}
return "", err
}

func NewDomainStatsCommand() *cobra.Command {
return &cobra.Command{
Use: "stats",
Expand Down
Loading