Merge "Workflow to select nodes matching a profile/role"
This commit is contained in:
commit
93558ac4e2
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
features:
|
||||
- Added a new workflow to fetch all the matching nodes with the given
|
||||
profile. To support it, a new action to fetch the node's capabilities
|
||||
has been added too.
|
|
@ -64,6 +64,7 @@ output_file = tripleo_common/locale/tripleo-common.pot
|
|||
mistral.actions =
|
||||
tripleo.baremetal.configure_boot = tripleo_common.actions.baremetal:ConfigureBootAction
|
||||
tripleo.baremetal.configure_root_device = tripleo_common.actions.baremetal:ConfigureRootDeviceAction
|
||||
tripleo.baremetal.get_profile = tripleo_common.actions.baremetal:GetProfileAction
|
||||
tripleo.baremetal.register_or_update_nodes = tripleo_common.actions.baremetal:RegisterOrUpdateNodes
|
||||
tripleo.baremetal.update_node_capability = tripleo_common.actions.baremetal:UpdateNodeCapability
|
||||
tripleo.baremetal.cell_v2_discover_hosts = tripleo_common.actions.baremetal:CellV2DiscoverHostsAction
|
||||
|
|
|
@ -331,3 +331,17 @@ class CellV2DiscoverHostsAction(base.TripleOAction):
|
|||
return mistral_workflow_utils.Result(
|
||||
error="%s: %s" % (type(err).__name__, str(err))
|
||||
)
|
||||
|
||||
|
||||
class GetProfileAction(base.TripleOAction):
|
||||
"""Return the profile associated with the given node """
|
||||
|
||||
def __init__(self, node):
|
||||
super(GetProfileAction, self).__init__()
|
||||
self.node = node
|
||||
|
||||
def run(self):
|
||||
result = {}
|
||||
result['profile'] = nodes.get_node_profile(self.node)
|
||||
result['uuid'] = self.node.get('uuid')
|
||||
return result
|
||||
|
|
|
@ -353,3 +353,21 @@ class TestCellV2DiscoverHostsAction(base.TestCase):
|
|||
result = action.run()
|
||||
self.assertTrue(result.is_error())
|
||||
mock_command.assert_called_once()
|
||||
|
||||
|
||||
class TestGetProfileAction(base.TestCase):
|
||||
|
||||
def test_run(self):
|
||||
node = {
|
||||
'uuid': 'abcd1',
|
||||
'properties': {
|
||||
'capabilities': 'profile:compute'
|
||||
}
|
||||
}
|
||||
action = baremetal.GetProfileAction(node=node)
|
||||
result = action.run()
|
||||
expected_result = {
|
||||
'uuid': 'abcd1',
|
||||
'profile': 'compute'
|
||||
}
|
||||
self.assertEqual(result, expected_result)
|
||||
|
|
|
@ -550,3 +550,15 @@ def run_nova_cell_v2_discovery():
|
|||
'discover_hosts',
|
||||
'--verbose'
|
||||
)
|
||||
|
||||
|
||||
def get_node_profile(node):
|
||||
"""Return the profile assosicated with the node """
|
||||
|
||||
capabilities = node.get('properties').get('capabilities')
|
||||
capabilities_dict = capabilities_to_dict(capabilities)
|
||||
|
||||
if 'profile' in capabilities_dict:
|
||||
return capabilities_dict['profile']
|
||||
|
||||
return None
|
||||
|
|
|
@ -728,6 +728,54 @@ workflows:
|
|||
on-success:
|
||||
- fail: <% $.get('status') = "FAILED" %>
|
||||
|
||||
nodes_with_profile:
|
||||
description: Find nodes with a specific profile
|
||||
input:
|
||||
- profile
|
||||
- queue_name: tripleo
|
||||
|
||||
tasks:
|
||||
get_available_nodes:
|
||||
action: ironic.node_list maintenance=false provision_state='available' detail=true
|
||||
on-success: get_matching_nodes
|
||||
on-error: set_status_failed_get_available_nodes
|
||||
|
||||
get_matching_nodes:
|
||||
with-items: node in <% task(get_available_nodes).result %>
|
||||
action: tripleo.baremetal.get_profile node=<% $.node %>
|
||||
on-success: send_message
|
||||
on-error: set_status_failed_get_matching_nodes
|
||||
publish:
|
||||
matching_nodes: <% let(input_profile_name => $.profile) -> task(get_matching_nodes).result.where($.profile = $input_profile_name).uuid %>
|
||||
|
||||
set_status_failed_get_available_nodes:
|
||||
on-success: send_message
|
||||
publish:
|
||||
status: FAILED
|
||||
message: <% task(get_available_nodes).result %>
|
||||
|
||||
set_status_failed_get_matching_nodes:
|
||||
on-success: send_message
|
||||
publish:
|
||||
status: FAILED
|
||||
message: <% task(get_matching_nodes).result %>
|
||||
|
||||
send_message:
|
||||
action: zaqar.queue_post
|
||||
retry: count=5 delay=1
|
||||
input:
|
||||
queue_name: <% $.queue_name %>
|
||||
messages:
|
||||
body:
|
||||
type: tripleo.baremetal.v1.nodes_with_profile
|
||||
payload:
|
||||
status: <% $.get('status', 'SUCCESS') %>
|
||||
message: <% $.get('message', '') %>
|
||||
execution: <% execution() %>
|
||||
matching_nodes: <% $.matching_nodes or [] %>
|
||||
on-success:
|
||||
- fail: <% $.get('status') = "FAILED" %>
|
||||
|
||||
create_raid_configuration:
|
||||
description: Create and apply RAID configuration for given nodes
|
||||
input:
|
||||
|
|
Loading…
Reference in New Issue