コード例 #1
0
ファイル: cli_rest.py プロジェクト: haesunyoum/hs_sona
def run(evt, conn_evt):
    global global_conn_evt
    global global_evt
    LOG.debug_log("--- REST Server Start --- ")

    global_evt = evt
    global_conn_evt = conn_evt

    try:
        server_address = ("", CONFIG.get_rest_port())
        httpd = HTTPServer(server_address, RestHandler)
        httpd.serve_forever()
    except:
        LOG.exception_err_write()
コード例 #2
0
    def display_event(cls, cnt=20):
        try:
            cmd = 'tail -n ' + str(cnt) + ' log/event_history.log'
            result = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True)
            output, error = result.communicate()

            if result.returncode != 0:
                LOG.debug_log("Cmd Fail, cause => %s", error)
                print 'Failed to load file'
            else:
                print '\n * Only the last ' + str(cnt) + ' logs are printed.'
                print ' * Please refer to the log file for details. (path = log/event_history.log)\n'
                print output
        except:
            LOG.exception_err_write()
コード例 #3
0
def listen_disconnect_evt(evt, rest_evt):
    global evt_thread

    while SYS.get_sys_thr_flag():
        try:
            evt.wait(1)

            if evt.is_set():
                LOG.debug_log('Get disconnect event')
                evt.clear()
                SYS.disconnect_type = 'disconnect'

                if SYS.get_sys_redraw_flag():
                    SCREEN.draw_event(SYS.disconnect_type)
                    SCREEN.get_screen().clear()
                    SCREEN.screen_exit()

                print '\nCheck monitoring server.'
                os.killpg(os.getpid(), signal.SIGKILL)
                #os.kill(os.getpid(), signal.SIGKILL)

            time.sleep(1)

            rest_evt.wait(1)

            if rest_evt.is_set():
                LOG.debug_log('Get rest error event')
                rest_evt.clear()
                SYS.disconnect_type = 'rest_warn'

                if SYS.get_sys_redraw_flag():
                    SCREEN.draw_event(SYS.disconnect_type)
                    SCREEN.get_screen().clear()
                    SCREEN.screen_exit()

                print '\nCheck client rest server.'
                os.killpg(os.getpid(), signal.SIGKILL)
                #os.kill(os.getpid(), signal.SIGKILL)

            time.sleep(1)
        except:
            LOG.exception_err_write()
コード例 #4
0
def run(evt, conn_evt, rest_evt, history_log):
    global global_history_log
    global global_conn_evt
    global global_evt

    global_history_log = history_log
    global_evt = evt
    global_conn_evt = conn_evt

    LOG.debug_log("--- REST Server Start --- ")
    global_history_log.write_history("--- Event History Start ---")

    try:
        server_address = ("", CONFIG.get_rest_port())
        httpd = HTTPServer(server_address, RestHandler)
        httpd.serve_forever()

    except:
        LOG.exception_err_write()
        # occure rest server err event
        rest_evt.set()
コード例 #5
0
def check_system():
    try:
        # inquiry onos info
        res_code, sys_info = CLI.req_sys_info()

        if res_code != 200:
            SYS.disconnect_type = 'disconnect'
            SCREEN.draw_event(SYS.disconnect_type)
            LOG.debug_log(
                '[SYSTEM_CHECK_THREAD] Rest server does not respond to the request. RES_CODE = ' + str(res_code))
            return

        ret = SYS.changed_sys_info(sys_info)

        if SYS.get_sys_redraw_flag():
            if ret is True:
                SCREEN.draw_system(menu_list)
                SCREEN.draw_event(SYS.disconnect_type)
            else:
                SCREEN.draw_refresh_time(menu_list)
    except:
        LOG.exception_err_write()
コード例 #6
0
    def do_POST(self):
        global global_evt
        global global_conn_evt
        global global_history_log

        try:
            request_sz = int(self.headers["Content-length"])
            request_str = self.rfile.read(request_sz)
            request_obj = json.loads(request_str)

            LOG.debug_log('[REST-SERVER] CLIENT INFO = ' +
                          str(self.client_address))
            LOG.debug_log('[REST-SERVER] RECV HEADER = \n' + str(self.headers))
            LOG.debug_log('[REST-SERVER] RECV BODY = \n' +
                          json.dumps(request_obj, sort_keys=True, indent=4))

            if self.path.startswith('/test'):
                t_id = request_obj['transaction_id']

                if os.path.exists('log/flowtrace_' + t_id):
                    os.remove('log/flowtrace_' + t_id)
                result_file = open('log/flowtrace_' + t_id, 'w')
                result_file.write(str(request_obj))
                result_file.close()
            elif self.path.startswith('/traffictest'):
                t_id = request_obj['transaction_id']

                if os.path.exists('log/traffictest_' + t_id):
                    os.remove('log/traffictest_' + t_id)
                result_file = open('log/traffictest_' + t_id, 'w')
                result_file.write(str(request_obj))
                result_file.close()

            elif self.headers.getheader('Authorization') is None:
                LOG.debug_log('[REST-SERVER] no auth header received')

            elif not self.path.startswith('/event'):
                LOG.debug_log('[REST-SERVER] ' + self.path + ' not found')

            elif self.auth_pw(self.headers.getheader('Authorization')):
                global_history_log.write_history('[%s][%s][%s][%s] %s',
                                                 request_obj['system'],
                                                 request_obj['item'],
                                                 request_obj['grade'],
                                                 request_obj['pre_grade'],
                                                 request_obj['reason'])

                if request_obj['system'] == 'sonawatcher' and request_obj[
                        'item'] == 'SONAWATCHER_DISCONNECT':
                    global_conn_evt.set()
                    LOG.debug_log('[REST-SERVER] ' + request_obj['reason'])
                else:
                    global_evt.set()
            else:
                LOG.debug_log('[REST-SERVER] not authenticated')
        except:
            LOG.exception_err_write()
コード例 #7
0
ファイル: cli_rest.py プロジェクト: sonaproject/slsnet
    def do_POST(self):
        global global_evt
        global global_conn_evt
        global global_history_log

        try:
            request_sz = int(self.headers["Content-length"])
            request_str = self.rfile.read(request_sz)
            body = json.loads(request_str)

            LOG.debug_log('[REST-SERVER] CLIENT INFO = ' +
                          str(self.client_address))
            LOG.debug_log('[REST-SERVER] RECV HEADER = \n' + str(self.headers))
            LOG.debug_log('[REST-SERVER] RECV BODY = \n' +
                          json.dumps(body, sort_keys=True, indent=4))

            if self.headers.getheader('Authorization') is None:
                LOG.debug_log('[REST-SERVER] no auth header received')

            elif not self.path.startswith('/event'):
                LOG.debug_log('[REST-SERVER] ' + self.path + ' not found')

            elif self.auth_pw(self.headers.getheader('Authorization')):
                reason_str = ''
                if type(body['reason']) == list:
                    if len(body['reason']) > 0:
                        reason_str = '\n-- ' + '\n-- '.join(body['reason'])
                else:
                    reason_str = str(body['reason'])
                global_history_log.write_history(
                    '[%s] %s %s changed from %s to %s %s', body['time'],
                    body['system'], body['item'], body['pre_grade'],
                    body['grade'], reason_str)

                if body['system'] == 'SimpleFabricWatchd' and body[
                        'item'] == 'Daemon':
                    global_conn_evt.set()
                    LOG.debug_log('[REST-SERVER] ' + reason_str)
                else:
                    global_evt.set()
            else:
                LOG.debug_log('[REST-SERVER] not authenticated')
        except:
            LOG.exception_err_write()
コード例 #8
0
ファイル: cli_rest.py プロジェクト: haesunyoum/hs_sona
    def do_POST(self):
        global global_evt
        global global_conn_evt

        request_sz = int(self.headers["Content-length"])
        request_str = self.rfile.read(request_sz)
        request_obj = json.loads(request_str)

        LOG.debug_log('[REST-SERVER] CLIENT INFO = ' +
                      str(self.client_address))
        LOG.debug_log('[REST-SERVER] RECV BODY = \n' +
                      json.dumps(request_obj, sort_keys=True, indent=4))

        if self.headers.getheader('Authorization') is None:
            LOG.debug_log('[REST-SERVER] no auth header received')

        elif not self.path.startswith('/event'):
            LOG.debug_log('[REST-SERVER] ' + self.path + ' not found')

        elif self.auth_pw(self.headers.getheader('Authorization')):
            if request_obj['system'] == 'sonawatcher' and request_obj[
                    'item'] == 'disconnect':
                global_conn_evt.set()
                LOG.debug_log('[REST-SERVER] ' + request_obj['desc'])
            else:
                global_evt.set()
        else:
            LOG.debug_log('[REST-SERVER] not authenticated')