def doit(args): if len(args) < 2: print('usage: python runcommand.py nameofcommand [nameofminer] [commandparameter]') APP.shutdown(1) cmd = args[1] if len(args) == 2: #single command, no miner specified if cmd == 'alert': APP.trybroadcast(cmd, '{0}: runcommand called on {1}'.format(APP.now(), cmd)) else: APP.trypublish(cmd, '{0}: runcommand called on {1}'.format(APP.now(), cmd)) print('sent command {0}'.format(cmd)) else: minertofind = args[2] miner = findminerbyname(minertofind) cmdparam = '' if len(args) > 3: cmdparam = args[3] qnames = QueueName() if not qnames.isvalidqname(cmd): print('Queue {0} is not valid'.format(cmd)) sys.exit(1) if cmd: qmess = MinerCommand(cmd, cmdparam) msg = APP.createmessagecommand(miner, qmess) APP.bus.publish(queue_name=cmd, msg=msg) print('sent command {0} for miner {1}'.format(cmd, miner.name))
def doit(args): if len(args) < 2: print('usage: python runcommand.py nameofcommand [nameofminer] [commandparameter]') APP.shutdown(1) cmd = args[1] if len(args) == 2: #single command, no miner specified queue_command = Queue(cmd, APP.getservice('rabbit')) queue_command.publish('{0} runcommand called on {1}'.format(APP.now(), cmd)) queue_command.close() print('sent command {0}'.format(cmd)) else: minertofind = args[2] cmdparam = '' if len(args) > 3: cmdparam = args[3] miners = MinerRepository() miner = miners.getminerbyname(minertofind, APP.getconfigfilename('config/miners.conf')) if miner is None: miner = APP.getknownminerbyname(minertofind) if miner is None: miner = APP.getminer(Miner(name=minertofind)) if miner is None: print('Miner {0} does not exist'.format(minertofind)) sys.exit(1) qnames = QueueName() if not qnames.isvalidqname(cmd): print('Queue {0} is not valid'.format(cmd)) sys.exit(1) queue_command = Queue(cmd, APP.getservice('rabbit')) #TODO: cleanup logic here. when to call app and when to override with just miner and command if cmd: qmess = MinerCommand(cmd, cmdparam) msg = APP.createmessagecommand(miner, qmess) queue_command.publish(msg) else: queue_command.publish(APP.messageencode(miner)) queue_command.close() print('sent command {0} for miner {1}'.format(cmd, miner.name))
def dispatchmessages(mainapp, entries): '''process the messages''' if entries is None: return dispatch_table = { QueueName.value(QueueName.Q_DISCOVERED): run_discovered, QueueName.value(QueueName.Q_ALERT): run_alert, QueueName.value(QueueName.Q_PROVISION): run_provision, QueueName.value(QueueName.Q_MONITORMINER): run_monitorminer, QueueName.value(QueueName.Q_STATISTICSUPDATED): run_statsupdated, QueueName.value(QueueName.Q_OFFLINE): run_offline, QueueName.value(QueueName.Q_ONLINE): run_online, QueueName.value(QueueName.Q_RESTART): run_restart, } for entry in entries.entries: run_method = dispatch_table[QueueName.value(entry.queuename)] if run_method: run_method(mainapp, entry) else: print('{0} is not handled'.format(entry.queuename))
def get_queue_name(cls, queue_name): name_of_q = queue_name if isinstance(queue_name, QueueName): name_of_q = QueueName.value(queue_name) return name_of_q
def test_queue_invalid_name(self): self.assertFalse(QueueName.has_value('notaqueuename'))
def test_queue_valid_name(self): self.assertTrue(QueueName.has_value(QueueName.Q_ALERT.value))
def test_queue_value(self): self.assertTrue(QueueName.value(QueueName.Q_ALERT) == 'alert')