diff options
author | Tim Rozet <trozet@redhat.com> | 2016-08-30 13:06:33 -0400 |
---|---|---|
committer | Tim Rozet <trozet@redhat.com> | 2016-08-30 21:47:55 +0000 |
commit | ae26e2717c408225534033726614a25e16fe18ca (patch) | |
tree | c71cc3f99a03d42a8ec794337c15d10a3a3afbe8 /lib/python/apex/clean.py | |
parent | 2eaa43854eb4abfcae8566c37cfb63f187f6696f (diff) |
Adds ability to power off nodes in clean
Now if an inventory file is provided to clean, those nodes will be
powered off.
JIRA: APEX-250
Change-Id: I2d78285717726c3d1c9d7d88c38e706d4617e337
Signed-off-by: Tim Rozet <trozet@redhat.com>
Diffstat (limited to 'lib/python/apex/clean.py')
-rw-r--r-- | lib/python/apex/clean.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/python/apex/clean.py b/lib/python/apex/clean.py new file mode 100644 index 00000000..184b5ec9 --- /dev/null +++ b/lib/python/apex/clean.py @@ -0,0 +1,39 @@ +############################################################################## +# Copyright (c) 2016 Tim Rozet (trozet@redhat.com) and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Clean will eventually be migrated to this file + +import logging +import pyipmi +import pyipmi.interfaces +import sys + +from .common import utils + + +def clean_nodes(inventory): + inv_dict = utils.parse_yaml(inventory) + if inv_dict is None or 'nodes' not in inv_dict: + logging.error("Inventory file is empty or missing nodes definition") + sys.exit(1) + for node, node_info in inv_dict['nodes'].items(): + logging.info("Cleaning node: {}".format(node)) + try: + interface = pyipmi.interfaces.create_interface( + 'ipmitool', interface_type='lanplus') + connection = pyipmi.create_connection(interface) + connection.session.set_session_type_rmcp(node_info['ipmi_ip']) + connection.target = pyipmi.Target(0x20) + connection.session.set_auth_type_user(node_info['ipmi_user'], + node_info['ipmi_pass']) + connection.session.establish() + connection.chassis_control_power_down() + except Exception as e: + logging.error("Failure while shutting down node {}".format(e)) + sys.exit(1) |