Ejemplo n.º 1
0
 def __init__(
     self, jobManagerClient=False, sbRPCClient=False, sbTransferClient=False, useCertificates=False, timeout=120
 ):
     """ WMS Client constructor
 """
     gProxyManager.uploadProxy()
     self.useCertificates = useCertificates
     self.jobManagerClient = jobManagerClient
     self.sbRPCClient = sbRPCClient
     self.sbTransferClient = sbTransferClient
     self.timeout = timeout
Ejemplo n.º 2
0
    def submitJob(self, jdl):
        """ Submit one job specified by its JDL to WMS
    """

        if not self.jobManagerClient:
            jobManager = RPCClient(
                "WorkloadManagement/JobManager", useCertificates=self.useCertificates, timeout=self.timeout
            )
        else:
            jobManager = self.jobManagerClient
        if os.path.exists(jdl):
            fic = open(jdl, "r")
            jdlString = fic.read()
            fic.close()
        else:
            # If file JDL does not exist, assume that the JDL is
            # passed as a string
            jdlString = jdl

        # Check the validity of the input JDL
        jdlString = jdlString.strip()
        if jdlString.find("[") != 0:
            jdlString = "[%s]" % jdlString
        classAdJob = ClassAd(jdlString)
        if not classAdJob.isOK():
            return S_ERROR("Invalid job JDL")

        # Check the size and the contents of the input sandbox
        result = self.__uploadInputSandbox(classAdJob)
        if not result["OK"]:
            return result

        # Submit the job now and get the new job ID
        result = jobManager.submitJob(classAdJob.asJDL())

        if not result["OK"]:
            return result
        jobID = result["Value"]
        if "requireProxyUpload" in result and result["requireProxyUpload"]:
            gProxyManager.uploadProxy()

        # print "Sandbox uploading"
        return S_OK(jobID)
Ejemplo n.º 3
0
  def uploadProxy( self, group ):
    """Upload a proxy to the DIRAC WMS.  This method

       Example usage:

       >>> print diracAdmin.uploadProxy('lhcb_pilot')
       {'OK': True, 'Value': 0L}

       @param group: DIRAC Group
       @type job: string
       @return: S_OK,S_ERROR

       @param permanent: Indefinitely update proxy
       @type permanent: boolean

    """
    return gProxyManager.uploadProxy( diracGroup = group )
Ejemplo n.º 4
0
  def uploadProxy( self, group ):
    """Upload a proxy to the DIRAC WMS.  This method

       Example usage:

         >>> print diracAdmin.uploadProxy('lhcb_pilot')
         {'OK': True, 'Value': 0L}

       :param group: DIRAC Group
       :type job: string
       :return: S_OK,S_ERROR

       :param permanent: Indefinitely update proxy
       :type permanent: boolean

    """
    return gProxyManager.uploadProxy( diracGroup = group )
Ejemplo n.º 5
0
def uploadProxy( params ):
  DIRAC.gLogger.info( "Loading user proxy" )
  proxyLoc = params.proxyLoc
  if not proxyLoc:
    proxyLoc = Locations.getDefaultProxyLocation()
  if not proxyLoc:
    return S_ERROR( "Can't find any proxy" )

  if params.onTheFly:
    DIRAC.gLogger.info( "Uploading proxy on-the-fly" )
    certLoc = params.certLoc
    keyLoc = params.keyLoc
    if not certLoc or not keyLoc:
      cakLoc = Locations.getCertificateAndKeyLocation()
      if not cakLoc:
        return S_ERROR( "Can't find user certificate and key" )
      if not certLoc:
        certLoc = cakLoc[0]
      if not keyLoc:
        keyLoc = cakLoc[1]

    DIRAC.gLogger.info( "Cert file %s" % certLoc )
    DIRAC.gLogger.info( "Key file  %s" % keyLoc )

    testChain = X509Chain()
    retVal = testChain.loadKeyFromFile( keyLoc, password = params.userPasswd )
    if not retVal[ 'OK' ]:
      passwdPrompt = "Enter Certificate password:"******"\n" )
      else:
        userPasswd = getpass.getpass( passwdPrompt )
      params.userPasswd = userPasswd

    DIRAC.gLogger.info( "Loading cert and key" )
    chain = X509Chain()
    #Load user cert and key
    retVal = chain.loadChainFromFile( certLoc )
    if not retVal[ 'OK' ]:
      return S_ERROR( "Can't load %s" % certLoc )
    retVal = chain.loadKeyFromFile( keyLoc, password = params.userPasswd )
    if not retVal[ 'OK' ]:
      return S_ERROR( "Can't load %s" % keyLoc )
    DIRAC.gLogger.info( "User credentials loaded" )

    diracGroup = params.diracGroup
    if not diracGroup:
      result = chain.getCredentials()
      if not result['OK']:
        return result
      if 'group' not in result['Value']:
        return S_ERROR( 'Can not get Group from existing credentials' )
      diracGroup = result['Value']['group']
    restrictLifeTime = params.proxyLifeTime

  else:
    proxyChain = X509Chain()
    retVal = proxyChain.loadProxyFromFile( proxyLoc )
    if not retVal[ 'OK' ]:
      return S_ERROR( "Can't load proxy file %s: %s" % ( params.proxyLoc, retVal[ 'Message' ] ) )

    chain = proxyChain
    diracGroup = params.diracGroup
    if params.diracGroup:
      # Check that there is no conflict with the already present DIRAC group
      result = chain.getDIRACGroup( ignoreDefault = True )
      if result['OK'] and result['Value'] and result['Value'] == params.diracGroup:
        # No need to embed a new DIRAC group
        diracGroup = False

    restrictLifeTime = 0

  DIRAC.gLogger.info( " Uploading..." )
  return gProxyManager.uploadProxy( chain, diracGroup, restrictLifeTime = restrictLifeTime, rfcIfPossible = params.rfcIfPossible )
Ejemplo n.º 6
0
def uploadProxy( params ):
  DIRAC.gLogger.info( "Loading user proxy" )
  proxyLoc = params.proxyLoc
  if not proxyLoc:
    proxyLoc = Locations.getDefaultProxyLocation()
  if not proxyLoc:
    return S_ERROR( "Can't find any proxy" )

  proxyChain = X509Chain()
  retVal = proxyChain.loadProxyFromFile( proxyLoc )
  if not retVal[ 'OK' ]:
    return S_ERROR( "Can't load proxy file %s: %s" % ( params.proxyLoc, retVal[ 'Message' ] ) )

  if params.onTheFly:
    DIRAC.gLogger.info( "Uploading proxy on-the-fly" )
    certLoc = params.certLoc
    keyLoc = params.keyLoc
    if not certLoc or not keyLoc:
      cakLoc = Locations.getCertificateAndKeyLocation()
      if not cakLoc:
        return S_ERROR( "Can't find user certificate and key" )
      if not certLoc:
        certLoc = cakLoc[0]
      if not keyLoc:
        keyLoc = cakLoc[1]

    DIRAC.gLogger.info( "Cert file %s" % certLoc )
    DIRAC.gLogger.info( "Key file  %s" % keyLoc )

    testChain = X509Chain()
    retVal = testChain.loadKeyFromFile( keyLoc, password = params.userPasswd )
    if not retVal[ 'OK' ]:
      passwdPrompt = "Enter Certificate password:"******"\n" )
      else:
        userPasswd = getpass.getpass( passwdPrompt )
      params.userPasswd = userPasswd

    DIRAC.gLogger.info( "Loading cert and key" )
    chain = X509Chain()
    #Load user cert and key
    retVal = chain.loadChainFromFile( certLoc )
    if not retVal[ 'OK' ]:
      return S_ERROR( "Can't load %s" % certLoc )
    retVal = chain.loadKeyFromFile( keyLoc, password = params.userPasswd )
    if not retVal[ 'OK' ]:
      return S_ERROR( "Can't load %s" % keyLoc )
    DIRAC.gLogger.info( "User credentials loaded" )

    diracGroup = params.diracGroup
    if not diracGroup:
      diracGroup = CS.getDefaultUserGroup()
    restrictLifeTime = params.proxyLifeTime

  else:
    chain = proxyChain
    diracGroup = False
    restrictLifeTime = 0

  DIRAC.gLogger.info( " Uploading..." )
  return gProxyManager.uploadProxy( chain, diracGroup, restrictLifeTime = restrictLifeTime )
Ejemplo n.º 7
0
def uploadProxy(params):
  DIRAC.gLogger.info("Loading user proxy")
  proxyLoc = params.proxyLoc
  if not proxyLoc:
    proxyLoc = Locations.getDefaultProxyLocation()
  if not proxyLoc:
    return S_ERROR("Can't find any proxy")

  if params.onTheFly:
    DIRAC.gLogger.info("Uploading proxy on-the-fly")
    certLoc = params.certLoc
    keyLoc = params.keyLoc
    if not certLoc or not keyLoc:
      cakLoc = Locations.getCertificateAndKeyLocation()
      if not cakLoc:
        return S_ERROR("Can't find user certificate and key")
      if not certLoc:
        certLoc = cakLoc[0]
      if not keyLoc:
        keyLoc = cakLoc[1]

    DIRAC.gLogger.info("Cert file %s" % certLoc)
    DIRAC.gLogger.info("Key file  %s" % keyLoc)

    testChain = X509Chain()
    retVal = testChain.loadKeyFromFile(keyLoc, password=params.userPasswd)
    if not retVal['OK']:
      passwdPrompt = "Enter Certificate password:"******"\n")
      else:
        userPasswd = getpass.getpass(passwdPrompt)
      params.userPasswd = userPasswd

    DIRAC.gLogger.info("Loading cert and key")
    chain = X509Chain()
    # Load user cert and key
    retVal = chain.loadChainFromFile(certLoc)
    if not retVal['OK']:
      return S_ERROR("Can't load %s" % certLoc)
    retVal = chain.loadKeyFromFile(keyLoc, password=params.userPasswd)
    if not retVal['OK']:
      return S_ERROR("Can't load %s" % keyLoc)
    DIRAC.gLogger.info("User credentials loaded")

    diracGroup = params.diracGroup
    if not diracGroup:
      result = chain.getCredentials()
      if not result['OK']:
        return result
      if 'group' not in result['Value']:
        return S_ERROR('Can not get Group from existing credentials')
      diracGroup = result['Value']['group']
    restrictLifeTime = params.proxyLifeTime

  else:
    proxyChain = X509Chain()
    retVal = proxyChain.loadProxyFromFile(proxyLoc)
    if not retVal['OK']:
      return S_ERROR("Can't load proxy file %s: %s" % (params.proxyLoc, retVal['Message']))

    chain = proxyChain
    diracGroup = params.diracGroup
    if params.diracGroup:
      # Check that there is no conflict with the already present DIRAC group
      result = chain.getDIRACGroup(ignoreDefault=True)
      if result['OK'] and result['Value'] and result['Value'] == params.diracGroup:
        # No need to embed a new DIRAC group
        diracGroup = False

    restrictLifeTime = 0

  DIRAC.gLogger.info(" Uploading...")
  return gProxyManager.uploadProxy(
      chain,
      diracGroup,
      restrictLifeTime=restrictLifeTime,
      rfcIfPossible=params.rfcIfPossible)
Ejemplo n.º 8
0
        if self.enableCS:
            # After creating the proxy, we can try to connect to the server
            if not (result := self.__enableCS())["OK"]:
                return result

            # Step 2: Upload proxy to DIRAC server
            result = gProxyManager.getUploadedProxyLifeTime(credentials["subject"])
            if not result["OK"]:
                return result
            uploadedProxyLifetime = result["Value"]

            # Upload proxy to the server if it longer that uploaded one
            if credentials["secondsLeft"] > uploadedProxyLifetime:
                gLogger.notice("Upload proxy to server.")
                return gProxyManager.uploadProxy(proxy)
        return S_OK()

    def __enableCS(self):
        if not (result := Script.enableCS())["OK"] or not (result := gConfig.forceRefresh())["OK"]:
            return S_ERROR(f"Cannot contact CS: {result['Message']}")
        return result

    def howToSwitch(self) -> bool:
        """Helper message, how to switch access type(proxy or access token)"""
        if "DIRAC_USE_ACCESS_TOKEN" in self.ENV:
            src, useTokens = ("env", self.ENV.get("DIRAC_USE_ACCESS_TOKEN", "false").lower() in ("y", "yes", "true"))
        else:
            src, useTokens = (
                "conf",
                gConfig.getValue("/DIRAC/Security/UseTokens", "false").lower() in ("y", "yes", "true"),
Ejemplo n.º 9
0
def uploadProxy(params):
    DIRAC.gLogger.info("Loading user proxy")
    proxyLoc = params.proxyLoc
    if not proxyLoc:
        proxyLoc = Locations.getDefaultProxyLocation()
    if not proxyLoc:
        return S_ERROR("Can't find any proxy")

    if params.onTheFly:
        DIRAC.gLogger.info("Uploading proxy on-the-fly")
        certLoc = params.certLoc
        keyLoc = params.keyLoc
        if not certLoc or not keyLoc:
            cakLoc = Locations.getCertificateAndKeyLocation()
            if not cakLoc:
                return S_ERROR("Can't find user certificate and key")
            if not certLoc:
                certLoc = cakLoc[0]
            if not keyLoc:
                keyLoc = cakLoc[1]

        DIRAC.gLogger.info("Cert file %s" % certLoc)
        DIRAC.gLogger.info("Key file  %s" % keyLoc)

        testChain = X509Chain()
        retVal = testChain.loadKeyFromFile(keyLoc, password=params.userPasswd)
        if not retVal['OK']:
            if params.stdinPasswd:
                userPasswd = sys.stdin.readline().strip("\n")
            else:
                try:
                    userPasswd = prompt(u"Enter Certificate password: "******"Caught KeyboardInterrupt, exiting...")
            params.userPasswd = userPasswd

        DIRAC.gLogger.info("Loading cert and key")
        chain = X509Chain()
        # Load user cert and key
        retVal = chain.loadChainFromFile(certLoc)
        if not retVal['OK']:
            return S_ERROR("Can't load %s" % certLoc)
        retVal = chain.loadKeyFromFile(keyLoc, password=params.userPasswd)
        if not retVal['OK']:
            return S_ERROR("Can't load %s" % keyLoc)
        DIRAC.gLogger.info("User credentials loaded")
        restrictLifeTime = params.proxyLifeTime

    else:
        proxyChain = X509Chain()
        retVal = proxyChain.loadProxyFromFile(proxyLoc)
        if not retVal['OK']:
            return S_ERROR("Can't load proxy file %s: %s" %
                           (params.proxyLoc, retVal['Message']))

        chain = proxyChain
        restrictLifeTime = 0

    DIRAC.gLogger.info(" Uploading...")
    return gProxyManager.uploadProxy(proxy=chain,
                                     restrictLifeTime=restrictLifeTime,
                                     rfcIfPossible=params.rfcIfPossible)
Ejemplo n.º 10
0
def uploadProxy(params):
    DIRAC.gLogger.info("Loading user proxy")
    proxyLoc = params.proxyLoc
    if not proxyLoc:
        proxyLoc = Locations.getDefaultProxyLocation()
    if not proxyLoc:
        return S_ERROR("Can't find any proxy")

    proxyChain = X509Chain()
    retVal = proxyChain.loadProxyFromFile(proxyLoc)
    if not retVal['OK']:
        return S_ERROR("Can't load proxy file %s: %s" %
                       (params.proxyLoc, retVal['Message']))

    if params.onTheFly:
        DIRAC.gLogger.info("Uploading proxy on-the-fly")
        certLoc = params.certLoc
        keyLoc = params.keyLoc
        if not certLoc or not keyLoc:
            cakLoc = Locations.getCertificateAndKeyLocation()
            if not cakLoc:
                return S_ERROR("Can't find user certificate and key")
            if not certLoc:
                certLoc = cakLoc[0]
            if not keyLoc:
                keyLoc = cakLoc[1]

        DIRAC.gLogger.info("Cert file %s" % certLoc)
        DIRAC.gLogger.info("Key file  %s" % keyLoc)

        testChain = X509Chain()
        retVal = testChain.loadKeyFromFile(keyLoc, password=params.userPasswd)
        if not retVal['OK']:
            passwdPrompt = "Enter Certificate password:"******"\n")
            else:
                userPasswd = getpass.getpass(passwdPrompt)
            params.userPasswd = userPasswd

        DIRAC.gLogger.info("Loading cert and key")
        chain = X509Chain()
        #Load user cert and key
        retVal = chain.loadChainFromFile(certLoc)
        if not retVal['OK']:
            return S_ERROR("Can't load %s" % certLoc)
        retVal = chain.loadKeyFromFile(keyLoc, password=params.userPasswd)
        if not retVal['OK']:
            return S_ERROR("Can't load %s" % keyLoc)
        DIRAC.gLogger.info("User credentials loaded")

        diracGroup = params.diracGroup
        if not diracGroup:
            diracGroup = CS.getDefaultUserGroup()
        restrictLifeTime = params.proxyLifeTime

    else:
        chain = proxyChain
        diracGroup = False
        restrictLifeTime = 0

    DIRAC.gLogger.info(" Uploading...")
    return gProxyManager.uploadProxy(chain,
                                     diracGroup,
                                     restrictLifeTime=restrictLifeTime)