def __init__(self, IP, username, password, port=22):
     self.rc = SSHLibrary()
     self.IP = IP
     self.usr = username
     self.pwd = password
     self.port = port
     self.resp = ""
class _RobotSSHConnection(Connection):
    """
    This class used the Robot Framework SSHLibrary to provide an interface to connect and remotely execute commands.
    It is supported on both Jython and Python
    """

    def __init__(self, IP, username, password, port=22):
        self.rc = SSHLibrary()
        self.IP = IP
        self.usr = username
        self.pwd = password
        self.port = port
        self.resp = ""

    def connect(self):
        try:
            self.rc.open_connection(host=self.IP, port=self.port)
            self.rc.login(username=self.usr, password=self.pwd)
            return True
        except:
            return False

    def execute_command(self, cmd, wait):
        dlog("Command Execution: {0}".format(cmd))
        if wait:
            self.resp = self.rc.execute_command(cmd)
            dlog(self.resp)
            if self.resp:
                dlog("INFO: Successful Response")
                return True
            else:
                # dlog("INFO: No Response")
                return False
        else:
            self.rc.start_command(cmd)

    def capture_output(self, wait):
        if not wait:
            self.resp = self.rc.read_command_output()
        return self.resp

    def disconnect(self):
        self.rc.close_connection()
'''
Created on May 12, 2014

@author: xiaoqin.li
'''
import re

#from robot.libraries.BuiltIn import BuiltIn
#BuiltInInstance= BuiltIn()

from rc import _rc

from SSHLibrary.library import SSHLibrary

G_SSHInstance = SSHLibrary()

#===============================================================================
# def _get_current_connection():
#     try:
#         sshinstance= BuiltInInstance.get_library_instance('SSHLibrary')
#     except AttributeError:
#         raise AssertionError("*ERROR* please import SSHLibrary and call open_connection first")
#     return sshinstance.current
#===============================================================================


def _get_current_connection():
    return G_SSHInstance.current


def _run_command(cmd):