def __irodsClient( self , user = None ):

    global IRODS_USER
    password = None

    cfgPath = self.serviceInfoDict[ 'serviceSectionPath' ]
    gLogger.debug( "cfgPath: %s" % cfgPath )

    if not user:
      credentials = self.getRemoteCredentials()
      if credentials and ( "username" in credentials ):
        IRODS_USER = credentials[ "username" ]
        ## TODO: should get user password somehow
    elif user == "r":
      IRODS_USER = gConfig.getValue( "%s/read" % cfgPath , IRODS_USER )
    elif user == "w":
      IRODS_USER = gConfig.getValue( "%s/write" % cfgPath , IRODS_USER )

    if not IRODS_USER:
      return False , "Failed to get iRods user"
    gLogger.debug( "iRods user: %s" % IRODS_USER )

    password = gConfig.getValue( "%s/%s" % ( cfgPath , IRODS_USER ) , password )

    conn , errMsg = rcConnect( IRODS_HOST , IRODS_PORT , IRODS_USER , IRODS_ZONE )

    status = clientLoginWithPassword( conn , password )

    if not status == 0:
      return False , "Failed to authenticate user '%s'" % IRODS_USER

    return conn , errMsg
Exemple #2
0
def create_irods_connection(username, password, rodsconfig):
    from irods import (getRodsEnv, rcConnect, clientLoginWithPassword,
                       rodsErrorName)

    err, rodsEnv = getRodsEnv()  # Override all values later
    rodsEnv.rodsUserName = username

    rodsEnv.rodsHost = rodsconfig[0]
    rodsEnv.rodsPort = rodsconfig[1]
    rodsEnv.rodsZone = rodsconfig[2]

    conn, err = rcConnect(rodsEnv.rodsHost,
                          rodsEnv.rodsPort,
                          rodsEnv.rodsUserName,
                          rodsEnv.rodsZone
                          )

    if err.status != 0:
        raise Exception('Connecting to iRODS failed %s'
                        % rodsErrorName(err.status)[0])

    err = clientLoginWithPassword(conn, password)

    if err != 0:
        raise Exception('Authenticating to iRODS failed %s, user: %, pw: %s'
                        % rodsErrorName(err.status)[0], username, password)

    return conn
  def __irodsClient( self , user = None ):
    """ Get the iRods client
    """
    global IRODS_USER
    
    userDict = {}
    result = self.__getUserDetails()
    if not result['OK']:
      return False , "Failed to get iRods user info", userDict
    
    userDict = result['Value']

    IRODS_USER = userDict['iRodsUser']

    if not IRODS_USER:
      return False , "Failed to get iRods user", userDict
    gLogger.debug( "iRods user: %s" % IRODS_USER )

    password = userDict['iRodsPassword']
    if not password:
      return False , "Failed to get iRods user/password", userDict

    conn , errMsg = rcConnect( IRODS_HOST , IRODS_PORT , IRODS_USER , IRODS_ZONE )
    status = clientLoginWithPassword( conn , password )

    if not status == 0:
      return False , "Failed to authenticate user '%s'" % IRODS_USER, userDict

    return conn , errMsg, userDict
    def __init__(self, session, stream):
        myEnv, status = irods.getRodsEnv()
        conn, errMsg = irods.rcConnect(myEnv.getRodsHost(), myEnv.getRodsPort(), 
                                       myEnv.getRodsUserName(), myEnv.getRodsZone())
        status = irods.clientLogin(conn)
        if status:
            raise ConfigFileException("Cannot connect to iRODS: (%s) %s" % (status, errMsg))
        
        home = myEnv.getRodsHome()
        c = irods.irodsCollection(conn, home)
        self.cxn = conn
        self.coll = c

        instream = stream
        # check if abs path to home dir
        if stream.startswith(home):
            stream = stream[len(home):]
            if stream[0] == "/":
                stream = stream[1:]
        colls = stream.split('/')
        for i, cln in enumerate(colls):
            exit_status = c.openCollection(cln)
            if exit_status < 0:
                if (i < len(colls) - 1) or \
                    (cln not in [obj[0] for obj in c.getObjects()]):
                    raise IOError("When opening {0}: {1} does not exists in collection {2}".format(instream, cln, c.getCollName()))
Exemple #5
0
    def __irodsClient(self, user=None):
        """ Get the iRods client
    """
        global IRODS_USER

        userDict = {}
        result = self.__getUserDetails()
        if not result['OK']:
            return False, "Failed to get iRods user info", userDict

        userDict = result['Value']

        IRODS_USER = userDict['iRodsUser']

        if not IRODS_USER:
            return False, "Failed to get iRods user", userDict
        gLogger.debug("iRods user: %s" % IRODS_USER)

        password = userDict['iRodsPassword']
        if not password:
            return False, "Failed to get iRods user/password", userDict

        conn, errMsg = rcConnect(IRODS_HOST, IRODS_PORT, IRODS_USER,
                                 IRODS_ZONE)
        status = clientLoginWithPassword(conn, password)

        if not status == 0:
            return False, "Failed to authenticate user '%s'" % IRODS_USER, userDict

        return conn, errMsg, userDict
Exemple #6
0
    def __irodsClient(self, user=None):

        global IRODS_USER
        password = None

        cfgPath = self.serviceInfoDict['serviceSectionPath']
        gLogger.debug("cfgPath: %s" % cfgPath)

        if not user:
            credentials = self.getRemoteCredentials()
            if credentials and ("username" in credentials):
                IRODS_USER = credentials["username"]
                ## TODO: should get user password somehow
        elif user == "r":
            IRODS_USER = gConfig.getValue("%s/read" % cfgPath, IRODS_USER)
        elif user == "w":
            IRODS_USER = gConfig.getValue("%s/write" % cfgPath, IRODS_USER)

        if not IRODS_USER:
            return False, "Failed to get iRods user"
        gLogger.debug("iRods user: %s" % IRODS_USER)

        password = gConfig.getValue("%s/%s" % (cfgPath, IRODS_USER), password)

        conn, errMsg = rcConnect(IRODS_HOST, IRODS_PORT, IRODS_USER,
                                 IRODS_ZONE)

        status = clientLoginWithPassword(conn, password)

        if not status == 0:
            return False, "Failed to authenticate user '%s'" % IRODS_USER

        return conn, errMsg
Exemple #7
0
 def connect_infos(self, host, port, user, zone):
     """Same as connect but with information on the server in parameters
     port is an integer, host, user and zone are strings"""
     conn, err_msg = irods.rcConnect(host, port, user, zone)
     if not conn:
         self.conn = None
         return err_msg.status
     self.conn = conn
     return irods.clientLoginWithObfPassword(conn, self.cfg.password)
    def _open(self, session):

        if self.cxn == None:
            # connect to iRODS
            myEnv, status = irods.getRodsEnv()
            host = self.host if self.host else myEnv.getRodsHost()
            port = self.port if self.port else myEnv.getRodsPort()
            user = self.user if self.user else myEnv.getRodsUserName()
            zone = self.zone if self.zone else myEnv.getRodsZone()
         
            conn, errMsg = irods.rcConnect(host, port, user, zone) 
            if self.passwd:
                status = irods.clientLoginWithPassword(conn, self.passwd)
            else:
                status = irods.clientLogin(conn)

            if status:
                raise ConfigFileException("Cannot connect to iRODS: (%s) %s" % (status, errMsg.getMsg()))
            self.cxn = conn
            self.env = myEnv

            resources = irods.getResources(self.cxn)
            self.resourceHash = {}
            for r in resources:
                self.resourceHash[r.getName()] = r

            
        if self.coll != None:
            # already open, just skip
            return None

        c = irods.irodsCollection(self.cxn, self.env.getRodsHome())
        self.coll = c

        # move into cheshire3 section
        path = self.get_path(session, 'irodsCollection', 'cheshire3')
        dirs = c.getSubCollections()
        if not path in dirs:
            c.createCollection(path)
        c.openCollection(path)


        if self.get_setting(session, 'createSubDir', 1):
            # now look for object's storage area
            # maybe move into database collection
            if (isinstance(self.parent, Database)):
                sc = self.parent.id
                dirs = c.getSubCollections()
                if not sc in dirs:
                    c.createCollection(sc)
                c.openCollection(sc)
            # move into store collection
            dirs = c.getSubCollections()
            if not self.id in dirs:
                c.createCollection(self.id)
            c.openCollection(self.id)
    def __init__(self, session, stream):
        # Check for dependency
        if irods is None:
            raise MissingDependencyException(
                '{0.__module__}.{0.__class__.__name__}'.format(self),
                'irods (PyRods)'
            )
        # Check for URL
        if stream.startswith(('irods://', 'rods://')):
            myEnv = parse_irodsUrl(stream)
            stream = myEnv.relpath
        else:
            # Get parameters from env
            status, myEnv = irods.getRodsEnv()
        try:
            host = myEnv.getRodsHost()
            port = myEnv.getRodsPort()
            username = myEnv.getRodsUserName()
            zone = myEnv.getRodsZone()
            home = myEnv.getRodsHome()
        except AttributeError:
            host = myEnv.rodsHost
            port = myEnv.rodsPort
            username = myEnv.rodsUserName
            zone = myEnv.rodsZone
            home = myEnv.rodsHome
        conn, errMsg = irods.rcConnect(host, port, username, zone)
        status = irods.clientLogin(conn)
        if status:
            raise ConfigFileException("Cannot connect to iRODS: ({0}) {1}"
                                      "".format(status, errMsg)
                                      )

        c = irods.irodsCollection(conn)
        self.cxn = conn
        self.coll = c
        instream = stream
        # Check if abs path to home dir
        if stream.startswith(home):
            stream = stream[len(home):]
            if stream[0] == "/":
                stream = stream[1:]
        colls = stream.split('/')
        for i, cln in enumerate(colls):
            exit_status = c.openCollection(cln)
            if exit_status < 0:
                if (
                    (i < len(colls) - 1) or
                    (cln not in [obj[0] for obj in c.getObjects()])
                ):
                    raise IOError("When opening {0}: {1} does not exists in "
                                  "collection {2}".format(instream,
                                                          cln,
                                                          c.getCollName()
                                                          )
                                  )
Exemple #10
0
def open_irodsUrl(url, mode='r'):
    """Open and return the file specified by an iRODS URL.

    Returns a file-like object - ``irods.IrodsFile``
    """
    if irods is None:
        raise MissingDependencyException("open_irodsUrl()", 'irods (PyRods)')
    parsed = parse_irodsUrl(url)
    conn, errMsg = irods.rcConnect(parsed.rodsHost, parsed.rodsPort,
                                   parsed.rodsUserName, parsed.rodsZone)
    status = irods.clientLogin(conn)
    return irods.irodsOpen(conn, parsed.path, mode)
Exemple #11
0
	def __init__(self):
		self.status, self.myEnv = irods.getRodsEnv()
		self.conn, self.errMsg = irods.rcConnect(self.myEnv.rodsHost,
												 self.myEnv.rodsPort,
												 self.myEnv.rodsUserName,
												 self.myEnv.rodsZone)
		self.status = irods.clientLogin(self.conn)
		self.path = makePath(self.myEnv.rodsHome, FOLDER) # addSlash(self.myEnv.rodsHome, reduce(addSlash, FOLDER))
		self.coll = irods.irodsCollection(self.conn, self.path)
		self.popen_opt = dict(shell=True,
							  stdout=subprocess.PIPE,
							  stderr=subprocess.PIPE)
Exemple #12
0
	def getConnection(self):
		err = None

		logging.debug('connecting to iRODS: host=%s port=%d login=%s zone=%s' \
         		% (self.host, self.port, self.user, self.zone))
		# now connect
		self.conn, err = irods.rcConnect(self.host, self.port, self.user, self.zone)
		if self.conn is None:
        		logging.info('cannot connect to iRODS - Is server up?')
		else:
			irods.clientLoginWithPassword(self.conn, self.password)

		return self.conn
Exemple #13
0
def connect_to_irods(host, port, username, password, zone):
    conn, err = rcConnect(host, port, username, zone)
    if err.status != 0:
        print 'ERROR: Unable to connect to iRODS@%s' % config['RODSHOST']
        return None

    if conn is None:
        return conn

    err = clientLoginWithPassword(conn, password)
    if err != 0:
        return conn

    print 'Connection successful'
    return conn
Exemple #14
0
def get_connection_from_params(params):
    """
    Create a iRODS data connection from POST parameters.
    """
    conn = None
    username = params['uname']
    password = params['pw']
    host = params['server']
    port = params['port']
    zone = params['zone']
    if (host and port and username and zone):
        from irods import rcConnect, clientLoginWithPassword
        conn, _ = rcConnect(host, int(port), username, zone)
        clientLoginWithPassword(conn, password)
    return conn
Exemple #15
0
def open_irodsUrl(url, mode='r'):
    """Open and return the file specified by an iRODS URL.

    Returns a file-like object - ``irods.IrodsFile``
    """
    if irods is None:
        raise MissingDependencyException("open_irodsUrl()", 'irods (PyRods)')
    parsed = parse_irodsUrl(url)
    conn, errMsg = irods.rcConnect(parsed.rodsHost,
                                   parsed.rodsPort,
                                   parsed.rodsUserName,
                                   parsed.rodsZone
                                   )
    status = irods.clientLogin(conn)
    return irods.irodsOpen(conn, parsed.path, mode)
def get_connection_from_params(params):
    """
    Create a iRODS data connection from POST parameters.
    """
    conn = None
    username = params['uname']
    password = params['pw']
    host = params['server']
    port = params['port']
    zone = params['zone']
    if (host and port and username and zone):
        from irods import rcConnect, clientLoginWithPassword
        conn, _ = rcConnect(host, int(port), username, zone)
        clientLoginWithPassword(conn, password)
    return conn
Exemple #17
0
def rods_connect():
    """
    A basic iRODS connection mechanism that connects using the current iRODS
    environment
    """
    status, env = irods.getRodsEnv()
    assert status == 0, 'connect(): getRodsEnv() failed (%s): %s' % ( status, irods.strerror( status ) )
    conn, err = irods.rcConnect( env.rodsHost,
                                 env.rodsPort,
                                 env.rodsUserName,
                                 env.rodsZone )
    assert err.status == 0, 'connect(): rcConnect() failed (%s): %s' % ( err.status, err.msg )
    status, pw = irods.obfGetPw()
    assert status == 0, 'connect(): getting password with obfGetPw() failed (%s): %s' % ( status, irods.strerror( status ) )
    status = irods.clientLoginWithObfPassword( conn, pw )
    assert status == 0, 'connect(): logging in with clientLoginWithObfPassword() failed (%s): %s' % ( status, irods.strerror( status ) )
    return env, conn
Exemple #18
0
def rods_connect():
    """
    A basic iRODS connection mechanism that connects using the current iRODS
    environment
    """
    status, env = irods.getRodsEnv()
    assert status == 0, 'connect(): getRodsEnv() failed (%s): %s' % ( status, irods.strerror( status ) )
    conn, err = irods.rcConnect( env.rodsHost,
                                 env.rodsPort,
                                 env.rodsUserName,
                                 env.rodsZone )
    assert err.status == 0, 'connect(): rcConnect() failed (%s): %s' % ( err.status, err.msg )
    status, pw = irods.obfGetPw()
    assert status == 0, 'connect(): getting password with obfGetPw() failed (%s): %s' % ( status, irods.strerror( status ) )
    status = irods.clientLoginWithObfPassword( conn, pw )
    assert status == 0, 'connect(): logging in with clientLoginWithObfPassword() failed (%s): %s' % ( status, irods.strerror( status ) )
    return env, conn
Exemple #19
0
    def _openIrods(self, session):

        if self.cxn is None:
            # connect to iRODS
            myEnv, status = irods.getRodsEnv()
            conn, errMsg = irods.rcConnect(myEnv.getRodsHost(),
                                           myEnv.getRodsPort(), 
                                           myEnv.getRodsUserName(),
                                           myEnv.getRodsZone()
                                           )
            status = irods.clientLogin(conn)
            if status:
                raise ConfigFileException("Cannot connect to iRODS: (%s) %s"
                                          "" % (status, errMsg))
            self.cxn = conn
            self.env = myEnv

        if self.coll is not None:
            # already open, just skip
            return None

        c = irods.irodsCollection(self.cxn, self.env.getRodsHome())
        self.coll = c

        # move into cheshire3 section
        path = self.get_path(session, 'irodsCollection', 'cheshire3')
        dirs = c.getSubCollections()
        if not path in dirs:
            c.createCollection(path)
        c.openCollection(path)

        # now look for object's storage area
        # maybe move into database collection
        if (isinstance(self.parent, Database)):
            sc = self.parent.id
            dirs = c.getSubCollections()
            if not sc in dirs:
                c.createCollection(sc)
            c.openCollection(sc)

        # move into store collection
        dirs = c.getSubCollections()
        if not self.id in dirs:
            c.createCollection(self.id)
        c.openCollection(self.id)
Exemple #20
0
    def open(self):
        # pylint: disable=no-member
        conn, _err = irods.rcConnect(self.host, self.port, self.user,
                                     self.zone)
        if conn is None:
            raise IrodsError("Can't create connection to %s:%s " %
                             (self.host, _err))
        if self.password:
            irods.clientLoginWithPassword(conn, self.password)
        else:
            irods.clientLogin(conn)

        coll = irods.irodsCollection(conn)
        nm = coll.getCollName()

        self.irods_url = urlparse.urlunparse(
            list(self.irods_url)[:2] + [''] * 4)
        if self.path in ['', '/']:
            self.path = nm

        self.conn = conn
        self.base_dir = nm
        return self
Exemple #21
0
# Copyright (c) 2013, University of Liverpool
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# Author       : Jerome Fuselier
#

from irods import *
import irods

if __name__ == "__main__":
    conn, errMsg = irods.rcConnect(u"localhost", 1247, u"rods", u"tempZone", 0)
    print conn, errMsg
    status = clientLogin(conn)
    
    print status
    print getUserInfo(conn, u"rods//??")
    
    conn.disconnect()
    def _open(self, session):

        if self.cxn == None:
            # connect to iRODS
            myEnv, status = irods.getRodsEnv()

            host = self.host if self.host else myEnv.getRodsHost()
            port = self.port if self.port else myEnv.getRodsPort()
            user = self.user if self.user else myEnv.getRodsUserName()
            zone = self.zone if self.zone else myEnv.getRodsZone()
            
            conn, errMsg = irods.rcConnect(host, port, user, zone)
            if self.passwd:
                status = irods.clientLoginWithPassword(conn, self.passwd)
            else:
                status = irods.clientLogin(conn)

            if status:
                raise ConfigFileException("Cannot connect to iRODS: (%s) %s" % (status, errMsg))
            self.cxn = conn
            self.env = myEnv

            resources = irods.getResources(self.cxn)
            self.resourceHash = {}
            for r in resources:
                self.resourceHash[r.getName()] = r

            
        if self.coll != None:
            # already open, just skip
            return None

        c = irods.irodsCollection(self.cxn, self.env.getRodsHome())
        self.coll = c

        # move into cheshire3 section
        path = self.get_path(session, 'irodsCollection', 'cheshire3')
        dirs = c.getSubCollections()
        if not path in dirs:
            c.createCollection(path)
        c.openCollection(path)


        if self.get_setting(session, 'createSubDir', 1):
            # now look for object's storage area
            # maybe move into database collection
            if (isinstance(self.parent, Database)):
                sc = self.parent.id
                dirs = c.getSubCollections()
                if not sc in dirs:
                    c.createCollection(sc)
                c.openCollection(sc)
            # move into store collection
            dirs = c.getSubCollections()
            if not self.id in dirs:
                c.createCollection(self.id)
            c.openCollection(self.id)

        # Fetch user metadata
        myMetadata = self.get_metadataTypes(session)
        umd = c.getUserMetadata()
        umdHash = {}
        for u in umd:
            umdHash[u[0]] = icatValToPy(*u[1:])

        for md in myMetadata:
            try:
                setattr(self, md, umdHash[md])
            except KeyError:
                # hasn't been set yet
                pass

        if self.totalItems != 0:
            self.meanWordCount = self.totalWordCount / self.totalItems
            self.meanByteCount = self.totalByteCount / self.totalItems
        else:
            self.meanWordCount = 1
            self.meanByteCount = 1