summaryrefslogtreecommitdiffstats
path: root/app/discover/find_links_for_vedges.py
diff options
context:
space:
mode:
authorIlia Abashin <abashinos@gmail.com>2017-09-01 15:51:52 +0300
committerIlia Abashin <abashinos@gmail.com>2017-09-01 15:51:52 +0300
commit7b4235dced0c66096638bebd5cc98a631538b0e1 (patch)
treeea6e17af0fbd854ef7b2053aa7c1e71949d977aa /app/discover/find_links_for_vedges.py
parent692489cc50c8025ede1646627a7a583a4feb3798 (diff)
Refactored link finders
Mappings are now defined in a configuration file and fetched dynamically. Change-Id: I250c22967fc66fc0aca173d4c9d65581d879b5d2 Signed-off-by: Ilia Abashin <abashinos@gmail.com>
Diffstat (limited to 'app/discover/find_links_for_vedges.py')
-rw-r--r--app/discover/find_links_for_vedges.py128
1 files changed, 0 insertions, 128 deletions
diff --git a/app/discover/find_links_for_vedges.py b/app/discover/find_links_for_vedges.py
deleted file mode 100644
index acafceb..0000000
--- a/app/discover/find_links_for_vedges.py
+++ /dev/null
@@ -1,128 +0,0 @@
-###############################################################################
-# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) #
-# and others #
-# #
-# All rights reserved. This program and the accompanying materials #
-# are made available under the terms of the Apache License, Version 2.0 #
-# which accompanies this distribution, and is available at #
-# http://www.apache.org/licenses/LICENSE-2.0 #
-###############################################################################
-from discover.find_links import FindLinks
-
-
-class FindLinksForVedges(FindLinks):
- def __init__(self):
- super().__init__()
-
- def add_links(self):
- self.log.info("adding link types: " +
- "vnic-vedge, vconnector-vedge, vedge-host_pnic")
- vedges = self.inv.find_items({
- "environment": self.get_env(),
- "type": "vedge"
- })
- for vedge in vedges:
- ports = vedge["ports"]
- for p in ports.values():
- self.add_link_for_vedge(vedge, p)
-
- def add_link_for_vedge(self, vedge, port):
- vnic = self.inv.get_by_id(self.get_env(),
- vedge['host'] + '-' + port["name"])
- if not vnic:
- self.find_matching_vconnector(vedge, port)
- self.find_matching_pnic(vedge, port)
- return
- source = vnic["_id"]
- source_id = vnic["id"]
- target = vedge["_id"]
- target_id = vedge["id"]
- link_type = "vnic-vedge"
- link_name = vnic["name"] + "-" + vedge["name"]
- if "tag" in port:
- link_name += "-" + port["tag"]
- state = "up" # TBD
- link_weight = 0 # TBD
- source_label = vnic["mac_address"]
- target_label = port["id"]
- self.create_link(self.get_env(),
- source, source_id, target, target_id,
- link_type, link_name, state, link_weight,
- host=vedge["host"],
- extra_attributes={"source_label": source_label,
- "target_label": target_label})
-
- def find_matching_vconnector(self, vedge, port):
- if self.configuration.has_network_plugin('VPP'):
- vconnector_interface_name = port['name']
- else:
- if not port["name"].startswith("qv"):
- return
- base_id = port["name"][3:]
- vconnector_interface_name = "qvb" + base_id
- vconnector = self.inv.find_items({
- "environment": self.get_env(),
- "type": "vconnector",
- "host": vedge['host'],
- 'interfaces_names': vconnector_interface_name},
- get_single=True)
- if not vconnector:
- return
- source = vconnector["_id"]
- source_id = vconnector["id"]
- target = vedge["_id"]
- target_id = vedge["id"]
- link_type = "vconnector-vedge"
- link_name = "port-" + port["id"]
- if "tag" in port:
- link_name += "-" + port["tag"]
- state = "up" # TBD
- link_weight = 0 # TBD
- source_label = vconnector_interface_name
- target_label = port["name"]
- mac_address = "Unknown"
- attributes = {'mac_address': mac_address, 'source_label': source_label,
- 'target_label': target_label}
- for interface in vconnector['interfaces'].values():
- if vconnector_interface_name != interface['name']:
- continue
- if 'mac_address' not in interface:
- continue
- mac_address = interface['mac_address']
- attributes['mac_address'] = mac_address
- break
- if 'network' in vconnector:
- attributes['network'] = vconnector['network']
- self.create_link(self.get_env(),
- source, source_id, target, target_id,
- link_type, link_name, state, link_weight,
- host=vedge["host"],
- extra_attributes=attributes)
-
- def find_matching_pnic(self, vedge, port):
- pname = port["name"]
- if "pnic" in vedge:
- if pname != vedge["pnic"]:
- return
- elif self.configuration.has_network_plugin('VPP'):
- pass
- pnic = self.inv.find_items({
- "environment": self.get_env(),
- "type": "host_pnic",
- "host": vedge["host"],
- "name": pname
- }, get_single=True)
- if not pnic:
- return
- source = vedge["_id"]
- source_id = vedge["id"]
- target = pnic["_id"]
- target_id = pnic["id"]
- link_type = "vedge-host_pnic"
- link_name = "Port-" + port["id"]
- state = "up" if pnic["Link detected"] == "yes" else "down"
- link_weight = 0 # TBD
- self.create_link(self.get_env(),
- source, source_id, target, target_id,
- link_type, link_name, state, link_weight,
- host=vedge["host"])