aboutsummaryrefslogtreecommitdiffstats
path: root/app/discover/find_links_for_vconnectors.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_vconnectors.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_vconnectors.py')
-rw-r--r--app/discover/find_links_for_vconnectors.py91
1 files changed, 0 insertions, 91 deletions
diff --git a/app/discover/find_links_for_vconnectors.py b/app/discover/find_links_for_vconnectors.py
deleted file mode 100644
index ab96ebe..0000000
--- a/app/discover/find_links_for_vconnectors.py
+++ /dev/null
@@ -1,91 +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 FindLinksForVconnectors(FindLinks):
- def __init__(self):
- super().__init__()
-
- def add_links(self):
- vconnectors = self.inv.find_items({
- "environment": self.get_env(),
- "type": "vconnector"
- })
- self.log.info("adding links of type: vnic-vconnector, "
- "vconnector-host_pnic")
- for vconnector in vconnectors:
- for interface in vconnector["interfaces_names"]:
- self.add_vnic_vconnector_link(vconnector, interface)
- self.add_vconnector_pnic_link(vconnector, interface)
-
- def add_vnic_vconnector_link(self, vconnector, interface_name):
- mechanism_drivers = self.configuration.environment['mechanism_drivers']
- is_ovs = mechanism_drivers and mechanism_drivers[0] == 'OVS'
- if is_ovs:
- # interface ID for OVS
- vnic = self.inv.get_by_id(self.get_env(), interface_name)
- else:
- # interface ID for VPP - match interface MAC address to vNIC MAC
- interface = vconnector['interfaces'][interface_name]
- if not interface or 'mac_address' not in interface:
- return
- vnic_mac = interface['mac_address']
- vnic = self.inv.get_by_field(self.get_env(), 'vnic',
- 'mac_address', vnic_mac,
- get_single=True)
- if not vnic:
- return
- host = vnic["host"]
- source = vnic["_id"]
- source_id = vnic["id"]
- target = vconnector["_id"]
- target_id = vconnector["id"]
- link_type = "vnic-vconnector"
- link_name = vnic["mac_address"]
- state = "up" # TBD
- link_weight = 0 # TBD
- attributes = {}
- if 'network' in vnic:
- attributes = {'network': vnic['network']}
- vconnector['network'] = vnic['network']
- self.inv.set(vconnector)
- self.create_link(self.get_env(),
- source, source_id, target, target_id,
- link_type, link_name, state, link_weight,
- host=host,
- extra_attributes=attributes)
-
- def add_vconnector_pnic_link(self, vconnector, interface):
- ifname = interface['name'] if isinstance(interface, dict) else interface
- if "." in ifname:
- ifname = ifname[:ifname.index(".")]
- host = vconnector["host"]
- pnic = self.inv.find_items({
- "environment": self.get_env(),
- "type": "host_pnic",
- "host": vconnector["host"],
- "name": ifname
- }, get_single=True)
- if not pnic:
- return
- source = vconnector["_id"]
- source_id = vconnector["id"]
- target = pnic["_id"]
- target_id = pnic["id"]
- link_type = "vconnector-host_pnic"
- link_name = pnic["name"]
- 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,
- host=host)