Exemplo n.º 1
0
    def __init__(self, hostname, port, ssh_transport=None, ssh_port=22, user=None, password=None, use_keys=False):
        """ constructor, takes in host and port to which the tunnel
           is to be opened. Assumes ssh on 22 for now.
           An already authenticated paramiko transport can be passed.
           It is assumed that the transport is to the same host as specified
           by hostname.
       """
        self.hostname = hostname
        self.ssh_port = ssh_port
        self.username = user
        self.password = password
        self.port = port
        self.transport_created = False
        self.use_keys = use_keys
        if ssh_transport == None:
            authtype = None
            pwd = self.password
            if self.use_keys:
                pwd = None
                authtype = "agent"

            self.transport = PHelper.init_ssh_transport(
                self.hostname, self.ssh_port, username=self.username, password=pwd, authtype=authtype
            )
            self.transport_created = True
        else:
            self.transport = ssh_transport
Exemplo n.º 2
0
 def connect(self):
     # We already have a transport to the remote machine.
     # lets create a tunnel on the remote node to forward traffic from
     # localhost, localport  ==> localhost, xen port
     # (NOTE : localhost is interpreted on the remote node.)
     self.sock = PHelper.open_channel(
         self.ssh_transport, "direct-tcpip", ("localhost", self.port), ("localhost", self.localport)
     )
Exemplo n.º 3
0
 def connect(self):
     # We already have a transport to the remote machine.
     # lets create a tunnel on the remote node to forward traffic from
     # localhost, localport  ==> localhost, xen port
     # (NOTE : localhost is interpreted on the remote node.)
     self.sock = PHelper.open_channel(self.ssh_transport, "direct-tcpip",
                                      ("localhost", self.port),
                                      ("localhost", self.localport))
Exemplo n.º 4
0
    def __init__(self,
                 hostname=None,
                 ssh_port=22,
                 username=DEFAULT_USER,
                 password=None,
                 isRemote=False,
                 use_keys=False):

        self.isRemote = isRemote
        self.hostname = hostname
        self.ssh_port = ssh_port
        self.username = username
        self.password = password
        self.use_keys = use_keys

        self.ssh_transport = None

        self._fptrs = None
        self._sftp_client = None
        self._sftp_client_lock = None

        self._sftp_init_lock = threading.RLock()
        self._sftp_client_lock = threading.RLock()

        self._last_error = None

        ### Uncomment the following if you want to use thread local again.
        ### self.thread_local = _threading_local.local()
        ### self.local_obj_key = object.__getattribute__(self.thread_local,
        ###                                             '_local__key')

        #print "Creating NodeProxy with  ", self.hostname, self.local_obj_key
        # pointers to functions for doing file / directory manipulations
        self._fptrs = None

        if isRemote:
            try:
                authtype = None
                pwd = self.password
                if not pwd and self.use_keys:
                    authtype = "agent"

                self.ssh_transport = \
                PHelper.init_ssh_transport(self.hostname,
                                           ssh_port = self.ssh_port,
                                           username=self.username,
                                           password=pwd,
                                           authtype = authtype
                                           )
            except Exception, ex:
                print "Could not initialize ssh for %s %d" % (hostname,
                                                              ssh_port)
                raise
Exemplo n.º 5
0
    def __init__(
        self, hostname=None, ssh_port=22, username=DEFAULT_USER, password=None, isRemote=False, use_keys=False
    ):

        self.isRemote = isRemote
        self.hostname = hostname
        self.ssh_port = ssh_port
        self.username = username
        self.password = password
        self.use_keys = use_keys

        self.ssh_transport = None

        self._fptrs = None
        self._sftp_client = None
        self._sftp_client_lock = None

        self._sftp_init_lock = threading.RLock()
        self._sftp_client_lock = threading.RLock()

        self._last_error = None

        ### Uncomment the following if you want to use thread local again.
        ### self.thread_local = _threading_local.local()
        ### self.local_obj_key = object.__getattribute__(self.thread_local,
        ###                                             '_local__key')

        # print "Creating NodeProxy with  ", self.hostname, self.local_obj_key
        # pointers to functions for doing file / directory manipulations
        self._fptrs = None

        if isRemote:
            try:
                authtype = None
                pwd = self.password
                if not pwd and self.use_keys:
                    authtype = "agent"

                self.ssh_transport = PHelper.init_ssh_transport(
                    self.hostname, ssh_port=self.ssh_port, username=self.username, password=pwd, authtype=authtype
                )
            except Exception, ex:
                print "Could not initialize ssh for %s %d" % (hostname, ssh_port)
                raise
Exemplo n.º 6
0
    def __init__(self,
                 hostname,
                 port,
                 ssh_transport=None,
                 ssh_port=22,
                 user=None,
                 password=None,
                 use_keys=False):
        """ constructor, takes in host and port to which the tunnel
           is to be opened. Assumes ssh on 22 for now.
           An already authenticated paramiko transport can be passed.
           It is assumed that the transport is to the same host as specified
           by hostname.
       """
        self.hostname = hostname
        self.ssh_port = ssh_port
        self.username = user
        self.password = password
        self.port = port
        self.transport_created = False
        self.use_keys = use_keys
        if ssh_transport == None:
            authtype = None
            pwd = self.password
            if self.use_keys:
                pwd = None
                authtype = "agent"

            self.transport = PHelper.init_ssh_transport(self.hostname,
                                                        self.ssh_port,
                                                        username=self.username,
                                                        password=pwd,
                                                        authtype=authtype)
            self.transport_created = True
        else:
            self.transport = ssh_transport