Пример #1
0
    def __exec(self, cmd, rrdFile=None):
        """
        Executes a system command.

        :type cmd: string
        :param cmd: The cmd command to be executed.
        :type rrdFile: string
        :param rrdFile: name of the rrd file.
        :return: The value dictionary / S_ERROR with a message.
        """
        self.log.debug("RRD command: %s" % cmd)
        retVal = Subprocess.shellCall(0, cmd)
        if self.__logRRDCommands and rrdFile:
            try:
                logFile = "%s.log" % rrdFile
                with open(logFile, "a") as fd:
                    if not retVal["OK"] or retVal["Value"][0]:
                        fd.write("ERROR %s\n" % cmd)
                    else:
                        fd.write("OK    %s\n" % cmd)
            except Exception as e:
                self.log.warn("Cannot write log %s: %s" % (logFile, str(e)))
        if not retVal["OK"]:
            return retVal
        retTuple = retVal["Value"]
        if retTuple[0]:
            return S_ERROR("Failed to execute rrdtool: %s" % (retTuple[2]))
        return retVal
Пример #2
0
 def __checkoutFromCVS( self ):
   cmd = "cvs export -d '%s' '%s'" % ( self.params.sourceURL, os.path.join( self.params.destination, self.params.name ) )
   gLogger.verbose( "Executing: %s" % cmd )
   result = Subprocess.shellCall( 900, cmd )
   if not result[ 'OK' ]:
     return S_ERROR( "Error while retrieving sources from CVS: %s" % result[ 'Message' ] )
   exitStatus, stdData, errData = result[ 'Value' ]
   if exitStatus:
     return S_ERROR( "Error while retrieving sources from CVS: %s" % "\n".join( [ stdData, errData ] ) )
   return S_OK()
Пример #3
0
 def __checkoutFromSVN( self ):
   cmd = "svn export --trust-server-cert --non-interactive '%s/%s' '%s'" % ( self.params.sourceURL, self.params.version,
                                                                             os.path.join( self.params.destination, self.params.name ) )
   gLogger.verbose( "Executing: %s" % cmd )
   result = Subprocess.shellCall( 900, cmd )
   if not result[ 'OK' ]:
     return S_ERROR( "Error while retrieving sources from SVN: %s" % result[ 'Message' ] )
   exitStatus, stdData, errData = result[ 'Value' ]
   if exitStatus:
     return S_ERROR( "Error while retrieving sources from SVN: %s" % "\n".join( [ stdData, errData ] ) )
   return S_OK()
Пример #4
0
 def __getLastUpdateTime( self, rrdFile ):
   """
   Get last update time from an rrd
   """
   cmd = "%s last %s" % ( self.rrdExec, rrdFile )
   retVal = Subprocess.shellCall( 0, cmd )
   if not retVal[ 'OK' ]:
     return retVal
   retTuple = retVal[ 'Value' ]
   if retTuple[0]:
     return S_ERROR( "Failed to fetch last update %s : %s" % ( rrdFile, retTuple[2] ) )
   return S_OK( int( retTuple[1].strip() ) )
Пример #5
0
 def __getLastUpdateTime(self, rrdFile):
     """
 Get last update time from an rrd
 """
     cmd = "%s last %s" % (self.rrdExec, rrdFile)
     retVal = Subprocess.shellCall(0, cmd)
     if not retVal['OK']:
         return retVal
     retTuple = retVal['Value']
     if retTuple[0]:
         return S_ERROR("Failed to fetch last update %s : %s" %
                        (rrdFile, retTuple[2]))
     return S_OK(int(retTuple[1].strip()))
Пример #6
0
 def __exec( self, cmd, rrdFile = None ):
   """
   Execute a system command
   """
   self.log.debug( "RRD command: %s" % cmd )
   retVal = Subprocess.shellCall( 0, cmd )
   if self.__logRRDCommands and rrdFile:
     try:
       logFile = "%s.log" % rrdFile
       fd = file( logFile, "a" )
       if not retVal[ 'OK' ] or retVal[ 'Value' ][0]:
         fd.write( "ERROR %s\n" % cmd )
       else:
         fd.write( "OK    %s\n" % cmd )
       fd.close()
     except Exception, e:
       self.log.warn( "Cannot write log %s: %s" % ( logFile, str( e ) ) )
Пример #7
0
    def __getLastUpdateTime(self, rrdFile):
        """
        Gets last update time from an rrd.

        :type rrdFile: string
        :param rrdFile: name of the rrd file.
        :return: S_OK / S_ERROR with a message.
        """
        cmd = "%s last %s" % (self.rrdExec, rrdFile)
        retVal = Subprocess.shellCall(0, cmd)
        if not retVal["OK"]:
            return retVal
        retTuple = retVal["Value"]
        if retTuple[0]:
            return S_ERROR("Failed to fetch last update %s : %s" %
                           (rrdFile, retTuple[2]))
        return S_OK(int(retTuple[1].strip()))
Пример #8
0
 def __exec(self, cmd, rrdFile=None):
     """
 Execute a system command
 """
     self.log.debug("RRD command: %s" % cmd)
     retVal = Subprocess.shellCall(0, cmd)
     if self.__logRRDCommands and rrdFile:
         try:
             logFile = "%s.log" % rrdFile
             fd = file(logFile, "a")
             if not retVal['OK'] or retVal['Value'][0]:
                 fd.write("ERROR %s\n" % cmd)
             else:
                 fd.write("OK    %s\n" % cmd)
             fd.close()
         except Exception, e:
             self.log.warn("Cannot write log %s: %s" % (logFile, str(e)))
Пример #9
0
   return {"success":"false","error":error}
 gLogger.info("Split certificate(s) to public and private keys")
 keyList = list()
 from DIRAC.Core.Utilities import Subprocess
 for i in descriptionList:
   key = dict()
   name = i["name"]
   p12 = i["p12"]
   key["pem"] = i["pem"]
   for j in "pub","private":
     tmp = "".join(random.choice(string.letters) for x in range(10))
     key[j] = os.path.join(storePath,tmp)
   cmdCert = "openssl pkcs12 -clcerts -nokeys -in %s -out %s -password file:%s" % (name,key["pub"],p12)
   cmdKey = "openssl pkcs12 -nocerts -in %s -out %s -passout file:%s -password file:%s" % (name,key["private"],key["pem"],p12)
   for cmd in cmdCert,cmdKey:
     result = Subprocess.shellCall(900,cmd)
     gLogger.debug("Command is: %s" % cmd)
     gLogger.debug("Result is: %s" % result)
     if not result["OK"]:
       shutil.rmtree(storePath)
       gLogger.error(result["Message"])
       error =  "Error while executing SSL command: %s" % result["Message"]
       error = error + disclaimer
       gLogger.debug("Service response: %s" % error)
       return {"success":"false","error":error}
   keyList.append(key)
 if not len(keyList) > 0:
   shutil.rmtree(storePath)
   error = "List of public and private keys is empty"
   gLogger.error(error)
   error = error + disclaimer
Пример #10
0
 keyList = list()
 from DIRAC.Core.Utilities import Subprocess
 for i in descriptionList:
     key = dict()
     name = i["name"]
     p12 = i["p12"]
     key["pem"] = i["pem"]
     for j in "pub", "private":
         tmp = "".join(random.choice(string.letters) for x in range(10))
         key[j] = os.path.join(storePath, tmp)
     cmdCert = "openssl pkcs12 -clcerts -nokeys -in %s -out %s -password file:%s" % (
         name, key["pub"], p12)
     cmdKey = "openssl pkcs12 -nocerts -in %s -out %s -passout file:%s -password file:%s" % (
         name, key["private"], key["pem"], p12)
     for cmd in cmdCert, cmdKey:
         result = Subprocess.shellCall(900, cmd)
         gLogger.debug("Command is: %s" % cmd)
         gLogger.debug("Result is: %s" % result)
         if not result["OK"]:
             shutil.rmtree(storePath)
             gLogger.error(result["Message"])
             error = "Error while executing SSL command: %s" % result[
                 "Message"]
             error = error + disclaimer
             gLogger.debug("Service response: %s" % error)
             return {"success": "false", "error": error}
     keyList.append(key)
 if not len(keyList) > 0:
     shutil.rmtree(storePath)
     error = "List of public and private keys is empty"
     gLogger.error(error)