コード例 #1
0
ファイル: SubCommand.py プロジェクト: blinkseb/CRABClient
    def __init__(self, logger, cmdargs = None, disable_interspersed_args = False):
        """
        Initialize common client parameters
        """
        if not hasattr(self, 'name'):
            self.name = self.__class__.__name__

        ## The command logger.
        self.logger = logger
        self.logfile = self.logger.logfile
        self.logger.debug("Executing command: '%s'" % str(self.name))

        self.proxy = None
        self.restClass = CRABClient.Emulator.getEmulator('rest')

        ## Get the command configuration.
        self.cmdconf = commandsConfiguration.get(self.name)

        ## Get the CRAB cache file.
        self.crab3dic = self.getConfiDict()

        ## The options parser.
        self.parser = CRABCmdOptParser(self.name, self.__doc__,  disable_interspersed_args)

        ## Define the command options.
        self.setSuperOptions()

        ## Parse the command options/arguments.
        cmdargs = cmdargs or []
        (self.options, self.args) = self.parser.parse_args(cmdargs)

        ## Validate the command options.
        self.validateOptions()

        ## Get the VO group/role from the command options (if the command requires these
        ## options).
        proxyOptsSetPlace = {'set_in': {'group': "default", 'role': "default"}, 'for_set_use': ""}
        msgadd = []
        self.voGroup, self.voRole = "", "NULL"
        if self.cmdconf['requiresProxyVOOptions']:
            proxyOptsSetPlace['for_set_use'] = "cmdopts"
            if self.options.voGroup is not None:
                self.voGroup = self.options.voGroup
                proxyOptsSetPlace['set_in']['group'] = "cmdopts"
                msgadd.append("VO group '%s'" % (self.voGroup))
            if self.options.voRole is not None:
                self.voRole = self.options.voRole if self.options.voRole != "" else "NULL"
                proxyOptsSetPlace['set_in']['role'] = "cmdopts"
                msgadd.append("VO role '%s'" % (self.voRole))
        if msgadd:
            msg = "Using %s as specified in the crab command options." % (" and ".join(msgadd))
            self.logger.debug(msg)

        ## Create the object that will do the proxy operations. We don't really care
        ## what VO role and group and server URL we pass to the constructor, because
        ## these are not used until we do the proxy delegation to the myproxy server.
        ## And this happens in handleProxy(), which is called after we load the
        ## configuration file and retrieve the final values for those parameters.
        ## handleProxy() takes care of passing those parameters to self.proxy.
        self.proxy = CredentialInteractions('', '', self.voRole, self.voGroup, self.logger, '')

        ## If the user didn't use the --proxy command line option, and if there isn't a
        ## valid proxy already, we create a new one with the current VO role and group
        ## (as commented above, we don't really care what are the VO role and group so
        ## far).
        self.proxyCreated = False
        if not self.options.proxy and self.cmdconf['initializeProxy']:
            self.proxyCreated = self.proxy.createNewVomsProxySimple(timeLeftThreshold = 720)

        ## If there is an input configuration file:
        if hasattr(self.options, 'config') and self.options.config is not None:
            proxyOptsSetPlace['for_set_use'] = "config"
            ## Load the configuration file and validate it.
            self.loadConfig(self.options.config, self.args)
            ## Create the CRAB project directory.
            self.requestarea, self.requestname, self.logfile = createWorkArea(self.logger, \
                                                                              getattr(self.configuration.General, 'workArea', None), \
                                                                              getattr(self.configuration.General, 'requestName', None))
            ## Get the VO group/role from the configuration file.
            msgadd = []
            if hasattr(self.configuration, 'User') and hasattr(self.configuration.User, 'voGroup'):
                self.voGroup = self.configuration.User.voGroup
                proxyOptsSetPlace['set_in']['group'] = "config"
                msgadd.append("VO group '%s'" % (self.voGroup))
            if hasattr(self.configuration, 'User') and hasattr(self.configuration.User, 'voRole'):
                self.voRole = self.configuration.User.voRole if self.configuration.User.voRole != "" else "NULL"
                proxyOptsSetPlace['set_in']['role'] = "config"
                msgadd.append("VO role '%s'" % (self.voRole))
            if msgadd:
                msg = "Using %s as specified in the CRAB configuration file." % (" and ".join(msgadd))
                self.logger.debug(msg)

        ## If an input project directory was given, load the request cache and take the
        ## server URL from it. If the VO group/role was not given in the command options,
        ## take it also from the request cache.
        if self.cmdconf['requiresDirOption']:
            self.loadLocalCache(proxyOptsSetPlace)

        ## If the server URL isn't already set, we check the args and then the config.
        if not hasattr(self, 'serverurl') and self.cmdconf['requiresREST']:
            self.instance, self.serverurl = self.serverInstance()
        elif not self.cmdconf['requiresREST']:
            self.instance, self.serverurl = None, None

        ## Update (or create) the CRAB cache file.
        self.updateCRABCacheFile()

        ## At this point there should be a valid proxy, because we have already checked that and
        ## eventually created a new one. If the proxy was not created by CRAB, we check that the
        ## VO role/group in the proxy are the same as specified by the user in the configuration
        ## file (or in the command line options). If it is not, we ask the user if he wants to 
        ## overwrite the current proxy. If he doesn't want to overwrite it, we don't continue 
        ## and ask him to provide the VO role/group as in the existing proxy. 
        ## Finally, delegate the proxy to myproxy server.
        self.handleProxy(proxyOptsSetPlace)

        ## Logging user command and options used for debuging purpose.
        self.logger.debug('Command use: %s' % self.name)
        self.logger.debug('Options use: %s' % cmdargs)
        if self.cmdconf['requiresREST']:
            self.checkversion(self.getUrl(self.instance, resource='info'))
            self.uri = self.getUrl(self.instance)
        self.logger.debug("Instance is %s" %(self.instance))
        self.logger.debug("Server base url is %s" %(self.serverurl))
        if self.cmdconf['requiresREST']:
            self.logger.debug("Command url %s" %(self.uri))
コード例 #2
0
    def __init__(self, logger, cmdargs=None, disable_interspersed_args=False):
        """
        Initialize common client parameters
        """
        if not hasattr(self, 'name'):
            self.name = self.__class__.__name__

        ConfigCommand.__init__(self)
        # The command logger.
        self.logger = logger
        self.logfile = self.logger.logfile

        stdout, _, _ = execute_command(command='uname -a')
        localSystem = stdout.strip()
        try:
            localOS, _, _ = execute_command('grep PRETTY_NAME /etc/os-release')
            localOS = localOS.strip().split('=')[1].strip('"')
        except Exception as ex:  # pylint: disable=unused-variable
            try:
                localOS, _, _ = execute_command(command='lsb_release -d')
                localOS = localOS.strip().split(':')[1].strip()
            except Exception as ex:  # pylint: disable=unused-variable
                localOS = "Unknown Operating System"
        self.logger.debug("CRAB Client version: %s", __version__)
        self.logger.debug("Running on: " + localSystem + " - " + localOS)
        self.logger.debug("Executing command: '%s'" % str(self.name))

        # Get the command configuration.
        self.cmdconf = commandsConfiguration.get(self.name)
        if not self.cmdconf:
            raise RuntimeError(
                "Canot find command %s in commandsConfiguration inside ClientMapping. Are you a developer"
                "trying to add a command without it's correspondant configuration?"
                % self.name)

        # Get the CRAB cache file.
        self.cachedinfo = None
        self.crab3dic = self.getConfiDict()

        # The options parser.
        self.parser = CRABCmdOptParser(self.name, self.__doc__,
                                       disable_interspersed_args)

        # Define the command options.
        self.setSuperOptions()

        # Parse the command options/arguments.
        cmdargs = cmdargs or []
        (self.options, self.args) = self.parser.parse_args(cmdargs)

        self.transferringIds = None
        self.dest = None

        self.validateLogpathOption()
        # Validate first the SubCommand options
        SubCommand.validateOptions(self)
        # then the config option for the submit command
        self.validateConfigOption()

        # Get the VO group/role from the command options (if the command requires these
        # options).
        proxyOptsSetPlace = {
            'set_in': {
                'group': "default",
                'role': "default"
            },
            'for_set_use': ""
        }
        msgadd = []
        self.voGroup, self.voRole = "", "NULL"
        if self.cmdconf['requiresProxyVOOptions']:
            proxyOptsSetPlace['for_set_use'] = "cmdopts"
            if self.options.voGroup is not None:
                self.voGroup = self.options.voGroup
                proxyOptsSetPlace['set_in']['group'] = "cmdopts"
                msgadd.append("VO group '%s'" % (self.voGroup))
            if self.options.voRole is not None:
                self.voRole = self.options.voRole if self.options.voRole != "" else "NULL"
                proxyOptsSetPlace['set_in']['role'] = "cmdopts"
                msgadd.append("VO role '%s'" % (self.voRole))
        if msgadd:
            msg = "Using %s as specified in the crab command options." % (
                " and ".join(msgadd))
            self.logger.debug(msg)

        # Create the object that will do the proxy operations. We don't really care
        # what VO role and group and server URL we pass to the constructor, because
        # these are not used until we do the proxy delegation to the myproxy server.
        # And this happens in handleProxy(), which is called after we load the
        # configuration file and retrieve the final values for those parameters.
        # handleProxy() takes care of passing those parameters to self.credentialHandler
        self.credentialHandler = CredentialInteractions(self.logger)

        # If the user didn't use the --proxy command line option, and if there isn't a
        # valid proxy already, we will create a new one with the current VO role and group
        # (as commented above, we don't really care what are the VO role and group so
        # far).
        self.proxyCreated = False

        # If there is an input configuration file:
        if hasattr(self.options, 'config') and self.options.config is not None:
            proxyOptsSetPlace['for_set_use'] = "config"
            # Load the configuration file and validate it.
            self.loadConfig(self.options.config, self.args)
            # Create the CRAB project directory.
            self.requestarea, self.requestname, self.logfile = createWorkArea(
                self.logger,
                getattr(self.configuration.General, 'workArea', None),
                getattr(self.configuration.General, 'requestName', None))
            # Get the VO group/role from the configuration file.
            msgadd = []
            if hasattr(self.configuration, 'User') and hasattr(
                    self.configuration.User, 'voGroup'):
                self.voGroup = self.configuration.User.voGroup
                proxyOptsSetPlace['set_in']['group'] = "config"
                msgadd.append("VO group '%s'" % (self.voGroup))
            if hasattr(self.configuration, 'User') and hasattr(
                    self.configuration.User, 'voRole'):
                self.voRole = self.configuration.User.voRole if self.configuration.User.voRole != "" else "NULL"
                proxyOptsSetPlace['set_in']['role'] = "config"
                msgadd.append("VO role '%s'" % (self.voRole))
            if msgadd:
                msg = "Using %s as specified in the CRAB configuration file." % (
                    " and ".join(msgadd))
                self.logger.debug(msg)

        # If the VO group/role was not given in the command options, take it from the request cache.
        if self.cmdconf['requiresDirOption']:
            self.setCachedProxy(proxyOptsSetPlace)

        # If the server URL isn't already set, we check the args and then the config.
        if not hasattr(self, 'serverurl') and self.cmdconf['requiresREST']:
            self.instance, self.serverurl = self.serverInstance()
        elif not self.cmdconf['requiresREST']:
            self.instance, self.serverurl = None, None

        # Update (or create) the CRAB cache file.
        self.updateCRABCacheFile()

        # At this point we check if there is a valid proxy, and
        # eventually create a new one. If the proxy was not created by CRAB, we check that the
        # VO role/group in the proxy are the same as specified by the user in the configuration
        # file (or in the command line options). If it is not, we ask the user if he wants to
        # overwrite the current proxy. If he doesn't want to overwrite it, we don't continue
        # and ask him to provide the VO role/group as in the existing proxy.
        # Finally, delegate the proxy to myproxy server.
        self.handleVomsProxy(proxyOptsSetPlace)

        # only if this command talks to the REST we create a CRABRest object to communicate with CRABServer
        # and check/upate credentials on myproxy
        # this is usually the first time that a call to the server is made, so where Emulator('rest') is initialized
        # arguments to Emulator('rest') call must match those for HTTPRequest.__init__ in RESTInteractions.py
        #server = CRABClient.Emulator.getEmulator('rest')(url=serverurl, localcert=proxyfilename, localkey=proxyfilename,
        #          version=__version__, retry=2, logger=logger)
        if self.cmdconf['requiresREST']:
            crabRest = CRABClient.Emulator.getEmulator('rest')
            self.crabserver = crabRest(hostname=self.serverurl,
                                       localcert=self.proxyfilename,
                                       localkey=self.proxyfilename,
                                       retry=2,
                                       logger=self.logger,
                                       verbose=False,
                                       version=__version__,
                                       userAgent='CRABClient')
            self.crabserver.setDbInstance(self.instance)
            # prepare also a test crabserver instance which will send tarballs to S3
            self.s3tester = crabRest(hostname='cmsweb-testbed.cern.ch',
                                     localcert=self.proxyfilename,
                                     localkey=self.proxyfilename,
                                     retry=0,
                                     logger=self.logger,
                                     verbose=False,
                                     version=__version__,
                                     userAgent='CRABClient')
            self.s3tester.setDbInstance('preprod')
            self.handleMyProxy()

        # Validate the command options
        self.validateOptions()
        self.validateOptions()

        # Log user command and options used for debuging purpose.
        self.logger.debug('Command use: %s' % self.name)
        self.logger.debug('Options use: %s' % cmdargs)
        if self.cmdconf['requiresREST']:
            self.checkversion()
            self.defaultApi = 'workflow'
        self.logger.debug("Instance is %s" % (self.instance))
        self.logger.debug("Server base url is %s" % (self.serverurl))
        if self.cmdconf['requiresREST']:
            self.logger.debug("Command api %s" % (self.defaultApi))
コード例 #3
0
ファイル: SubCommand.py プロジェクト: smuzaffar/CRABClient
    def __init__(self, logger, cmdargs=None, disable_interspersed_args=False):
        """
        Initialize common client parameters
        """
        if not hasattr(self, 'name'):
            self.name = self.__class__.__name__

        ConfigCommand.__init__(self)
        ## The command logger.
        self.logger = logger
        self.logfile = self.logger.logfile

        localSystem = subprocess.check_output(['uname', '-a']).strip('\n')
        try:
            localOS = subprocess.check_output(
                ['grep', 'PRETTY_NAME', '/etc/os-release'],
                stderr=subprocess.STDOUT).strip('\n')
            localOS = localOS.split('=')[1].strip('"')
        except:
            try:
                localOS = subprocess.check_output(['lsb_release',
                                                   '-d']).strip('\n')
                localOS = localOS.split(':')[1].strip()
            except:
                localOS = "Unknown Operating System"
        self.logger.debug("Running on: " + localSystem + " - " + localOS)

        opensslInfo = subprocess.check_output(["openssl",
                                               "version"]).strip('\n')
        self.logger.debug("OpenSSl version: %s", opensslInfo)
        opensslVersion = opensslInfo.split()[1]
        nDots = opensslVersion.count(".")
        if float(opensslVersion.rsplit(".", nDots - 1)[0]) > 1:
            raise EnvironmentException(
                "Your OpenSSl version (%s) is not supported. Supported versions are < 1.1"
                % opensslVersion)

        self.logger.debug("Executing command: '%s'" % str(self.name))

        self.proxy = None
        self.restClass = CRABClient.Emulator.getEmulator('rest')

        ## Get the command configuration.
        self.cmdconf = commandsConfiguration.get(self.name)
        if not self.cmdconf:
            raise RuntimeError(
                "Canot find command %s in commandsConfiguration inside ClientMapping. Are you a developer"
                "trying to add a command without it's correspondant configuration?"
                % self.name)

        ## Get the CRAB cache file.
        self.cachedinfo = None
        self.crab3dic = self.getConfiDict()

        ## The options parser.
        self.parser = CRABCmdOptParser(self.name, self.__doc__,
                                       disable_interspersed_args)

        ## Define the command options.
        self.setSuperOptions()

        ## Parse the command options/arguments.
        cmdargs = cmdargs or []
        (self.options, self.args) = self.parser.parse_args(cmdargs)

        self.transferringIds = None
        self.dest = None

        self.validateLogpathOption()
        ## Validate first the SubCommand options
        SubCommand.validateOptions(self)
        ## then the config option for the submit command
        self.validateConfigOption()

        ## Get the VO group/role from the command options (if the command requires these
        ## options).
        proxyOptsSetPlace = {
            'set_in': {
                'group': "default",
                'role': "default"
            },
            'for_set_use': ""
        }
        msgadd = []
        self.voGroup, self.voRole = "", "NULL"
        if self.cmdconf['requiresProxyVOOptions']:
            proxyOptsSetPlace['for_set_use'] = "cmdopts"
            if self.options.voGroup is not None:
                self.voGroup = self.options.voGroup
                proxyOptsSetPlace['set_in']['group'] = "cmdopts"
                msgadd.append("VO group '%s'" % (self.voGroup))
            if self.options.voRole is not None:
                self.voRole = self.options.voRole if self.options.voRole != "" else "NULL"
                proxyOptsSetPlace['set_in']['role'] = "cmdopts"
                msgadd.append("VO role '%s'" % (self.voRole))
        if msgadd:
            msg = "Using %s as specified in the crab command options." % (
                " and ".join(msgadd))
            self.logger.debug(msg)

        ## Create the object that will do the proxy operations. We don't really care
        ## what VO role and group and server URL we pass to the constructor, because
        ## these are not used until we do the proxy delegation to the myproxy server.
        ## And this happens in handleProxy(), which is called after we load the
        ## configuration file and retrieve the final values for those parameters.
        ## handleProxy() takes care of passing those parameters to self.proxy.
        self.proxy = CredentialInteractions('', '', self.voRole, self.voGroup,
                                            self.logger, '')

        ## If the user didn't use the --proxy command line option, and if there isn't a
        ## valid proxy already, we create a new one with the current VO role and group
        ## (as commented above, we don't really care what are the VO role and group so
        ## far).
        self.proxyCreated = False
        if not self.options.proxy and self.cmdconf['initializeProxy']:
            self.proxyCreated = self.proxy.createNewVomsProxySimple(
                timeLeftThreshold=720)

        ## If there is an input configuration file:
        if hasattr(self.options, 'config') and self.options.config is not None:
            proxyOptsSetPlace['for_set_use'] = "config"
            ## Load the configuration file and validate it.
            self.loadConfig(self.options.config, self.args)
            ## Create the CRAB project directory.
            self.requestarea, self.requestname, self.logfile = createWorkArea(self.logger, \
                                                                              getattr(self.configuration.General, 'workArea', None), \
                                                                              getattr(self.configuration.General, 'requestName', None))
            ## Get the VO group/role from the configuration file.
            msgadd = []
            if hasattr(self.configuration, 'User') and hasattr(
                    self.configuration.User, 'voGroup'):
                self.voGroup = self.configuration.User.voGroup
                proxyOptsSetPlace['set_in']['group'] = "config"
                msgadd.append("VO group '%s'" % (self.voGroup))
            if hasattr(self.configuration, 'User') and hasattr(
                    self.configuration.User, 'voRole'):
                self.voRole = self.configuration.User.voRole if self.configuration.User.voRole != "" else "NULL"
                proxyOptsSetPlace['set_in']['role'] = "config"
                msgadd.append("VO role '%s'" % (self.voRole))
            if msgadd:
                msg = "Using %s as specified in the CRAB configuration file." % (
                    " and ".join(msgadd))
                self.logger.debug(msg)

        ## If the VO group/role was not given in the command options, take it from the request cache.
        if self.cmdconf['requiresDirOption']:
            self.setCachedProxy(proxyOptsSetPlace)

        ## If the server URL isn't already set, we check the args and then the config.
        if not hasattr(self, 'serverurl') and self.cmdconf['requiresREST']:
            self.instance, self.serverurl = self.serverInstance()
        elif not self.cmdconf['requiresREST']:
            self.instance, self.serverurl = None, None

        ## Update (or create) the CRAB cache file.
        self.updateCRABCacheFile()

        ## At this point there should be a valid proxy, because we have already checked that and
        ## eventually created a new one. If the proxy was not created by CRAB, we check that the
        ## VO role/group in the proxy are the same as specified by the user in the configuration
        ## file (or in the command line options). If it is not, we ask the user if he wants to
        ## overwrite the current proxy. If he doesn't want to overwrite it, we don't continue
        ## and ask him to provide the VO role/group as in the existing proxy.
        ## Finally, delegate the proxy to myproxy server.
        self.handleProxy(proxyOptsSetPlace)

        ## Validate the command options
        self.validateOptions()

        ## Logging user command and options used for debuging purpose.
        self.logger.debug('Command use: %s' % self.name)
        self.logger.debug('Options use: %s' % cmdargs)
        if self.cmdconf['requiresREST']:
            self.checkversion(getUrl(self.instance, resource='info'))
            self.uri = getUrl(self.instance)
        self.logger.debug("Instance is %s" % (self.instance))
        self.logger.debug("Server base url is %s" % (self.serverurl))
        if self.cmdconf['requiresREST']:
            self.logger.debug("Command url %s" % (self.uri))
コード例 #4
0
ファイル: SubCommand.py プロジェクト: cirkovic/CRABClient
    def __init__(self, logger, cmdargs = None, disable_interspersed_args = False):
        """
        Initialize common client parameters
        """
        if not hasattr(self, 'name'):
            self.name = self.__class__.__name__

        ## The command logger.
        self.logger = logger
        self.logfile = self.logger.logfile
        self.logger.debug("Executing command: '%s'" % str(self.name))

        self.proxy = None
        self.restClass = CRABClient.Emulator.getEmulator('rest')

        ## Get the command configuration.
        self.cmdconf = commandsConfiguration.get(self.name)

        ## Get the CRAB cache file.
        self.crab3dic = self.getConfiDict()

        ## The options parser.
        self.parser = CRABCmdOptParser(self.name, self.__doc__,  disable_interspersed_args)

        ## Define the command options.
        self.setSuperOptions()

        ## Parse the command options/arguments.
        cmdargs = cmdargs or []
        (self.options, self.args) = self.parser.parse_args(cmdargs)

        ## Validate the command options.
        self.validateOptions()

        ## Get the VO group/role from the command options (if the command requires these
        ## options).
        proxyOptsSetPlace = {'set_in': {'group': "default", 'role': "default"}, 'for_set_use': ""}
        msgadd = []
        self.voGroup, self.voRole = "", "NULL"
        if self.cmdconf['requiresProxyVOOptions']:
            proxyOptsSetPlace['for_set_use'] = "cmdopts"
            if self.options.voGroup is not None:
                self.voGroup = self.options.voGroup
                proxyOptsSetPlace['set_in']['group'] = "cmdopts"
                msgadd.append("VO group '%s'" % (self.voGroup))
            if self.options.voRole is not None:
                self.voRole = self.options.voRole if self.options.voRole != "" else "NULL"
                proxyOptsSetPlace['set_in']['role'] = "cmdopts"
                msgadd.append("VO role '%s'" % (self.voRole))
        if msgadd:
            msg = "Using %s as specified in the crab command options." % (" and ".join(msgadd))
            self.logger.debug(msg)

        ## Create the object that will do the proxy operations. We don't really care
        ## what VO role and group and server URL we pass to the constructor, because
        ## these are not used until we do the proxy delegation to the myproxy server.
        ## And this happens in handleProxy(), which is called after we load the
        ## configuration file and retrieve the final values for those parameters.
        ## handleProxy() takes care of passing those parameters to self.proxy.
        self.proxy = CredentialInteractions('', '', self.voRole, self.voGroup, self.logger, '')

        ## If the user didn't use the --proxy command line option, and if there isn't a
        ## valid proxy already, we create a new one with the current VO role and group
        ## (as commented above, we don't really care what are the VO role and group so
        ## far).
        self.proxyCreated = False
        if not self.options.proxy and self.cmdconf['initializeProxy']:
            self.proxyCreated = self.proxy.createNewVomsProxySimple(timeLeftThreshold = 720)

        ## If there is an input configuration file:
        if hasattr(self.options, 'config') and self.options.config is not None:
            proxyOptsSetPlace['for_set_use'] = "config"
            ## Load the configuration file and validate it.
            self.loadConfig(self.options.config, self.args)
            ## Create the CRAB project directory.
            self.requestarea, self.requestname, self.logfile = createWorkArea(self.logger, \
                                                                              getattr(self.configuration.General, 'workArea', None), \
                                                                              getattr(self.configuration.General, 'requestName', None))
            ## Get the VO group/role from the configuration file.
            msgadd = []
            if hasattr(self.configuration, 'User') and hasattr(self.configuration.User, 'voGroup'):
                self.voGroup = self.configuration.User.voGroup
                proxyOptsSetPlace['set_in']['group'] = "config"
                msgadd.append("VO group '%s'" % (self.voGroup))
            if hasattr(self.configuration, 'User') and hasattr(self.configuration.User, 'voRole'):
                self.voRole = self.configuration.User.voRole if self.configuration.User.voRole != "" else "NULL"
                proxyOptsSetPlace['set_in']['role'] = "config"
                msgadd.append("VO role '%s'" % (self.voRole))
            if msgadd:
                msg = "Using %s as specified in the CRAB configuration file." % (" and ".join(msgadd))
                self.logger.debug(msg)

        ## If an input project directory was given, load the request cache and take the
        ## server URL from it. If the VO group/role was not given in the command options,
        ## take it also from the request cache.
        if self.cmdconf['requiresDirOption']:
            self.loadLocalCache(proxyOptsSetPlace)

        ## If the server URL isn't already set, we check the args and then the config.
        if not hasattr(self, 'serverurl') and self.cmdconf['requiresREST']:
            self.instance, self.serverurl = self.serverInstance()
        elif not self.cmdconf['requiresREST']:
            self.instance, self.serverurl = None, None

        ## Update (or create) the CRAB cache file.
        self.updateCRABCacheFile()

        ## At this point there should be a valid proxy, because we have already checked that and
        ## eventually created a new one. If the proxy was not created by CRAB, we check that the
        ## VO role/group in the proxy are the same as specified by the user in the configuration
        ## file (or in the command line options). If it is not, we ask the user if he wants to 
        ## overwrite the current proxy. If he doesn't want to overwrite it, we don't continue 
        ## and ask him to provide the VO role/group as in the existing proxy. 
        ## Finally, delegate the proxy to myproxy server.
        self.handleProxy(proxyOptsSetPlace)

        ## Logging user command and options used for debuging purpose.
        self.logger.debug('Command use: %s' % self.name)
        self.logger.debug('Options use: %s' % cmdargs)
        if self.cmdconf['requiresREST']:
            self.checkversion(self.getUrl(self.instance, resource='info'))
            self.uri = self.getUrl(self.instance)
        self.logger.debug("Instance is %s" %(self.instance))
        self.logger.debug("Server base url is %s" %(self.serverurl))
        if self.cmdconf['requiresREST']:
            self.logger.debug("Command url %s" %(self.uri))
コード例 #5
0
 def _prepareWorkArea(self):
     self.reqarea, self.reqname, _ = createWorkArea(
         self.logger, requestName=self.TEST_REQ_NAME)
     server = {}
     createCache(self.reqarea, "127.0.0.1", 8518, self.reqname)
コード例 #6
0
 def _prepareWorkArea(self):
     self.reqarea, self.reqname, _ = createWorkArea(self.logger, requestName = self.TEST_REQ_NAME)
     server = {}
     createCache(self.reqarea, "127.0.0.1", 8518, self.reqname)
コード例 #7
0
ファイル: SubCommand.py プロジェクト: matz-e/CRABClient
    def __init__(self, logger, cmdargs = None, disable_interspersed_args = False):
        """
        Initialize common client parameters
        """
        if not hasattr(self, 'name'):
            self.name = self.__class__.__name__
        self.usage = "usage: %prog " + self.name + " [options] [args]"
        self.logger = logger
        self.logfile = self.logger.logfile
        self.logger.debug("Executing command: '%s'" % str(self.name))

        self.proxy = None
        self.restClass = CRABClient.Emulator.getEmulator('rest')
        self.cmdconf = commandsConfiguration.get(self.name)
        self.crab3dic = self.getConfiDict()

        self.parser = OptionParser(description = self.__doc__, usage = self.usage, add_help_option = True)
        ## TODO: check on self.name should be removed (creating another abstraction in between or refactoring this)
        if disable_interspersed_args:
            self.parser.disable_interspersed_args()
        self.setSuperOptions()
        ## Parse the command line parameters.
        cmdargs = cmdargs or []
        (self.options, self.args) = self.parser.parse_args(cmdargs)

        ## Validate the command line parameters before initializing the proxy.
        self.validateOptions()

        ## Retrieve VO role/group from the command line parameters.
        self.voRole  = self.options.voRole  if self.options.voRole  is not None else ''
        self.voGroup = self.options.voGroup if self.options.voGroup is not None else ''

        ## Create the object that will do the proxy operations. We ignore the VO role/group and
        ## server URL in the initialization, because they are not used until we do the proxy
        ## delegation to myproxy server. And the delegation happends in handleProxy(), which is
        ## called after we load the configuration file and retrieve the final values for those
        ## parameters. handleProxy() takes care of passing those parameters to self.proxy.
        self.proxy = CredentialInteractions('', '', self.voRole, self.voGroup, self.logger, '')

        ## Create a new proxy (if there isn't a valid one already) with current VO role/group.
        ## The VO role/group are not relevant for the proxy. We only want to check that the
        ## user doesn't expect the proxy to have different VO role/group than those specified
        ## in the configuration file, but this check is done later in handleProxy() after we
        ## load the configuration file.
        self.proxy_created = False
        if not self.options.proxy and self.cmdconf['initializeProxy']:
            self.proxy_created = self.proxy.createNewVomsProxySimple(time_left_threshold = 720)

        ## If we get an input configuration file:
        if hasattr(self.options, 'config') and self.options.config is not None:
            ## Load the configuration file and validate it.
            self.loadConfig(self.options.config, self.args)
            ## Create the CRAB project directory.
            self.requestarea, self.requestname, self.logfile = createWorkArea(self.logger,
                                                                              getattr(self.configuration.General, 'workArea', None),
                                                                              getattr(self.configuration.General, 'requestName', None))
            ## If VO role/group were not given in the command options, get them from the configuration file.
            ## If they are specified in both places, print a message saying that the command options will be used.
            if self.options.voRole  is None and hasattr(self.configuration, 'User'):
                self.voRole  = getattr(self.configuration.User, 'voRole',  '')
            if self.options.voGroup is None and hasattr(self.configuration, 'User'):
                self.voGroup = getattr(self.configuration.User, 'voGroup', '')
            if (self.options.voRole  is not None) and (hasattr(self.configuration, 'User') and hasattr(self.configuration.User, 'voRole' )):
                msg = "Ignoring the VO role specified in the configuration file. Using VO role \"%s\" "
                if self.voRole == '': msg += "(i.e. no VO role) "
                msg += "as specified in the command line."
                self.logger.info(msg % self.voRole)
            if (self.options.voGroup is not None) and (hasattr(self.configuration, 'User') and hasattr(self.configuration.User, 'voGroup')):
                msg = "Ignoring the VO group specified in the configuration file. Using VO group \"%s\" "
                if self.voGroup == '': msg += "(i.e. no VO group) "
                msg += "as specified in the command line."
                self.logger.info(msg % self.voGroup)

        ## If we get an input task, we load the cache and set the server URL and VO role/group from it.
        if hasattr(self.options, 'task') and self.options.task:
            self.loadLocalCache()

        ## If the server url isn't already set, we check the args and then the config.
        if not hasattr(self, 'serverurl') and self.cmdconf['requiresREST']:
            self.instance, self.serverurl = self.serverInstance()
        elif not self.cmdconf['requiresREST']:
            self.instance, self.serverurl = None, None

        ## Update (or create) the .crab3 cache file.
        self.updateCrab3()

        ## At this point there should be a valid proxy, because we have already checked that and
        ## eventually created a new one. If the proxy was not created by CRAB, we check that the
        ## VO role/group in the proxy are the same as specified by the user in the configuration
        ## file (or in the command line options). If it is not, we ask the user if he wants to 
        ## overwrite the current proxy. If he doesn't want to overwrite it, we don't continue 
        ## and ask him to provide the VO role/group as in the existing proxy. 
        ## Finally, delegate the proxy to myproxy server.
        self.handleProxy()

        ## Logging user command and options used for debuging purpose.
        self.logger.debug('Command use: %s' % self.name)
        self.logger.debug('Options use: %s' % cmdargs)
        if self.cmdconf['requiresREST']:
            self.checkversion(self.getUrl(self.instance, resource='info'))
            self.uri = self.getUrl(self.instance)
        self.logger.debug("Instance is %s" %(self.instance))
        self.logger.debug("Server base url is %s" %(self.serverurl))
        if self.cmdconf['requiresREST']:
            self.logger.debug("Command url %s" %(self.uri))
コード例 #8
0
ファイル: SubCommand.py プロジェクト: matz-e/CRABClient
    def __init__(self, logger, cmdargs=None, disable_interspersed_args=False):
        """
        Initialize common client parameters
        """
        if not hasattr(self, 'name'):
            self.name = self.__class__.__name__
        self.usage = "usage: %prog " + self.name + " [options] [args]"
        self.logger = logger
        self.logfile = self.logger.logfile
        self.logger.debug("Executing command: '%s'" % str(self.name))

        self.proxy = None
        self.restClass = CRABClient.Emulator.getEmulator('rest')
        self.cmdconf = commandsConfiguration.get(self.name)
        self.crab3dic = self.getConfiDict()

        self.parser = OptionParser(description=self.__doc__,
                                   usage=self.usage,
                                   add_help_option=True)
        ## TODO: check on self.name should be removed (creating another abstraction in between or refactoring this)
        if disable_interspersed_args:
            self.parser.disable_interspersed_args()
        self.setSuperOptions()
        ## Parse the command line parameters.
        cmdargs = cmdargs or []
        (self.options, self.args) = self.parser.parse_args(cmdargs)

        ## Validate the command line parameters before initializing the proxy.
        self.validateOptions()

        ## Retrieve VO role/group from the command line parameters.
        self.voRole = self.options.voRole if self.options.voRole is not None else ''
        self.voGroup = self.options.voGroup if self.options.voGroup is not None else ''

        ## Create the object that will do the proxy operations. We ignore the VO role/group and
        ## server URL in the initialization, because they are not used until we do the proxy
        ## delegation to myproxy server. And the delegation happends in handleProxy(), which is
        ## called after we load the configuration file and retrieve the final values for those
        ## parameters. handleProxy() takes care of passing those parameters to self.proxy.
        self.proxy = CredentialInteractions('', '', self.voRole, self.voGroup,
                                            self.logger, '')

        ## Create a new proxy (if there isn't a valid one already) with current VO role/group.
        ## The VO role/group are not relevant for the proxy. We only want to check that the
        ## user doesn't expect the proxy to have different VO role/group than those specified
        ## in the configuration file, but this check is done later in handleProxy() after we
        ## load the configuration file.
        self.proxy_created = False
        if not self.options.proxy and self.cmdconf['initializeProxy']:
            self.proxy_created = self.proxy.createNewVomsProxySimple(
                time_left_threshold=720)

        ## If we get an input configuration file:
        if hasattr(self.options, 'config') and self.options.config is not None:
            ## Load the configuration file and validate it.
            self.loadConfig(self.options.config, self.args)
            ## Create the CRAB project directory.
            self.requestarea, self.requestname, self.logfile = createWorkArea(
                self.logger,
                getattr(self.configuration.General, 'workArea', None),
                getattr(self.configuration.General, 'requestName', None))
            ## If VO role/group were not given in the command options, get them from the configuration file.
            ## If they are specified in both places, print a message saying that the command options will be used.
            if self.options.voRole is None and hasattr(self.configuration,
                                                       'User'):
                self.voRole = getattr(self.configuration.User, 'voRole', '')
            if self.options.voGroup is None and hasattr(
                    self.configuration, 'User'):
                self.voGroup = getattr(self.configuration.User, 'voGroup', '')
            if (self.options.voRole is not None) and (
                    hasattr(self.configuration, 'User')
                    and hasattr(self.configuration.User, 'voRole')):
                msg = "Ignoring the VO role specified in the configuration file. Using VO role \"%s\" "
                if self.voRole == '': msg += "(i.e. no VO role) "
                msg += "as specified in the command line."
                self.logger.info(msg % self.voRole)
            if (self.options.voGroup is not None) and (
                    hasattr(self.configuration, 'User')
                    and hasattr(self.configuration.User, 'voGroup')):
                msg = "Ignoring the VO group specified in the configuration file. Using VO group \"%s\" "
                if self.voGroup == '': msg += "(i.e. no VO group) "
                msg += "as specified in the command line."
                self.logger.info(msg % self.voGroup)

        ## If we get an input task, we load the cache and set the server URL and VO role/group from it.
        if hasattr(self.options, 'task') and self.options.task:
            self.loadLocalCache()

        ## If the server url isn't already set, we check the args and then the config.
        if not hasattr(self, 'serverurl') and self.cmdconf['requiresREST']:
            self.instance, self.serverurl = self.serverInstance()
        elif not self.cmdconf['requiresREST']:
            self.instance, self.serverurl = None, None

        ## Update (or create) the .crab3 cache file.
        self.updateCrab3()

        ## At this point there should be a valid proxy, because we have already checked that and
        ## eventually created a new one. If the proxy was not created by CRAB, we check that the
        ## VO role/group in the proxy are the same as specified by the user in the configuration
        ## file (or in the command line options). If it is not, we ask the user if he wants to
        ## overwrite the current proxy. If he doesn't want to overwrite it, we don't continue
        ## and ask him to provide the VO role/group as in the existing proxy.
        ## Finally, delegate the proxy to myproxy server.
        self.handleProxy()

        ## Logging user command and options used for debuging purpose.
        self.logger.debug('Command use: %s' % self.name)
        self.logger.debug('Options use: %s' % cmdargs)
        if self.cmdconf['requiresREST']:
            self.checkversion(self.getUrl(self.instance, resource='info'))
            self.uri = self.getUrl(self.instance)
        self.logger.debug("Instance is %s" % (self.instance))
        self.logger.debug("Server base url is %s" % (self.serverurl))
        if self.cmdconf['requiresREST']:
            self.logger.debug("Command url %s" % (self.uri))