Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:09

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