예제 #1
0
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))
예제 #2
0
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))
예제 #3
0
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))
예제 #4
0
 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
예제 #5
0
 def test_queue_invalid_name(self):
     self.assertFalse(QueueName.has_value('notaqueuename'))
예제 #6
0
 def test_queue_valid_name(self):
     self.assertTrue(QueueName.has_value(QueueName.Q_ALERT.value))
예제 #7
0
 def test_queue_value(self):
     self.assertTrue(QueueName.value(QueueName.Q_ALERT) == 'alert')