initial commit
This commit is contained in:
commit
501d579a90
35 changed files with 11357 additions and 0 deletions
39
network.go
Normal file
39
network.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
// Copyright (C) 2020 Marius Schellenberger
|
||||
|
||||
package pve
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type NetworkDevice struct {
|
||||
Type string
|
||||
MACAddress string
|
||||
Bridge string
|
||||
}
|
||||
|
||||
func (n *NetworkDevice) String() string {
|
||||
return fmt.Sprintf("%s=%s,bridge=%s", n.Type, n.MACAddress, n.Bridge)
|
||||
}
|
||||
func parseNetworkDevice(s string) (n *NetworkDevice) {
|
||||
cfg := strings.Split(s, ",")
|
||||
if len(cfg) < 2 {
|
||||
return
|
||||
}
|
||||
n = new(NetworkDevice)
|
||||
for _, dev := range []string{"virtio", "e1000", "rtl8139", "vmxnet3"} {
|
||||
if strings.HasPrefix(cfg[0], dev) {
|
||||
n.Type = dev
|
||||
n.MACAddress = cfg[0][len(dev)+1:]
|
||||
break
|
||||
}
|
||||
}
|
||||
for _, o := range cfg {
|
||||
if strings.HasPrefix(o, "bridge=") {
|
||||
n.Bridge = o[7:]
|
||||
break
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue