Commit 76719abd authored by Lu Xu's avatar Lu Xu 👀

add delay yang model support

parent 3db1ebe5
......@@ -16,7 +16,7 @@
[template]
filename = instance.cfg
md5sum = 43f02b7b3552d0d657fa7dbf43ce20a5
md5sum = 18f5c6627308068131d0df3489c4b98d
[template-ors]
filename = instance-ors.cfg
......@@ -52,7 +52,11 @@ md5sum = bc5d82b8737b6990674b280ef2774be7
[ru_lopcomm_ncclient_common.py]
_update_hash_filename_ = ru/lopcomm/ncclient_common.py
md5sum = 8dbe6a48fc0fca4f0cbd0c746be1aeda
md5sum = 5cc878f4c596335a1b6d90e1c03b53a5
[ru_lopcomm_delay.jinja2.py]
_update_hash_filename_ = ru/lopcomm/delay.jinja2.py
md5sum = ac284ce07181d3c5d1a5f4fc7cdb2304
[ru_lopcomm_stats.jinja2.py]
_update_hash_filename_ = ru/lopcomm/stats.jinja2.py
......
......@@ -161,6 +161,7 @@ extra-context =
raw ru_lopcomm_stats_template ${ru_lopcomm_stats.jinja2.py:target}
raw ru_lopcomm_config_template ${ru_lopcomm_config.jinja2.py:target}
raw ru_lopcomm_software_template ${ru_lopcomm_software.jinja2.py:target}
raw ru_lopcomm_delay_template ${ru_lopcomm_delay.jinja2.py:target}
raw ru_lopcomm_reset_info_template ${ru_lopcomm_reset-info.jinja2.py:target}
raw ru_lopcomm_reset_template ${ru_lopcomm_reset.jinja2.py:target}
raw ru_lopcomm_CreateProcessingEle_template ${ru_lopcomm_CreateProcessingEle.jinja2.xml:target}
......@@ -217,6 +218,7 @@ extra-context =
raw ru_lopcomm_stats_template ${ru_lopcomm_stats.jinja2.py:target}
raw ru_lopcomm_config_template ${ru_lopcomm_config.jinja2.py:target}
raw ru_lopcomm_software_template ${ru_lopcomm_software.jinja2.py:target}
raw ru_lopcomm_delay_template ${ru_lopcomm_delay.jinja2.py:target}
raw ru_lopcomm_reset_info_template ${ru_lopcomm_reset-info.jinja2.py:target}
raw ru_lopcomm_reset_template ${ru_lopcomm_reset.jinja2.py:target}
raw ru_lopcomm_CreateProcessingEle_template ${ru_lopcomm_CreateProcessingEle.jinja2.xml:target}
......
......@@ -7,6 +7,9 @@ parts +=
[ru_lopcomm_libinstance.jinja2.cfg]
<= download-base
[ru_lopcomm_delay.jinja2.py]
<= download-base
[ru_lopcomm_config.jinja2.py]
<= download-base
......
#!{{ python_path }}
import time
import json
import xmltodict
import sys
import re
import os
sys.path.append({{ repr(buildout_directory_path) }})
from ncclient_common import LopcommNetconfClient
if __name__ == '__main__':
nc = LopcommNetconfClient(
log_file="{{ log_file }}",
delay_reply_json_log_file="{{ delay_reply_json_log_file }}"
)
while True:
try:
delay_rpc_xml = f"""
<get xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<filter type="xpath" xmlns:o-ran-delay-ru-cpri="urn:o-ran:delay-ru-cpri:1.0" select="/o-ran-delay-ru-cpri:ru-delay-profile" />
</get>
"""
delay_reply_xml = nc.custom_rpc_request(delay_rpc_xml)
nc.logger.info("Getting delay parameters...")
time.sleep(60)
if delay_reply_xml:
nc.logger.info("Got delay parameter.")
delay_data = xmltodict.parse(delay_reply_xml)
nc.delay_reply_json_logger.info('', extra={'data': json.dumps(delay_data)})
break
except Exception as e:
nc.logger.debug('Got exception, waiting 10 seconds before reconnecting...')
nc.logger.debug(str(e))
time.sleep(10)
finally:
nc.close()
......@@ -10,7 +10,7 @@ from ncclient.devices.default import DefaultDeviceHandler
class LopcommNetconfClient:
def __init__(self, log_file, json_log_file=None, cfg_json_log_file=None, supervision_json_log_file=None, ncsession_json_log_file=None, software_json_log_file=None, software_reply_json_log_file=None, supervision_reply_json_log_file=None, testing=False):
def __init__(self, log_file, json_log_file=None, cfg_json_log_file=None, supervision_json_log_file=None, ncsession_json_log_file=None, software_json_log_file=None, software_reply_json_log_file=None, supervision_reply_json_log_file=None, delay_reply_json_log_file=None, testing=False):
self.logger = logging.getLogger('logger')
self.logger.setLevel(logging.DEBUG)
......@@ -82,6 +82,16 @@ class LopcommNetconfClient:
else:
self.software_reply_json_logger = None
if delay_reply_json_log_file:
self.delay_reply_json_logger = logging.getLogger('delay_reply_json_logger')
self.delay_reply_json_logger.setLevel(logging.DEBUG)
delay_reply_json_handler = RotatingFileHandler(delay_reply_json_log_file, maxBytes=100000, backupCount=5)
delay_reply_json_formatter = logging.Formatter('{"time": "%(asctime)s", "log_level": "%(levelname)s", "message": "%(message)s", "data": %(data)s}')
delay_reply_json_handler.setFormatter(delay_reply_json_formatter)
self.delay_reply_json_logger.addHandler(delay_reply_json_handler)
else:
self.delay_reply_json_logger = None
if testing:
return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment