Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:43

0001 #!/usr/bin/env python3
0002 
0003 from __future__ import print_function
0004 import sys
0005 import subprocess
0006 
0007 
0008 COLOR_PURPLE = '\033[95m'
0009 COLOR_BLUE = '\033[94m'
0010 COLOR_GREEN = '\033[92m'
0011 COLOR_YELLOW = '\033[93m'
0012 COLOR_RED = '\033[91m'
0013 COLOR_DEF = '\033[0m'
0014 
0015 # This variable is used only when the daemon is installed/updated 
0016 # by hand and needs to be explicitly specified by the user.
0017 rpm_path = '' # '/nfshome0/smorovic/gcc481/dqm/hltd-1.5.0-2.x86_64.rpm'
0018 
0019 def rpm_install(machine):
0020     return 'sudo rpm --install {0}'.format(rpm_path)
0021 
0022 def rpm_update(machine):
0023     return 'sudo rpm -Uhv --force {0}'.format(rpm_path)
0024 
0025 
0026 machines = { 'bu' : ['dqm-c2d07-22', 'bu-c2f13-31-01', 'bu-c2f13-29-01'],
0027              'dev' : ['dqm-c2d07-21', 'dqm-c2d07-22', 'dqm-c2d07-23', 'dqm-c2d07-24', 'dqm-c2d07-25', 'dqm-c2d07-26', 'dqm-c2d07-27'],
0028              'dev_current' : ['dqm-c2d07-22', 'dqm-c2d07-23'],
0029              'ed' : ['bu-c2f13-29-01', 'fu-c2f13-41-01', 'fu-c2f13-41-02', 'fu-c2f13-41-03', 'fu-c2f13-41-04'],
0030              'ed_current' : ['bu-c2f13-29-01', 'fu-c2f13-41-03'],
0031              'prod' : ['bu-c2f13-31-01', 'fu-c2f13-39-01', 'fu-c2f13-39-02', 'fu-c2f13-39-03', 'fu-c2f13-39-04'],
0032              'prod_current' : ['bu-c2f13-31-01', 'fu-c2f13-39-04']
0033            }
0034 
0035 
0036 actions = { 'rpm_install' : rpm_install,  
0037             'rpm_update' : rpm_update,
0038             'rpm_install_status' : 'rpm -qa hltd',
0039             'rpm_remove' : 'sudo rpm --erase hltd',
0040             'daemon_status' : 'sudo /sbin/service hltd status',
0041             'daemon_start' : 'sudo /sbin/service hltd start',
0042             'daemon_stop' : 'sudo /sbin/service hltd stop',
0043             'daemon_stop-light' : 'sudo /sbin/service hltd stop-light',
0044             'daemon_restart' : 'sudo /sbin/service hltd restart'}
0045 
0046 
0047 def usage():
0048     print('Usage: ' + sys.argv[0] + ' MACHINES ACTIONS')
0049 
0050     print('\tMACHINES:')
0051     for target in machines.keys():
0052         print('\t\t' + target + ': ' + ', '.join(machines[target]))
0053 
0054     print('\tACTIONS:')
0055     for action in actions.keys():
0056         print('\t\t' + action)
0057 
0058 
0059 def info(info=None):
0060     if None != info:
0061         print(COLOR_BLUE + '***************************** ' + info + ' *****************************' + COLOR_DEF)
0062     else:
0063         print(COLOR_BLUE + '*********************************************************************************' + COLOR_DEF)
0064 
0065 
0066 def exec_func(machine, action):
0067     info('Machine: ' + machine)
0068     call_list = []
0069     call_list.append('ssh')
0070     call_list.append(machine)
0071 
0072     if hasattr(action, '__call__'):
0073         call_list.append(action(machine))
0074     else:
0075         call_list.append(action)
0076 
0077     # print(call_list) # DEBUG_CODE
0078     subprocess.call(call_list, stderr=subprocess.STDOUT)
0079 
0080     info()
0081 
0082 
0083 if __name__ == '__main__':
0084     if len(sys.argv) < 3:
0085         usage()
0086         exit(1)
0087 
0088     targets = machines.get(sys.argv[1])
0089     if targets == None:
0090         print('Wrong target machines')
0091         exit(2)
0092 
0093     action = actions.get(sys.argv[2])
0094     if action == None:
0095         print('Wrong action')
0096         exit(3)
0097 
0098     for target in targets:
0099         exec_func(target, action)
0100