summaryrefslogtreecommitdiffstats
path: root/app/discover/find_links_for_vservice_vnics.py
diff options
context:
space:
mode:
authorKoren Lev <korenlev@gmail.com>2017-07-27 15:04:07 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-27 15:04:07 +0000
commit162c03ef301396072c1934e7e7e0c40a841b4fe2 (patch)
tree7a2a2781949252436450ff5832962785061a774a /app/discover/find_links_for_vservice_vnics.py
parentb88c78e3cf2bef22aa2f1c4d0bf305e303bc15f0 (diff)
parent7e83d0876ddb84a45e130eeba28bc40ef53c074b (diff)
Merge "Calipso initial release for OPNFV"
Diffstat (limited to 'app/discover/find_links_for_vservice_vnics.py')
-rw-r--r--app/discover/find_links_for_vservice_vnics.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/app/discover/find_links_for_vservice_vnics.py b/app/discover/find_links_for_vservice_vnics.py
new file mode 100644
index 0000000..e8a91c8
--- /dev/null
+++ b/app/discover/find_links_for_vservice_vnics.py
@@ -0,0 +1,56 @@
+###############################################################################
+# 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 FindLinksForVserviceVnics(FindLinks):
+ def __init__(self):
+ super().__init__()
+
+ def add_links(self, search=None):
+ self.log.info("adding links of type: vservice-vnic")
+
+ if search is None:
+ search = {}
+
+ search.update({"environment": self.get_env(),
+ "type": "vnic",
+ "vnic_type": "vservice_vnic"})
+
+ vnics = self.inv.find_items(search)
+
+ for v in vnics:
+ self.add_link_for_vnic(v)
+
+ def add_link_for_vnic(self, v):
+ host = self.inv.get_by_id(self.get_env(), v["host"])
+ if "Network" not in host["host_type"]:
+ return
+ if "network" not in v:
+ return
+ network = self.inv.get_by_id(self.get_env(), v["network"])
+ if network == []:
+ return
+ vservice_id = v["parent_id"]
+ vservice_id = vservice_id[:vservice_id.rindex('-')]
+ vservice = self.inv.get_by_id(self.get_env(), vservice_id)
+ source = vservice["_id"]
+ source_id = vservice_id
+ target = v["_id"]
+ target_id = v["id"]
+ link_type = "vservice-vnic"
+ link_name = network["name"]
+ state = "up" # TBD
+ link_weight = 0 # TBD
+ self.create_link(self.get_env(), v["host"],
+ source, source_id,
+ target, target_id,
+ link_type, link_name, state, link_weight,
+ extra_attributes={'network': v['network']})