From 4e1320c4235476d7e2a0a90f80997e8371c5f399 Mon Sep 17 00:00:00 2001 From: Tim Rozet Date: Wed, 30 Nov 2016 11:03:02 -0500 Subject: Adds declaring disk device to use on overcloud nodes Now in inventory file a user can declare 'disk_device' which will allow the user to specify which disk on their overcloud server to use for installation. The variable can be a comma delimited list, which will search in order post-introspection for the first device on the node that exists. The default disk used will be sda for deployments. Currently defining a per node disk is not supported by OSCLI, so although defined that way in Apex inventory, only the last definition will be used for all nodes. Other changes include: - Various fixes in inventory parsing - Makes bash writing a common function - Introspection now enabled for baremetal deployments JIRA: APEX-296 Change-Id: I330d91eb17408ccfceb7a99c25edbae5ce6d848d Signed-off-by: Tim Rozet --- lib/python/apex/common/constants.py | 1 + lib/python/apex/common/utils.py | 8 ++++++++ lib/python/apex/deploy_settings.py | 9 +++------ lib/python/apex/inventory.py | 27 +++++++++++++++++++++++---- lib/python/apex/network_settings.py | 8 ++------ 5 files changed, 37 insertions(+), 16 deletions(-) (limited to 'lib/python/apex') diff --git a/lib/python/apex/common/constants.py b/lib/python/apex/common/constants.py index 741bb4f8..3aa28eab 100644 --- a/lib/python/apex/common/constants.py +++ b/lib/python/apex/common/constants.py @@ -27,3 +27,4 @@ COMPUTE_PRE = "OS::TripleO::ComputeExtraConfigPre" CONTROLLER_PRE = "OS::TripleO::ControllerExtraConfigPre" PRE_CONFIG_DIR = "/usr/share/openstack-tripleo-heat-templates/puppet/" \ "extraconfig/pre_deploy/" +DEFAULT_ROOT_DEV = 'sda' diff --git a/lib/python/apex/common/utils.py b/lib/python/apex/common/utils.py index d623638c..8e6896fa 100644 --- a/lib/python/apex/common/utils.py +++ b/lib/python/apex/common/utils.py @@ -21,3 +21,11 @@ def parse_yaml(yaml_file): with open(yaml_file) as f: parsed_dict = yaml.safe_load(f) return parsed_dict + + +def write_str(bash_str, path=None): + if path: + with open(path, 'w') as file: + file.write(bash_str) + else: + print(bash_str) diff --git a/lib/python/apex/deploy_settings.py b/lib/python/apex/deploy_settings.py index e2d37c82..3133d7f8 100644 --- a/lib/python/apex/deploy_settings.py +++ b/lib/python/apex/deploy_settings.py @@ -11,6 +11,8 @@ import yaml import logging +from .common import utils + REQ_DEPLOY_SETTINGS = ['sdn_controller', 'odl_version', 'sdn_l3', @@ -165,12 +167,7 @@ class DeploySettings(dict): if 'performance' in self['deploy_options']: bash_str += self._dump_performance() bash_str += self._dump_deploy_options_array() - - if path: - with open(path, 'w') as file: - file.write(bash_str) - else: - print(bash_str) + utils.write_str(bash_str, path) class DeploySettingsException(Exception): diff --git a/lib/python/apex/inventory.py b/lib/python/apex/inventory.py index 711eb18f..ce16ef41 100644 --- a/lib/python/apex/inventory.py +++ b/lib/python/apex/inventory.py @@ -10,18 +10,22 @@ import yaml import json +from .common import constants +from .common import utils + class Inventory(dict): """ This class parses an APEX inventory yaml file into an object. It generates or detects all missing fields for deployment. - It then collapses one level of identifcation from the object to + It then collapses one level of identification from the object to convert it to a structure that can be dumped into a json file formatted such that Triple-O can read the resulting json as an instackenv.json file. """ def __init__(self, source, ha=True, virtual=False): init_dict = {} + self.root_device = constants.DEFAULT_ROOT_DEV if isinstance(source, str): with open(source, 'r') as inventory_file: yaml_dict = yaml.safe_load(inventory_file) @@ -40,8 +44,13 @@ class Inventory(dict): node['pm_user'] = node['ipmi_user'] node['mac'] = [node['mac_address']] - for i in ('ipmi_ip', 'ipmi_pass', 'ipmi_user', 'mac_address'): - del i + for i in ('ipmi_ip', 'ipmi_pass', 'ipmi_user', 'mac_address', + 'disk_device'): + if i == 'disk_device' and 'disk_device' in node.keys(): + self.root_device = node[i] + else: + continue + del node[i] return node @@ -53,7 +62,7 @@ class Inventory(dict): 'nodes for HA baremetal deployment') elif len(self['nodes']) < 2: raise InventoryException('You must provide at least 2 nodes ' - 'for non-HA baremetal deployment${reset}') + 'for non-HA baremetal deployment') if virtual: self['arch'] = 'x86_64' @@ -67,6 +76,16 @@ class Inventory(dict): def dump_instackenv_json(self): print(json.dumps(dict(self), sort_keys=True, indent=4)) + def dump_bash(self, path=None): + """ + Prints settings for bash consumption. + + If optional path is provided, bash string will be written to the file + instead of stdout. + """ + bash_str = "{}={}\n".format('root_disk_list', str(self.root_device)) + utils.write_str(bash_str, path) + class InventoryException(Exception): def __init__(self, value): diff --git a/lib/python/apex/network_settings.py b/lib/python/apex/network_settings.py index 64065ca7..b04f141a 100644 --- a/lib/python/apex/network_settings.py +++ b/lib/python/apex/network_settings.py @@ -12,7 +12,7 @@ import logging import ipaddress from copy import copy - +from .common import utils from . import ip_utils from .common.constants import ( CONTROLLER, @@ -338,11 +338,7 @@ class NetworkSettings(dict): bash_str += flatten('dns_servers', self['dns_servers'], ' ') bash_str += flatten('domain_name', self['dns-domain'], ' ') bash_str += flatten('ntp_server', self['ntp_servers'][0], ' ') - if path: - with open(path, 'w') as file: - file.write(bash_str) - else: - print(bash_str) + utils.write_str(bash_str, path) def get_ip_addr_family(self,): """ -- cgit 1.2.3-korg