infamy: Set hostname from logical topology

If no hostname is specified, set it to the dut-name in
logical topology
This commit is contained in:
Mattias Walström
2024-11-07 09:47:36 +01:00
parent 6a9f9fd3cc
commit 82ff83c50d
3 changed files with 12 additions and 2 deletions
+2 -1
View File
@@ -16,7 +16,7 @@ import lxml
import netconf_client.connect
import netconf_client.ncclient
import infamy.iface as iface
from infamy.transport import Transport
from infamy.transport import Transport,infer_put_dict
from netconf_client.error import RpcError
from . import env
@@ -315,6 +315,7 @@ class Device(Transport):
def put_config_dicts(self, models):
config = ""
infer_put_dict(self.name, models)
for model in models.keys():
mod = self.ly.get_module(model)
+2 -1
View File
@@ -10,7 +10,7 @@ import time
from requests.auth import HTTPBasicAuth
from urllib3.exceptions import InsecureRequestWarning
from dataclasses import dataclass
from infamy.transport import Transport
from infamy.transport import Transport, infer_put_dict
from . import env
# We know we have a self-signed certificate, silence warning about it
@@ -263,6 +263,7 @@ class Device(Transport):
return {container: v}
def put_config_dicts(self, models):
infer_put_dict(self.name, models)
running = self.get_running()
for model in models.keys():
+8
View File
@@ -1,6 +1,14 @@
from abc import ABC, abstractmethod
from infamy.neigh import ll6ping
def infer_put_dict(name, models):
if not models.get("ietf-system"):
models["ietf-system"] = { "system": { "hostname": name} }
else:
if not models["ietf-system"].get("system"):
models["ieft-system"]["system"] = {}
if not models["ietf-system"]["system"].get("hostname"):
models["ietf-system"]["system"]["hostname"] = name
class Transport(ABC):
"""Common functions for NETCONF/RESTCONF"""