Class: VNCTunnel
- Inherits:
-
Object
- Object
- VNCTunnel
- Defined in:
- lib/foreman_xen/vnc_tunnel.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(full_url) ⇒ VNCTunnel
constructor
A new instance of VNCTunnel.
- #logger ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(full_url) ⇒ VNCTunnel
Returns a new instance of VNCTunnel.
8 9 10 11 12 13 14 15 16 |
# File 'lib/foreman_xen/vnc_tunnel.rb', line 8 def initialize(full_url) @uri = URI(full_url) logger.info(full_url) self.host = 'localhost' s = TCPServer.new('127.0.0.1', 0) self.port = s.addr[1] s.close @read_from_server = true end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
2 3 4 |
# File 'lib/foreman_xen/vnc_tunnel.rb', line 2 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
2 3 4 |
# File 'lib/foreman_xen/vnc_tunnel.rb', line 2 def port @port end |
Instance Method Details
#logger ⇒ Object
37 38 39 |
# File 'lib/foreman_xen/vnc_tunnel.rb', line 37 def logger Rails.logger end |
#start ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/foreman_xen/vnc_tunnel.rb', line 18 def start client_srv = TCPServer.new('127.0.0.1', port) thr = Thread.new do req = "CONNECT #{@uri.path}?#{@uri.query} HTTP/1.1\r\n\r\n" @srv_socket = TCPSocket.open(@uri.host, 80) @srv_socket.print req header = @srv_socket.readline if header == "HTTP/1.1 200 OK\r\n" @srv_socket.each_line do |line| break if line == "\r\n" end listen client_srv else logger.error "Cannot connect to the conosle located at #{uri} reason: #{header}" raise "Cannot connect to the console located at #{uri} reason: #{header}" end end end |