initial commit
This commit is contained in:
commit
501d579a90
35 changed files with 11357 additions and 0 deletions
62
ipconfig.go
Normal file
62
ipconfig.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
// Copyright (C) 2020 Marius Schellenberger
|
||||
|
||||
package pve
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type IPConfig struct {
|
||||
IPv4CIDR string
|
||||
IPv4Gateway string
|
||||
IPv6CIDR string
|
||||
IPv6Gateway string
|
||||
MTU string
|
||||
}
|
||||
|
||||
func (c *IPConfig) String() string {
|
||||
var str []string
|
||||
if c.IPv4CIDR != "" {
|
||||
str = append(str, "ip="+c.IPv4CIDR)
|
||||
if c.IPv4Gateway != "" {
|
||||
str = append(str, "gw="+c.IPv4Gateway)
|
||||
}
|
||||
}
|
||||
if c.IPv6CIDR != "" {
|
||||
str = append(str, "ip6="+c.IPv6CIDR)
|
||||
if c.IPv6Gateway != "" {
|
||||
str = append(str, "gw6="+c.IPv6Gateway)
|
||||
}
|
||||
}
|
||||
if c.MTU != "" {
|
||||
str = append(str, "mtu="+c.MTU)
|
||||
}
|
||||
return strings.Join(str, ",")
|
||||
}
|
||||
|
||||
func parseIPConfig(s string) (c *IPConfig) {
|
||||
cfg := strings.Split(s, ",")
|
||||
if len(cfg) == 0 {
|
||||
return
|
||||
}
|
||||
c = new(IPConfig)
|
||||
for _, val := range cfg {
|
||||
v := strings.Split(val, "=")
|
||||
if len(v) != 2 {
|
||||
continue
|
||||
}
|
||||
switch v[0] {
|
||||
case "ip":
|
||||
c.IPv4CIDR = v[1]
|
||||
case "gw":
|
||||
c.IPv4Gateway = v[1]
|
||||
case "ip6":
|
||||
c.IPv6CIDR = v[1]
|
||||
case "gw6":
|
||||
c.IPv6Gateway = v[1]
|
||||
case "mtu":
|
||||
c.MTU = v[1]
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue