Repository: SaaShup/netbox-docker-plugin (language: python)

Issue:
Host new properties
Add this two properties:

* Agent version
* Docker API version

Read only on UI and Read Write on API


Discussion / hints:

Fix patch:
diff --git a/netbox_docker_plugin/api/serializers.py b/netbox_docker_plugin/api/serializers.py
index 47cee75..cae8075 100644
--- a/netbox_docker_plugin/api/serializers.py
+++ b/netbox_docker_plugin/api/serializers.py
@@ -1,4 +1,5 @@
 """API Serializer definitions"""
+
 # pylint: disable=E1101
 
 from rest_framework import serializers
@@ -22,7 +23,16 @@ class Meta:
         """Nested Host Serializer Meta class"""
 
         model = Host
-        fields = ("id", "url", "display", "endpoint", "name", "state")
+        fields = (
+            "id",
+            "url",
+            "display",
+            "endpoint",
+            "name",
+            "state",
+            "agent_version",
+            "docker_api_version",
+        )
 
 
 class NestedImageSerializer(WritableNestedSerializer):
@@ -128,15 +138,13 @@ class Meta:
 class NestedNetworkSettingSerializer(WritableNestedSerializer):
     """Nested NetworkSetting Serializer class"""
 
-    network=NestedNetworkSerializer()
+    network = NestedNetworkSerializer()
 
     class Meta:
         """Nested NetworkSetting Serializer Meta class"""
 
         model = NetworkSetting
-        fields = (
-            "id", "network"
-        )
+        fields = ("id", "network")
 
 
 class ImageSerializer(NetBoxModelSerializer):
@@ -447,6 +455,8 @@ class Meta:
             "state",
             "token",
             "netbox_base_url",
+            "agent_version",
+            "docker_api_version",
             "custom_fields",
             "created",
             "last_updated",
diff --git a/netbox_docker_plugin/filtersets.py b/netbox_docker_plugin/filtersets.py
index 708a778..4832005 100644
--- a/netbox_docker_plugin/filtersets.py
+++ b/netbox_docker_plugin/filtersets.py
@@ -19,7 +19,14 @@ class Meta:
         """Host filterset definition meta class"""
 
         model = Host
-        fields = ("id", "name", "endpoint", "state")
+        fields = (
+            "id",
+            "name",
+            "endpoint",
+            "state",
+            "agent_version",
+            "docker_api_version",
+        )
 
     # pylint: disable=W0613
     def search(self, queryset, name, value):
diff --git a/netbox_docker_plugin/forms/host.py b/netbox_docker_plugin/forms/host.py
index dcaa320..029dd68 100644
--- a/netbox_docker_plugin/forms/host.py
+++ b/netbox_docker_plugin/forms/host.py
@@ -36,6 +36,12 @@ class HostFilterForm(NetBoxModelFilterSetForm):
         label="Endpoint", max_length=256, min_length=1, required=False
     )
     state = forms.ChoiceField(label="State", choices=HostStateChoices, required=False)
+    agent_version = forms.CharField(
+        label="Agent Version", max_length=32, min_length=1, required=False
+    )
+    docker_api_version = forms.CharField(
+        label="Docker API Version", max_length=32, min_length=1, required=False
+    )
     tag = TagFilterField(model)
 
 
diff --git a/netbox_docker_plugin/migrations/0019_host_agent_version_host_docker_api_version.py b/netbox_docker_plugin/migrations/0019_host_agent_version_host_docker_api_version.py
new file mode 100644
index 0000000..2059647
--- /dev/null
+++ b/netbox_docker_plugin/migrations/0019_host_agent_version_host_docker_api_version.py
@@ -0,0 +1,28 @@
+# pylint: disable=C0103
+"""Migration file"""
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    """Migration file"""
+
+    dependencies = [
+        (
+            "netbox_docker_plugin",
+            "0018_alter_mount_volume_alter_networksetting_network",
+        ),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="host",
+            name="agent_version",
+            field=models.CharField(blank=True, max_length=32, null=True),
+        ),
+        migrations.AddField(
+            model_name="host",
+            name="docker_api_version",
+            field=models.CharField(blank=True, max_length=32, null=True),
+        ),
+    ]
diff --git a/netbox_docker_plugin/models/host.py b/netbox_docker_plugin/models/host.py
index 5d61d26..f7a6bfd 100644
--- a/netbox_docker_plugin/models/host.py
+++ b/netbox_docker_plugin/models/host.py
@@ -52,6 +52,16 @@ class Host(NetBoxModel):
         null=True,
         blank=True,
     )
+    agent_version = models.CharField(
+        max_length=32,
+        null=True,
+        blank=True,
+    )
+    docker_api_version = models.CharField(
+        max_length=32,
+        null=True,
+        blank=True,
+    )
 
     class Meta:
         """Host Model Meta Class"""
diff --git a/netbox_docker_plugin/tables.py b/netbox_docker_plugin/tables.py
index 9de68af..815b985 100644
--- a/netbox_docker_plugin/tables.py
+++ b/netbox_docker_plugin/tables.py
@@ -50,6 +50,8 @@ class Meta(NetBoxTable.Meta):
             "name",
             "endpoint",
             "state",
+            "agent_version",
+            "docker_api_version",
             "image_count",
             "volume_count",
             "network_count",
diff --git a/netbox_docker_plugin/templates/netbox_docker_plugin/host.html b/netbox_docker_plugin/templates/netbox_docker_plugin/host.html
index 09809f4..fd44c73 100644
--- a/netbox_docker_plugin/templates/netbox_docker_plugin/host.html
+++ b/netbox_docker_plugin/templates/netbox_docker_plugin/host.html
@@ -22,6 +22,14 @@ <h5 class="card-header">HOST</h5>
             <th scope="row">State</th>
             <td>{{ object.get_state_display }}</td>
           </tr>
+          <tr>
+            <th scope="row">Agent Version</th>
+            <td>{{ object.agent_version|placeholder }}</td>
+          </tr>
+          <tr>
+            <th scope="row">Docker API Version</th>
+            <td>{{ object.docker_api_version|placeholder }}</td>
+          </tr>
         </table>
       </div>
     </div>


Test patch:
diff --git a/netbox_docker_plugin/tests/host/test_host_api.py b/netbox_docker_plugin/tests/host/test_host_api.py
index 96394e3..dc4cbb3 100644
--- a/netbox_docker_plugin/tests/host/test_host_api.py
+++ b/netbox_docker_plugin/tests/host/test_host_api.py
@@ -21,7 +21,16 @@ class HostApiTestCase(
     """Host API Test Case Class"""
 
     model = Host
-    brief_fields = ["display", "endpoint", "id", "name", "state", "url"]
+    brief_fields = [
+        "agent_version",
+        "display",
+        "docker_api_version",
+        "endpoint",
+        "id",
+        "name",
+        "state",
+        "url",
+    ]
     create_data = [
         {
             "endpoint": "http://localhost:8083",