'Gracefully exit the SSH session.'

def cleanup(self):

    self.exit_config_mode()
    self.write_channel(u'logout\n')
    count = 0
    while (count <= 5):
        time.sleep(0.5)
        output = self.read_channel()
        if (u'Do    you    want    to    log    out' in output):
            self.write_channel(u'y\n')
        elif (u'Do    you    want    to    save    the    current' in output):
            self.write_channel(u'n\n')
        try:
            self.write_channel(u'\n')
        except socket.error:
            break
        count += 1
