Esempio n. 1
0
    def _child(self, pipe, args, kwargs):
        signal.alarm(30)

        if not isinstance(self.cred, basestring):
            os.environ['X509_USER_CERT'] = self.cred.name
            os.environ['X509_USER_KEY'] = self.cred.name
            os.environ['X509_USER_PROXY'] = self.cred.name

        exit_code = 0
        try:
            if context_type is None:
                raise RuntimeError('Could not load the gfal2 python module')
            ctx = context_type()

            if isinstance(self.cred, basestring):
                # A IAM token is used for authentication, set it in the context
                s_cred = gfal2.cred_new("BEARER", self.cred.split(':')[0])
                try:
                    if isinstance(args[0], dict):
                        if "surl" in args[0].keys():
                            domain = urlparse.urlparse(
                                args[0]["surl"]).hostname
                        else:
                            domain = urlparse.urlparse(args[0]["old"]).hostname
                    else:
                        domain = urlparse.urlparse(args[0]).hostname
                except Exception, e:
                    # Will get a 401 from storage
                    domain = ""
                gfal2.cred_set(ctx, domain, s_cred)

            result = self.method(ctx, *args, **kwargs)
            pipe.write(json.dumps(result))
Esempio n. 2
0
def parse_args(args, io):

    if args.srmv in svcVers:
        svcVer = str(args.srmv)
    else:
        errstr = 'srmv parameter must be one of '+ \
                ', '.join([x for x in svcVers])+'. '+args.srmv+' given'
        io.set_status(nap.CRITICAL, errstr)
        return 1
    os.environ['LCG_GFAL_INFOSYS'] = args.ldap_url

    if args.x509:
        cred = gfal2.cred_new("X509_CERT", args.x509)
        gfal2.cred_set(ctx, "srm://", cred)
        gfal2.cred_set(ctx, "gsiftp://", cred)
Esempio n. 3
0
def _get_cred(cred_file):
    if cred_file:
        cred = gfal2.cred_new('X509_CERT', str(cred_file))
    else:
        return None
    return cred
Esempio n. 4
0
    token = args[2]

    if action not in [
            "list-classes", "list-transitions", "get-qos", "get-target-qos",
            "change-qos"
    ]:
        parser.error("Unrecognized action: %s" % action)

    if action == "change-qos":
        if len(args) < 4:
            parser.error("Missing <target-qos> argument!")
        target_qos = args[3]

    # Create Gfal2 handler
    context = gfal2.creat_context()
    cred = gfal2.cred_new("BEARER", token)
    host = '{uri.scheme}://{uri.netloc}/'.format(uri=urlparse(url))
    gfal2.cred_set(context, host, cred)

    if action == "list-classes":
        print "Dataobject: %s" % context.qos_check_classes(host, "dataobject")
        print "Container: %s" % context.qos_check_classes(host, "container")
    elif action == "list-transitions":
        print context.check_available_qos_transitions(url)
    elif action == "get-qos":
        print context.check_file_qos(url)
    elif action == "get-target-qos":
        print context.check_target_qos(url)
    elif action == "change-qos":
        print context.change_object_qos(url, target_qos)
    else:
    if options.checksum:
        (alg, val) = options.checksum.split(':')
        params.set_user_defined_checksum(alg, val)
        print("User defined checksum: %s:%s" %
              params.get_user_defined_checksum())

    if options.source_space_token:
        params.src_spacetoken = options.source_space_token
        print("Source space token: %s" % params.src_spacetoken)
    if options.dest_space_token:
        params.dst_spacetoken = options.dest_space_token
        print("Destination space token: %s" % params.dst_spacetoken)

    if options.source_cred:
        s_cred = gfal2.cred_new("X509_CERT", options.source_cred)
        gfal2.cred_set(ctx, source, s_cred)
        print("Source credentials: %s" % options.source_cred)
    if options.dest_cred:
        d_cred = gfal2.cred_new("X509_CERT", options.dest_cred)
        gfal2.cred_set(ctx, dest, d_cred)
        print("Destination credentials: %s" % options.dest_cred)
    # Five minutes timeout
    params.timeout = 300

    # Copy!
    # Keep in mind source and destination can have different protocols,
    # and gfal2 will deal with it
    # (i.e. source can be file:/// and destination gsiftp://)
    try:
        r = ctx.filecopy(params, source, dest)
Esempio n. 6
0
import logging

streamHandler = logging.StreamHandler(sys.stdout)
streamHandler.setFormatter(
    logging.Formatter(
        "%(asctime)s.%(msecs)03d [%(levelname)s](%(module)s:%(lineno)d) %(message)s",
        "%d %b %H:%M:%S"))

gfal2_logger = logging.getLogger("gfal2")
gfal2_logger.addHandler(streamHandler)
gfal2_logger.setLevel(logging.DEBUG)
gfal2.set_verbose(gfal2.verbose_level.debug)
gfal2.set_verbose(gfal2.verbose_level.trace)

dst = 'davs://storm.example:8443/wlcg/test-not-found'
ctx = gfal2.creat_context()

ctx.set_opt_boolean("HTTP PLUGIN", "KEEP_ALIVE", False)

cred = gfal2.cred_new("BEARER", os.getenv('BEARER_TOKEN'))
gfal2.cred_set(ctx, dst, cred)

try:
    ctx.stat(dst)
except:
    pass
try:
    ctx.stat(dst)
except:
    pass