1 ##############################################################################
2 # Copyright (c) 2016 Tim Rozet (trozet@redhat.com) 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 ##############################################################################
10 # Clean will eventually be migrated to this file
14 import pyipmi.interfaces
17 from .common import utils
20 def clean_nodes(inventory):
21 inv_dict = utils.parse_yaml(inventory)
22 if inv_dict is None or 'nodes' not in inv_dict:
23 logging.error("Inventory file is empty or missing nodes definition")
25 for node, node_info in inv_dict['nodes'].items():
26 logging.info("Cleaning node: {}".format(node))
28 interface = pyipmi.interfaces.create_interface(
29 'ipmitool', interface_type='lanplus')
30 connection = pyipmi.create_connection(interface)
31 connection.session.set_session_type_rmcp(node_info['ipmi_ip'])
32 connection.target = pyipmi.Target(0x20)
33 connection.session.set_auth_type_user(node_info['ipmi_user'],
34 node_info['ipmi_pass'])
35 connection.session.establish()
36 connection.chassis_control_power_down()
37 except Exception as e:
38 logging.error("Failure while shutting down node {}".format(e))