diff --git a/module/netbox/connection.py b/module/netbox/connection.py index e9eabd6..37eb8a0 100644 --- a/module/netbox/connection.py +++ b/module/netbox/connection.py @@ -472,7 +472,10 @@ class NetBoxHandler: # request a brief list of existing objects log.debug(f"Requesting a brief list of {nb_object_class.name}s from NetBox") - brief_nb_data = self.request(nb_object_class, params={"brief": 1, "limit": 500}) + brief_params = {"brief": 1, "limit": 500} + if version.parse(self.inventory.netbox_api_version) >= version.parse("4.0"): + brief_params["fields"] = "id" + brief_nb_data = self.request(nb_object_class, params=brief_params) log.debug("NetBox returned %d results." % len(brief_nb_data.get("results", list()))) log.debug(f"Requesting the last updates since {latest_update} of {nb_object_class.name}s from NetBox") diff --git a/module/netbox/object_classes.py b/module/netbox/object_classes.py index 09fa8eb..f93d431 100644 --- a/module/netbox/object_classes.py +++ b/module/netbox/object_classes.py @@ -1152,7 +1152,7 @@ class NBCustomField(NetBoxObject): primary_key = "name" prune = False # used by this software - valid_content_types = [ + valid_object_types = [ "dcim.device", "dcim.interface", "dcim.inventoryitem", @@ -1164,6 +1164,8 @@ class NBCustomField(NetBoxObject): def __init__(self, *args, **kwargs): self.data_model = { + "object_types": list, + # field name (object_types) for NetBox < 4.0.0 "content_types": list, "type": ["text", "longtext", "integer", "boolean", "date", "url", "json", "select", "multiselect"], "name": 50, @@ -1178,29 +1180,39 @@ class NBCustomField(NetBoxObject): def update(self, data=None, read_from_netbox=False, source=None): """ handle content types properly - append to existing content_types and don't delete any + append to existing object_types and don't delete any """ # get current content types - current_content_types = list() - for content_type in grab(self, "data.content_types", fallback=list()): - current_content_types.append(content_type) + current_object_types = list() + for object_type in grab(self, "data.object_types", fallback=list()): + current_object_types.append(object_type) - if isinstance(data.get("content_types"), str): - data["content_types"] = [data.get("content_types")] + if isinstance(data.get("object_types"), str): + data["object_types"] = [data.get("object_types")] - for content_type in data.get("content_types"): - if content_type not in self.valid_content_types and read_from_netbox is False: - log.error(f"Invalid content type '{content_type}' for {self.name}") + for object_type in data.get("object_types"): + if object_type not in self.valid_object_types and read_from_netbox is False: + log.error(f"Invalid content type '{object_type}' for {self.name}") continue - if content_type not in current_content_types: - current_content_types.append(content_type) + if object_type not in current_object_types: + current_object_types.append(object_type) - data["content_types"] = current_content_types + data["object_types"] = current_object_types + + # Keep support for NetBox < 4.0 + if version.parse(self.inventory.netbox_api_version) < version.parse("4.0.0"): + if data.get("object_types") is not None: + data["content_types"] = data.get("object_types") + del data["object_types"] super().update(data=data, read_from_netbox=read_from_netbox, source=source) + if isinstance(grab(self, "data.object_types"), str): + self.data["object_types"] = [grab(self, "data.object_types")] + + # Keep support for NetBox < 4.0 if isinstance(grab(self, "data.content_types"), str): self.data["content_types"] = [grab(self, "data.content_types")] diff --git a/module/sources/check_redfish/import_inventory.py b/module/sources/check_redfish/import_inventory.py index 470de89..822d244 100644 --- a/module/sources/check_redfish/import_inventory.py +++ b/module/sources/check_redfish/import_inventory.py @@ -248,7 +248,7 @@ class CheckRedfish(SourceBase): self.add_update_custom_field({ "name": "service_tag", "label": "Service Tag", - "content_types": [ + "object_types": [ "dcim.device" ], "type": "text", @@ -1040,7 +1040,7 @@ class CheckRedfish(SourceBase): self.add_update_custom_field({ "name": "firmware", "label": "Firmware", - "content_types": [ + "object_types": [ "dcim.inventoryitem", "dcim.powerport" ], @@ -1052,7 +1052,7 @@ class CheckRedfish(SourceBase): self.add_update_custom_field({ "name": "inventory_type", "label": "Type", - "content_types": ["dcim.inventoryitem"], + "object_types": ["dcim.inventoryitem"], "type": "text", "description": "Describes the type of inventory item" }) @@ -1061,7 +1061,7 @@ class CheckRedfish(SourceBase): self.add_update_custom_field({ "name": "inventory_size", "label": "Size", - "content_types": ["dcim.inventoryitem"], + "object_types": ["dcim.inventoryitem"], "type": "text", "description": "Describes the size of the inventory item if applicable" }) @@ -1070,7 +1070,7 @@ class CheckRedfish(SourceBase): self.add_update_custom_field({ "name": "inventory_speed", "label": "Speed", - "content_types": ["dcim.inventoryitem"], + "object_types": ["dcim.inventoryitem"], "type": "text", "description": "Describes the speed of the inventory item if applicable" }) @@ -1079,7 +1079,7 @@ class CheckRedfish(SourceBase): self.add_update_custom_field({ "name": "health", "label": "Health", - "content_types": [ + "object_types": [ "dcim.inventoryitem", "dcim.powerport", "dcim.device" diff --git a/module/sources/common/source_base.py b/module/sources/common/source_base.py index bde9ae1..86f06b8 100644 --- a/module/sources/common/source_base.py +++ b/module/sources/common/source_base.py @@ -770,7 +770,7 @@ class SourceBase: def add_update_custom_field(self, data) -> NBCustomField: """ Adds/updates a NBCustomField object with data. - Update will only update the 'content_types' attribute. + Update will only update the 'object_types' attribute. Parameters ---------- @@ -792,7 +792,7 @@ class SourceBase: if custom_field is None: custom_field = self.inventory.add_object(NBCustomField, data=data, source=self) else: - custom_field.update(data={"content_types": data.get("content_types")}, source=self) + custom_field.update(data={"object_types": data.get("object_types")}, source=self) return custom_field diff --git a/module/sources/vmware/connection.py b/module/sources/vmware/connection.py index c2baf1b..e16106c 100644 --- a/module/sources/vmware/connection.py +++ b/module/sources/vmware/connection.py @@ -779,16 +779,16 @@ class VMWareHandler(SourceBase): custom_value = grab(obj, "customValue", fallback=list()) if grab(obj, "_wsdlName") == "VirtualMachine": - content_type = "virtualization.virtualmachine" + object_type = "virtualization.virtualmachine" custom_object_attributes = self.settings.vm_custom_object_attributes or list() object_attribute_prefix = "vm" else: - content_type = "dcim.device" + object_type = "dcim.device" custom_object_attributes = self.settings.host_custom_object_attributes or list() object_attribute_prefix = "host" # add basic host data to device - if content_type == "dcim.device": + if object_type == "dcim.device": num_cpu_cores = grab(obj, "summary.hardware.numCpuCores") cpu_model = grab(obj, "summary.hardware.cpuModel") memory_size = grab(obj, "summary.hardware.memorySize") @@ -797,7 +797,7 @@ class VMWareHandler(SourceBase): custom_field = self.add_update_custom_field({ "name": "vcsa_host_cpu_cores", "label": "Physical CPU Cores", - "content_types": [content_type], + "object_types": [object_type], "type": "text", "description": f"vCenter '{self.name}' reported Host CPU cores" }) @@ -808,7 +808,7 @@ class VMWareHandler(SourceBase): custom_field = self.add_update_custom_field({ "name": "vcsa_host_memory", "label": "Memory", - "content_types": [content_type], + "object_types": [object_type], "type": "text", "description": f"vCenter '{self.name}' reported Memory" }) @@ -846,7 +846,7 @@ class VMWareHandler(SourceBase): custom_field = self.add_update_custom_field({ "name": f"vcsa_{label}", "label": label, - "content_types": [content_type], + "object_types": [object_type], "type": "text", "description": f"vCenter '{self.name}' synced custom attribute '{label}'" }) @@ -883,7 +883,7 @@ class VMWareHandler(SourceBase): custom_field = self.add_update_custom_field({ "name": f"vcsa_{object_attribute_prefix}_{custom_object_attribute}", "label": custom_object_attribute, - "content_types": [content_type], + "object_types": [object_type], "type": custom_field_type, "description": f"vCenter '{self.name}' synced object attribute '{custom_object_attribute}'" }) @@ -1321,7 +1321,7 @@ class VMWareHandler(SourceBase): custom_field = self.add_update_custom_field({ "name": f"vcsa_{label}", "label": label, - "content_types": ["virtualization.clustergroup"], + "object_types": ["virtualization.clustergroup"], "type": "text", "description": f"vCenter '{self.name}' synced custom attribute '{label}'" }) diff --git a/scripts/publi.sh b/scripts/publi.sh index 36fc0f9..8fcc348 100755 --- a/scripts/publi.sh +++ b/scripts/publi.sh @@ -33,7 +33,7 @@ unset DOCKER_TLS_VERIFY unset DOCKER_HOST unset DOCKER_CERT_PATH -find . -name "__pycache__" -delete +find module -type d -name "__pycache__" -exec rm -rf {} \; docker --config ./docker-tmp login docker --config ./docker-tmp buildx create --use if [[ $FINAL == true ]]; then