예제 #1
0
파일: sfascan.py 프로젝트: gnogueras/sfa
    def get_version(self):
        ### if we already know the answer:
        if self.probed:
            return self._version
        ### otherwise let's look in the cache file
        logger.debug("searching in version cache %s" % self.url())
        cached_version = VersionCache().get(self.url())
        if cached_version is not None:
            logger.info("Retrieved version info from cache %s" % self.url())
            return cached_version
        ### otherwise let's do the hard work
        # dummy to meet Sfi's expectations for its 'options' field
        class DummyOptions:
            pass

        options = DummyOptions()
        options.verbose = self.verbose
        options.timeout = 10
        try:
            client = Sfi(options)
            client.read_config()
            client.bootstrap()
            key_file = client.private_key
            cert_file = client.my_gid
            logger.debug("using key %s & cert %s" % (key_file, cert_file))
            url = self.url()
            logger.info('issuing GetVersion at %s' % url)
            # setting timeout here seems to get the call to fail - even though the response time is fast
            #server=SfaServerProxy(url, key_file, cert_file, verbose=self.verbose, timeout=options.timeout)
            server = SfaServerProxy(url,
                                    key_file,
                                    cert_file,
                                    verbose=self.verbose)
            self._version = ReturnValue.get_value(server.GetVersion())
        except:
            logger.log_exc("failed to get version")
            self._version = {}
        # so that next run from this process will find out
        self.probed = True
        # store in version cache so next processes will remember for an hour
        cache = VersionCache()
        cache.set(self.url(), self._version)
        cache.save()
        logger.debug("Saved version for url=%s in version cache" % self.url())
        # that's our result
        return self._version
예제 #2
0
#! /usr/bin/env python

# sfi -- slice-based facility interface

import sys
from sfa.client.sfi import Sfi

if __name__ == "__main__":
    sys.exit(Sfi().main())