Skip to content

Commit

Permalink
V1.1.0 layer1 (#23)
Browse files Browse the repository at this point in the history
* update description2netbox.py

* remove log

* update vars

* Update description2netbox.py

* Delete biglobe-config_index.json

* Update netbox.json

---------

Co-authored-by: mddo <you@example.com>
  • Loading branch information
t-tkgh and mddo authored Aug 18, 2023
1 parent ff7a95b commit 20c0119
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
configs/nttcom-trial-*/
configs/biglobe_*/
configs/biglobe*/
queries
demo/layer1_topology/inet-henge/*
topologies
.idea
.vscode
Expand Down
2 changes: 1 addition & 1 deletion configs/mddo-ospf
2 changes: 1 addition & 1 deletion demo/copy_to_emulated_env/demo_vars
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ API_BRIDGE="playground_default"
LOCALSERVER_USER=mddo
PLAYGROUND_DIR="/home/${LOCALSERVER_USER}/playground"
ANSIBLE_RUNNER_DIR="${PLAYGROUND_DIR}/demo/copy_to_emulated_env"
NETWORK_NAME="mddo-ospf"
NETWORK_NAME="biglobe_deform"
NETWORK_INDEX="${NETWORK_NAME}_index.json"
2 changes: 1 addition & 1 deletion demo/layer1_topology/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
BATFISH_IMAGE=ghcr.io/ool-mddo/mddo-batfish
BATFISH_IMAGE_TAG=main
SHARED_SNAPSHOT_DIR=../../configs/pushed_configs/mddo_network
SHARED_SNAPSHOT_DIR=../../configs/biglobe_deform/original_asis
1 change: 1 addition & 0 deletions demo/layer1_topology/inet-henge/netbox.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

36 changes: 23 additions & 13 deletions demo/layer1_topology/mnt/description2netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def get_interface(self, interface_name) -> "Interface":
return self.interfaces[interface_name]

def found_bidiractional_cable(cable_matrix: Dict[str, Dict[str, int]], cable: Cable) -> bool:
return (cable_matrix[f"{cable.a.device.lower_name}.{cable.a.name}"][f"{cable.b.device.lower_name}.{cable.b.name}"] == 1
and cable_matrix[f"{cable.b.device.lower_name}.{cable.b.name}"][f"{cable.a.device.lower_name}.{cable.a.name}"] == 1)
return (cable_matrix[f"{cable.a.device.lower_name}.{cable.a.name}"][f"{cable.b.device.lower_name}.{cable.b.name}"] > 0
and cable_matrix[f"{cable.b.device.lower_name}.{cable.b.name}"][f"{cable.a.device.lower_name}.{cable.a.name}"] > 0)

if __name__ == "__main__":
if len(sys.argv) < 3:
Expand All @@ -149,18 +149,17 @@ def found_bidiractional_cable(cable_matrix: Dict[str, Dict[str, int]], cable: Ca
load_questions()
bf_init_snapshot("/mnt/snapshot")
# exclude junos sub interface and other... TODO
is_exclude_interface = lambda x:bool(
re.search(r'\.\d+$', x.interface) # e.g. ge-0/0/0.0
)
#is_exclude_interface = lambda x:bool(
# re.search(r'\.\d+$', x.interface) # e.g. ge-0/0/0.0
#)
# judge LAG interface to exclude
is_lag_interface = lambda x:bool(len(x)>0)
interfaces = bfq \
.interfaceProperties(properties="Description, Channel_Group, Channel_Group_Members") \
.answer() \
.frame() \
.query("Description == Description") \
.query('~(Channel_Group_Members.apply(@is_lag_interface))', engine='python') \
.query('~(Interface.apply(@is_exclude_interface))', engine='python')
.query('~(Channel_Group_Members.apply(@is_lag_interface))', engine='python')

# check and greate meta entries
res = nb.dcim.sites.filter("dummy-site")
Expand Down Expand Up @@ -217,6 +216,11 @@ def found_bidiractional_cable(cable_matrix: Dict[str, Dict[str, int]], cable: Ca

# search src intf
interface_name = row["Interface"].interface # batfish returns correct name such as "Ethernet1"
# convert ge-0/0/0.0 -> ge-0/0/0
if re.search(r'\.\d+$', interface_name):
converted_if = interface_name.split('.')
interface_name = converted_if[0]

intf = devices[device_name_lower].get_interface(interface_name)
src_intf = intf

Expand All @@ -225,6 +229,8 @@ def found_bidiractional_cable(cable_matrix: Dict[str, Dict[str, int]], cable: Ca
r"(.+) (.+) via .+", # Switch-01 ge-0/0/1 via pp-01
r"(.+)_(.+) S-in:.+", # Switch-01 ge-0/0/1 S-in:1970-01-01
r"^to_(.+)_(.+)", # to_Switch-01_ge-0/0/1
r"^to (.+) (.+)", # to Switch-01 ge-0/0/1
r"^to (.+)_(.+)", # to Switch-01_ge-0/0/1
r"(.+)_(.+) via .+", # Switch-01_ge-0/0/1 via pp-01
r"(.+)_(.+)", # Switch-01_ge-0/0/1
r"(.+) (.+)", # Switch-01 ge-0/0/1
Expand All @@ -235,13 +241,14 @@ def found_bidiractional_cable(cable_matrix: Dict[str, Dict[str, int]], cable: Ca
if m is not None:
break
print (str(row))
print (str(device_name_lower))
print (str(interface_name))
print ("SrcDevice:" + str(device_name_lower))
print ("SrcInterface:" + str(interface_name))
print (str(m))
#print (str(device_name))

if m:
device_name_lower, interface_name = m.groups()
device_name, interface_name = m.groups()
device_name_lower = device_name.lower()

# Convert Et(h)~ to Ethernet~
if m := re.fullmatch(r"Eth?([\d/]+)", interface_name):
Expand All @@ -258,11 +265,15 @@ def found_bidiractional_cable(cable_matrix: Dict[str, Dict[str, int]], cable: Ca
else:
devices[device_name_lower].set_name(device_name_lower)

print ("DestDevice:" + str(device_name_lower))
print ("DestInterface:" + str(interface_name))
# search dst intf
intf = devices[device_name_lower].get_interface(interface_name)
dst_intf = intf

print (str(src_intf.name))
print (str(dst_intf.name))
cables.append(Cable(src_intf, dst_intf))
print (str(len(cables)))

src_key = f"{src_intf.device.lower_name}.{src_intf.name}"
dst_key = f"{dst_intf.device.lower_name}.{dst_intf.name}"
Expand All @@ -274,7 +285,7 @@ def found_bidiractional_cable(cable_matrix: Dict[str, Dict[str, int]], cable: Ca
if (host["Node"].lower() == dst_intf.device.lower_name and dst_intf.name in host["Interfaces"]):
cable_matrix[dst_key][src_key] += 1
break

print (str(cable_matrix))
for dev in devices.values():
dev.save(nb)
dev.save_interfaces(nb)
Expand All @@ -283,4 +294,3 @@ def found_bidiractional_cable(cable_matrix: Dict[str, Dict[str, int]], cable: Ca
if not found_bidiractional_cable(cable_matrix, cable):
continue
cable.save(nb)

2 changes: 1 addition & 1 deletion repos/netomox-exp
Submodule netomox-exp updated 0 files

0 comments on commit 20c0119

Please sign in to comment.