From 9f1535290167b3a15235a1074eaa4b1eb8a9b801 Mon Sep 17 00:00:00 2001 From: Sam Betts Date: Tue, 3 Jul 2018 16:01:31 +0100 Subject: [PATCH] Add ability to deploy only specific nodes from the ansible inventory This patch adds the BIFROST_NODE_NAMES environment variable which allows a user to specify a list of node names like export BIFROST_NODE_NAMES=node1,node2,node3 which will filter the bifrost inventory before it is passed to ansible to only include the nodes you want to deploy. Change-Id: I02b42ca42ee3f2f77494930aec3b077ec2064c4e --- bifrost/inventory.py | 24 +++++++++++++++++++ .../bifrost_node_names-f26ca2eab7e261d6.yaml | 7 ++++++ 2 files changed, 31 insertions(+) create mode 100644 releasenotes/notes/bifrost_node_names-f26ca2eab7e261d6.yaml diff --git a/bifrost/inventory.py b/bifrost/inventory.py index 04a56c4b0..baf2d862f 100755 --- a/bifrost/inventory.py +++ b/bifrost/inventory.py @@ -195,7 +195,14 @@ def _process_baremetal_data(data_source, groups, hostvars): LOG.debug("Failed to parse JSON or YAML: %s", e) raise Exception("Failed to parse JSON or YAML") + node_names = os.environ.get('BIFROST_NODE_NAMES', None) + if node_names: + node_names = node_names.split(',') + for name in file_data: + if node_names and name not in node_names: + continue + host = file_data[name] # Perform basic validation node_net_data = host.get('node_network_data') @@ -224,6 +231,10 @@ def _process_baremetal_data(data_source, groups, hostvars): def _process_baremetal_csv(data_source, groups, hostvars): """Process legacy baremetal.csv format""" + node_names = os.environ.get('BIFROST_NODE_NAMES', None) + if node_names: + node_names = node_names.split(',') + with open(data_source, 'r') as file_data: for row in csv.reader(file_data, delimiter=','): if not row: @@ -253,6 +264,10 @@ def _process_baremetal_csv(data_source, groups, hostvars): properties['cpu_arch'] = "x86_64" host['uuid'] = _val_or_none(row, 9) host['name'] = _val_or_none(row, 10) + + if node_names and host['name'] not in node_names: + continue + host['host_groups'] = ["baremetal"] host['ipv4_address'] = _val_or_none(row, 11) if ('ipv4_address' not in host or @@ -331,6 +346,11 @@ def _process_shade(groups, hostvars): options = _identify_shade_auth() cloud = shade.operator_cloud(**options) machines = cloud.list_machines() + + node_names = os.environ.get('BIFROST_NODE_NAMES', None) + if node_names: + node_names = node_names.split(',') + for machine in machines: if 'properties' not in machine: machine = cloud.get_machine(machine['uuid']) @@ -338,6 +358,10 @@ def _process_shade(groups, hostvars): name = machine['uuid'] else: name = machine['name'] + + if node_names and name not in node_names: + continue + new_machine = {} for key, value in machine.items(): # NOTE(TheJulia): We don't want to pass infomrational links diff --git a/releasenotes/notes/bifrost_node_names-f26ca2eab7e261d6.yaml b/releasenotes/notes/bifrost_node_names-f26ca2eab7e261d6.yaml new file mode 100644 index 000000000..07e302f5e --- /dev/null +++ b/releasenotes/notes/bifrost_node_names-f26ca2eab7e261d6.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Adds ability to enroll or deploy specific nodes from the bifrost inventory + using the new environment variable BIFROST_NODE_NAMES for example: + + export BIFROST_NODE_NAMES=node1,node2,node5