vagrant-skytap 0.2.10 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/vagrant-skytap/action/check_created.rb +43 -0
  4. data/lib/vagrant-skytap/action/check_running.rb +43 -0
  5. data/lib/vagrant-skytap/action/get_host_vm.rb +52 -0
  6. data/lib/vagrant-skytap/action/prepare_nfs_settings.rb +22 -5
  7. data/lib/vagrant-skytap/action.rb +11 -18
  8. data/lib/vagrant-skytap/api/connectable.rb +50 -0
  9. data/lib/vagrant-skytap/api/environment.rb +10 -5
  10. data/lib/vagrant-skytap/api/interface.rb +9 -0
  11. data/lib/vagrant-skytap/api/network.rb +60 -1
  12. data/lib/vagrant-skytap/api/public_ip.rb +7 -75
  13. data/lib/vagrant-skytap/api/publish_set.rb +4 -0
  14. data/lib/vagrant-skytap/api/published_service.rb +7 -71
  15. data/lib/vagrant-skytap/api/resource.rb +25 -3
  16. data/lib/vagrant-skytap/api/tunnel.rb +69 -0
  17. data/lib/vagrant-skytap/api/vm.rb +10 -2
  18. data/lib/vagrant-skytap/api/vpn.rb +2 -106
  19. data/lib/vagrant-skytap/cap/host_metadata.rb +45 -0
  20. data/lib/vagrant-skytap/connection/public_ip_choice.rb +94 -0
  21. data/lib/vagrant-skytap/connection/published_service_choice.rb +100 -0
  22. data/lib/vagrant-skytap/connection/tunnel_choice.rb +118 -0
  23. data/lib/vagrant-skytap/connection/vpn_choice.rb +132 -0
  24. data/lib/vagrant-skytap/connection.rb +123 -0
  25. data/lib/vagrant-skytap/errors.rb +4 -0
  26. data/lib/vagrant-skytap/plugin.rb +5 -0
  27. data/lib/vagrant-skytap/setup_helper.rb +34 -8
  28. data/lib/vagrant-skytap/version.rb +1 -1
  29. data/locales/en.yml +46 -0
  30. data/spec/unit/actions/prepare_nfs_settings_spec.rb +63 -16
  31. data/spec/unit/cap/host_metadata_spec.rb +43 -0
  32. data/spec/unit/connections/public_ip_choice_spec.rb +57 -0
  33. data/spec/unit/connections/published_service_choice_spec.rb +79 -0
  34. data/spec/unit/connections/tunnel_choice_spec.rb +124 -0
  35. data/spec/unit/connections/vpn_choice_spec.rb +109 -0
  36. data/spec/unit/interface_spec.rb +53 -0
  37. data/spec/unit/network_spec.rb +123 -0
  38. data/spec/unit/setup_helper_spec.rb +59 -19
  39. data/spec/unit/support/api_responses/tunnel1.json +7 -0
  40. data/spec/unit/support/api_responses/vm1.json +12 -1
  41. data/spec/unit/support/shared/rest_api_context.rb +1 -0
  42. data/spec/unit/tunnel_spec.rb +62 -0
  43. data/spec/unit/vm_spec.rb +53 -60
  44. metadata +22 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 489ea945efd6c1515171a6aa12fc3dff169acc6a
4
- data.tar.gz: 9e32a36b3d528047f7f4ab87a2f6a58ec41a75c2
3
+ metadata.gz: 4a5a789108c848d82077b5a1d094a784603116ef
4
+ data.tar.gz: abf71c4beeec288a9d6332dce9c788ef0f9cb957
5
5
  SHA512:
6
- metadata.gz: a14d3e7fd76c84f23128fb04e31650f95cc229aed47b01184b6ab8b548f49b6399c166fe19360854e615378e42d14d1ba2ce2b72a2402490f70f3e3737b46784
7
- data.tar.gz: 7f038b87db83b4568a038eac6feb6f0d178ba567c8577c7465a643bb5760d2c594ccd28de994eca50199de027cdc24f669377005e5af2e7b06c358bf8d6353cf
6
+ metadata.gz: e90ed82be35afc441c0b84a7c270ad30d36ceb5a2010538df3b9fd800bf8cd8fdec755c2f035f34d3ac0a58cf12364c6c8ca1964ba340ef4581c51afcea02319
7
+ data.tar.gz: f3a501db191b0fca564b7401e936854221f0adc77342cc0d153b851e56026204916d20bbe79dbb4ce4075a57410523007e7921a34184f39136e00b7328e67eda
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 0.3.0 (April 13, 2016)
2
+
3
+ * New functionality to support running Vagrant from within a Skytap VM. The connection between host and
4
+ guest will be made over a network tunnel between the two Skytap environments.
5
+ * `vagrant ssh` now shows the expected error when the machine is not running.
6
+ * Support unattended `vagrant up` by automatically choosing the only available connection option.
7
+
1
8
  # 0.2.10 (March 17, 2016)
2
9
 
3
10
  * Fix bug in port forwarding messaging.
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2014-2016 Skytap, Inc.
2
+ #
3
+ # The MIT License (MIT)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ # DEALINGS IN THE SOFTWARE.
22
+
23
+ module VagrantPlugins
24
+ module Skytap
25
+ module Action
26
+ # This middleware checks that the VM is created, and raises an exception
27
+ # if it is not, notifying the user that creation is required.
28
+ class CheckCreated
29
+ def initialize(app, env)
30
+ @app = app
31
+ end
32
+
33
+ def call(env)
34
+ if env[:machine].state.id == :not_created
35
+ raise Vagrant::Errors::VMNotCreatedError
36
+ end
37
+
38
+ @app.call(env)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2014-2016 Skytap, Inc.
2
+ #
3
+ # The MIT License (MIT)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ # DEALINGS IN THE SOFTWARE.
22
+
23
+ module VagrantPlugins
24
+ module Skytap
25
+ module Action
26
+ # This middleware checks that the VM is running, and raises an exception
27
+ # if it is not, notifying the user that the VM must be running.
28
+ class CheckRunning
29
+ def initialize(app, env)
30
+ @app = app
31
+ end
32
+
33
+ def call(env)
34
+ if env[:machine].state.id != :running
35
+ raise Vagrant::Errors::VMNotRunningError
36
+ end
37
+
38
+ @app.call(env)
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,52 @@
1
+ # Copyright (c) 2014-2016 Skytap, Inc.
2
+ #
3
+ # The MIT License (MIT)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ # DEALINGS IN THE SOFTWARE.
22
+
23
+ require "vagrant-skytap/api/vm"
24
+
25
+ module VagrantPlugins
26
+ module Skytap
27
+ module Action
28
+ # If Vagrant is running in a Skytap VM, retrieve the VM's metadata,
29
+ # instantiate the VM, and store the result in env[:vagrant_host_vm].
30
+ # The request does not go through the REST API, so it can be made
31
+ # without an api token.
32
+ class GetHostVM
33
+ def initialize(app, env)
34
+ @app = app
35
+ @logger = Log4r::Logger.new("vagrant_skytap::action::get_host_metadata")
36
+ end
37
+
38
+ def call(env)
39
+ unless env[:vagrant_host_vm]
40
+ if metadata = env[:machine].provider.capability(:host_metadata)
41
+ # The environment will be lazy loaded
42
+ env[:vagrant_host_vm] = vm = API::Vm.new(metadata, nil, env)
43
+ @logger.info("Running Vagrant in a Skytap VM. ID: #{vm.try(:id)}")
44
+ end
45
+ end
46
+
47
+ @app.call(env)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -20,11 +20,15 @@
20
20
  # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
21
  # DEALINGS IN THE SOFTWARE.
22
22
 
23
+ require_relative 'action_helpers'
24
+
23
25
  module VagrantPlugins
24
26
  module Skytap
25
27
  module Action
26
28
  class PrepareNFSSettings
27
- attr_reader :env, :machine
29
+ include ActionHelpers
30
+
31
+ attr_reader :env, :machine, :host_vm
28
32
 
29
33
  def initialize(app,env)
30
34
  @app = app
@@ -34,6 +38,7 @@ module VagrantPlugins
34
38
 
35
39
  def call(env)
36
40
  @machine = env[:machine]
41
+ @host_vm = env[:vagrant_host_vm]
37
42
 
38
43
  if using_nfs?
39
44
  env[:nfs_host_ip] = read_host_ip
@@ -59,13 +64,25 @@ module VagrantPlugins
59
64
  end
60
65
 
61
66
  # Returns the IP address of the host, preferring one on an interface
62
- # which the client can route to.
67
+ # which the client can route to. If we're running in a Skytap VM, and
68
+ # the guest's network is NAT-enabled, the host VM will have been
69
+ # assigned a NAT address which can be determined from its metadata.
63
70
  #
64
71
  # @return [String]
65
72
  def read_host_ip
66
- UDPSocket.open do |s|
67
- s.connect(machine.ssh_info[:host], 1)
68
- s.addr.last
73
+ if host_vm
74
+ host_iface = host_vm.reload.interfaces.first
75
+ guest_network = current_vm(env).interfaces.first.network
76
+ end
77
+
78
+ if guest_network.try(:nat_enabled?)
79
+ host_iface.nat_address_for_network(guest_network)
80
+ else
81
+ UDPSocket.open do |s|
82
+ s.connect(machine.ssh_info[:host], 1)
83
+ @logger.debug("PrepareNFSSettings#read_host_ip found the following addresses #{s.addr}")
84
+ s.addr.last
85
+ end
69
86
  end.tap do |ret|
70
87
  @logger.debug("PrepareNFSSettings#read_host_ip returning #{ret}")
71
88
  end
@@ -171,29 +171,17 @@ module VagrantPlugins
171
171
  # This action is called to SSH into the machine.
172
172
  def self.action_ssh
173
173
  Vagrant::Action::Builder.new.tap do |b|
174
- b.use action_fetch_environment
175
- b.use Call, ExistenceCheck do |env1, b1|
176
- case result = env1[:result]
177
- when :missing_environment, :missing_vm, :no_vms
178
- b1.use MessageNotCreated
179
- else
180
- b1.use SSHExec
181
- end
182
- end
174
+ b.use CheckCreated
175
+ b.use CheckRunning
176
+ b.use SSHExec
183
177
  end
184
178
  end
185
179
 
186
180
  def self.action_ssh_run
187
181
  Vagrant::Action::Builder.new.tap do |b|
188
- b.use action_fetch_environment
189
- b.use Call, ExistenceCheck do |env1, b1|
190
- case result = env1[:result]
191
- when :missing_environment, :missing_vm, :no_vms
192
- b1.use MessageNotCreated
193
- else
194
- b1.use SSHRun
195
- end
196
- end
182
+ b.use CheckCreated
183
+ b.use CheckRunning
184
+ b.use SSHRun
197
185
  end
198
186
  end
199
187
 
@@ -204,6 +192,7 @@ module VagrantPlugins
204
192
  # later in the sequence.
205
193
  def self.action_prepare_boot
206
194
  Vagrant::Action::Builder.new.tap do |b|
195
+ b.use GetHostVM
207
196
  b.use PrepareNFSSettings
208
197
  b.use PrepareNFSValidIds
209
198
  b.use Provision
@@ -258,6 +247,7 @@ module VagrantPlugins
258
247
  def self.action_update_hardware
259
248
  Vagrant::Action::Builder.new.tap do |b|
260
249
  b.use StoreExtraData
250
+ b.use GetHostVM
261
251
  b.use SetUpVm
262
252
  b.use Call, IsStopped do |env, b1|
263
253
  if env[:result]
@@ -342,6 +332,8 @@ module VagrantPlugins
342
332
  action_root = Pathname.new(File.expand_path("../action", __FILE__))
343
333
  autoload :StoreExtraData, action_root.join("store_extra_data")
344
334
  autoload :AddVmToEnvironment, action_root.join("add_vm_to_environment")
335
+ autoload :CheckCreated, action_root.join("check_created")
336
+ autoload :CheckRunning, action_root.join("check_running")
345
337
  autoload :ClearForwardedPorts, action_root.join("clear_forwarded_ports")
346
338
  autoload :ComposeEnvironment, action_root.join("compose_environment")
347
339
  autoload :CreateEnvironment, action_root.join("create_environment")
@@ -350,6 +342,7 @@ module VagrantPlugins
350
342
  autoload :ExistenceCheck, action_root.join("existence_check")
351
343
  autoload :FetchEnvironment, action_root.join("fetch_environment")
352
344
  autoload :ForwardPorts, action_root.join("forward_ports")
345
+ autoload :GetHostVM, action_root.join("get_host_vm")
353
346
  autoload :InitializeAPIClient, action_root.join("initialize_api_client")
354
347
  autoload :InitialState, action_root.join("initial_state")
355
348
  autoload :IsParallelized, action_root.join("is_parallelized")
@@ -0,0 +1,50 @@
1
+ # Copyright (c) 2014-2016 Skytap, Inc.
2
+ #
3
+ # The MIT License (MIT)
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ # DEALINGS IN THE SOFTWARE.
22
+
23
+ require 'vagrant-skytap/connection'
24
+
25
+ module VagrantPlugins
26
+ module Skytap
27
+ module API
28
+ module Connectable
29
+ # Determine the corresponding [Connection::Choice] subclass for this
30
+ # resource type; e.g. for [API::Vpn] this would return
31
+ # [Connection::VpnChoice]. This method may be overridden where the
32
+ # class name varies from this pattern.
33
+ #
34
+ # @return [Class]
35
+ def connection_choice_class
36
+ require "vagrant-skytap/connection/#{self.class.rest_name}_choice"
37
+ Class.const_get("VagrantPlugins::Skytap::Connection::#{self.class.name.split('::').last}Choice")
38
+ end
39
+
40
+ # Return a choice object representing the potential to connect
41
+ # via this resource. Arguments depend on resource type.
42
+ #
43
+ # @return [Connection::Choice]
44
+ def choice_for_setup(*args)
45
+ connection_choice_class.new(env, self, *args)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -100,7 +100,7 @@ module VagrantPlugins
100
100
  attr_reader :provider_config
101
101
  attr_reader :vms, :networks
102
102
 
103
- reads :id, :name, :vms, :networks, :region, :runstate, :url, :region
103
+ reads :id, :name, :vms, :networks, :region, :runstate, :url, :routable
104
104
 
105
105
  def initialize(attrs, env)
106
106
  super
@@ -133,10 +133,6 @@ module VagrantPlugins
133
133
  end
134
134
  end
135
135
 
136
- def region
137
- get_api_attribute('region')
138
- end
139
-
140
136
  def refresh(attrs)
141
137
  @vms = nil
142
138
  @networks = nil
@@ -185,6 +181,15 @@ module VagrantPlugins
185
181
  def properties
186
182
  @properties ||= EnvironmentProperties.new(env[:machine].env.local_data_path)
187
183
  end
184
+
185
+ # Indicates whether traffic will be routed between networks within this
186
+ # environment. (This is different from routing traffic to/from a network
187
+ # within another environment, which requires an ICNR tunnel.)
188
+ #
189
+ # @return [Boolean]
190
+ def routable?
191
+ !!routable
192
+ end
188
193
  end
189
194
  end
190
195
  end
@@ -86,6 +86,11 @@ module VagrantPlugins
86
86
  end
87
87
  end
88
88
 
89
+ def nat_address_for_network(network)
90
+ nat_address = network_nat_addresses.find{|addr| addr['network_id'].to_i == network.id.to_i}
91
+ nat_address['ip_address'] if nat_address
92
+ end
93
+
89
94
  def vpn_attachments
90
95
  if network
91
96
  network.vpn_attachments
@@ -98,6 +103,10 @@ module VagrantPlugins
98
103
  nat_addresses['vpn_nat_addresses'] || []
99
104
  end
100
105
 
106
+ def network_nat_addresses
107
+ nat_addresses['network_nat_addresses'] || []
108
+ end
109
+
101
110
  def nat_addresses
102
111
  get_api_attribute('nat_addresses') || {}
103
112
  end
@@ -22,23 +22,32 @@
22
22
 
23
23
  require 'vagrant-skytap/api/resource'
24
24
  require 'vagrant-skytap/api/vpn_attachment'
25
+ require 'vagrant-skytap/api/tunnel'
25
26
  require 'vagrant-skytap/util/subnet'
27
+ require 'vagrant-skytap/api/connectable'
26
28
 
27
29
  module VagrantPlugins
28
30
  module Skytap
29
31
  module API
30
32
  class Network < Resource
33
+ include Connectable
34
+
31
35
  attr_reader :environment
32
36
 
33
- reads :id, :subnet, :vpn_attachments
37
+ reads :id, :subnet, :nat_subnet, :vpn_attachments, :name
34
38
 
35
39
  def initialize(attrs, environment, env)
36
40
  super
37
41
  @environment = environment
38
42
  end
39
43
 
44
+ def url
45
+ "/configurations/#{environment.id}/networks/#{id}"
46
+ end
47
+
40
48
  def refresh(attrs)
41
49
  @vpn_attachments = nil
50
+ @tunnels = nil
42
51
  super
43
52
  end
44
53
 
@@ -56,6 +65,56 @@ module VagrantPlugins
56
65
  vpn = vpn.id unless vpn.is_a?(String)
57
66
  vpn_attachments.detect {|att| att.vpn['id'] == vpn}
58
67
  end
68
+
69
+ # Indicates whether this network is NAT-enabled.
70
+ #
71
+ # @return [Boolean]
72
+ def nat_enabled?
73
+ nat_subnet.present?
74
+ end
75
+
76
+ # Indicates whether networks in other environments may connect
77
+ # to this one.
78
+ #
79
+ # @return [Boolean]
80
+ def tunnelable?
81
+ get_api_attribute('tunnelable')
82
+ end
83
+
84
+ # The set of ICNR tunnels connecting this network to networks in other
85
+ # environments.
86
+ #
87
+ # @returns [Array] of [API::Tunnel]
88
+ def tunnels
89
+ @tunnels ||= (get_api_attribute('tunnels') || []).collect do |tunnel_attrs|
90
+ Tunnel.new(tunnel_attrs, env)
91
+ end
92
+ end
93
+
94
+ # Connects to a network in another environment via an ICNR tunnel.
95
+ #
96
+ # @param [API::Network] other_network The network to connect to.
97
+ def connect_to_network(other_network)
98
+ API::Tunnel.create!(env, self, other_network)
99
+ updated_network = environment.reload.networks.find{|n| n.id == id}
100
+ refresh(updated_network.attrs)
101
+ end
102
+
103
+ # Indicates whether an ICNR tunnel exists between this network and the
104
+ # given network in another environment. (For networks within the same
105
+ # environment, check the environment's #routable? flag instead.)
106
+ #
107
+ # @return [Boolean]
108
+ def connected_to_network?(other_network)
109
+ tunnels.any? do |tunnel|
110
+ tunnel.target_network.id == other_network.id || tunnel.source_network.id == other_network.id
111
+ end
112
+ end
113
+
114
+ def connection_choice_class
115
+ require "vagrant-skytap/connection/tunnel_choice"
116
+ Class.const_get("VagrantPlugins::Skytap::Connection::TunnelChoice")
117
+ end
59
118
  end
60
119
  end
61
120
  end
@@ -21,82 +21,18 @@
21
21
  # DEALINGS IN THE SOFTWARE.
22
22
 
23
23
  require 'vagrant-skytap/api/resource'
24
-
25
- class PublicIpChoice
26
- attr_reader :env, :ip, :iface, :execution
27
-
28
- def initialize(env, ip, iface)
29
- @env = env
30
- @ip = ip
31
- @iface = iface
32
- @execution = AttachmentExecution.make(env, ip, iface)
33
- end
34
-
35
- def to_s
36
- "#{execution.verb} public IP: #{ip.address}".tap do |ret|
37
- if ip.deployed?
38
- ret << ' (attached and deployed to another VM)'
39
- elsif ip.attached?
40
- ret << ' (attached to another VM)'
41
- end
42
- end
43
- end
44
-
45
- def choose
46
- execution.execute
47
-
48
- host = ip.address
49
- port = 22
50
- [host, port]
51
- end
52
-
53
- def valid?
54
- true
55
- end
56
-
57
- class AttachmentExecution
58
- def self.make(env, ip, iface)
59
- if ip.attached?
60
- UseAttachmentExecution.new(env, ip, iface)
61
- else
62
- AttachAndUseExecution.new(env, ip, iface)
63
- end
64
- end
65
-
66
- attr_reader :env, :ip, :iface
67
-
68
- def initialize(env, ip, iface)
69
- @env = env
70
- @ip = ip
71
- @iface = iface
72
- end
73
- end
74
-
75
- class UseAttachmentExecution < AttachmentExecution
76
- def verb
77
- 'Use'
78
- end
79
-
80
- def execute
81
- # No-op
82
- end
83
- end
84
-
85
- class AttachAndUseExecution < AttachmentExecution
86
- def verb
87
- 'Attach and use'
88
- end
89
-
90
- def execute
91
- iface.attach_public_ip(ip)
92
- end
93
- end
94
- end
24
+ require 'vagrant-skytap/api/connectable'
95
25
 
96
26
  module VagrantPlugins
97
27
  module Skytap
98
28
  module API
99
29
  class PublicIp < Resource
30
+ include Connectable
31
+
32
+ def self.rest_name
33
+ "public_ip"
34
+ end
35
+
100
36
  attr_reader :interface
101
37
 
102
38
  reads :id, :address, :nics
@@ -107,10 +43,6 @@ module VagrantPlugins
107
43
  @interface = interface
108
44
  end
109
45
 
110
- def choice_for_setup(iface)
111
- PublicIpChoice.new(env, self, iface)
112
- end
113
-
114
46
  def attached?
115
47
  interface || nics.present?
116
48
  end
@@ -30,6 +30,10 @@ module VagrantPlugins
30
30
  attr_reader :environment
31
31
  reads :id, :url, :desktops_url
32
32
 
33
+ def self.rest_name
34
+ "publish_set"
35
+ end
36
+
33
37
  def initialize(attrs, environment, env)
34
38
  super
35
39
  @environment = environment