mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 04:33:00 +02:00
infamy: Wait for NETCONF and RESTCONF
Also remove some code duplication.
This commit is contained in:
@@ -2,8 +2,12 @@
|
||||
|
||||
import socket
|
||||
import time
|
||||
|
||||
import requests
|
||||
import infamy, infamy.neigh
|
||||
import infamy.restconf as restconf
|
||||
import infamy.netconf as netconf
|
||||
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
def ll6ping(node):
|
||||
neigh = None
|
||||
@@ -44,7 +48,8 @@ with infamy.Test() as test:
|
||||
retry = []
|
||||
for node in infixen:
|
||||
neigh = ll6ping(node)
|
||||
if neigh and netconf_syn(neigh):
|
||||
password = env.ptop.get_password(node)
|
||||
if neigh and netconf.netconf_syn(neigh) and restconf.restconf_reachable(neigh, password):
|
||||
continue
|
||||
|
||||
retry.append(node)
|
||||
|
||||
@@ -23,6 +23,23 @@ class Location:
|
||||
username: str = "admin"
|
||||
port: int = 443
|
||||
|
||||
|
||||
def restconf_reachable(neigh, password):
|
||||
try:
|
||||
headers={
|
||||
'Content-Type': 'application/yang-data+json',
|
||||
'Accept': 'application/yang-data+json'
|
||||
}
|
||||
url=f"https://[{neigh}]/restconf/data/ietf-system:system/hostname"
|
||||
auth=HTTPBasicAuth("admin", password)
|
||||
response=requests.get(url, headers=headers, auth=auth, verify=False)
|
||||
print(f"{neigh} answers to TCP connections on port 443 (RESTCONF)")
|
||||
if response.status_code==200:
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
return False
|
||||
class Device(Transport):
|
||||
def __init__(self,
|
||||
location: Location,
|
||||
|
||||
@@ -122,7 +122,8 @@ class Topology:
|
||||
n = self.dotg.get_node(node)
|
||||
b = n[0] if n else {}
|
||||
password=b.get("password")
|
||||
return qstrip(password) if password is not None else None
|
||||
|
||||
return qstrip(password) if password is not None else "admin"
|
||||
|
||||
def get_link(self, src, dst, flt=lambda _: True):
|
||||
es = self.g.get_edge_data(src, dst)
|
||||
|
||||
@@ -2,6 +2,7 @@ import time
|
||||
import threading
|
||||
import infamy.neigh
|
||||
import infamy.netconf as netconf
|
||||
import infamy.restconf as restconf
|
||||
|
||||
class ParallelFn(threading.Thread):
|
||||
def __init__(self, group=None, target=None, name=None,
|
||||
@@ -50,4 +51,6 @@ def wait_boot(target):
|
||||
if not neigh:
|
||||
return False
|
||||
until(lambda: netconf.netconf_syn(neigh) == True, attempts = 300)
|
||||
until(lambda: restconf.restconf_reachable(neigh, target.location.password) == True, attempts = 300)
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user