Sha256: 6660e04a65b8556f702966085863438de9fec75ecf7e19fa1474726352d6c2d9

Contents?: true

Size: 1.29 KB

Versions: 15

Compression:

Stored size: 1.29 KB

Contents

require 'vagrant-skytap/api/resource'
require_relative 'busyable'

module VagrantPlugins
  module Skytap
    module API
      class VpnAttachment < Resource
        include Busyable

        attr_reader :network

        reads :connected, :network, :vpn

        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

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

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

        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

        def nat_enabled?
          vpn['nat_enabled']
        end

        def connected?
          !!connected
        end

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

        def vpn_name
          vpn['name']
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
vagrant-skytap-0.2.3 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.2.2 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.2.1 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.2.0 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.11 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.10 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.9 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.8 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.7 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.6 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.5 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.4 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.3 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.2 lib/vagrant-skytap/api/vpn_attachment.rb
vagrant-skytap-0.1.1a lib/vagrant-skytap/api/vpn_attachment.rb