@@ -98,6 +98,7 @@ def _close_vterm_local(adapter, lpar_uuid):
9898 :param lpar_uuid: partition uuid
9999 """
100100 lpar_id = _get_lpar_id (adapter , lpar_uuid )
101+ LOG .info ("Invokling rmvterm for lpar id %s" % lpar_id )
101102 _run_proc (['rmvterm' , '--id' , lpar_id ])
102103
103104 # Stop the port.
@@ -182,7 +183,7 @@ def _run_mkvterm_cmd(lpar_uuid, force, codepage=codepage):
182183def open_remotable_vnc_vterm (
183184 adapter , lpar_uuid , local_ip , remote_ips = None , vnc_path = None ,
184185 use_x509_auth = False , ca_certs = None , server_cert = None , server_key = None ,
185- force = False , codepage = "037" ):
186+ force = False , codepage = "037" , vterm_timeout = 300 ):
186187 """Opens a VNC vTerm to a given LPAR. Wraps in some validation.
187188
188189 Must run on the management partition.
@@ -266,8 +267,8 @@ def open_remotable_vnc_vterm(
266267 if remote_port not in _VNC_REMOTE_PORT_TO_LISTENER or listen != 0 :
267268 LOG .info ("Trying VNCSocket Listener" )
268269 listener = _VNCSocketListener (
269- adapter , remote_port , local_ip , verify_vnc_path ,
270- remote_ips = remote_ips )
270+ adapter , lpar_uuid , remote_port , local_ip , verify_vnc_path ,
271+ vterm_timeout , remote_ips = remote_ips )
271272 # If we are doing x509 Authentication, then setup the certificates
272273 if use_x509_auth :
273274 listener .set_x509_certificates (
@@ -336,8 +337,8 @@ class _VNCSocketListener(threading.Thread):
336337 and setup a repeater to forward the data between the two sides.
337338 """
338339
339- def __init__ (self , adapter , remote_port , local_ip , verify_vnc_path ,
340- remote_ips = None ):
340+ def __init__ (self , adapter , lpar_uuid , remote_port , local_ip , verify_vnc_path ,
341+ vterm_timeout , remote_ips = None ):
341342 """Creates the listener bound to a remote-accessible port.
342343
343344 :param adapter: The pypowervm adapter
@@ -354,11 +355,13 @@ def __init__(self, adapter, remote_port, local_ip, verify_vnc_path,
354355 super (_VNCSocketListener , self ).__init__ ()
355356
356357 self .adapter = adapter
358+ self .lpar_uuid = lpar_uuid
357359 self .remote_port = remote_port
358360 self .local_ip = local_ip
359361 self .verify_vnc_path = verify_vnc_path
360362 self .remote_ips = remote_ips
361363 self .x509_certs = None
364+ self .vterm_timeout = vterm_timeout
362365
363366 self .alive = True
364367 self .vnc_killer = None
@@ -480,7 +483,10 @@ def _setup_forwarding_socket(self, lpar_uuid, client_socket):
480483 # socket.
481484
482485 fwd = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
483- fwd .connect (('127.0.0.1' , local_port ))
486+ if fwd .connect_ex (('127.0.0.1' , local_port )) != 0 :
487+ LOG .exception (_ ("Port %s is not listening "
488+ "maybe VNC is down " ), local_port )
489+ return
484490
485491 # If we were told to enable VeNCrypt using X509 Authentication, do so
486492 if self .x509_certs is not None :
@@ -495,7 +501,8 @@ def _setup_forwarding_socket(self, lpar_uuid, client_socket):
495501 # See if we need to start up a new repeater for the given local port
496502 if local_port not in _VNC_LOCAL_PORT_TO_REPEATER :
497503 _VNC_LOCAL_PORT_TO_REPEATER [local_port ] = _VNCRepeaterServer (
498- self .adapter , lpar_uuid , local_port , client_socket , fwd )
504+ self .adapter , lpar_uuid , local_port , client_socket , fwd ,
505+ vterm_timeout = self .vterm_timeout )
499506 _VNC_LOCAL_PORT_TO_REPEATER [local_port ].start ()
500507 else :
501508 repeater = _VNC_LOCAL_PORT_TO_REPEATER [local_port ]
@@ -510,6 +517,7 @@ def _enable_x509_authentication(self, client_socket, server_socket):
510517 if there is an error.
511518 """
512519 try :
520+ LOG .info ("--> _enable_x509_authentication %s" % self .lpar_uuid )
513521 # First perform the RFB Version negotiation between client/server
514522 self ._version_negotiation (client_socket , server_socket )
515523 # Next perform the Security Authentication Type Negotiation
@@ -522,6 +530,7 @@ def _enable_x509_authentication(self, client_socket, server_socket):
522530 ca_certs = self .x509_certs .get ('ca_certs' )
523531 server_key = self .x509_certs .get ('server_key' )
524532 server_cert = self .x509_certs .get ('server_cert' )
533+ LOG .info ("<-- _enable_x509_authentication %s" % self .lpar_uuid )
525534 return ssl .wrap_socket (
526535 client_socket , server_side = True , ca_certs = ca_certs ,
527536 certfile = server_cert , keyfile = server_key ,
@@ -540,13 +549,15 @@ def _version_negotiation(self, client_socket, server_socket):
540549 """
541550 # Do a pass-thru of the RFB Version negotiation up-front
542551 # The length of the version is 12, such as 'RFB 003.007\n'
552+ LOG .info ("--> _version_negotiation %s" % self .lpar_uuid )
543553 client_socket .sendall (self ._socket_receive (server_socket , 12 ))
544554 server_socket .sendall (self ._socket_receive (client_socket , 12 ))
545555 # Since we are doing our own additional authentication
546556 # just tell the server we are doing No Authentication (1) to it
547557 auth_size = self ._socket_receive (server_socket , 1 )
548558 self ._socket_receive (server_socket , six .byte2int (auth_size ))
549559 server_socket .sendall (six .int2byte (1 ))
560+ LOG .info ("<-- _version_negotiation %s" % self .lpar_uuid )
550561
551562 def _auth_type_negotiation (self , client_socket ):
552563 """Performs the VeNCrypt Authentication Type Negotiation.
@@ -556,6 +567,7 @@ def _auth_type_negotiation(self, client_socket):
556567 """
557568 # Do the VeNCrypt handshake next before establishing SSL
558569 # Say we only support VeNCrypt (19) authentication version 0.2
570+ LOG .info ("--> into _auth_type_negotiation %s" % self .lpar_uuid )
559571 client_socket .sendall (six .int2byte (1 ))
560572 client_socket .sendall (six .int2byte (19 ))
561573 client_socket .sendall (encodeutils .safe_encode ("\x00 \x02 " ))
@@ -575,6 +587,7 @@ def _auth_type_negotiation(self, client_socket):
575587 # Tell the Client we have accepted the authentication type
576588 # In this particular case 0 means the type was accepted
577589 client_socket .sendall (six .int2byte (0 ))
590+ LOG .info ("<-- _auth_type_negotiation %s" % self .lpar_uuid )
578591 return True
579592
580593 def _auth_subtype_negotiation (self , client_socket ):
@@ -584,6 +597,7 @@ def _auth_subtype_negotiation(self, client_socket):
584597 :return success: Boolean whether the handshake was successful.
585598 """
586599 # Tell the client the authentication sub-type is x509None (260)
600+ LOG .info ("--> into _auth_subtype_negotiation %s" % self .lpar_uuid )
587601 client_socket .sendall (six .int2byte (1 ))
588602 client_socket .sendall (struct .pack ('!I' , 260 ))
589603 subtyp_raw = self ._socket_receive (client_socket , 4 )
@@ -595,6 +609,7 @@ def _auth_subtype_negotiation(self, client_socket):
595609 # Tell the Client we have accepted the authentication handshake
596610 # In this particular case 1 means the sub-type was accepted
597611 client_socket .sendall (six .int2byte (1 ))
612+ LOG .info ("<-- _auth_subtype_negotiation %s" % self .lpar_uuid )
598613 return True
599614
600615 def _socket_receive (self , asocket , bufsize ):
@@ -657,7 +672,7 @@ class _VNCRepeaterServer(threading.Thread):
657672 """
658673
659674 def __init__ (self , adapter , lpar_uuid , local_port , client_socket = None ,
660- local_socket = None ):
675+ local_socket = None , vterm_timeout = 300 ):
661676 """Creates the repeater.
662677
663678 :param adapter: The pypowervm adapter
@@ -676,6 +691,7 @@ def __init__(self, adapter, lpar_uuid, local_port, client_socket=None,
676691 self .local_port = local_port
677692 self .alive = True
678693 self .vnc_killer = None
694+ self .vterm_timeout = vterm_timeout
679695
680696 # Add the connection passed into us to the forwarding list
681697 if client_socket is not None and local_socket is not None :
@@ -703,6 +719,8 @@ def run(self):
703719 # 0, then we know that we're ready to close this.
704720 data = s_input .recv (4096 )
705721 if len (data ) == 0 :
722+ LOG .info ("The client connection will be closed "
723+ "since no data is received for %s" % self .lpar_uuid )
706724 self ._close_client (s_input )
707725
708726 # Note that we have to break here. We do that because the
@@ -749,7 +767,7 @@ def _close_client(self, s_input):
749767
750768 # If this was the last port, close the local connection
751769 if len (self .peers ) == 0 :
752- self .vnc_killer = _VNCKiller (self .adapter , self .lpar_uuid )
770+ self .vnc_killer = _VNCKiller (self .adapter , self .lpar_uuid , vterm_timeout = self . vterm_timeout )
753771 self .vnc_killer .start ()
754772
755773
@@ -766,11 +784,12 @@ class _VNCKiller(threading.Thread):
766784 session will be closed out and the memory will be reclaimed.
767785 """
768786
769- def __init__ (self , adapter , lpar_uuid ):
787+ def __init__ (self , adapter , lpar_uuid , vterm_timeout = 300 ):
770788 super (_VNCKiller , self ).__init__ ()
771789 self .adapter = adapter
772790 self .lpar_uuid = lpar_uuid
773791 self ._abort = False
792+ self .vterm_timeout = vterm_timeout
774793
775794 def abort (self ):
776795 """Call to stop the killer from completing its job."""
@@ -780,11 +799,12 @@ def run(self):
780799 count = 0
781800
782801 # Wait up to 5 minutes to see if any new negotiations came in
783- while count < 300 and not self ._abort :
802+ while count < self . vterm_timeout and not self ._abort :
784803 time .sleep (1 )
785804 if self ._abort :
786805 break
787806 count += 1
788807
789808 if not self ._abort :
809+ LOG .info ("closing console - rmvterm for lpar id %s" % self .lpar_uuid )
790810 _close_vterm_local (self .adapter , self .lpar_uuid )
0 commit comments