Skip to content

vmware: take parent_folder_2 tags from the folder two levels up - #638

Open
tyderian1978 wants to merge 1 commit into
bb-Ricardo:developmentfrom
tyderian1978:fix/vmware-parent-folder-2-tags
Open

tyderian1978 wants to merge 1 commit into
bb-Ricardo:developmentfrom
tyderian1978:fix/vmware-parent-folder-2-tags

Conversation

@tyderian1978

Copy link
Copy Markdown

Disclaimer: AI generated, based off the work we're doing with Netbox.

What happens

The parent_folder_2 tag source is documented as "the indirect folder this object is organized in (2 levels up)". collect_object_tags() looks it up with get_parent_object_by_class(obj, vim.Folder), the same call it uses for parent_folder_1, so both return the first folder above the object:

  • vm_tag_source = parent_folder_2 gives the tags of the direct folder instead of the folder above it
  • vm_tag_source = parent_folder_1, parent_folder_2 gives the direct folder's tags twice and never the second folder's

The same applies to host_tag_source and cluster_tag_source.

Fix

parent_folder_2 is now the folder that parent_folder_1 is organized in. When parent_folder_1 is the top VM or host folder of a datacenter, the next level up is the datacenter itself, so there is no second folder. Setups using parent_folder_2 will see their synced tags change to what the documentation describes.

The new lookup reads the folder's parent directly. Once #634 is merged, I'll route it through #634's per-run parent cache.

Tests

tests/test_vmware_tag_sources.py uses a faked tagging API and a folder tree datacenter / vm / Dept / Prod in which every folder carries one tag:

  • parent_folder_1 for a VM in Prod gives Prod's tag (unchanged)
  • parent_folder_2 gives Dept's tag, and both together give Prod's and Dept's
  • for a VM in the datacenter's top VM folder, parent_folder_2 adds nothing

The three parent_folder_2 cases fail on development. Full suite: 838 passed, 8 skipped.

The 'parent_folder_2' tag source is documented as the folder an object is
organized in 2 levels up, but collect_object_tags() looked up the first
folder above the object a second time and used the tags of parent_folder_1.
On its own 'parent_folder_2' gave the direct folder's tags, together with
'parent_folder_1' the same tags twice.

parent_folder_2 is now the folder that parent_folder_1 is organized in. If
parent_folder_1 is the top VM or host folder of a datacenter there is none.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant