/etc/maas/templates/commissioning-user-data/snippets/maas_ipmi_autodetect_tool.py is in maas-region-controller-min 1.5.4+bzr2294-0ubuntu1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #!/usr/bin/python
from __future__ import (
absolute_import,
print_function,
#unicode_literals,
)
str = None
__metaclass__ = type
import commands
import glob
import re
import subprocess
def detect_ipmi():
# XXX: andreserl 2013-04-09 bug=1064527: Try to detect if node
# is a Virtual Machine. If it is, do not try to detect IPMI.
with open('/proc/cpuinfo', 'r') as cpuinfo:
for line in cpuinfo:
if line.startswith('model name') and 'QEMU' in line:
return (False, None)
(status, output) = commands.getstatusoutput('ipmi-locate')
show_re = re.compile('(IPMI\ Version:) (\d\.\d)')
res = show_re.search(output)
if res is None:
found = glob.glob("/dev/ipmi[0-9]")
if len(found):
return (True, "UNKNOWN: %s" % " ".join(found))
return (False, "")
return (True, res.group(2))
def is_host_moonshot():
output = subprocess.check_output(['ipmitool', 'raw', '06', '01'])
# 14 is the code that identifies a machine as a moonshot
if output.split()[0] == "14":
return True
return False
def main():
# Check whether IPMI exists or not.
(status, ipmi_version) = detect_ipmi()
if not status:
# if False, then failed to detect ipmi
exit(1)
if is_host_moonshot():
print("moonshot")
else:
print("ipmi")
if __name__ == '__main__':
main()
|