forked from shaba/openuds
fixed initialization order for IPMachinesDeployed
This commit is contained in:
parent
a69bda8673
commit
97e5ff1b6a
@ -679,6 +679,7 @@ class UserServiceManager:
|
||||
userServiceInstance = userService.getInstance()
|
||||
ip = userServiceInstance.getIp()
|
||||
userService.logIP(ip) # Update known ip
|
||||
logger.debug('IP: %s', ip)
|
||||
|
||||
if self.checkUuid(userService) is False: # The service is not the expected one
|
||||
serviceNotReadyCode = 0x0004
|
||||
|
@ -382,7 +382,7 @@ class UserDeployment(Environmentable, Serializable): # pylint: disable=too-many
|
||||
to the core. Take that into account and handle exceptions inside
|
||||
this method.
|
||||
"""
|
||||
raise NotImplementedError('Base deploy for cache invoked! for class {0}'.format(self.__class__.__name__))
|
||||
raise Exception('Base deploy for cache invoked! for class {0}'.format(self.__class__.__name__))
|
||||
|
||||
def deployForUser(self, user: 'User') -> str:
|
||||
"""
|
||||
@ -573,8 +573,8 @@ class UserDeployment(Environmentable, Serializable): # pylint: disable=too-many
|
||||
"""
|
||||
This method is invoked for "reset" an user service
|
||||
This method is not intended to be a task right now, (so its one step method)
|
||||
base method does nothing
|
||||
"""
|
||||
raise NotImplementedError('reset method for class {0} not provided!'.format(self.__class__.__name__))
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
|
@ -64,7 +64,6 @@ class Attribute:
|
||||
self._value = self._type(value)
|
||||
|
||||
|
||||
# noinspection PyMissingConstructor
|
||||
class AutoAttributes(Serializable):
|
||||
"""
|
||||
Easy creation of attributes to marshal & unmarshal at modules
|
||||
@ -74,21 +73,21 @@ class AutoAttributes(Serializable):
|
||||
Access attrs as "self._attr1, self._attr2"
|
||||
"""
|
||||
|
||||
_dict: typing.Dict
|
||||
attrs: typing.Dict
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__()
|
||||
self.dict = {}
|
||||
self.attrs = {}
|
||||
self.declare(**kwargs)
|
||||
|
||||
def __getattribute__(self, name):
|
||||
if name.startswith('_') and name[1:] in self.dict:
|
||||
return self.dict[name[1:]].getValue()
|
||||
if name.startswith('_') and name[1:] in self.attrs:
|
||||
return self.attrs[name[1:]].getValue()
|
||||
return object.__getattribute__(self, name)
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name.startswith('_') and name[1:] in self.dict:
|
||||
self.dict[name[1:]].setValue(value)
|
||||
if name.startswith('_') and name[1:] in self.attrs:
|
||||
self.attrs[name[1:]].setValue(value)
|
||||
else:
|
||||
object.__setattr__(self, name, value)
|
||||
|
||||
@ -96,10 +95,12 @@ class AutoAttributes(Serializable):
|
||||
d = {}
|
||||
for key, typ in kwargs.items():
|
||||
d[key] = Attribute(typ)
|
||||
self.dict = d
|
||||
self.attrs = d
|
||||
|
||||
def marshal(self) -> bytes:
|
||||
return typing.cast(bytes, encoders.encode(b'\2'.join([b'%s\1%s' % (k.encode('utf8'), pickle.dumps(v, protocol=0)) for k, v in self.dict.items()]), 'bz2'))
|
||||
for k, v in self.attrs.items():
|
||||
logger.debug('Marshall Autoattributes: %s=%s', k, v.getValue())
|
||||
return typing.cast(bytes, encoders.encode(b'\2'.join([b'%s\1%s' % (k.encode('utf8'), pickle.dumps(v, protocol=0)) for k, v in self.attrs.items()]), 'bz2'))
|
||||
|
||||
def unmarshal(self, data: bytes):
|
||||
if not data: # Can be empty
|
||||
@ -113,10 +114,13 @@ class AutoAttributes(Serializable):
|
||||
for pair in data.split(b'\2'):
|
||||
k, v = pair.split(b'\1')
|
||||
# logger.debug('k: %s --- v: %s', k, v)
|
||||
self.dict[k.decode('utf8')] = pickle.loads(v)
|
||||
self.attrs[k.decode('utf8')] = pickle.loads(v)
|
||||
|
||||
for k, v in self.attrs.items():
|
||||
logger.debug('Marshall Autoattributes: %s=%s', k, v.getValue())
|
||||
|
||||
def __str__(self):
|
||||
str_ = '<AutoAttribute '
|
||||
for k, v in self.dict.items():
|
||||
for k, v in self.attrs.items():
|
||||
str_ += "%s (%s) = %s" % (k, v.getType(), v.getStrValue())
|
||||
return str_ + '>'
|
||||
|
@ -30,27 +30,30 @@
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
import logging
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from uds.core import services
|
||||
from uds.core.util.state import State
|
||||
from uds.core.util.auto_attributes import AutoAttributes
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IPMachineDeployed(AutoAttributes, services.UserDeployment):
|
||||
class IPMachineDeployed(services.UserDeployment, AutoAttributes):
|
||||
suggestedTime = 10
|
||||
|
||||
_ip: str
|
||||
_reason: str
|
||||
_state: str
|
||||
|
||||
def __init__(self, environment, **kwargs):
|
||||
AutoAttributes.__init__(self, ip=str, reason=str, state=str)
|
||||
services.UserDeployment.__init__(self, environment, **kwargs)
|
||||
self._state = State.FINISHED
|
||||
|
||||
def setIp(self, ip):
|
||||
logger.debug('Setting IP to %s (ignored)' % ip)
|
||||
logger.debug('Setting IP to %s (ignored)', ip)
|
||||
|
||||
def getIp(self):
|
||||
return self._ip.split('~')[0]
|
||||
@ -78,7 +81,7 @@ class IPMachineDeployed(AutoAttributes, services.UserDeployment):
|
||||
return self._state
|
||||
|
||||
def deployForUser(self, user):
|
||||
logger.debug("Starting deploy of {0} for user {1}".format(self._ip, user))
|
||||
logger.debug("Starting deploy of %s for user %s", self._ip, user)
|
||||
return self.__deploy()
|
||||
|
||||
def checkState(self):
|
||||
|
Loading…
Reference in New Issue
Block a user