mirror of
https://github.com/dkmstr/openuds.git
synced 2025-03-11 00:58:39 +03:00
Refactor Proxmox service classes
This commit is contained in:
parent
4b85424f56
commit
6fca6c2d0a
@ -93,9 +93,8 @@ class ServiceProvider(module.Module):
|
||||
type_name = 'Base Provider'
|
||||
|
||||
# : Name of type used by Managers to identify this tipe of service
|
||||
# : We could have used here the Class name, but we decided that the
|
||||
# : module implementator will be the one that will provide a name that
|
||||
# : will relation the class (type) and that name.
|
||||
# : Must not be modified once assigned, because it's stored at database, and any saved
|
||||
# : data will not be able to be unmarshalled if this is changed.
|
||||
type_type = 'BaseServiceProvider'
|
||||
|
||||
# : Description shown at administration level for this provider.
|
||||
|
@ -102,9 +102,8 @@ class Service(Module):
|
||||
type_name = _('Base Service')
|
||||
|
||||
# : Name of type used by Managers to identify this type of service
|
||||
# : We could have used here the Class name, but we decided that the
|
||||
# : module implementator will be the one that will provide a name that
|
||||
# : will relation the class (type) and that name.
|
||||
# : Must not be modified once assigned, because it's stored at database, and any saved
|
||||
# : data will not be able to be unmarshalled if this is changed.
|
||||
type_type = 'BaseService'
|
||||
|
||||
# : Description shown at administration level for this service.
|
||||
|
@ -49,7 +49,7 @@ from . import client
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from uds import models
|
||||
from .service import ProxmoxLinkedService
|
||||
from .service import ProxmoxServiceLinked
|
||||
from .publication import ProxmoxPublication
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -91,7 +91,7 @@ class Operation(enum.IntEnum):
|
||||
# UP_STATES = ('up', 'reboot_in_progress', 'powering_up', 'restoring_state')
|
||||
|
||||
|
||||
class ProxmoxDeployment(services.UserService, autoserializable.AutoSerializable):
|
||||
class ProxmoxUserserviceLinked(services.UserService, autoserializable.AutoSerializable):
|
||||
"""
|
||||
This class generates the user consumable elements of the service tree.
|
||||
|
||||
@ -124,8 +124,8 @@ class ProxmoxDeployment(services.UserService, autoserializable.AutoSerializable)
|
||||
# _queue: list[int]
|
||||
|
||||
# Utility overrides for type checking...
|
||||
def service(self) -> 'ProxmoxLinkedService':
|
||||
return typing.cast('ProxmoxLinkedService', super().service())
|
||||
def service(self) -> 'ProxmoxServiceLinked':
|
||||
return typing.cast('ProxmoxServiceLinked', super().service())
|
||||
|
||||
def publication(self) -> 'ProxmoxPublication':
|
||||
pub = super().publication()
|
||||
@ -709,5 +709,5 @@ if sys.platform == 'win32':
|
||||
self._ip,
|
||||
self._mac,
|
||||
self._vmid,
|
||||
[ProxmoxDeployment._op2str(op) for op in self._queue],
|
||||
[ProxmoxUserserviceLinked._op2str(op) for op in self._queue],
|
||||
)
|
||||
|
@ -75,8 +75,8 @@ class ProxmoxFixedUserService(FixedUserService, autoserializable.AutoSerializabl
|
||||
return (vals[0], vals[1])
|
||||
|
||||
# Utility overrides for type checking...
|
||||
def service(self) -> 'service_fixed.ProxmoxFixedService':
|
||||
return typing.cast('service_fixed.ProxmoxFixedService', super().service())
|
||||
def service(self) -> 'service_fixed.ProxmoxServiceFixed':
|
||||
return typing.cast('service_fixed.ProxmoxServiceFixed', super().service())
|
||||
|
||||
def set_ready(self) -> str:
|
||||
if self.cache.get('ready') == '1':
|
||||
|
@ -41,8 +41,8 @@ from uds.core.util.unique_id_generator import UniqueIDGenerator
|
||||
from uds.core.util.unique_mac_generator import UniqueMacGenerator
|
||||
|
||||
from . import client
|
||||
from .service import ProxmoxLinkedService
|
||||
from .service_fixed import ProxmoxFixedService
|
||||
from .service import ProxmoxServiceLinked
|
||||
from .service_fixed import ProxmoxServiceFixed
|
||||
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
@ -67,7 +67,7 @@ class ProxmoxProvider(services.ServiceProvider):
|
||||
type_description = _('Proxmox platform service provider')
|
||||
icon_file = 'provider.png'
|
||||
|
||||
offers = [ProxmoxLinkedService, ProxmoxFixedService]
|
||||
offers = [ProxmoxServiceLinked, ProxmoxServiceFixed]
|
||||
|
||||
host = gui.TextField(
|
||||
length=64,
|
||||
|
@ -41,7 +41,7 @@ from uds.core.types.states import State
|
||||
|
||||
# Not imported at runtime, just for type checking
|
||||
if typing.TYPE_CHECKING:
|
||||
from .service import ProxmoxLinkedService
|
||||
from .service import ProxmoxServiceLinked
|
||||
from . import client
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -59,8 +59,8 @@ class ProxmoxPublication(services.Publication, autoserializable.AutoSerializable
|
||||
_reason = autoserializable.StringField(default='')
|
||||
|
||||
# Utility overrides for type checking...
|
||||
def service(self) -> 'ProxmoxLinkedService':
|
||||
return typing.cast('ProxmoxLinkedService', super().service())
|
||||
def service(self) -> 'ProxmoxServiceLinked':
|
||||
return typing.cast('ProxmoxServiceLinked', super().service())
|
||||
|
||||
def unmarshal(self, data: bytes) -> None:
|
||||
"""
|
||||
|
@ -40,7 +40,7 @@ from uds.core.util import validators, log, fields
|
||||
from uds.core.util.decorators import cached
|
||||
|
||||
from . import helpers
|
||||
from .deployment import ProxmoxDeployment
|
||||
from .deployment import ProxmoxUserserviceLinked
|
||||
from .publication import ProxmoxPublication
|
||||
|
||||
# Not imported at runtime, just for type checking
|
||||
@ -53,7 +53,7 @@ if typing.TYPE_CHECKING:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public-methods
|
||||
class ProxmoxServiceLinked(services.Service): # pylint: disable=too-many-public-methods
|
||||
"""
|
||||
Proxmox Linked clones service. This is based on creating a template from selected vm, and then use it to
|
||||
"""
|
||||
@ -62,7 +62,7 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
|
||||
# : sending it to administration interface, so don't forget to
|
||||
# : mark it as _ (using gettext_noop)
|
||||
type_name = _('Proxmox Linked Clone')
|
||||
# : Type used internally to identify this provider
|
||||
# : Type used internally to identify this provider, must not be modified once created
|
||||
type_type = 'ProxmoxLinkedService'
|
||||
# : Description shown at administration interface for this provider
|
||||
type_description = _('Proxmox Services based on templates and COW')
|
||||
@ -99,7 +99,7 @@ class ProxmoxLinkedService(services.Service): # pylint: disable=too-many-public
|
||||
# : In our case, we do no need a publication, so this is None
|
||||
publication_type = ProxmoxPublication
|
||||
# : Types of deploys (services in cache and/or assigned to users)
|
||||
user_service_type = ProxmoxDeployment
|
||||
user_service_type = ProxmoxUserserviceLinked
|
||||
|
||||
allowed_protocols = types.transports.Protocol.generic_vdi(types.transports.Protocol.SPICE)
|
||||
services_type_provided = types.services.ServiceType.VDI
|
||||
|
@ -56,7 +56,7 @@ if typing.TYPE_CHECKING:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProxmoxFixedService(FixedService): # pylint: disable=too-many-public-methods
|
||||
class ProxmoxServiceFixed(FixedService): # pylint: disable=too-many-public-methods
|
||||
"""
|
||||
Proxmox fixed machines service.
|
||||
"""
|
||||
|
@ -40,7 +40,7 @@ from uds.core.environment import Environment
|
||||
from uds.services import Proxmox
|
||||
|
||||
|
||||
from uds.services.Proxmox.deployment import Operation as Operation, ProxmoxDeployment as Deployment
|
||||
from uds.services.Proxmox.deployment import Operation as Operation, ProxmoxUserserviceLinked as Deployment
|
||||
|
||||
# if not data.startswith(b'v'):
|
||||
# return super().unmarshal(data)
|
||||
|
@ -420,14 +420,14 @@ def create_provider(**kwargs: typing.Any) -> provider.ProxmoxProvider:
|
||||
|
||||
def create_service_linked(
|
||||
provider: typing.Optional[provider.ProxmoxProvider] = None, **kwargs: typing.Any
|
||||
) -> service.ProxmoxLinkedService:
|
||||
) -> service.ProxmoxServiceLinked:
|
||||
"""
|
||||
Create a fixed service
|
||||
"""
|
||||
uuid_ = str(uuid.uuid4())
|
||||
values = SERVICE_LINKED_VALUES_DICT.copy()
|
||||
values.update(kwargs)
|
||||
return service.ProxmoxLinkedService(
|
||||
return service.ProxmoxServiceLinked(
|
||||
environment=environment.Environment.private_environment(uuid_),
|
||||
provider=provider or create_provider(),
|
||||
values=values,
|
||||
@ -437,14 +437,14 @@ def create_service_linked(
|
||||
|
||||
def create_service_fixed(
|
||||
provider: typing.Optional[provider.ProxmoxProvider] = None, **kwargs: typing.Any
|
||||
) -> service_fixed.ProxmoxFixedService:
|
||||
) -> service_fixed.ProxmoxServiceFixed:
|
||||
"""
|
||||
Create a fixed service
|
||||
"""
|
||||
uuid_ = str(uuid.uuid4())
|
||||
values = SERVICE_FIXED_VALUES_DICT.copy()
|
||||
values.update(kwargs)
|
||||
return service_fixed.ProxmoxFixedService(
|
||||
return service_fixed.ProxmoxServiceFixed(
|
||||
environment=environment.Environment.private_environment(uuid_),
|
||||
provider=provider or create_provider(),
|
||||
values=values,
|
||||
|
@ -31,9 +31,7 @@
|
||||
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
import typing
|
||||
import datetime
|
||||
import collections.abc
|
||||
import itertools
|
||||
from unittest import mock
|
||||
|
||||
from uds.core import ui, environment
|
||||
|
@ -40,7 +40,7 @@ from ...utils import fake
|
||||
from uds.core.services import service
|
||||
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, ProxmoxUserserviceLinked as Deployment
|
||||
|
||||
|
||||
# if not data.startswith(b'v'):
|
||||
|
@ -31,16 +31,10 @@
|
||||
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
import typing
|
||||
import datetime
|
||||
import collections.abc
|
||||
import itertools
|
||||
from unittest import mock
|
||||
from netaddr import N
|
||||
|
||||
from numpy import fix
|
||||
|
||||
from uds.core import types, ui, environment
|
||||
from uds.services.Proxmox.service_fixed import ProxmoxFixedService
|
||||
from uds.services.Proxmox.service_fixed import ProxmoxServiceFixed
|
||||
|
||||
from . import fixtures
|
||||
|
||||
|
@ -30,16 +30,9 @@
|
||||
"""
|
||||
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
import typing
|
||||
import datetime
|
||||
import collections.abc
|
||||
import itertools
|
||||
from unittest import mock
|
||||
|
||||
from numpy import fix
|
||||
|
||||
from uds.core import ui, environment
|
||||
from uds.services.Proxmox.service import ProxmoxLinkedService
|
||||
from uds.services.Proxmox.service import ProxmoxServiceLinked
|
||||
|
||||
from . import fixtures
|
||||
|
||||
|
54
server/tests/services/proxmox/test_userservice_linked.py
Normal file
54
server/tests/services/proxmox/test_userservice_linked.py
Normal file
@ -0,0 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
#
|
||||
# Copyright (c) 2024 Virtual Cable S.L.U.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
# are permitted provided that the following conditions are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
# * Neither the name of Virtual Cable S.L.U. nor the names of its contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""
|
||||
Author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
import typing
|
||||
import datetime
|
||||
import collections.abc
|
||||
import itertools
|
||||
from unittest import mock
|
||||
|
||||
from uds.core import ui, environment
|
||||
from uds.services.Proxmox.deployment import ProxmoxUserserviceLinked
|
||||
|
||||
from . import fixtures
|
||||
|
||||
from ...utils.test import UDSTestCase
|
||||
|
||||
|
||||
class TestProxmovLinkedService(UDSTestCase):
|
||||
|
||||
def test_userservice(self) -> None:
|
||||
"""
|
||||
Test the user service
|
||||
"""
|
||||
with fixtures.patch_provider_api() as api:
|
||||
pass
|
Loading…
x
Reference in New Issue
Block a user