1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-03-20 06:50:23 +03:00

Renamed client to proxmox

This commit is contained in:
Adolfo Gómez García 2024-07-02 23:25:24 +02:00
parent 1218904895
commit 3f7cb8e3db
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
9 changed files with 109 additions and 109 deletions

View File

@ -46,20 +46,20 @@ from ...utils.autospec import autospec, AutoSpecMethodInfo
from uds.services.Proxmox import (
deployment_linked,
provider,
client,
proxmox,
service_fixed,
publication,
deployment_fixed,
service_linked,
)
NODES: typing.Final[list[client.types.Node]] = [
client.types.Node(name='node0', online=True, local=True, nodeid=1, ip='0.0.0.1', level='level', id='id'),
client.types.Node(name='node1', online=True, local=True, nodeid=2, ip='0.0.0.2', level='level', id='id'),
NODES: typing.Final[list[proxmox.types.Node]] = [
proxmox.types.Node(name='node0', online=True, local=True, nodeid=1, ip='0.0.0.1', level='level', id='id'),
proxmox.types.Node(name='node1', online=True, local=True, nodeid=2, ip='0.0.0.2', level='level', id='id'),
]
NODE_STATS: typing.Final[list[client.types.NodeStats]] = [
client.types.NodeStats(
NODE_STATS: typing.Final[list[proxmox.types.NodeStats]] = [
proxmox.types.NodeStats(
name='name',
status='status',
uptime=1,
@ -72,7 +72,7 @@ NODE_STATS: typing.Final[list[client.types.NodeStats]] = [
cpu=1.0,
maxcpu=1,
),
client.types.NodeStats(
proxmox.types.NodeStats(
name='name',
status='status',
uptime=1,
@ -88,13 +88,13 @@ NODE_STATS: typing.Final[list[client.types.NodeStats]] = [
]
CLUSTER_INFO: typing.Final[client.types.ClusterInfo] = client.types.ClusterInfo(
cluster=client.types.Cluster(name='name', version='version', id='id', nodes=2, quorate=1),
CLUSTER_INFO: typing.Final[proxmox.types.ClusterInfo] = proxmox.types.ClusterInfo(
cluster=proxmox.types.Cluster(name='name', version='version', id='id', nodes=2, quorate=1),
nodes=NODES,
)
STORAGES: typing.Final[list[client.types.StorageInfo]] = [
client.types.StorageInfo(
STORAGES: typing.Final[list[proxmox.types.StorageInfo]] = [
proxmox.types.StorageInfo(
node=NODES[i % len(NODES)].name,
storage=f'storage_{i}',
content=(f'content{i}',) * (i % 3),
@ -110,22 +110,22 @@ STORAGES: typing.Final[list[client.types.StorageInfo]] = [
]
VGPUS: typing.Final[list[client.types.VGPUInfo]] = [
client.types.VGPUInfo(
VGPUS: typing.Final[list[proxmox.types.VGPUInfo]] = [
proxmox.types.VGPUInfo(
name='name_1',
description='description_1',
device='device_1',
available=True,
type='gpu_type_1',
),
client.types.VGPUInfo(
proxmox.types.VGPUInfo(
name='name_2',
description='description_2',
device='device_2',
available=False,
type='gpu_type_2',
),
client.types.VGPUInfo(
proxmox.types.VGPUInfo(
name='name_3',
description='description_3',
device='device_3',
@ -141,8 +141,8 @@ HA_GROUPS: typing.Final[list[str]] = [
'ha_group_4',
]
VMS_INFO: list[client.types.VMInfo] = [
client.types.VMInfo(
VMS_INFO: list[proxmox.types.VMInfo] = [
proxmox.types.VMInfo(
status='stopped',
vmid=i,
node=NODES[i % len(NODES)].name,
@ -168,8 +168,8 @@ VMS_INFO: list[client.types.VMInfo] = [
for i in range(1, 16)
]
VMS_CONFIGURATION: typing.Final[list[client.types.VMConfiguration]] = [
client.types.VMConfiguration(
VMS_CONFIGURATION: typing.Final[list[proxmox.types.VMConfiguration]] = [
proxmox.types.VMConfiguration(
name=f'vm_name_{i}',
vga='cirrus',
sockets=1,
@ -177,7 +177,7 @@ VMS_CONFIGURATION: typing.Final[list[client.types.VMConfiguration]] = [
vmgenid='vmgenid',
digest='digest',
networks=[
client.types.NetworkConfiguration(
proxmox.types.NetworkConfiguration(
net='net', type='type', mac=f'{i:02x}:{i+1:02x}:{i+2:02x}:{i+3:02x}:{i+4:02x}:{i+5:02x}'
)
],
@ -188,7 +188,7 @@ VMS_CONFIGURATION: typing.Final[list[client.types.VMConfiguration]] = [
]
UPID: typing.Final[client.types.UPID] = client.types.UPID(
UPID: typing.Final[proxmox.types.UPID] = proxmox.types.UPID(
node=NODES[0].name,
pid=1,
pstart=1,
@ -200,15 +200,15 @@ UPID: typing.Final[client.types.UPID] = client.types.UPID(
)
VM_CREATION_RESULT: typing.Final[client.types.VmCreationResult] = client.types.VmCreationResult(
VM_CREATION_RESULT: typing.Final[proxmox.types.VmCreationResult] = proxmox.types.VmCreationResult(
node=NODES[0].name,
vmid=VMS_INFO[0].vmid,
upid=UPID,
)
SNAPSHOTS_INFO: typing.Final[list[client.types.SnapshotInfo]] = [
client.types.SnapshotInfo(
SNAPSHOTS_INFO: typing.Final[list[proxmox.types.SnapshotInfo]] = [
proxmox.types.SnapshotInfo(
name=f'snap_name_{i}',
description=f'snap desription{i}',
parent=f'snap_parent_{i}',
@ -218,7 +218,7 @@ SNAPSHOTS_INFO: typing.Final[list[client.types.SnapshotInfo]] = [
for i in range(10)
]
TASK_STATUS = client.types.TaskStatus(
TASK_STATUS = proxmox.types.TaskStatus(
node=NODES[0].name,
pid=1,
pstart=1,
@ -231,8 +231,8 @@ TASK_STATUS = client.types.TaskStatus(
id='id',
)
POOL_MEMBERS: typing.Final[list[client.types.PoolMemberInfo]] = [
client.types.PoolMemberInfo(
POOL_MEMBERS: typing.Final[list[proxmox.types.PoolMemberInfo]] = [
proxmox.types.PoolMemberInfo(
id=f'id_{i}',
node=NODES[i % len(NODES)].name,
storage=STORAGES[i % len(STORAGES)].storage,
@ -243,8 +243,8 @@ POOL_MEMBERS: typing.Final[list[client.types.PoolMemberInfo]] = [
for i in range(10)
]
POOLS: typing.Final[list[client.types.PoolInfo]] = [
client.types.PoolInfo(
POOLS: typing.Final[list[proxmox.types.PoolInfo]] = [
proxmox.types.PoolInfo(
poolid=f'pool_{i}',
comments=f'comments_{i}',
members=POOL_MEMBERS,
@ -269,7 +269,7 @@ CONSOLE_CONNECTION_INFO: typing.Final[types.services.ConsoleConnectionInfo] = (
)
def replace_vm_info(vmid: int, **kwargs: typing.Any) -> client.types.UPID:
def replace_vm_info(vmid: int, **kwargs: typing.Any) -> proxmox.types.UPID:
"""
Set the values of VMS_INFO[vmid - 1]
"""
@ -280,7 +280,7 @@ def replace_vm_info(vmid: int, **kwargs: typing.Any) -> client.types.UPID:
return UPID
def replacer_vm_info(**kwargs: typing.Any) -> typing.Callable[..., client.types.UPID]:
def replacer_vm_info(**kwargs: typing.Any) -> typing.Callable[..., proxmox.types.UPID]:
return functools.partial(replace_vm_info, **kwargs)
@ -288,87 +288,87 @@ def replacer_vm_info(**kwargs: typing.Any) -> typing.Callable[..., client.types.
CLIENT_METHODS_INFO: typing.Final[list[AutoSpecMethodInfo]] = [
# connect returns None
# Test method
AutoSpecMethodInfo(client.ProxmoxClient.test, returns=True),
AutoSpecMethodInfo(proxmox.ProxmoxClient.test, returns=True),
# get_cluster_info
AutoSpecMethodInfo(client.ProxmoxClient.get_cluster_info, returns=CLUSTER_INFO),
AutoSpecMethodInfo(proxmox.ProxmoxClient.get_cluster_info, returns=CLUSTER_INFO),
# get_next_vmid
AutoSpecMethodInfo(client.ProxmoxClient.get_next_vmid, returns=1),
AutoSpecMethodInfo(proxmox.ProxmoxClient.get_next_vmid, returns=1),
# is_vmid_available
AutoSpecMethodInfo(client.ProxmoxClient.is_vmid_available, returns=True),
AutoSpecMethodInfo(proxmox.ProxmoxClient.is_vmid_available, returns=True),
# get_node_networks, not called never (ensure it's not called by mistake)
# list_node_gpu_devices
AutoSpecMethodInfo(client.ProxmoxClient.list_node_gpu_devices, returns=['gpu_dev_1', 'gpu_dev_2']),
AutoSpecMethodInfo(proxmox.ProxmoxClient.list_node_gpu_devices, returns=['gpu_dev_1', 'gpu_dev_2']),
# list_node_vgpus
AutoSpecMethodInfo(client.ProxmoxClient.list_node_vgpus, returns=VGPUS),
AutoSpecMethodInfo(proxmox.ProxmoxClient.list_node_vgpus, returns=VGPUS),
# node_has_vgpus_available
AutoSpecMethodInfo(client.ProxmoxClient.node_has_vgpus_available, returns=True),
AutoSpecMethodInfo(proxmox.ProxmoxClient.node_has_vgpus_available, returns=True),
# get_best_node_for_machine
AutoSpecMethodInfo(client.ProxmoxClient.get_best_node_for_machine, returns=NODE_STATS[0]),
AutoSpecMethodInfo(proxmox.ProxmoxClient.get_best_node_for_machine, returns=NODE_STATS[0]),
# clone_machine
AutoSpecMethodInfo(client.ProxmoxClient.clone_machine, returns=VM_CREATION_RESULT),
AutoSpecMethodInfo(proxmox.ProxmoxClient.clone_machine, returns=VM_CREATION_RESULT),
# list_ha_groups
AutoSpecMethodInfo(client.ProxmoxClient.list_ha_groups, returns=HA_GROUPS),
AutoSpecMethodInfo(proxmox.ProxmoxClient.list_ha_groups, returns=HA_GROUPS),
# enable_machine_ha return None
# disable_machine_ha return None
# set_protection return None
# get_guest_ip_address
AutoSpecMethodInfo(client.ProxmoxClient.get_guest_ip_address, returns=GUEST_IP_ADDRESS),
AutoSpecMethodInfo(proxmox.ProxmoxClient.get_guest_ip_address, returns=GUEST_IP_ADDRESS),
# remove_machine
AutoSpecMethodInfo(client.ProxmoxClient.remove_machine, returns=UPID),
AutoSpecMethodInfo(proxmox.ProxmoxClient.remove_machine, returns=UPID),
# list_snapshots
AutoSpecMethodInfo(client.ProxmoxClient.list_snapshots, returns=SNAPSHOTS_INFO),
AutoSpecMethodInfo(proxmox.ProxmoxClient.list_snapshots, returns=SNAPSHOTS_INFO),
# supports_snapshot
AutoSpecMethodInfo(client.ProxmoxClient.supports_snapshot, returns=True),
AutoSpecMethodInfo(proxmox.ProxmoxClient.supports_snapshot, returns=True),
# create_snapshot
AutoSpecMethodInfo(client.ProxmoxClient.create_snapshot, returns=UPID),
AutoSpecMethodInfo(proxmox.ProxmoxClient.create_snapshot, returns=UPID),
# remove_snapshot
AutoSpecMethodInfo(client.ProxmoxClient.remove_snapshot, returns=UPID),
AutoSpecMethodInfo(proxmox.ProxmoxClient.remove_snapshot, returns=UPID),
# restore_snapshot
AutoSpecMethodInfo(client.ProxmoxClient.restore_snapshot, returns=UPID),
AutoSpecMethodInfo(proxmox.ProxmoxClient.restore_snapshot, returns=UPID),
# get_task
AutoSpecMethodInfo(client.ProxmoxClient.get_task, returns=TASK_STATUS),
AutoSpecMethodInfo(proxmox.ProxmoxClient.get_task, returns=TASK_STATUS),
# list_machines
AutoSpecMethodInfo(client.ProxmoxClient.list_machines, returns=VMS_INFO),
AutoSpecMethodInfo(proxmox.ProxmoxClient.list_machines, returns=VMS_INFO),
# get_machine_pool_info
AutoSpecMethodInfo(
client.ProxmoxClient.get_machine_pool_info,
proxmox.ProxmoxClient.get_machine_pool_info,
returns=lambda vmid, poolid, **kwargs: VMS_INFO[vmid - 1], # pyright: ignore
),
# get_machine_info
AutoSpecMethodInfo(
client.ProxmoxClient.get_machine_info,
proxmox.ProxmoxClient.get_machine_info,
returns=lambda vmid, *args, **kwargs: VMS_INFO[vmid - 1], # pyright: ignore
),
# get_machine_configuration
AutoSpecMethodInfo(
client.ProxmoxClient.get_machine_configuration,
proxmox.ProxmoxClient.get_machine_configuration,
returns=lambda vmid, **kwargs: VMS_CONFIGURATION[vmid - 1], # pyright: ignore
),
# enable_machine_ha return None
# start_machine
AutoSpecMethodInfo(client.ProxmoxClient.start_machine, returns=replacer_vm_info(status='running')),
AutoSpecMethodInfo(proxmox.ProxmoxClient.start_machine, returns=replacer_vm_info(status='running')),
# stop_machine
AutoSpecMethodInfo(client.ProxmoxClient.stop_machine, returns=replacer_vm_info(status='stopped')),
AutoSpecMethodInfo(proxmox.ProxmoxClient.stop_machine, returns=replacer_vm_info(status='stopped')),
# reset_machine
AutoSpecMethodInfo(client.ProxmoxClient.reset_machine, returns=replacer_vm_info(status='stopped')),
AutoSpecMethodInfo(proxmox.ProxmoxClient.reset_machine, returns=replacer_vm_info(status='stopped')),
# suspend_machine
AutoSpecMethodInfo(client.ProxmoxClient.suspend_machine, returns=replacer_vm_info(status='suspended')),
AutoSpecMethodInfo(proxmox.ProxmoxClient.suspend_machine, returns=replacer_vm_info(status='suspended')),
# resume_machine
AutoSpecMethodInfo(client.ProxmoxClient.resume_machine, returns=replacer_vm_info(status='running')),
AutoSpecMethodInfo(proxmox.ProxmoxClient.resume_machine, returns=replacer_vm_info(status='running')),
# shutdown_machine
AutoSpecMethodInfo(client.ProxmoxClient.shutdown_machine, returns=replacer_vm_info(status='stopped')),
AutoSpecMethodInfo(proxmox.ProxmoxClient.shutdown_machine, returns=replacer_vm_info(status='stopped')),
# convert_to_template
AutoSpecMethodInfo(client.ProxmoxClient.convert_to_template, returns=replacer_vm_info(template=True)),
AutoSpecMethodInfo(proxmox.ProxmoxClient.convert_to_template, returns=replacer_vm_info(template=True)),
# get_storage
AutoSpecMethodInfo(
client.ProxmoxClient.get_storage,
proxmox.ProxmoxClient.get_storage,
returns=lambda storage, node, **kwargs: next( # pyright: ignore
filter(lambda s: s.storage == storage, STORAGES) # pyright: ignore
),
),
# list_storages
AutoSpecMethodInfo(
client.ProxmoxClient.list_storages,
proxmox.ProxmoxClient.list_storages,
returns=lambda node, **kwargs: ( # pyright: ignore
(list(filter(lambda s: s.node == node, STORAGES))) # pyright: ignore
if node is not None
@ -377,24 +377,24 @@ CLIENT_METHODS_INFO: typing.Final[list[AutoSpecMethodInfo]] = [
),
# get_node_stats
AutoSpecMethodInfo(
client.ProxmoxClient.get_node_stats,
proxmox.ProxmoxClient.get_node_stats,
returns=lambda node, **kwargs: next( # pyright: ignore
filter(lambda n: n.name == node, NODE_STATS) # pyright: ignore
),
),
# list_pools
AutoSpecMethodInfo(client.ProxmoxClient.list_pools, returns=POOLS),
AutoSpecMethodInfo(proxmox.ProxmoxClient.list_pools, returns=POOLS),
# get_pool_info
AutoSpecMethodInfo(
client.ProxmoxClient.get_pool_info,
proxmox.ProxmoxClient.get_pool_info,
returns=lambda poolid, **kwargs: next( # pyright: ignore
filter(lambda p: p.poolid == poolid, POOLS) # pyright: ignore
),
),
# get_console_connection
AutoSpecMethodInfo(client.ProxmoxClient.get_console_connection, returns=CONSOLE_CONNECTION_INFO),
AutoSpecMethodInfo(proxmox.ProxmoxClient.get_console_connection, returns=CONSOLE_CONNECTION_INFO),
# journal
AutoSpecMethodInfo(client.ProxmoxClient.journal, returns=['journal line 1', 'journal line 2']),
AutoSpecMethodInfo(proxmox.ProxmoxClient.journal, returns=['journal line 1', 'journal line 2']),
]
PROVIDER_VALUES_DICT: typing.Final[gui.ValuesDictType] = {
@ -436,7 +436,7 @@ def create_client_mock() -> mock.Mock:
"""
Create a mock of ProxmoxClient
"""
return autospec(client.ProxmoxClient, CLIENT_METHODS_INFO)
return autospec(proxmox.ProxmoxClient, CLIENT_METHODS_INFO)
@contextlib.contextmanager

View File

@ -37,7 +37,7 @@ from uds.core import types
from uds.core.services.generics.fixed.userservice import FixedUserService, Operation
from uds.core.util import autoserializable
from . import client
from . import proxmox
# Not imported at runtime, just for type checking
if typing.TYPE_CHECKING:
@ -61,7 +61,7 @@ class ProxmoxUserServiceFixed(FixedUserService, autoserializable.AutoSerializabl
# : Recheck every ten seconds by default (for task methods)
suggested_delay = 4
def _store_task(self, upid: 'client.types.UPID') -> None:
def _store_task(self, upid: 'proxmox.types.UPID') -> None:
self._task = '\t'.join([upid.node, upid.upid])
def _retrieve_task(self) -> tuple[str, str]:
@ -78,7 +78,7 @@ class ProxmoxUserServiceFixed(FixedUserService, autoserializable.AutoSerializabl
try:
vminfo = self.service().get_machine_info(int(self._vmid))
except client.ProxmoxConnectionError:
except proxmox.ProxmoxConnectionError:
raise # If connection fails, let it fail on parent
except Exception as e:
return self.error(f'Machine not found: {e}')
@ -105,7 +105,7 @@ class ProxmoxUserServiceFixed(FixedUserService, autoserializable.AutoSerializabl
def op_start(self) -> None:
try:
vminfo = self.service().get_machine_info(int(self._vmid))
except client.ProxmoxConnectionError:
except proxmox.ProxmoxConnectionError:
self.retry_later()
return
except Exception as e:
@ -123,7 +123,7 @@ class ProxmoxUserServiceFixed(FixedUserService, autoserializable.AutoSerializabl
try:
task = self.service().provider().get_task_info(node, upid)
except client.ProxmoxConnectionError:
except proxmox.ProxmoxConnectionError:
return types.states.TaskState.RUNNING # Try again later
if task.is_errored():

View File

@ -40,7 +40,7 @@ from uds.core.services.generics.dynamic.userservice import DynamicUserService
from uds.core.managers.userservice import UserServiceManager
from uds.core.util import autoserializable
from . import client
from . import proxmox
# Not imported at runtime, just for type checking
@ -117,7 +117,7 @@ class ProxmoxUserserviceLinked(DynamicUserService):
_task = autoserializable.StringField(default='')
def _store_task(self, upid: 'client.types.UPID') -> None:
def _store_task(self, upid: 'proxmox.types.UPID') -> None:
self._task = ','.join([upid.node, upid.upid])
def _retrieve_task(self) -> tuple[str, str]:
@ -132,7 +132,7 @@ class ProxmoxUserserviceLinked(DynamicUserService):
try:
task = self.service().provider().get_task_info(node, upid)
except client.ProxmoxConnectionError:
except proxmox.ProxmoxConnectionError:
return types.states.TaskState.RUNNING # Try again later
if task.is_errored():
@ -204,7 +204,7 @@ class ProxmoxUserserviceLinked(DynamicUserService):
# Set vm mac address now on first interface
self.service().provider().set_machine_mac(int(self._vmid), self.get_unique_id())
except client.ProxmoxConnectionError:
except proxmox.ProxmoxConnectionError:
self.retry_later() # Push nop to front of queue, so it is consumed instead of this one
return
except Exception as e:

View File

@ -38,7 +38,7 @@ from uds.core.util.model import sql_stamp_seconds
from uds.core.util.unique_id_generator import UniqueIDGenerator
from . import provider
from . import client
from . import proxmox
# Note that even reseting, UDS will get always a FREE vmid, so even if the machine is already in use
# (and removed from used db), it will not be reused until it has dissapeared from the proxmox server
@ -104,7 +104,7 @@ class ProxmoxDeferredRemoval(jobs.Job):
@staticmethod
def waitForTaskFinish(
providerInstance: 'provider.ProxmoxProvider',
upid: 'client.types.UPID',
upid: 'proxmox.types.UPID',
maxWait: int = 30, # 30 * 0.3 = 9 seconds
) -> bool:
counter = 0
@ -146,7 +146,7 @@ class ProxmoxDeferredRemoval(jobs.Job):
# It this is reached, remove check
storage.remove('tr' + str(vmid))
except client.ProxmoxNotFound:
except proxmox.ProxmoxNotFound:
storage.remove('tr' + str(vmid)) # VM does not exists anymore
except Exception as e: # Any other exception wil be threated again
# instance.log('Delayed removal of %s has failed: %s. Will retry later', vmId, e)

View File

@ -38,7 +38,7 @@ from uds.core.util import validators, fields
from uds.core.util.decorators import cached
from uds.core.util.unique_id_generator import UniqueIDGenerator
from . import client
from . import proxmox
from .service_linked import ProxmoxServiceLinked
from .service_fixed import ProxmoxServiceFixed
@ -119,15 +119,15 @@ class ProxmoxProvider(services.ServiceProvider):
macs_range = fields.macs_range_field(default='52:54:00:00:00:00-52:54:00:FF:FF:FF')
# Own variables
_cached_api: typing.Optional[client.ProxmoxClient] = None
_cached_api: typing.Optional[proxmox.ProxmoxClient] = None
_vmid_generator: UniqueIDGenerator
def _api(self) -> client.ProxmoxClient:
def _api(self) -> proxmox.ProxmoxClient:
"""
Returns the connection API object
"""
if self._cached_api is None:
self._cached_api = client.ProxmoxClient(
self._cached_api = proxmox.ProxmoxClient(
self.host.value,
self.port.as_int(),
self.username.value,
@ -166,29 +166,29 @@ class ProxmoxProvider(services.ServiceProvider):
return self._api().test()
def list_machines(self, force: bool = False) -> list[client.types.VMInfo]:
def list_machines(self, force: bool = False) -> list[proxmox.types.VMInfo]:
return self._api().list_machines(force=force)
def get_machine_info(self, vmid: int, poolid: typing.Optional[str] = None) -> client.types.VMInfo:
def get_machine_info(self, vmid: int, poolid: typing.Optional[str] = None) -> proxmox.types.VMInfo:
return self._api().get_machine_pool_info(vmid, poolid, force=True)
def get_machine_configuration(self, vmid: int) -> client.types.VMConfiguration:
def get_machine_configuration(self, vmid: int) -> proxmox.types.VMConfiguration:
return self._api().get_machine_configuration(vmid, force=True)
def get_storage_info(self, storageid: str, node: str, force: bool = False) -> client.types.StorageInfo:
def get_storage_info(self, storageid: str, node: str, force: bool = False) -> proxmox.types.StorageInfo:
return self._api().get_storage(storageid, node, force=force)
def list_storages(
self, node: typing.Optional[str] = None, force: bool = False
) -> list[client.types.StorageInfo]:
) -> list[proxmox.types.StorageInfo]:
return self._api().list_storages(node=node, content='images', force=force)
def list_pools(self, force: bool = False) -> list[client.types.PoolInfo]:
def list_pools(self, force: bool = False) -> list[proxmox.types.PoolInfo]:
return self._api().list_pools(force=force)
def get_pool_info(
self, pool_id: str, retrieve_vm_names: bool = False, force: bool = False
) -> client.types.PoolInfo:
) -> proxmox.types.PoolInfo:
return self._api().get_pool_info(pool_id, retrieve_vm_names=retrieve_vm_names, force=force)
def create_template(self, vmid: int) -> None:
@ -204,7 +204,7 @@ class ProxmoxProvider(services.ServiceProvider):
target_storage: typing.Optional[str] = None,
target_pool: typing.Optional[str] = None,
must_have_vgpus: typing.Optional[bool] = None,
) -> client.types.VmCreationResult:
) -> proxmox.types.VmCreationResult:
return self._api().clone_machine(
vmid,
self.get_new_vmid(),
@ -217,25 +217,25 @@ class ProxmoxProvider(services.ServiceProvider):
must_have_vgpus,
)
def start_machine(self, vmid: int) -> client.types.UPID:
def start_machine(self, vmid: int) -> proxmox.types.UPID:
return self._api().start_machine(vmid)
def stop_machine(self, vmid: int) -> client.types.UPID:
def stop_machine(self, vmid: int) -> proxmox.types.UPID:
return self._api().stop_machine(vmid)
def reset_machine(self, vmid: int) -> client.types.UPID:
def reset_machine(self, vmid: int) -> proxmox.types.UPID:
return self._api().reset_machine(vmid)
def suspend_machine(self, vmId: int) -> client.types.UPID:
def suspend_machine(self, vmId: int) -> proxmox.types.UPID:
return self._api().suspend_machine(vmId)
def shutdown_machine(self, vmid: int) -> client.types.UPID:
def shutdown_machine(self, vmid: int) -> proxmox.types.UPID:
return self._api().shutdown_machine(vmid)
def remove_machine(self, vmid: int) -> client.types.UPID:
def remove_machine(self, vmid: int) -> proxmox.types.UPID:
return self._api().remove_machine(vmid)
def get_task_info(self, node: str, upid: str) -> client.types.TaskStatus:
def get_task_info(self, node: str, upid: str) -> proxmox.types.TaskStatus:
return self._api().get_task(node, upid)
def enable_machine_ha(self, vmid: int, started: bool = False, group: typing.Optional[str] = None) -> None:
@ -270,7 +270,7 @@ class ProxmoxProvider(services.ServiceProvider):
# All assigned vmid will be left as unusable on UDS until released by time (3 years)
# This is not a problem at all, in the rare case that a machine id is released from uds db
# if it exists when we try to create a new one, we will simply try to get another one
raise client.ProxmoxError(f'Could not get a new vmid!!: last tried {vmid}')
raise proxmox.ProxmoxError(f'Could not get a new vmid!!: last tried {vmid}')
def get_guest_ip_address(self, vmid: int, node: typing.Optional[str] = None, ip_version: typing.Literal['4', '6', ''] = '') -> str:
return self._api().get_guest_ip_address(vmid, node, ip_version)
@ -280,7 +280,7 @@ class ProxmoxProvider(services.ServiceProvider):
def get_current_snapshot(
self, vmid: int, node: typing.Optional[str] = None
) -> typing.Optional[client.types.SnapshotInfo]:
) -> typing.Optional[proxmox.types.SnapshotInfo]:
return (
sorted(
filter(lambda x: x.snaptime, self._api().list_snapshots(vmid, node)),
@ -296,12 +296,12 @@ class ProxmoxProvider(services.ServiceProvider):
node: typing.Optional[str] = None,
name: typing.Optional[str] = None,
description: typing.Optional[str] = None,
) -> client.types.UPID:
) -> proxmox.types.UPID:
return self._api().create_snapshot(vmid, node, name, description)
def restore_snapshot(
self, vmid: int, node: typing.Optional[str] = None, name: typing.Optional[str] = None
) -> client.types.UPID:
) -> proxmox.types.UPID:
"""
In fact snapshot is not optional, but node is and want to keep the same signature as the api
"""

View File

@ -46,7 +46,7 @@ from .deployment_fixed import ProxmoxUserServiceFixed
if typing.TYPE_CHECKING:
from uds import models
from . import client
from . import proxmox
from .provider import ProxmoxProvider
logger = logging.getLogger(__name__)
@ -113,7 +113,7 @@ class ProxmoxServiceFixed(FixedService): # pylint: disable=too-many-public-meth
def provider(self) -> 'ProxmoxProvider':
return typing.cast('ProxmoxProvider', super().provider())
def get_machine_info(self, vmId: int) -> 'client.types.VMInfo':
def get_machine_info(self, vmId: int) -> 'proxmox.types.VMInfo':
return self.provider().get_machine_info(vmId, self.pool.value.strip())
def is_avaliable(self) -> bool:

View File

@ -47,7 +47,7 @@ from .publication import ProxmoxPublication
# Not imported at runtime, just for type checking
if typing.TYPE_CHECKING:
from . import client
from . import proxmox
from .provider import ProxmoxProvider
from uds.core.services.generics.dynamic.publication import DynamicPublication
from uds.core.services.generics.dynamic.service import DynamicService
@ -207,7 +207,7 @@ class ProxmoxServiceLinked(DynamicService):
"""
return re.sub("[^a-zA-Z0-9_-]", "-", name)
def clone_machine(self, name: str, description: str, vmid: int = -1) -> 'client.types.VmCreationResult':
def clone_machine(self, name: str, description: str, vmid: int = -1) -> 'proxmox.types.VmCreationResult':
name = self.sanitized_name(name)
pool = self.pool.value or None
if vmid == -1: # vmId == -1 if cloning for template
@ -230,14 +230,14 @@ class ProxmoxServiceLinked(DynamicService):
must_have_vgpus={'1': True, '2': False}.get(self.gpu.value, None),
)
def get_machine_info(self, vmid: int) -> 'client.types.VMInfo':
def get_machine_info(self, vmid: int) -> 'proxmox.types.VMInfo':
return self.provider().get_machine_info(vmid, self.pool.value.strip())
def get_nic_mac(self, vmid: int) -> str:
config = self.provider().get_machine_configuration(vmid)
return config.networks[0].mac.lower()
def xremove_machine(self, vmid: int) -> 'client.types.UPID':
def xremove_machine(self, vmid: int) -> 'proxmox.types.UPID':
# First, remove from HA if needed
try:
self.disable_machine_ha(vmid)