vagrant-skytap 0.1.1a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.hgignore +22 -0
- data/.project +11 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +85 -0
- data/Gemfile +29 -0
- data/LICENSE +8 -0
- data/README.md +292 -0
- data/Rakefile +31 -0
- data/Vagrantfile.orig +34 -0
- data/bar/checksums.yaml +7 -0
- data/bar/data.tar +0 -0
- data/bar/metadata +242 -0
- data/dummy.box +0 -0
- data/example_box/README.md +13 -0
- data/example_box/metadata.json +3 -0
- data/lib/vagrant-skytap/action/add_vm_to_environment.rb +35 -0
- data/lib/vagrant-skytap/action/create_environment.rb +44 -0
- data/lib/vagrant-skytap/action/delete_environment.rb +26 -0
- data/lib/vagrant-skytap/action/delete_vm.rb +27 -0
- data/lib/vagrant-skytap/action/existence_check.rb +35 -0
- data/lib/vagrant-skytap/action/fetch_environment.rb +32 -0
- data/lib/vagrant-skytap/action/initialize_api_client.rb +28 -0
- data/lib/vagrant-skytap/action/is_running.rb +19 -0
- data/lib/vagrant-skytap/action/is_stopped.rb +19 -0
- data/lib/vagrant-skytap/action/is_suspended.rb +19 -0
- data/lib/vagrant-skytap/action/message_already_created.rb +16 -0
- data/lib/vagrant-skytap/action/message_already_running.rb +16 -0
- data/lib/vagrant-skytap/action/message_environment_url.rb +16 -0
- data/lib/vagrant-skytap/action/message_not_created.rb +16 -0
- data/lib/vagrant-skytap/action/message_will_not_destroy.rb +16 -0
- data/lib/vagrant-skytap/action/mixin_machine_index.rb +22 -0
- data/lib/vagrant-skytap/action/prepare_nfs_settings.rb +46 -0
- data/lib/vagrant-skytap/action/prepare_nfs_valid_ids.rb +28 -0
- data/lib/vagrant-skytap/action/read_ssh_info.rb +23 -0
- data/lib/vagrant-skytap/action/read_state.rb +42 -0
- data/lib/vagrant-skytap/action/run_environment.rb +53 -0
- data/lib/vagrant-skytap/action/run_vm.rb +51 -0
- data/lib/vagrant-skytap/action/set_hostname.rb +31 -0
- data/lib/vagrant-skytap/action/set_up_vm.rb +21 -0
- data/lib/vagrant-skytap/action/stop_environment.rb +43 -0
- data/lib/vagrant-skytap/action/stop_vm.rb +43 -0
- data/lib/vagrant-skytap/action/store_extra_data.rb +35 -0
- data/lib/vagrant-skytap/action/suspend_environment.rb +32 -0
- data/lib/vagrant-skytap/action/suspend_vm.rb +32 -0
- data/lib/vagrant-skytap/action/timed_provision.rb +21 -0
- data/lib/vagrant-skytap/action/update_hardware.rb +37 -0
- data/lib/vagrant-skytap/action.rb +272 -0
- data/lib/vagrant-skytap/api/busyable.rb +37 -0
- data/lib/vagrant-skytap/api/client.rb +127 -0
- data/lib/vagrant-skytap/api/credentials.rb +41 -0
- data/lib/vagrant-skytap/api/environment.rb +99 -0
- data/lib/vagrant-skytap/api/interface.rb +123 -0
- data/lib/vagrant-skytap/api/network.rb +40 -0
- data/lib/vagrant-skytap/api/public_ip.rb +103 -0
- data/lib/vagrant-skytap/api/published_service.rb +90 -0
- data/lib/vagrant-skytap/api/resource.rb +44 -0
- data/lib/vagrant-skytap/api/runstate_operations.rb +63 -0
- data/lib/vagrant-skytap/api/specified_attributes.rb +27 -0
- data/lib/vagrant-skytap/api/vm.rb +88 -0
- data/lib/vagrant-skytap/api/vpn.rb +146 -0
- data/lib/vagrant-skytap/api/vpn_attachment.rb +57 -0
- data/lib/vagrant-skytap/config.rb +106 -0
- data/lib/vagrant-skytap/core_ext/object/blank.rb +82 -0
- data/lib/vagrant-skytap/core_ext/object/tap.rb +8 -0
- data/lib/vagrant-skytap/core_ext/try.rb +42 -0
- data/lib/vagrant-skytap/environment_properties.rb +11 -0
- data/lib/vagrant-skytap/errors.rb +59 -0
- data/lib/vagrant-skytap/plugin.rb +73 -0
- data/lib/vagrant-skytap/properties.rb +42 -0
- data/lib/vagrant-skytap/provider.rb +50 -0
- data/lib/vagrant-skytap/setup_helper.rb +193 -0
- data/lib/vagrant-skytap/util/ip_address.rb +69 -0
- data/lib/vagrant-skytap/util/subnet.rb +97 -0
- data/lib/vagrant-skytap/util/timer.rb +17 -0
- data/lib/vagrant-skytap/version.rb +5 -0
- data/lib/vagrant-skytap/version.rb.orig +5 -0
- data/lib/vagrant-skytap/vm_properties.rb +22 -0
- data/lib/vagrant-skytap.rb +23 -0
- data/locales/en.yml +127 -0
- data/skytap-dummy.box +0 -0
- data/spec/acceptance/base.rb +2 -0
- data/spec/acceptance/provider/halt_spec.rb +3 -0
- data/spec/acceptance/shared/context_skytap.rb +3 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/isolated_environment.rb +45 -0
- data/spec/unit/base.rb +57 -0
- data/spec/unit/config_spec.rb +73 -0
- data/spec/unit/environment_spec.rb +144 -0
- data/spec/unit/skeletons/empty_environment.json +19 -0
- data/spec/unit/skeletons/network1.json +36 -0
- data/spec/unit/skeletons/vm1.json +85 -0
- data/spec/unit/support/dummy_communicator.rb +83 -0
- data/spec/unit/support/dummy_provider.rb +41 -0
- data/spec/unit/support/isolated_environment.rb +217 -0
- data/spec/unit/support/shared/action_synced_folders_context.rb +15 -0
- data/spec/unit/support/shared/base_context.rb +116 -0
- data/spec/unit/support/shared/capability_helpers_context.rb +29 -0
- data/spec/unit/support/shared/plugin_command_context.rb +12 -0
- data/spec/unit/support/shared/skytap_context.rb +3 -0
- data/spec/unit/vm_spec.rb +118 -0
- data/tasks/acceptance.rake +22 -0
- data/tasks/bundler.rake +3 -0
- data/tasks/test.rake +14 -0
- data/vagrant-skytap.gemspec +62 -0
- data/vagrant-spec.config.rb +10 -0
- metadata +247 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'vagrant-skytap/api/resource'
|
2
|
+
require 'vagrant-skytap/api/vpn_attachment'
|
3
|
+
require 'vagrant-skytap/util/subnet'
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module Skytap
|
7
|
+
module API
|
8
|
+
class Network < Resource
|
9
|
+
attr_reader :environment
|
10
|
+
|
11
|
+
reads :id, :subnet, :vpn_attachments
|
12
|
+
|
13
|
+
def initialize(attrs, environment, env)
|
14
|
+
super
|
15
|
+
@environment = environment
|
16
|
+
end
|
17
|
+
|
18
|
+
def refresh(attrs)
|
19
|
+
@vpn_attachments = nil
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def vpn_attachments
|
24
|
+
@vpn_attachments ||= (get_api_attribute('vpn_attachments') || []).collect do |att_attrs|
|
25
|
+
VpnAttachment.new(att_attrs, self, env)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def subnet
|
30
|
+
Util::Subnet.new(get_api_attribute('subnet'))
|
31
|
+
end
|
32
|
+
|
33
|
+
def attachment_for(vpn)
|
34
|
+
vpn = vpn.id unless vpn.is_a?(String)
|
35
|
+
vpn_attachments.detect {|att| att.vpn['id'] == vpn}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'vagrant-skytap/api/resource'
|
2
|
+
|
3
|
+
#TODO:NLA Move this to another class, properly namespaced.
|
4
|
+
class PublicIpChoice
|
5
|
+
attr_reader :env, :ip, :iface, :execution
|
6
|
+
|
7
|
+
def initialize(env, ip, iface)
|
8
|
+
@env = env
|
9
|
+
@ip = ip
|
10
|
+
@iface = iface
|
11
|
+
@execution = AttachmentExecution.make(env, ip, iface)
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_s
|
15
|
+
"#{execution.verb} public IP: #{ip.address}".tap do |ret|
|
16
|
+
if ip.deployed?
|
17
|
+
ret << ' (attached and deployed to another VM)'
|
18
|
+
elsif ip.attached?
|
19
|
+
ret << ' (attached to another VM)'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def choose
|
25
|
+
execution.execute
|
26
|
+
|
27
|
+
host = ip.address
|
28
|
+
port = 22 #TODO:NLA Use constant.
|
29
|
+
[host, port]
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid?
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
class AttachmentExecution
|
37
|
+
def self.make(env, ip, iface)
|
38
|
+
if ip.attached?
|
39
|
+
UseAttachmentExecution.new(env, ip, iface)
|
40
|
+
else
|
41
|
+
AttachAndUseExecution.new(env, ip, iface)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_reader :env, :ip, :iface
|
46
|
+
|
47
|
+
def initialize(env, ip, iface)
|
48
|
+
@env = env
|
49
|
+
@ip = ip
|
50
|
+
@iface = iface
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class UseAttachmentExecution < AttachmentExecution
|
55
|
+
def verb
|
56
|
+
'Use'
|
57
|
+
end
|
58
|
+
|
59
|
+
def execute
|
60
|
+
# No-op
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class AttachAndUseExecution < AttachmentExecution
|
65
|
+
def verb
|
66
|
+
'Attach and use'
|
67
|
+
end
|
68
|
+
|
69
|
+
def execute
|
70
|
+
iface.attach_public_ip(ip)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
module VagrantPlugins
|
76
|
+
module Skytap
|
77
|
+
module API
|
78
|
+
class PublicIp < Resource
|
79
|
+
attr_reader :interface
|
80
|
+
|
81
|
+
reads :id, :address, :nics
|
82
|
+
|
83
|
+
# +interface+ may be nil; i.e., this IP isn't attached to anything.
|
84
|
+
def initialize(attrs, interface, env)
|
85
|
+
super
|
86
|
+
@interface = interface
|
87
|
+
end
|
88
|
+
|
89
|
+
def choice_for_setup(iface)
|
90
|
+
PublicIpChoice.new(env, self, iface)
|
91
|
+
end
|
92
|
+
|
93
|
+
def attached?
|
94
|
+
interface || nics.present?
|
95
|
+
end
|
96
|
+
|
97
|
+
def deployed?
|
98
|
+
nics.any? {|nic_attrs| nic_attrs['deployed']}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'vagrant-skytap/api/resource'
|
2
|
+
|
3
|
+
#TODO:NLA Move this to another class, properly namespaced.
|
4
|
+
class PublishedServiceChoice
|
5
|
+
attr_reader :env, :iface, :service, :execution
|
6
|
+
|
7
|
+
def self.uncreated_choice(env, iface)
|
8
|
+
new(env, iface, nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(env, iface, service=nil)
|
12
|
+
@env = env
|
13
|
+
@iface = iface
|
14
|
+
@service = service
|
15
|
+
@execution = ServiceExecution.make(env, iface, service)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
execution.message
|
20
|
+
end
|
21
|
+
|
22
|
+
def choose
|
23
|
+
execution.execute
|
24
|
+
@service = execution.service
|
25
|
+
[service.external_ip, service.external_port]
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid?
|
29
|
+
service.nil? || service.internal_port == 22 #TODO:NLA Use constant
|
30
|
+
end
|
31
|
+
|
32
|
+
class ServiceExecution
|
33
|
+
def self.make(env, iface, service=nil)
|
34
|
+
if service
|
35
|
+
UseServiceExecution.new(env, iface, service)
|
36
|
+
else
|
37
|
+
CreateAndUseServiceExecution.new(env, iface, service)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
attr_reader :env, :iface, :service
|
42
|
+
|
43
|
+
def initialize(env, iface, service)
|
44
|
+
@env = env
|
45
|
+
@iface = iface
|
46
|
+
@service = service
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class UseServiceExecution < ServiceExecution
|
51
|
+
def message
|
52
|
+
"Use published service #{service.external_ip}:#{service.external_port}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def execute
|
56
|
+
# No-op
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class CreateAndUseServiceExecution < ServiceExecution
|
61
|
+
def message
|
62
|
+
'Create and use published service'
|
63
|
+
end
|
64
|
+
|
65
|
+
def execute
|
66
|
+
@service = iface.create_published_service(22) #TODO:NLA Use constant
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
module VagrantPlugins
|
72
|
+
module Skytap
|
73
|
+
module API
|
74
|
+
class PublishedService < Resource
|
75
|
+
attr_reader :interface
|
76
|
+
|
77
|
+
reads :id, :internal_port, :external_ip, :external_port
|
78
|
+
|
79
|
+
def initialize(attrs, interface, env)
|
80
|
+
super
|
81
|
+
@interface = interface
|
82
|
+
end
|
83
|
+
|
84
|
+
def choice_for_setup
|
85
|
+
PublishedServiceChoice.new(env, self)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'specified_attributes'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Skytap
|
5
|
+
module API
|
6
|
+
class Resource
|
7
|
+
include SpecifiedAttributes
|
8
|
+
|
9
|
+
attr_reader :attrs, :env
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def resource_name
|
13
|
+
name.split("::").last
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(*args)
|
18
|
+
@attrs = args.first
|
19
|
+
@env = args.last
|
20
|
+
end
|
21
|
+
|
22
|
+
def url
|
23
|
+
"/#{self.class.resource_name.downcase}s/#{id}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def reload
|
27
|
+
resp = api_client.get(url)
|
28
|
+
refresh(JSON.load(resp.body))
|
29
|
+
end
|
30
|
+
|
31
|
+
def refresh(attrs)
|
32
|
+
@attrs = attrs
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def api_client
|
39
|
+
env[:api_client]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
require_relative 'busyable'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Skytap
|
6
|
+
module API
|
7
|
+
module RunstateOperations
|
8
|
+
include Busyable
|
9
|
+
|
10
|
+
def run!
|
11
|
+
set_runstate :running
|
12
|
+
end
|
13
|
+
|
14
|
+
def suspend!
|
15
|
+
set_runstate :suspended
|
16
|
+
end
|
17
|
+
|
18
|
+
def stop!
|
19
|
+
set_runstate :stopped
|
20
|
+
end
|
21
|
+
|
22
|
+
def poweroff!
|
23
|
+
set_runstate :halted, :stopped
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_runstate(new_runstate, completed_runstate = nil)
|
27
|
+
completed_runstate ||= new_runstate
|
28
|
+
update_with_retry(runstate: new_runstate)
|
29
|
+
wait_for_runstate(completed_runstate) unless runstate == completed_runstate
|
30
|
+
end
|
31
|
+
|
32
|
+
def wait_until_ready
|
33
|
+
wait_for_runstate :ready
|
34
|
+
end
|
35
|
+
|
36
|
+
def wait_for_runstate(expected_runstate)
|
37
|
+
expected_runstate = expected_runstate.to_s
|
38
|
+
retry_while_resource_busy do
|
39
|
+
unless reload.busy?
|
40
|
+
break if runstate == expected_runstate || expected_runstate == 'ready'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def runstate
|
46
|
+
get_api_attribute('runstate')
|
47
|
+
end
|
48
|
+
|
49
|
+
def busy?
|
50
|
+
runstate == 'busy'
|
51
|
+
end
|
52
|
+
|
53
|
+
def stopped?
|
54
|
+
runstate == 'stopped'
|
55
|
+
end
|
56
|
+
|
57
|
+
def running?
|
58
|
+
runstate == 'running'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Skytap
|
3
|
+
module API
|
4
|
+
module SpecifiedAttributes
|
5
|
+
module ClassMethods
|
6
|
+
def reads(*names)
|
7
|
+
@readables ||= []
|
8
|
+
|
9
|
+
names.each do |name|
|
10
|
+
define_method(name) do
|
11
|
+
get_api_attribute(name.to_s)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_api_attribute(name)
|
18
|
+
attrs.fetch(name.to_s, nil)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.included(base)
|
22
|
+
base.singleton_class.send(:include, ClassMethods)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'vagrant-skytap/api/resource'
|
2
|
+
require 'vagrant-skytap/api/interface'
|
3
|
+
require 'vagrant-skytap/api/credentials'
|
4
|
+
require_relative 'runstate_operations'
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module Skytap
|
8
|
+
module API
|
9
|
+
class Vm < Resource
|
10
|
+
include RunstateOperations
|
11
|
+
|
12
|
+
attr_reader :provider_config
|
13
|
+
attr_reader :environment
|
14
|
+
|
15
|
+
reads :id, :interfaces, :credentials
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def fetch(env, url)
|
19
|
+
resp = env[:api_client].get(url)
|
20
|
+
new(JSON.load(resp.body), env[:environment], env)
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_vm(env)
|
24
|
+
if (environment = env[:environment]) && (machine = env[:machine]) && machine.id
|
25
|
+
environment.get_vm_by_id(machine.id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(attrs, environment, env)
|
31
|
+
super
|
32
|
+
@environment = environment
|
33
|
+
@provider_config = env[:machine].provider_config
|
34
|
+
end
|
35
|
+
|
36
|
+
def refresh(attrs)
|
37
|
+
@interfaces = nil
|
38
|
+
@credentials = nil
|
39
|
+
super
|
40
|
+
end
|
41
|
+
|
42
|
+
def interfaces
|
43
|
+
@interfaces ||= (get_api_attribute('interfaces') || []).collect do |iface_attrs|
|
44
|
+
Interface.new(iface_attrs, self, env)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def credentials
|
49
|
+
@credentials ||= (get_api_attribute('credentials') || []).collect do |cred_attrs|
|
50
|
+
Credentials.new(cred_attrs, self, env)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def hardware
|
55
|
+
get_api_attribute('hardware')
|
56
|
+
end
|
57
|
+
|
58
|
+
def template_id
|
59
|
+
get_api_attribute('template_url') =~ /templates\/(\d+)/
|
60
|
+
$1
|
61
|
+
end
|
62
|
+
|
63
|
+
def delete
|
64
|
+
begin
|
65
|
+
retry_while_resource_busy do
|
66
|
+
api_client.delete(url)
|
67
|
+
break
|
68
|
+
end
|
69
|
+
rescue Errors::OperationFailed => ex
|
70
|
+
raise Errors::OperationFailed, err: 'Failed to delete VM'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def machine
|
75
|
+
env[:machine]
|
76
|
+
end
|
77
|
+
|
78
|
+
def current_machine?
|
79
|
+
id && machine && id == machine.id
|
80
|
+
end
|
81
|
+
|
82
|
+
def communicate_ready?
|
83
|
+
current_machine? && machine.communicate.ready?
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'vagrant-skytap/util/subnet'
|
2
|
+
require 'vagrant-skytap/api/resource'
|
3
|
+
require 'vagrant-skytap/api/vpn_attachment'
|
4
|
+
|
5
|
+
#TODO:NLA Move this to another class, properly namespaced.
|
6
|
+
class VpnChoice
|
7
|
+
attr_reader :env, :vpn, :vm, :iface, :attachment, :execution
|
8
|
+
|
9
|
+
def initialize(env, vpn, vm)
|
10
|
+
@env = env
|
11
|
+
@vpn = vpn
|
12
|
+
@vm = vm
|
13
|
+
@iface = vm.interfaces.select(&:network).tap do |ifaces|
|
14
|
+
unless vpn.nat_enabled?
|
15
|
+
ifaces.select! {|i| vpn.subsumes?(i.network) }
|
16
|
+
end
|
17
|
+
end.first
|
18
|
+
@execution = AttachmentExecution.make(env, vpn, iface)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"#{execution.verb} VPN: #{vpn.name}".tap do |ret|
|
23
|
+
if vpn.nat_enabled?
|
24
|
+
ret << " (NAT-enabled)"
|
25
|
+
else
|
26
|
+
ret << " (local subnet: #{vpn.local_subnet})"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def choose
|
32
|
+
execution.execute
|
33
|
+
|
34
|
+
@iface = vm.reload.interfaces.detect{|i| i.id == iface.id }
|
35
|
+
host = iface.address_for(vpn)
|
36
|
+
port = 22 #TODO:NLA Use constant
|
37
|
+
|
38
|
+
[host, port]
|
39
|
+
end
|
40
|
+
|
41
|
+
def valid?
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
class AttachmentExecution
|
46
|
+
attr_reader :env, :vpn, :iface, :attachment
|
47
|
+
|
48
|
+
def self.make(env, vpn, iface)
|
49
|
+
attachment = iface.attachment_for(vpn)
|
50
|
+
|
51
|
+
if attachment.try(:connected?)
|
52
|
+
UseAttachmentExecution.new(env, vpn, iface, attachment)
|
53
|
+
elsif attachment
|
54
|
+
ConnectAttachmentExecution.new(env, vpn, iface, attachment)
|
55
|
+
else
|
56
|
+
CreateAttachmentExecution.new(env, vpn, iface)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def initialize(env, vpn, iface, attachment=nil)
|
61
|
+
@env = env
|
62
|
+
@vpn = vpn
|
63
|
+
@iface = iface
|
64
|
+
@attachment = attachment
|
65
|
+
end
|
66
|
+
|
67
|
+
def verb
|
68
|
+
raise NotImplementedError.new('Must override')
|
69
|
+
end
|
70
|
+
|
71
|
+
def execute
|
72
|
+
raise NotImplementedError.new('Must override')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class UseAttachmentExecution < AttachmentExecution
|
77
|
+
def verb
|
78
|
+
'Use'
|
79
|
+
end
|
80
|
+
|
81
|
+
def execute
|
82
|
+
# No-op
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class ConnectAttachmentExecution < AttachmentExecution
|
87
|
+
def verb
|
88
|
+
'Connect to and use'
|
89
|
+
end
|
90
|
+
|
91
|
+
def execute
|
92
|
+
attachment.connect!
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class CreateAttachmentExecution < AttachmentExecution
|
97
|
+
def verb
|
98
|
+
'Attach to and use'
|
99
|
+
end
|
100
|
+
|
101
|
+
def execute
|
102
|
+
@attachment = VagrantPlugins::Skytap::API::VpnAttachment.create(iface.network, vpn, env)
|
103
|
+
@attachment.connect!
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
module VagrantPlugins
|
109
|
+
module Skytap
|
110
|
+
module API
|
111
|
+
class Vpn < Resource
|
112
|
+
|
113
|
+
class << self
|
114
|
+
def all(env, options = {})
|
115
|
+
resp = env[:api_client].get('/vpns', options)
|
116
|
+
vpn_attrs = JSON.load(resp.body)
|
117
|
+
vpn_attrs.collect {|attrs| new(attrs, env)}
|
118
|
+
end
|
119
|
+
|
120
|
+
def fetch(env, url, options = {})
|
121
|
+
resp = env[:api_client].get(url, options)
|
122
|
+
new(JSON.load(resp.body), env)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
reads :id, :local_subnet, :name, :nat_local_subnet
|
127
|
+
|
128
|
+
def choice_for_setup(vm)
|
129
|
+
VpnChoice.new(env, self, vm)
|
130
|
+
end
|
131
|
+
|
132
|
+
def nat_enabled?
|
133
|
+
!!nat_local_subnet
|
134
|
+
end
|
135
|
+
|
136
|
+
def subsumes?(network)
|
137
|
+
subnet.subsumes?(network.subnet)
|
138
|
+
end
|
139
|
+
|
140
|
+
def subnet
|
141
|
+
Util::Subnet.new(local_subnet)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'vagrant-skytap/api/resource'
|
2
|
+
require_relative 'busyable'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Skytap
|
6
|
+
module API
|
7
|
+
class VpnAttachment < Resource
|
8
|
+
include Busyable
|
9
|
+
|
10
|
+
attr_reader :network
|
11
|
+
|
12
|
+
reads :connected, :network, :vpn
|
13
|
+
|
14
|
+
def self.create(network, vpn, env)
|
15
|
+
path = "#{base_url(network.id, network.environment.id)}?id=#{vpn.id}"
|
16
|
+
resp = env[:api_client].post(path)
|
17
|
+
body = JSON.load(resp.body)
|
18
|
+
new(body, network, env)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.base_url(network_id, environment_id)
|
22
|
+
"/configurations/#{environment_id}/networks/#{network_id}/vpns"
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(attrs, network, env)
|
26
|
+
super
|
27
|
+
@network = network
|
28
|
+
end
|
29
|
+
|
30
|
+
def url
|
31
|
+
environment_id = network['configuration_id']
|
32
|
+
network_id = network['id']
|
33
|
+
vpn_id = vpn['id']
|
34
|
+
"#{self.class.base_url(network_id, environment_id)}/#{vpn_id}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def nat_enabled?
|
38
|
+
vpn['nat_enabled']
|
39
|
+
end
|
40
|
+
|
41
|
+
def connected?
|
42
|
+
!!connected
|
43
|
+
end
|
44
|
+
|
45
|
+
def connect!
|
46
|
+
update_with_retry(connected: true)
|
47
|
+
raise Errors::VpnConnectionFailed unless connected?
|
48
|
+
end
|
49
|
+
|
50
|
+
def vpn_name
|
51
|
+
vpn['name']
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|