示例#1
0
文件: job.py 项目: cofinoa/DRM4G
def run(arg):
    try:
        daemon = Daemon()
        if not daemon.is_alive():
            raise Exception('DRM4G is stopped. ')
        if arg['submit']:
            dependencies = '-d "%s"' % ' '.join(
                arg['--dep']) if arg['--dep'] else ''
            number_of_tasks = '-n %s' % arg['--ntasks'] if arg[
                '--ntasks'] else ''
            cmd = 'gwsubmit %s -v %s %s' % (dependencies, arg['<template>'],
                                            number_of_tasks)
        elif arg['list']:
            cmd = 'gwps -o Jsetxjh '
            if arg['<job_id>']:
                cmd = cmd + arg['<job_id>'][0]
        elif arg['history']:
            cmd = 'gwhistory %s' % (arg['<job_id>'][0])
        elif arg['log']:
            directory = join(
                DRM4G_DIR, 'var',
                '%d00-%d99' % (int(int(float(arg['<job_id>'][0])) / 100),
                               int(int(float(arg['<job_id>'][0])) / 100)),
                arg['<job_id>'][0], 'job.log')
            if not exists(directory):
                raise Exception('There is not a log available for this job.')
            cmd = 'cat %s' % (directory)
        else:
            cmd = 'gwkill -9 %s' % (' '.join(arg['<job_id>']))
        out, err = exec_cmd(cmd)
        logger.info(out)
        if err:
            logger.info(err)
    except Exception as err:
        logger.error(str(err))
示例#2
0
def run(arg):
    # El logger no funcionaba porque el import logging se hace varias veces y coge la primera. Hacemos un reload para que funcione
    # https://stackoverflow.com/questions/20240464/python-logging-file-is-not-working-when-using-logging-basicconfig
    from imp import reload
    reload(logging)
    logging.basicConfig(format='%(message)s',
                        level=logging.DEBUG if arg['--dbg'] else logging.INFO,
                        stream=sys.stdout)

    try:
        config = Configuration()
        daemon = Daemon()
        if not daemon.is_alive():
            raise Exception('DRM4G is stopped.')
        resource = Resource(config)
        if arg['edit']:
            resource.edit()
        elif arg['check']:
            resource.check_frontends()
        else:
            resource.list()
    except KeyboardInterrupt:
        pass
    except Exception as err:
        logging.error(str(err))
示例#3
0
def run(arg):
    logging.basicConfig(format='%(message)s',
                        level=logging.DEBUG if arg['--dbg'] else logging.INFO,
                        stream=sys.stdout)
    try:
        daemon = Daemon()
        if not daemon.is_alive():
            raise Exception('DRM4G is stopped. ')
        gw_job = GWJob()
        if arg['list']:
            if not arg['--delay']:
                gw_job.list(None if not arg['<job_id>'] else arg['<job_id>'])
            else:
                try:
                    while True:
                        cls()
                        gw_job.list(
                            None if not arg['<job_id>'] else arg['<job_id>'])
                        time.sleep(int(arg['--delay']))
                except KeyboardInterrupt:
                    pass
        elif arg['history']:
            gw_job.history(arg['<job_id>'])
        elif arg['log']:
            gw_job.log(arg['<job_id>'])
        else:
            gw_job.kill(arg['<job_id>'], arg['--hard'])
    except KeyboardInterrupt:
        pass
    except Exception as err:
        logging.error(str(err))
示例#4
0
文件: id.py 项目: cofinoa/DRM4G
def run(arg):
    try:
        daemon = Daemon()
        if not daemon.is_alive():
            raise Exception('DRM4G is stopped.')
        config = Configuration()
        config.load()
        if config.check():
            raise Exception("Review the configuration of '%s'." %
                            (arg['<resource_name>']))
        if arg['<resource_name>'] not in config.resources:
            raise Exception("'%s' is not a configured resource." %
                            (arg['<resource_name>']))
        lrms = config.resources.get(arg['<resource_name>'])['lrms']
        communicator = config.resources.get(
            arg['<resource_name>'])['communicator']
        if lrms != 'cream' and lrms != 'rocci' and communicator == 'local':
            raise Exception("'%s' does not have an identity to configure." %
                            (arg['<resource_name>']))
        if lrms == 'cream' or lrms == 'rocci':
            comm = config.make_communicators()[arg['<resource_name>']]
            if communicator == 'op_ssh':
                #paramiko will always be used to renew the grid certificate
                config.resources.get(
                    arg['<resource_name>'])['communicator'] = 'pk_ssh'
                comm = config.make_communicators()[arg['<resource_name>']]
            proxy = Proxy(config.resources[arg['<resource_name>']], comm)
            config.resources.get(
                arg['<resource_name>'])['communicator'] = communicator
            config.make_communicators()
        if communicator != 'local':
            agent = Agent(config.resources[arg['<resource_name>']])
        if arg['init']:
            if communicator != 'local':
                agent.start()
                agent.add_key(arg['--lifetime'])
                agent.copy_key()
            if lrms == 'cream' or lrms == 'rocci':
                proxy.configure()
                proxy.create(arg['--lifetime'])
        elif arg['delete']:
            if lrms == 'cream' or lrms == 'rocci':
                proxy.destroy()
            if communicator != 'local':
                agent.delete_key()
        else:
            if communicator != 'local':
                agent.list_key()
            if lrms == 'cream' or lrms == 'rocci':
                proxy.check()
    except Exception as err:
        logger.error(str(err))
示例#5
0
def run(arg):

    try:
        # El logger no funcionaba porque el import logging se hace varias veces y coge la primera. Hacemos un reload para que funcione
        # https://stackoverflow.com/questions/20240464/python-logging-file-is-not-working-when-using-logging-basicconfig
        from imp import reload
        reload(logging)
        logging.basicConfig(
            format='%(message)s',
            level=logging.DEBUG if arg['--dbg'] else logging.INFO,
            stream=sys.stdout)

        if not exists(WRF4G_DIR) or arg['--clear-conf']:
            from shutil import copytree, rmtree
            if exists(WRF4G_DIR):
                logging.debug("Removing WRF4G local configuration in '%s'" %
                              WRF4G_DIR)
                rmtree(WRF4G_DIR)
            logging.debug("Creating a WRF4G local configuration in '%s'" %
                          WRF4G_DIR)
            for directory in ['log', 'submission', 'acct']:
                abs_dir = join(WRF4G_DIR, 'var', directory)
                logging.debug("Creating '%s' directory" % abs_dir)
                os.makedirs(abs_dir)

            src = join(WRF4G_DEPLOYMENT_DIR, 'data')
            logging.debug("Coping from '%s' to '%s'" % (src, WRF4G_DIR))
            copy_tree(src, WRF4G_DIR)

            logging.debug('Downloading and extracting data repository')
            r = requests.get(
                'http://personales.gestion.unican.es/fernanqv/repository2.tar.gz'
            )
            open('repository.tar.gz', 'wb').write(r.content)
            tar = tarfile.open('repository.tar.gz')
            tar.extractall(path=WRF4G_DIR)
            tar.close()
            os.remove('repository.tar.gz')

        if arg['--disc-jobs']:
            Daemon().clear()
        else:
            Daemon().start()
        Agent().start()
        # Update database configuration
        with open(DB4G_CONF, 'w') as f:
            f.write(DEFAULT_DB_CONF % {"WRF4G_DIR": WRF4G_DIR})
    except KeyboardInterrupt:
        pass
    except Exception as err:
        logging.error(err)
示例#6
0
def run(arg):
    try:
        daemon = Daemon()
        if not daemon.is_alive():
            raise Exception('DRM4G is stopped.')
        cmd = 'gwhost '
        if arg['<hid>']:
            cmd = cmd + arg['<hid>']
        out, err = exec_cmd(cmd)
        console_logger.info(out)
        if err:
            console_logger.info(err)
    except Exception as err:
        console_logger.error(str(err))
示例#7
0
def run(arg):
    logging.basicConfig(format='%(message)s',
                        level=logging.DEBUG if arg['--dbg'] else logging.INFO,
                        stream=sys.stdout)
    try:
        daemon = Daemon()
        if not daemon.is_alive():
            raise Exception('DRM4G is stopped.')
        config = Configuration()
        config.load()
        if config.check():
            raise Exception("Review the configuration of '%s'." %
                            (arg['<resource>']))
        if arg['<resource>'] not in config.resources:
            raise Exception("'%s' is not a configured resource." %
                            (arg['<resource>']))
        lrms = config.resources.get(arg['<resource>'])['lrms']
        communicator = config.resources.get(arg['<resource>'])['communicator']
        if lrms != 'cream' and communicator != 'ssh':
            raise Exception("'%s' does not have an identity to configure." %
                            (arg['<resource>']))
        if lrms == 'cream':
            proxy = Proxy(config.resources[arg['<resource>']],
                          config.make_communicators()[arg['<resource>']])
        if communicator == 'ssh':
            agent = Agent(config.resources[arg['<resource>']])
        if arg['init']:
            if communicator == 'ssh':
                agent.start()
                agent.add_key(arg['--lifetime'])
                agent.copy_key()
            if lrms == 'cream':
                proxy.configure()
                proxy.create(arg['--lifetime'])
        elif arg['delete']:
            if lrms == 'cream':
                proxy.destroy()
            if communicator == 'ssh':
                agent.delete_key()
        else:
            if communicator == 'ssh':
                agent.list_key()
            if lrms == 'cream':
                proxy.check()
    except KeyboardInterrupt:
        pass
    except Exception as err:
        logging.error(str(err))
示例#8
0
def run(arg):
    #if arg[ '--dbg' ] :
    #    logger.setLevel(logging.DEBUG)
    try:
        daemon = Daemon()
        if not daemon.is_alive():
            raise Exception('DRM4G is stopped.')
        cmd = 'gwhost '
        if arg['<hid>']:
            cmd = cmd + arg['<hid>']
        out, err = exec_cmd(cmd)
        logger.info(out)
        if err:
            logger.info(err)
    except Exception as err:
        logger.error(str(err))
示例#9
0
def run(arg):
    try:
        Daemon().stop()
        agent = Agent()
        if agent.is_alive():
            agent.stop()
    except Exception as err:
        console_logger.error(str(err))
示例#10
0
文件: start.py 项目: markelg/WRF4G
def run(arg):
    try:
        logging.basicConfig(
            format='%(message)s',
            level=logging.DEBUG if arg['--dbg'] else logging.INFO,
            stream=sys.stdout)
        if not exists(WRF4G_DIR) or arg['--clear-conf']:
            from shutil import copytree, rmtree
            if exists(WRF4G_DIR):
                logging.debug("Removing WRF4G local configuration in '%s'" %
                              WRF4G_DIR)
                rmtree(WRF4G_DIR)
            logging.debug("Creating a WRF4G local configuration in '%s'" %
                          WRF4G_DIR)
            for directory in ['log', 'submission', 'acct']:
                abs_dir = join(WRF4G_DIR, 'var', directory)
                logging.debug("Creating '%s' directory" % abs_dir)
                os.makedirs(abs_dir)
            if 'VIRTUAL_ENV' in os.environ.keys():
                deployment_dir = glob.glob(
                    join(WRF4G_DEPLOYMENT_DIR,
                         'lib/python*/site-packages/wrf4g'))[0]
            else:
                deployment_dir = glob.glob(
                    join(WRF4G_DEPLOYMENT_DIR,
                         'local/lib/python*/dist-packages/wrf4g'))[0]
            src = join(deployment_dir, 'etc')
            print src
            dest = join(WRF4G_DIR, 'etc')
            print dest
            logging.debug("Coping from '%s' to '%s'" % (src, dest))
            copytree(src, dest)
        if arg['--disc-jobs']:
            Daemon().clear()
        else:
            Daemon().start()
        Agent().start()
        # Update database configuration
        with open(DB4G_CONF, 'w') as f:
            f.write(DEFAULT_DB_CONF % {"WRF4G_DIR": WRF4G_DIR})
    except KeyboardInterrupt:
        pass
    except Exception as err:
        logging.error(err)
示例#11
0
def run(arg):
    logging.basicConfig(format='%(message)s',
                        level=logging.DEBUG if arg['--dbg'] else logging.INFO,
                        stream=sys.stdout)
    try:
        daemon = Daemon()
        if not daemon.is_alive():
            raise Exception('DRM4G is stopped.')
        cmd = 'gwhost '
        if arg['<hid>']:
            cmd = cmd + arg['<hid>']
        out, err = exec_cmd(cmd)
        logging.info(out)
        if err:
            logging.info(err)
    except KeyboardInterrupt:
        pass
    except Exception as err:
        logging.error(str(err))
示例#12
0
def run( arg ) :
    logging.basicConfig( format = '%(message)s',
                         level  = logging.DEBUG if arg[ '--dbg' ] else logging.INFO,
                         stream = sys.stdout )
    try :
        config = Configuration()
        daemon = Daemon()
        if not daemon.is_alive() :
           raise Exception( 'DRM4G is stopped.' )
        resource = Resource( config )
        if arg[ 'edit' ] :
            resource.edit()
        elif arg[ 'check' ] :
            resource.check_frontends( )
        else :
            resource.list()
    except KeyboardInterrupt :
        pass
    except Exception as err :
        logging.error( str( err ) )
示例#13
0
def run(arg):
    try:
        logging.basicConfig(
            format='%(message)s',
            level=logging.DEBUG if arg['--dbg'] else logging.INFO,
            stream=sys.stdout)
        Daemon().stop()
        Agent().stop()
    except KeyboardInterrupt:
        pass
    except Exception as err:
        logging.error(str(err))
示例#14
0
def run(arg):
    try:
        daemon = Daemon()
        daemon.stop()
        #sleep( 2.0 )
        daemon.start()
    except Exception as err:
        console_logger.error(str(err))
示例#15
0
文件: clear.py 项目: cofinoa/DRM4G
def run( arg ) :
    try:
        daemon = Daemon()
        daemon.stop()
        sleep( 2.0 )
        daemon.clear()
    except Exception as err :
        logger.error( str( err ) )
示例#16
0
文件: resource.py 项目: cofinoa/DRM4G
def run( arg ) :
    try :
        config = Configuration()
        resource = Resource( config )
        if arg[ 'edit' ] :
            resource.edit()
        else :
            daemon = Daemon()
            if not daemon.is_alive() :
                raise Exception( 'DRM4G is stopped.' )

            elif arg[ 'check' ] :
                resource.check_frontends( )
            elif arg[ 'create' ] :
                resource.create_vms()
            elif arg[ 'destroy' ] :
                resource.destroy_vms( )
            elif arg[ '--all' ] :
                resource.list_resources( )
            else :
                resource.list()
    except Exception as err :
        logger.error( str( err ) )
示例#17
0
def run( arg ) :
    try:
        # El logger no funcionaba porque el import logging se hace varias veces y coge la primera. Hacemos un reload para que funcione
        # https://stackoverflow.com/questions/20240464/python-logging-file-is-not-working-when-using-logging-basicconfig
        from imp import reload
        reload(logging)
        logging.basicConfig( format = '%(message)s',
                         level  = logging.DEBUG if arg[ '--dbg' ] else logging.INFO,
                         stream = sys.stdout )
        Daemon().status()
        Agent().status()
    except KeyboardInterrupt :
        pass
    except Exception as err :
        logging.error( str( err ) )
示例#18
0
文件: start.py 项目: cofinoa/DRM4G
def run(arg):
    try:
        Daemon().start()
        #Agent().start()
    except Exception as err:
        logger.error(str(err))
示例#19
0
文件: start.py 项目: fernanqv/DRM4G
def run(arg):
    try:
        Daemon().start()
    except Exception as err:
        console_logger.error(str(err))