stop/restart on clone running container
This commit is contained in:
@@ -19,6 +19,7 @@ from lib.db import (
|
||||
)
|
||||
from lib.proxmox import Proxmox
|
||||
from mikrotik.models import DNSStatic, IPAddress, IPDHCPLease
|
||||
from proxmox.models import Lxc
|
||||
|
||||
|
||||
class MinValueValidatorExtended(MinValueValidator):
|
||||
@@ -87,6 +88,11 @@ class CloneContainer(CloneAbstract):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._old_active = self.is_active
|
||||
|
||||
def get_clone_machine_status(self):
|
||||
self.vm.sync_from_proxmox()
|
||||
return self.vm.status
|
||||
|
||||
|
||||
def execute(self, task_uuid_override=None, *args, **kwargs):
|
||||
from proxmox.models import Lxc
|
||||
from tasklogger.models import TaskFactory
|
||||
@@ -99,6 +105,12 @@ class CloneContainer(CloneAbstract):
|
||||
|
||||
try:
|
||||
data = self.proxmox_data
|
||||
old_status = None
|
||||
if self.vm:
|
||||
old_status = self.get_clone_machine_status()
|
||||
if old_status == 'running':
|
||||
task.add_entry(f"Stopping container '{self.vm.name}'")
|
||||
self.vm.stop()
|
||||
pm = Proxmox()
|
||||
route = data.pop('route')
|
||||
vmdata = data.pop('vm')
|
||||
@@ -128,6 +140,7 @@ class CloneContainer(CloneAbstract):
|
||||
}
|
||||
task.add_entry(f"Cloning container {self.vm.vmid}")
|
||||
|
||||
|
||||
success = False
|
||||
lxc = None
|
||||
lease = None
|
||||
@@ -141,9 +154,13 @@ class CloneContainer(CloneAbstract):
|
||||
|
||||
def _lxc_post():
|
||||
return pm.lxc_post(route, **vmparams)
|
||||
def _restart_cloned():
|
||||
return self.vm.start()
|
||||
|
||||
# Wrap the proxmox function - this handles UPID monitoring synchronously
|
||||
task.wrap_proxmox_function(_lxc_post)
|
||||
if old_status == 'running':
|
||||
task.wrap_proxmox_function(_restart_cloned)
|
||||
task.add_entry("Container creation completed")
|
||||
success = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user