forked from shaba/openuds
Renamed module "openStack" to more convenient "openstack", and a couple of minor fixes related to it
This commit is contained in:
parent
edd6714cd0
commit
758f409372
@ -38,7 +38,7 @@ from uds.core.services import UserDeployment
|
|||||||
from uds.core.util.state import State
|
from uds.core.util.state import State
|
||||||
from uds.core.util import log
|
from uds.core.util import log
|
||||||
|
|
||||||
from . import openStack
|
from . import openstack
|
||||||
|
|
||||||
# Not imported at runtime, just for type checking
|
# Not imported at runtime, just for type checking
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
@ -139,12 +139,12 @@ class LiveDeployment(UserDeployment): # pylint: disable=too-many-public-methods
|
|||||||
|
|
||||||
status = self.service().getMachineState(self._vmid)
|
status = self.service().getMachineState(self._vmid)
|
||||||
|
|
||||||
if openStack.statusIsLost(status):
|
if openstack.statusIsLost(status):
|
||||||
return self.__error('Machine is not available anymore')
|
return self.__error('Machine is not available anymore')
|
||||||
|
|
||||||
if status == openStack.PAUSED:
|
if status == openstack.PAUSED:
|
||||||
self.service().resumeMachine(self._vmid)
|
self.service().resumeMachine(self._vmid)
|
||||||
elif status in (openStack.STOPPED, openStack.SHUTOFF):
|
elif status in (openstack.STOPPED, openstack.SHUTOFF):
|
||||||
self.service().startMachine(self._vmid)
|
self.service().startMachine(self._vmid)
|
||||||
|
|
||||||
# Right now, we suppose the machine is ready
|
# Right now, we suppose the machine is ready
|
||||||
@ -192,7 +192,7 @@ class LiveDeployment(UserDeployment): # pylint: disable=too-many-public-methods
|
|||||||
status = self.service().getMachineState(self._vmid)
|
status = self.service().getMachineState(self._vmid)
|
||||||
|
|
||||||
# If we want to check an state and machine does not exists (except in case that we whant to check this)
|
# If we want to check an state and machine does not exists (except in case that we whant to check this)
|
||||||
if openStack.statusIsLost(status):
|
if openstack.statusIsLost(status):
|
||||||
return self.__error('Machine not available. ({})'.format(status))
|
return self.__error('Machine not available. ({})'.format(status))
|
||||||
|
|
||||||
ret = State.RUNNING
|
ret = State.RUNNING
|
||||||
@ -311,7 +311,7 @@ class LiveDeployment(UserDeployment): # pylint: disable=too-many-public-methods
|
|||||||
"""
|
"""
|
||||||
status = self.service().getMachineState(self._vmid)
|
status = self.service().getMachineState(self._vmid)
|
||||||
|
|
||||||
if openStack.statusIsLost(status):
|
if openstack.statusIsLost(status):
|
||||||
raise Exception('Machine not found. (Status {})'.format(status))
|
raise Exception('Machine not found. (Status {})'.format(status))
|
||||||
|
|
||||||
self.service().removeMachine(self._vmid)
|
self.service().removeMachine(self._vmid)
|
||||||
@ -339,7 +339,7 @@ class LiveDeployment(UserDeployment): # pylint: disable=too-many-public-methods
|
|||||||
"""
|
"""
|
||||||
Checks the state of a deploy for an user or cache
|
Checks the state of a deploy for an user or cache
|
||||||
"""
|
"""
|
||||||
ret = self.__checkMachineState(openStack.ACTIVE)
|
ret = self.__checkMachineState(openstack.ACTIVE)
|
||||||
if ret == State.FINISHED:
|
if ret == State.FINISHED:
|
||||||
# Get IP & MAC (early stage)
|
# Get IP & MAC (early stage)
|
||||||
self._mac, self._ip = self.service().getNetInfo(self._vmid)
|
self._mac, self._ip = self.service().getNetInfo(self._vmid)
|
||||||
@ -350,13 +350,13 @@ class LiveDeployment(UserDeployment): # pylint: disable=too-many-public-methods
|
|||||||
"""
|
"""
|
||||||
Checks if machine has started
|
Checks if machine has started
|
||||||
"""
|
"""
|
||||||
return self.__checkMachineState(openStack.ACTIVE)
|
return self.__checkMachineState(openstack.ACTIVE)
|
||||||
|
|
||||||
def __checkSuspend(self) -> str:
|
def __checkSuspend(self) -> str:
|
||||||
"""
|
"""
|
||||||
Check if the machine has suspended
|
Check if the machine has suspended
|
||||||
"""
|
"""
|
||||||
return self.__checkMachineState(openStack.SUSPENDED)
|
return self.__checkMachineState(openstack.SUSPENDED)
|
||||||
|
|
||||||
def __checkRemoved(self) -> str:
|
def __checkRemoved(self) -> str:
|
||||||
"""
|
"""
|
||||||
|
@ -35,11 +35,11 @@ import typing
|
|||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from uds.core.ui import gui
|
from uds.core.ui import gui
|
||||||
|
|
||||||
from . import openStack
|
from . import openstack
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def getApi(parameters: typing.Dict[str, str]) -> typing.Tuple[openStack.Client, bool]:
|
def getApi(parameters: typing.Dict[str, str]) -> typing.Tuple[openstack.Client, bool]:
|
||||||
from .provider_legacy import ProviderLegacy
|
from .provider_legacy import ProviderLegacy
|
||||||
from .provider import OpenStackProvider
|
from .provider import OpenStackProvider
|
||||||
from uds.core.environment import Environment
|
from uds.core.environment import Environment
|
||||||
|
@ -31,9 +31,10 @@
|
|||||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .UDSOpenStackClient import Client
|
from .openstack_client import Client
|
||||||
|
|
||||||
# Import submodules
|
# Import submodules
|
||||||
from .common import *
|
from .common import *
|
||||||
|
|
||||||
|
# Logger imported from .common, if you ask
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
@ -39,7 +39,7 @@ from uds.core.ui import gui
|
|||||||
from uds.core.util import validators
|
from uds.core.util import validators
|
||||||
|
|
||||||
from .service import LiveService
|
from .service import LiveService
|
||||||
from . import openStack
|
from . import openstack
|
||||||
|
|
||||||
# Not imported at runtime, just for type checking
|
# Not imported at runtime, just for type checking
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
@ -115,7 +115,7 @@ class OpenStackProvider(ServiceProvider):
|
|||||||
legacy = False
|
legacy = False
|
||||||
|
|
||||||
# Own variables
|
# Own variables
|
||||||
_api: typing.Optional[openStack.Client] = None
|
_api: typing.Optional[openstack.Client] = None
|
||||||
|
|
||||||
def initialize(self, values: 'Module.ValuesType' = None):
|
def initialize(self, values: 'Module.ValuesType' = None):
|
||||||
"""
|
"""
|
||||||
@ -126,11 +126,11 @@ class OpenStackProvider(ServiceProvider):
|
|||||||
if values is not None:
|
if values is not None:
|
||||||
self.timeout.value = validators.validateTimeout(self.timeout.value)
|
self.timeout.value = validators.validateTimeout(self.timeout.value)
|
||||||
|
|
||||||
def api(self, projectId=None, region=None) -> openStack.Client:
|
def api(self, projectId=None, region=None) -> openstack.Client:
|
||||||
projectId = projectId or self.tenant.value or None
|
projectId = projectId or self.tenant.value or None
|
||||||
region = region or self.region.value or None
|
region = region or self.region.value or None
|
||||||
if self._api is None:
|
if self._api is None:
|
||||||
self._api = openStack.Client(
|
self._api = openstack.Client(
|
||||||
self.endpoint.value,
|
self.endpoint.value,
|
||||||
-1,
|
-1,
|
||||||
self.domain.value,
|
self.domain.value,
|
||||||
@ -145,7 +145,7 @@ class OpenStackProvider(ServiceProvider):
|
|||||||
return self._api
|
return self._api
|
||||||
|
|
||||||
def sanitizeVmName(self, name: str) -> str:
|
def sanitizeVmName(self, name: str) -> str:
|
||||||
return openStack.sanitizeName(name)
|
return openstack.sanitizeName(name)
|
||||||
|
|
||||||
def testConnection(self):
|
def testConnection(self):
|
||||||
"""
|
"""
|
||||||
|
@ -41,7 +41,7 @@ from uds.core.ui import gui
|
|||||||
from uds.core.util import validators
|
from uds.core.util import validators
|
||||||
|
|
||||||
from .service import LiveService
|
from .service import LiveService
|
||||||
from . import openStack
|
from . import openstack
|
||||||
|
|
||||||
|
|
||||||
# Not imported at runtime, just for type checking
|
# Not imported at runtime, just for type checking
|
||||||
@ -120,7 +120,7 @@ class ProviderLegacy(ServiceProvider):
|
|||||||
legacy = True
|
legacy = True
|
||||||
|
|
||||||
# Own variables
|
# Own variables
|
||||||
_api: typing.Optional[openStack.Client] = None
|
_api: typing.Optional[openstack.Client] = None
|
||||||
|
|
||||||
def initialize(self, values: 'Module.ValuesType' = None):
|
def initialize(self, values: 'Module.ValuesType' = None):
|
||||||
'''
|
'''
|
||||||
@ -131,8 +131,8 @@ class ProviderLegacy(ServiceProvider):
|
|||||||
if values is not None:
|
if values is not None:
|
||||||
self.timeout.value = validators.validateTimeout(self.timeout.value)
|
self.timeout.value = validators.validateTimeout(self.timeout.value)
|
||||||
|
|
||||||
def api(self, projectId=None, region=None) -> openStack.Client:
|
def api(self, projectId=None, region=None) -> openstack.Client:
|
||||||
return openStack.Client(
|
return openstack.Client(
|
||||||
self.host.value,
|
self.host.value,
|
||||||
self.port.value,
|
self.port.value,
|
||||||
self.domain.value,
|
self.domain.value,
|
||||||
@ -146,7 +146,7 @@ class ProviderLegacy(ServiceProvider):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def sanitizeVmName(self, name: str) -> str:
|
def sanitizeVmName(self, name: str) -> str:
|
||||||
return openStack.sanitizeName(name)
|
return openstack.sanitizeName(name)
|
||||||
|
|
||||||
def testConnection(self):
|
def testConnection(self):
|
||||||
'''
|
'''
|
||||||
|
@ -48,7 +48,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
# Not imported at runtime, just for type checking
|
# Not imported at runtime, just for type checking
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
from . import openStack
|
from . import openstack
|
||||||
from .provider import OpenStackProvider
|
from .provider import OpenStackProvider
|
||||||
from .provider_legacy import ProviderLegacy
|
from .provider_legacy import ProviderLegacy
|
||||||
Provider = typing.Union[OpenStackProvider, ProviderLegacy]
|
Provider = typing.Union[OpenStackProvider, ProviderLegacy]
|
||||||
@ -159,7 +159,7 @@ class LiveService(Service):
|
|||||||
ev = gui.HiddenField(value=None)
|
ev = gui.HiddenField(value=None)
|
||||||
legacy = gui.HiddenField(value=None) # We need to keep the env so we can instantiate the Provider
|
legacy = gui.HiddenField(value=None) # We need to keep the env so we can instantiate the Provider
|
||||||
|
|
||||||
_api: typing.Optional['openStack.Client'] = None
|
_api: typing.Optional['openstack.Client'] = None
|
||||||
|
|
||||||
def initialize(self, values):
|
def initialize(self, values):
|
||||||
"""
|
"""
|
||||||
@ -204,7 +204,7 @@ class LiveService(Service):
|
|||||||
self.legacy.setDefValue(self.parent().legacy and 'true' or 'false')
|
self.legacy.setDefValue(self.parent().legacy and 'true' or 'false')
|
||||||
|
|
||||||
@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(projectId=self.project.value, region=self.region.value)
|
self._api = self.parent().api(projectId=self.project.value, region=self.region.value)
|
||||||
|
|
||||||
@ -282,6 +282,7 @@ class LiveService(Service):
|
|||||||
STOPPED. The server is powered off and the disk image still persists.
|
STOPPED. The server is powered off and the disk image still persists.
|
||||||
SUSPENDED. The server is suspended, either by request or necessity. This status appears for only the XenServer/XCP, KVM, and ESXi hypervisors. Administrative users can suspend an instance if it is infrequently used or to perform system maintenance. When you suspend an instance, its VM state is stored on disk, all memory is written to disk, and the virtual machine is stopped. Suspending an instance is similar to placing a device in hibernation; memory and vCPUs become available to create other instances.
|
SUSPENDED. The server is suspended, either by request or necessity. This status appears for only the XenServer/XCP, KVM, and ESXi hypervisors. Administrative users can suspend an instance if it is infrequently used or to perform system maintenance. When you suspend an instance, its VM state is stored on disk, all memory is written to disk, and the virtual machine is stopped. Suspending an instance is similar to placing a device in hibernation; memory and vCPUs become available to create other instances.
|
||||||
VERIFY_RESIZE. System is awaiting confirmation that the server is operational after a move or resize.
|
VERIFY_RESIZE. System is awaiting confirmation that the server is operational after a move or resize.
|
||||||
|
SHUTOFF. The server was powered down by the user, either through the OpenStack Compute API or from within the server. For example, the user issued a shutdown -h command from within the server. If the OpenStack Compute manager detects that the VM was powered down, it transitions the server to the SHUTOFF status.
|
||||||
"""
|
"""
|
||||||
server = self.api.getServer(machineId)
|
server = self.api.getServer(machineId)
|
||||||
if server['status'] in ('ERROR', 'DELETED'):
|
if server['status'] in ('ERROR', 'DELETED'):
|
||||||
|
Loading…
Reference in New Issue
Block a user