コード例 #1
0
    def upsertParameter(self, session: Session, parameter: Parameter) -> None:
        try:
            self._globalParametersDbHandler.upsertParameter(
                session, parameter.getName(), parameter.getValue(),
                description=parameter.getDescription())

            session.commit()
        except TortugaException:
            session.rollback()
            raise
        except Exception:
            session.rollback()
            self._logger.exception('upsertParameter failed')
            raise
コード例 #2
0
    def createParameter(self):
        """
        Creates a parameter.

        """
        self._logger.debug('Creating parameter')

        postdata = cherrypy.request.json
        parameter = Parameter.getFromDict(postdata)

        try:
            self.app.parameter_api.getParameter(cherrypy.request.db,
                                                parameter.getName())
            parameter_exists = True

        except ParameterNotFound:
            parameter_exists = False

        try:
            if parameter_exists:
                raise ParameterAlreadyExists()

            self.app.parameter_api.upsertParameter(cherrypy.request.db,
                                                   parameter)

            response = None

        except Exception as ex:
            self._logger.error(str(ex))
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
コード例 #3
0
ファイル: parameterApi.py プロジェクト: tprestegard/tortuga
    def upsertParameter(self, session: Session, parameter: Parameter) \
            -> None:
        try:
            return ParameterManager().upsertParameter(session, parameter)
        except TortugaException:
            raise
        except Exception as ex:
            self._logger.exception('Error upserting parameter [%s]' %
                                   (parameter.getName()))

            raise TortugaException(exception=ex)
コード例 #4
0
    def getParameter(self, session: Session, name: str) -> Parameter:
        """
        Returns the named parameter
        """

        try:
            dbParam = self._globalParametersDbHandler.getParameter(
                session, name)

            return Parameter.getFromDbDict(dbParam.__dict__)
        except TortugaException:
            raise
        except Exception as ex:
            self._logger.exception(str(ex))
            raise
コード例 #5
0
ファイル: ucparam.py プロジェクト: tprestegard/tortuga
    def _set_parameter(self, name, value):
        """
        Sets the value of a parameter.

        :param name:  the name of the parameter to set
        :param value: the value of the parameter to set

        """
        try:
            parameter = self.get_api().getParameter(name)
            parameter.setValue(value)
            self.get_api().updateParameter(parameter)

        except ParameterNotFound:
            parameter = Parameter(name=name, value=value)
            self.get_api().createParameter(parameter)
コード例 #6
0
    def getParameter(self, name):
        """
        Returns the named parameter
        """

        session = DbManager().openSession()

        try:
            dbParam = self._globalParametersDbHandler.getParameter(
                session, name)

            return Parameter.getFromDbDict(dbParam.__dict__)
        except TortugaException:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
コード例 #7
0
    def updateParameter(self, name):
        """
        Creates or updates a parameter.

        """
        self._logger.debug('Creating/updating parameter: {}'.format(name))

        postdata = cherrypy.request.json
        parameter = Parameter.getFromDict(postdata)

        try:
            if name != parameter.getName():
                raise Exception('Parameter name mismatch')

            self.app.parameter_api.upsertParameter(cherrypy.request.db,
                                                   parameter)
            response = None

        except Exception as ex:
            self._logger.error(str(ex))
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
コード例 #8
0
    def getProvisioningInfo(self, nodeName):
        """
        Get the provisioing information for a given provisioned address

            Returns:
                [provisioningInformation structure]
            Throws:
                NodeNotFound
                DbError
        """

        session = DbManager().openSession()

        try:
            provisioningInfo = ProvisioningInfo()

            dbNode = self._nodesDbHandler.getNode(session, nodeName)

            if dbNode.softwareprofile:
                self.loadRelations(dbNode.softwareprofile, {
                    'partitions': True,
                    'packages': True,
                })

                for component in dbNode.softwareprofile.components:
                    self.loadRelations(
                        component, {
                            'kit': True,
                            'os': True,
                            'family': True,
                            'os_components': True,
                            'osfamily_components': True,
                        })

            self.loadRelation(dbNode, 'hardwareprofile')

            provisioningInfo.setNode(Node.getFromDbDict(dbNode.__dict__))

            globalParameters = self._globalParameterDbApi.getParameterList()

            # TODO: this is a terrible hack until something better comes
            # along.

            p = Parameter()
            p.setName('Installer')

            hostName = socket.gethostname().split('.', 1)[0]

            if '.' in dbNode.name:
                nodeDomain = dbNode.name.split('.', 1)[1]

                priInstaller = hostName + '.%s' % (nodeDomain)
            else:
                priInstaller = hostName

            p.setValue(priInstaller)

            globalParameters.append(p)

            provisioningInfo.setGlobalParameters(globalParameters)

            return provisioningInfo
        except TortugaException as ex:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise
        finally:
            DbManager().closeSession()
コード例 #9
0
ファイル: dbUtility.py プロジェクト: cameronbrunner/tortuga
def init_global_parameters(session, settings):
    # Create Global Parameters
    pApi = GlobalParametersDbHandler()

    pApi.addParameter(session, Parameter('Language', settings['language']))
    pApi.addParameter(session, Parameter('Keyboard', settings['keyboard']))
    pApi.addParameter(session, Parameter('Timezone_zone',
                                         settings['timezone']))
    pApi.addParameter(session, Parameter('Timezone_utc', settings['utc']))
    pApi.addParameter(session, Parameter('DbSchemaVers', '3'))
    pApi.addParameter(session, Parameter('IntWebPort', settings['intWebPort']))
    pApi.addParameter(
        session, Parameter('IntWebServicePort', settings['intWebServicePort']))
    pApi.addParameter(session,
                      Parameter('WebservicePort', settings['adminPort']))
    pApi.addParameter(session,
                      Parameter('EulaAccepted', settings['eulaAccepted']))
    pApi.addParameter(session, Parameter('DNSZone', 'private'))
    pApi.addParameter(session, Parameter('depot', settings['depotpath']))
コード例 #10
0
ファイル: nodeDbApi.py プロジェクト: joedborg/tortuga
    def getProvisioningInfo(self, session: Session, nodeName: str) \
            -> ProvisioningInfo:
        """
        Get the provisioing information for a given provisioned address

            Returns:
                [provisioningInformation structure]
            Throws:
                NodeNotFound
                DbError
        """

        try:
            provisioningInfo = ProvisioningInfo()

            dbNode = self._nodesDbHandler.getNode(session, nodeName)

            if dbNode.softwareprofile:
                self.loadRelations(dbNode.softwareprofile, {
                    'partitions': True,
                })

                for component in dbNode.softwareprofile.components:
                    self.loadRelations(component, {
                        'kit': True,
                        'os': True,
                        'family': True,
                        'os_components': True,
                        'osfamily_components': True,
                    })

            self.loadRelation(dbNode, 'hardwareprofile')

            provisioningInfo.setNode(
                Node.getFromDbDict(dbNode.__dict__))

            globalParameters = \
                self._globalParameterDbApi.getParameterList(session)

            # manually inject value for 'installer'
            p = Parameter(name='Installer')

            hostName = getfqdn().split('.', 1)[0]

            if '.' in dbNode.name:
                nodeDomain = dbNode.name.split('.', 1)[1]

                priInstaller = hostName + '.%s' % (nodeDomain)
            else:
                priInstaller = hostName

            p.setValue(priInstaller)

            globalParameters.append(p)

            provisioningInfo.setGlobalParameters(globalParameters)

            return provisioningInfo
        except TortugaException:
            raise
        except Exception as ex:
            self.getLogger().exception('%s' % ex)
            raise