예제 #1
0
def exercise_ch(host, port, keyfile, certfile):
    url = 'https://%s' % (host)
    if port:
        url = '%s:%s' % (url, port)
    server = make_client(url, keyfile, certfile)
    print server
    try:
        print server.GetVersion()
    except xmlrpclib.Error, v:
        print 'ERROR', v
예제 #2
0
def exercise_ch(host, port, keyfile, certfile):
    url = "https://%s" % (host)
    if port:
        url = "%s:%s" % (url, port)
    server = make_client(url, keyfile, certfile)
    print server
    try:
        print server.GetVersion()
    except xmlrpclib.Error, v:
        print "ERROR", v
예제 #3
0
파일: scs.py 프로젝트: innnkkki/geni-tools
 def GetVersion(self, printResult=True):
     server = make_client(self.url, keyfile=self.key, certfile=self.cert, verbose=self.verbose, timeout=self.timeout)
     try:
         result = server.GetVersion()
     except xmlrpclib.Error as v:
         if printResult:
             print "ERROR", v
         raise
     if printResult:
         print "GetVersion said:"
         pp = pprint.PrettyPrinter(indent=4)
         print pp.pformat(result)
     return result
예제 #4
0
    def GetVersion(self, printResult=True):
        server = make_client(self.url, keyfile=self.key, certfile=self.cert, verbose=self.verbose, timeout=self.timeout)

        # As a sample of how to do make_client specifying the SSL version / ciphers (these are the defaults though):
#        import ssl
#        server = make_client(self.url, keyfile=self.key, certfile=self.cert, verbose=self.verbose, timeout=self.timeout, ssl_version=ssl.PROTOCOL_TLSv1, ciphers="HIGH:MEDIUM:!ADH:!SSLv2:!MD5:!RC4:@STRENGTH")

        try:
            result = server.GetVersion()
        except xmlrpclib.Error as v:
            if printResult:
                print "ERROR", v
            raise
        except Exception, e:
            if printResult:
                import traceback
                print "ERROR: %s" % traceback.format_exc()
            raise
예제 #5
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    opts = parse_args(argv)[0]
    level = logging.INFO
    if opts.debug:
        level = logging.DEBUG
        
    # Read in config file options, command line gets priority
    global config
    optspath = None
    if not opts.configfile is None:
        optspath = os.path.expanduser(opts.configfile)

    config = read_config(optspath)  
        
    for (key,val) in config['gcf-test'].items():
        if hasattr(opts,key) and getattr(opts,key) is None:
            setattr(opts,key,val)
        if not hasattr(opts,key):
            setattr(opts,key,val)      
    
    # Determine the AM and CH hostnames from the config file
    if getattr(opts,'ch') is None:
        host = config['geni clearinghouse']['host']
        port = config['geni clearinghouse']['port']
        if not host.startswith('http'):
            host = 'https://%s' % host.strip('/')
        url = "%s:%s/" % (host,port)
        setattr(opts,'ch',url)
        
    if getattr(opts,'am') is None:
        host = config['proxy aggregate_manager']['host']
        port = config['proxy aggregate_manager']['port']
        if not host.startswith('http'):
            host = 'https://%s' % host.strip('/')
        url = "%s:%s/" % (host,port)
        setattr(opts,'am',url)

    logging.basicConfig(level=level)
    logger = logging.getLogger('gcf-test')
    if not opts.keyfile or not opts.certfile:
        sys.exit('Missing required arguments -k for Key file and -c for cert file')

    keyf = getAbsPath(opts.keyfile)
    certf = getAbsPath(opts.certfile)

    if not os.path.exists(certf):
        sys.exit("Proxy certfile %s doesn't exist" % certf)
    if not os.path.getsize(certf) > 0:
        sys.exit("Proxy certfile %s is empty" % certf)

    if not os.path.exists(keyf):
        sys.exit("Proxy keyfile %s doesn't exist" % keyf)
    if not os.path.getsize(keyf) > 0:
        sys.exit("Proxy keyfile %s is empty" % keyf)

    logger.info('CH Server is %s. Using keyfile %s, certfile %s', opts.ch, keyf, certf)
    logger.info('AM Server is %s. Using keyfile %s, certfile %s', opts.am, keyf, certf)
    ch_server = make_client(opts.ch, keyf, certf, opts.debug_rpc)
    am_server = make_client(opts.am, keyf, certf, opts.debug_rpc)
    exercise_am(ch_server, am_server, certf)

    return 0
예제 #6
0
class Service(object):
    def __init__(self, url, key=None, cert=None, timeout=None, verbose=False):
        self.url = url
        self.timeout=timeout
        self.verbose=verbose
        if isinstance(url, unicode):
            url2 = url.encode('ISO-8859-1')
        else:
            url2 = url
        type, uri = urllib.splittype(url2.lower())
        if type == "https":
            self.key=key
            self.cert=cert
        else:
            self.key=None
            self.cert=None

    def GetVersion(self, printResult=True):
        server = make_client(self.url, keyfile=self.key, certfile=self.cert, verbose=self.verbose, timeout=self.timeout)
        try:
            result = server.GetVersion()
        except xmlrpclib.Error as v:
            if printResult:
                print "ERROR", v
            raise
        if printResult:
            print "GetVersion said:"
            pp = pprint.PrettyPrinter(indent=4)
            print pp.pformat(result)
        return result

    def ListAggregates(self, printResult=True):
        server = make_client(self.url, keyfile=self.key, certfile=self.cert, verbose=self.verbose, timeout=self.timeout)
        try:
            result = server.ListAggregates()
        except xmlrpclib.Error as v:
            if printResult:
                print "ERROR", v
            raise
        if printResult:
            print "ListAggregates said:"
            pp = pprint.PrettyPrinter(indent=4)
            print pp.pformat(result)
        return result

    def ComputePath(self, slice_urn, request_rspec, options, savedFile=None):
        """Invoke the XML-RPC service with the request rspec.
        Create an SCS PathInfo from the result.
        """
        result = None
        if savedFile and os.path.exists(savedFile) and os.path.getsize(savedFile) > 0:
            # read it in
            try:
                savedSCSResults = None
                with open(savedFile, 'r') as sfP:
                    savedStr = str(sfP.read())
                    result = json.loads(savedStr, encoding='ascii', cls=DateTimeAwareJSONDecoder)
            except Exception, e:
                import traceback
                print "ERROR", e, traceback.format_exc()
                raise
        if result is None:
            server = make_client(self.url, keyfile=self.key, certfile=self.cert, verbose=self.verbose, timeout=self.timeout)
            arg = dict(slice_urn=slice_urn, request_rspec=request_rspec,
                       request_options=options)
#        import json
#        print "Calling SCS with arg: %s" % (json.dumps(arg,
#                                                       ensure_ascii=True,
#                                                       indent=2))
            try:
                result = server.ComputePath(arg)
            except xmlrpclib.Error as v:
                print "ERROR", v
                raise

        self.result = result # save the raw result for stitchhandler to print
        geni_result = Result(result) # parse result
        if geni_result.isSuccess():
            return PathInfo(geni_result.value())
        else:
                # when there is no route I seem to get:
#{'geni_code': 3} MxTCE ComputeWorker return error message ' Action_ProcessRequestTopology_MP2P::Finish() Cannot find the set of paths for the RequestTopology. '.
            if self.result:
                raise StitchingServiceFailedError(None, self.result)
            else:
                raise StitchingServiceFailedError("ComputePath invocation failed: %s" % geni_result.errorString(), self.result)
예제 #7
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    opts = parse_args(argv)[0]
    level = logging.INFO
    if opts.debug:
        level = logging.DEBUG

    # Read in config file options, command line gets priority
    global config
    optspath = None
    if not opts.configfile is None:
        optspath = os.path.expanduser(opts.configfile)

    config = read_config(optspath)

    for (key, val) in config["gcf-test"].items():
        if hasattr(opts, key) and getattr(opts, key) is None:
            setattr(opts, key, val)
        if not hasattr(opts, key):
            setattr(opts, key, val)

    # Determine the AM and CH hostnames from the config file
    if getattr(opts, "ch") is None:
        host = config["clearinghouse"]["host"]
        port = config["clearinghouse"]["port"]
        if not host.startswith("http"):
            host = "https://%s" % host.strip("/")
        url = "%s:%s/" % (host, port)
        setattr(opts, "ch", url)

    if getattr(opts, "am") is None:
        host = config["aggregate_manager"]["host"]
        port = config["aggregate_manager"]["port"]
        if not host.startswith("http"):
            host = "https://%s" % host.strip("/")
        url = "%s:%s/" % (host, port)
        setattr(opts, "am", url)

    logging.basicConfig(level=level)
    logger = logging.getLogger("gcf-test")
    if not opts.keyfile or not opts.certfile:
        sys.exit("Missing required arguments -k for Key file and -c for cert file")

    keyf = getAbsPath(opts.keyfile)
    certf = getAbsPath(opts.certfile)
    if not os.path.exists(certf):
        sys.exit("Client certfile %s doesn't exist" % certf)
    if not os.path.getsize(certf) > 0:
        sys.exit("Client certfile %s is empty" % certf)

    if not os.path.exists(keyf):
        sys.exit("Client keyfile %s doesn't exist" % keyf)
    if not os.path.getsize(keyf) > 0:
        sys.exit("Client keyfile %s is empty" % keyf)
    #    print 'a_v: %d' % opts.api_version
    logger.info("CH Server is %s. Using keyfile %s, certfile %s", opts.ch, keyf, certf)
    logger.info("AM Server is %s. Using keyfile %s, certfile %s", opts.am, keyf, certf)
    ch_server = make_client(opts.ch, keyf, certf, opts.debug_rpc)
    am_server = make_client(opts.am, keyf, certf, opts.debug_rpc)
    exercise_am(ch_server, am_server, opts.api_version)

    return 0
예제 #8
0
        Create an SCS PathInfo from the result.
        """
        result = None
        if savedFile and os.path.exists(savedFile) and os.path.getsize(savedFile) > 0:
            # read it in
            try:
                savedSCSResults = None
                with open(savedFile, 'r') as sfP:
                    savedStr = str(sfP.read())
                    result = json.loads(savedStr, encoding='ascii', cls=DateTimeAwareJSONDecoder)
            except Exception, e:
                import traceback
                print "ERROR", e, traceback.format_exc()
                raise
        if result is None:
            server = make_client(self.url, keyfile=self.key, certfile=self.cert, verbose=self.verbose, timeout=self.timeout)
            arg = dict(slice_urn=slice_urn, request_rspec=request_rspec,
                       request_options=options)
#        import json
#        print "Calling SCS with arg: %s" % (json.dumps(arg,
#                                                       ensure_ascii=True,
#                                                       indent=2))
            try:
                result = server.ComputePath(arg)
            except xmlrpclib.Error as v:
                print "ERROR", v
                raise

        self.result = result # save the raw result for stitchhandler to print
        geni_result = Result(result) # parse result
        if geni_result.isSuccess():