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

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

Instance Attribute Summary collapse

Attributes inherited from Resource

#attrs, #env

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#delete, #refresh, #reload, rest_name, short_name, #update

Methods included from SpecifiedAttributes

#get_api_attribute, included

Constructor Details

#initialize(attrs, network, env) ⇒ VpnAttachment

Returns a new instance of VpnAttachment.



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

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

Instance Attribute Details

#networkObject (readonly)

Returns the value of attribute network.



29
30
31
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 29

def network
  @network
end

Class Method Details

.base_url(network_id, environment_id) ⇒ Object



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

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

.create(network, vpn, env) ⇒ Object



33
34
35
36
37
38
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 33

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



64
65
66
67
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 64

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

#connected?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 60

def connected?
  !!connected
end

#nat_enabled?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 56

def nat_enabled?
  vpn['nat_enabled']
end

#urlObject



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

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



69
70
71
# File 'lib/vagrant-skytap/api/vpn_attachment.rb', line 69

def vpn_name
  vpn['name']
end