Skip to content

Commit

Permalink
Merge pull request #182 from KohlsTechnology/support-xpn
Browse files Browse the repository at this point in the history
Looks great, thank you @seanmalloy and for the review @Temikus
  • Loading branch information
erjohnso authored Apr 2, 2018
2 parents 19eed45 + 6ae25f9 commit 1287d31
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ will pull the most recent CentOS 7 image. For more info, refer to
e.g. 10/08/2015 13:15:15 is "i-2015081013-15637fda".
* `network` - The name of the network to use for the instance. Default is
"default".
* `network_project_id` - The ID of the GCP project for the network and subnetwork to use for the instance. Default is `google_project_id`.
* `subnetwork` - The name of the subnetwork to use for the instance.
* `tags` - An array of tags to apply to this instance.
* `labels` - Custom key/value pairs of labels to add to the instance.
Expand Down
6 changes: 4 additions & 2 deletions lib/vagrant-google/action/run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
disk_name = zone_config.disk_name
disk_type = zone_config.disk_type
network = zone_config.network
network_project_id = zone_config.network_project_id
subnetwork = zone_config.subnetwork
metadata = zone_config.metadata
labels = zone_config.labels
Expand Down Expand Up @@ -78,6 +79,7 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
env[:ui].info(" -- Instance Group: #{instance_group}")
env[:ui].info(" -- Zone: #{zone}") if zone
env[:ui].info(" -- Network: #{network}") if network
env[:ui].info(" -- Network Project: #{network_project_id}") if network_project_id
env[:ui].info(" -- Subnetwork: #{subnetwork}") if subnetwork
env[:ui].info(" -- Metadata: '#{metadata}'")
env[:ui].info(" -- Labels: '#{labels}'")
Expand All @@ -101,8 +103,8 @@ def call(env) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize

# Munge network configs
if network != 'default'
network = "projects/#{project_id}/global/networks/#{network}"
subnetwork = "projects/#{project_id}/regions/#{zone.split('-')[0..1].join('-')}/subnetworks/#{subnetwork}"
network = "projects/#{network_project_id}/global/networks/#{network}"
subnetwork = "projects/#{network_project_id}/regions/#{zone.split('-')[0..1].join('-')}/subnetworks/#{subnetwork}"
else
network = "global/networks/default"
end
Expand Down
9 changes: 9 additions & 0 deletions lib/vagrant-google/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class Config < Vagrant.plugin("2", :config) # rubocop:disable Metrics/ClassLengt
# @return [String]
attr_accessor :network

# The name of the network_project_id
#
# @return [String]
attr_accessor :network_project_id

# The name of the subnetwork
#
# @return [String]
Expand Down Expand Up @@ -169,6 +174,7 @@ def initialize(zone_specific=false)
@metadata = {}
@name = UNSET_VALUE
@network = UNSET_VALUE
@network_project_id = UNSET_VALUE
@subnetwork = UNSET_VALUE
@tags = []
@labels = {}
Expand Down Expand Up @@ -289,6 +295,9 @@ def finalize! # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedC
# Network defaults to 'default'
@network = "default" if @network == UNSET_VALUE

# Network project id defaults to project_id
@network_project_id = @google_project_id if @network_project_id == UNSET_VALUE

# Subnetwork defaults to nil
@subnetwork = nil if @subnetwork == UNSET_VALUE

Expand Down
2 changes: 1 addition & 1 deletion test/unit/common/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# each of these attributes to "foo" in isolation, and reads the value
# and asserts the proper result comes back out.
[:name, :image, :zone, :instance_ready_timeout, :machine_type, :disk_size, :disk_name, :disk_type,
:network, :metadata, :labels, :can_ip_forward, :external_ip, :autodelete_disk].each do |attribute|
:network, :network_project_id, :metadata, :labels, :can_ip_forward, :external_ip, :autodelete_disk].each do |attribute|

it "should not default #{attribute} if overridden" do
instance.send("#{attribute}=".to_sym, "foo")
Expand Down

0 comments on commit 1287d31

Please sign in to comment.