[sonic-cfggen] Remove machine.conf info and add get_system_mac support (#1397)
[sonic-cfggen] Remove machine.conf info and add get_system_mac support
This commit is contained in:
parent
f657df7588
commit
04b694454a
@ -6,7 +6,7 @@ sonic-cfggen -d -t /usr/share/sonic/templates/switch.json.j2 > /etc/swss/config.
|
|||||||
sonic-cfggen -d -t /usr/share/sonic/templates/ipinip.json.j2 > /etc/swss/config.d/ipinip.json
|
sonic-cfggen -d -t /usr/share/sonic/templates/ipinip.json.j2 > /etc/swss/config.d/ipinip.json
|
||||||
sonic-cfggen -d -t /usr/share/sonic/templates/ports.json.j2 > /etc/swss/config.d/ports.json
|
sonic-cfggen -d -t /usr/share/sonic/templates/ports.json.j2 > /etc/swss/config.d/ports.json
|
||||||
|
|
||||||
export platform=`sonic-cfggen -v platform`
|
export platform=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
|
||||||
|
|
||||||
rm -f /var/run/rsyslogd.pid
|
rm -f /var/run/rsyslogd.pid
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ def log_error(msg):
|
|||||||
|
|
||||||
# Determine whether we are running on an Arista platform
|
# Determine whether we are running on an Arista platform
|
||||||
def is_platform_arista():
|
def is_platform_arista():
|
||||||
proc = subprocess.Popen(["sonic-cfggen", "-v", "platform"],
|
proc = subprocess.Popen(["sonic-cfggen", "-H", "-v", "DEVICE_METADATA.localhost.platform"],
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
|
||||||
(stdout, stderr) = proc.communicate()
|
(stdout, stderr) = proc.communicate()
|
||||||
|
@ -20,7 +20,7 @@ function postStartAction()
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Obtain our platform as we will mount directories with these names in each docker
|
# Obtain our platform as we will mount directories with these names in each docker
|
||||||
PLATFORM=`sonic-cfggen -v platform`
|
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
|
||||||
|
|
||||||
{%- if docker_container_name == "database" %}
|
{%- if docker_container_name == "database" %}
|
||||||
# Don't mount HWSKU in {{docker_container_name}} container.
|
# Don't mount HWSKU in {{docker_container_name}} container.
|
||||||
|
@ -30,7 +30,7 @@ ExecStartPre=/usr/bin/mst start
|
|||||||
ExecStartPre=/usr/bin/mlnx-fw-upgrade.sh
|
ExecStartPre=/usr/bin/mlnx-fw-upgrade.sh
|
||||||
ExecStartPre=/etc/init.d/sxdkernel start
|
ExecStartPre=/etc/init.d/sxdkernel start
|
||||||
ExecStartPre=/sbin/modprobe i2c-dev
|
ExecStartPre=/sbin/modprobe i2c-dev
|
||||||
ExecStartPre=/bin/bash -c "/usr/share/sonic/device/$(sonic-cfggen -v platform)/hw-management start"
|
ExecStartPre=/bin/bash -c "/usr/share/sonic/device/$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)/hw-management start"
|
||||||
{% elif sonic_asic_platform == 'cavium' %}
|
{% elif sonic_asic_platform == 'cavium' %}
|
||||||
ExecStartPre=/etc/init.d/xpnet.sh start
|
ExecStartPre=/etc/init.d/xpnet.sh start
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -43,7 +43,7 @@ ExecStop=/usr/bin/{{docker_container_name}}.sh stop
|
|||||||
ExecStopPost=/usr/bin/syncd.sh stop
|
ExecStopPost=/usr/bin/syncd.sh stop
|
||||||
|
|
||||||
{% if sonic_asic_platform == 'mellanox' %}
|
{% if sonic_asic_platform == 'mellanox' %}
|
||||||
ExecStopPost=/bin/bash -c "/usr/share/sonic/device/$(sonic-cfggen -v platform)/hw-management stop"
|
ExecStopPost=/bin/bash -c "/usr/share/sonic/device/$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)/hw-management stop"
|
||||||
ExecStopPost=/etc/init.d/sxdkernel stop
|
ExecStopPost=/etc/init.d/sxdkernel stop
|
||||||
ExecStopPost=/usr/bin/mst stop
|
ExecStopPost=/usr/bin/mst stop
|
||||||
{% elif sonic_asic_platform == 'cavium' %}
|
{% elif sonic_asic_platform == 'cavium' %}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
# Only start control plance ACL manager daemon if not an Arista platform.
|
# Only start control plance ACL manager daemon if not an Arista platform.
|
||||||
# Arista devices will use their own service ACL manager daemon(s) instead.
|
# Arista devices will use their own service ACL manager daemon(s) instead.
|
||||||
if [ "$(sonic-cfggen -v "platform" | grep -c "arista")" -gt 0 ]; then
|
if [ "$(sonic-cfggen -H -v "DEVICE_METADATA.localhost.platform" | grep -c "arista")" -gt 0 ]; then
|
||||||
echo "Not starting caclmgrd - unsupported platform"
|
echo "Not starting caclmgrd - unsupported platform"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
@ -79,22 +79,9 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then
|
|||||||
firsttime_exit
|
firsttime_exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# setup initial switch mac
|
if [ ! -f /etc/sonic/init_cfg.json ]; then
|
||||||
SONIC_ASIC_TYPE=$(sonic-cfggen -y /etc/sonic/sonic_version.yml -v asic_type)
|
# Generate an empty init_cfg.json
|
||||||
SYSTEM_MAC_ADDRESS=$(ip link show eth0 | grep ether | awk '{print $2}')
|
echo '{}' > /etc/sonic/init_cfg.json
|
||||||
|
|
||||||
# Align last byte of MAC if necessary
|
|
||||||
if [ "$SONIC_ASIC_TYPE" = "mellanox" ] || [ "$SONIC_ASIC_TYPE" = "centec" ]; then
|
|
||||||
last_byte=$(python -c "print '$SYSTEM_MAC_ADDRESS'[-2:]")
|
|
||||||
aligned_last_byte=$(python -c "print format(int(int('$last_byte', 16) & 0b11000000), '02x')") # put mask and take away the 0x prefix
|
|
||||||
SYSTEM_MAC_ADDRESS=$(python -c "print '$SYSTEM_MAC_ADDRESS'[:-2] + '$aligned_last_byte'") # put aligned byte into the end of MAC
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f /etc/sonic/init_cfg.json ]; then
|
|
||||||
sonic-cfggen -j /etc/sonic/init_cfg.json -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /tmp/init_cfg.json
|
|
||||||
mv /tmp/init_cfg.json /etc/sonic/init_cfg.json
|
|
||||||
else
|
|
||||||
sonic-cfggen -a '{"DEVICE_METADATA":{"localhost": {"mac": "'$SYSTEM_MAC_ADDRESS'"}}}' --print-data > /etc/sonic/init_cfg.json
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Try to take old configuration saved during installation
|
# Try to take old configuration saved during installation
|
||||||
@ -102,20 +89,20 @@ if [ -f /host/image-$sonic_version/platform/firsttime ]; then
|
|||||||
rm -f /host/old_config/sonic_version.yml
|
rm -f /host/old_config/sonic_version.yml
|
||||||
mv -f /host/old_config/* /etc/sonic/
|
mv -f /host/old_config/* /etc/sonic/
|
||||||
if [ ! -f /etc/sonic/config_db.json ]; then
|
if [ ! -f /etc/sonic/config_db.json ]; then
|
||||||
sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
||||||
fi
|
fi
|
||||||
elif [ -f /host/minigraph.xml ]; then
|
elif [ -f /host/minigraph.xml ]; then
|
||||||
mv /host/minigraph.xml /etc/sonic/
|
mv /host/minigraph.xml /etc/sonic/
|
||||||
# Combine information in minigraph and init_cfg.json to form initiate config DB dump file.
|
# Combine information in minigraph and init_cfg.json to form initiate config DB dump file.
|
||||||
# TODO: After moving all information from minigraph to DB, sample config DB dump should be provide
|
# TODO: After moving all information from minigraph to DB, sample config DB dump should be provide
|
||||||
sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
||||||
else
|
else
|
||||||
# Use default minigraph.xml
|
# Use default minigraph.xml
|
||||||
cp /usr/share/sonic/device/$platform/minigraph.xml /etc/sonic/
|
cp /usr/share/sonic/device/$platform/minigraph.xml /etc/sonic/
|
||||||
sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
||||||
fi
|
fi
|
||||||
|
|
||||||
HWSKU=`sonic-cfggen -m /etc/sonic/minigraph.xml -v "DEVICE_METADATA['localhost']['hwsku']"`
|
HWSKU=`sonic-cfggen -m /etc/sonic/minigraph.xml -v DEVICE_METADATA.localhost.hwsku`
|
||||||
if [ -f /usr/share/sonic/device/$platform/$HWSKU/buffers.json.j2 ]; then
|
if [ -f /usr/share/sonic/device/$platform/$HWSKU/buffers.json.j2 ]; then
|
||||||
# generate and merge buffers configuration into config file
|
# generate and merge buffers configuration into config file
|
||||||
sonic-cfggen -m -t /usr/share/sonic/device/$platform/$HWSKU/buffers.json.j2 > /tmp/buffers.json
|
sonic-cfggen -m -t /usr/share/sonic/device/$platform/$HWSKU/buffers.json.j2 > /tmp/buffers.json
|
||||||
|
@ -153,7 +153,7 @@ def log_error(msg):
|
|||||||
|
|
||||||
# Determine whether we are running on an Arista platform
|
# Determine whether we are running on an Arista platform
|
||||||
def is_platform_arista():
|
def is_platform_arista():
|
||||||
proc = subprocess.Popen(["sonic-cfggen", "-v", "platform"],
|
proc = subprocess.Popen(["sonic-cfggen", "-H", "-v", "DEVICE_METADATA.localhost.platform"],
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
|
||||||
(stdout, stderr) = proc.communicate()
|
(stdout, stderr) = proc.communicate()
|
||||||
|
@ -31,7 +31,7 @@ if [ "$src" = "dhcp" ]; then
|
|||||||
if [ "`cat /tmp/dhcp_graph_url`" = "N/A" ]; then
|
if [ "`cat /tmp/dhcp_graph_url`" = "N/A" ]; then
|
||||||
echo "'N/A' found in DHCP response. Skipping graph update and generating an empty configuration."
|
echo "'N/A' found in DHCP response. Skipping graph update and generating an empty configuration."
|
||||||
echo '{"DEVICE_METADATA":' > /tmp/device_meta.json
|
echo '{"DEVICE_METADATA":' > /tmp/device_meta.json
|
||||||
sonic-cfggen -m /etc/sonic/minigraph.xml --var-json DEVICE_METADATA >> /tmp/device_meta.json
|
sonic-cfggen -H -m /etc/sonic/minigraph.xml --var-json DEVICE_METADATA >> /tmp/device_meta.json
|
||||||
echo '}' >> /tmp/device_meta.json
|
echo '}' >> /tmp/device_meta.json
|
||||||
if [ -f /etc/sonic/init_cfg.json ]; then
|
if [ -f /etc/sonic/init_cfg.json ]; then
|
||||||
sonic-cfggen -j /tmp/device_meta.json -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
sonic-cfggen -j /tmp/device_meta.json -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
||||||
@ -88,9 +88,9 @@ done
|
|||||||
|
|
||||||
echo "Regenerating config DB from minigraph..."
|
echo "Regenerating config DB from minigraph..."
|
||||||
if [ -f /etc/sonic/init_cfg.json ]; then
|
if [ -f /etc/sonic/init_cfg.json ]; then
|
||||||
sonic-cfggen -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
sonic-cfggen -H -m -j /etc/sonic/init_cfg.json --print-data > /etc/sonic/config_db.json
|
||||||
else
|
else
|
||||||
sonic-cfggen -m --print-data > /etc/sonic/config_db.json
|
sonic-cfggen -H -m --print-data > /etc/sonic/config_db.json
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Mark as disabled after graph is successfully downloaded
|
# Mark as disabled after graph is successfully downloaded
|
||||||
|
@ -19,12 +19,6 @@ fi
|
|||||||
|
|
||||||
mkdir -p /etc/swss/config.d/
|
mkdir -p /etc/swss/config.d/
|
||||||
|
|
||||||
# sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/ipinip.json.j2 > /etc/swss/config.d/ipinip.json
|
|
||||||
# sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/mirror.json.j2 > /etc/swss/config.d/mirror.json
|
|
||||||
# sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/ports.json.j2 > /etc/swss/config.d/ports.json
|
|
||||||
|
|
||||||
# export platform=`sonic-cfggen -v platform`
|
|
||||||
|
|
||||||
rm -f /var/run/rsyslogd.pid
|
rm -f /var/run/rsyslogd.pid
|
||||||
|
|
||||||
echo "Start rsyslogd"
|
echo "Start rsyslogd"
|
||||||
|
@ -18,12 +18,6 @@ fi
|
|||||||
|
|
||||||
mkdir -p /etc/swss/config.d/
|
mkdir -p /etc/swss/config.d/
|
||||||
|
|
||||||
# sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/ipinip.json.j2 > /etc/swss/config.d/ipinip.json
|
|
||||||
# sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/mirror.json.j2 > /etc/swss/config.d/mirror.json
|
|
||||||
# sonic-cfggen -m /etc/sonic/minigraph.xml -d -t /usr/share/sonic/templates/ports.json.j2 > /etc/swss/config.d/ports.json
|
|
||||||
|
|
||||||
# export platform=`sonic-cfggen -v platform`
|
|
||||||
|
|
||||||
rm -f /var/run/rsyslogd.pid
|
rm -f /var/run/rsyslogd.pid
|
||||||
|
|
||||||
supervisorctl start rsyslogd
|
supervisorctl start rsyslogd
|
||||||
|
@ -28,6 +28,7 @@ from minigraph import parse_xml
|
|||||||
from minigraph import parse_device_desc_xml
|
from minigraph import parse_device_desc_xml
|
||||||
from sonic_platform import get_machine_info
|
from sonic_platform import get_machine_info
|
||||||
from sonic_platform import get_platform_info
|
from sonic_platform import get_platform_info
|
||||||
|
from sonic_platform import get_system_mac
|
||||||
from swsssdk import ConfigDBConnector
|
from swsssdk import ConfigDBConnector
|
||||||
|
|
||||||
def is_ipv4(value):
|
def is_ipv4(value):
|
||||||
@ -135,6 +136,7 @@ def main():
|
|||||||
parser.add_argument("-j", "--json", help="json 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")
|
parser.add_argument("-a", "--additional-data", help="addition data, in json string")
|
||||||
parser.add_argument("-d", "--from-db", help="read config from configdb", action='store_true')
|
parser.add_argument("-d", "--from-db", help="read config from configdb", action='store_true')
|
||||||
|
parser.add_argument("-H", "--platform-info", help="read platform and hardware info", action='store_true')
|
||||||
parser.add_argument("-s", "--redis-unix-sock-file", help="unix sock file for redis connection")
|
parser.add_argument("-s", "--redis-unix-sock-file", help="unix sock file for redis connection")
|
||||||
group = parser.add_mutually_exclusive_group()
|
group = parser.add_mutually_exclusive_group()
|
||||||
group.add_argument("-t", "--template", help="render the data with the template file")
|
group.add_argument("-t", "--template", help="render the data with the template file")
|
||||||
@ -144,25 +146,22 @@ def main():
|
|||||||
group.add_argument("--print-data", help="print all data", action='store_true')
|
group.add_argument("--print-data", help="print all data", action='store_true')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
data = {}
|
platform = get_platform_info(get_machine_info())
|
||||||
machine_info = get_machine_info()
|
|
||||||
if machine_info != None:
|
|
||||||
deep_update(data, machine_info)
|
|
||||||
platform_info = get_platform_info(machine_info)
|
|
||||||
if platform_info != None:
|
|
||||||
data['platform'] = platform_info
|
|
||||||
|
|
||||||
db_kwargs = {}
|
db_kwargs = {}
|
||||||
if args.redis_unix_sock_file != None:
|
if args.redis_unix_sock_file != None:
|
||||||
db_kwargs['unix_socket_path'] = args.redis_unix_sock_file
|
db_kwargs['unix_socket_path'] = args.redis_unix_sock_file
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
|
||||||
if args.minigraph != None:
|
if args.minigraph != None:
|
||||||
minigraph = args.minigraph
|
minigraph = args.minigraph
|
||||||
if data.has_key('platform'):
|
if platform:
|
||||||
if args.port_config != None:
|
if args.port_config != None:
|
||||||
deep_update(data, parse_xml(minigraph, data['platform'], args.port_config))
|
deep_update(data, parse_xml(minigraph, platform, args.port_config))
|
||||||
else:
|
else:
|
||||||
deep_update(data, parse_xml(minigraph, data['platform']))
|
deep_update(data, parse_xml(minigraph, platform))
|
||||||
else:
|
else:
|
||||||
if args.port_config != None:
|
if args.port_config != None:
|
||||||
deep_update(data, parse_xml(minigraph, port_config_file=args.port_config))
|
deep_update(data, parse_xml(minigraph, port_config_file=args.port_config))
|
||||||
@ -189,6 +188,13 @@ def main():
|
|||||||
configdb.connect()
|
configdb.connect()
|
||||||
deep_update(data, FormatConverter.db_to_output(configdb.get_config()))
|
deep_update(data, FormatConverter.db_to_output(configdb.get_config()))
|
||||||
|
|
||||||
|
if args.platform_info:
|
||||||
|
hardware_data = {'DEVICE_METADATA': {'localhost': {
|
||||||
|
'platform': platform,
|
||||||
|
'mac': get_system_mac()
|
||||||
|
}}}
|
||||||
|
deep_update(data, hardware_data)
|
||||||
|
|
||||||
if args.template != None:
|
if args.template != None:
|
||||||
template_file = os.path.abspath(args.template)
|
template_file = os.path.abspath(args.template)
|
||||||
env = jinja2.Environment(loader=jinja2.FileSystemLoader('/'), trim_blocks=True)
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader('/'), trim_blocks=True)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import os
|
import os
|
||||||
|
import yaml
|
||||||
|
import subprocess
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
@ -29,3 +31,25 @@ def get_platform_info(machine_info):
|
|||||||
elif machine_info.has_key('aboot_platform'):
|
elif machine_info.has_key('aboot_platform'):
|
||||||
return machine_info['aboot_platform']
|
return machine_info['aboot_platform']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def get_sonic_version_info():
|
||||||
|
if not os.path.isfile('/etc/sonic/version.yml'):
|
||||||
|
return None
|
||||||
|
data = {}
|
||||||
|
with open('/etc/sonic/version.yml') as stream:
|
||||||
|
data = yaml.load(stream)
|
||||||
|
return data
|
||||||
|
|
||||||
|
def get_system_mac():
|
||||||
|
proc = subprocess.Popen("ip link show eth0 | grep ether | awk '{print $2}'", shell=True, stdout=subprocess.PIPE)
|
||||||
|
(mac, err) = proc.communicate()
|
||||||
|
mac = mac.strip()
|
||||||
|
|
||||||
|
# Align last byte of MAC if necessary
|
||||||
|
version_info = get_sonic_version_info()
|
||||||
|
if version_info and (version_info['asic_type'] == 'mellanox' or version_info['asic_type'] == 'centec'):
|
||||||
|
last_byte = mac[-2:]
|
||||||
|
aligned_last_byte = format(int(int(last_byte, 16) & 0b11000000), '02x')
|
||||||
|
mac = mac[:-2] + aligned_last_byte
|
||||||
|
return mac
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 63309c5388dd7d208d88b48d5b090791d314e62b
|
Subproject commit 35967e545af98f4d064e079d1057cc41590f079e
|
Loading…
Reference in New Issue
Block a user