pkg/gce: use current instance network

The current instance is not necessary in the default network.
This commit is contained in:
Dmitry Vyukov 2018-02-27 11:58:41 +01:00
parent 6d41d29ecd
commit 64482eb948
2 changed files with 8 additions and 3 deletions

View File

@ -31,6 +31,8 @@ type Context struct {
Instance string
InternalIP string
ExternalIP string
Network string
Subnetwork string
computeService *compute.Service
@ -80,6 +82,8 @@ func NewContext() (*Context, error) {
ctx.ExternalIP = ac.NatIP
}
}
ctx.Network = iface.Network
ctx.Subnetwork = iface.Network
}
if ctx.InternalIP == "" {
return nil, fmt.Errorf("failed to get current instance internal IP")
@ -121,7 +125,8 @@ func (ctx *Context) CreateInstance(name, machineType, image, sshkey string) (str
},
NetworkInterfaces: []*compute.NetworkInterface{
&compute.NetworkInterface{
Network: "global/networks/default",
Network: ctx.Network,
Subnetwork: ctx.Subnetwork,
},
},
Scheduling: &compute.Scheduling{

View File

@ -96,8 +96,8 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) {
if err != nil {
return nil, fmt.Errorf("failed to init gce: %v", err)
}
Logf(0, "GCE initialized: running on %v, internal IP %v, project %v, zone %v",
GCE.Instance, GCE.InternalIP, GCE.ProjectID, GCE.ZoneID)
Logf(0, "GCE initialized: running on %v, internal IP %v, project %v, zone %v, net %v/%v",
GCE.Instance, GCE.InternalIP, GCE.ProjectID, GCE.ZoneID, GCE.Network, GCE.Subnetwork)
if cfg.GCE_Image == "" {
cfg.GCE_Image = env.Name