Exemplo n.º 1
0
 def getCEStatus(self):
     """ Method to return information on running and pending jobs.
 """
     vo = ''
     res = getVOfromProxyGroup()
     if res['OK']:
         vo = res['Value']
     else:  # A backup solution which may work
         vo = self.ceParameters['VO']
     cmd = 'ldapsearch -x -LLL -H ldap://%s:2135 -b mds-vo-name=resource,o=grid "(GlueVOViewLocalID=%s)"' % (
         self.ceHost, vo.lower())
     res = shellCall(0, cmd)
     if not res['OK']:
         gLogger.debug("Could not query CE %s - is it down?" % self.ceHost)
         return res
     result = S_OK()
     try:
         ldapValues = res['Value'][1].split("\n")
         running = [y for y in ldapValues if 'GlueCEStateRunningJobs' in y]
         waiting = [y for y in ldapValues if 'GlueCEStateWaitingJobs' in y]
         result['RunningJobs'] = int(running[0].split(":")[1])
         result['WaitingJobs'] = int(waiting[0].split(":")[1])
     except IndexError:
         result = S_ERROR('Unknown ldap failure for site %s' % self.ceHost)
         result['RunningJobs'] = 0
         result['WaitingJobs'] = 0
     gLogger.debug("Running jobs for CE %s : %s" %
                   (self.ceHost, result['RunningJobs']))
     gLogger.debug("Waiting jobs for CE %s : %s" %
                   (self.ceHost, result['WaitingJobs']))
     result['SubmittedJobs'] = 0
     return result
Exemplo n.º 2
0
 def getCEStatus( self ):
   """ Method to return information on running and pending jobs.
   """
   vo = ''
   res = getVOfromProxyGroup()
   if res['OK']:
     vo = res['Value']
   else: # A backup solution which may work
     vo = self.ceParameters['VO']
   cmd = 'ldapsearch -x -LLL -H ldap://%s:2135 -b mds-vo-name=resource,o=grid "(GlueVOViewLocalID=%s)"' %(self.ceHost, vo.lower())
   res = shellCall( 0, cmd )
   if not res['OK']:
     gLogger.debug("Could not query CE %s - is it down?" % self.ceHost)
     return res
   result = S_OK()
   try:
     ldapValues = res['Value'][1].split("\n")
     running = [y for y in ldapValues if 'GlueCEStateRunningJobs' in y]
     waiting = [y for y in ldapValues if 'GlueCEStateWaitingJobs' in y]
     result['RunningJobs'] = int(running[0].split(":")[1])
     result['WaitingJobs'] = int(waiting[0].split(":")[1])
   except IndexError:
     result = S_ERROR('Unknown ldap failure for site %s' % self.ceHost)
     result['RunningJobs'] = 0
     result['WaitingJobs'] = 0
   gLogger.debug("Running jobs for CE %s : %s" % (self.ceHost, result['RunningJobs']))
   gLogger.debug("Waiting jobs for CE %s : %s" % (self.ceHost, result['WaitingJobs']))
   result['SubmittedJobs'] = 0
   return result
Exemplo n.º 3
0
def ldapsearchBDII( filt = None, attr = None, host = None, base = None ):
  """ Python wrapper for ldapserch at bdii.
      
      Input parameters:
        filt:    Filter used to search ldap, default = '', means select all
        attr:    Attributes returned by ldapsearch, default = '*', means return all
        host:    Host used for ldapsearch, default = 'lcg-bdii.cern.ch:2170', can be changed by $LCG_GFAL_INFOSYS
      
      Return standard DIRAC answer with Value equals to list of ldapsearch responses
      Each element of list is dictionary with keys:
        'dn':                 Distinguished name of ldapsearch response
        'objectClass':        List of classes in response
        'attr':               Dictionary of attributes
  """

  if filt == None:
    filt = ''
  if attr == None:
    attr = '*'
  if host == None:
    host = 'lcg-bdii.cern.ch:2170'
  if base == None:
    base = 'Mds-Vo-name=local,o=grid'

  cmd = 'ldapsearch -x -LLL -h %s -b %s "%s" "%s"' % ( host, base, filt, attr )
  result = shellCall( 0, cmd )

  response = []

  if not result['OK']:
    return result

  status = result['Value'][0]
  stdout = result['Value'][1]
  stderr = result['Value'][2]

  if not status == 0:
    return S_ERROR( stderr )

  lines = []
  for line in stdout.split( "\n" ):
    if line.find( " " ) == 0:
      lines[-1] += line.strip()
    else:
      lines.append( line.strip() )

  record = None
  for line in lines:
    if line.find( 'dn:' ) == 0:
      record = {'dn':line.replace( 'dn:', '' ).strip(),
                'objectClass':[],
                'attr':{'dn':line.replace( 'dn:', '' ).strip()}}
      response.append( record )
      continue
    if record:
      if line.find( 'objectClass:' ) == 0:
        record['objectClass'].append( line.replace( 'objectClass:', '' ).strip() )
        continue
      if line.find( 'Glue' ) == 0:
        index = line.find( ':' )
        if index > 0:
          attr = line[:index]
          value = line[index + 1:].strip()
          if record['attr'].has_key( attr ):
            if type( record['attr'][attr] ) == type( [] ):
              record['attr'][attr].append( value )
            else:
              record['attr'][attr] = [record['attr'][attr], value]
          else:
            record['attr'][attr] = value

  return S_OK( response )
Exemplo n.º 4
0
 def export_executeCommand( self, command ):
   """ Execute a command locally and return its output
   """
   result = shellCall( 60, command )
   return result
Exemplo n.º 5
0
def ldapsearchBDII(filt=None, attr=None, host=None, base=None):
    """ Python wrapper for ldapserch at bdii.
      
      :param  filt:    Filter used to search ldap, default = '', means select all
      :param  attr:    Attributes returned by ldapsearch, default = '*', means return all
      :param  host:    Host used for ldapsearch, default = 'lcg-bdii.cern.ch:2170', can be changed by $LCG_GFAL_INFOSYS
      
      :return: standard DIRAC answer with Value equals to list of ldapsearch responses

      Each element of list is dictionary with keys:
      
        'dn':                 Distinguished name of ldapsearch response
        'objectClass':        List of classes in response
        'attr':               Dictionary of attributes
  """

    if filt == None:
        filt = ''
    if attr == None:
        attr = ''
    if host == None:
        host = 'lcg-bdii.cern.ch:2170'
    if base == None:
        base = 'Mds-Vo-name=local,o=grid'

    if type(attr) == types.ListType:
        attr = ' '.join(attr)

    cmd = 'ldapsearch -x -LLL -h %s -b %s "%s" %s' % (host, base, filt, attr)
    result = shellCall(0, cmd)

    response = []

    if not result['OK']:
        return result

    status = result['Value'][0]
    stdout = result['Value'][1]
    stderr = result['Value'][2]

    if not status == 0:
        return S_ERROR(stderr)

    lines = []
    for line in stdout.split("\n"):
        if line.find(" ") == 0:
            lines[-1] += line.strip()
        else:
            lines.append(line.strip())

    record = None
    for line in lines:
        if line.find('dn:') == 0:
            record = {
                'dn': line.replace('dn:', '').strip(),
                'objectClass': [],
                'attr': {
                    'dn': line.replace('dn:', '').strip()
                }
            }
            response.append(record)
            continue
        if record:
            if line.find('objectClass:') == 0:
                record['objectClass'].append(
                    line.replace('objectClass:', '').strip())
                continue
            if line.find('Glue') == 0:
                index = line.find(':')
                if index > 0:
                    attr = line[:index]
                    value = line[index + 1:].strip()
                    if record['attr'].has_key(attr):
                        if type(record['attr'][attr]) == type([]):
                            record['attr'][attr].append(value)
                        else:
                            record['attr'][attr] = [
                                record['attr'][attr], value
                            ]
                    else:
                        record['attr'][attr] = value

    return S_OK(response)
 def export_executeCommand(self, command):
     """ Execute a command locally and return its output
 """
     result = shellCall(60, command)
     return result
Exemplo n.º 7
0
          # Passwordless login, get the output
          return S_OK( ( 0, child.before, '' ) )
  
  
        if self.password:
          child.sendline( self.password )
          child.expect( pexpect.EOF )
          return S_OK( ( 0, child.before, '' ) )
        else:
          return S_ERROR( ( -2, child.before, '' ) )
      except Exception, x:
        res = ( -1 , 'Encountered exception %s: %s' % ( Exception, str( x ) ) )
        return S_ERROR( res )  
    else:
      # Try passwordless login
      result = shellCall( timeout, command )
#      print ( "!!! SSH command: %s returned %s\n" % (command, result) )
      if result['Value'][0] == 255:
        return S_ERROR ( ( -1, 'Cannot connect to host %s' % self.host, '' ) )
      return result

  def sshCall( self, timeout, cmdSeq ):
    """ Execute remote command via a ssh remote call
    
    :param int timeout: timeout of the command
    :param list cmdSeq: list of command components 
    """

    command = cmdSeq
    if type( cmdSeq ) == type( [] ):
      command = ' '.join( cmdSeq )
Exemplo n.º 8
0
                    # Passwordless login, get the output
                    return S_OK((0, child.before, ''))

                if self.password:
                    child.sendline(self.password)
                    child.expect(pexpect.EOF)
                    return S_OK((0, child.before, ''))
                else:
                    return S_ERROR((-2, child.before, ''))
            except Exception, x:
                res = (-1,
                       'Encountered exception %s: %s' % (Exception, str(x)))
                return S_ERROR(res)
        else:
            # Try passwordless login
            result = shellCall(timeout, command)
            #      print ( "!!! SSH command: %s returned %s\n" % (command, result) )
            if result['Value'][0] == 255:
                return S_ERROR(
                    (-1, 'Cannot connect to host %s' % self.host, ''))
            return result

    def sshCall(self, timeout, cmdSeq):
        """ Execute remote command via a ssh remote call
    """

        command = cmdSeq
        if type(cmdSeq) == type([]):
            command = ' '.join(cmdSeq)

        key = ''