From 758cf50fe87ab8b0a3f9259d2ecb1c985b2378b9 Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Thu, 12 Feb 2015 15:44:22 +0000 Subject: [PATCH 01/12] Adding support for ec2 network_interfaces --- Gemfile | 4 ++++ lib/vagrant-aws/action/run_instance.rb | 4 +++- lib/vagrant-aws/config.rb | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 4211d5ce..4062e6cc 100644 --- a/Gemfile +++ b/Gemfile @@ -8,3 +8,7 @@ group :development do # Vagrant environment itself using `vagrant plugin`. gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git" end + +group :plugins do + gem "vagrant-aws", path: "." +end diff --git a/lib/vagrant-aws/action/run_instance.rb b/lib/vagrant-aws/action/run_instance.rb index 0eede22b..5bd0f01a 100644 --- a/lib/vagrant-aws/action/run_instance.rb +++ b/lib/vagrant-aws/action/run_instance.rb @@ -43,6 +43,7 @@ def call(env) monitoring = region_config.monitoring ebs_optimized = region_config.ebs_optimized associate_public_ip = region_config.associate_public_ip + network_interfaces = region_config.network_interfaces # If there is no keypair then warn the user if !keypair @@ -90,7 +91,8 @@ def call(env) :instance_initiated_shutdown_behavior => terminate_on_shutdown == true ? "terminate" : nil, :monitoring => monitoring, :ebs_optimized => ebs_optimized, - :associate_public_ip => associate_public_ip + :associate_public_ip => associate_public_ip, + :network_interfaces => network_interfaces } if !security_groups.empty? security_group_key = options[:subnet_id].nil? ? :groups : :security_group_ids diff --git a/lib/vagrant-aws/config.rb b/lib/vagrant-aws/config.rb index ee2a58b8..d3072269 100644 --- a/lib/vagrant-aws/config.rb +++ b/lib/vagrant-aws/config.rb @@ -144,6 +144,12 @@ class Config < Vagrant.plugin("2", :config) # @return [String] attr_accessor :elb + # The additional network adapters which should + # be attached to instance + # + # @return [Array] + attr_accessor :network_interfaces + def initialize(region_specific=false) @access_key_id = UNSET_VALUE @ami = UNSET_VALUE @@ -171,6 +177,7 @@ def initialize(region_specific=false) @ebs_optimized = UNSET_VALUE @associate_public_ip = UNSET_VALUE @elb = UNSET_VALUE + @network_interfaces = [] # Internal state (prefix with __ so they aren't automatically # merged) @@ -362,7 +369,7 @@ def validate(machine) end errors << I18n.interpolate("vagrant_aws.config.ami_required", :region => @region) if config.ami.nil? - end + end { "AWS Provider" => errors } end From 3e6bd0dca4a2312ba75151e0e01da3d8a8087773 Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Thu, 12 Feb 2015 17:38:19 +0000 Subject: [PATCH 02/12] changing to add adapters after machine is up, otherwise cannot get public ip assigned --- lib/vagrant-aws/action.rb | 2 ++ .../action/network_adapters_register.rb | 28 +++++++++++++++++++ lib/vagrant-aws/action/run_instance.rb | 6 ++-- lib/vagrant-aws/config.rb | 4 +-- lib/vagrant-aws/util/network_adapters.rb | 12 ++++++++ 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 lib/vagrant-aws/action/network_adapters_register.rb create mode 100644 lib/vagrant-aws/util/network_adapters.rb diff --git a/lib/vagrant-aws/action.rb b/lib/vagrant-aws/action.rb index 2f160dc0..cb80ef65 100644 --- a/lib/vagrant-aws/action.rb +++ b/lib/vagrant-aws/action.rb @@ -142,6 +142,7 @@ def self.action_up else b1.use action_prepare_boot b1.use RunInstance # launch a new instance + b1.use RegisterAdditionalNetworkInterfaces end end end @@ -189,6 +190,7 @@ def self.action_reload autoload :WarnNetworks, action_root.join("warn_networks") autoload :ElbRegisterInstance, action_root.join("elb_register_instance") autoload :ElbDeregisterInstance, action_root.join("elb_deregister_instance") + autoload :RegisterAdditionalNetworkInterfaces, action_root.join("network_adapters_register") end end end diff --git a/lib/vagrant-aws/action/network_adapters_register.rb b/lib/vagrant-aws/action/network_adapters_register.rb new file mode 100644 index 00000000..d2b6fe92 --- /dev/null +++ b/lib/vagrant-aws/action/network_adapters_register.rb @@ -0,0 +1,28 @@ +require 'vagrant-aws/util/network_adapters' + +module VagrantPlugins + module AWS + module Action + class RegisterAdditionalNetworkInterfaces + include ElasticLoadBalancer + + def initialize(app, env) + @app = app + @logger = Log4r::Logger.new("vagrant_aws::action::network_adapters_register") + end + + def call(env) + + @app.call(env) + + interfaces = env[:machine].provider_config.additional_network_interfaces + + interfaces.each do |intf| + register_adapter env, intf[:device_index], intf[:subnet_id], intf[:security_groups], env[:machine].id + end + + end + end + end + end +end diff --git a/lib/vagrant-aws/action/run_instance.rb b/lib/vagrant-aws/action/run_instance.rb index 5bd0f01a..2c165206 100644 --- a/lib/vagrant-aws/action/run_instance.rb +++ b/lib/vagrant-aws/action/run_instance.rb @@ -42,8 +42,7 @@ def call(env) iam_instance_profile_name = region_config.iam_instance_profile_name monitoring = region_config.monitoring ebs_optimized = region_config.ebs_optimized - associate_public_ip = region_config.associate_public_ip - network_interfaces = region_config.network_interfaces + associate_public_ip = region_config.associate_public_ip # If there is no keypair then warn the user if !keypair @@ -91,8 +90,7 @@ def call(env) :instance_initiated_shutdown_behavior => terminate_on_shutdown == true ? "terminate" : nil, :monitoring => monitoring, :ebs_optimized => ebs_optimized, - :associate_public_ip => associate_public_ip, - :network_interfaces => network_interfaces + :associate_public_ip => associate_public_ip } if !security_groups.empty? security_group_key = options[:subnet_id].nil? ? :groups : :security_group_ids diff --git a/lib/vagrant-aws/config.rb b/lib/vagrant-aws/config.rb index d3072269..b0070e42 100644 --- a/lib/vagrant-aws/config.rb +++ b/lib/vagrant-aws/config.rb @@ -148,7 +148,7 @@ class Config < Vagrant.plugin("2", :config) # be attached to instance # # @return [Array] - attr_accessor :network_interfaces + attr_accessor :additional_network_interfaces def initialize(region_specific=false) @access_key_id = UNSET_VALUE @@ -177,7 +177,7 @@ def initialize(region_specific=false) @ebs_optimized = UNSET_VALUE @associate_public_ip = UNSET_VALUE @elb = UNSET_VALUE - @network_interfaces = [] + @additional_network_interfaces = [] # Internal state (prefix with __ so they aren't automatically # merged) diff --git a/lib/vagrant-aws/util/network_adapters.rb b/lib/vagrant-aws/util/network_adapters.rb new file mode 100644 index 00000000..e6bc54da --- /dev/null +++ b/lib/vagrant-aws/util/network_adapters.rb @@ -0,0 +1,12 @@ +module VagrantPlugins + module AWS + module NetworkAdapter + + def register_adapter(env, device_index, subnet_id, security_groups, instance_id) + interface = env[:aws_compute].network_interfaces.create(:subnet_id => subnet_id, :group_set => security_groups ) + ec2.attach_network_interface(interface.network_interface_id, instance_id, device_index) + end + + end + end +end From 87419c5d62622fbe96e1f844e8c56b4ebfb8f895 Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Thu, 12 Feb 2015 20:12:28 +0000 Subject: [PATCH 03/12] removing the duplicate plugins set up --- Gemfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Gemfile b/Gemfile index b0a4f73c..45704b9d 100644 --- a/Gemfile +++ b/Gemfile @@ -9,10 +9,6 @@ group :development do gem "vagrant", :git => "https://github.com/mitchellh/vagrant.git" end -group :plugins do - gem "vagrant-aws" , path: "." -end - group :plugins do gem "vagrant-aws", path: "." end From 4da410fcf5e8e3443c0bf2ab4521772369e2f704 Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Fri, 13 Feb 2015 11:24:41 +0000 Subject: [PATCH 04/12] putting Gemfile back the way it wa --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 45704b9d..4d52f3a6 100644 --- a/Gemfile +++ b/Gemfile @@ -10,5 +10,5 @@ group :development do end group :plugins do - gem "vagrant-aws", path: "." + gem "vagrant-aws" , path: "." end From ccc88c9a38bff9116ae051966d3c36bde9a2351b Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Fri, 13 Feb 2015 11:50:04 +0000 Subject: [PATCH 05/12] adding docs + logging --- README.md | 29 ++++++++++++++++--- .../action/network_adapters_register.rb | 8 +++-- lib/vagrant-aws/util/network_adapters.rb | 2 +- locales/en.yml | 2 ++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c0b2734a..d5da788f 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,7 @@ This provider exposes quite a few provider-specific configuration options: for credentials. * `block_device_mapping` - Amazon EC2 Block Device Mapping Property * `elb` - The ELB name to attach to the instance. +* `additional_network_interfaces` - An array of the extra network interfaces to create and attach once the machine is up These can be set like typical provider-specific configuration: @@ -265,6 +266,29 @@ Vagrant.configure("2") do |config| end ``` +### Additional Network Adapters + +You can add extra network adapters to your instance after boot. + +```ruby +Vagrant.configure("2") do |config| + # ... other stuff + + config.vm.provider "aws" do |aws| + + # subnet & security groups for primary network interface with device index 0 + aws.subnet_id = 'subnet-caba8084' + aws.security_groups = 'sg-edb6e09b' + + # add additonal interfaces after boot + aws.additional_network_interfaces = [ + { :device_index => 1, :subnet_id => 'subnet-2f76b4e7', :security_groups => ['sg-b2a58ce3', 'sg-008f7950']} + { :device_index => 2, :subnet_id => 'subnet-e9725abc', :security_groups => ['sg-0ded8ff6']} + ] + end +end +``` + ## Development To work on the `vagrant-aws` plugin, clone this repository out, and use @@ -283,10 +307,7 @@ $ bundle exec rake If those pass, you're ready to start developing the plugin. You can test the plugin without installing it into your Vagrant environment by just creating a `Vagrantfile` in the top level of this directory (it is gitignored) -and add the following line to your `Vagrantfile` -```ruby -Vagrant.require_plugin "vagrant-aws" -``` + Use bundler to execute Vagrant: ``` $ bundle exec vagrant up --provider=aws diff --git a/lib/vagrant-aws/action/network_adapters_register.rb b/lib/vagrant-aws/action/network_adapters_register.rb index d2b6fe92..a2b71685 100644 --- a/lib/vagrant-aws/action/network_adapters_register.rb +++ b/lib/vagrant-aws/action/network_adapters_register.rb @@ -4,7 +4,7 @@ module VagrantPlugins module AWS module Action class RegisterAdditionalNetworkInterfaces - include ElasticLoadBalancer + include NetworkAdapter def initialize(app, env) @app = app @@ -18,6 +18,10 @@ def call(env) interfaces = env[:machine].provider_config.additional_network_interfaces interfaces.each do |intf| + env[:ui].info(I18n.t("vagrant_aws.creating_network_interface")) + env[:ui].info(" -- Device Index: #{intf[:device_index]}") + env[:ui].info(" -- Subnet ID: #{intf[:subnet_id]}") + env[:ui].info(" -- Security Groups: #{intf[:security_groups]}") register_adapter env, intf[:device_index], intf[:subnet_id], intf[:security_groups], env[:machine].id end @@ -25,4 +29,4 @@ def call(env) end end end -end +end \ No newline at end of file diff --git a/lib/vagrant-aws/util/network_adapters.rb b/lib/vagrant-aws/util/network_adapters.rb index e6bc54da..95bdffdd 100644 --- a/lib/vagrant-aws/util/network_adapters.rb +++ b/lib/vagrant-aws/util/network_adapters.rb @@ -4,7 +4,7 @@ module NetworkAdapter def register_adapter(env, device_index, subnet_id, security_groups, instance_id) interface = env[:aws_compute].network_interfaces.create(:subnet_id => subnet_id, :group_set => security_groups ) - ec2.attach_network_interface(interface.network_interface_id, instance_id, device_index) + env[:aws_compute].attach_network_interface(interface.network_interface_id, instance_id, device_index) end end diff --git a/locales/en.yml b/locales/en.yml index 00513ba6..a74c18f3 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -59,6 +59,8 @@ en: will_not_destroy: |- The instance '%{name}' will not be destroyed, since the confirmation was declined. + creating_network_interface: |- + Creating additional network interface with the following settings... config: access_key_id_required: |- From 8146cdfd6a73becc5022e919ec77f4e3bd633874 Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Fri, 13 Feb 2015 13:33:38 +0000 Subject: [PATCH 06/12] adding unit test for deafult config --- spec/vagrant-aws/config_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/vagrant-aws/config_spec.rb b/spec/vagrant-aws/config_spec.rb index b41588f1..54517ee8 100644 --- a/spec/vagrant-aws/config_spec.rb +++ b/spec/vagrant-aws/config_spec.rb @@ -42,6 +42,7 @@ its("monitoring") { should == false } its("ebs_optimized") { should == false } its("associate_public_ip") { should == false } + its("additional_network_interfaces") { should == [] } end describe "overriding defaults" do From 1dd23e6229c1b95268263d537222dcdcdbcdc21d Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Tue, 17 Feb 2015 15:28:15 +0000 Subject: [PATCH 07/12] destroy network adapters with machine --- lib/vagrant-aws/action.rb | 6 ++-- .../action/network_adapters_destroy.rb | 31 +++++++++++++++++++ lib/vagrant-aws/util/network_adapters.rb | 9 +++++- locales/en.yml | 2 ++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 lib/vagrant-aws/action/network_adapters_destroy.rb diff --git a/lib/vagrant-aws/action.rb b/lib/vagrant-aws/action.rb index 85afb9dd..7e83750d 100644 --- a/lib/vagrant-aws/action.rb +++ b/lib/vagrant-aws/action.rb @@ -51,8 +51,9 @@ def self.action_destroy next end b3.use ConnectAWS - b3.use ElbDeregisterInstance - b3.use TerminateInstance + b3.use DestroyAdditionalNetworkInterfaces + b3.use ElbDeregisterInstance + b3.use TerminateInstance b3.use ProvisionerCleanup if defined?(ProvisionerCleanup) end else @@ -206,6 +207,7 @@ def self.action_reload autoload :ElbRegisterInstance, action_root.join("elb_register_instance") autoload :ElbDeregisterInstance, action_root.join("elb_deregister_instance") autoload :RegisterAdditionalNetworkInterfaces, action_root.join("network_adapters_register") + autoload :DestroyAdditionalNetworkInterfaces, action_root.join("network_adapters_destroy") end end end diff --git a/lib/vagrant-aws/action/network_adapters_destroy.rb b/lib/vagrant-aws/action/network_adapters_destroy.rb new file mode 100644 index 00000000..3ab309aa --- /dev/null +++ b/lib/vagrant-aws/action/network_adapters_destroy.rb @@ -0,0 +1,31 @@ +require 'vagrant-aws/util/network_adapters' + +module VagrantPlugins + module AWS + module Action + class DestroyAdditionalNetworkInterfaces + include NetworkAdapter + + def initialize(app, env) + @app = app + @logger = Log4r::Logger.new("vagrant_aws::action::network_adapters_register") + end + + def call(env) + + interfaces = env[:machine].provider_config.additional_network_interfaces + + interfaces.each do |intf| + env[:ui].info(I18n.t("vagrant_aws.destroy_network_interface")) + env[:ui].info(" -- Device Index: #{intf[:device_index]}") + env[:ui].info(" -- Attached To: #{env[:machine].id}") + destroy_adapter env, intf[:device_index], env[:machine].id + end + + @app.call(env) + + end + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant-aws/util/network_adapters.rb b/lib/vagrant-aws/util/network_adapters.rb index 95bdffdd..8f4f8c42 100644 --- a/lib/vagrant-aws/util/network_adapters.rb +++ b/lib/vagrant-aws/util/network_adapters.rb @@ -6,7 +6,14 @@ def register_adapter(env, device_index, subnet_id, security_groups, instance_id) interface = env[:aws_compute].network_interfaces.create(:subnet_id => subnet_id, :group_set => security_groups ) env[:aws_compute].attach_network_interface(interface.network_interface_id, instance_id, device_index) end + + def destroy_adapter(env, device_index, instance_id) + interface = env[:aws_compute].network_interfaces.all('attachment.instance-id' => instance_id, 'attachment.device-index' => device_index ).first + env[:aws_compute].detach_network_interface(interface.attachment['attachmentId'], true) + interface.wait_for { attachment.nil? || attachment == {} } + interface.destroy + end end end -end +end \ No newline at end of file diff --git a/locales/en.yml b/locales/en.yml index a74c18f3..3ecf381c 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -61,6 +61,8 @@ en: was declined. creating_network_interface: |- Creating additional network interface with the following settings... + destroy_network_interface: |- + Destroying additional network interface... config: access_key_id_required: |- From 05a5abf0f4278732245b5f56a70ff92ee86a94fa Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Tue, 17 Feb 2015 15:42:59 +0000 Subject: [PATCH 08/12] deal with when adapter wasn't attached --- lib/vagrant-aws/util/network_adapters.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-aws/util/network_adapters.rb b/lib/vagrant-aws/util/network_adapters.rb index 8f4f8c42..744b639b 100644 --- a/lib/vagrant-aws/util/network_adapters.rb +++ b/lib/vagrant-aws/util/network_adapters.rb @@ -9,8 +9,16 @@ def register_adapter(env, device_index, subnet_id, security_groups, instance_id) def destroy_adapter(env, device_index, instance_id) interface = env[:aws_compute].network_interfaces.all('attachment.instance-id' => instance_id, 'attachment.device-index' => device_index ).first - env[:aws_compute].detach_network_interface(interface.attachment['attachmentId'], true) - interface.wait_for { attachment.nil? || attachment == {} } + + if interface.nil? + return + end + + if !interface.attachment.nil? && interface.attachment != {} + env[:aws_compute].detach_network_interface(interface.attachment['attachmentId'], true) + interface.wait_for { attachment.nil? || attachment == {} } + end + interface.destroy end From 34c88dab2568ac4a2142195cffb169f2bd719c71 Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Tue, 17 Feb 2015 17:03:19 +0000 Subject: [PATCH 09/12] addtional network adapters can have set ips --- README.md | 13 +++++++++++-- lib/vagrant-aws/action/network_adapters_register.rb | 3 ++- lib/vagrant-aws/util/network_adapters.rb | 10 ++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d5da788f..1abbd179 100644 --- a/README.md +++ b/README.md @@ -282,8 +282,17 @@ Vagrant.configure("2") do |config| # add additonal interfaces after boot aws.additional_network_interfaces = [ - { :device_index => 1, :subnet_id => 'subnet-2f76b4e7', :security_groups => ['sg-b2a58ce3', 'sg-008f7950']} - { :device_index => 2, :subnet_id => 'subnet-e9725abc', :security_groups => ['sg-0ded8ff6']} + { + :device_index => 1, + :subnet_id => 'subnet-2f76b4e7', + :security_groups => ['sg-b2a58ce3', 'sg-008f7950'], + :private_ip_address => '172.16.110.200' #optional + }, + { + :device_index => 2, + :subnet_id => 'subnet-e9725abc', + :security_groups => ['sg-0ded8ff6'] + } ] end end diff --git a/lib/vagrant-aws/action/network_adapters_register.rb b/lib/vagrant-aws/action/network_adapters_register.rb index a2b71685..fe06d757 100644 --- a/lib/vagrant-aws/action/network_adapters_register.rb +++ b/lib/vagrant-aws/action/network_adapters_register.rb @@ -22,7 +22,8 @@ def call(env) env[:ui].info(" -- Device Index: #{intf[:device_index]}") env[:ui].info(" -- Subnet ID: #{intf[:subnet_id]}") env[:ui].info(" -- Security Groups: #{intf[:security_groups]}") - register_adapter env, intf[:device_index], intf[:subnet_id], intf[:security_groups], env[:machine].id + env[:ui].info(" -- IP: #{intf[:private_ip_address]}") + register_adapter env, intf[:device_index], intf[:subnet_id], intf[:security_groups], intf[:private_ip_address], env[:machine].id end end diff --git a/lib/vagrant-aws/util/network_adapters.rb b/lib/vagrant-aws/util/network_adapters.rb index 744b639b..9b2f9535 100644 --- a/lib/vagrant-aws/util/network_adapters.rb +++ b/lib/vagrant-aws/util/network_adapters.rb @@ -2,8 +2,14 @@ module VagrantPlugins module AWS module NetworkAdapter - def register_adapter(env, device_index, subnet_id, security_groups, instance_id) - interface = env[:aws_compute].network_interfaces.create(:subnet_id => subnet_id, :group_set => security_groups ) + def register_adapter(env, device_index, subnet_id, security_groups, private_ip_address, instance_id) + + if private_ip_address.nil? + interface = env[:aws_compute].network_interfaces.create(:subnet_id => subnet_id, :group_set => security_groups ) + else + interface = env[:aws_compute].network_interfaces.create(:subnet_id => subnet_id, :group_set => security_groups, :private_ip_address => private_ip_address ) + end + env[:aws_compute].attach_network_interface(interface.network_interface_id, instance_id, device_index) end From 8de44bbef43eb949cdbd4a1686e8b32c0cb7f249 Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Fri, 20 Feb 2015 11:26:35 +0000 Subject: [PATCH 10/12] adding support for multiple private ips --- lib/vagrant-aws/util/network_adapters.rb | 45 ++++++++++++++++++++---- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/lib/vagrant-aws/util/network_adapters.rb b/lib/vagrant-aws/util/network_adapters.rb index 9b2f9535..664d0cbb 100644 --- a/lib/vagrant-aws/util/network_adapters.rb +++ b/lib/vagrant-aws/util/network_adapters.rb @@ -2,16 +2,49 @@ module VagrantPlugins module AWS module NetworkAdapter + def ip_attributes(ips) + return {} if ips.nil? + + attrs = { 'PrivateIpAddresses.0.Primary' => true } + + if ips.kind_of?(Array) + ips.each_with_index do |ip, i| + attrs["PrivateIpAddresses.#{i}.PrivateIpAddress"] = ip + end + else + attrs["PrivateIpAddresses.0.PrivateIpAddress"] = ips + end + + attrs + end + + def security_group_attributes(security_groups) + attrs = {} + + if security_groups.kind_of?(Array) + security_groups.each_with_index do |sid, i| + attrs["SecurityGroupId.#{i + 1}"] = sid + end + else + attrs["SecurityGroupId.1"] = security_groups + end + + attrs + end + def register_adapter(env, device_index, subnet_id, security_groups, private_ip_address, instance_id) - if private_ip_address.nil? - interface = env[:aws_compute].network_interfaces.create(:subnet_id => subnet_id, :group_set => security_groups ) - else - interface = env[:aws_compute].network_interfaces.create(:subnet_id => subnet_id, :group_set => security_groups, :private_ip_address => private_ip_address ) - end + options = {} + options.merge security_group_attributes(security_groups) + options.merge ip_attributes(private_ip_address) + + interface = env[:aws_compute].create_network_interface( + subnet_id, + options + ) env[:aws_compute].attach_network_interface(interface.network_interface_id, instance_id, device_index) - end + end def destroy_adapter(env, device_index, instance_id) interface = env[:aws_compute].network_interfaces.all('attachment.instance-id' => instance_id, 'attachment.device-index' => device_index ).first From 024af4c4abccd8900ecf4aa78e90f8f4c287b092 Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Fri, 20 Feb 2015 11:54:20 +0000 Subject: [PATCH 11/12] fixing adapter attachment --- lib/vagrant-aws/util/network_adapters.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-aws/util/network_adapters.rb b/lib/vagrant-aws/util/network_adapters.rb index 664d0cbb..76223c8b 100644 --- a/lib/vagrant-aws/util/network_adapters.rb +++ b/lib/vagrant-aws/util/network_adapters.rb @@ -41,9 +41,9 @@ def register_adapter(env, device_index, subnet_id, security_groups, private_ip_a interface = env[:aws_compute].create_network_interface( subnet_id, options - ) + ).body['networkInterface'] - env[:aws_compute].attach_network_interface(interface.network_interface_id, instance_id, device_index) + env[:aws_compute].attach_network_interface(interface['networkInterfaceId'], instance_id, device_index) end def destroy_adapter(env, device_index, instance_id) From 3c2e3f838dfcbdb59abd332261f4fdbbd6dbdf05 Mon Sep 17 00:00:00 2001 From: Peter Beams Date: Fri, 20 Feb 2015 12:06:04 +0000 Subject: [PATCH 12/12] fixing merging of options --- lib/vagrant-aws/util/network_adapters.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-aws/util/network_adapters.rb b/lib/vagrant-aws/util/network_adapters.rb index 76223c8b..55276fed 100644 --- a/lib/vagrant-aws/util/network_adapters.rb +++ b/lib/vagrant-aws/util/network_adapters.rb @@ -35,8 +35,8 @@ def security_group_attributes(security_groups) def register_adapter(env, device_index, subnet_id, security_groups, private_ip_address, instance_id) options = {} - options.merge security_group_attributes(security_groups) - options.merge ip_attributes(private_ip_address) + options.merge! security_group_attributes(security_groups) + options.merge! ip_attributes(private_ip_address) interface = env[:aws_compute].create_network_interface( subnet_id,