in fixtures.go [767:813]
func (t *TestVM) AddCustomNetwork(network *Network, subnetwork *Subnetwork) error {
var subnetworkName string
if subnetwork == nil {
subnetworkName = ""
if !*network.network.AutoCreateSubnetworks {
return fmt.Errorf("network %s is not auto mode, subnet is required", network.name)
}
} else {
subnetworkName = subnetwork.name
}
if t.instance != nil {
// Add network config.
networkInterface := compute.NetworkInterface{
Network: network.name,
Subnetwork: subnetworkName,
AccessConfigs: []*compute.AccessConfig{
{
Type: "ONE_TO_ONE_NAT",
},
},
}
if t.instance.NetworkInterfaces == nil {
t.instance.NetworkInterfaces = []*compute.NetworkInterface{&networkInterface}
} else {
t.instance.NetworkInterfaces = append(t.instance.NetworkInterfaces, &networkInterface)
}
} else if t.instancebeta != nil {
// Add network config.
networkInterface := computeBeta.NetworkInterface{
Network: network.name,
Subnetwork: subnetworkName,
AccessConfigs: []*computeBeta.AccessConfig{
{
Type: "ONE_TO_ONE_NAT",
},
},
}
if t.instancebeta.NetworkInterfaces == nil {
t.instancebeta.NetworkInterfaces = []*computeBeta.NetworkInterface{&networkInterface}
} else {
t.instancebeta.NetworkInterfaces = append(t.instancebeta.NetworkInterfaces, &networkInterface)
}
}
return nil
}