make configs settable
This commit is contained in:
parent
3789178234
commit
163f11c397
3 changed files with 40 additions and 0 deletions
16
ipconfig.go
16
ipconfig.go
|
|
@ -8,6 +8,22 @@ import (
|
||||||
|
|
||||||
type IPConfigs []*IPConfig
|
type IPConfigs []*IPConfig
|
||||||
|
|
||||||
|
func (c *IPConfigs) Set(index int, ipc *IPConfig) {
|
||||||
|
l := len(*c)
|
||||||
|
if index >= l {
|
||||||
|
n := make(IPConfigs, index+1)
|
||||||
|
copy(n, *c)
|
||||||
|
n[index] = ipc
|
||||||
|
*c = n
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if l == 0 {
|
||||||
|
*c = append(*c, ipc)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
(*c)[index] = ipc
|
||||||
|
}
|
||||||
|
|
||||||
func (c IPConfigs) Get(index int) *IPConfig {
|
func (c IPConfigs) Get(index int) *IPConfig {
|
||||||
if len(c)-1 >= index {
|
if len(c)-1 >= index {
|
||||||
return c[index]
|
return c[index]
|
||||||
|
|
|
||||||
16
network.go
16
network.go
|
|
@ -9,6 +9,22 @@ import (
|
||||||
|
|
||||||
type NetworkDevices []*NetworkDevice
|
type NetworkDevices []*NetworkDevice
|
||||||
|
|
||||||
|
func (c *NetworkDevices) Set(index int, d *NetworkDevice) {
|
||||||
|
l := len(*c)
|
||||||
|
if index >= l {
|
||||||
|
n := make(NetworkDevices, index+1)
|
||||||
|
copy(n, *c)
|
||||||
|
n[index] = d
|
||||||
|
*c = n
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if l == 0 {
|
||||||
|
*c = append(*c, d)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
(*c)[index] = d
|
||||||
|
}
|
||||||
|
|
||||||
func (c NetworkDevices) Get(index int) *NetworkDevice {
|
func (c NetworkDevices) Get(index int) *NetworkDevice {
|
||||||
if len(c)-1 >= index {
|
if len(c)-1 >= index {
|
||||||
return c[index]
|
return c[index]
|
||||||
|
|
|
||||||
|
|
@ -34,9 +34,17 @@ func (s *Server) body() (httpbody, error) {
|
||||||
userdata, err := s.UserData.String()
|
userdata, err := s.UserData.String()
|
||||||
body["ciuserdata"] = userdata
|
body["ciuserdata"] = userdata
|
||||||
for i, n := range s.NetDevices {
|
for i, n := range s.NetDevices {
|
||||||
|
if n == nil {
|
||||||
|
body["net"+strconv.Itoa(i)] = ""
|
||||||
|
continue
|
||||||
|
}
|
||||||
body["net"+strconv.Itoa(i)] = n.String()
|
body["net"+strconv.Itoa(i)] = n.String()
|
||||||
}
|
}
|
||||||
for i, ip := range s.IPConfig {
|
for i, ip := range s.IPConfig {
|
||||||
|
if ip == nil {
|
||||||
|
body["ipconfig"+strconv.Itoa(i)] = ""
|
||||||
|
continue
|
||||||
|
}
|
||||||
body["ipconfig"+strconv.Itoa(i)] = ip.String()
|
body["ipconfig"+strconv.Itoa(i)] = ip.String()
|
||||||
}
|
}
|
||||||
return body, err
|
return body, err
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue