Skip to content

Commit 132d197

Browse files
committed
Merge branch 'main' into issue#199
2 parents 8e10eb5 + aa90e94 commit 132d197

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

.github/workflows/pr_ci.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,3 @@ jobs:
7070
coverage run --include='*/netbox_docker_plugin/*' netbox/manage.py test netbox_docker_plugin.tests -v 2
7171
coverage report -m
7272
coverage xml -o coverage.xml
73-
- name: Get Cover
74-
uses: orgoro/coverage@v3.1
75-
with:
76-
coverageFile: netbox/coverage.xml
77-
token: ${{ secrets.GITHUB_TOKEN }}
78-
thresholdAll: 0.9
79-
thresholdNew: 0.9
80-
thresholdModified: 0.9
81-
passIcon: ""
82-
failIcon: ""

netbox_docker_plugin/models/container.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ class ContainerOperationChoices(ChoiceSet):
5252
("start", "Start", "blue"),
5353
("restart", "Restart", "blue"),
5454
("stop", "Stop", "blue"),
55+
("pause", "Pause", "blue"),
56+
("unpause", "Unpause", "blue"),
5557
("recreate", "Recreate", "blue"),
5658
("kill", "Kill", "red"),
5759
("none", "None", "white"),
@@ -209,6 +211,16 @@ def can_kill(self) -> bool:
209211
"""Check if the container can be killed"""
210212
return self.state in ["created", "restarting", "running", "exited", "dead"]
211213

214+
@property
215+
def can_pause(self) -> bool:
216+
"""Check if the container can be paused"""
217+
return self.state in ["running"]
218+
219+
@property
220+
def can_unpause(self) -> bool:
221+
"""Check if the container can be unpaused"""
222+
return self.state in ["paused"]
223+
212224
class Meta:
213225
"""Image Model Meta Class"""
214226

netbox_docker_plugin/signals.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def restrict_container_actions(instance, **_kwargs):
4343
instance.operation == "stop" and not instance.can_stop,
4444
instance.operation == "recreate" and not instance.can_recreate,
4545
instance.operation == "kill" and not instance.can_kill,
46+
instance.operation == "pause" and not instance.can_pause,
47+
instance.operation == "unpause" and not instance.can_unpause,
4648
]
4749
):
4850
raise AbortRequest(

netbox_docker_plugin/templates/netbox_docker_plugin/container-layout.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@
3131
</button>
3232
</form>
3333

34+
{% if object.state == 'paused' %}
35+
<form action="{% url 'plugins:netbox_docker_plugin:container_operation' pk=object.id operation='unpause' %}" method="post">
36+
{% csrf_token %}
37+
<input type="hidden" name="operation" value="unpause">
38+
<button type="submit" class="btn btn-danger">
39+
<i class="mdi mdi-play"></i>Unpause</button>
40+
</form>
41+
42+
{% elif object.state == 'running' %}
43+
<form action="{% url 'plugins:netbox_docker_plugin:container_operation' pk=object.id operation='pause' %}" method="post">
44+
{% csrf_token %}
45+
<input type="hidden" name="operation" value="pause">
46+
<button type="submit" class="btn btn-success">
47+
<i class="mdi mdi-stop"></i> Pause
48+
</button>
49+
</form>
50+
{% endif %}
51+
3452
<form action="{% url 'plugins:netbox_docker_plugin:container_operation' pk=object.id operation='restart' %}" method="post">
3553
{% csrf_token %}
3654
<input type="hidden" name="operation" value="restart">

0 commit comments

Comments
 (0)