-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sonic-cfggen supports hwsku parameter #1631
Changes from all commits
4444249
a41ad22
95353c8
775aea9
798424f
6da1feb
46cedda
6aa03c5
fd2998a
2df0f3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"DEVICE_METADATA": {{ DEVICE_METADATA | tojson }}, | ||
"PORT": {{ PORT | tojson }}, | ||
"VLAN": { | ||
"Vlan1000": { | ||
"vlanid": "1000" | ||
} | ||
}, | ||
{% set ns = {'firstPrinted': False} -%} | ||
"VLAN_MEMBER": { | ||
{%- for port in PORT -%} | ||
{%- if ns.firstPrinted %},{% endif %} | ||
|
||
"Vlan1000|{{ port }}": { | ||
"tagging_mode": "untagged" | ||
} | ||
{%- if ns.update({'firstPrinted': True}) %}{% endif -%} | ||
{%- endfor %} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Examples: | |
See usage string for detail description for arguments. | ||
""" | ||
|
||
from __future__ import print_function | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's it for? Print to stderr? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To write 'print' in the most compatible style, for example python3. In reply to: 183192730 [](ancestors = 183192730) |
||
import sys | ||
import os.path | ||
import argparse | ||
|
@@ -26,6 +27,7 @@ from functools import partial | |
from minigraph import minigraph_encoder | ||
from minigraph import parse_xml | ||
from minigraph import parse_device_desc_xml | ||
from portconfig import get_port_config | ||
from sonic_platform import get_machine_info | ||
from sonic_platform import get_platform_info | ||
from sonic_platform import get_system_mac | ||
|
@@ -140,7 +142,8 @@ def main(): | |
group = parser.add_mutually_exclusive_group() | ||
group.add_argument("-m", "--minigraph", help="minigraph xml file", nargs='?', const='/etc/sonic/minigraph.xml') | ||
group.add_argument("-M", "--device-description", help="device description xml file") | ||
parser.add_argument("-p", "--port-config", help="port config file, used with -m") | ||
group.add_argument("-k", "--hwsku", help="HwSKU") | ||
parser.add_argument("-p", "--port-config", help="port config file, used with -m or -k", nargs='?', const=None) | ||
parser.add_argument("-y", "--yaml", help="yaml file that contains additional variables", action='append', default=[]) | ||
parser.add_argument("-j", "--json", help="json file that contains additional variables", action='append', default=[]) | ||
parser.add_argument("-a", "--additional-data", help="addition data, in json string") | ||
|
@@ -162,7 +165,18 @@ def main(): | |
db_kwargs['unix_socket_path'] = args.redis_unix_sock_file | ||
|
||
data = {} | ||
hwsku = args.hwsku | ||
|
||
if hwsku is not None: | ||
hardware_data = {'DEVICE_METADATA': {'localhost': { | ||
'hwsku': hwsku | ||
}}} | ||
deep_update(data, hardware_data) | ||
(ports, _) = get_port_config(hwsku, platform, args.port_config) | ||
if not ports: | ||
print('Failed to get port config', file=sys.stderr) | ||
sys.exit(1) | ||
deep_update(data, {'PORT': ports}) | ||
|
||
if args.minigraph != None: | ||
minigraph = args.minigraph | ||
|
@@ -172,10 +186,7 @@ def main(): | |
else: | ||
deep_update(data, parse_xml(minigraph, platform)) | ||
else: | ||
if args.port_config != None: | ||
deep_update(data, parse_xml(minigraph, port_config_file=args.port_config)) | ||
else: | ||
deep_update(data, parse_xml(minigraph)) | ||
deep_update(data, parse_xml(minigraph, port_config_file=args.port_config)) | ||
|
||
if args.device_description != None: | ||
deep_update(data, parse_device_desc_xml(args.device_description)) | ||
|
@@ -216,22 +227,22 @@ def main(): | |
for attr in ['ip', 'network', 'prefixlen', 'netmask']: | ||
env.filters[attr] = partial(prefix_attr, attr) | ||
template = env.get_template(template_file) | ||
print template.render(sort_data(data)) | ||
print(template.render(sort_data(data))) | ||
|
||
if args.var != None: | ||
template = jinja2.Template('{{' + args.var + '}}') | ||
print template.render(data) | ||
print(template.render(data)) | ||
|
||
if args.var_json != None: | ||
print json.dumps(FormatConverter.to_serialized(data[args.var_json]), indent=4, cls=minigraph_encoder) | ||
print(json.dumps(FormatConverter.to_serialized(data[args.var_json]), indent=4, cls=minigraph_encoder)) | ||
|
||
if args.write_to_db: | ||
configdb = ConfigDBConnector(**db_kwargs) | ||
configdb.connect(False) | ||
configdb.mod_config(FormatConverter.output_to_db(data)) | ||
|
||
if args.print_data: | ||
print json.dumps(FormatConverter.to_serialized(data), indent=4, cls=minigraph_encoder) | ||
print(json.dumps(FormatConverter.to_serialized(data), indent=4, cls=minigraph_encoder)) | ||
|
||
|
||
if __name__ == "__main__": | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need management port configuration. #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
"DEVICE_METADATA": {"localhost": {"hwsku": "Mellanox-SN2700"}}, | ||
"PORT": {"Ethernet0": {"alias": "fortyGigE0/0", "lanes": "29,30,31,32"}, "Ethernet100": {"alias": "fortyGigE0/100", "lanes": "125,126,127,128"}, "Ethernet104": {"alias": "fortyGigE0/104", "lanes": "85,86,87,88"}, "Ethernet108": {"alias": "fortyGigE0/108", "lanes": "81,82,83,84"}, "Ethernet112": {"alias": "fortyGigE0/112", "lanes": "89,90,91,92"}, "Ethernet116": {"alias": "fortyGigE0/116", "lanes": "93,94,95,96"}, "Ethernet12": {"alias": "fortyGigE0/12", "lanes": "33,34,35,36"}, "Ethernet120": {"alias": "fortyGigE0/120", "lanes": "97,98,99,100"}, "Ethernet124": {"alias": "fortyGigE0/124", "lanes": "101,102,103,104"}, "Ethernet16": {"alias": "fortyGigE0/16", "lanes": "41,42,43,44"}, "Ethernet20": {"alias": "fortyGigE0/20", "lanes": "45,46,47,48"}, "Ethernet24": {"alias": "fortyGigE0/24", "lanes": "5,6,7,8"}, "Ethernet28": {"alias": "fortyGigE0/28", "lanes": "1,2,3,4"}, "Ethernet32": {"alias": "fortyGigE0/32", "lanes": "9,10,11,12"}, "Ethernet36": {"alias": "fortyGigE0/36", "lanes": "13,14,15,16"}, "Ethernet4": {"alias": "fortyGigE0/4", "lanes": "25,26,27,28"}, "Ethernet40": {"alias": "fortyGigE0/40", "lanes": "21,22,23,24"}, "Ethernet44": {"alias": "fortyGigE0/44", "lanes": "17,18,19,20"}, "Ethernet48": {"alias": "fortyGigE0/48", "lanes": "49,50,51,52"}, "Ethernet52": {"alias": "fortyGigE0/52", "lanes": "53,54,55,56"}, "Ethernet56": {"alias": "fortyGigE0/56", "lanes": "61,62,63,64"}, "Ethernet60": {"alias": "fortyGigE0/60", "lanes": "57,58,59,60"}, "Ethernet64": {"alias": "fortyGigE0/64", "lanes": "65,66,67,68"}, "Ethernet68": {"alias": "fortyGigE0/68", "lanes": "69,70,71,72"}, "Ethernet72": {"alias": "fortyGigE0/72", "lanes": "77,78,79,80"}, "Ethernet76": {"alias": "fortyGigE0/76", "lanes": "73,74,75,76"}, "Ethernet8": {"alias": "fortyGigE0/8", "lanes": "37,38,39,40"}, "Ethernet80": {"alias": "fortyGigE0/80", "lanes": "105,106,107,108"}, "Ethernet84": {"alias": "fortyGigE0/84", "lanes": "109,110,111,112"}, "Ethernet88": {"alias": "fortyGigE0/88", "lanes": "117,118,119,120"}, "Ethernet92": {"alias": "fortyGigE0/92", "lanes": "113,114,115,116"}, "Ethernet96": {"alias": "fortyGigE0/96", "lanes": "121,122,123,124"}}, | ||
"VLAN": { | ||
"Vlan1000": { | ||
"vlanid": "1000" | ||
} | ||
}, | ||
"VLAN_MEMBER": { | ||
"Vlan1000|Ethernet0": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet4": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet8": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet12": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet16": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet20": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet24": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet28": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet32": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet36": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet40": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet44": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet48": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet52": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet56": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet60": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet64": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet68": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet72": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet76": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet80": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet84": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet88": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet92": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet96": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet100": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet104": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet108": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet112": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet116": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet120": { | ||
"tagging_mode": "untagged" | ||
}, | ||
"Vlan1000|Ethernet124": { | ||
"tagging_mode": "untagged" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we install this file with sonic-config-engine? Shouldn't it go with base image? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is only used by sonic-cfggen, and tested here. So no need to move.
In reply to: 183192364 [](ancestors = 183192364)