diff options
author | Tim Rozet <trozet@redhat.com> | 2016-08-30 13:06:33 -0400 |
---|---|---|
committer | Tim Rozet <trozet@redhat.com> | 2016-08-30 15:34:04 -0400 |
commit | 4b84887ed2322db6b04924bdee7b44d3dcf7c32d (patch) | |
tree | 7500abe13324ba298ce0b6eff08bd04f87510bd3 /lib | |
parent | d7ceff5d5eefef27f7c2dd23c9161cc8ddd7140b (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')
-rw-r--r-- | lib/python/apex/__init__.py | 1 | ||||
-rw-r--r-- | lib/python/apex/clean.py | 39 | ||||
-rw-r--r-- | lib/python/apex/common/utils.py | 8 | ||||
-rwxr-xr-x | lib/python/apex_python_utils.py | 11 |
4 files changed, 59 insertions, 0 deletions
diff --git a/lib/python/apex/__init__.py b/lib/python/apex/__init__.py index e1b8b547..9993dc97 100644 --- a/lib/python/apex/__init__.py +++ b/lib/python/apex/__init__.py @@ -11,3 +11,4 @@ from .network_settings import NetworkSettings from .deploy_settings import DeploySettings from .network_environment import NetworkEnvironment +from .clean import clean_nodes 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) diff --git a/lib/python/apex/common/utils.py b/lib/python/apex/common/utils.py index b7678a20..fe34096d 100644 --- a/lib/python/apex/common/utils.py +++ b/lib/python/apex/common/utils.py @@ -7,9 +7,17 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import yaml + def str2bool(var): if isinstance(var, bool): return var else: return var.lower() in ("true", "yes") + + +def parse_yaml(yaml_file): + with open(yaml_file) as f: + parsed_dict = yaml.load(f) + return parsed_dict diff --git a/lib/python/apex_python_utils.py b/lib/python/apex_python_utils.py index b6aaafaa..1f5e407c 100755 --- a/lib/python/apex_python_utils.py +++ b/lib/python/apex_python_utils.py @@ -7,6 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +import apex import argparse import sys import logging @@ -61,6 +62,10 @@ def parse_deploy_settings(args): settings.dump_bash() +def run_clean(args): + apex.clean_nodes(args.file) + + def find_ip(args): """ Get and print the IP from a specific interface @@ -192,6 +197,12 @@ def get_parser(): help='path to deploy settings file') deploy_settings.set_defaults(func=parse_deploy_settings) + clean = subparsers.add_parser('clean', + help='Parse deploy settings file') + clean.add_argument('-f', '--file', + help='path to inventory file') + clean.set_defaults(func=run_clean) + return parser |