mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-03 01:17:56 +03:00
Fix service provider naming in code
* Renamed service "parent" to more convenient "provider"
This commit is contained in:
parent
57be9c80b6
commit
b58d3e210c
@ -547,8 +547,8 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
|||||||
)
|
)
|
||||||
service_instance = service_pool.service.get_instance()
|
service_instance = service_pool.service.get_instance()
|
||||||
if (
|
if (
|
||||||
(removing >= service_instance.parent().get_concurrent_removal_limit()
|
(removing >= service_instance.provider().get_concurrent_removal_limit()
|
||||||
and service_instance.parent().get_ignore_limits() is False)
|
and service_instance.provider().get_ignore_limits() is False)
|
||||||
or service_pool.service.provider.is_in_maintenance()
|
or service_pool.service.provider.is_in_maintenance()
|
||||||
or service_pool.is_restrained()
|
or service_pool.is_restrained()
|
||||||
or not service_instance.is_avaliable()
|
or not service_instance.is_avaliable()
|
||||||
@ -566,8 +566,8 @@ class UserServiceManager(metaclass=singleton.Singleton):
|
|||||||
)
|
)
|
||||||
serviceInstance = service_pool.service.get_instance()
|
serviceInstance = service_pool.service.get_instance()
|
||||||
if self.maximum_user_services_reached(service_pool.service) or (
|
if self.maximum_user_services_reached(service_pool.service) or (
|
||||||
preparingForProvider >= serviceInstance.parent().get_concurrent_creation_limit()
|
preparingForProvider >= serviceInstance.provider().get_concurrent_creation_limit()
|
||||||
and serviceInstance.parent().get_ignore_limits() is False
|
and serviceInstance.provider().get_ignore_limits() is False
|
||||||
):
|
):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
@ -212,7 +212,7 @@ class Service(Module):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
environment: 'environment.Environment',
|
environment: 'environment.Environment',
|
||||||
parent: 'services.ServiceProvider',
|
provider: 'services.ServiceProvider',
|
||||||
values: Module.ValuesType = None,
|
values: Module.ValuesType = None,
|
||||||
uuid: typing.Optional[str] = None,
|
uuid: typing.Optional[str] = None,
|
||||||
):
|
):
|
||||||
@ -222,7 +222,7 @@ class Service(Module):
|
|||||||
cache and storage are "convenient" methods to access _env.cache and _env.storage
|
cache and storage are "convenient" methods to access _env.cache and _env.storage
|
||||||
"""
|
"""
|
||||||
Module.__init__(self, environment, values, uuid)
|
Module.__init__(self, environment, values, uuid)
|
||||||
self._provider = parent
|
self._provider = provider
|
||||||
self.initialize(values)
|
self.initialize(values)
|
||||||
|
|
||||||
def initialize(self, values: Module.ValuesType) -> None:
|
def initialize(self, values: Module.ValuesType) -> None:
|
||||||
@ -251,7 +251,7 @@ class Service(Module):
|
|||||||
self._db_obj = Service.objects.get(uuid=self.get_uuid())
|
self._db_obj = Service.objects.get(uuid=self.get_uuid())
|
||||||
return self._db_obj
|
return self._db_obj
|
||||||
|
|
||||||
def parent(self) -> 'services.ServiceProvider':
|
def provider(self) -> 'services.ServiceProvider':
|
||||||
"""
|
"""
|
||||||
Utility method to access parent provider for this service
|
Utility method to access parent provider for this service
|
||||||
|
|
||||||
|
@ -848,7 +848,7 @@ class gui:
|
|||||||
def init_gui(self):
|
def init_gui(self):
|
||||||
# always set default using self, cause we only want to store
|
# always set default using self, cause we only want to store
|
||||||
# value for current instance
|
# value for current instance
|
||||||
self.hidden.value = self.parent().serialize()
|
self.hidden.value = self.provider().serialize()
|
||||||
# Note, you can use setDefault for legacy compat
|
# Note, you can use setDefault for legacy compat
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -337,7 +337,7 @@ if sys.platform == 'win32':
|
|||||||
self.do_log(log.LogLevel.ERROR, reason)
|
self.do_log(log.LogLevel.ERROR, reason)
|
||||||
|
|
||||||
if self._vmid != '': # Powers off
|
if self._vmid != '': # Powers off
|
||||||
OVirtDeferredRemoval.remove(self.service().parent(), self._vmid)
|
OVirtDeferredRemoval.remove(self.service().provider(), self._vmid)
|
||||||
|
|
||||||
self._queue = [Operation.ERROR]
|
self._queue = [Operation.ERROR]
|
||||||
self._reason = reason
|
self._reason = reason
|
||||||
|
@ -239,10 +239,10 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
# Here we have to use "default values", cause values aren't used at form initialization
|
# Here we have to use "default values", cause values aren't used at form initialization
|
||||||
# This is that value is always '', so if we want to change something, we have to do it
|
# This is that value is always '', so if we want to change something, we have to do it
|
||||||
# at defValue
|
# at defValue
|
||||||
self.ov.value = self.parent().serialize()
|
self.ov.value = self.provider().serialize()
|
||||||
self.ev.value = self.parent().env.key
|
self.ev.value = self.provider().env.key
|
||||||
|
|
||||||
machines = self.parent().getMachines()
|
machines = self.provider().getMachines()
|
||||||
vals = []
|
vals = []
|
||||||
for m in machines:
|
for m in machines:
|
||||||
vals.append(gui.choice_item(m['id'], m['name']))
|
vals.append(gui.choice_item(m['id'], m['name']))
|
||||||
@ -251,15 +251,15 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
# the list of values shown because this is a "ChoiceField"
|
# the list of values shown because this is a "ChoiceField"
|
||||||
self.machine.set_choices(vals)
|
self.machine.set_choices(vals)
|
||||||
|
|
||||||
clusters = self.parent().getClusters()
|
clusters = self.provider().getClusters()
|
||||||
vals = []
|
vals = []
|
||||||
for c in clusters:
|
for c in clusters:
|
||||||
vals.append(gui.choice_item(c['id'], c['name']))
|
vals.append(gui.choice_item(c['id'], c['name']))
|
||||||
|
|
||||||
self.cluster.set_choices(vals)
|
self.cluster.set_choices(vals)
|
||||||
|
|
||||||
def parent(self) -> 'OVirtProvider':
|
def provider(self) -> 'OVirtProvider':
|
||||||
return typing.cast('OVirtProvider', super().parent())
|
return typing.cast('OVirtProvider', super().provider())
|
||||||
|
|
||||||
def datastoreHasSpace(self) -> None:
|
def datastoreHasSpace(self) -> None:
|
||||||
"""Checks if datastore has enough space
|
"""Checks if datastore has enough space
|
||||||
@ -272,7 +272,7 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
"""
|
"""
|
||||||
# Get storages for that datacenter
|
# Get storages for that datacenter
|
||||||
logger.debug('Checking datastore space for %s', self.datastore.value)
|
logger.debug('Checking datastore space for %s', self.datastore.value)
|
||||||
info = self.parent().getStorageInfo(self.datastore.value)
|
info = self.provider().getStorageInfo(self.datastore.value)
|
||||||
logger.debug('Datastore Info: %s', info)
|
logger.debug('Datastore Info: %s', info)
|
||||||
availableGB = info['available'] / (1024 * 1024 * 1024)
|
availableGB = info['available'] / (1024 * 1024 * 1024)
|
||||||
if availableGB < self.minSpaceGB.as_int():
|
if availableGB < self.minSpaceGB.as_int():
|
||||||
@ -306,7 +306,7 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
# Get storages for that datacenter
|
# Get storages for that datacenter
|
||||||
|
|
||||||
self.datastoreHasSpace()
|
self.datastoreHasSpace()
|
||||||
return self.parent().makeTemplate(
|
return self.provider().makeTemplate(
|
||||||
name,
|
name,
|
||||||
comments,
|
comments,
|
||||||
self.machine.value,
|
self.machine.value,
|
||||||
@ -326,7 +326,7 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
|
|
||||||
Raises an exception if operation fails.
|
Raises an exception if operation fails.
|
||||||
"""
|
"""
|
||||||
return self.parent().getTemplateState(templateId)
|
return self.provider().getTemplateState(templateId)
|
||||||
|
|
||||||
def deploy_from_template(self, name: str, comments: str, templateId: str) -> str:
|
def deploy_from_template(self, name: str, comments: str, templateId: str) -> str:
|
||||||
"""
|
"""
|
||||||
@ -345,7 +345,7 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
"""
|
"""
|
||||||
logger.debug('Deploying from template %s machine %s', templateId, name)
|
logger.debug('Deploying from template %s machine %s', templateId, name)
|
||||||
self.datastoreHasSpace()
|
self.datastoreHasSpace()
|
||||||
return self.parent().deployFromTemplate(
|
return self.provider().deployFromTemplate(
|
||||||
name,
|
name,
|
||||||
comments,
|
comments,
|
||||||
templateId,
|
templateId,
|
||||||
@ -360,7 +360,7 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
"""
|
"""
|
||||||
invokes removeTemplate from parent provider
|
invokes removeTemplate from parent provider
|
||||||
"""
|
"""
|
||||||
self.parent().removeTemplate(templateId)
|
self.provider().removeTemplate(templateId)
|
||||||
|
|
||||||
def get_machine_state(self, machineId: str) -> str:
|
def get_machine_state(self, machineId: str) -> str:
|
||||||
"""
|
"""
|
||||||
@ -378,7 +378,7 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
suspended, image_illegal, image_locked or powering_down
|
suspended, image_illegal, image_locked or powering_down
|
||||||
Also can return'unknown' if Machine is not known
|
Also can return'unknown' if Machine is not known
|
||||||
"""
|
"""
|
||||||
return self.parent().getMachineState(machineId)
|
return self.provider().getMachineState(machineId)
|
||||||
|
|
||||||
def startMachine(self, machineId: str) -> None:
|
def startMachine(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -391,7 +391,7 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
self.parent().startMachine(machineId)
|
self.provider().startMachine(machineId)
|
||||||
|
|
||||||
def stopMachine(self, machineId: str) -> None:
|
def stopMachine(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -402,7 +402,7 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
self.parent().stopMachine(machineId)
|
self.provider().stopMachine(machineId)
|
||||||
|
|
||||||
def suspend_machine(self, machineId: str) -> None:
|
def suspend_machine(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -413,7 +413,7 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
self.parent().suspendMachine(machineId)
|
self.provider().suspendMachine(machineId)
|
||||||
|
|
||||||
def removeMachine(self, machineId: str) -> None:
|
def removeMachine(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -424,23 +424,23 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
self.parent().removeMachine(machineId)
|
self.provider().removeMachine(machineId)
|
||||||
|
|
||||||
def updateMachineMac(self, machineId: str, macAddres: str) -> None:
|
def updateMachineMac(self, machineId: str, macAddres: str) -> None:
|
||||||
"""
|
"""
|
||||||
Changes the mac address of first nic of the machine to the one specified
|
Changes the mac address of first nic of the machine to the one specified
|
||||||
"""
|
"""
|
||||||
self.parent().updateMachineMac(machineId, macAddres)
|
self.provider().updateMachineMac(machineId, macAddres)
|
||||||
|
|
||||||
def fixUsb(self, machineId: str):
|
def fixUsb(self, machineId: str):
|
||||||
if self.usb.value in ('native',):
|
if self.usb.value in ('native',):
|
||||||
self.parent().fixUsb(machineId)
|
self.provider().fixUsb(machineId)
|
||||||
|
|
||||||
def getMacRange(self) -> str:
|
def getMacRange(self) -> str:
|
||||||
"""
|
"""
|
||||||
Returns de selected mac range
|
Returns de selected mac range
|
||||||
"""
|
"""
|
||||||
return self.parent().getMacRange()
|
return self.provider().getMacRange()
|
||||||
|
|
||||||
def get_basename(self) -> str:
|
def get_basename(self) -> str:
|
||||||
"""
|
"""
|
||||||
@ -463,7 +463,7 @@ class OVirtLinkedService(services.Service): # pylint: disable=too-many-public-m
|
|||||||
def getConsoleConnection(
|
def getConsoleConnection(
|
||||||
self, machineId: str
|
self, machineId: str
|
||||||
) -> typing.Optional[collections.abc.MutableMapping[str, typing.Any]]:
|
) -> typing.Optional[collections.abc.MutableMapping[str, typing.Any]]:
|
||||||
return self.parent().getConsoleConnection(machineId)
|
return self.provider().getConsoleConnection(machineId)
|
||||||
|
|
||||||
def is_avaliable(self) -> bool:
|
def is_avaliable(self) -> bool:
|
||||||
return self.parent().is_available()
|
return self.provider().is_available()
|
||||||
|
@ -156,19 +156,19 @@ class OGService(services.Service):
|
|||||||
"""
|
"""
|
||||||
Loads required values inside
|
Loads required values inside
|
||||||
"""
|
"""
|
||||||
ous = [gui.choice_item(r['id'], r['name']) for r in self.parent().api.list_of_ous()]
|
ous = [gui.choice_item(r['id'], r['name']) for r in self.provider().api.list_of_ous()]
|
||||||
self.ou.set_choices(ous)
|
self.ou.set_choices(ous)
|
||||||
|
|
||||||
self.parent_uuid.value = self.parent().db_obj().uuid
|
self.parent_uuid.value = self.provider().db_obj().uuid
|
||||||
|
|
||||||
def parent(self) -> 'OGProvider':
|
def provider(self) -> 'OGProvider':
|
||||||
return typing.cast('OGProvider', super().parent())
|
return typing.cast('OGProvider', super().provider())
|
||||||
|
|
||||||
def status(self, machine_id: str) -> typing.Any:
|
def status(self, machine_id: str) -> typing.Any:
|
||||||
return self.parent().status(machine_id)
|
return self.provider().status(machine_id)
|
||||||
|
|
||||||
def reserve(self) -> typing.Any:
|
def reserve(self) -> typing.Any:
|
||||||
return self.parent().reserve(
|
return self.provider().reserve(
|
||||||
self.ou.value,
|
self.ou.value,
|
||||||
self.image.value,
|
self.image.value,
|
||||||
self.lab.value,
|
self.lab.value,
|
||||||
@ -176,10 +176,10 @@ class OGService(services.Service):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def unreserve(self, machine_id: str) -> None:
|
def unreserve(self, machine_id: str) -> None:
|
||||||
self.parent().unreserve(machine_id)
|
self.provider().unreserve(machine_id)
|
||||||
|
|
||||||
def notify_endpoints(self, machine_id: str, token: str, uuid: str) -> None:
|
def notify_endpoints(self, machine_id: str, token: str, uuid: str) -> None:
|
||||||
self.parent().notify_endpoints(
|
self.provider().notify_endpoints(
|
||||||
machine_id,
|
machine_id,
|
||||||
self.get_login_notify_url(uuid, token),
|
self.get_login_notify_url(uuid, token),
|
||||||
self.get_logout_notify_url(uuid, token),
|
self.get_logout_notify_url(uuid, token),
|
||||||
@ -187,14 +187,14 @@ class OGService(services.Service):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def notify_deadline(self, machine_id: str, deadLine: typing.Optional[int]) -> None:
|
def notify_deadline(self, machine_id: str, deadLine: typing.Optional[int]) -> None:
|
||||||
self.parent().notify_deadline(machine_id, deadLine)
|
self.provider().notify_deadline(machine_id, deadLine)
|
||||||
|
|
||||||
def power_on(self, machine_id: str) -> None:
|
def power_on(self, machine_id: str) -> None:
|
||||||
self.parent().power_on(machine_id, self.image.value)
|
self.provider().power_on(machine_id, self.image.value)
|
||||||
|
|
||||||
def _notify_url(self, uuid: str, token: str, message: str) -> str:
|
def _notify_url(self, uuid: str, token: str, message: str) -> str:
|
||||||
# The URL is "GET messages URL".
|
# The URL is "GET messages URL".
|
||||||
return f'{self.parent().get_uds_endpoint()}uds/ognotify/{message}/{token}/{uuid}'
|
return f'{self.provider().get_uds_endpoint()}uds/ognotify/{message}/{token}/{uuid}'
|
||||||
|
|
||||||
def get_login_notify_url(self, uuid: str, token: str) -> str:
|
def get_login_notify_url(self, uuid: str, token: str) -> str:
|
||||||
return self._notify_url(uuid, token, 'login')
|
return self._notify_url(uuid, token, 'login')
|
||||||
@ -209,4 +209,4 @@ class OGService(services.Service):
|
|||||||
return self.start_if_unavailable.as_bool()
|
return self.start_if_unavailable.as_bool()
|
||||||
|
|
||||||
def is_avaliable(self) -> bool:
|
def is_avaliable(self) -> bool:
|
||||||
return self.parent().is_available()
|
return self.provider().is_available()
|
||||||
|
@ -153,8 +153,8 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
self.baseName.value, length=self.lenName.as_int()
|
self.baseName.value, length=self.lenName.as_int()
|
||||||
)
|
)
|
||||||
|
|
||||||
def parent(self) -> 'OpenNebulaProvider':
|
def provider(self) -> 'OpenNebulaProvider':
|
||||||
return typing.cast('OpenNebulaProvider', super().parent())
|
return typing.cast('OpenNebulaProvider', super().provider())
|
||||||
|
|
||||||
def init_gui(self) -> None:
|
def init_gui(self) -> None:
|
||||||
"""
|
"""
|
||||||
@ -163,24 +163,24 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
|
|
||||||
t: 'on.types.TemplateType'
|
t: 'on.types.TemplateType'
|
||||||
self.template.set_choices(
|
self.template.set_choices(
|
||||||
[gui.choice_item(t.id, t.name) for t in self.parent().getTemplates()]
|
[gui.choice_item(t.id, t.name) for t in self.provider().getTemplates()]
|
||||||
)
|
)
|
||||||
|
|
||||||
d: 'on.types.StorageType'
|
d: 'on.types.StorageType'
|
||||||
self.datastore.set_choices(
|
self.datastore.set_choices(
|
||||||
[gui.choice_item(d.id, d.name) for d in self.parent().getDatastores()]
|
[gui.choice_item(d.id, d.name) for d in self.provider().getDatastores()]
|
||||||
)
|
)
|
||||||
|
|
||||||
def sanitized_name(self, name: str) -> str:
|
def sanitized_name(self, name: str) -> str:
|
||||||
return self.parent().sanitized_name(name)
|
return self.provider().sanitized_name(name)
|
||||||
|
|
||||||
def make_template(self, name: str) -> str:
|
def make_template(self, name: str) -> str:
|
||||||
return self.parent().make_template(
|
return self.provider().make_template(
|
||||||
self.template.value, name, self.datastore.value
|
self.template.value, name, self.datastore.value
|
||||||
)
|
)
|
||||||
|
|
||||||
def check_template_published(self, template_id: str) -> bool:
|
def check_template_published(self, template_id: str) -> bool:
|
||||||
return self.parent().check_template_published(template_id)
|
return self.provider().check_template_published(template_id)
|
||||||
|
|
||||||
def deploy_from_template(self, name: str, templateId: str) -> str:
|
def deploy_from_template(self, name: str, templateId: str) -> str:
|
||||||
"""
|
"""
|
||||||
@ -196,13 +196,13 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
"""
|
"""
|
||||||
logger.debug('Deploying from template %s machine %s', templateId, name)
|
logger.debug('Deploying from template %s machine %s', templateId, name)
|
||||||
# self.datastoreHasSpace()
|
# self.datastoreHasSpace()
|
||||||
return self.parent().deply_from_template(name, templateId)
|
return self.provider().deply_from_template(name, templateId)
|
||||||
|
|
||||||
def remove_template(self, templateId: str) -> None:
|
def remove_template(self, templateId: str) -> None:
|
||||||
"""
|
"""
|
||||||
invokes removeTemplate from parent provider
|
invokes removeTemplate from parent provider
|
||||||
"""
|
"""
|
||||||
self.parent().removeTemplate(templateId)
|
self.provider().removeTemplate(templateId)
|
||||||
|
|
||||||
def getMachineState(self, machineId: str) -> 'on.types.VmState':
|
def getMachineState(self, machineId: str) -> 'on.types.VmState':
|
||||||
"""
|
"""
|
||||||
@ -220,14 +220,14 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
suspended, image_illegal, image_locked or powering_down
|
suspended, image_illegal, image_locked or powering_down
|
||||||
Also can return'unknown' if Machine is not known
|
Also can return'unknown' if Machine is not known
|
||||||
"""
|
"""
|
||||||
return self.parent().getMachineState(machineId)
|
return self.provider().getMachineState(machineId)
|
||||||
|
|
||||||
def getMachineSubstate(self, machineId: str) -> int:
|
def getMachineSubstate(self, machineId: str) -> int:
|
||||||
"""
|
"""
|
||||||
On OpenNebula, the machine can be "active" but not "running".
|
On OpenNebula, the machine can be "active" but not "running".
|
||||||
Any active machine will have a LCM_STATE, that is what we get here
|
Any active machine will have a LCM_STATE, that is what we get here
|
||||||
"""
|
"""
|
||||||
return self.parent().getMachineSubstate(machineId)
|
return self.provider().getMachineSubstate(machineId)
|
||||||
|
|
||||||
def startMachine(self, machineId: str) -> None:
|
def startMachine(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -240,7 +240,7 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
self.parent().startMachine(machineId)
|
self.provider().startMachine(machineId)
|
||||||
|
|
||||||
def stopMachine(self, machineId: str) -> None:
|
def stopMachine(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -251,7 +251,7 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
self.parent().stopMachine(machineId)
|
self.provider().stopMachine(machineId)
|
||||||
|
|
||||||
def suspendMachine(self, machineId: str) -> None:
|
def suspendMachine(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -262,7 +262,7 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
self.parent().suspendMachine(machineId)
|
self.provider().suspendMachine(machineId)
|
||||||
|
|
||||||
def shutdownMachine(self, machineId: str) -> None:
|
def shutdownMachine(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -273,10 +273,10 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
self.parent().shutdownMachine(machineId)
|
self.provider().shutdownMachine(machineId)
|
||||||
|
|
||||||
def resetMachine(self, machineId: str) -> None:
|
def resetMachine(self, machineId: str) -> None:
|
||||||
self.parent().resetMachine(machineId)
|
self.provider().resetMachine(machineId)
|
||||||
|
|
||||||
def removeMachine(self, machineId: str) -> None:
|
def removeMachine(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -287,7 +287,7 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
self.parent().removeMachine(machineId)
|
self.provider().removeMachine(machineId)
|
||||||
|
|
||||||
def getNetInfo(
|
def getNetInfo(
|
||||||
self, machineId: str, networkId: typing.Optional[str] = None
|
self, machineId: str, networkId: typing.Optional[str] = None
|
||||||
@ -295,7 +295,7 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
"""
|
"""
|
||||||
Changes the mac address of first nic of the machine to the one specified
|
Changes the mac address of first nic of the machine to the one specified
|
||||||
"""
|
"""
|
||||||
return self.parent().getNetInfo(machineId, networkId=None)
|
return self.provider().getNetInfo(machineId, networkId=None)
|
||||||
|
|
||||||
def get_basename(self) -> str:
|
def get_basename(self) -> str:
|
||||||
"""
|
"""
|
||||||
@ -310,12 +310,12 @@ class OpenNebulaLiveService(services.Service):
|
|||||||
return self.lenName.as_int()
|
return self.lenName.as_int()
|
||||||
|
|
||||||
def getConsoleConnection(self, machineId: str) -> dict[str, typing.Any]:
|
def getConsoleConnection(self, machineId: str) -> dict[str, typing.Any]:
|
||||||
return self.parent().getConsoleConnection(machineId)
|
return self.provider().getConsoleConnection(machineId)
|
||||||
|
|
||||||
def desktop_login(
|
def desktop_login(
|
||||||
self, machineId: str, username: str, password: str, domain: str
|
self, machineId: str, username: str, password: str, domain: str
|
||||||
) -> dict[str, typing.Any]:
|
) -> dict[str, typing.Any]:
|
||||||
return self.parent().desktop_login(machineId, username, password, domain)
|
return self.provider().desktop_login(machineId, username, password, domain)
|
||||||
|
|
||||||
def is_avaliable(self) -> bool:
|
def is_avaliable(self) -> bool:
|
||||||
return self.parent().is_available()
|
return self.provider().is_available()
|
||||||
|
@ -213,22 +213,22 @@ class OpenStackLiveService(services.Service):
|
|||||||
if values:
|
if values:
|
||||||
validators.validate_basename(self.baseName.value, self.lenName.as_int())
|
validators.validate_basename(self.baseName.value, self.lenName.as_int())
|
||||||
|
|
||||||
# self.ov.value = self.parent().serialize()
|
# self.ov.value = self.provider().serialize()
|
||||||
# self.ev.value = self.parent().env.key
|
# self.ev.value = self.provider().env.key
|
||||||
|
|
||||||
def parent(self) -> 'Provider':
|
def provider(self) -> 'Provider':
|
||||||
return typing.cast('Provider', super().parent())
|
return typing.cast('Provider', super().provider())
|
||||||
|
|
||||||
def init_gui(self):
|
def init_gui(self):
|
||||||
"""
|
"""
|
||||||
Loads required values inside
|
Loads required values inside
|
||||||
"""
|
"""
|
||||||
api = self.parent().api()
|
api = self.provider().api()
|
||||||
|
|
||||||
# Checks if legacy or current openstack provider
|
# Checks if legacy or current openstack provider
|
||||||
parentCurrent = (
|
parentCurrent = (
|
||||||
typing.cast('OpenStackProvider', self.parent())
|
typing.cast('OpenStackProvider', self.provider())
|
||||||
if not self.parent().legacy
|
if not self.provider().legacy
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -250,23 +250,23 @@ class OpenStackLiveService(services.Service):
|
|||||||
self.project.set_choices(tenants)
|
self.project.set_choices(tenants)
|
||||||
|
|
||||||
# So we can instantiate parent to get API
|
# So we can instantiate parent to get API
|
||||||
logger.debug(self.parent().serialize())
|
logger.debug(self.provider().serialize())
|
||||||
|
|
||||||
self.ov.value = self.parent().serialize()
|
self.ov.value = self.provider().serialize()
|
||||||
self.ev.value = self.parent().env.key
|
self.ev.value = self.provider().env.key
|
||||||
self.legacy.value = gui.bool_as_str(self.parent().legacy)
|
self.legacy.value = gui.bool_as_str(self.provider().legacy)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def api(self) -> 'openstack.Client':
|
def api(self) -> 'openstack.Client':
|
||||||
if not self._api:
|
if not self._api:
|
||||||
self._api = self.parent().api(
|
self._api = self.provider().api(
|
||||||
projectId=self.project.value, region=self.region.value
|
projectId=self.project.value, region=self.region.value
|
||||||
)
|
)
|
||||||
|
|
||||||
return self._api
|
return self._api
|
||||||
|
|
||||||
def sanitizeVmName(self, name: str) -> str:
|
def sanitizeVmName(self, name: str) -> str:
|
||||||
return self.parent().sanitizeVmName(name)
|
return self.provider().sanitizeVmName(name)
|
||||||
|
|
||||||
def makeTemplate(self, templateName: str, description: typing.Optional[str] = None):
|
def makeTemplate(self, templateName: str, description: typing.Optional[str] = None):
|
||||||
# First, ensures that volume has not any running instances
|
# First, ensures that volume has not any running instances
|
||||||
@ -443,4 +443,4 @@ class OpenStackLiveService(services.Service):
|
|||||||
return int(self.lenName.value)
|
return int(self.lenName.value)
|
||||||
|
|
||||||
def is_avaliable(self) -> bool:
|
def is_avaliable(self) -> bool:
|
||||||
return self.parent().is_available()
|
return self.provider().is_available()
|
||||||
|
@ -93,7 +93,7 @@ class IPMachineUserService(services.UserService, autoserializable.AutoSerializab
|
|||||||
res = dns.resolver.resolve(ip, 'AAAA')
|
res = dns.resolver.resolve(ip, 'AAAA')
|
||||||
ip = typing.cast(str, res[0].address) # type: ignore # If no address, it will raise an exception
|
ip = typing.cast(str, res[0].address) # type: ignore # If no address, it will raise an exception
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.service().parent().do_log(
|
self.service().provider().do_log(
|
||||||
log.LogLevel.WARNING, f'User service could not resolve Name {ip} ({e}).'
|
log.LogLevel.WARNING, f'User service could not resolve Name {ip} ({e}).'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,8 +48,8 @@ if typing.TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
class IPServiceBase(services.Service):
|
class IPServiceBase(services.Service):
|
||||||
def parent(self) -> 'provider.PhysicalMachinesProvider':
|
def provider(self) -> 'provider.PhysicalMachinesProvider':
|
||||||
return typing.cast('provider.PhysicalMachinesProvider', super().parent())
|
return typing.cast('provider.PhysicalMachinesProvider', super().provider())
|
||||||
|
|
||||||
def get_unassigned_host(self) -> typing.Optional['HostInfo']:
|
def get_unassigned_host(self) -> typing.Optional['HostInfo']:
|
||||||
raise NotImplementedError('getUnassignedMachine')
|
raise NotImplementedError('getUnassignedMachine')
|
||||||
@ -59,7 +59,7 @@ class IPServiceBase(services.Service):
|
|||||||
|
|
||||||
def wakeup(self, host: 'HostInfo', verify_ssl: bool = False) -> None:
|
def wakeup(self, host: 'HostInfo', verify_ssl: bool = False) -> None:
|
||||||
if host.mac:
|
if host.mac:
|
||||||
wake_on_land_endpoint = self.parent().wake_on_lan_endpoint(host)
|
wake_on_land_endpoint = self.provider().wake_on_lan_endpoint(host)
|
||||||
if wake_on_land_endpoint:
|
if wake_on_land_endpoint:
|
||||||
logger.info('Launching WOL: %s', wake_on_land_endpoint)
|
logger.info('Launching WOL: %s', wake_on_land_endpoint)
|
||||||
try:
|
try:
|
||||||
|
@ -281,14 +281,14 @@ class IPMachinesService(IPServiceBase):
|
|||||||
self.storage.put_pickle(host.host, now)
|
self.storage.put_pickle(host.host, now)
|
||||||
|
|
||||||
# Is WOL enabled?
|
# Is WOL enabled?
|
||||||
is_wakeonland_enabled = bool(self.parent().wake_on_lan_endpoint(host))
|
is_wakeonland_enabled = bool(self.provider().wake_on_lan_endpoint(host))
|
||||||
# Now, check if it is available on port, if required...
|
# Now, check if it is available on port, if required...
|
||||||
if (
|
if (
|
||||||
self.port.as_int() > 0 and not is_wakeonland_enabled
|
self.port.as_int() > 0 and not is_wakeonland_enabled
|
||||||
): # If configured WOL, check is a nonsense
|
): # If configured WOL, check is a nonsense
|
||||||
if net.test_connectivity(host.host, self.port.as_int(), timeout=0.5) is False:
|
if net.test_connectivity(host.host, self.port.as_int(), timeout=0.5) is False:
|
||||||
# Log into logs of provider, so it can be "shown" on services logs
|
# Log into logs of provider, so it can be "shown" on services logs
|
||||||
self.parent().do_log(
|
self.provider().do_log(
|
||||||
log.LogLevel.WARNING,
|
log.LogLevel.WARNING,
|
||||||
f'Host {host.host} not accesible on port {self.port.as_int()}',
|
f'Host {host.host} not accesible on port {self.port.as_int()}',
|
||||||
)
|
)
|
||||||
|
@ -313,7 +313,7 @@ if sys.platform == 'win32':
|
|||||||
self.do_log(log.LogLevel.ERROR, reason)
|
self.do_log(log.LogLevel.ERROR, reason)
|
||||||
|
|
||||||
if self._vmid != '': # Powers off
|
if self._vmid != '': # Powers off
|
||||||
ProxmoxDeferredRemoval.remove(self.service().parent(), int(self._vmid))
|
ProxmoxDeferredRemoval.remove(self.service().provider(), int(self._vmid))
|
||||||
|
|
||||||
self._queue = [Operation.ERROR]
|
self._queue = [Operation.ERROR]
|
||||||
self._reason = reason
|
self._reason = reason
|
||||||
|
@ -176,28 +176,28 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
|
|||||||
# Here we have to use "default values", cause values aren't used at form initialization
|
# Here we have to use "default values", cause values aren't used at form initialization
|
||||||
# This is that value is always '', so if we want to change something, we have to do it
|
# This is that value is always '', so if we want to change something, we have to do it
|
||||||
# at defValue
|
# at defValue
|
||||||
self.prov_uuid.value = self.parent().db_obj().uuid
|
self.prov_uuid.value = self.provider().db_obj().uuid
|
||||||
|
|
||||||
# This is not the same case, values is not the "value" of the field, but
|
# This is not the same case, values is not the "value" of the field, but
|
||||||
# the list of values shown because this is a "ChoiceField"
|
# the list of values shown because this is a "ChoiceField"
|
||||||
self.machine.set_choices(
|
self.machine.set_choices(
|
||||||
[
|
[
|
||||||
gui.choice_item(str(m.vmid), f'{m.node}\\{m.name or m.vmid} ({m.vmid})')
|
gui.choice_item(str(m.vmid), f'{m.node}\\{m.name or m.vmid} ({m.vmid})')
|
||||||
for m in self.parent().list_machines()
|
for m in self.provider().list_machines()
|
||||||
if m.name and m.name[:3] != 'UDS'
|
if m.name and m.name[:3] != 'UDS'
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
self.pool.set_choices(
|
self.pool.set_choices(
|
||||||
[gui.choice_item('', _('None'))]
|
[gui.choice_item('', _('None'))]
|
||||||
+ [gui.choice_item(p.poolid, p.poolid) for p in self.parent().list_pools()]
|
+ [gui.choice_item(p.poolid, p.poolid) for p in self.provider().list_pools()]
|
||||||
)
|
)
|
||||||
self.ha.set_choices(
|
self.ha.set_choices(
|
||||||
[gui.choice_item('', _('Enabled')), gui.choice_item('__', _('Disabled'))]
|
[gui.choice_item('', _('Enabled')), gui.choice_item('__', _('Disabled'))]
|
||||||
+ [gui.choice_item(group, group) for group in self.parent().list_ha_groups()]
|
+ [gui.choice_item(group, group) for group in self.provider().list_ha_groups()]
|
||||||
)
|
)
|
||||||
|
|
||||||
def parent(self) -> 'ProxmoxProvider':
|
def provider(self) -> 'ProxmoxProvider':
|
||||||
return typing.cast('ProxmoxProvider', super().parent())
|
return typing.cast('ProxmoxProvider', super().provider())
|
||||||
|
|
||||||
def sanitized_name(self, name: str) -> str:
|
def sanitized_name(self, name: str) -> str:
|
||||||
"""
|
"""
|
||||||
@ -206,13 +206,13 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
|
|||||||
return re.sub("[^a-zA-Z0-9_-]", "-", name)
|
return re.sub("[^a-zA-Z0-9_-]", "-", name)
|
||||||
|
|
||||||
def make_template(self, vmId: int) -> None:
|
def make_template(self, vmId: int) -> None:
|
||||||
self.parent().create_template(vmId)
|
self.provider().create_template(vmId)
|
||||||
|
|
||||||
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) -> 'client.types.VmCreationResult':
|
||||||
name = self.sanitized_name(name)
|
name = self.sanitized_name(name)
|
||||||
pool = self.pool.value or None
|
pool = self.pool.value or None
|
||||||
if vmId == -1: # vmId == -1 if cloning for template
|
if vmId == -1: # vmId == -1 if cloning for template
|
||||||
return self.parent().clone_machine(
|
return self.provider().clone_machine(
|
||||||
self.machine.value,
|
self.machine.value,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
@ -221,7 +221,7 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
|
|||||||
target_pool=pool,
|
target_pool=pool,
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.parent().clone_machine(
|
return self.provider().clone_machine(
|
||||||
vmId,
|
vmId,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
@ -232,29 +232,29 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_machine_info(self, vmId: int) -> 'client.types.VMInfo':
|
def get_machine_info(self, vmId: int) -> 'client.types.VMInfo':
|
||||||
return self.parent().get_machine_info(vmId, self.pool.value.strip())
|
return self.provider().get_machine_info(vmId, self.pool.value.strip())
|
||||||
|
|
||||||
def get_nic_mac(self, vmid: int) -> str:
|
def get_nic_mac(self, vmid: int) -> str:
|
||||||
config = self.parent().get_machine_configuration(vmid)
|
config = self.provider().get_machine_configuration(vmid)
|
||||||
return config.networks[0].mac.lower()
|
return config.networks[0].mac.lower()
|
||||||
|
|
||||||
def get_task_info(self, node: str, upid: str) -> 'client.types.TaskStatus':
|
def get_task_info(self, node: str, upid: str) -> 'client.types.TaskStatus':
|
||||||
return self.parent().get_task_info(node, upid)
|
return self.provider().get_task_info(node, upid)
|
||||||
|
|
||||||
def start_machine(self, vmId: int) -> 'client.types.UPID':
|
def start_machine(self, vmId: int) -> 'client.types.UPID':
|
||||||
return self.parent().start_machine(vmId)
|
return self.provider().start_machine(vmId)
|
||||||
|
|
||||||
def stop_machine(self, vmId: int) -> 'client.types.UPID':
|
def stop_machine(self, vmId: int) -> 'client.types.UPID':
|
||||||
return self.parent().stop_machine(vmId)
|
return self.provider().stop_machine(vmId)
|
||||||
|
|
||||||
def reset_machine(self, vmId: int) -> 'client.types.UPID':
|
def reset_machine(self, vmId: int) -> 'client.types.UPID':
|
||||||
return self.parent().reset_machine(vmId)
|
return self.provider().reset_machine(vmId)
|
||||||
|
|
||||||
def suspend_machine(self, vmId: int) -> 'client.types.UPID':
|
def suspend_machine(self, vmId: int) -> 'client.types.UPID':
|
||||||
return self.parent().suspend_machine(vmId)
|
return self.provider().suspend_machine(vmId)
|
||||||
|
|
||||||
def shutdown_machine(self, vmId: int) -> 'client.types.UPID':
|
def shutdown_machine(self, vmId: int) -> 'client.types.UPID':
|
||||||
return self.parent().shutdown_machine(vmId)
|
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
|
# First, remove from HA if needed
|
||||||
@ -265,23 +265,23 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
|
|||||||
self.do_log(level=log.LogLevel.WARNING, message=f'Exception disabling HA for vm {vmId}: {e}')
|
self.do_log(level=log.LogLevel.WARNING, message=f'Exception disabling HA for vm {vmId}: {e}')
|
||||||
|
|
||||||
# And remove it
|
# And remove it
|
||||||
return self.parent().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 == '__':
|
if self.ha.value == '__':
|
||||||
return
|
return
|
||||||
self.parent().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 == '__':
|
if self.ha.value == '__':
|
||||||
return
|
return
|
||||||
self.parent().disable_ha(vmId)
|
self.provider().disable_ha(vmId)
|
||||||
|
|
||||||
def set_protection(self, vmId: int, node: typing.Optional[str] = None, protection: bool = False) -> None:
|
def set_protection(self, vmId: int, node: typing.Optional[str] = None, protection: bool = False) -> None:
|
||||||
self.parent().set_protection(vmId, node, protection)
|
self.provider().set_protection(vmId, node, protection)
|
||||||
|
|
||||||
def set_machine_mac(self, vmId: int, mac: str) -> None:
|
def set_machine_mac(self, vmId: int, mac: str) -> None:
|
||||||
self.parent().set_machine_mac(vmId, mac)
|
self.provider().set_machine_mac(vmId, mac)
|
||||||
|
|
||||||
def get_basename(self) -> str:
|
def get_basename(self) -> str:
|
||||||
return self.basename.value
|
return self.basename.value
|
||||||
@ -293,7 +293,7 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
|
|||||||
"""
|
"""
|
||||||
Returns de selected mac range
|
Returns de selected mac range
|
||||||
"""
|
"""
|
||||||
return self.parent().get_macs_range()
|
return self.provider().get_macs_range()
|
||||||
|
|
||||||
def enable_ha_for_machines(self) -> bool:
|
def enable_ha_for_machines(self) -> bool:
|
||||||
return self.ha.value != '__'
|
return self.ha.value != '__'
|
||||||
@ -304,8 +304,8 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
|
|||||||
def get_console_connection(
|
def get_console_connection(
|
||||||
self, machineId: str
|
self, machineId: str
|
||||||
) -> typing.Optional[collections.abc.MutableMapping[str, typing.Any]]:
|
) -> typing.Optional[collections.abc.MutableMapping[str, typing.Any]]:
|
||||||
return self.parent().get_console_connection(machineId)
|
return self.provider().get_console_connection(machineId)
|
||||||
|
|
||||||
@cached('reachable', consts.cache.SHORT_CACHE_TIMEOUT)
|
@cached('reachable', consts.cache.SHORT_CACHE_TIMEOUT)
|
||||||
def is_avaliable(self) -> bool:
|
def is_avaliable(self) -> bool:
|
||||||
return self.parent().is_available()
|
return self.provider().is_available()
|
||||||
|
@ -120,43 +120,43 @@ class ProxmoxFixedService(FixedService): # pylint: disable=too-many-public-meth
|
|||||||
# This is that value is always '', so if we want to change something, we have to do it
|
# This is that value is always '', so if we want to change something, we have to do it
|
||||||
# at defValue
|
# at defValue
|
||||||
# Log with call stack
|
# Log with call stack
|
||||||
self.prov_uuid.value = self.parent().get_uuid()
|
self.prov_uuid.value = self.provider().get_uuid()
|
||||||
|
|
||||||
self.pool.set_choices(
|
self.pool.set_choices(
|
||||||
[gui.choice_item('', _('None'))]
|
[gui.choice_item('', _('None'))]
|
||||||
+ [gui.choice_item(p.poolid, p.poolid) for p in self.parent().list_pools()]
|
+ [gui.choice_item(p.poolid, p.poolid) for p in self.provider().list_pools()]
|
||||||
)
|
)
|
||||||
|
|
||||||
def parent(self) -> 'ProxmoxProvider':
|
def provider(self) -> 'ProxmoxProvider':
|
||||||
return typing.cast('ProxmoxProvider', super().parent())
|
return typing.cast('ProxmoxProvider', super().provider())
|
||||||
|
|
||||||
def get_machine_info(self, vmId: int) -> 'client.types.VMInfo':
|
def get_machine_info(self, vmId: int) -> 'client.types.VMInfo':
|
||||||
return self.parent().get_machine_info(vmId, self.pool.value.strip())
|
return self.provider().get_machine_info(vmId, self.pool.value.strip())
|
||||||
|
|
||||||
def get_task_info(self, node: str, upid: str) -> 'client.types.TaskStatus':
|
def get_task_info(self, node: str, upid: str) -> 'client.types.TaskStatus':
|
||||||
return self.parent().get_task_info(node, upid)
|
return self.provider().get_task_info(node, upid)
|
||||||
|
|
||||||
def start_machine(self, vmId: int) -> 'client.types.UPID':
|
def start_machine(self, vmId: int) -> 'client.types.UPID':
|
||||||
return self.parent().start_machine(vmId)
|
return self.provider().start_machine(vmId)
|
||||||
|
|
||||||
def stop_machine(self, vmId: int) -> 'client.types.UPID':
|
def stop_machine(self, vmId: int) -> 'client.types.UPID':
|
||||||
return self.parent().stop_machine(vmId)
|
return self.provider().stop_machine(vmId)
|
||||||
|
|
||||||
def reset_machine(self, vmId: int) -> 'client.types.UPID':
|
def reset_machine(self, vmId: int) -> 'client.types.UPID':
|
||||||
return self.parent().reset_machine(vmId)
|
return self.provider().reset_machine(vmId)
|
||||||
|
|
||||||
def shutdown_machine(self, vmId: int) -> 'client.types.UPID':
|
def shutdown_machine(self, vmId: int) -> 'client.types.UPID':
|
||||||
return self.parent().shutdown_machine(vmId)
|
return self.provider().shutdown_machine(vmId)
|
||||||
|
|
||||||
@cached('reachable', consts.cache.SHORT_CACHE_TIMEOUT)
|
@cached('reachable', consts.cache.SHORT_CACHE_TIMEOUT)
|
||||||
def is_avaliable(self) -> bool:
|
def is_avaliable(self) -> bool:
|
||||||
return self.parent().is_available()
|
return self.provider().is_available()
|
||||||
|
|
||||||
def enumerate_assignables(self) -> collections.abc.Iterable[types.ui.ChoiceItem]:
|
def enumerate_assignables(self) -> collections.abc.Iterable[types.ui.ChoiceItem]:
|
||||||
# Obtain machines names and ids for asignables
|
# Obtain machines names and ids for asignables
|
||||||
vms: dict[int, str] = {}
|
vms: dict[int, str] = {}
|
||||||
|
|
||||||
for member in self.parent().get_pool_info(self.pool.value.strip(), retrieve_vm_names=True).members:
|
for member in self.provider().get_pool_info(self.pool.value.strip(), retrieve_vm_names=True).members:
|
||||||
vms[member.vmid] = member.vmname
|
vms[member.vmid] = member.vmname
|
||||||
|
|
||||||
assigned_vms = self._get_assigned_machines()
|
assigned_vms = self._get_assigned_machines()
|
||||||
@ -181,10 +181,10 @@ class ProxmoxFixedService(FixedService): # pylint: disable=too-many-public-meth
|
|||||||
if remove:
|
if remove:
|
||||||
try:
|
try:
|
||||||
# try to revert to snapshot
|
# try to revert to snapshot
|
||||||
snapshot = self.parent().get_current_snapshot(vmid)
|
snapshot = self.provider().get_current_snapshot(vmid)
|
||||||
if snapshot:
|
if snapshot:
|
||||||
userservice_instance._store_task(
|
userservice_instance._store_task(
|
||||||
self.parent().restore_snapshot(vmid, name=snapshot.name)
|
self.provider().restore_snapshot(vmid, name=snapshot.name)
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.do_log(log.LogLevel.WARNING, 'Could not restore SNAPSHOT for this VM. ({})'.format(e))
|
self.do_log(log.LogLevel.WARNING, 'Could not restore SNAPSHOT for this VM. ({})'.format(e))
|
||||||
@ -194,9 +194,9 @@ class ProxmoxFixedService(FixedService): # pylint: disable=too-many-public-meth
|
|||||||
# If no snapshot exists for this vm, try to create one for it on background
|
# If no snapshot exists for this vm, try to create one for it on background
|
||||||
# Lauch an snapshot. We will not wait for it to finish, but instead let it run "as is"
|
# Lauch an snapshot. We will not wait for it to finish, but instead let it run "as is"
|
||||||
try:
|
try:
|
||||||
if not self.parent().get_current_snapshot(vmid):
|
if not self.provider().get_current_snapshot(vmid):
|
||||||
logger.debug('Not current snapshot')
|
logger.debug('Not current snapshot')
|
||||||
self.parent().create_snapshot(
|
self.provider().create_snapshot(
|
||||||
vmid,
|
vmid,
|
||||||
name='UDS Snapshot',
|
name='UDS Snapshot',
|
||||||
)
|
)
|
||||||
@ -212,11 +212,11 @@ class ProxmoxFixedService(FixedService): # pylint: disable=too-many-public-meth
|
|||||||
if found_vmid not in assigned_vms: # Not assigned
|
if found_vmid not in assigned_vms: # Not assigned
|
||||||
# Check that the machine exists...
|
# Check that the machine exists...
|
||||||
try:
|
try:
|
||||||
vm_info = self.parent().get_machine_info(checking_vmid, self.pool.value.strip())
|
vm_info = self.provider().get_machine_info(checking_vmid, self.pool.value.strip())
|
||||||
found_vmid = checking_vmid
|
found_vmid = checking_vmid
|
||||||
break
|
break
|
||||||
except Exception: # Notifies on log, but skipt it
|
except Exception: # Notifies on log, but skipt it
|
||||||
self.parent().do_log(
|
self.provider().do_log(
|
||||||
log.LogLevel.WARNING, 'Machine {} not accesible'.format(found_vmid)
|
log.LogLevel.WARNING, 'Machine {} not accesible'.format(found_vmid)
|
||||||
)
|
)
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@ -236,14 +236,14 @@ class ProxmoxFixedService(FixedService): # pylint: disable=too-many-public-meth
|
|||||||
return str(found_vmid)
|
return str(found_vmid)
|
||||||
|
|
||||||
def get_first_network_mac(self, vmid: str) -> str:
|
def get_first_network_mac(self, vmid: str) -> str:
|
||||||
config = self.parent().get_machine_configuration(int(vmid))
|
config = self.provider().get_machine_configuration(int(vmid))
|
||||||
return config.networks[0].mac.lower()
|
return config.networks[0].mac.lower()
|
||||||
|
|
||||||
def get_guest_ip_address(self, vmid: str) -> str:
|
def get_guest_ip_address(self, vmid: str) -> str:
|
||||||
return self.parent().get_guest_ip_address(int(vmid))
|
return self.provider().get_guest_ip_address(int(vmid))
|
||||||
|
|
||||||
def get_machine_name(self, vmid: str) -> str:
|
def get_machine_name(self, vmid: str) -> str:
|
||||||
return self.parent().get_machine_info(int(vmid)).name or ''
|
return self.provider().get_machine_info(int(vmid)).name or ''
|
||||||
|
|
||||||
def remove_and_free_machine(self, vmid: str) -> str:
|
def remove_and_free_machine(self, vmid: str) -> str:
|
||||||
try:
|
try:
|
||||||
|
@ -72,14 +72,14 @@ class TestServiceNoCache(services.Service):
|
|||||||
publication_type = None
|
publication_type = None
|
||||||
user_service_type = TestUserService
|
user_service_type = TestUserService
|
||||||
|
|
||||||
def parent(self) -> 'TestProvider':
|
def provider(self) -> 'TestProvider':
|
||||||
return typing.cast('TestProvider', super().parent())
|
return typing.cast('TestProvider', super().provider())
|
||||||
|
|
||||||
def get_name(self) -> str:
|
def get_name(self) -> str:
|
||||||
return self.parent().get_name() + '{' + self.type_name + '}'
|
return self.provider().get_name() + '{' + self.type_name + '}'
|
||||||
|
|
||||||
def get_basename(self) -> str:
|
def get_basename(self) -> str:
|
||||||
return self.parent().get_name()
|
return self.provider().get_name()
|
||||||
|
|
||||||
class TestServiceCache(services.Service):
|
class TestServiceCache(services.Service):
|
||||||
"""
|
"""
|
||||||
@ -108,11 +108,11 @@ class TestServiceCache(services.Service):
|
|||||||
# : Types of deploys (services in cache and/or assigned to users)
|
# : Types of deploys (services in cache and/or assigned to users)
|
||||||
user_service_type = TestUserService
|
user_service_type = TestUserService
|
||||||
|
|
||||||
def parent(self) -> 'TestProvider':
|
def provider(self) -> 'TestProvider':
|
||||||
return typing.cast('TestProvider', super().parent())
|
return typing.cast('TestProvider', super().provider())
|
||||||
|
|
||||||
def get_name(self) -> str:
|
def get_name(self) -> str:
|
||||||
return self.parent().get_name() + '{' + self.type_name + '}'
|
return self.provider().get_name() + '{' + self.type_name + '}'
|
||||||
|
|
||||||
def get_basename(self) -> str:
|
def get_basename(self) -> str:
|
||||||
return self.parent().get_name()
|
return self.provider().get_name()
|
||||||
|
@ -175,18 +175,18 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
if int(self.memory.value) < 256:
|
if int(self.memory.value) < 256:
|
||||||
raise exceptions.ui.ValidationError(_('The minimum allowed memory is 256 Mb'))
|
raise exceptions.ui.ValidationError(_('The minimum allowed memory is 256 Mb'))
|
||||||
|
|
||||||
def parent(self) -> 'XenProvider':
|
def provider(self) -> 'XenProvider':
|
||||||
return typing.cast('XenProvider', super().parent())
|
return typing.cast('XenProvider', super().provider())
|
||||||
|
|
||||||
def init_gui(self) -> None:
|
def init_gui(self) -> None:
|
||||||
# Here we have to use "default values", cause values aren't used at form initialization
|
# Here we have to use "default values", cause values aren't used at form initialization
|
||||||
# This is that value is always '', so if we want to change something, we have to do it
|
# This is that value is always '', so if we want to change something, we have to do it
|
||||||
# at defValue
|
# at defValue
|
||||||
|
|
||||||
machines_list = [gui.choice_item(m['id'], m['name']) for m in self.parent().list_machines()]
|
machines_list = [gui.choice_item(m['id'], m['name']) for m in self.provider().list_machines()]
|
||||||
|
|
||||||
storages_list = []
|
storages_list = []
|
||||||
for storage in self.parent().list_storages():
|
for storage in self.provider().list_storages():
|
||||||
space, free = (
|
space, free = (
|
||||||
storage['size'] / 1024,
|
storage['size'] / 1024,
|
||||||
(storage['size'] - storage['used']) / 1024,
|
(storage['size'] - storage['used']) / 1024,
|
||||||
@ -198,18 +198,18 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
network_list = [gui.choice_item(net['id'], net['name']) for net in self.parent().get_networks()]
|
network_list = [gui.choice_item(net['id'], net['name']) for net in self.provider().get_networks()]
|
||||||
|
|
||||||
self.machine.set_choices(machines_list)
|
self.machine.set_choices(machines_list)
|
||||||
self.datastore.set_choices(storages_list)
|
self.datastore.set_choices(storages_list)
|
||||||
self.network.set_choices(network_list)
|
self.network.set_choices(network_list)
|
||||||
|
|
||||||
def check_task_finished(self, task: str) -> tuple[bool, str]:
|
def check_task_finished(self, task: str) -> tuple[bool, str]:
|
||||||
return self.parent().check_task_finished(task)
|
return self.provider().check_task_finished(task)
|
||||||
|
|
||||||
def has_datastore_space(self) -> None:
|
def has_datastore_space(self) -> None:
|
||||||
# Get storages for that datacenter
|
# Get storages for that datacenter
|
||||||
info = self.parent().get_storage_info(self.datastore.value)
|
info = self.provider().get_storage_info(self.datastore.value)
|
||||||
logger.debug('Checking datastore space for %s: %s', self.datastore.value, info)
|
logger.debug('Checking datastore space for %s: %s', self.datastore.value, info)
|
||||||
availableGB = (info['size'] - info['used']) / 1024
|
availableGB = (info['size'] - info['used']) / 1024
|
||||||
if availableGB < self.min_space_gb.as_int():
|
if availableGB < self.min_space_gb.as_int():
|
||||||
@ -248,13 +248,13 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
# Checks datastore available space, raises exeception in no min available
|
# Checks datastore available space, raises exeception in no min available
|
||||||
self.has_datastore_space()
|
self.has_datastore_space()
|
||||||
|
|
||||||
return self.parent().clone_for_template(name, comments, self.machine.value, self.datastore.value)
|
return self.provider().clone_for_template(name, comments, self.machine.value, self.datastore.value)
|
||||||
|
|
||||||
def convert_to_template(self, machineId: str) -> None:
|
def convert_to_template(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
converts machine to template
|
converts machine to template
|
||||||
"""
|
"""
|
||||||
self.parent().convert_to_template(machineId, self.shadow.value)
|
self.provider().convert_to_template(machineId, self.shadow.value)
|
||||||
|
|
||||||
def start_deploy_from_template(self, name: str, comments: str, templateId: str) -> str:
|
def start_deploy_from_template(self, name: str, comments: str, templateId: str) -> str:
|
||||||
"""
|
"""
|
||||||
@ -274,13 +274,13 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
logger.debug('Deploying from template %s machine %s', templateId, name)
|
logger.debug('Deploying from template %s machine %s', templateId, name)
|
||||||
self.has_datastore_space()
|
self.has_datastore_space()
|
||||||
|
|
||||||
return self.parent().start_deploy_from_template(name, comments, templateId)
|
return self.provider().start_deploy_from_template(name, comments, templateId)
|
||||||
|
|
||||||
def remove_template(self, templateId: str) -> None:
|
def remove_template(self, templateId: str) -> None:
|
||||||
"""
|
"""
|
||||||
invokes removeTemplate from parent provider
|
invokes removeTemplate from parent provider
|
||||||
"""
|
"""
|
||||||
self.parent().remove_template(templateId)
|
self.provider().remove_template(templateId)
|
||||||
|
|
||||||
def get_machine_power_state(self, machineId: str) -> str:
|
def get_machine_power_state(self, machineId: str) -> str:
|
||||||
"""
|
"""
|
||||||
@ -292,7 +292,7 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
Returns:
|
Returns:
|
||||||
one of this values:
|
one of this values:
|
||||||
"""
|
"""
|
||||||
return self.parent().get_machine_power_state(machineId)
|
return self.provider().get_machine_power_state(machineId)
|
||||||
|
|
||||||
def start_machine(self, machineId: str, asnc: bool = True) -> typing.Optional[str]:
|
def start_machine(self, machineId: str, asnc: bool = True) -> typing.Optional[str]:
|
||||||
"""
|
"""
|
||||||
@ -305,7 +305,7 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
return self.parent().start_machine(machineId, asnc)
|
return self.provider().start_machine(machineId, asnc)
|
||||||
|
|
||||||
def stop_machine(self, machineId: str, asnc: bool = True) -> typing.Optional[str]:
|
def stop_machine(self, machineId: str, asnc: bool = True) -> typing.Optional[str]:
|
||||||
"""
|
"""
|
||||||
@ -316,7 +316,7 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
return self.parent().stop_machine(machineId, asnc)
|
return self.provider().stop_machine(machineId, asnc)
|
||||||
|
|
||||||
def reset_machine(self, machine_id: str, asnc: bool = True) -> typing.Optional[str]:
|
def reset_machine(self, machine_id: str, asnc: bool = True) -> typing.Optional[str]:
|
||||||
"""
|
"""
|
||||||
@ -327,7 +327,7 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
return self.parent().reset_machine(machine_id, asnc)
|
return self.provider().reset_machine(machine_id, asnc)
|
||||||
|
|
||||||
def can_suspend_machine(self, machineId: str) -> bool:
|
def can_suspend_machine(self, machineId: str) -> bool:
|
||||||
"""
|
"""
|
||||||
@ -339,7 +339,7 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
Returns:
|
Returns:
|
||||||
True if the machien can be suspended
|
True if the machien can be suspended
|
||||||
"""
|
"""
|
||||||
return self.parent().can_suspend_machine(machineId)
|
return self.provider().can_suspend_machine(machineId)
|
||||||
|
|
||||||
def suspend_machine(self, machineId: str, asnc: bool = True) -> typing.Optional[str]:
|
def suspend_machine(self, machineId: str, asnc: bool = True) -> typing.Optional[str]:
|
||||||
"""
|
"""
|
||||||
@ -350,7 +350,7 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
return self.parent().suspend_machine(machineId, asnc)
|
return self.provider().suspend_machine(machineId, asnc)
|
||||||
|
|
||||||
def resume_machine(self, machineId: str, asnc: bool = True) -> typing.Optional[str]:
|
def resume_machine(self, machineId: str, asnc: bool = True) -> typing.Optional[str]:
|
||||||
"""
|
"""
|
||||||
@ -361,7 +361,7 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
return self.parent().suspend_machine(machineId, asnc)
|
return self.provider().suspend_machine(machineId, asnc)
|
||||||
|
|
||||||
def remove_machine(self, machineId: str) -> None:
|
def remove_machine(self, machineId: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -372,19 +372,19 @@ class XenLinkedService(services.Service): # pylint: disable=too-many-public-met
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
self.parent().remove_machine(machineId)
|
self.provider().remove_machine(machineId)
|
||||||
|
|
||||||
def configure_machine(self, machine_id: str, mac: str) -> None:
|
def configure_machine(self, machine_id: str, mac: str) -> None:
|
||||||
self.parent().configure_machine(machine_id, self.network.value, mac, self.memory.value)
|
self.provider().configure_machine(machine_id, self.network.value, mac, self.memory.value)
|
||||||
|
|
||||||
def provision_machine(self, machine_id: str, as_async: bool = True) -> str:
|
def provision_machine(self, machine_id: str, as_async: bool = True) -> str:
|
||||||
return self.parent().provision_machine(machine_id, as_async)
|
return self.provider().provision_machine(machine_id, as_async)
|
||||||
|
|
||||||
def get_macs_range(self) -> str:
|
def get_macs_range(self) -> str:
|
||||||
"""
|
"""
|
||||||
Returns de selected mac range
|
Returns de selected mac range
|
||||||
"""
|
"""
|
||||||
return self.parent().get_macs_range()
|
return self.provider().get_macs_range()
|
||||||
|
|
||||||
def get_basename(self) -> str:
|
def get_basename(self) -> str:
|
||||||
"""
|
"""
|
||||||
|
@ -116,12 +116,12 @@ class XenFixedService(FixedService): # pylint: disable=too-many-public-methods
|
|||||||
# Here we have to use "default values", cause values aren't used at form initialization
|
# Here we have to use "default values", cause values aren't used at form initialization
|
||||||
# This is that value is always '', so if we want to change something, we have to do it
|
# This is that value is always '', so if we want to change something, we have to do it
|
||||||
# at defValue
|
# at defValue
|
||||||
self.prov_uuid.value = self.parent().get_uuid()
|
self.prov_uuid.value = self.provider().get_uuid()
|
||||||
|
|
||||||
self.folder.set_choices([gui.choice_item(folder, folder) for folder in self.parent().list_folders()])
|
self.folder.set_choices([gui.choice_item(folder, folder) for folder in self.provider().list_folders()])
|
||||||
|
|
||||||
def parent(self) -> 'XenProvider':
|
def provider(self) -> 'XenProvider':
|
||||||
return typing.cast('XenProvider', super().parent())
|
return typing.cast('XenProvider', super().provider())
|
||||||
|
|
||||||
def get_machine_power_state(self, machine_id: str) -> str:
|
def get_machine_power_state(self, machine_id: str) -> str:
|
||||||
"""
|
"""
|
||||||
@ -133,7 +133,7 @@ class XenFixedService(FixedService): # pylint: disable=too-many-public-methods
|
|||||||
Returns:
|
Returns:
|
||||||
one of this values:
|
one of this values:
|
||||||
"""
|
"""
|
||||||
return self.parent().get_machine_power_state(machine_id)
|
return self.provider().get_machine_power_state(machine_id)
|
||||||
|
|
||||||
def start_machine(self, machine_id: str) -> typing.Optional[str]:
|
def start_machine(self, machine_id: str) -> typing.Optional[str]:
|
||||||
"""
|
"""
|
||||||
@ -146,7 +146,7 @@ class XenFixedService(FixedService): # pylint: disable=too-many-public-methods
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
return self.parent().start_machine(machine_id)
|
return self.provider().start_machine(machine_id)
|
||||||
|
|
||||||
def stop_machine(self, machine_id: str) -> typing.Optional[str]:
|
def stop_machine(self, machine_id: str) -> typing.Optional[str]:
|
||||||
"""
|
"""
|
||||||
@ -157,7 +157,7 @@ class XenFixedService(FixedService): # pylint: disable=too-many-public-methods
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
return self.parent().stop_machine(machine_id)
|
return self.provider().stop_machine(machine_id)
|
||||||
|
|
||||||
def reset_machine(self, machine_id: str) -> typing.Optional[str]:
|
def reset_machine(self, machine_id: str) -> typing.Optional[str]:
|
||||||
"""
|
"""
|
||||||
@ -168,17 +168,17 @@ class XenFixedService(FixedService): # pylint: disable=too-many-public-methods
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
"""
|
"""
|
||||||
return self.parent().reset_machine(machine_id)
|
return self.provider().reset_machine(machine_id)
|
||||||
|
|
||||||
def shutdown_machine(self, machine_id: str) -> typing.Optional[str]:
|
def shutdown_machine(self, machine_id: str) -> typing.Optional[str]:
|
||||||
return self.parent().shutdown_machine(machine_id)
|
return self.provider().shutdown_machine(machine_id)
|
||||||
|
|
||||||
def check_task_finished(self, task: str) -> tuple[bool, str]:
|
def check_task_finished(self, task: str) -> tuple[bool, str]:
|
||||||
return self.parent().check_task_finished(task)
|
return self.provider().check_task_finished(task)
|
||||||
|
|
||||||
@cached('reachable', consts.cache.SHORT_CACHE_TIMEOUT)
|
@cached('reachable', consts.cache.SHORT_CACHE_TIMEOUT)
|
||||||
def is_avaliable(self) -> bool:
|
def is_avaliable(self) -> bool:
|
||||||
return self.parent().is_available()
|
return self.provider().is_available()
|
||||||
|
|
||||||
def enumerate_assignables(self) -> collections.abc.Iterable[types.ui.ChoiceItem]:
|
def enumerate_assignables(self) -> collections.abc.Iterable[types.ui.ChoiceItem]:
|
||||||
# Obtain machines names and ids for asignables
|
# Obtain machines names and ids for asignables
|
||||||
@ -204,12 +204,12 @@ class XenFixedService(FixedService): # pylint: disable=too-many-public-methods
|
|||||||
if self.use_snapshots.as_bool():
|
if self.use_snapshots.as_bool():
|
||||||
vmid = userservice_instance._vmid
|
vmid = userservice_instance._vmid
|
||||||
|
|
||||||
snapshots = [i['id'] for i in self.parent().list_snapshots(vmid)]
|
snapshots = [i['id'] for i in self.provider().list_snapshots(vmid)]
|
||||||
snapshot = snapshots[0] if snapshots else None
|
snapshot = snapshots[0] if snapshots else None
|
||||||
|
|
||||||
if remove and snapshot:
|
if remove and snapshot:
|
||||||
try:
|
try:
|
||||||
userservice_instance._task = self.parent().restore_snapshot(snapshot['id'])
|
userservice_instance._task = self.provider().restore_snapshot(snapshot['id'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.do_log(log.LogLevel.WARNING, 'Could not restore SNAPSHOT for this VM. ({})'.format(e))
|
self.do_log(log.LogLevel.WARNING, 'Could not restore SNAPSHOT for this VM. ({})'.format(e))
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ class XenFixedService(FixedService): # pylint: disable=too-many-public-methods
|
|||||||
if not snapshot: # No snapshot, try to create one
|
if not snapshot: # No snapshot, try to create one
|
||||||
logger.debug('Not current snapshot')
|
logger.debug('Not current snapshot')
|
||||||
# We don't need the snapshot nor the task, will simply restore to newer snapshot on remove
|
# We don't need the snapshot nor the task, will simply restore to newer snapshot on remove
|
||||||
self.parent().create_snapshot(
|
self.provider().create_snapshot(
|
||||||
vmid,
|
vmid,
|
||||||
name='UDS Snapshot',
|
name='UDS Snapshot',
|
||||||
)
|
)
|
||||||
@ -237,11 +237,11 @@ class XenFixedService(FixedService): # pylint: disable=too-many-public-methods
|
|||||||
if found_vmid not in assigned_vms: # Not assigned
|
if found_vmid not in assigned_vms: # Not assigned
|
||||||
# Check that the machine exists...
|
# Check that the machine exists...
|
||||||
try:
|
try:
|
||||||
vm_name = self.parent().get_machine_name(checking_vmid)
|
vm_name = self.provider().get_machine_name(checking_vmid)
|
||||||
found_vmid = checking_vmid
|
found_vmid = checking_vmid
|
||||||
break
|
break
|
||||||
except Exception: # Notifies on log, but skipt it
|
except Exception: # Notifies on log, but skipt it
|
||||||
self.parent().do_log(
|
self.provider().do_log(
|
||||||
log.LogLevel.WARNING, 'Machine {} not accesible'.format(found_vmid)
|
log.LogLevel.WARNING, 'Machine {} not accesible'.format(found_vmid)
|
||||||
)
|
)
|
||||||
logger.warning(
|
logger.warning(
|
||||||
@ -261,13 +261,13 @@ class XenFixedService(FixedService): # pylint: disable=too-many-public-methods
|
|||||||
return str(found_vmid)
|
return str(found_vmid)
|
||||||
|
|
||||||
def get_first_network_mac(self, vmid: str) -> str:
|
def get_first_network_mac(self, vmid: str) -> str:
|
||||||
return self.parent().get_first_mac(vmid)
|
return self.provider().get_first_mac(vmid)
|
||||||
|
|
||||||
def get_guest_ip_address(self, vmid: str) -> str:
|
def get_guest_ip_address(self, vmid: str) -> str:
|
||||||
return self.parent().get_first_ip(vmid)
|
return self.provider().get_first_ip(vmid)
|
||||||
|
|
||||||
def get_machine_name(self, vmid: str) -> str:
|
def get_machine_name(self, vmid: str) -> str:
|
||||||
return self.parent().get_machine_name(vmid)
|
return self.provider().get_machine_name(vmid)
|
||||||
|
|
||||||
def remove_and_free_machine(self, vmid: str) -> str:
|
def remove_and_free_machine(self, vmid: str) -> str:
|
||||||
try:
|
try:
|
||||||
|
@ -167,7 +167,7 @@ class FixedServiceTest(UDSTestCase):
|
|||||||
) -> tuple['FixedTestingProvider', 'FixedTestingService', 'FixedTestingUserService']:
|
) -> tuple['FixedTestingProvider', 'FixedTestingService', 'FixedTestingUserService']:
|
||||||
environment = self.create_environment()
|
environment = self.create_environment()
|
||||||
prov = FixedTestingProvider(environment=environment)
|
prov = FixedTestingProvider(environment=environment)
|
||||||
service = FixedTestingService(environment=environment, parent=prov)
|
service = FixedTestingService(environment=environment, provider=prov)
|
||||||
user_service = FixedTestingUserService(environment=environment, service=service)
|
user_service = FixedTestingUserService(environment=environment, service=service)
|
||||||
|
|
||||||
return prov, service, user_service
|
return prov, service, user_service
|
||||||
|
@ -129,7 +129,7 @@ class PhysicalMachinesMultiSerializationTest(UDSTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
instance = service_multi.IPMachinesService(
|
instance = service_multi.IPMachinesService(
|
||||||
environment=self.environment, parent=uninitialized_provider
|
environment=self.environment, provider=uninitialized_provider
|
||||||
)
|
)
|
||||||
instance.unmarshal(SERIALIZED_DATA[version])
|
instance.unmarshal(SERIALIZED_DATA[version])
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ class PhysicalMachinesMultiSerializationTest(UDSTestCase):
|
|||||||
# Unmarshall last version, remarshall and check that is marshalled using new marshalling format
|
# Unmarshall last version, remarshall and check that is marshalled using new marshalling format
|
||||||
version = f'v{len(SERIALIZED_DATA)}'
|
version = f'v{len(SERIALIZED_DATA)}'
|
||||||
uninitialized_provider = provider.PhysicalMachinesProvider(environment=self.environment)
|
uninitialized_provider = provider.PhysicalMachinesProvider(environment=self.environment)
|
||||||
instance = service_multi.IPMachinesService(environment=self.environment, parent=uninitialized_provider)
|
instance = service_multi.IPMachinesService(environment=self.environment, provider=uninitialized_provider)
|
||||||
instance.unmarshal(SERIALIZED_DATA[version])
|
instance.unmarshal(SERIALIZED_DATA[version])
|
||||||
marshalled_data = instance.marshal()
|
marshalled_data = instance.marshal()
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ class PhysicalMachinesMultiSerializationTest(UDSTestCase):
|
|||||||
# Ensure fields has been marshalled using new format
|
# Ensure fields has been marshalled using new format
|
||||||
self.assertFalse(marshalled_data.startswith(b'v'))
|
self.assertFalse(marshalled_data.startswith(b'v'))
|
||||||
# Reunmarshall again and check that remarshalled flag is not set
|
# Reunmarshall again and check that remarshalled flag is not set
|
||||||
instance = service_multi.IPMachinesService(environment=self.environment, parent=uninitialized_provider)
|
instance = service_multi.IPMachinesService(environment=self.environment, provider=uninitialized_provider)
|
||||||
instance.unmarshal(marshalled_data)
|
instance.unmarshal(marshalled_data)
|
||||||
self.assertFalse(instance.needs_upgrade())
|
self.assertFalse(instance.needs_upgrade())
|
||||||
|
|
||||||
|
@ -34,13 +34,15 @@ import pickle
|
|||||||
import typing
|
import typing
|
||||||
|
|
||||||
# We use storage, so we need transactional tests
|
# We use storage, so we need transactional tests
|
||||||
from tests.utils.test import UDSTransactionTestCase
|
from ...utils.test import UDSTransactionTestCase
|
||||||
|
from ...utils import fake
|
||||||
|
|
||||||
from uds.core.services import service
|
from uds.core.services import service
|
||||||
from uds.core.environment import Environment
|
from uds.core.environment import Environment
|
||||||
|
|
||||||
|
|
||||||
from uds.services.Proxmox.deployment import Operation as Operation, ProxmoxDeployment as Deployment
|
from uds.services.Proxmox.deployment import Operation as Operation, ProxmoxDeployment as Deployment
|
||||||
|
|
||||||
|
|
||||||
# if not data.startswith(b'v'):
|
# if not data.startswith(b'v'):
|
||||||
# return super().unmarshal(data)
|
# return super().unmarshal(data)
|
||||||
|
|
||||||
@ -94,7 +96,7 @@ class ProxmoxDeploymentSerializationTest(UDSTransactionTestCase):
|
|||||||
environment = Environment.testing_environment()
|
environment = Environment.testing_environment()
|
||||||
|
|
||||||
def _create_instance(unmarshal_data: 'bytes|None' = None) -> Deployment:
|
def _create_instance(unmarshal_data: 'bytes|None' = None) -> Deployment:
|
||||||
instance = Deployment(environment=environment, service=service.Service(Environment.testing_environment(), )
|
instance = Deployment(environment=environment, service=fake.fake_service())
|
||||||
if unmarshal_data:
|
if unmarshal_data:
|
||||||
instance.unmarshal(unmarshal_data)
|
instance.unmarshal(unmarshal_data)
|
||||||
return instance
|
return instance
|
||||||
@ -125,7 +127,7 @@ class ProxmoxDeploymentSerializationTest(UDSTransactionTestCase):
|
|||||||
environment.storage.put_pickle('queue', TEST_QUEUE)
|
environment.storage.put_pickle('queue', TEST_QUEUE)
|
||||||
|
|
||||||
def _create_instance(unmarshal_data: 'bytes|None' = None) -> Deployment:
|
def _create_instance(unmarshal_data: 'bytes|None' = None) -> Deployment:
|
||||||
instance = Deployment(environment=environment, service=None)
|
instance = Deployment(environment=environment, service=fake.fake_service())
|
||||||
if unmarshal_data:
|
if unmarshal_data:
|
||||||
instance.unmarshal(unmarshal_data)
|
instance.unmarshal(unmarshal_data)
|
||||||
return instance
|
return instance
|
||||||
@ -169,6 +171,6 @@ class ProxmoxDeploymentSerializationTest(UDSTransactionTestCase):
|
|||||||
# This test is designed to ensure that all fields are autoserializable
|
# This test is designed to ensure that all fields are autoserializable
|
||||||
# If some field is added or removed, this tests will warn us about it to fix the rest of the related tests
|
# If some field is added or removed, this tests will warn us about it to fix the rest of the related tests
|
||||||
with Environment.temporary_environment() as env:
|
with Environment.temporary_environment() as env:
|
||||||
instance = Deployment(environment=env, service=None)
|
instance = Deployment(environment=env, service=fake.fake_service())
|
||||||
|
|
||||||
self.assertSetEqual(set(f[0] for f in instance._autoserializable_fields()), EXPECTED_FIELDS)
|
self.assertSetEqual(set(f[0] for f in instance._autoserializable_fields()), EXPECTED_FIELDS)
|
||||||
|
@ -48,6 +48,6 @@ def fake_service() -> services.Service:
|
|||||||
uuid_ = str(uuid.uuid4())
|
uuid_ = str(uuid.uuid4())
|
||||||
return services.Service(
|
return services.Service(
|
||||||
environment=environment.Environment.private_environment(uuid_),
|
environment=environment.Environment.private_environment(uuid_),
|
||||||
parent=fake_service_provider(),
|
provider=fake_service_provider(),
|
||||||
uuid=uuid_,
|
uuid=uuid_,
|
||||||
)
|
)
|
Loading…
Reference in New Issue
Block a user