From 1685ad47fa61296b72e0b11e9d5f35df80607d26 Mon Sep 17 00:00:00 2001 From: Andrew Pantuso Date: Tue, 2 Mar 2021 16:39:15 -0500 Subject: [PATCH 01/10] Included explicit parsing for proxmox guest tags and updated corresponding unit test with tags key --- plugins/inventory/proxmox.py | 4 ++++ tests/unit/plugins/inventory/test_proxmox.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index d21688c4d43..b6e46fe183e 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -226,6 +226,10 @@ def _get_vm_config(self, node, vmid, vmtype, name): if config == 'rootfs' or config.startswith(('virtio', 'sata', 'ide', 'scsi')): value = ('disk_image=' + value) + # Parse Proxmox tag string into list + if config == 'tags': + value = [tag.strip() for tag in value.split(",")] + if not (isinstance(value, int) or ',' not in value): # split off strings with commas to a dict # skip over any keys that cannot be processed diff --git a/tests/unit/plugins/inventory/test_proxmox.py b/tests/unit/plugins/inventory/test_proxmox.py index 14332e750e6..90ac1840cad 100644 --- a/tests/unit/plugins/inventory/test_proxmox.py +++ b/tests/unit/plugins/inventory/test_proxmox.py @@ -71,7 +71,8 @@ def get_json(url): "status": "running", "vmid": "100", "disk": "1000", - "uptime": 1000}] + "uptime": 1000, + "tags": "test, tags, ..."}] elif url == "https://localhost:8006/api2/json/nodes/testnode/qemu": # _get_qemu_per_node return [{"name": "test-qemu", @@ -105,7 +106,8 @@ def get_json(url): "vmid": "9001", "uptime": 0, "disk": 0, - "status": "stopped"}] + "status": "stopped", + "tags": "test, tags, ..."}] elif url == "https://localhost:8006/api2/json/pools/test": # _get_members_per_pool return {"members": [{"uptime": 1000, From a1a7d2be460cbd3b72e235a9149badad9f13875f Mon Sep 17 00:00:00 2001 From: Ajpantuso Date: Tue, 2 Mar 2021 18:20:15 -0500 Subject: [PATCH 02/10] Including changelog fragment for PR 1949 --- 1949-proxmox-inventory-tags.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 1949-proxmox-inventory-tags.yml diff --git a/1949-proxmox-inventory-tags.yml b/1949-proxmox-inventory-tags.yml new file mode 100644 index 00000000000..db8adc2a439 --- /dev/null +++ b/1949-proxmox-inventory-tags.yml @@ -0,0 +1,3 @@ +--- +minor_changes: +- proxmox inventory plugin - enabled support for parsing qemu/lxc tags as list to be returned with facts (https://github.com/ansible-collections/community.general/pull/1949) From 2b873c7b63ab854a466b0e060c196eaa9c2781de Mon Sep 17 00:00:00 2001 From: Ajpantuso Date: Tue, 2 Mar 2021 20:59:26 -0500 Subject: [PATCH 03/10] Removed ellipsis from test Proxmox only permits periods when surrounded by alphanumeric characters --- tests/unit/plugins/inventory/test_proxmox.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/plugins/inventory/test_proxmox.py b/tests/unit/plugins/inventory/test_proxmox.py index 90ac1840cad..036c8e5938b 100644 --- a/tests/unit/plugins/inventory/test_proxmox.py +++ b/tests/unit/plugins/inventory/test_proxmox.py @@ -72,7 +72,7 @@ def get_json(url): "vmid": "100", "disk": "1000", "uptime": 1000, - "tags": "test, tags, ..."}] + "tags": "test, tags, here"}] elif url == "https://localhost:8006/api2/json/nodes/testnode/qemu": # _get_qemu_per_node return [{"name": "test-qemu", @@ -107,7 +107,7 @@ def get_json(url): "uptime": 0, "disk": 0, "status": "stopped", - "tags": "test, tags, ..."}] + "tags": "test, tags, here"}] elif url == "https://localhost:8006/api2/json/pools/test": # _get_members_per_pool return {"members": [{"uptime": 1000, From f899a80e4abf87353e037d91bb8bede82a87b11b Mon Sep 17 00:00:00 2001 From: Ajpantuso Date: Wed, 3 Mar 2021 08:05:03 -0500 Subject: [PATCH 04/10] Corrected punctuation for changelog entry Co-authored-by: Felix Fontein --- 1949-proxmox-inventory-tags.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1949-proxmox-inventory-tags.yml b/1949-proxmox-inventory-tags.yml index db8adc2a439..dd7ee03e2d4 100644 --- a/1949-proxmox-inventory-tags.yml +++ b/1949-proxmox-inventory-tags.yml @@ -1,3 +1,3 @@ --- minor_changes: -- proxmox inventory plugin - enabled support for parsing qemu/lxc tags as list to be returned with facts (https://github.com/ansible-collections/community.general/pull/1949) +- proxmox inventory plugin - enabled support for parsing qemu/lxc tags as list to be returned with facts (https://github.com/ansible-collections/community.general/pull/1949). From fe0015ddd255685871f2ea8c416334e477be227c Mon Sep 17 00:00:00 2001 From: Andrew Pantuso Date: Wed, 3 Mar 2021 09:25:56 -0500 Subject: [PATCH 05/10] Allowing tags string to contain commas --- 1949-proxmox-inventory-tags.yml | 3 --- changelogs/fragments/1949-proxmox-inventory-tags.yml | 3 +++ plugins/inventory/proxmox.py | 6 +----- 3 files changed, 4 insertions(+), 8 deletions(-) delete mode 100644 1949-proxmox-inventory-tags.yml create mode 100644 changelogs/fragments/1949-proxmox-inventory-tags.yml diff --git a/1949-proxmox-inventory-tags.yml b/1949-proxmox-inventory-tags.yml deleted file mode 100644 index dd7ee03e2d4..00000000000 --- a/1949-proxmox-inventory-tags.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -minor_changes: -- proxmox inventory plugin - enabled support for parsing qemu/lxc tags as list to be returned with facts (https://github.com/ansible-collections/community.general/pull/1949). diff --git a/changelogs/fragments/1949-proxmox-inventory-tags.yml b/changelogs/fragments/1949-proxmox-inventory-tags.yml new file mode 100644 index 00000000000..e375d6ff3eb --- /dev/null +++ b/changelogs/fragments/1949-proxmox-inventory-tags.yml @@ -0,0 +1,3 @@ +--- +bugfixes: +- proxmox inventory plugin - allowed proxomox tag strng to contain commas when returned as fact (https://github.com/ansible-collections/community.general/pull/1949). diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index b6e46fe183e..8bc0993551a 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -226,11 +226,7 @@ def _get_vm_config(self, node, vmid, vmtype, name): if config == 'rootfs' or config.startswith(('virtio', 'sata', 'ide', 'scsi')): value = ('disk_image=' + value) - # Parse Proxmox tag string into list - if config == 'tags': - value = [tag.strip() for tag in value.split(",")] - - if not (isinstance(value, int) or ',' not in value): + if config != 'tags' and not (isinstance(value, int) or ',' not in value): # split off strings with commas to a dict # skip over any keys that cannot be processed try: From 4a8e8b48a6a185e54049ff9fe554d9ff797d14f7 Mon Sep 17 00:00:00 2001 From: Andrew Pantuso Date: Sun, 7 Mar 2021 10:13:29 -0500 Subject: [PATCH 06/10] Incorporated new parsed tags fact with bugfix --- changelogs/fragments/1949-proxmox-inventory-tags.yml | 2 ++ plugins/inventory/proxmox.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/changelogs/fragments/1949-proxmox-inventory-tags.yml b/changelogs/fragments/1949-proxmox-inventory-tags.yml index e375d6ff3eb..92822652719 100644 --- a/changelogs/fragments/1949-proxmox-inventory-tags.yml +++ b/changelogs/fragments/1949-proxmox-inventory-tags.yml @@ -1,3 +1,5 @@ --- bugfixes: - proxmox inventory plugin - allowed proxomox tag strng to contain commas when returned as fact (https://github.com/ansible-collections/community.general/pull/1949). +minor_changes: +- proxmox inventory plugin - added tags_parsed fact containing tags parsed as a list (https://github.com/ansible-collections/community.general/pull/1949). diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 8bc0993551a..bea3624698e 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -217,6 +217,10 @@ def _get_vm_config(self, node, vmid, vmtype, name): vmtype_key = self.to_safe('%s%s' % (self.get_option('facts_prefix'), vmtype_key.lower())) self.inventory.set_variable(name, vmtype_key, vmtype) + plaintext_configs = [ + 'tags', + ] + for config in ret: key = config key = self.to_safe('%s%s' % (self.get_option('facts_prefix'), key.lower())) @@ -226,7 +230,13 @@ def _get_vm_config(self, node, vmid, vmtype, name): if config == 'rootfs' or config.startswith(('virtio', 'sata', 'ide', 'scsi')): value = ('disk_image=' + value) - if config != 'tags' and not (isinstance(value, int) or ',' not in value): + #Additional field containing parsed tags as list + if config == 'tags': + parsed_key = self.to_safe('%s%s' % (key, "_parsed")) + parsed_value = [tag.strip() for tag in value.split(",")] + self.inventory.set_variable(name, parsed_key , parsed_value) + + if not (isinstance(value, int) or ',' not in value or config in plaintext_configs): # split off strings with commas to a dict # skip over any keys that cannot be processed try: From e8d32f6b256e4889449910437480b9e14d87a853 Mon Sep 17 00:00:00 2001 From: Andrew Pantuso Date: Sun, 7 Mar 2021 10:25:25 -0500 Subject: [PATCH 07/10] Correcting whitespace issues --- plugins/inventory/proxmox.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index bea3624698e..066453ba5aa 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -230,11 +230,11 @@ def _get_vm_config(self, node, vmid, vmtype, name): if config == 'rootfs' or config.startswith(('virtio', 'sata', 'ide', 'scsi')): value = ('disk_image=' + value) - #Additional field containing parsed tags as list + # Additional field containing parsed tags as list if config == 'tags': parsed_key = self.to_safe('%s%s' % (key, "_parsed")) parsed_value = [tag.strip() for tag in value.split(",")] - self.inventory.set_variable(name, parsed_key , parsed_value) + self.inventory.set_variable(name, parsed_key, parsed_value) if not (isinstance(value, int) or ',' not in value or config in plaintext_configs): # split off strings with commas to a dict From 47f6bf7c9bc73b94d261da5c0e393bb16fb693ac Mon Sep 17 00:00:00 2001 From: Ajpantuso Date: Thu, 11 Mar 2021 06:42:57 -0500 Subject: [PATCH 08/10] Update changelogs/fragments/1949-proxmox-inventory-tags.yml Co-authored-by: Felix Fontein --- changelogs/fragments/1949-proxmox-inventory-tags.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/1949-proxmox-inventory-tags.yml b/changelogs/fragments/1949-proxmox-inventory-tags.yml index 92822652719..34a816b2146 100644 --- a/changelogs/fragments/1949-proxmox-inventory-tags.yml +++ b/changelogs/fragments/1949-proxmox-inventory-tags.yml @@ -1,5 +1,5 @@ --- bugfixes: -- proxmox inventory plugin - allowed proxomox tag strng to contain commas when returned as fact (https://github.com/ansible-collections/community.general/pull/1949). +- proxmox inventory plugin - allowed proxomox tag string to contain commas when returned as fact (https://github.com/ansible-collections/community.general/pull/1949). minor_changes: - proxmox inventory plugin - added tags_parsed fact containing tags parsed as a list (https://github.com/ansible-collections/community.general/pull/1949). From b61896ae37cc1cd2fb4374fa870174bd2eee20b8 Mon Sep 17 00:00:00 2001 From: Ajpantuso Date: Thu, 11 Mar 2021 06:43:04 -0500 Subject: [PATCH 09/10] Update plugins/inventory/proxmox.py Co-authored-by: Felix Fontein --- plugins/inventory/proxmox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/inventory/proxmox.py b/plugins/inventory/proxmox.py index 066453ba5aa..bc79d596cb1 100644 --- a/plugins/inventory/proxmox.py +++ b/plugins/inventory/proxmox.py @@ -236,7 +236,7 @@ def _get_vm_config(self, node, vmid, vmtype, name): parsed_value = [tag.strip() for tag in value.split(",")] self.inventory.set_variable(name, parsed_key, parsed_value) - if not (isinstance(value, int) or ',' not in value or config in plaintext_configs): + if not (isinstance(value, int) or ',' not in value): # split off strings with commas to a dict # skip over any keys that cannot be processed try: From 02273d352b634c5ef345e1a3aa9c57f8b26f4ae3 Mon Sep 17 00:00:00 2001 From: Ajpantuso Date: Thu, 11 Mar 2021 06:43:50 -0500 Subject: [PATCH 10/10] Update changelogs/fragments/1949-proxmox-inventory-tags.yml Co-authored-by: Felix Fontein --- changelogs/fragments/1949-proxmox-inventory-tags.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/1949-proxmox-inventory-tags.yml b/changelogs/fragments/1949-proxmox-inventory-tags.yml index 34a816b2146..073428c2e6c 100644 --- a/changelogs/fragments/1949-proxmox-inventory-tags.yml +++ b/changelogs/fragments/1949-proxmox-inventory-tags.yml @@ -2,4 +2,4 @@ bugfixes: - proxmox inventory plugin - allowed proxomox tag string to contain commas when returned as fact (https://github.com/ansible-collections/community.general/pull/1949). minor_changes: -- proxmox inventory plugin - added tags_parsed fact containing tags parsed as a list (https://github.com/ansible-collections/community.general/pull/1949). +- proxmox inventory plugin - added ``tags_parsed`` fact containing tags parsed as a list (https://github.com/ansible-collections/community.general/pull/1949).