def __init__(self, backend, node_type, user, computer=None, process_type=None, label='', description='', ctime=None, mtime=None): """Construct a new `BackendNode` instance wrapping a new `DbNode` instance. :param backend: the backend :param node_type: the node type string :param user: associated `BackendUser` :param computer: associated `BackendComputer` :param label: string label :param description: string description :param ctime: The creation time as datetime object :param mtime: The modification time as datetime object """ # pylint: disable=too-many-arguments super().__init__(backend) arguments = { 'node_type': node_type, 'process_type': process_type, 'user': user.dbmodel, 'label': label, 'description': description, } type_check(user, SqlaUser) if computer: type_check(computer, SqlaComputer, f'computer is of type {type(computer)}') arguments['dbcomputer'] = computer.dbmodel if ctime: type_check(ctime, datetime, f'the given ctime is of type {type(ctime)}') arguments['ctime'] = ctime if mtime: type_check(mtime, datetime, f'the given mtime is of type {type(mtime)}') arguments['mtime'] = mtime self._dbmodel = sqla_utils.ModelWrapper(models.DbNode(**arguments))
def clone(self): """Return an unstored clone of ourselves. :return: an unstored `BackendNode` with the exact same attributes and extras as self """ arguments = { 'node_type': self._dbmodel.node_type, 'process_type': self._dbmodel.process_type, 'user': self._dbmodel.user, 'dbcomputer': self._dbmodel.dbcomputer, 'label': self._dbmodel.label, 'description': self._dbmodel.description, 'attributes': self._dbmodel.attributes, 'extras': self._dbmodel.extras, } clone = self.__class__.__new__(self.__class__) # pylint: disable=no-value-for-parameter clone.__init__(self.backend, self.node_type, self.user) clone._dbmodel = sqla_utils.ModelWrapper(models.DbNode(**arguments)) # pylint: disable=protected-access return clone