Class: VagrantPlugins::Skytap::API::VpnAttachment

Inherits:
Resource show all
Includes:
Busyable
Defined in:
lib/vagrant-skytap/api/vpn_attachment.rb

Constant Summary

Constants included from Busyable

Busyable::WAIT_ITERATION_PERIOD, Busyable::WAIT_TIMEOUT

Instance Attribute Summary collapse

Attributes inherited from Resource

#attrs, #env

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Busyable

#retry_while_resource_busy, #update_with_retry

Methods inherited from Resource

#refresh, #reload, resource_name

Methods included from SpecifiedAttributes

#get_api_attribute, included

Constructor Details

#initialize(attrs, network, env) ⇒ VpnAttachment

Returns a new instance of VpnAttachment.



25
26
27
28
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 25

def initialize(attrs, network, env)
  super
  @network = network
end

Instance Attribute Details

#networkObject (readonly)

Returns the value of attribute network.



10
11
12
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 10

def network
  @network
end

Class Method Details

.base_url(network_id, environment_id) ⇒ Object



21
22
23
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 21

def self.base_url(network_id, environment_id)
  "/configurations/#{environment_id}/networks/#{network_id}/vpns"
end

.create(network, vpn, env) ⇒ Object



14
15
16
17
18
19
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 14

def self.create(network, vpn, env)
  path = "#{base_url(network.id, network.environment.id)}?id=#{vpn.id}"
  resp = env[:api_client].post(path)
  body = JSON.load(resp.body)
  new(body, network, env)
end

Instance Method Details

#connect!Object



45
46
47
48
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 45

def connect!
  update_with_retry(connected: true)
  raise Errors::VpnConnectionFailed unless connected?
end

#connected?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 41

def connected?
  !!connected
end

#nat_enabled?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 37

def nat_enabled?
  vpn['nat_enabled']
end

#urlObject



30
31
32
33
34
35
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 30

def url
  environment_id = network['configuration_id']
  network_id = network['id']
  vpn_id = vpn['id']
  "#{self.class.base_url(network_id, environment_id)}/#{vpn_id}"
end

#vpn_nameObject



50
51
52
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 50

def vpn_name
  vpn['name']
end