diff options
author | Koren Lev <korenlev@gmail.com> | 2017-08-09 14:25:35 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-08-09 14:25:35 +0000 |
commit | 345c902bd05572db6092def8099376e91aabe04b (patch) | |
tree | fb9a3062c7824e5c8166282f6428f1b7d53c33ab /app/discover/find_links_for_pnics.py | |
parent | 16ef24e075255addbcdd78671fa32eacb484389e (diff) | |
parent | 1f78242187a54928d1e5ac4acebbc64c25be4a51 (diff) |
Merge "US2853 ACI data & links added"
Diffstat (limited to 'app/discover/find_links_for_pnics.py')
-rw-r--r-- | app/discover/find_links_for_pnics.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/app/discover/find_links_for_pnics.py b/app/discover/find_links_for_pnics.py index 19828d0..717c1c1 100644 --- a/app/discover/find_links_for_pnics.py +++ b/app/discover/find_links_for_pnics.py @@ -18,10 +18,11 @@ class FindLinksForPnics(FindLinks): pnics = self.inv.find_items({ "environment": self.get_env(), "type": "pnic", - "pnic_type": {"$ne": "switch"} # TODO: make a more educated guess + "pnic_type": "host" }) for pnic in pnics: self.add_pnic_network_links(pnic) + self.add_host_pnic_to_switch_pnic_link(pnic) def add_pnic_network_links(self, pnic): self.log.info("adding links of type: pnic-network") @@ -56,3 +57,31 @@ class FindLinksForPnics(FindLinks): link_type, link_name, state, link_weight, source_label, extra_attributes={"network": target_id}) + + 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({ + "environment": self.get_env(), + "type": "pnic", + "pnic_type": "switch", + "mac_address": host_pnic["mac_address"] + }, {"id": 1}) + if not switch_pnics: + 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) + state = "up" if host_pnic["Link detected"] == "yes" else "down" + link_weight = 0 # TBD + self.create_link(self.get_env(), host_pnic['host'], + source, source_id, target, target_id, + link_type, link_name, state, link_weight)
\ No newline at end of file |