class EventMachine::WinRM::Server

Attributes

host[RW]
master[RW]

Public Class Methods

new(master, host, options) click to toggle source
# File lib/em-winrm/server.rb, line 28
def initialize(master, host, options)
  @master = master
  @host = host
  @transport = options[:transport] || :plaintext
  @options = options
  @options[:user] = @options.delete(:user) || ENV['USER'] || ENV['USERNAME'] || "unknown"
  @options[:pass] = @options.delete(:password)
  @options[:port] = @options.delete(:port) || 5985
  @options[:basic_auth_only] = true unless defined? @options[:basic_auth_only]
  @options[:no_ssl_peer_verification] = false unless defined? @options[:no_ssl_peer_verification]
end

Public Instance Methods

run_command(data) click to toggle source

create a shell and run command

# File lib/em-winrm/server.rb, line 43
def run_command(data)
  cid = UUIDTools::UUID.random_create.to_s
  EM.epoll
  EM.run do
    EM.defer(proc do
      WinRM::Log.debug("#{@host} => :run_command")
      @shell = Shell.new(client, self)
      @shell.on_output do |out|
        @master.relay_output_from_backend(@host, out)
      end
      @shell.on_error do |error|
        @master.relay_error_from_backend(@host, error)
      end
      @shell.on_close do |result, exit_code|
        @master.command_complete(@host, cid, exit_code)
      end
      @shell.run_command(data)
    end)
  end
  cid
end
unbind() click to toggle source

Notify upstream master that the backend server is done processing the request

# File lib/em-winrm/server.rb, line 69
def unbind
  WinRM::Log.debug("#{@host} => :unbind")
  @master.unbind_backend(@host)
end

Private Instance Methods

client() click to toggle source
# File lib/em-winrm/server.rb, line 76
def client
  @winrm ||= begin
    http_method = ((@transport == :ssl) || @options[:port].to_s=~/(443|5986)/) ? 'https' : 'http' 
    endpoint = "#{http_method}://#{@host}:#{@options[:port]}/wsman"
    client = ::WinRM::WinRMWebService.new(endpoint, @transport, @options)
    client.set_timeout(@options[:operation_timeout]) if @options[:operation_timeout]
    client
  rescue ::WinRM::WinRMAuthorizationError => error
    raise ::WinRM::WinRMAuthorizationError.new("#{error.message}@#{@host}")
  end
end