Sha256: 65ea38259b022547576609567cddd627ca304342ab43dc15db4dfdb7b28da079

Contents?: true

Size: 1.86 KB

Versions: 15

Compression:

Stored size: 1.86 KB

Contents

require 'vagrant-skytap/api/resource'

#TODO:NLA Move this to another class, properly namespaced.
class PublishedServiceChoice
  attr_reader :env, :iface, :service, :execution

  def self.uncreated_choice(env, iface)
    new(env, iface, nil)
  end

  def initialize(env, iface, service=nil)
    @env = env
    @iface = iface
    @service = service
    @execution = ServiceExecution.make(env, iface, service)
  end

  def to_s
    execution.message
  end

  def choose
    execution.execute
    @service = execution.service
    [service.external_ip, service.external_port]
  end

  def valid?
    service.nil? || service.internal_port == 22 #TODO:NLA Use constant
  end

  class ServiceExecution
    def self.make(env, iface, service=nil)
      if service
        UseServiceExecution.new(env, iface, service)
      else
        CreateAndUseServiceExecution.new(env, iface, service)
      end
    end

    attr_reader :env, :iface, :service

    def initialize(env, iface, service)
      @env = env
      @iface = iface
      @service = service
    end
  end

  class UseServiceExecution < ServiceExecution
    def message
      "Use published service #{service.external_ip}:#{service.external_port}"
    end

    def execute
      # No-op
    end
  end

  class CreateAndUseServiceExecution < ServiceExecution
    def message
      'Create and use published service'
    end

    def execute
      @service = iface.create_published_service(22) #TODO:NLA Use constant
    end
  end
end

module VagrantPlugins
  module Skytap
    module API
      class PublishedService < Resource
        attr_reader :interface

        reads :id, :internal_port, :external_ip, :external_port

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

        def choice_for_setup
          PublishedServiceChoice.new(env, self)
        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/published_service.rb
vagrant-skytap-0.2.2 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.2.1 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.2.0 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.11 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.10 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.9 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.8 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.7 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.6 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.5 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.4 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.3 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.2 lib/vagrant-skytap/api/published_service.rb
vagrant-skytap-0.1.1a lib/vagrant-skytap/api/published_service.rb