From 275018e5d47143f7ec128b3ba4ee1828b9468859 Mon Sep 17 00:00:00 2001 From: Matteo Monti Date: Wed, 20 Jun 2018 18:50:32 +0200 Subject: [PATCH 1/2] Implemented private ips --- lib/vagrant-google/action/run_instance.rb | 17 +++++++++++++++-- lib/vagrant-google/config.rb | 6 ++++++ lib/vagrant-google/version.rb | 2 +- test/unit/common/config_test.rb | 2 ++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-google/action/run_instance.rb b/lib/vagrant-google/action/run_instance.rb index 47a94cd..537eac4 100644 --- a/lib/vagrant-google/action/run_instance.rb +++ b/lib/vagrant-google/action/run_instance.rb @@ -60,6 +60,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize can_ip_forward = zone_config.can_ip_forward use_private_ip = zone_config.use_private_ip external_ip = zone_config.external_ip + internal_ip = zone_config.internal_ip preemptible = zone_config.preemptible auto_restart = zone_config.auto_restart on_host_maintenance = zone_config.on_host_maintenance @@ -90,6 +91,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize env[:ui].info(" -- IP Forward: #{can_ip_forward}") env[:ui].info(" -- Use private IP: #{use_private_ip}") env[:ui].info(" -- External IP: #{external_ip}") + env[:ui].info(" -- Internal IP: #{internal_ip}") env[:ui].info(" -- Preemptible: #{preemptible}") env[:ui].info(" -- Auto Restart: #{auto_restart}") env[:ui].info(" -- On Maintenance: #{on_host_maintenance}") @@ -113,11 +115,21 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize network = "global/networks/default" end + + base_network_interfaces = { :network => network, :subnetwork => subnetwork } + + if internal_ip != false + base_network_interfaces[:networkIP] = internal_ip + end + if external_ip == false # No external IP - network_interfaces = [ { :network => network, :subnetwork => subnetwork } ] + network_interfaces = [ base_network_interfaces ] else - network_interfaces = [ { :network => network, :subnetwork => subnetwork, :access_configs => [{:name => 'External NAT', :type => 'ONE_TO_ONE_NAT'}]} ] + + base_network_interfaces[:access_configs] = [{:name => 'External NAT', :type => 'ONE_TO_ONE_NAT'}] + + network_interfaces = [ base_network_interfaces ] end # Munge scheduling configs @@ -176,6 +188,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize :can_ip_forward => can_ip_forward, :use_private_ip => use_private_ip, :external_ip => external_ip, + :internal_ip => internal_ip, :disks => [disk.get_as_boot_disk(true, autodelete_disk)], :scheduling => scheduling, :service_accounts => service_accounts diff --git a/lib/vagrant-google/config.rb b/lib/vagrant-google/config.rb index 72e079a..a8c56fd 100644 --- a/lib/vagrant-google/config.rb +++ b/lib/vagrant-google/config.rb @@ -117,6 +117,11 @@ class Config < Vagrant.plugin("2", :config) # rubocop:disable Metrics/ClassLengt # @return String attr_accessor :external_ip + # The internal IP Address to use + # + # @return String + attr_accessor :internal_ip + # Use private ip address # # @return Boolean @@ -194,6 +199,7 @@ def initialize(zone_specific=false) @labels = {} @can_ip_forward = UNSET_VALUE @external_ip = UNSET_VALUE + @internal_ip = UNSET_VALUE @use_private_ip = UNSET_VALUE @autodelete_disk = UNSET_VALUE @preemptible = UNSET_VALUE diff --git a/lib/vagrant-google/version.rb b/lib/vagrant-google/version.rb index bfd9a72..5d6bc67 100644 --- a/lib/vagrant-google/version.rb +++ b/lib/vagrant-google/version.rb @@ -13,6 +13,6 @@ # limitations under the License. module VagrantPlugins module Google - VERSION = "2.2.0".freeze + VERSION = "2.3.0".freeze end end diff --git a/test/unit/common/config_test.rb b/test/unit/common/config_test.rb index b70ddcc..b4aa568 100644 --- a/test/unit/common/config_test.rb +++ b/test/unit/common/config_test.rb @@ -134,6 +134,7 @@ let(:config_network) { "foo" } let(:can_ip_forward) { true } let(:external_ip) { "foo" } + let(:internal_ip) { "foo" } def set_test_values(instance) instance.name = config_name @@ -146,6 +147,7 @@ def set_test_values(instance) instance.zone = config_zone instance.can_ip_forward = can_ip_forward instance.external_ip = external_ip + instance.internal_ip = internal_ip end it "should raise an exception if not finalized" do From 6f61afca9fe3d000fcd8556e67893b4608354fa7 Mon Sep 17 00:00:00 2001 From: Matteo Monti Date: Wed, 20 Jun 2018 22:46:10 +0200 Subject: [PATCH 2/2] fix mispelled var --- lib/vagrant-google/action/run_instance.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-google/action/run_instance.rb b/lib/vagrant-google/action/run_instance.rb index 537eac4..fd8d0dd 100644 --- a/lib/vagrant-google/action/run_instance.rb +++ b/lib/vagrant-google/action/run_instance.rb @@ -119,7 +119,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize base_network_interfaces = { :network => network, :subnetwork => subnetwork } if internal_ip != false - base_network_interfaces[:networkIP] = internal_ip + base_network_interfaces[:network_ip] = internal_ip end if external_ip == false @@ -188,7 +188,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize :can_ip_forward => can_ip_forward, :use_private_ip => use_private_ip, :external_ip => external_ip, - :internal_ip => internal_ip, + :network_ip => internal_ip, :disks => [disk.get_as_boot_disk(true, autodelete_disk)], :scheduling => scheduling, :service_accounts => service_accounts