@@ -679,13 +679,18 @@ def get_vmware_object_tags(self, obj):
679679 # noinspection PyBroadException
680680 try :
681681 tag_name = self .tag_session .tagging .Tag .get (tag_id ).name
682- tag_description = f"{ primary_tag_name } : " \
683- f"{ self .tag_session .tagging .Tag .get (tag_id ).description } "
682+ tag_description = self .tag_session .tagging .Tag .get (tag_id ).description
684683 except Exception as e :
685684 log .error (f"Unable to retrieve vCenter tag '{ tag_id } ' for '{ obj .name } ': { e } " )
686685 continue
687686
688687 if tag_name is not None :
688+
689+ if tag_description is not None and len (f"{ tag_description } " ) > 0 :
690+ tag_description = f"{ primary_tag_name } : { tag_description } "
691+ else :
692+ tag_description = primary_tag_name
693+
689694 tag_list .append (self .inventory .add_update_object (NBTag , data = {
690695 "name" : tag_name ,
691696 "description" : tag_description
@@ -1092,13 +1097,25 @@ def add_device_vm_to_inventory(self, object_type, object_data, pnic_data=None, v
10921097 role_name = self .get_object_relation (object_name ,
10931098 "host_role_relation" if object_type == NBDevice else "vm_role_relation" )
10941099
1100+ # take care of object role in NetBox
10951101 if object_type == NBDevice :
10961102 if role_name is None :
10971103 role_name = "Server"
10981104 device_vm_object .update (data = {"device_role" : {"name" : role_name }})
10991105 if object_type == NBVM and role_name is not None :
11001106 device_vm_object .update (data = {"role" : {"name" : role_name }})
11011107
1108+ # verify if source tags have been removed from object.
1109+ new_object_tags = list (map (NetBoxObject .extract_tag_name , object_data .get ("tags" , list ())))
1110+
1111+ for object_tag in device_vm_object .data .get ("tags" , list ()):
1112+
1113+ if not f'{ object_tag .data .get ("description" )} ' .startswith (primary_tag_name ):
1114+ continue
1115+
1116+ if NetBoxObject .extract_tag_name (object_tag ) not in new_object_tags :
1117+ device_vm_object .remove_tags (object_tag )
1118+
11021119 # update VM disk data information
11031120 if version .parse (self .inventory .netbox_api_version ) >= version .parse ("3.7.0" ) and \
11041121 object_type == NBVM and disk_data is not None and len (disk_data ) > 0 :
@@ -2167,8 +2184,8 @@ def add_virtual_machine(self, obj):
21672184 # Add adaption for added virtual disks in NetBox 3.7.0
21682185 if version .parse (self .inventory .netbox_api_version ) < version .parse ("3.7.0" ):
21692186 vm_data ["disk" ] = int (sum ([getattr (comp , "capacityInKB" , 0 ) for comp in hardware_devices
2170- if isinstance (comp , vim .vm .device .VirtualDisk )
2171- ]) / 1024 / 1024 )
2187+ if isinstance (comp , vim .vm .device .VirtualDisk )
2188+ ]) / 1024 / 1024 )
21722189
21732190 if platform is not None :
21742191 vm_data ["platform" ] = {"name" : platform }
0 commit comments