Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementing #160 #203

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/vagrant-google/action/run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -113,11 +115,21 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
network = "global/networks/default"
end


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole block should not be necessary as we've implemented the change in fog-google

base_network_interfaces = { :network => network, :subnetwork => subnetwork }

if internal_ip != false
base_network_interfaces[:network_ip] = 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
Expand Down Expand Up @@ -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,
:network_ip => internal_ip,
:disks => [disk.get_as_boot_disk(true, autodelete_disk)],
:scheduling => scheduling,
:service_accounts => service_accounts
Expand Down
6 changes: 6 additions & 0 deletions lib/vagrant-google/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-google/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
# limitations under the License.
module VagrantPlugins
module Google
VERSION = "2.2.0".freeze
VERSION = "2.3.0".freeze
end
end
2 changes: 2 additions & 0 deletions test/unit/common/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down