Add availability to ensure nodes moved from enroll to available
Starting from Ironic API microversion 1.11 newly-created nodes
added in enroll state. To move all nodes from enroll state to
available the following pillar might be used:
ironic:
client:
node_state_transition:
enabled: true
enroll_to_available:
provision_state: 'enroll'
Change-Id: If2249ba17eb3c4b89079a78fbd14b129ef80ed01
Related-prod: PROD-25757
(cherry picked from commit ebaa23c13fcc10fe23856e426e040ca33515dacd)
diff --git a/_states/ironicv1.py b/_states/ironicv1.py
index 53f7f36..150cc15 100644
--- a/_states/ironicv1.py
+++ b/_states/ironicv1.py
@@ -284,18 +284,32 @@
return _failed('find', name, resource)
-def enroll_to_state(name, node_names, cloud_name,
- pool_size=3, sleep_time=5, timeout=600, **kwargs):
+def ensure_target_state(name, cloud_name, node_names=None,
+ provision_state=None, pool_size=3, sleep_time=5,
+ timeout=600, **kwargs):
"""
+ Ensures nodes are moved to target state. As node distinguisher might take
+ either list of nodes specified in node names param or provision state.
+ Is designed to move nodes from enroll to available state for now.
:param name: name of target state
:param node_names: list of node names
- :param cloud_name:
+ :param provision_state: current provision_state to filter nodes by.
+ :param cloud_name: the mane of cloud in clouds.yml
:param pool_size: max size of nodes to change state in one moment
:param sleep_time: time between checking states
:param timeout: global timeout
"""
+
microversion = kwargs.pop('microversion', '1.32')
+
+ if node_names is None:
+ nodes = _ironicv1_call('node_list', provision_state=provision_state,
+ cloud_name=cloud_name,
+ fields='name',
+ microversion=microversion)['nodes']
+ node_names = [n['name'] for n in nodes]
+
Transition = collections.namedtuple('Transition',
('action', 'success', 'failures'))
transition_map = {
@@ -305,7 +319,7 @@
}
nodes = [
{'name': node, 'status': 'new', 'result': None,
- 'current_state': 'enroll'}
+ 'current_state': provision_state or 'enroll'}
for node in node_names
]
counter = 0