aboutsummaryrefslogtreecommitdiffstats
path: root/app/discover/link_finders/find_links_for_instance_vnics.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/link_finders/find_links_for_instance_vnics.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/link_finders/find_links_for_instance_vnics.py')
-rw-r--r--app/discover/link_finders/find_links_for_instance_vnics.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/app/discover/link_finders/find_links_for_instance_vnics.py b/app/discover/link_finders/find_links_for_instance_vnics.py
new file mode 100644
index 0000000..7e0273d
--- /dev/null
+++ b/app/discover/link_finders/find_links_for_instance_vnics.py
@@ -0,0 +1,60 @@
+###############################################################################
+# 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 FindLinksForInstanceVnics(FindLinks):
+ def __init__(self):
+ super().__init__()
+
+ def add_links(self):
+ self.log.info("adding links of type: instance-vnic")
+ vnics = self.inv.find_items({
+ "environment": self.get_env(),
+ "type": "vnic",
+ "vnic_type": "instance_vnic"
+ })
+ for v in vnics:
+ self.add_link_for_vnic(v)
+
+ def add_link_for_vnic(self, v):
+ instance = self.inv.get_by_id(self.get_env(), v["instance_id"])
+ if "network_info" not in instance:
+ self.log.warn("add_link_for_vnic: " +
+ "network_info missing in instance: %s ",
+ instance["id"])
+ return
+ host = self.inv.get_by_id(self.get_env(), instance["host"])
+ host_types = host["host_type"]
+ if "Network" not in host_types and "Compute" not in host_types:
+ return []
+ source = instance["_id"]
+ source_id = instance["id"]
+ target = v["_id"]
+ target_id = v["id"]
+ link_type = "instance-vnic"
+ # find related network
+ network_name = None
+ network_id = None
+ for net in instance["network_info"]:
+ if net["devname"] == v["id"]:
+ network_name = net["network"]["label"]
+ network_id = net['network']['id']
+ v['network'] = network_id
+ self.inv.set(v)
+ break
+ state = "up" # TBD
+ link_weight = 0 # TBD
+ attributes = {} if not network_id else {'network': network_id}
+ self.create_link(self.get_env(),
+ source, source_id, target, target_id,
+ link_type, network_name, state, link_weight,
+ host=host["name"],
+ extra_attributes=attributes)