report any expired sites & nodes
[monitor.git] / extra / pcutest.py
1 #!/usr/bin/python
2
3 from monitor.wrapper import plc
4 import sys
5 import time
6
7 from monitor import config
8
9 api06 = plc.PLC(plc.Auth(config.API06_AUTH_USER, config.API06_AUTH_PASSWORD).auth, config.API06_SERVER)
10 api06 = plc.api
11
12 if True:
13         # update old model names to new model names.
14         update = {      'AP79xx' : 'APCControl13p13',
15                                 'Masterswitch' : 'APCControl13p13',
16                                 'DS4-RPC' : 'BayTech',
17                                 'IP-41x_IP-81x' : 'IPAL',
18                                 'DRAC3' : 'DRAC',
19                                 'DRAC4' : 'DRAC',
20                                 'ePowerSwitch' : 'ePowerSwitchOld',
21                                 'ilo2' : 'HPiLO',
22                                 'ilo1' : 'HPiLO',
23                                 'PM211-MIP' : 'PM211MIP',
24                                 'AMT2.5' : 'IntelAMT',
25                                 'AMT3.0' : 'IntelAMT',
26                                 'WTI_IPS-4' : 'WTIIPS4',
27                                 'unknown'  : 'ManualPCU',
28                                 'DRAC5' : 'DRAC',
29                                 'ipmi'  : 'OpenIPMI',
30                                 'bbsemaverick' : 'BlackBoxPSMaverick',
31                                 'manualadmin'  : 'ManualPCU',
32                         }
33         pcus = api06.GetPCUs()
34         for pcu in pcus:
35                 if pcu['model'] in update.keys():
36                         new_model = update[pcu['model']]
37                         values = pcu
38
39                         if values['pcu_id'] in [1102,1163,1055,1111,1231,1113,1127,1128,1148]:
40                                 new_model = 'APCControl12p3'
41                         elif values['pcu_id'] in [1110,86]:
42                                 new_model = 'APCControl1p4'
43                         elif values['pcu_id'] in [1221,1225,1220,1192]:
44                                 new_model = 'APCControl121p3'
45                         elif values['pcu_id'] in [1173,1240,47,1363,1405,1401,1372,1371]:
46                                 new_model = 'APCControl121p1'
47                         elif values['pcu_id'] in [1056,1237,1052,1209,1002,1008,1041,1013,1022]:
48                                 new_model = 'BayTechCtrlC'
49                         elif values['pcu_id'] in [93]:
50                                 new_model = 'BayTechRPC3NC'
51                         elif values['pcu_id'] in [1057]:
52                                 new_model = 'BayTechCtrlCUnibe'
53                         elif values['pcu_id'] in [1012]:
54                                 new_model = 'BayTechRPC16'
55                         elif values['pcu_id'] in [1089, 1071, 1046, 1035, 1118]:
56                                 new_model = 'ePowerSwitchNew'
57
58                         print "Updating %s \tfrom model name %s to %s" % (pcu['pcu_id'], pcu['model'], new_model)
59                         api06.UpdatePCU(pcu['pcu_id'], {'model' : new_model})
60
61 if False:
62         pcus = api06.GetPCUs()
63         for pcu in pcus:
64                 api06.AddNodeToPCU(1, pcu['pcu_id'], 1)
65
66 if False:
67         pcu_types = [
68                          {'model': 'APCControl12p3',
69                           'name': 'APC AP79xx or Masterswitch (sequence 1-2-port-3)', },
70                          {'model': 'APCControl1p4',
71                           'name': 'APC AP79xx or Masterswitch (sequence 1-port-4)', },
72                          {'model': 'APCControl121p3',
73                           'name': 'APC AP79xx or Masterswitch (sequence 1-2-1-port-3)', },
74                          {'model': 'APCControl121p1',
75                           'name': 'APC AP79xx or Masterswitch (sequence 1-2-1-port-1)', },
76                          {'model': 'APCControl13p13',
77                           'name': 'APC AP79xx or Masterswitch (sequence 1-3-port-1-3)', },
78
79                          {'model': 'BayTechRPC3NC', 
80                           'name': 'BayTech with prompt RPC3-NC>', },
81                          {'model': 'BayTechRPC16', 
82                           'name': 'BayTech with prompt RPC-16>', },
83                          {'model': 'BayTech', # 'DS4-RPC',
84                           'name': 'BayTech with prompt DS-RPC>', },
85                          {'model': 'BayTechCtrlC', 
86                           'name': 'BayTech Ctrl-C, 5, then with prompt DS-RPC>', },
87                          {'model': 'BayTechCtrlCUnibe', 
88                           'name': 'BayTech Ctrl-C, 3, then with prompt DS-RPC>', },
89
90                          {'model': 'BlackBoxPSMaverick',
91                           'name': 'BlackBoxPSMaverick Web based controller'},
92
93                          {'model': 'IPAL',  # 'IP-41x_IP-81x',
94                           'name': 'IPAL - Dataprobe IP-41x & IP-81x', },
95                          {'model': 'DRAC',
96                           'name': 'DRAC - Dell RAC Version 3 or 4', },
97                          {'model': 'ePowerSwitchNew',
98                           'name': 'ePowerSwitch Newer Models 1/4/8x', },
99                          {'model': 'ePowerSwitchOld',
100                           'name': 'ePowerSwitch Older Models 1/4/8x', },
101
102                          {'model': 'HPiLO',  # ilo2
103                           'name': 'HP iLO v1 or v2 (Integrated Lights-Out)', },
104
105                          {'model': 'IntelAMT', # 'AMT3.0',
106                           'name': 'Intel AMT v2.5 or v3.0 (Active Management Technology)', },
107
108                          {'model': 'IPMI',
109                           'name': 'IPMI - Intelligent Platform Management Interface', },
110
111                          {'model': 'PM211MIP',
112                           'name': 'Infratec PM221-MIP', },
113
114                          {'model': 'WTIIPS4', #WTI-IPS-4
115                           'name': 'Western Telematic (WTI IPS-4)', },
116
117                          {'model': 'ManualPCU',
118                           'name': 'Manual Administrator Operation (choose if model unknown)', },
119                           ]
120
121         # Get all model names
122         pcu_models = [type['model'] for type in api06.GetPCUTypes()]
123         for type in pcu_types:
124                 if 'pcu_protocol_types' in type:
125                         protocol_types = type['pcu_protocol_types']
126                         # Take this value out of the struct.
127                         del type['pcu_protocol_types']
128                 else:
129                         protocol_types = []
130                 if type['model'] not in pcu_models:
131                         # Add the name/model info into DB
132                         id = api06.AddPCUType(type)
133                         # for each protocol, also add this.
134                         for ptype in protocol_types:
135                                 api06.AddPCUProtocolType(id, ptype)
136
137 #for type in api06.GetPCUTypes():
138 #       print "removing %s" % type['model']
139 #       api06.DeletePCUType(type['pcu_type_id'])
140