From bd6bf1ff9a425b729294db89ffe7a6b04bda3973 Mon Sep 17 00:00:00 2001 From: Taoyu Li Date: Mon, 6 Mar 2017 12:41:26 -0800 Subject: [PATCH] [config] [oneimage & dhcp relay docker] Move ntp, rsyslog, and dhcp server information into minigraph (#374) Move DHCP, rsyslog, and NTP server information into minigraph * Fix dhcp relay template according to CR --- .../x86_64-accton_as7512_32x-r0/minigraph.xml | 25 ++++++++++++++ .../x86_64-arista_7050_qx32/minigraph.xml | 25 ++++++++++++++ .../x86_64-arista_7060_cx32s/minigraph.xml | 25 ++++++++++++++ .../x86_64-dell_s6000_s1220-r0/minigraph.xml | 25 ++++++++++++++ .../x86_64-dell_s6100_c2538-r0/minigraph.xml | 25 ++++++++++++++ .../x86_64-dell_z9100_c2538-r0/minigraph.xml | 25 ++++++++++++++ .../x86_64-ingrasys_s9100-r0/minigraph.xml | 33 ++++++++++++++++++- .../x86_64-mlnx_msn2700-r0/minigraph.xml | 25 ++++++++++++++ dockers/docker-dhcp-relay/config.sh | 2 +- dockers/docker-dhcp-relay/isc-dhcp-relay.j2 | 2 +- .../build_templates/sonic_debian_extension.j2 | 2 -- files/image_config/ntp/ntp-config.sh | 2 +- files/image_config/ntp/ntp.yml | 6 ---- files/image_config/rsyslog/rsyslog-config.sh | 2 +- files/image_config/rsyslog/rsyslog.yml | 1 - src/sonic-config-engine/minigraph.py | 27 +++++++++++++++ 16 files changed, 238 insertions(+), 14 deletions(-) delete mode 100644 files/image_config/ntp/ntp.yml delete mode 100644 files/image_config/rsyslog/rsyslog.yml diff --git a/device/accton/x86_64-accton_as7512_32x-r0/minigraph.xml b/device/accton/x86_64-accton_as7512_32x-r0/minigraph.xml index 42bb951add..f2326c44aa 100644 --- a/device/accton/x86_64-accton_as7512_32x-r0/minigraph.xml +++ b/device/accton/x86_64-accton_as7512_32x-r0/minigraph.xml @@ -1044,6 +1044,31 @@ + + + + switch1 + + + DhcpResources + + + + + NtpResources + + 0.debian.pool.ntp.org;1.debian.pool.ntp.org;2.debian.pool.ntp.org;3.debian.pool.ntp.org + + + SyslogResources + + + + + + + + switch1 AS7512 diff --git a/device/arista/x86_64-arista_7050_qx32/minigraph.xml b/device/arista/x86_64-arista_7050_qx32/minigraph.xml index 26bf46132a..f2ef7b0b8b 100644 --- a/device/arista/x86_64-arista_7050_qx32/minigraph.xml +++ b/device/arista/x86_64-arista_7050_qx32/minigraph.xml @@ -1044,6 +1044,31 @@ + + + + switch1 + + + DhcpResources + + + + + NtpResources + + 0.debian.pool.ntp.org;1.debian.pool.ntp.org;2.debian.pool.ntp.org;3.debian.pool.ntp.org + + + SyslogResources + + + + + + + + switch1 Arista-7050-QX32 diff --git a/device/arista/x86_64-arista_7060_cx32s/minigraph.xml b/device/arista/x86_64-arista_7060_cx32s/minigraph.xml index 3fcd713cbc..5d7dcea980 100644 --- a/device/arista/x86_64-arista_7060_cx32s/minigraph.xml +++ b/device/arista/x86_64-arista_7060_cx32s/minigraph.xml @@ -1044,6 +1044,31 @@ + + + + switch1 + + + DhcpResources + + + + + NtpResources + + 0.debian.pool.ntp.org;1.debian.pool.ntp.org;2.debian.pool.ntp.org;3.debian.pool.ntp.org + + + SyslogResources + + + + + + + + switch1 Arista-7060-CX32S diff --git a/device/dell/x86_64-dell_s6000_s1220-r0/minigraph.xml b/device/dell/x86_64-dell_s6000_s1220-r0/minigraph.xml index 436f6880da..0fd1f49ab8 100644 --- a/device/dell/x86_64-dell_s6000_s1220-r0/minigraph.xml +++ b/device/dell/x86_64-dell_s6000_s1220-r0/minigraph.xml @@ -1044,6 +1044,31 @@ + + + + switch1 + + + DhcpResources + + + + + NtpResources + + 0.debian.pool.ntp.org;1.debian.pool.ntp.org;2.debian.pool.ntp.org;3.debian.pool.ntp.org + + + SyslogResources + + + + + + + + switch1 Force10-S6000 diff --git a/device/dell/x86_64-dell_s6100_c2538-r0/minigraph.xml b/device/dell/x86_64-dell_s6100_c2538-r0/minigraph.xml index e07ec53e18..3ae8e77f80 100644 --- a/device/dell/x86_64-dell_s6100_c2538-r0/minigraph.xml +++ b/device/dell/x86_64-dell_s6100_c2538-r0/minigraph.xml @@ -739,6 +739,31 @@ + + + + switch1 + + + DhcpResources + + + + + NtpResources + + 0.debian.pool.ntp.org;1.debian.pool.ntp.org;2.debian.pool.ntp.org;3.debian.pool.ntp.org + + + SyslogResources + + + + + + + + switch1 Force10-S6100 diff --git a/device/dell/x86_64-dell_z9100_c2538-r0/minigraph.xml b/device/dell/x86_64-dell_z9100_c2538-r0/minigraph.xml index 44cffcdd43..ab1ce20a69 100644 --- a/device/dell/x86_64-dell_z9100_c2538-r0/minigraph.xml +++ b/device/dell/x86_64-dell_z9100_c2538-r0/minigraph.xml @@ -1044,6 +1044,31 @@ + + + + switch1 + + + DhcpResources + + + + + NtpResources + + 0.debian.pool.ntp.org;1.debian.pool.ntp.org;2.debian.pool.ntp.org;3.debian.pool.ntp.org + + + SyslogResources + + + + + + + + switch1 Force10-Z9100 diff --git a/device/ingrasys/x86_64-ingrasys_s9100-r0/minigraph.xml b/device/ingrasys/x86_64-ingrasys_s9100-r0/minigraph.xml index c67990fc73..154c1847eb 100644 --- a/device/ingrasys/x86_64-ingrasys_s9100-r0/minigraph.xml +++ b/device/ingrasys/x86_64-ingrasys_s9100-r0/minigraph.xml @@ -109,7 +109,38 @@ Ethernet4 - + + + OCPSCH01040GGLF + ingrasys-s9100 + + + + + + + OCPSCH01040GGLF + + + DhcpResources + + + + + NtpResources + + 0.debian.pool.ntp.org;1.debian.pool.ntp.org;2.debian.pool.ntp.org;3.debian.pool.ntp.org + + + SyslogResources + + + + + + + + OCPSCH01040GGLF ingrasys-s9100 diff --git a/device/mellanox/x86_64-mlnx_msn2700-r0/minigraph.xml b/device/mellanox/x86_64-mlnx_msn2700-r0/minigraph.xml index 0fa570c7a0..4942e64be5 100644 --- a/device/mellanox/x86_64-mlnx_msn2700-r0/minigraph.xml +++ b/device/mellanox/x86_64-mlnx_msn2700-r0/minigraph.xml @@ -1044,6 +1044,31 @@ ` + + + + switch2 + + + DhcpResources + + + + + NtpResources + + 0.debian.pool.ntp.org;1.debian.pool.ntp.org;2.debian.pool.ntp.org;3.debian.pool.ntp.org + + + SyslogResources + + + + + + + + switch2 ACS-MSN2700 diff --git a/dockers/docker-dhcp-relay/config.sh b/dockers/docker-dhcp-relay/config.sh index f0a861cfb9..99df251572 100755 --- a/dockers/docker-dhcp-relay/config.sh +++ b/dockers/docker-dhcp-relay/config.sh @@ -1,4 +1,4 @@ #!/bin/bash -sonic-cfggen -m /etc/sonic/minigraph.xml -y /etc/sonic/dhcp_relay.yml -t /usr/share/sonic/templates/isc-dhcp-relay.j2 > /etc/default/isc-dhcp-relay +sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/isc-dhcp-relay.j2 > /etc/default/isc-dhcp-relay diff --git a/dockers/docker-dhcp-relay/isc-dhcp-relay.j2 b/dockers/docker-dhcp-relay/isc-dhcp-relay.j2 index 07df5e1f9a..812e2bb8e1 100644 --- a/dockers/docker-dhcp-relay/isc-dhcp-relay.j2 +++ b/dockers/docker-dhcp-relay/isc-dhcp-relay.j2 @@ -1,4 +1,4 @@ -SERVERS="{{ dhcp_servers }}" +SERVERS="{{ dhcp_servers | join(' ') }}" INTERFACES="{{ minigraph_vlan_interfaces[0]['name'] }}" diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index c84518576f..5d079ea35c 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -83,14 +83,12 @@ sudo cp $IMAGE_CONFIGS/ntp/ntp-config.service $FILESYSTEM_ROOT/etc/systemd/syste sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable ntp-config.service sudo cp $IMAGE_CONFIGS/ntp/ntp-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/ntp/ntp.conf.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/ -sudo cp $IMAGE_CONFIGS/ntp/ntp.yml $FILESYSTEM_ROOT/etc/sonic/ # Copy rsyslog configuration files and templates sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.service $FILESYSTEM_ROOT/etc/systemd/system/ sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable rsyslog-config.service sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog-config.sh $FILESYSTEM_ROOT/usr/bin/ sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.conf.j2 $FILESYSTEM_ROOT/usr/share/sonic/templates/ -sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.yml $FILESYSTEM_ROOT/etc/sonic/ sudo cp $IMAGE_CONFIGS/rsyslog/rsyslog.d/* $FILESYSTEM_ROOT/etc/rsyslog.d/ # Copy interfaces configuration files and templates diff --git a/files/image_config/ntp/ntp-config.sh b/files/image_config/ntp/ntp-config.sh index 55a048a713..2465058ba0 100755 --- a/files/image_config/ntp/ntp-config.sh +++ b/files/image_config/ntp/ntp-config.sh @@ -1,3 +1,3 @@ #!/bin/bash -sonic-cfggen -m /etc/sonic/minigraph.xml -y /etc/sonic/ntp.yml -t /usr/share/sonic/templates/ntp.conf.j2 >/etc/ntp.conf +sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/ntp.conf.j2 >/etc/ntp.conf diff --git a/files/image_config/ntp/ntp.yml b/files/image_config/ntp/ntp.yml deleted file mode 100644 index efb3a5272f..0000000000 --- a/files/image_config/ntp/ntp.yml +++ /dev/null @@ -1,6 +0,0 @@ -ntp_servers: - - 0.debian.pool.ntp.org - - 1.debian.pool.ntp.org - - 2.debian.pool.ntp.org - - 3.debian.pool.ntp.org - diff --git a/files/image_config/rsyslog/rsyslog-config.sh b/files/image_config/rsyslog/rsyslog-config.sh index 8c14b9adce..0448880296 100755 --- a/files/image_config/rsyslog/rsyslog-config.sh +++ b/files/image_config/rsyslog/rsyslog-config.sh @@ -1,3 +1,3 @@ #!/bin/bash -sonic-cfggen -m /etc/sonic/minigraph.xml -y /etc/sonic/rsyslog.yml -t /usr/share/sonic/templates/rsyslog.conf.j2 >/etc/rsyslog.conf +sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/rsyslog.conf.j2 >/etc/rsyslog.conf diff --git a/files/image_config/rsyslog/rsyslog.yml b/files/image_config/rsyslog/rsyslog.yml deleted file mode 100644 index 006271123b..0000000000 --- a/files/image_config/rsyslog/rsyslog.yml +++ /dev/null @@ -1 +0,0 @@ -syslog_servers: [] diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index aece9dee8a..afd4538f13 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -266,6 +266,25 @@ def parse_cpg(cpg, hname): return bgp_sessions, myasn +def parse_meta(meta, hname): + syslog_servers = [] + dhcp_servers = [] + ntp_servers = [] + device_metas = meta.find(str(QName(ns, "Devices"))) + for device in device_metas.findall(str(QName(ns1, "DeviceMetadata"))): + if device.find(str(QName(ns1, "Name"))).text == hname: + properties = device.find(str(QName(ns1, "Properties"))) + for device_property in properties.findall(str(QName(ns1, "DeviceProperty"))): + name = device_property.find(str(QName(ns1, "Name"))).text + value = device_property.find(str(QName(ns1, "Value"))).text + value_group = value.split(';') if value and value != "" else [] + if name == "DhcpResources": + dhcp_servers = value_group + elif name == "NtpResources": + ntp_servers = value_group + elif name == "SyslogResources": + syslog_servers = value_group + return syslog_servers, dhcp_servers, ntp_servers def get_console_info(devices, dev, port): for k, v in devices.items(): @@ -340,6 +359,9 @@ def parse_xml(filename, platform=None): neighbors = None devices = None hostname = None + syslog_servers = [] + dhcp_servers = [] + ntp_servers = [] hwsku_qn = QName(ns, "HwSku") hostname_qn = QName(ns, "Hostname") @@ -363,6 +385,8 @@ def parse_xml(filename, platform=None): (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port) = parse_png(child, hostname) elif child.tag == str(QName(ns, "UngDec")): (u_neighbors, u_devices, _, _, _, _) = parse_png(child, hostname) + elif child.tag == str(QName(ns, "MetadataDeclaration")): + (syslog_servers, dhcp_servers, ntp_servers) = parse_meta(child, hostname) Tree = lambda: defaultdict(Tree) @@ -389,6 +413,9 @@ def parse_xml(filename, platform=None): results['minigraph_mgmt'] = get_mgmt_info(devices, mgmt_dev, mgmt_port) results['minigraph_hostname'] = hostname results['inventory_hostname'] = hostname + results['syslog_servers'] = syslog_servers + results['dhcp_servers'] = dhcp_servers + results['ntp_servers'] = ntp_servers results['alias_map'] = alias_map_list return results