Commit 520f7e80 authored by Lu Xu's avatar Lu Xu 👀

software/ors-amarisoft: software management WIP

parent 8244c24b
...@@ -36,7 +36,7 @@ md5sum = b34fe47a73890097fbc6ea6374aeb38d ...@@ -36,7 +36,7 @@ md5sum = b34fe47a73890097fbc6ea6374aeb38d
[template-enb] [template-enb]
_update_hash_filename_ = instance-enb.jinja2.cfg _update_hash_filename_ = instance-enb.jinja2.cfg
md5sum = 3f7416ff8d012de487479e0372c515a3 md5sum = a7186816e468937baafa211ca67984ee
[template-gnb] [template-gnb]
_update_hash_filename_ = instance-gnb.jinja2.cfg _update_hash_filename_ = instance-gnb.jinja2.cfg
......
...@@ -11,6 +11,7 @@ parts = ...@@ -11,6 +11,7 @@ parts =
lopcomm-firmware-dl lopcomm-firmware-dl
lopcomm-rrh-stats-service lopcomm-rrh-stats-service
lopcomm-rrh-config-template lopcomm-rrh-config-template
lopcomm-rrh-software-template
lopcomm-cu-config lopcomm-cu-config
check-lopcomm-vswr.py check-lopcomm-vswr.py
check-lopcomm-pa-current.py check-lopcomm-pa-current.py
...@@ -269,6 +270,23 @@ mode = 0775 ...@@ -269,6 +270,23 @@ mode = 0775
url = {{ lopcomm_rrh_config_template }} url = {{ lopcomm_rrh_config_template }}
output = ${directory:script}/lopcomm-rrh-config.py output = ${directory:script}/lopcomm-rrh-config.py
[lopcomm-rrh-software-template]
recipe = slapos.recipe.template:jinja2
extensions = jinja2.ext.do
log-output = ${directory:var}/log/lopcomm-rrh-software.log
context =
section directory directory
section slap_configuration slap-configuration
key slapparameter_dict slap-configuration:configuration
key log_file :log-output
raw testing {{ slapparameter_dict.get("testing", False) }}
raw python_path {{ buildout_directory}}/bin/pythonwitheggs
raw software_download {{ software_download_template }}
import netaddr netaddr
mode = 0775
url = {{ lopcomm_rrh_software_template }}
output = ${directory:script}/lopcomm-rrh-software.py
[amarisoft-stats-service] [amarisoft-stats-service]
recipe = slapos.cookbook:wrapper recipe = slapos.cookbook:wrapper
command-line = ${amarisoft-stats-template:output} command-line = ${amarisoft-stats-template:output}
......
#!{{ python_path }}
import logging
import time
import xmltodict
from logging.handlers import RotatingFileHandler
from ncclient import manager
from ncclient.operations import RPCError
from ncclient.xml_ import *
from ncclient.devices.default import DefaultDeviceHandler
class LopcommNetconfClient:
def __init__(self):
log_file = "{{ log_file }}"
self.logger = logging.getLogger('logger')
self.logger.setLevel(logging.DEBUG)
handler = RotatingFileHandler(log_file, maxBytes=100000, backupCount=5)
self.logger.addHandler(handler)
formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
handler.setFormatter(formatter)
if {{ testing }}:
return
def connect(self, host, port, user, password):
if {{ testing }}:
return
self.address = (host, port)
self.logger.info('Connecting to %s, user %s...' % (self.address, user))
self.conn = manager.connect(host=host,
port=port,
username=user,
password=password,
timeout=1800,
device_params={
'name': 'default'
},
hostkey_verify=False)
self.logger.info('Connection to %s successful' % (self.address,))
def edit_config(self, config_files):
for config_file in config_files:
with open(config_file) as f:
config_xml = f.read()
try:
self.logger.info('Sending software management RPC request...')
self.conn.edit_config(target='running', config=config_xml)
self.logger.info('Software management RPC request sent successfully')
except RPCError as e:
self.logger.error('Error sending software management RPC request: %s' % e)
def close(self):
# Close not compatible between ncclient and netconf server
#self.conn.close()
pass
if __name__ == '__main__':
nc = LopcommNetconfClient()
while True:
try:
nc.connect("{{ netaddr.IPAddress(slap_configuration.get('tap-ipv6-gateway', '')) }}", 830, "oranuser", "oranpassword")
nc.edit_config(["{{ CreateProcessingEle_template }}", "{{ cu_config_template }}"])
break
except Exception as e:
nc.logger.debug('Got exception, waiting 10 seconds before reconnecting...')
nc.logger.debug(e)
time.sleep(10)
finally:
nc.close()
<software-install xmlns="urn:o-ran:software-management:1.0"> <software-install xmlns="urn:o-ran:software-management:1.0">
<slot-name>slot-1</slot-name> <slot-name>slot-2</slot-name>
<file-names>PR.PR46Q1LNV1001.1.tar.gz</file-names> <file-names>PR.PRM61C70V1002.K010927.tar.g</file-names>
</software-install> </software-install>
\ No newline at end of file
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