Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions files/sonic/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,35 @@
"default|connected|bgp|ipv4": {},
"default|connected|bgp|ipv6": {}
},
"SNMP": {
"LOCATION": {
"Location": "public"
"SNMP_SERVER": {
"SYSTEM": {
"sysContact": "info@example.com",
"sysLocation": "Data Center"
}
},
"SNMP_COMMUNITY": {
"public": {
"TYPE": "RO"
"SNMP_SERVER_GROUP": {
"monitoring": {}
},
"SNMP_SERVER_GROUP_ACCESS": {
"monitoring|Default|usm|auth-no-priv": {
"contextMatch": "exact",
"notifyView": "None",
"readView": "rview",
"writeView": "None"
}
},
"SNMP_SERVER_GROUP_MEMBER": {},
"SNMP_SERVER_GROUP_PARAMS": {},
"SNMP_SERVER_GROUP_TARGET": {},
"SNMP_SERVER_GROUP_USER": {},
"SNMP_SERVER_VIEW": {
"rview": {
"include": [
".1"
]
}
},
"STATIC_ROUTE": {},
"SSHD_COMMON": {
"GLOBAL": {
"ciphers": "aes128-ctr,aes192-ctr,aes256-ctr,chacha20-poly1305@openssh.com,aes128-gcm@openssh.com,aes256-gcm@openssh.com",
Expand All @@ -442,7 +461,7 @@
"TELEMETRY": {
"gnmi": {}
},
"VERSION": {
"VERSIONS": {
"DATABASE": {
"VERSION": "version_4_0_1"
}
Expand Down
112 changes: 105 additions & 7 deletions osism/tasks/conductor/sonic/config_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,22 @@ def generate_sonic_config(device, hwsku, device_as_mapping=None, config_version=
# Add Loopback configuration
_add_loopback_configuration(config, loopback_info)

# Add log-server configuration
_add_log_server_configuration(config, device)

# Add management interface configuration
if oob_ip_result:
oob_ip, prefix_len = oob_ip_result
config["MGMT_INTERFACE"]["eth0"] = {"admin_status": "up"}
config["MGMT_INTERFACE"][f"eth0|{oob_ip}/{prefix_len}"] = {}
metalbox_ip = _get_metalbox_ip_for_device(device)
config["STATIC_ROUTE"] = {}
config["STATIC_ROUTE"]["mgmt|0.0.0.0/0"] = {"nexthop": metalbox_ip}
else:
oob_ip = None

# Add SNMP configuration
_add_snmp_configuration(config, device, oob_ip)

# Add breakout configuration
if breakout_info["breakout_cfgs"]:
Expand All @@ -269,10 +280,10 @@ def generate_sonic_config(device, hwsku, device_as_mapping=None, config_version=
_add_vrf_configuration(config, vrf_info, netbox_interfaces)

# Set DATABASE VERSION from config_version parameter or default
if "VERSION" not in config:
config["VERSION"] = {}
if "DATABASE" not in config["VERSION"]:
config["VERSION"]["DATABASE"] = {}
if "VERSIONS" not in config:
config["VERSIONS"] = {}
if "DATABASE" not in config["VERSIONS"]:
config["VERSIONS"]["DATABASE"] = {}

if config_version:
# Normalize config_version: add "version_" prefix if not present
Expand All @@ -283,12 +294,12 @@ def generate_sonic_config(device, hwsku, device_as_mapping=None, config_version=
f"Normalized config_version from '{config_version}' to '{normalized_version}' for device {device.name}"
)

config["VERSION"]["DATABASE"]["VERSION"] = normalized_version
config["VERSIONS"]["DATABASE"]["VERSION"] = normalized_version
logger.info(
f"Using custom config_version '{normalized_version}' for device {device.name}"
)
elif "VERSION" not in config.get("VERSION", {}).get("DATABASE", {}):
config["VERSION"]["DATABASE"]["VERSION"] = "version_4_0_1"
elif "VERSION" not in config.get("VERSIONS", {}).get("DATABASE", {}):
config["VERSIONS"]["DATABASE"]["VERSION"] = "version_4_0_1"
logger.debug(
f"Using default config_version 'version_4_0_1' for device {device.name}"
)
Expand Down Expand Up @@ -2081,3 +2092,90 @@ def _add_portchannel_configuration(config, portchannel_info):
logger.debug(
f"Added port channel {pc_name} with {len(pc_data['members'])} members"
)


def _add_log_server_configuration(config, device):
"""Add SYSLOG_SERVER configuration to device config.

The configuration is taken from multiple _segment_log_server_* variables
in the config_context of the device.
"""
hosts = device.config_context.get("_segment_log_server_hosts", [])
if hosts:
proto = device.config_context.get("_segment_log_server_proto", "udp")
severity = device.config_context.get("_segment_log_server_severity", "info")
vrf = device.config_context.get("_segment_log_server_vrf", "mgmt")
config["SYSLOG_SERVER"] = {}
for host in hosts:
config["SYSLOG_SERVER"][host] = {}
config["SYSLOG_SERVER"][host]["message-type"] = "log"
config["SYSLOG_SERVER"][host]["protocol"] = proto.upper()
config["SYSLOG_SERVER"][host]["remote-port"] = "514"
config["SYSLOG_SERVER"][host]["severity"] = severity
config["SYSLOG_SERVER"][host]["vrf_name"] = vrf

logger.debug(f"Added syslog_server {host}")


def _add_snmp_configuration(config, device, oob_ip):
"""Add Snmp configuration to device config.

The configuration is taken from multiple _segment_snmp_server_* variables
in the config_context of the device.
"""

location = device.config_context.get("_segment_snmp_server_location", "Data Center")
contact = device.config_context.get(
"_segment_snmp_server_contact", "info@example.com"
)
config["SNMP_SERVER"] = {"SYSTEM": {"sysContact": contact, "sysLocation": location}}

traps = device.config_context.get("_segment_snmp_server_traps", True)
if traps:
config["SNMP_SERVER"]["SYSTEM"]["traps"] = "enable"

if oob_ip:
config["SNMP_AGENT_ADDRESS_CONFIG"] = {
f"{oob_ip}|161|mgmt": {"name": "agentEntry1"}
}

username = device.config_context.get("_segment_snmp_server_username", None)
if username:
userauthpass = device.config_context.get(
"_segment_snmp_server_userauthpass", "OBFUSCATEDSECRET1"
)
userprivpass = device.config_context.get(
"_segment_snmp_server_userprivpass", "OBFUSCATEDSECRET2"
)
config["SNMP_SERVER_GROUP_MEMBER"] = {}
config["SNMP_SERVER_USER"] = {}
config["SNMP_SERVER_GROUP_MEMBER"][f"monitoring|{username}"] = {
"securityModel": ["usm"]
}
config["SNMP_SERVER_USER"][f"{username}"] = {
"shaKey": userauthpass,
"aesKey": userprivpass,
}
logger.debug(f"Added snmp_server_user {username}")

hosts = device.config_context.get("_segment_snmp_server_hosts", [])
if hosts:
config["SNMP_SERVER_PARAMS"] = {}
config["SNMP_SERVER_TARGET"] = {}
counter = 1
for host in hosts:
config["SNMP_SERVER_PARAMS"][f"targetEntry{counter}"] = {
"security-level": "auth-priv",
"user": username,
}
config["SNMP_SERVER_TARGET"][f"targetEntry{counter}"] = {
"ip": host,
"port": "162",
"retries": "3",
"tag": ["trapNotify", "mgmt"],
"targetParams": f"targetEntry{counter}",
"timeout": "1500",
}
counter += 1

logger.debug(f"Added snmp_server_target {host}")