#!/usr/bin/env python from string import lower, split from sys import argv, exit from os import getenv import socket import re program = 'mk5command' version = '0.4' author = 'Walter Brisken ' verdate = '20100527' defaultDifxMessagePort = 50200 defaultDifxMessageGroup = '224.2.2.1' def usage(pgm): print '%s ver. %s %s %s\n' % (program, version, author, verdate) print 'A program that talks to the mk5daemon programs running on the' print 'software correlator computers, including the mark5s.\n' print 'usage : %s \n' % pgm print ' can be one of the following (case insensitive):' print ' GetVSN -- tell Mark5 unit to report is modules' print ' ResetMark5 -- runs SSReset followed by ssopen on Mark5' print ' StartMark5A -- starts the Mark5A program' print ' StopMark5A -- stops the Mark5A program' print ' Reboot -- reboots the machine' print ' Poweroff -- powers off the machine' print ' Clear -- used to clear errant "busy" state' print ' stopmk5daemon -- tell the mk5daemon program to quit' print ' killmpifxcorr -- kill -9 mpifxcorr and mpirin' print ' getdirA, getdirB -- get directory of module in A or B' print ' getdir -- get directory of all loaded modules' print ' stopdir -- stop a getdir in progress' print ' condition, conditionR, conditionW -- condition module A' print ' stopcondition -- stop a conditioning process' print ' copy -- copy data from module to file; see below' print ' stopcopy -- stop a copy in progress' print ' getver -- tell machine to report its version info' print ' mountXX -- mount /dev/sdXX /mnt/usb' print ' umount -- umount /mnt/usb\n' print ' is a list of cluster members to receive the message;' print ' the format is as follows:' print ' general: the explicit computer hostname, or "all" for all' print ' mark5 units: 01 through 24, or "mark5" for all' print ' processor node: 000 though 999, or "swc" for all' print ' ranges are allowed: 12-18 or 001-010\n' print 'Data copying requires additional parameters corresponding to the' print 'parameters needed by program mk5cp.\n' print 'Example: mk5control "copy A 12-14 /mnt/usb/bb269a/BR" 03\n' def sendCommand(cmd, units, verbose): src = socket.gethostname() dest = '' for u in units: if lower(u) == 'all': name = 'all' elif len(u) == 2: name = 'mark5fx' + u elif len(u) == 3: name = 'swc' + u else: name = u dest += '%s' % name message = \ '\n' \ '' \ '
' \ '%s' \ '%s' \ '-1' \ 'mk5control' \ 'DifxCommand' \ '
' \ '' \ '0' \ '' \ '%s' \ '' \ '' \ '
' % (src, dest, cmd) if verbose: print message port = getenv('DIFX_MESSAGE_PORT') if port == None: port = defaultDifxMessagePort else: port = int(port) group = getenv('DIFX_MESSAGE_GROUP') if group == None: group = defaultDifxMessageGroup sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) sock.sendto(message, (group, port)) if len(argv) < 3: usage(argv[0]) exit(0) machines = [] p = re.compile( '^[0-9]+-[0-9]+$' ) for a in argv[2:]: if ( p.match( a ) ): s = split( a, '-') if len(s[0]) != len(s[1]): print 'bad syntax: ', a exit(0) m = int(s[0]) n = int(s[1]) if len(s[0]) == 2: for i in range(m, n+1): machines.append('%02d' % i) elif len(s[0]) == 3: for i in range(m, n+1): machines.append('%03d' % i) else: print 'bad syntax: ', a exit(0) else: machines.append(a) sendCommand(argv[1], machines, False)