Exemplo n.º 1
0
    def getSoftwareProfileById(self, softwareProfileId, optionDict=None):
        """
        Get softwareProfile from the db.

            Returns:
               softwareProfile
            Throws:
                SoftwareProfileNotFound
                DbError
        """

        session = DbManager().openSession()

        try:
            dbSoftwareProfile = self._softwareProfilesDbHandler.\
                getSoftwareProfileById(session, softwareProfileId)

            self.loadRelations(dbSoftwareProfile, optionDict or {})

            return SoftwareProfile.getFromDbDict(dbSoftwareProfile.__dict__)
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
Exemplo n.º 2
0
    def getSoftwareProfile(
            self,
            name: str,
            optionDict: Optional[Union[dict, None]] = None) -> SoftwareProfile:
        """
        Get softwareProfile from the db.

            Returns:
               softwareProfile
            Throws:
                SoftwareProfileNotFound
                DbError
        """

        session = DbManager().openSession()

        try:
            dbSoftwareProfile = self._softwareProfilesDbHandler.\
                getSoftwareProfile(session, name)

            self.loadRelations(dbSoftwareProfile, optionDict)

            self.loadRelations(dbSoftwareProfile, dict(tags=True))

            return SoftwareProfile.getFromDbDict(dbSoftwareProfile.__dict__)
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
Exemplo n.º 3
0
    def __get_software_profile_obj(
            self,
            software_profile: SoftwareProfileModel,
            options: Optional[dict] = None) -> SoftwareProfile:
        """
        Deserialize SQLAlchemy object to TortugaObject
        """
        self.loadRelations(software_profile, options)

        self.loadRelations(software_profile, dict(tags=True))

        # if 'components' is specified, ensure 'kit' relationship is
        # also serialized
        if options and 'components' in options and options['components']:
            for component in software_profile.components:
                self.loadRelation(component, 'kit')

        software_profile_obj = SoftwareProfile.getFromDbDict(
            software_profile.__dict__)

        return software_profile_obj
Exemplo n.º 4
0
    def getSoftwareProfileList(self, tags=None):
        """
        Get list of all available softwareProfiles from the db.

            Returns:
                [softwareProfile]
            Throws:
                DbError
        """

        session = DbManager().openSession()

        try:
            dbSoftwareProfileList = self._softwareProfilesDbHandler.\
                getSoftwareProfileList(session, tags=tags)

            softwareProfileList = TortugaObjectList()

            for dbSoftwareProfile in dbSoftwareProfileList:
                self.loadRelations(
                    dbSoftwareProfile, {
                        'components': True,
                        'partitions': True,
                        'hardwareprofiles': True,
                        'tags': True,
                    })

                softwareProfileList.append(
                    SoftwareProfile.getFromDbDict(dbSoftwareProfile.__dict__))

            return softwareProfileList
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()