Exemple #1
0
    def addAdmin(self,
                 session,
                 name,
                 password,
                 realname=None,
                 description=None):
        """
        Insert admin into the db.

        Raises:
            AdminAlreadyExists
        """

        # Check if admin already exists before attempting to add
        try:
            self.getAdmin(session, name)

            raise AdminAlreadyExists('Admin user [%s] already exists' % (name))
        except AdminNotFound:
            pass

        dbAdmin = Admins(username=name,
                         password=password,
                         realname=realname,
                         description=description)

        session.add(dbAdmin)
    def addAdmin(self, hardwareProfileName, adminUsername):
        """
        Add an admin to this hardware profile

        Raises:
            AdminAlreadyExists
        """

        session = DbManager().openSession()

        try:
            dbAdmin = self._adminsDbHandler.getAdmin(session, adminUsername)

            dbHardwareProfile = self._hardwareProfilesDbHandler.\
                getHardwareProfile(session, hardwareProfileName)

            if dbAdmin in dbHardwareProfile.admins:
                raise AdminAlreadyExists(
                    'The admin %s is already associated with %s.' %
                    (adminUsername, hardwareProfileName))

            dbHardwareProfile.admins.append(dbAdmin)

            session.commit()
        except TortugaException as ex:
            session.rollback()
            raise
        except Exception as ex:
            session.rollback()
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
    def addAdmin(self, session: Session, softwareProfileName: str,
                 adminUsername: str) -> None:
        """
        Add an admin to this software profile

        Raises:
            AdminAlreadyExists
        """

        try:
            dbAdmin = self._adminsDbHandler.getAdmin(session, adminUsername)

            dbSoftwareProfile = self._softwareProfilesDbHandler.\
                getSoftwareProfile(session, softwareProfileName)

            if dbAdmin not in dbSoftwareProfile.admins:
                dbSoftwareProfile.admins.append(dbAdmin)
            else:
                raise AdminAlreadyExists(
                    'Admin [%s] already associated with %s' %
                    (adminUsername, softwareProfileName))

            session.commit()
        except TortugaException:
            session.rollback()
            raise
        except Exception as ex:
            session.rollback()
            self._logger.exception(str(ex))
            raise
    def addAdmin(
            self, session: Session, hardwareProfileName,
            adminUsername: str) -> None:
        """
        Add an admin to this hardware profile

        Raises:
            AdminAlreadyExists
        """

        try:
            dbAdmin = self._adminsDbHandler.getAdmin(
                session, adminUsername)

            dbHardwareProfile = self._hardwareProfilesDbHandler.\
                getHardwareProfile(session, hardwareProfileName)

            if dbAdmin in dbHardwareProfile.admins:
                raise AdminAlreadyExists(
                    'The admin %s is already associated with %s.' % (
                        adminUsername, hardwareProfileName))

            dbHardwareProfile.admins.append(dbAdmin)

            session.commit()
        except TortugaException:
            session.rollback()
            raise
        except Exception as ex:
            session.rollback()
            self._logger.exception(str(ex))
            raise
Exemple #5
0
    def addAdmin(self, softwareProfileName, adminUsername):
        """ Add an admin to this software profile """
        session = DbManager().openSession()

        try:
            dbAdmin = self._adminsDbHandler.getAdmin(session, adminUsername)

            dbSoftwareProfile = self._softwareProfilesDbHandler.\
                getSoftwareProfile(session, softwareProfileName)

            if dbAdmin not in dbSoftwareProfile.admins:
                dbSoftwareProfile.admins.append(dbAdmin)
            else:
                raise AdminAlreadyExists(
                    'Admin [%s] already associated with %s' %
                    (adminUsername, softwareProfileName))
            session.commit()
        except TortugaException as ex:
            session.rollback()
            raise
        except Exception as ex:
            session.rollback()
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
Exemple #6
0
    def updateAdmin(self, session, dbAdmin):
        """
        Update an existing admin.

        Raises:
            AdminAlreadyExists
        """

        dbOldAdmin = self.getAdminById(session, dbAdmin.id)

        # If admin name is changing, ensure there is presently not an
        # admin with the new name.

        if dbAdmin.username != dbOldAdmin.username:
            try:
                self.getAdmin(session, dbAdmin.username)

                raise AdminAlreadyExists('Admin [%s] already exists' %
                                         (dbAdmin.username))
            except AdminNotFound:
                # OK.
                pass