From 922610c996dec8cec0bb145553257081465afcb9 Mon Sep 17 00:00:00 2001 From: Dimitris Aragiorgis Date: Sat, 16 Feb 2013 15:19:33 +0200 Subject: [PATCH] Add GetInstanceNetworks() config method This will be needed for Instance Queries. It walks through the instance's NICs and returns a list network uuids that the NICs are attached to. Signed-off-by: Dimitris Aragiorgis Reviewed-by: Helga Velroyen --- lib/config.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/config.py b/lib/config.py index 532a762..ee26de6 100644 --- a/lib/config.py +++ b/lib/config.py @@ -1572,6 +1572,24 @@ class ConfigWriter: for node_name in nodes) @locking.ssynchronized(_config_lock, shared=1) + def GetInstanceNetworks(self, instance_name): + """Returns set of network UUIDs for instance's nics. + + @rtype: frozenset + + """ + instance = self._UnlockedGetInstanceInfo(instance_name) + if not instance: + raise errors.ConfigurationError("Unknown instance '%s'" % instance_name) + + networks = set() + for nic in instance.nics: + if nic.network: + networks.add(nic.network) + + return frozenset(networks) + + @locking.ssynchronized(_config_lock, shared=1) def GetMultiInstanceInfo(self, instances): """Get the configuration of multiple instances. -- 1.7.10.4