コード例 #1
0
ファイル: updateController.py プロジェクト: joedborg/tortuga
class UpdateController(TortugaController):
    """
    Update controller class.

    """
    actions = [
        {
            'name': 'clusterUpdate',
            'path': '/v1/updates/cluster',
            'action': 'scheduleClusterUpdateRequest',
            'method': ['POST', 'GET'],
        },
    ]

    def __init__(self, app: Application) -> None:
        super().__init__(app)

        self._syncApi = SyncApi()

    @authentication_required()
    @cherrypy.tools.json_out()
    @cherrypy.tools.json_in()
    def scheduleClusterUpdateRequest(self):
        # Could be post or get...
        if cherrypy.request.method == 'POST':
            # POST handler
            return self.scheduleClusterUpdate()

        # GET handler
        return self.getUpdateStatus()

    def scheduleClusterUpdate(self): \
            # pylint: disable=broad-except
        """
        Schedule cluster update
        """

        response = None

        postdata = cherrypy.request.json

        updateReason = postdata['reason'] \
            if 'reason' in postdata else None

        try:
            self._syncApi.scheduleClusterUpdate(updateReason)
        except Exception as ex:
            self.getLogger().exception('scheduleClusterUpdate() failed')
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)

    def getUpdateStatus(self): \
            # pylint: disable=broad-except
        """
        Get cluster update status
        """

        try:
            status = self._syncApi.getUpdateStatus()

            response = {
                'running': status,
            }
        except Exception as ex:
            self.getLogger().exception('getUpdateStatus() failed')
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)
コード例 #2
0
ファイル: updateController.py プロジェクト: ilumb/tortuga
class UpdateController(TortugaController):
    """
    Update controller class.

    """
    actions = [
        {
            'name': 'clusterUpdate',
            'path': '/v1/updates/cluster',
            'action': 'scheduleClusterUpdateRequest',
            'method': ['POST', 'GET'],
        },
    ]

    def __init__(self):
        super(UpdateController, self).__init__()

        self._syncApi = SyncApi()

    @require()
    @cherrypy.tools.json_out()
    @cherrypy.tools.json_in()
    def scheduleClusterUpdateRequest(self):
        # Could be post or get...
        if cherrypy.request.method == 'POST':
            return self.scheduleClusterUpdate()
        else:
            return self.getUpdateStatus()

    def scheduleClusterUpdate(self):
        """ Schedule cluster update. """

        response = None

        postdata = cherrypy.request.json

        updateReason = postdata['reason'] \
            if 'reason' in postdata else None

        try:
            self._syncApi.scheduleClusterUpdate(updateReason)
        except Exception as ex:
            self.getLogger().error('%s' % ex)
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)

    def getUpdateStatus(self):
        """ Get cluster update status. """

        try:
            status = self._syncApi.getUpdateStatus()

            response = {
                'running': status,
            }
        except Exception as ex:
            self.getLogger().error('%s' % ex)
            self.handleException(ex)
            response = self.errorResponse(str(ex))

        return self.formatResponse(response)