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

Issue:
add network state
Can you please add states with 2 values on a network entity ?
When we create a network pls default value of state is "create" , the second possible valued is "created"

name and value can be changed if a better proposal is shared.



Discussion / hints:

Fix patch:
diff --git a/netbox_docker_plugin/__init__.py b/netbox_docker_plugin/__init__.py
index fee958a..9bce96b 100644
--- a/netbox_docker_plugin/__init__.py
+++ b/netbox_docker_plugin/__init__.py
@@ -9,7 +9,7 @@ class NetBoxDockerConfig(PluginConfig):
     name = "netbox_docker_plugin"
     verbose_name = " NetBox Docker Plugin"
     description = "Manage Docker"
-    version = "1.0.0-rc5"
+    version = "1.0.0-rc6"
     base_url = "docker"
 
 
diff --git a/netbox_docker_plugin/api/serializers.py b/netbox_docker_plugin/api/serializers.py
index 413cd0a..da3acbe 100644
--- a/netbox_docker_plugin/api/serializers.py
+++ b/netbox_docker_plugin/api/serializers.py
@@ -86,6 +86,7 @@ class Meta:
             "name",
             "driver",
             "NetworkID",
+            "state",
         )
 
 
@@ -178,6 +179,7 @@ class Meta:
             "name",
             "driver",
             "NetworkID",
+            "state",
             "custom_fields",
             "created",
             "last_updated",
diff --git a/netbox_docker_plugin/forms/network.py b/netbox_docker_plugin/forms/network.py
index c96cfbe..f258ebc 100644
--- a/netbox_docker_plugin/forms/network.py
+++ b/netbox_docker_plugin/forms/network.py
@@ -8,7 +8,7 @@
     NetBoxModelFilterSetForm,
     NetBoxModelBulkEditForm,
 )
-from ..models.network import Network, NetworkDriverChoices
+from ..models.network import Network, NetworkDriverChoices, NetworkStateChoices
 from ..models.host import Host
 
 
@@ -51,6 +51,11 @@ class NetworkFilterForm(NetBoxModelFilterSetForm):
     NetworkID = forms.CharField(
         label="NetworkID", max_length=128, min_length=1, required=False
     )
+    state = forms.ChoiceField(
+        label="Driver",
+        choices=NetworkStateChoices,
+        required=False,
+    )
     tag = TagFilterField(model)
 
 
diff --git a/netbox_docker_plugin/migrations/0017_network_state.py b/netbox_docker_plugin/migrations/0017_network_state.py
new file mode 100644
index 0000000..5a335ec
--- /dev/null
+++ b/netbox_docker_plugin/migrations/0017_network_state.py
@@ -0,0 +1,20 @@
+# pylint: disable=C0103
+"""Migration file"""
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    """Migration Class"""
+
+    dependencies = [
+        ('netbox_docker_plugin', '0016_alter_env_value'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='network',
+            name='state',
+            field=models.CharField(default='creating', max_length=32),
+        ),
+    ]
diff --git a/netbox_docker_plugin/models/network.py b/netbox_docker_plugin/models/network.py
index 0d788e2..086a5e1 100644
--- a/netbox_docker_plugin/models/network.py
+++ b/netbox_docker_plugin/models/network.py
@@ -25,6 +25,19 @@ class NetworkDriverChoices(ChoiceSet):
     ]
 
 
+class NetworkStateChoices(ChoiceSet):
+    """Network state choices definition class"""
+
+    key = "Network.state"
+
+    DEFAULT_VALUE = "creating"
+
+    CHOICES = [
+        ("creating", "Creating", "blue"),
+        ("created", "Created", "green"),
+    ]
+
+
 class Network(NetBoxModel):
     """Network definition class"""
 
@@ -52,6 +65,13 @@ class Network(NetBoxModel):
         blank=True,
         null=True,
     )
+    state = models.CharField(
+        max_length=32,
+        choices=NetworkStateChoices,
+        default=NetworkStateChoices.DEFAULT_VALUE,
+        blank=False,
+        null=False,
+    )
 
     class Meta:
         """Network Model Meta Class"""
diff --git a/netbox_docker_plugin/tables.py b/netbox_docker_plugin/tables.py
index efddfc5..839de2a 100644
--- a/netbox_docker_plugin/tables.py
+++ b/netbox_docker_plugin/tables.py
@@ -113,8 +113,8 @@ class Meta(NetBoxTable.Meta):
         """Network Table definition Meta class"""
 
         model = Network
-        fields = ("pk", "id", "host", "name", "driver", "NetworkID", "tags")
-        default_columns = ("name", "driver", "host")
+        fields = ("pk", "id", "host", "name", "driver", "NetworkID", "state", "tags")
+        default_columns = ("name", "driver", "state", "host")
 
 
 class ContainerTable(NetBoxTable):
diff --git a/netbox_docker_plugin/templates/netbox_docker_plugin/network.html b/netbox_docker_plugin/templates/netbox_docker_plugin/network.html
index 322f9e3..6a733ed 100644
--- a/netbox_docker_plugin/templates/netbox_docker_plugin/network.html
+++ b/netbox_docker_plugin/templates/netbox_docker_plugin/network.html
@@ -25,6 +25,10 @@ <h5 class="card-header">NETWORK</h5>
             <th scope="row">NetworkID</th>
             <td>{{ object.NetworkID|placeholder }}</td>
           </tr>
+          <tr>
+            <th scope="row">State</th>
+            <td>{{ object.get_state_display }}</td>
+          </tr>
         </table>
       </div>
     </div>
diff --git a/pyproject.toml b/pyproject.toml
index 517160d..2251581 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
 
 [project]
 name = "netbox-docker-plugin"
-version = "1.0.0-rc5"
+version = "1.0.0-rc6"
 authors = [
   { name="Vincent Simonin", email="vincent@saashup.com" },
 ]


Test patch:
diff --git a/netbox_docker_plugin/tests/network/test_network_api.py b/netbox_docker_plugin/tests/network/test_network_api.py
index 9c74590..22cfb89 100644
--- a/netbox_docker_plugin/tests/network/test_network_api.py
+++ b/netbox_docker_plugin/tests/network/test_network_api.py
@@ -17,7 +17,7 @@ class NetworkApiTestCase(
     """Network Test Case Class"""
 
     model = Network
-    brief_fields = ["NetworkID", "display", "driver", "id", "name", "url"]
+    brief_fields = ["NetworkID", "display", "driver", "id", "name", "state", "url"]
 
     @classmethod
     def setUpTestData(cls) -> None: