diff --git a/netbox_awx_plugin/serializers.py b/netbox_awx_plugin/serializers.py index 3b05ae0845cd25200c4442cc4c568dee66b8c07d..7e2b7c9d8d20e524673bdf2a468c4669fb6e1612 100644 --- a/netbox_awx_plugin/serializers.py +++ b/netbox_awx_plugin/serializers.py @@ -18,16 +18,16 @@ group_prefixes = { class TagSerializer(serializers.BaseSerializer): def to_representation(self, instance): return { - "name": f"{group_prefixes[Tag]}{instance.slug.replace('-', '_')}", - "description": instance.description, + "name": f"{group_prefixes[Tag]}{instance.slug.replace('-', '_')}".strip(), + "description": instance.description.strip(), "variables": json.dumps({"netbox_tag_name": instance.name}), } class SiteSerializer(serializers.BaseSerializer): def to_representation(self, instance): return { - "name": f"{group_prefixes[Site]}{instance.slug.replace('-', '_')}", - "description": instance.description, + "name": f"{group_prefixes[Site]}{instance.slug.replace('-', '_')}".strip(), + "description": instance.description.strip(), "variables": json.dumps( { "netbox_site_status": instance.status, @@ -38,16 +38,16 @@ class SiteSerializer(serializers.BaseSerializer): class DeviceRoleSerializer(serializers.BaseSerializer): def to_representation(self, instance): return { - "name": f"{group_prefixes[DeviceRole]}{instance.slug.replace('-', '_')}", - "description": instance.description, + "name": f"{group_prefixes[DeviceRole]}{instance.slug.replace('-', '_')}".strip(), + "description": instance.description.strip(), "variables": json.dumps({}) } class DeviceTypeSerializer(serializers.BaseSerializer): def to_representation(self, instance): return { - "name": f"{group_prefixes[DeviceType]}{instance.slug.replace('-', '_')}", - "description": instance.description, + "name": f"{group_prefixes[DeviceType]}{instance.slug.replace('-', '_')}".strip(), + "description": instance.description.strip(), "variables": json.dumps( { "netbox_devicetype_model": instance.model, @@ -59,8 +59,8 @@ class PrefixSerializer(serializers.BaseSerializer): def to_representation(self, instance): prefix_str = str(instance.prefix).replace(".", "_").replace("/", "_") return { - "name": f"{group_prefixes[Prefix]}{prefix_str}", - "description": instance.description, + "name": f"{group_prefixes[Prefix]}{prefix_str}".strip(), + "description": instance.description.strip(), "variables": json.dumps({"netbox_prefix": str(instance.prefix)}), } @@ -91,8 +91,8 @@ class DeviceSerializer(serializers.BaseSerializer): serializer = InterfaceSerializer(interface) variables["netbox_interfaces"].append(serializer.data) return { - "name": getattr(instance.primary_ip4, 'dns_name', instance.name), - "description": instance.description, + "name": getattr(instance.primary_ip4, 'dns_name', instance.name).strip(), + "description": instance.description.strip(), "enabled": instance.status == DeviceStatusChoices.STATUS_ACTIVE, "variables": json.dumps(variables), } @@ -122,8 +122,8 @@ class VMSerializer(serializers.BaseSerializer): serializer = VMInterfaceSerializer(interface) variables["netbox_interfaces"].append(serializer.data) return { - "name": getattr(instance.primary_ip4, 'dns_name', instance.name), - "description": instance.description, + "name": getattr(instance.primary_ip4, 'dns_name', instance.name).strip(), + "description": instance.description.strip(), "enabled": instance.status == VirtualMachineStatusChoices.STATUS_ACTIVE, "variables": json.dumps(variables), }