1 ##############################################################################
2 # Copyright (c) 2015 Todd Gaunt and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
14 def power_nodes(nodes, action):
15 """ Attempts to power on all nodes specified in a list, then returns a list
16 of the names of all failures. The list will be empty if no failures."""
18 logger = logging.getLogger(__name__)
20 logger.info("No nodes, is empty list")
22 # -I flag must be 'lanplus', 'lan' by itself doesn't work with
23 # the most recent idrac/ipmi version
29 logger.error("Invalid ipmi command")
33 "-H ", "'"+node.ipmi_addr+"'", \
34 "-U ", "'"+node.ipmi_user+"'", \
35 "-P ", "'"+node.ipmi_pass+"'", \
38 logger.debug("Running: \"{}\"".format(' '.join(cmd)))
40 with open(os.devnull, 'w') as fn:
41 status = subprocess.check_call(" ".join(cmd), \
42 stdout=fn, stderr=fn, shell=True)
43 except subprocess.CalledProcessError as e:
45 logger.error("{} could not be accessed at {} (exit code {})".format(\
46 node.name, node.ipmi_addr, status))
47 failed_nodes.append(node.name)
49 logger.info("{} successfully powered {}".format(node.name, action))
53 def status(node, ipaddr, username, passwd):
54 # -I flag must be 'lanplus', 'lan' by itself doesn't work with
55 # the most recent idrac/ipmi version
56 chkcmd = ["ipmitool", \
63 subprocess.Popen(chkcmd)