Example #1
0
    def _create_kit_db_entry(self, session: Session, kit) -> Kit:
        """
        Creates a database entry for a kit.

        :param kit:
        :return: a Kit instance (TortugaObject)

        """
        try:
            return self._kit_db_api.getKit(session, kit['name'], kit['ver'])
        except KitNotFound:
            pass

        # Add the database entries for the kit
        kitObj = Kit(name=kit['name'], version=kit['ver'], iteration='0')
        kitObj.setDescription(kit['sum'])
        kitObj.setIsOs(True)
        kitObj.setIsRemovable(True)

        kit_descr = format_kit_descriptor(kit['name'], kit['ver'], kit['arch'])

        newComp = Component(name=kit_descr, version=kit['ver'])

        newComp.setDescription('%s mock component' % (kit_descr))

        newComp.addOsInfo(
            osHelper.getOsInfo(kit['name'], kit['ver'], kit['arch']))

        kitObj.addComponent(newComp)

        # Kit does not previously exist, perform 'normal' add kit operation
        self._kit_db_api.addKit(session, kitObj)

        return kitObj
Example #2
0
def parse(kitXmlFile):
    """Parse kit information for a given os and return kit object."""

    logger = logging.getLogger('tortuga.kit.parse')
    logger.addHandler(logging.NullHandler())

    try:
        logger.debug('parse(): parsing [%s]' % (kitXmlFile))

        xmlDoc = minidom.parse(kitXmlFile)

        rootNode = xmlDoc.getElementsByTagName('kit')[0]

        kit = Kit(name=rootNode.getAttribute('name'),
                  version=rootNode.getAttribute('version'),
                  iteration=rootNode.getAttribute('iteration'))

        documentationNode = rootNode.getElementsByTagName('documentation')[0]

        kit.setDocumentation(documentationNode.getAttribute('path'))

        eulaNodes = rootNode.getElementsByTagName('eula')

        if len(eulaNodes):
            try:
                with open(os.path.join(os.path.dirname(kitXmlFile),
                                       eulaNodes[0].getAttribute('path')),
                          'r') as f:
                    textContents = f.read()

                kit.setEula(
                    Eula(eulaNodes[0].getAttribute('key'), textContents))
            except Exception:
                logger.exception('Exception raised parsing EULA from kit')

                logger.debug('Unable to load EULA file contents')

        kit.setIntegrationModulePath(
            rootNode.getElementsByTagName('integration-module')[0].
            getAttribute('path'))

        kit.setDescription(
            rootNode.getElementsByTagName('description')[0].firstChild.
            nodeValue)

        for cNode in xmlDoc.getElementsByTagName('component'):
            component = Component(name=cNode.getAttribute('name'),
                                  version=cNode.getAttribute('version'))

            logger.debug(
                'parse(): Found component [%s]' % (component.getName()))

            # Kit description
            nodeList = cNode.getElementsByTagName('description')
            if nodeList:
                component.setDescription(nodeList[0].firstChild.nodeValue)

            # process os elements
            for osNode in cNode.getElementsByTagName('os'):
                result = _process_component_os(osNode, component)

                logger.debug(
                    'parse(): Adding component [%s] for [%s]' % (
                        component, result))

            kit.addComponent(component)

        return kit
    except TortugaException:
        raise
    except Exception as ex:
        logger.exception('Exception raised while parsing [%s]' % (kitXmlFile))

        raise TortugaException(exception=ex)