1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-21 18:03:54 +03:00

Cleaning "nonsense" repeated methods from proxmox service that are only direct proxies to proxmox provider<

This commit is contained in:
Adolfo Gómez García 2024-02-19 02:21:55 +01:00
parent 500cb2ed96
commit 202444f64e
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
4 changed files with 21 additions and 65 deletions

View File

@ -207,7 +207,7 @@ class ProxmoxDeployment(services.UserService, autoserializable.AutoSerializable)
"""
if self._vmid != '':
try:
self.service().reset_machine(int(self._vmid))
self.service().provider().reset_machine(int(self._vmid))
except Exception: # nosec: if cannot reset, ignore it
pass # If could not reset, ignore it...
@ -417,7 +417,7 @@ if sys.platform == 'win32':
raise Exception('Machine not found on start machine') from e
if vmInfo.status == 'stopped':
self._store_task(self.service().start_machine(int(self._vmid)))
self._store_task(self.service().provider().start_machine(int(self._vmid)))
return State.RUNNING
@ -429,7 +429,7 @@ if sys.platform == 'win32':
if vm_info.status != 'stopped':
logger.debug('Stopping machine %s', vm_info)
self._store_task(self.service().stop_machine(int(self._vmid)))
self._store_task(self.service().provider().stop_machine(int(self._vmid)))
return State.RUNNING
@ -442,7 +442,7 @@ if sys.platform == 'win32':
raise Exception('Machine not found or suspended machine') from e
if vmInfo.status != 'stopped':
self._store_task(self.service().shutdown_machine(int(self._vmid)))
self._store_task(self.service().provider().shutdown_machine(int(self._vmid)))
return State.RUNNING
@ -456,7 +456,7 @@ if sys.platform == 'win32':
shutdown = -1 # Means machine already stopped
vmInfo = self.service().get_machine_info(int(self._vmid))
if vmInfo.status != 'stopped':
self._store_task(self.service().shutdown_machine(int(self._vmid)))
self._store_task(self.service().provider().shutdown_machine(int(self._vmid)))
shutdown = sql_stamp_seconds()
logger.debug('Stoped vm using guest tools')
self.storage.put_pickle('shutdown', shutdown)
@ -467,7 +467,7 @@ if sys.platform == 'win32':
self.service().enable_ha(int(self._vmid), True) # Enable HA before continuing here
# Set vm mac address now on first interface
self.service().set_machine_mac(int(self._vmid), self.get_unique_id())
self.service().provider().set_machine_mac(int(self._vmid), self.get_unique_id())
except Exception as e:
logger.exception('Setting HA and MAC on proxmox')
raise Exception(f'Error setting MAC and HA on proxmox: {e}') from e
@ -481,7 +481,7 @@ if sys.platform == 'win32':
node, upid = self._retrieve_task()
try:
task = self.service().get_task_info(node, upid)
task = self.service().provider().get_task_info(node, upid)
except client.ProxmoxConnectionError:
return State.RUNNING # Try again later

View File

@ -101,7 +101,7 @@ class ProxmoxFixedUserService(FixedUserService, autoserializable.AutoSerializabl
"""
if self._vmid != '':
try:
self.service().reset_machine(int(self._vmid))
self.service().provider().reset_machine(int(self._vmid))
except Exception: # nosec: if cannot reset, ignore it
pass # If could not reset, ignore it...
@ -120,7 +120,7 @@ class ProxmoxFixedUserService(FixedUserService, autoserializable.AutoSerializabl
raise Exception('Machine not found on start machine') from e
if vminfo.status == 'stopped':
self._store_task(self.service().start_machine(int(self._vmid)))
self._store_task(self.service().provider().start_machine(int(self._vmid)))
def _stop_machine(self) -> None:
try:
@ -130,7 +130,7 @@ class ProxmoxFixedUserService(FixedUserService, autoserializable.AutoSerializabl
if vm_info.status != 'stopped':
logger.debug('Stopping machine %s', vm_info)
self._store_task(self.service().stop_machine(int(self._vmid)))
self._store_task(self.service().provider().stop_machine(int(self._vmid)))
# Check methods
def _check_task_finished(self) -> str:
@ -140,7 +140,7 @@ class ProxmoxFixedUserService(FixedUserService, autoserializable.AutoSerializabl
node, upid = self._retrieve_task()
try:
task = self.service().get_task_info(node, upid)
task = self.service().provider().get_task_info(node, upid)
except client.ProxmoxConnectionError:
return State.RUNNING # Try again later

View File

@ -205,9 +205,6 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
"""
return re.sub("[^a-zA-Z0-9_-]", "-", name)
def make_template(self, vmId: int) -> None:
self.provider().create_template(vmId)
def clone_machine(self, name: str, description: str, vmId: int = -1) -> 'client.types.VmCreationResult':
name = self.sanitized_name(name)
pool = self.pool.value or None
@ -238,50 +235,26 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
config = self.provider().get_machine_configuration(vmid)
return config.networks[0].mac.lower()
def get_task_info(self, node: str, upid: str) -> 'client.types.TaskStatus':
return self.provider().get_task_info(node, upid)
def start_machine(self, vmId: int) -> 'client.types.UPID':
return self.provider().start_machine(vmId)
def stop_machine(self, vmId: int) -> 'client.types.UPID':
return self.provider().stop_machine(vmId)
def reset_machine(self, vmId: int) -> 'client.types.UPID':
return self.provider().reset_machine(vmId)
def suspend_machine(self, vmId: int) -> 'client.types.UPID':
return self.provider().suspend_machine(vmId)
def shutdown_machine(self, vmId: int) -> 'client.types.UPID':
return self.provider().shutdown_machine(vmId)
def remove_machine(self, vmId: int) -> 'client.types.UPID':
def remove_machine(self, vmid: int) -> 'client.types.UPID':
# First, remove from HA if needed
try:
self.disable_ha(vmId)
self.disable_ha(vmid)
except Exception as e:
logger.warning('Exception disabling HA for vm %s: %s', vmId, e)
self.do_log(level=log.LogLevel.WARNING, message=f'Exception disabling HA for vm {vmId}: {e}')
logger.warning('Exception disabling HA for vm %s: %s', vmid, e)
self.do_log(level=log.LogLevel.WARNING, message=f'Exception disabling HA for vm {vmid}: {e}')
# And remove it
return self.provider().remove_machine(vmId)
return self.provider().remove_machine(vmid)
def enable_ha(self, vmId: int, started: bool = False) -> None:
def enable_ha(self, vmid: int, started: bool = False) -> None:
if self.ha.value == '__':
return
self.provider().enable_ha(vmId, started, self.ha.value or None)
self.provider().enable_ha(vmid, started, self.ha.value or None)
def disable_ha(self, vmId: int) -> None:
def disable_ha(self, vmid: int) -> None:
if self.ha.value == '__':
return
self.provider().disable_ha(vmId)
def set_protection(self, vmId: int, node: typing.Optional[str] = None, protection: bool = False) -> None:
self.provider().set_protection(vmId, node, protection)
def set_machine_mac(self, vmId: int, mac: str) -> None:
self.provider().set_machine_mac(vmId, mac)
self.provider().disable_ha(vmid)
def get_basename(self) -> str:
return self.basename.value
@ -295,7 +268,7 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
"""
return self.provider().get_macs_range()
def enable_ha_for_machines(self) -> bool:
def is_ha_enabled(self) -> bool:
return self.ha.value != '__'
def try_graceful_shutdown(self) -> bool:
@ -306,6 +279,5 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
) -> typing.Optional[types.services.ConsoleConnectionInfo]:
return self.provider().get_console_connection(machine_id)
@cached('reachable', consts.cache.SHORT_CACHE_TIMEOUT)
def is_avaliable(self) -> bool:
return self.provider().is_available()

View File

@ -133,22 +133,6 @@ class ProxmoxFixedService(FixedService): # pylint: disable=too-many-public-meth
def get_machine_info(self, vmId: int) -> 'client.types.VMInfo':
return self.provider().get_machine_info(vmId, self.pool.value.strip())
def get_task_info(self, node: str, upid: str) -> 'client.types.TaskStatus':
return self.provider().get_task_info(node, upid)
def start_machine(self, vmId: int) -> 'client.types.UPID':
return self.provider().start_machine(vmId)
def stop_machine(self, vmId: int) -> 'client.types.UPID':
return self.provider().stop_machine(vmId)
def reset_machine(self, vmId: int) -> 'client.types.UPID':
return self.provider().reset_machine(vmId)
def shutdown_machine(self, vmId: int) -> 'client.types.UPID':
return self.provider().shutdown_machine(vmId)
@cached('reachable', consts.cache.SHORT_CACHE_TIMEOUT)
def is_avaliable(self) -> bool:
return self.provider().is_available()