def listprofiles(*args): logger = get_logger('ListProfiles') session = Session() profiles = session.query(Profile).all() if not profiles: logger.error('No profiles found') else: logger.info('Profiles found: %s' % ', '.join([profile.name for profile in profiles])) sys.exit(0)
def runcommand(options, parser): logger = get_logger('RunCommand') if not options.command or not options.node: return parser.print_help() #ns = Pyro.naming.NameServerLocator().getNS() #uri = ns.resolve('%s.%s.jobservice' % (domain, options.node)) #js = Pyro.core.getProxyForURI(uri) js = Pyro.core.getProxyForURI("PYROLOC://localhost:7766/jobservice") if options.command == 'create': if not options.profile: return logger.error( 'crate should be called with profile name: -n nodename -c create -p profile' ) sess = Session() try: pf = sess.query(Profile).filter( profile.c.name == options.profile).first() status, workername = js.create(pf.configuration) except Exception, e: logger.error('No profile found with name: %s' % options.profile) logger.error("".join(getPyroTraceback(e))) return -1 if status: j = Job(workername, 'paused') pf.jobs.append(j) #sess.save(j) sess.add(j) sess.commit() sess.close() logger.info("worker with name %s created" % workername) return 0 logger.error('no worker created: %s' % workername) return -1
def runcommand(options, parser): logger = get_logger('RunCommand') if not options.command or not options.node: return parser.print_help() #ns = Pyro.naming.NameServerLocator().getNS() #uri = ns.resolve('%s.%s.jobservice' % (domain, options.node)) #js = Pyro.core.getProxyForURI(uri) js = Pyro.core.getProxyForURI("PYROLOC://localhost:7766/jobservice") if options.command == 'create': if not options.profile: return logger.error('crate should be called with profile name: -n nodename -c create -p profile') sess = Session() try: pf = sess.query(Profile).filter(profile.c.name==options.profile).first() status, workername = js.create(pf.configuration) except Exception, e: logger.error( 'No profile found with name: %s' % options.profile) logger.error("".join(getPyroTraceback(e))) return -1 if status: j = Job(workername, 'paused') pf.jobs.append(j) #sess.save(j) sess.add(j) sess.commit() sess.close() logger.info ("worker with name %s created" % workername) return 0 logger.error('no worker created: %s' % workername) return -1
else: if not options.worker: logger.error('%s should be called with a worker name: -n nodename -c %s -w workername' % \ (options.command, options.command)) return -1 try: status, retval = getattr(js, options.command)(options.worker) except Exception, e: logger.error("".join(getPyroTraceback(e))) d = {'kill':'killed', 'pause':'paused', 'resume':'running'} if options.command in d: s = Session() j = s.query(Job).filter(job.c.name==options.worker).one() j.status = d.get(options.command) if options.command == 'kill': j.end_date = datetime.now() s.commit() s.close() else: logger.info(retval) if __name__ == '__main__': parser = OptionParser() parser.add_option('--nlist', action='callback', callback=listnodes, help="List active nodes") parser.add_option('--plist', action='callback', callback=listprofiles, help="List profiles") parser.add_option('-c', '--command', choices=('create', 'pause', 'resume', 'report', 'status', 'list', 'kill', 'listjobs', 'nodeinfo'),
logger.info('%s' % l) else: if not options.worker: logger.error('%s should be called with a worker name: -n nodename -c %s -w workername' % \ (options.command, options.command)) return -1 try: status, retval = getattr(js, options.command)(options.worker) except Exception, e: logger.error("".join(getPyroTraceback(e))) d = {'kill': 'killed', 'pause': 'paused', 'resume': 'running'} if options.command in d: s = Session() j = s.query(Job).filter(job.c.name == options.worker).one() j.status = d.get(options.command) if options.command == 'kill': j.end_date = datetime.now() s.commit() s.close() else: logger.info(retval) if __name__ == '__main__': parser = OptionParser() parser.add_option('--nlist', action='callback', callback=listnodes,