aboutsummaryrefslogtreecommitdiffstats
path: root/app/discover/find_links_for_pnics.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/discover/find_links_for_pnics.py')
-rw-r--r--app/discover/find_links_for_pnics.py70
1 files changed, 48 insertions, 22 deletions
diff --git a/app/discover/find_links_for_pnics.py b/app/discover/find_links_for_pnics.py
index 717c1c1..268aa55 100644
--- a/app/discover/find_links_for_pnics.py
+++ b/app/discover/find_links_for_pnics.py
@@ -7,6 +7,8 @@
# which accompanies this distribution, and is available at #
# http://www.apache.org/licenses/LICENSE-2.0 #
###############################################################################
+import re
+
from discover.find_links import FindLinks
@@ -20,12 +22,21 @@ class FindLinksForPnics(FindLinks):
"type": "pnic",
"pnic_type": "host"
})
+ self.log.info("adding links of type: pnic-network, host-switch")
for pnic in pnics:
self.add_pnic_network_links(pnic)
self.add_host_pnic_to_switch_pnic_link(pnic)
+ pnics = self.inv.find_items({
+ "environment": self.get_env(),
+ "type": "pnic",
+ "pnic_type": "switch",
+ "role": "uplink"
+ })
+ self.log.info("adding links of type: switch-switch")
+ for pnic in pnics:
+ self.add_switch_to_switch_link(pnic)
def add_pnic_network_links(self, pnic):
- self.log.info("adding links of type: pnic-network")
host = pnic["host"]
# find ports for that host, and fetch just the network ID
ports = self.inv.find_items({
@@ -38,7 +49,7 @@ class FindLinksForPnics(FindLinks):
networks[port["network_id"]] = 1
for network_id in networks.keys():
network = self.inv.get_by_id(self.get_env(), network_id)
- if network == []:
+ if not network:
return
source = pnic["_id"]
source_id = pnic["id"]
@@ -50,38 +61,53 @@ class FindLinksForPnics(FindLinks):
else "Segment-None"
state = "up" if pnic["Link detected"] == "yes" else "down"
link_weight = 0 # TBD
- source_label = "port-" + pnic["port_id"] if "port_id" in pnic \
- else ""
- self.create_link(self.get_env(), host,
+ attributes={"network": target_id}
+ if "port_id" in pnic:
+ attributes['source_label'] = "port-" + pnic["port_id"]
+ self.create_link(self.get_env(),
source, source_id, target, target_id,
link_type, link_name, state, link_weight,
- source_label,
- extra_attributes={"network": target_id})
+ host=host,
+ extra_attributes=attributes)
def add_host_pnic_to_switch_pnic_link(self, host_pnic):
- link_type = "host_pnic-switch_pnic"
- self.log.info("adding links of type: {}".format(link_type))
- # find ports for that host, and fetch just the network ID
- switch_pnics = self.inv.find_items({
+ switch_pnic = self.inv.find_items({
"environment": self.get_env(),
"type": "pnic",
"pnic_type": "switch",
- "mac_address": host_pnic["mac_address"]
- }, {"id": 1})
- if not switch_pnics:
+ "mac_address": host_pnic["mac_address"]},
+ get_single=True)
+ if not switch_pnic:
return
- if len(switch_pnics) > 1:
- self.log.warn("multiple matching switch pNICs found "
- "for host pNIC: mac_address={}"
- .format(host_pnic["mac_address"]))
- switch_pnic = switch_pnics[0]
source = host_pnic["_id"]
source_id = host_pnic["id"]
target = switch_pnic["_id"]
target_id = switch_pnic["id"]
- link_name = "{}-{}".format(target_id, source_id)
+ link_type = "host-switch"
+ link_name = "{}-{}".format(host_pnic['host'],
+ switch_pnic['parent_id'])
state = "up" if host_pnic["Link detected"] == "yes" else "down"
link_weight = 0 # TBD
- self.create_link(self.get_env(), host_pnic['host'],
+ self.create_link(self.get_env(),
+ source, source_id, target, target_id,
+ link_type, link_name, state, link_weight,
+ host=host_pnic['host'])
+
+ def add_switch_to_switch_link(self, leaf_pnic):
+ spine_pnic = self.inv.get_by_id(self.get_env(),
+ leaf_pnic['connected_to'])
+ if not spine_pnic:
+ return
+ source = leaf_pnic["_id"]
+ source_id = leaf_pnic["id"]
+ target = spine_pnic["_id"]
+ target_id = spine_pnic["id"]
+ link_type = "switch-switch"
+ if_id_matches = re.search("(eth.*)$", source_id)
+ link_name = if_id_matches.group(1).replace("__", "/")
+ state = "up" # TBD
+ link_weight = 0 # TBD
+ self.create_link(self.get_env(),
source, source_id, target, target_id,
- link_type, link_name, state, link_weight) \ No newline at end of file
+ link_type, link_name, state, link_weight,
+ switch=leaf_pnic['switch']) \ No newline at end of file