From 0843990dee91c76a7f1fbd0602f5e86d30c0aea8 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Sat, 9 Jan 2021 13:52:41 +0100 Subject: [PATCH] ironic: stop putting meaningless values to properties None of the properties are required nowadays, putting made-up values there brings more harm than good. Change-Id: I35bda0ac2dc9c32acb94aaa4d28572af2cac85fa --- plugins/modules/baremetal_node.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/modules/baremetal_node.py b/plugins/modules/baremetal_node.py index 9145d54e..416d03a1 100644 --- a/plugins/modules/baremetal_node.py +++ b/plugins/modules/baremetal_node.py @@ -174,17 +174,24 @@ from ansible_collections.openstack.cloud.plugins.module_utils.openstack import ( ) +_PROPERTIES = { + 'cpu_arch': 'cpu_arch', + 'cpus': 'cpus', + 'ram': 'memory_mb', + 'disk_size': 'local_gb', + 'capabilities': 'capabilities', + 'root_device': 'root_device', +} + + def _parse_properties(module): + """Convert ansible properties into native ironic values. + + Also filter out any properties that are not set. + """ p = module.params['properties'] - props = dict( - cpu_arch=p.get('cpu_arch') if p.get('cpu_arch') else 'x86_64', - cpus=p.get('cpus') if p.get('cpus') else 1, - memory_mb=p.get('ram') if p.get('ram') else 1, - local_gb=p.get('disk_size') if p.get('disk_size') else 1, - capabilities=p.get('capabilities') if p.get('capabilities') else '', - root_device=p.get('root_device') if p.get('root_device') else '', - ) - return props + return {to_key: p[from_key] for (from_key, to_key) in _PROPERTIES.items() + if p.get(from_key) is not None} def _parse_driver_info(sdk, module):