Пример #1
0
    def updateNetwork(self, network):
        """
        Updates network in DB..

            Returns:
                network
            Throws:
                NetworkNotFound
                DbError
        """

        session = DbManager().openSession()

        try:
            dbNetwork = self._networksDbHandler.updateNetwork(session, network)

            newNetwork = Network.getFromDbDict(dbNetwork.__dict__)

            session.commit()

            return newNetwork
        except TortugaException as ex:
            session.rollback()
            raise
        except Exception as ex:
            session.rollback()
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
Пример #2
0
    def getNetworkById(self, session: Session, id_):
        """
        Get a network by id from the db.
        """

        self._logger.debug('Retrieving network ID [%s]' % (id_))

        try:
            network = self._networksDbHandler.getNetworkById(session, id_)

            return Network.getFromDbDict(network.__dict__)
        except TortugaException:
            raise
        except Exception as ex:
            self._logger.exception(str(ex))
            raise
Пример #3
0
    def getNetwork(self, session: Session, address: str, netmask: str):
        """
        Get a network from the db.
        """

        self._logger.debug('Retrieving network [%s/%s]' % (address, netmask))

        try:
            network = self._networksDbHandler.getNetwork(
                session, address, netmask)

            return Network.getFromDbDict(network.__dict__)
        except TortugaException:
            raise
        except Exception as ex:
            self._logger.exception(str(ex))
            raise
Пример #4
0
    def getFromDbDict(cls, _dict):
        nic = super(Nic, cls).getFromDict(_dict)

        # network (relation)
        networkDict = _dict.get(Network.ROOT_TAG)

        if networkDict:
            nic.setNetwork(Network.getFromDbDict(networkDict.__dict__))

        # networkdevice (relation)
        networkDeviceDict = _dict.get(NetworkDevice.ROOT_TAG)

        if networkDeviceDict:
            nic.setNetworkDevice(
                NetworkDevice.getFromDbDict(networkDeviceDict.__dict__))

        return nic
Пример #5
0
    def getFromDbDict(cls, _dict, ignore: Optional[Iterable[str]] = None):
        nic = super(Nic, cls).getFromDict(_dict, ignore=ignore)

        # network (relation)
        networkDict = _dict.get(Network.ROOT_TAG)

        if networkDict:
            nic.setNetwork(Network.getFromDbDict(networkDict.__dict__))

        # networkdevice (relation)
        networkDeviceDict = _dict.get(NetworkDevice.ROOT_TAG)

        if networkDeviceDict:
            nic.setNetworkDevice(
                NetworkDevice.getFromDbDict(networkDeviceDict.__dict__))

        return nic
Пример #6
0
    def getNetworkById(self, id_):
        """
        Get a network by id from the db.
        """

        session = DbManager().openSession()

        try:
            network = self._networksDbHandler.getNetworkById(session, id_)

            return Network.getFromDbDict(network.__dict__)
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
Пример #7
0
    def updateNetwork(self, session: Session, network: Network) -> Network:
        """
        Updates network in DB..

            Returns:
                network
            Throws:
                NetworkNotFound
                InvalidArgument
        """

        try:
            if not network.getId():
                raise InvalidArgument(
                    'Network id not set: unable to identify network')

            self._logger.debug('Updating network [%s]' % (network))

            dbNetwork = self._networksDbHandler.getNetworkById(
                session, network.getId())

            dbNetwork = populate_network(network, dbNetwork)

            newNetwork = Network.getFromDbDict(dbNetwork.__dict__)

            session.commit()

            self._logger.info('Updated network [%s]' % (network))

            return newNetwork
        except TortugaException:
            session.rollback()

            raise
        except Exception as ex:
            session.rollback()

            self._logger.exception(str(ex))

            raise