[sonic-yang]: introduce yang template for cvl yang (#8880)

Signed-off-by: Guohan Lu <lguohan@gmail.com>
This commit is contained in:
Guohan Lu 2021-11-06 11:35:55 -07:00 committed by GitHub
parent 97d70e3e8b
commit a2d0dbe604
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 0 deletions

View File

@ -1,9 +1,44 @@
import shutil
import os
import glob
import jinja2
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py
# read me
with open('README.rst') as readme_file:
readme = readme_file.read()
class my_build_py(build_py):
def run(self):
if not self.dry_run:
print("hehe")
if not os.path.exists("./yang-models"):
os.makedirs("./yang-models")
if not os.path.exists("./cvlyang-models"):
os.makedirs("./cvlyang-models")
# copy non-template yang model to internal yang model directory
for fname in glob.glob("./yang-models/*.yang"):
bfname = os.path.basename(fname)
shutil.copyfile("./yang-models/{}".format(bfname), "./cvlyang-models/{}".format(bfname))
# templated yang models
env = jinja2.Environment(loader=jinja2.FileSystemLoader('./yang-templates/'), trim_blocks=True)
for fname in glob.glob("./yang-templates/*.yang.j2"):
bfname = os.path.basename(fname)
template = env.get_template(bfname)
yang_model = template.render(yang_model_type="py")
cvlyang_model = template.render(yang_model_type="cvl")
with open("./yang-models/{}".format(bfname.strip(".j2")), 'w') as f:
f.write(yang_model)
with open("./cvlyang-models/{}".format(bfname.strip(".j2")), 'w') as f:
f.write(cvlyang_model)
build_py.run(self)
setup(
author="lnos-coders",
author_email='lnos-coders@linkedin.com',
@ -40,6 +75,7 @@ setup(
py_modules=[],
packages=find_packages(),
version='1.0',
cmdclass={'build_py': my_build_py},
data_files=[
('yang-models', ['./yang-models/sonic-acl.yang',
'./yang-models/sonic-bgp-common.yang',
@ -87,6 +123,51 @@ setup(
'./yang-models/sonic-pfc-priority-queue-map.yang',
'./yang-models/sonic-pfc-priority-priority-group-map.yang',
'./yang-models/sonic-port-qos-map.yang']),
('cvlyang-models', ['./cvlyang-models/sonic-acl.yang',
'./cvlyang-models/sonic-bgp-common.yang',
'./cvlyang-models/sonic-bgp-global.yang',
'./cvlyang-models/sonic-bgp-neighbor.yang',
'./cvlyang-models/sonic-bgp-peergroup.yang',
'./cvlyang-models/sonic-breakout_cfg.yang',
'./cvlyang-models/sonic-copp.yang',
'./cvlyang-models/sonic-crm.yang',
'./cvlyang-models/sonic-device_metadata.yang',
'./cvlyang-models/sonic-device_neighbor.yang',
'./cvlyang-models/sonic-extension.yang',
'./cvlyang-models/sonic-flex_counter.yang',
'./cvlyang-models/sonic-feature.yang',
'./cvlyang-models/sonic-interface.yang',
'./cvlyang-models/sonic-loopback-interface.yang',
'./cvlyang-models/sonic-mgmt_interface.yang',
'./cvlyang-models/sonic-mgmt_port.yang',
'./cvlyang-models/sonic-mgmt_vrf.yang',
'./cvlyang-models/sonic-ntp.yang',
'./cvlyang-models/sonic-nat.yang',
'./cvlyang-models/sonic-port.yang',
'./cvlyang-models/sonic-portchannel.yang',
'./cvlyang-models/sonic-pfcwd.yang',
'./cvlyang-models/sonic-route-common.yang',
'./cvlyang-models/sonic-route-map.yang',
'./cvlyang-models/sonic-routing-policy-sets.yang',
'./cvlyang-models/sonic-sflow.yang',
'./cvlyang-models/sonic-system-aaa.yang',
'./cvlyang-models/sonic-system-tacacs.yang',
'./cvlyang-models/sonic-types.yang',
'./cvlyang-models/sonic-versions.yang',
'./cvlyang-models/sonic-vlan.yang',
'./cvlyang-models/sonic-vrf.yang',
'./cvlyang-models/sonic-warm-restart.yang',
'./cvlyang-models/sonic-lldp.yang',
'./cvlyang-models/sonic-scheduler.yang',
'./cvlyang-models/sonic-wred-profile.yang',
'./cvlyang-models/sonic-queue.yang',
'./cvlyang-models/sonic-dscp-tc-map.yang',
'./cvlyang-models/sonic-dot1p-tc-map.yang',
'./cvlyang-models/sonic-tc-priority-group-map.yang',
'./cvlyang-models/sonic-tc-queue-map.yang',
'./cvlyang-models/sonic-pfc-priority-queue-map.yang',
'./cvlyang-models/sonic-pfc-priority-priority-group-map.yang',
'./cvlyang-models/sonic-port-qos-map.yang']),
],
zip_safe=False,
)

View File

@ -1,3 +1,8 @@
{% if yang_model_type == "cvl" %}
/* this is sonic cvl yang model */
{% else %}
/* this is sonic py yang model */
{% endif %}
module sonic-acl {
yang-version 1.1;