예제 #1
0
class FileCatalogProxyClient(object):
    """File catalog client for the File Catalog proxy service"""
    def __init__(self, fcName, **kwargs):
        """Constructor of the LCGFileCatalogProxy client class"""
        self.method = None
        self.fcName = fcName
        self.rpc = Client(url="DataManagement/FileCatalogProxy", timeout=120)
        self.valid = False
        self.valid = self.rpc.ping()["OK"]
        self.interfaceMethods = None

    def isOK(self):
        """Is the Catalog available?"""
        return self.valid

    def getName(self):
        """Get the file catalog name"""
        return self.fcName

    def setInterfaceMethods(self, methodTuple):
        self.interfaceMethods = methodTuple

    def getInterfaceMethods(self):
        return self.interfaceMethods

    def __getattr__(self, name):
        self.method = name
        return self.execute

    def execute(self, *parms, **kws):
        """Magic method dispatcher"""
        return self.rpc.callProxyMethod(self.fcName, self.method, parms, kws)
예제 #2
0
    def doCommand(self):
        """
        The Command pings a service on a vobox, it needs a service URL to ping it.

        :returns: a dict with the following:

          .. code-block:: python

            {
              'serviceUpTime' : <serviceUpTime>,
              'machineUpTime' : <machineUpTime>,
              'site'          : <site>,
              'system'        : <system>,
              'service'       : <service>
            }

        """

        # INPUT PARAMETERS

        if "serviceURL" not in self.args:
            return self.returnERROR(
                S_ERROR('"serviceURL" not found in self.args'))
        serviceURL = self.args["serviceURL"]

        ##

        parsed = parse.urlparse(serviceURL)
        site = parsed[1].split(":")[0]

        try:
            system, service = parsed[2].strip("/").split("/")
        except ValueError:
            return self.returnERROR(
                S_ERROR('"%s" seems to be a malformed url' % serviceURL))

        pinger = Client(url=serviceURL)
        resPing = pinger.ping()

        if not resPing["OK"]:
            return self.returnERROR(resPing)

        serviceUpTime = resPing["Value"].get("service uptime", 0)
        machineUpTime = resPing["Value"].get("host uptime", 0)

        result = {
            "site": site,
            "system": system,
            "service": service,
            "serviceUpTime": serviceUpTime,
            "machineUpTime": machineUpTime,
        }

        return S_OK(result)
예제 #3
0
def main():
    with open(os.devnull, "w") as redirectStdout, open(os.devnull, "w") as redirectStderr:
        from DIRAC import gLogger
        from DIRAC.ConfigurationSystem.Client.ConfigurationData import gConfigurationData

        gConfigurationData.setOptionInCFG("/DIRAC/Security/UseServerCertificate", "true")
        gLogger.setLevel("FATAL")
        from DIRAC.Core.Base.Client import Client

        rpc = Client(url="dips://localhost:%s" % sys.argv[1])
        res = rpc.ping()
        time.sleep(0.1)
        sys.exit(0 if res["OK"] else 1)