summaryrefslogtreecommitdiffstats
path: root/apex/clean.py
diff options
context:
space:
mode:
authorTim Rozet <trozet@redhat.com>2017-06-25 21:25:36 -0400
committerTim Rozet <trozet@redhat.com>2017-08-23 08:59:54 -0400
commitf4d388ea508ba00771e43a219ac64e0d430b73bd (patch)
tree4f61a89664474154c3d6f7adecfbb0396617199c /apex/clean.py
parent807fad268c90649f2901c5f5c4cdeb788a0308e0 (diff)
Migrates Apex to Python
Removes all bash libraries and converts almost all of the code to a mixture of Python and Ansible. utils.sh and clean.sh still exist. clean.sh will be migrated fully to clean.py in another patch. The Apex Python package is now built into the opnfv-apex-common RPM. To install locally do 'pip3 install .'. To deploy: opnfv-deploy -d <file> -n <file> --image-dir /root/apex/.build -v --debug Non-python files (THT yaml, settings files, ansible playbooks) are all installed into /usr/share/opnfv-apex/. The RPM will copy settings files into /etc/opnfv-apex/. JIRA: APEX-317 Change-Id: I3232f0329bcd13bce5a28da6a8c9c84d0b048024 Signed-off-by: Tim Rozet <trozet@redhat.com>
Diffstat (limited to 'apex/clean.py')
-rw-r--r--apex/clean.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/apex/clean.py b/apex/clean.py
new file mode 100644
index 00000000..af9e8ce0
--- /dev/null
+++ b/apex/clean.py
@@ -0,0 +1,65 @@
+##############################################################################
+# 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 argparse
+import logging
+import os
+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)
+
+
+def main():
+ clean_parser = argparse.ArgumentParser()
+ clean_parser.add_argument('-f',
+ dest='inv_file',
+ required=True,
+ help='File which contains inventory')
+ args = clean_parser.parse_args(sys.argv[1:])
+ os.makedirs(os.path.dirname('./apex_clean.log'), exist_ok=True)
+ formatter = '%(asctime)s %(levelname)s: %(message)s'
+ logging.basicConfig(filename='./apex_clean.log',
+ format=formatter,
+ datefmt='%m/%d/%Y %I:%M:%S %p',
+ level=logging.DEBUG)
+ console = logging.StreamHandler()
+ console.setLevel(logging.DEBUG)
+ console.setFormatter(logging.Formatter(formatter))
+ logging.getLogger('').addHandler(console)
+ clean_nodes(args.inv_file)
+
+
+if __name__ == '__main__':
+ main()