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
This commit is contained in:
Sam Betts 2018-07-03 16:01:31 +01:00
parent 0d0cfd908d
commit 9f15352901
2 changed files with 31 additions and 0 deletions

View File

@ -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

View File

@ -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