mirror of
https://github.com/linka-cloud/d2vm.git
synced 2026-06-22 12:26:07 +00:00
feat: add mac address support to qemu run command
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
@@ -51,6 +51,7 @@ type config struct {
|
||||
qemuImgPath string
|
||||
publishedPorts []PublishedPort
|
||||
netdevConfig string
|
||||
mac string
|
||||
|
||||
stdin io.Reader
|
||||
stdout io.Writer
|
||||
@@ -129,6 +130,12 @@ func WithPublishedPorts(ports ...PublishedPort) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func WithMAC(mac string) Option {
|
||||
return func(c *config) {
|
||||
c.mac = mac
|
||||
}
|
||||
}
|
||||
|
||||
func WithStdin(r io.Reader) Option {
|
||||
return func(c *config) {
|
||||
c.stdin = r
|
||||
|
||||
+10
-3
@@ -135,6 +135,14 @@ func Run(ctx context.Context, path string, opts ...Option) error {
|
||||
return fmt.Errorf("Invalid networking mode: %s", netMode[0])
|
||||
}
|
||||
|
||||
if config.mac != "" {
|
||||
if _, err := net.ParseMAC(config.mac); err != nil {
|
||||
return fmt.Errorf("Invalid MAC address: %s", config.mac)
|
||||
}
|
||||
} else {
|
||||
config.mac = generateMAC().String()
|
||||
}
|
||||
|
||||
if err := config.discoverBinaries(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -286,11 +294,10 @@ func (c *config) buildQemuCmdline() ([]string, error) {
|
||||
}
|
||||
|
||||
if c.netdevConfig != "" {
|
||||
mac := generateMAC()
|
||||
if c.arch == "s390x" {
|
||||
qemuArgs = append(qemuArgs, "-device", "virtio-net-ccw,netdev=t0,mac="+mac.String())
|
||||
qemuArgs = append(qemuArgs, "-device", "virtio-net-ccw,netdev=t0,mac="+c.mac)
|
||||
} else {
|
||||
qemuArgs = append(qemuArgs, "-device", "virtio-net-pci,netdev=t0,mac="+mac.String())
|
||||
qemuArgs = append(qemuArgs, "-device", "virtio-net-pci,netdev=t0,mac="+c.mac)
|
||||
}
|
||||
forwardings, err := buildQemuForwardings(c.publishedPorts)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user