예제 #1
0
// Merge ("generate?") guest network configuration from host configuration.
func mergeNetConfig(netconfig *netConfig, guest *gabs.Container) (err error) {
	if guest.ExistsP("hostname") {
		log.Print("Guest already defines hostname, not overriden")
	} else {
		guest.SetP(netconfig.hostname, "hostname")
	}
	if guest.ExistsP("net") {
		return fmt.Errorf("Guest already defines net configuration")
	}
	addrs, _ := guest.ArrayOfSizeP(1, "net.interfaces.vioif0.addrs")
	addr, _ := addrs.ObjectI(0)
	addr.Set("inet", "type")
	addr.Set("static", "method")
	addr.Set(netconfig.ipAddress, "addr")
	gateways, _ := guest.ArrayOfSizeP(1, "net.gateways")
	gw, _ := gateways.ObjectI(0)
	gw.Set("inet", "type")
	gw.Set(netconfig.gateway, "addr")
	dns, _ := guest.ObjectP("net.dns")
	dns.Set(netconfig.dnsServers, "nameservers")
	dns.Set(netconfig.dnsSearch, "search")
	return
}