3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from hw_detector.hw_exception import HWException
20 def get_ipmi_info(ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level='ADMINISTRATOR'):
21 command = "ipmitool -I lanplus -H %s -U %s -P %s -L %s fru print 0" % (ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level)
22 info = ipmi_info(command)
24 command = "ipmitool -I lanplus -H %s -U %s -P %s -L %s lan print" % (ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level)
25 info.update(ipmi_info(command))
29 def _load_ipmi_drivers():
30 with open(os.devnull, 'w') as devnull:
31 subprocess.call('modprobe ipmi_msghandler', stderr=devnull, shell=True)
32 subprocess.call('modprobe ipmi_devintf', stderr=devnull, shell=True)
33 subprocess.call('modprobe ipmi_si', stderr=devnull, shell=True)
35 def get_local_ipmi_info():
37 info = ipmi_info("ipmitool fru print 0")
38 info.update(ipmi_info("ipmitool lan print"))
41 def ipmi_info(command):
43 p = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
44 out, _ = p.communicate()
47 raise HWException(out)
50 for line in out.split('\n'):
55 key = line[0:spl].strip()
58 info[line[0:spl].strip()] = line[spl+1:].strip()