diff options
author | Ilia Abashin <abashinos@gmail.com> | 2017-09-01 15:51:52 +0300 |
---|---|---|
committer | Ilia Abashin <abashinos@gmail.com> | 2017-09-01 15:51:52 +0300 |
commit | 7b4235dced0c66096638bebd5cc98a631538b0e1 (patch) | |
tree | ea6e17af0fbd854ef7b2053aa7c1e71949d977aa /app/discover/link_finders/find_links_for_oteps.py | |
parent | 692489cc50c8025ede1646627a7a583a4feb3798 (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/link_finders/find_links_for_oteps.py')
-rw-r--r-- | app/discover/link_finders/find_links_for_oteps.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/app/discover/link_finders/find_links_for_oteps.py b/app/discover/link_finders/find_links_for_oteps.py new file mode 100644 index 0000000..b5d1667 --- /dev/null +++ b/app/discover/link_finders/find_links_for_oteps.py @@ -0,0 +1,88 @@ +############################################################################### +# 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.link_finders.find_links import FindLinks + + +class FindLinksForOteps(FindLinks): + def __init__(self): + super().__init__() + + def add_links(self): + self.log.info("adding link types: " + + "vedge-otep, otep-vconnector, otep-host_pnic") + oteps = self.inv.find_items({ + "environment": self.get_env(), + "type": "otep" + }) + for otep in oteps: + self.add_vedge_otep_link(otep) + self.add_otep_vconnector_link(otep) + self.add_otep_pnic_link(otep) + + def add_vedge_otep_link(self, otep): + vedge = self.inv.get_by_id(self.get_env(), otep["parent_id"]) + source = vedge["_id"] + source_id = vedge["id"] + target = otep["_id"] + target_id = otep["id"] + link_type = "vedge-otep" + link_name = vedge["name"] + "-otep" + 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=vedge["host"]) + + def add_otep_vconnector_link(self, otep): + if "vconnector" not in otep: + return + vconnector = self.inv.find_items({ + "environment": self.get_env(), + "type": "vconnector", + "host": otep["host"], + "name": otep["vconnector"] + }, get_single=True) + if not vconnector: + return + source = otep["_id"] + source_id = otep["id"] + target = vconnector["_id"] + target_id = vconnector["id"] + link_type = "otep-vconnector" + link_name = otep["name"] + "-" + otep["vconnector"] + 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=otep["host"]) + + def add_otep_pnic_link(self, otep): + pnic = self.inv.find_items({ + "environment": self.get_env(), + "type": "host_pnic", + "host": otep["host"], + "IP Address": otep["ip_address"] + }, get_single=True) + if not pnic: + return + source = otep["_id"] + source_id = otep["id"] + target = pnic["_id"] + target_id = pnic["id"] + link_type = "otep-host_pnic" + link_name = otep["host"] + "pnic" + 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=otep["host"]) |