#!/usr/bin/env python3 ''' Created on July 4, 2014 @author: Hovanes Egiyan ''' import os, sys from iocPortMap import * def iocReboot( host, port ) : """ Function to reboot IOC with IOC name """ """ Telnets to the procServ on localhost and type CtrlX to restart the IOC process """ # Username is hdops, it is supposed to be able to login without password username = "hdops" telnetCommand = 'ssh {0}@{1}'.format( username, host ) procServCommand = '( echo -e \\\\0030; sleep 1 ) | telnet localhost {0}'.format( port ) command = telnetCommand + " '" + procServCommand + "'" # print 'Will execute command <{0}>'.format( command ) os.system( command ); return if __name__ == '__main__': args = sys.argv[1:] # Make sure only one command line argument exists" if( len(args) != 1 ) : raise Exception("Need one and only one string argument to specify the IOC") if args[0] == 'all' or args[0] == "all" : for iocName in hostPortMap: if hostPortMap[iocName]["enable"] == "enabled": print("IOC name is {0}".format( iocName )) host = hostPortMap[iocName]["host"] port = hostPortMap[iocName]["port"] print("Host is {0}, port number is {1}".format(host, port)) iocReboot( host, port ) elif args[0] in list(iocGroupMap.keys()): iocGroup = args[0] print("Rebooting IOC group {0}".format( iocGroup )) for iocName in iocGroupMap[iocGroup] : if ( iocName in list(hostPortMap.keys()) ) and ( hostPortMap[iocName]["enable"] == "enabled" ): host = hostPortMap[iocName]["host"] port = hostPortMap[iocName]["port"] print("Host is {0}, port number is {1}".format(host, port)) iocReboot( host, port ) else : iocName = args[0] print("IOC name is {0}".format( iocName )) if ( iocName in list(hostPortMap.keys()) ) and ( hostPortMap[iocName]["enable"] == "enabled" ): host = hostPortMap[iocName]["host"] port = hostPortMap[iocName]["port"] print("Host is {0}, port number is {1}".format(host, port)) iocReboot( host, port )