예제 #1
0
    def getHardwareProfiles(self, **kwargs):
        tagspec = []

        if 'tag' in kwargs and kwargs['tag']:
            tagspec.extend(parse_tag_query_string(kwargs['tag']))

        try:
            if 'name' in kwargs and kwargs['name']:
                options = make_options_from_query_string(
                    kwargs['include'] if 'include' in kwargs else None,
                    ['resourceadapter'])

                hardwareProfiles = TortugaObjectList([
                    HardwareProfileManager().getHardwareProfile(
                        cherrypy.request.db,
                        kwargs['name'],
                        optionDict=options)
                ])
            else:
                hardwareProfiles = \
                    HardwareProfileManager().getHardwareProfileList(
                        cherrypy.request.db, tags=tagspec)

            response = {
                'hardwareprofiles': hardwareProfiles.getCleanDict(),
            }
        except Exception as ex:  # pylint: disable=broad-except
            self.getLogger().exception(
                'hardware profile WS API getHardwareProfiles() failed')

            self.handleException(ex)

            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
    def __getRuleList(self):
        ruleList = TortugaObjectList()

        for ruleId in self._ruleDict.keys():
            ruleList.append(copy.deepcopy(self._ruleDict[ruleId]))

        return ruleList
예제 #3
0
    def getEnabledComponentList(self, name):
        """
        Get a list of enabled components from the db.

            Returns:
                node
            Throws:
                DbError
        """

        session = DbManager().openSession()

        try:
            componentList = TortugaObjectList()

            for c in self._softwareProfilesDbHandler.getSoftwareProfile(
                    session, name).components:
                self.loadRelation(c, 'kit')

                componentList.append(Component.getFromDbDict(c.__dict__))

            return componentList
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
예제 #4
0
    def getNodeList(self, softwareProfile):
        """
        Get list of nodes in 'softwareProfile'

            Returns:
                [node]
            Throws:
                DbError
        """

        session = DbManager().openSession()

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

            nodeList = TortugaObjectList()

            for dbNode in dbSoftwareProfile.nodes:
                self.loadRelation(dbNode, 'hardwareprofile')

                nodeList.append(Node.getFromDbDict(dbNode.__dict__))

            return nodeList
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
예제 #5
0
    def getAllowedHardwareProfilesBySoftwareProfileName(
            self, softwareProfileName):
        """
        Get list of hardware profiles for the given software profile

            Returns:
                [hardwareProfileId]
            Throws:
                DbError
        """

        session = DbManager().openSession()

        try:
            dbMappings = self._softwareUsesHardwareDbHandler.\
                getAllowedHardwareProfilesBySoftwareProfileName(
                    session, softwareProfileName)

            mappingList = TortugaObjectList()

            for dbMapping in dbMappings:
                mappingList.append(dbMapping.hardwareProfileId)

            return mappingList
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
예제 #6
0
    def getSoftwareUsesHardwareList(self):
        """
        Get list of all mappings

            Returns:
                [softwareProfileId, hardwareProfileId]
            Throws:
                DbError
        """

        session = DbManager().openSession()

        try:
            dbMappings = self._softwareUsesHardwareDbHandler.\
                getSoftwareUsesHardwareList(session)

            mappingList = TortugaObjectList()

            for dbMapping in dbMappings:
                mappingList.append(
                    (dbMapping.softwareProfileId, dbMapping.hardwareProfileId))

            return mappingList
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
예제 #7
0
    def getSoftwareProfileList(self, session: Session, tags=None):
        """
        Get list of all available softwareProfiles from the db.

            Returns:
                [softwareProfile]
            Throws:
                DbError
        """

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

            softwareProfileList = TortugaObjectList()

            for dbSoftwareProfile in dbSoftwareProfileList:
                softwareProfileList.append(
                    self.__get_software_profile_obj(dbSoftwareProfile,
                                                    options={
                                                        'components': True,
                                                        'partitions': True,
                                                        'hardwareprofiles':
                                                        True,
                                                        'tags': True,
                                                    }))

            return softwareProfileList
        except TortugaException:
            raise
        except Exception as ex:
            self._logger.exception(str(ex))
            raise
예제 #8
0
    def __convert_nodes_to_TortugaObjectList(
            self, nodes: List[NodeModel],
            optionDict: Optional[OptionsDict] = None) -> TortugaObjectList:
        """
        Return TortugaObjectList of nodes with relations populated

        :param nodes:      list of Node objects
        :param optionDict:
        :param deleting:   whether or not to include nodes in the deleting
                           state

        :return: TortugaObjectList

        """
        nodeList = TortugaObjectList()

        for node in nodes:
            self.loadRelations(node, optionDict)

            # ensure 'resourceadapter' relation is always loaded. This one
            # is special since it's a relationship inside of a relationship.
            # It needs to be explicitly defined.
            self.loadRelation(node.hardwareprofile, 'resourceadapter')

            nodeList.append(Node.getFromDbDict(node.__dict__))

        return nodeList
예제 #9
0
    def getEnabledComponentList(self, session: Session,
                                name: str) -> TortugaObjectList:
        """
        Get a list of enabled components from the db.

            Returns:
                node
            Throws:
                DbError
        """

        try:
            componentList = TortugaObjectList()

            for c in self._softwareProfilesDbHandler.getSoftwareProfile(
                    session, name).components:
                self.loadRelation(c, 'kit')

                componentList.append(Component.getFromDbDict(c.__dict__))

            return componentList
        except TortugaException:
            raise
        except Exception as ex:
            self._logger.exception(str(ex))
            raise
예제 #10
0
    def getNodeList(self, session: Session,
                    softwareProfile: SoftwareProfile) -> TortugaObjectList:
        """
        Get list of nodes in 'softwareProfile'

            Returns:
                [node]
            Throws:
                DbError
        """

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

            nodeList = TortugaObjectList()

            for dbNode in dbSoftwareProfile.nodes:
                self.loadRelation(dbNode, 'hardwareprofile')

                nodeList.append(Node.getFromDbDict(dbNode.__dict__))

            return nodeList
        except TortugaException:
            raise
        except Exception as ex:
            self._logger.exception(str(ex))
            raise
예제 #11
0
    def getFromDbDict(cls, _dict, ignore: Optional[Iterable[str]] = None):
        hardwareProfile = super(HardwareProfile,
                                cls).getFromDict(_dict, ignore=ignore)

        hardwareProfile.setAdmins(
            tortuga.objects.admin.Admin.getListFromDbDict(_dict))

        if ignore and 'nodes' not in ignore:
            hardwareProfile.setNodes(
                tortuga.objects.node.Node.getListFromDbDict(_dict))

        hardwareProfile.setProvisioningNics(
            tortuga.objects.nic.Nic.getListFromDbDict(_dict))

        resourceAdapterDict = _dict.get(
            tortuga.objects.resourceAdapter.ResourceAdapter.ROOT_TAG)

        if resourceAdapterDict:
            hardwareProfile.setResourceAdapter(
                tortuga.objects.resourceAdapter.ResourceAdapter.getFromDict(
                    resourceAdapterDict.__dict__))

        defaultResourceAdapterConfig = _dict.get(
            'default_resource_adapter_config')

        if defaultResourceAdapterConfig:
            hardwareProfile.setDefaultResourceAdapterConfig(
                defaultResourceAdapterConfig.name)

        if _dict.get('idlesoftwareprofile'):
            hardwareProfile.setIdleSoftwareProfile(
                tortuga.objects.softwareProfile.SoftwareProfile.getFromDbDict(
                    _dict.get('idlesoftwareprofile').__dict__))

        # hardwareprofilenetworks (relation)
        hardwareProfileNetworks = _dict.get('hardwareprofilenetworks')

        if hardwareProfileNetworks:
            networkList = TortugaObjectList()

            for item in hardwareProfileNetworks:
                networkDict = item.network.__dict__
                networkDeviceDict = item.networkdevice.__dict__

                network = tortuga.objects.network.Network.getFromDbDict(
                    networkDict)

                networkdevice = tortuga.objects.networkDevice.\
                    NetworkDevice.getFromDbDict(networkDeviceDict)

                network.setNetworkDevice(networkdevice)

                networkList.append(network)

            hardwareProfile.setNetworks(networkList)

        tags = {tag.name: tag.value for tag in _dict.get('tags', [])}
        hardwareProfile.setTags(tags)

        return hardwareProfile
    def getAllowedHardwareProfilesBySoftwareProfileName(
            self, session: Session, softwareProfileName):
        """
        Get list of hardware profiles for the given software profile

            Returns:
                [hardwareProfileId]
            Throws:
                DbError
        """

        try:
            dbMappings = self._softwareUsesHardwareDbHandler.\
                getAllowedHardwareProfilesBySoftwareProfileName(
                    session, softwareProfileName)

            mappingList = TortugaObjectList()

            for dbMapping in dbMappings:
                mappingList.append(dbMapping.hardwareProfileId)

            return mappingList
        except TortugaException:
            raise
        except Exception as ex:
            self._logger.exception(str(ex))
            raise
    def getSoftwareUsesHardwareList(self, session: Session):
        """
        Get list of all mappings

            Returns:
                [softwareProfileId, hardwareProfileId]
            Throws:
                DbError
        """

        try:
            dbMappings = self._softwareUsesHardwareDbHandler.\
                getSoftwareUsesHardwareList(session)

            mappingList = TortugaObjectList()

            for dbMapping in dbMappings:
                mappingList.append((dbMapping.softwareProfileId,
                                    dbMapping.hardwareProfileId))

            return mappingList
        except TortugaException:
            raise
        except Exception as ex:
            self._logger.exception(str(ex))
            raise
예제 #14
0
파일: kit.py 프로젝트: ilumb/tortuga
 def __init__(self, name=None, version=None, iteration=None):
     TortugaObject.__init__(self, {
         'name': name,
         'version': version,
         'iteration': iteration,
         'componentList': TortugaObjectList(),
         'sources': TortugaObjectList(),
     }, ['name', 'version', 'iteration', 'id'], Kit.ROOT_TAG)
예제 #15
0
 def __init__(self, name=None):
     TortugaObject.__init__(self, {
         'name': name,
         'networks': TortugaObjectList(),
         'admins': TortugaObjectList(),
         'nodes': TortugaObjectList(),
         'nics': TortugaObjectList(),
     }, ['name', 'id'], HardwareProfile.ROOT_TAG)
예제 #16
0
    def __init__(self):

        TortugaObject.__init__(
            self, {
                'nodes': TortugaObjectList(),
                'strings': TortugaObjectList(),
                'running': False
            }, [], AddHostStatus.ROOT_TAG)
예제 #17
0
 def __init__(self, name=None, version=None):
     TortugaObject.__init__(
         self, {
             'name': name,
             'version': version,
             'packageList': TortugaObjectList(),
             'osComponentList': TortugaObjectList(),
             'osFamilyComponentList': TortugaObjectList()
         }, ['name', 'version', 'id'], Component.ROOT_TAG)
예제 #18
0
파일: rule.py 프로젝트: ilumb/tortuga
 def __init__(self, applicationName='', name='', description=''):
     TortugaObject.__init__(self, {
         'applicationName': applicationName,
         'name': name,
         'description': description,
         'status': Rule.ENABLED_STATUS,
         'conditions': TortugaObjectList(),
         'xPathVariables': TortugaObjectList(),
     }, ['applicationName', 'name', 'id'], Rule.ROOT_TAG)
예제 #19
0
    def getFromDbDict(cls, _dict):
        hardwareProfile = super(HardwareProfile, cls).getFromDict(_dict)

        hardwareProfile.setAdmins(
            tortuga.objects.admin.Admin.getListFromDbDict(_dict))

        hardwareProfile.setNodes(
            tortuga.objects.node.Node.getListFromDbDict(_dict))

        hardwareProfile.setProvisioningNics(
            tortuga.objects.nic.Nic.getListFromDbDict(_dict))

        resourceAdapterDict = _dict.get(
            tortuga.objects.resourceAdapter.ResourceAdapter.ROOT_TAG)

        if resourceAdapterDict:
            hardwareProfile.setResourceAdapter(
                tortuga.objects.resourceAdapter.ResourceAdapter.getFromDict(
                    resourceAdapterDict.__dict__))

        if _dict.get('idlesoftwareprofile'):
            hardwareProfile.setIdleSoftwareProfile(
                tortuga.objects.softwareProfile.SoftwareProfile.getFromDbDict(
                    _dict.get('idlesoftwareprofile').__dict__))

        # hardwareprofilenetworks (relation)
        hardwareProfileNetworks = _dict.get('hardwareprofilenetworks')

        if hardwareProfileNetworks:
            networkList = TortugaObjectList()

            for item in hardwareProfileNetworks:
                networkDict = item.network.__dict__
                networkDeviceDict = item.networkdevice.__dict__

                network = tortuga.objects.network.Network.getFromDbDict(
                    networkDict)

                networkdevice = tortuga.objects.networkDevice.\
                    NetworkDevice.getFromDbDict(networkDeviceDict)

                network.setNetworkDevice(networkdevice)

                networkList.append(network)

            hardwareProfile.setNetworks(networkList)

        if 'tags' in _dict:
            tags = {}

            for tag in _dict['tags']:
                tags[tag.name] = tag.value

            hardwareProfile.setTags(tags)

        return hardwareProfile
예제 #20
0
 def __init__(self, name=None):
     TortugaObject.__init__(
         self, {
             'name': name,
             'admins': TortugaObjectList(),
             'partitions': TortugaObjectList(),
             'components': TortugaObjectList(),
             'nodes': TortugaObjectList(),
             'kitsources': TortugaObjectList(),
         }, ['name', 'id'], SoftwareProfile.ROOT_TAG)
예제 #21
0
파일: kit.py 프로젝트: ilumb/tortuga
 def getUniqueOsInfoList(self):
     """ Get list of unique operating systems. """
     osInfoList = TortugaObjectList()
     for c in self['componentList']:
         isDuplicate = False
         for osInfo in osInfoList:
             if c.getOsInfo() == osInfo:
                 isDuplicate = True
                 break
         if not isDuplicate:
             osInfoList.append(c.getOsInfo())
     return osInfoList
예제 #22
0
파일: san.py 프로젝트: ilumb/tortuga
    def getNodeVolumes(self, nodeName):
        vols = TortugaObjectList()

        for drive in self.__getAllNodeDrives(nodeName):
            try:
                driveinfo = self.__getDriveInfo(nodeName, drive)

                vols.append(driveinfo.volume)
            except Exception as ex:
                self.getLogger().debug(
                    '[%s] Error getting info for node [%s] drive [%s]:'
                    ' %s' % (self.__class__.__name__, nodeName, drive, ex))

        return vols
예제 #23
0
    def getStatus(self, session: str, startMessage: int,
                  getNodes: bool) -> AddHostStatus:
        """
        Raises:
            NotFound
        """
        with self._addHostLock:
            nodeList = self._nodeDbApi.getNodesByAddHostSession(session) \
                if getNodes else TortugaObjectList()

            # Lock and copy for data consistency
            if session not in self._sessions:
                raise NotFound('Invalid add host session ID [%s]' % (session))

            sessionDict = self._sessions.get(session)

            statusCopy = AddHostStatus()

            # Copy simple data
            for key in sessionDict['status'].getKeys():
                statusCopy.set(key, sessionDict['status'].get(key))

            # Get slice of status messages
            messages = sessionDict['status'].getMessageList()[startMessage:]

            statusCopy.setMessageList(messages)

            if nodeList:
                statusCopy.getNodeList().extend(nodeList)

            return statusCopy
예제 #24
0
    def getIdleSoftwareProfileList(self, session: Session):
        """
        Get list of all available idle softwareProfiles from the db.

            Returns:
                [idle softwareProfile]
            Throws:
                DbError
        """

        try:
            dbSoftwareProfileList = \
                self._softwareProfilesDbHandler.getIdleSoftwareProfileList(
                    session)

            result = TortugaObjectList()

            for software_profile in dbSoftwareProfileList:
                self.__get_software_profile_obj(software_profile)

            return result
        except TortugaException:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
예제 #25
0
    def getSoftwareProfiles(self, **kwargs):
        """
        TODO: implement support for optionDict through query string
        """

        try:
            tags = {}

            if 'tag' in kwargs and kwargs['tag']:
                tags.update(dict(parse_tag_query_string(kwargs['tag'])))

            if 'name' in kwargs and kwargs['name']:
                default_options = [
                    'components',
                    'partitions',
                    'hardwareprofiles',
                    'tags',
                ]

                options = make_options_from_query_string(
                    kwargs['include'] if 'include' in kwargs else None,
                    default_options)

                softwareProfiles = TortugaObjectList([
                    self._softwareProfileManager.getSoftwareProfile(
                        cherrypy.request.db,
                        kwargs['name'],
                        optionDict=options)
                ])
            else:
                softwareProfiles = \
                    self._softwareProfileManager.getSoftwareProfileList(
                        cherrypy.request.db, tags=tags)

            response = {
                'softwareprofiles': softwareProfiles.getCleanDict(),
            }
        except Exception as ex:
            self.handleException(ex)

            http_status = 404 \
                if isinstance(ex, SoftwareProfileNotFound) else 400

            response = self.errorResponse(str(ex), http_status=http_status)

        return self.formatResponse(response)
예제 #26
0
    def getTortugaObjectList(
            self, cls: Type[ResourceAdapter],
            db_list: List[ResourceAdapterModel]) -> List[ResourceAdapter]:
        item_list: List[ResourceAdapter] = []

        for db_item in db_list:
            item: ResourceAdapter = cls.getFromDbDict(db_item.__dict__)
            item.set_settings(db_item.settings)
            item_list.append(item)

        return TortugaObjectList(item_list)
예제 #27
0
    def getNodes(self, **kwargs):
        """
        Return list of all available nodes

        """

        tagspec = []

        if 'tag' in kwargs and kwargs['tag']:
            tagspec.extend(parse_tag_query_string(kwargs['tag']))

        try:
            options = make_options_from_query_string(
                kwargs['include'] if 'include' in kwargs else None,
                ['softwareprofile', 'hardwareprofile'])

            if 'addHostSession' in kwargs and kwargs['addHostSession']:
                nodeList = self.app.node_api.getNodesByAddHostSession(
                    cherrypy.request.db, kwargs['addHostSession'], options)
            elif 'name' in kwargs and kwargs['name']:
                nodeList = self.app.node_api.getNodesByNameFilter(
                    cherrypy.request.db, kwargs['name'], optionDict=options)
            elif 'installer' in kwargs and str2bool(kwargs['installer']):
                nodeList = TortugaObjectList(
                    [self.app.node_api.getInstallerNode(cherrypy.request.db)])
            elif 'ip' in kwargs:
                nodeList = TortugaObjectList([
                    self.app.node_api.getNodeByIp(cherrypy.request.db,
                                                  kwargs['ip'])
                ])
            else:
                nodeList = self.app.node_api.getNodeList(cherrypy.request.db,
                                                         tags=tagspec)

            response = {'nodes': NodeSchema().dump(nodeList, many=True).data}
        except Exception as ex:  # noqa pylint: disable=broad-except
            self._logger.exception('node WS API getNodes() failed')
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
예제 #28
0
    def __convert_nodes_to_TortugaObjectList(
            self,
            nodes,
            relations: Optional[Union[dict,
                                      None]] = None) -> TortugaObjectList:
        nodeList = TortugaObjectList()

        relations = relations or dict(softwareprofile=True,
                                      hardwareprofile=True)

        for t in nodes:
            self.loadRelations(t, relations)

            # Always load 'tags' relation
            self.loadRelations(t, {'tags': True})

            node = Node.getFromDbDict(t.__dict__)

            nodeList.append(node)

        return nodeList
예제 #29
0
    def getChildrenList(self, nodeName):
        """return the list of children currently on this node"""

        url = 'v1/nodes/%s/children' % (nodeName)

        try:
            _, responseDict = self.sendSessionRequest(url)

            nodeList = TortugaObjectList()

            if responseDict:
                if 'nodes' in responseDict:
                    cDicts = responseDict.get('nodes')
                    for cDict in cDicts:
                        node = tortuga.objects.node.Node.getFromDict(cDict)
                        nodeList.append(node)
                else:
                    node = tortuga.objects.node.Node.getFromDict(
                        responseDict.get('node'))

                    nodeList.append(node)

            return nodeList
        except TortugaException:
            raise
        except Exception as ex:
            raise TortugaException(exception=ex)
예제 #30
0
파일: san.py 프로젝트: ilumb/tortuga
    def __getVolumeHelper(self, queryVolume=None):
        """
        Returns a list of 0 or more volumes if 'queryVolume' is None, otherwise
        returns a list containing the requested volume.  Raises exception if
        'queryVolume' is set and no volumes match.

        Raises:
            VolumeDoesNotExist
        """

        config = self.__read_cache_file()

        volumes = TortugaObjectList()

        if not config.has_section(self.VOLUME_SECTION_NAME):
            return volumes

        for item in config.items(self.VOLUME_SECTION_NAME):
            volume = item[0]

            volinfo = self.__get_volume(volume, config)

            if queryVolume:
                if volume == queryVolume.lower():
                    volumes.append(volinfo)
                    break
            else:
                volumes.append(volinfo)

        if not volumes and queryVolume is not None:
            raise VolumeDoesNotExist('Volume [%s] does not exist' %
                                     (queryVolume.lower()))

        return volumes