CMS 3D CMS Logo

dqmd_manager.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from __future__ import print_function
4 import sys
5 import subprocess
6 
7 
8 COLOR_PURPLE = '\033[95m'
9 COLOR_BLUE = '\033[94m'
10 COLOR_GREEN = '\033[92m'
11 COLOR_YELLOW = '\033[93m'
12 COLOR_RED = '\033[91m'
13 COLOR_DEF = '\033[0m'
14 
15 # This variable is used only when the daemon is installed/updated
16 # by hand and needs to be explicitly specified by the user.
17 rpm_path = '' # '/nfshome0/smorovic/gcc481/dqm/hltd-1.5.0-2.x86_64.rpm'
18 
19 def rpm_install(machine):
20  return 'sudo rpm --install {0}'.format(rpm_path)
21 
22 def rpm_update(machine):
23  return 'sudo rpm -Uhv --force {0}'.format(rpm_path)
24 
25 
26 machines = { 'bu' : ['dqm-c2d07-22', 'bu-c2f13-31-01', 'bu-c2f13-29-01'],
27  'dev' : ['dqm-c2d07-21', 'dqm-c2d07-22', 'dqm-c2d07-23', 'dqm-c2d07-24', 'dqm-c2d07-25', 'dqm-c2d07-26', 'dqm-c2d07-27'],
28  'dev_current' : ['dqm-c2d07-22', 'dqm-c2d07-23'],
29  'ed' : ['bu-c2f13-29-01', 'fu-c2f13-41-01', 'fu-c2f13-41-02', 'fu-c2f13-41-03', 'fu-c2f13-41-04'],
30  'ed_current' : ['bu-c2f13-29-01', 'fu-c2f13-41-03'],
31  'prod' : ['bu-c2f13-31-01', 'fu-c2f13-39-01', 'fu-c2f13-39-02', 'fu-c2f13-39-03', 'fu-c2f13-39-04'],
32  'prod_current' : ['bu-c2f13-31-01', 'fu-c2f13-39-04']
33  }
34 
35 
36 actions = { 'rpm_install' : rpm_install,
37  'rpm_update' : rpm_update,
38  'rpm_install_status' : 'rpm -qa hltd',
39  'rpm_remove' : 'sudo rpm --erase hltd',
40  'daemon_status' : 'sudo /sbin/service hltd status',
41  'daemon_start' : 'sudo /sbin/service hltd start',
42  'daemon_stop' : 'sudo /sbin/service hltd stop',
43  'daemon_stop-light' : 'sudo /sbin/service hltd stop-light',
44  'daemon_restart' : 'sudo /sbin/service hltd restart'}
45 
46 
47 def usage():
48  print('Usage: ' + sys.argv[0] + ' MACHINES ACTIONS')
49 
50  print('\tMACHINES:')
51  for target in machines.keys():
52  print('\t\t' + target + ': ' + ', '.join(machines[target]))
53 
54  print('\tACTIONS:')
55  for action in actions.keys():
56  print('\t\t' + action)
57 
58 
59 def info(info=None):
60  if None != info:
61  print(COLOR_BLUE + '***************************** ' + info + ' *****************************' + COLOR_DEF)
62  else:
63  print(COLOR_BLUE + '*********************************************************************************' + COLOR_DEF)
64 
65 
66 def exec_func(machine, action):
67  info('Machine: ' + machine)
68  call_list = []
69  call_list.append('ssh')
70  call_list.append(machine)
71 
72  if hasattr(action, '__call__'):
73  call_list.append(action(machine))
74  else:
75  call_list.append(action)
76 
77  # print(call_list) # DEBUG_CODE
78  subprocess.call(call_list, stderr=subprocess.STDOUT)
79 
80  info()
81 
82 
83 if __name__ == '__main__':
84  if len(sys.argv) < 3:
85  usage()
86  exit(1)
87 
88  targets = machines.get(sys.argv[1])
89  if targets == None:
90  print('Wrong target machines')
91  exit(2)
92 
93  action = actions.get(sys.argv[2])
94  if action == None:
95  print('Wrong action')
96  exit(3)
97 
98  for target in targets:
99  exec_func(target, action)
100 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def info(info=None)
Definition: dqmd_manager.py:59
def exec_func(machine, action)
Definition: dqmd_manager.py:66
def rpm_update(machine)
Definition: dqmd_manager.py:22
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def rpm_install(machine)
Definition: dqmd_manager.py:19