Exemplo n.º 1
0
Arquivo: hp.py Projeto: wkumari/ldpush
 def _Disconnect(self):
     """Disconnects from the device."""
     if hasattr(self, '_connection'):
         try:
             try:
                 self._connection.child.send('exit\r')
                 while True:
                     i = self._connection.child.expect(
                         [
                             r'\S(?:#|>) ', r'Do you want to log out',
                             r'Do you want to save'
                         ],
                         timeout=self.timeout_act_user)
                     if i == 0:
                         self._connection.child.send('exit\r')
                         continue
                     elif i == 1:
                         self._connection.child.send('y')
                         return
                     elif i == 2:
                         self._connection.child.send('n')
                         logging.warn(
                             'Uncomitted config on %s(%s). Not saving.',
                             self.host, self.loopback_ipv4)
                         return
             except pexpect.TIMEOUT, e:
                 raise exceptions.DisconnectError('%s: %s' %
                                                  (e.__class__, str(e)))
             except pexpect.EOF, e:
                 # An EOF now means nothing more than a disconnect.
                 pass
Exemplo n.º 2
0
 def _Disconnect(self):
   if hasattr(self, '_connection'):
     try:
       self._connection.child.send('exit\r')
       self._connection.child.expect(self._connection.exit_list,
                                     timeout=self.timeout_act_user)
       self.connected = False
     except (pexpect.EOF, pexpect.TIMEOUT) as e:
       self.connected = False
       raise exceptions.DisconnectError('%s: %s' % (e.__class__, str(e)))
Exemplo n.º 3
0
 def _Disconnect(self):
   if hasattr(self, '_connection'):
     try:
       self._connection.child.send('exit\r')
       # Loose prompt RE as prompt changes after first exit.
       self._connection.child.expect(self._success,
                                     timeout=self.timeout_act_user)
       self._connection.child.send('exit\r')
       self._connection.child.expect(self._connection.exit_list,
                                     timeout=self.timeout_act_user)
       self.connected = False
     except (pexpect.EOF, pexpect.TIMEOUT), e:
       self.connected = False
       raise exceptions.DisconnectError('%s: %s' % (e.__class__, str(e)))