Skip to content

Commit

Permalink
[driver vbox] adding the func SubDevices
Browse files Browse the repository at this point in the history
  • Loading branch information
remimendes committed Sep 12, 2023
1 parent d753298 commit 662f1c1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions drivers/rescontainervbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"github.com/antchfx/xmlquery"
"io"
"net"
"os"
Expand All @@ -15,7 +16,6 @@ import (
"syscall"
"time"

"github.com/antchfx/xmlquery"
"github.com/go-ping/ping"
"github.com/google/uuid"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -196,22 +196,26 @@ func (t *T) Stop(ctx context.Context) error {

func (t *T) SubDevices() device.L {
l := make(device.L, 0)
cf := t.configFile()

f, err := os.Open(cf)
f, err := os.Open(t.configFile())
if err != nil {
t.Log().Error().Err(err).Send()
return l
}
defer f.Close()
doc, err := xmlquery.Parse(f)
if err != nil {
t.Log().Error().Err(err).Send()
return l
}
nodes, err := xmlquery.QueryAll(doc, "//VirtualBox/Machine/MediaRegistry/HardDisks/HardDisk/Property")
if err != nil {
t.Log().Error().Err(err).Send()
return l
}
for _, e := range xmlquery.Find(doc, "//domain/devices/disk") {
if dev := e.SelectAttr("dev"); dev != "" {
l = append(l, device.New(dev))
}
for _, v := range nodes {
l = append(l, device.New(v.SelectAttr("value")))
}

return l
}

Expand Down

0 comments on commit 662f1c1

Please sign in to comment.