Google driver: add `--google-use-internal-ip-only` flag

This addresses previously-closed issue #2876, which points out that
instances created with the `--google-use-internal-ip` command-line flag
are still assigned an external IP address. The new flag (which implies
the presence of `--google-use-internal-ip` if it isn't specified) will
cause the new instance to have no externally-accessible IP address.

Signed-off-by: Jason Roehm <jroehm@gmail.com>
This commit is contained in:
Jason Roehm 2016-03-01 12:41:19 -05:00
parent d87383e8f3
commit 6789c51b83
2 changed files with 55 additions and 42 deletions

View File

@ -28,6 +28,7 @@ type ComputeUtil struct {
address string address string
preemptible bool preemptible bool
useInternalIP bool useInternalIP bool
useInternalIPOnly bool
service *raw.Service service *raw.Service
zoneURL string zoneURL string
globalURL string globalURL string
@ -65,6 +66,7 @@ func newComputeUtil(driver *Driver) (*ComputeUtil, error) {
address: driver.Address, address: driver.Address,
preemptible: driver.Preemptible, preemptible: driver.Preemptible,
useInternalIP: driver.UseInternalIP, useInternalIP: driver.UseInternalIP,
useInternalIPOnly: driver.UseInternalIPOnly,
service: service, service: service,
zoneURL: apiURL + driver.Project + "/zones/" + driver.Zone, zoneURL: apiURL + driver.Project + "/zones/" + driver.Zone,
globalURL: apiURL + driver.Project + "/global", globalURL: apiURL + driver.Project + "/global",
@ -235,9 +237,6 @@ func (c *ComputeUtil) createInstance(d *Driver) error {
}, },
NetworkInterfaces: []*raw.NetworkInterface{ NetworkInterfaces: []*raw.NetworkInterface{
{ {
AccessConfigs: []*raw.AccessConfig{
{Type: "ONE_TO_ONE_NAT"},
},
Network: c.globalURL + "/networks/default", Network: c.globalURL + "/networks/default",
}, },
}, },
@ -255,6 +254,13 @@ func (c *ComputeUtil) createInstance(d *Driver) error {
}, },
} }
if !c.useInternalIPOnly {
cfg := &raw.AccessConfig{
Type: "ONE_TO_ONE_NAT",
}
instance.NetworkInterfaces[0].AccessConfigs = append(instance.NetworkInterfaces[0].AccessConfigs, cfg)
}
if c.address != "" { if c.address != "" {
staticAddress, err := c.staticAddress() staticAddress, err := c.staticAddress()
if err != nil { if err != nil {

View File

@ -22,6 +22,7 @@ type Driver struct {
Address string Address string
Preemptible bool Preemptible bool
UseInternalIP bool UseInternalIP bool
UseInternalIPOnly bool
Scopes string Scopes string
DiskSize int DiskSize int
Project string Project string
@ -111,6 +112,11 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Use internal GCE Instance IP rather than public one", Usage: "Use internal GCE Instance IP rather than public one",
EnvVar: "GOOGLE_USE_INTERNAL_IP", EnvVar: "GOOGLE_USE_INTERNAL_IP",
}, },
mcnflag.BoolFlag{
Name: "google-use-internal-ip-only",
Usage: "Configure GCE instance to not have an external IP address",
EnvVar: "GOOGLE_USE_INTERNAL_IP_ONLY",
},
mcnflag.BoolFlag{ mcnflag.BoolFlag{
Name: "google-use-existing", Name: "google-use-existing",
Usage: "Don't create a new VM, use an existing one", Usage: "Don't create a new VM, use an existing one",
@ -170,7 +176,8 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.DiskType = flags.String("google-disk-type") d.DiskType = flags.String("google-disk-type")
d.Address = flags.String("google-address") d.Address = flags.String("google-address")
d.Preemptible = flags.Bool("google-preemptible") d.Preemptible = flags.Bool("google-preemptible")
d.UseInternalIP = flags.Bool("google-use-internal-ip") d.UseInternalIP = flags.Bool("google-use-internal-ip") || flags.Bool("google-use-internal-ip-only")
d.UseInternalIPOnly = flags.Bool("google-use-internal-ip-only")
d.Scopes = flags.String("google-scopes") d.Scopes = flags.String("google-scopes")
d.Tags = flags.String("google-tags") d.Tags = flags.String("google-tags")
} }