Example #1
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
Example #2
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
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
  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
Example #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
  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
Example #7
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
Example #8
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
Example #9
0
    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)
Example #10
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
Example #11
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
Example #12
0
    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