1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

Added default implementatio of remove_and_free_machine (very common...)

This commit is contained in:
Adolfo Gómez García 2024-03-26 01:46:06 +01:00
parent fedd6507ae
commit 0322df85d5
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
2 changed files with 8 additions and 15 deletions

View File

@ -177,13 +177,15 @@ class FixedService(services.Service, abc.ABC): # pylint: disable=too-many-publi
"""
raise NotImplementedError()
@abc.abstractmethod
# default implementation, should be sufficient for most cases
def remove_and_free_machine(self, vmid: str) -> str:
"""
Removes and frees a machine
Returns an state (State.FINISHED is nothing to do left)
"""
raise NotImplementedError()
try:
with self._assigned_machines_access() as assigned:
assigned.remove(vmid)
return types.states.State.FINISHED
except Exception as e:
logger.warning('Cound not save assigned machines on fixed pool: %s', e)
raise
@abc.abstractmethod
def get_first_network_mac(self, vmid: str) -> str:

View File

@ -216,12 +216,3 @@ class ProxmoxServiceFixed(FixedService): # pylint: disable=too-many-public-meth
def get_machine_name(self, vmid: str) -> str:
return self.provider().get_machine_info(int(vmid)).name or ''
def remove_and_free_machine(self, vmid: str) -> str:
try:
with self._assigned_machines_access() as assigned_vms:
assigned_vms.remove(vmid)
return types.states.State.FINISHED
except Exception as e:
logger.warning('Cound not save assigned machines on fixed pool: %s', e)
raise