From 84e101ff33672e9ad60ef3634c75bc5f5879fcaa Mon Sep 17 00:00:00 2001 From: Antoine Millet Date: Mon, 15 Jun 2015 11:41:30 +0200 Subject: [PATCH] Implemented nic*_vlans and nic*_mode tags on VMs --- .../node/hypervisor/domains/__init__.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/cloudcontrol/node/hypervisor/domains/__init__.py b/cloudcontrol/node/hypervisor/domains/__init__.py index 7a0f2c3..4ce4af5 100644 --- a/cloudcontrol/node/hypervisor/domains/__init__.py +++ b/cloudcontrol/node/hypervisor/domains/__init__.py @@ -41,7 +41,7 @@ REGEX_TAG_VALUE = '.+' REGEX_TAG_IN_DESCRIPTION = '^@(' + REGEX_TAG_NAME + ')[ ]*?=[ ]*?(' + REGEX_TAG_VALUE + ')$' REGEX_TAG_REPLACE = '^@%s[ ]*?=[ ]*?(' + REGEX_TAG_VALUE + ')$' -NetworkInterface = namedtuple('NetworkInterface', ('source', 'mac', 'model')) +NetworkInterface = namedtuple('NetworkInterface', ('source', 'mac', 'model', 'vlans', 'mode')) class VirtualMachine(object): @@ -92,6 +92,8 @@ class VirtualMachine(object): Tag('nic%s_mac' % i, nic.mac), Tag('nic%s_source' % i, nic.source), Tag('nic%s_model' % i, nic.model), + Tag('nic%s_vlans' % i, ' '.join(nic.vlans)), + Tag('nic%s_mode' % i, nic.mode), ): self.tag_db.add_tag(t) @@ -290,10 +292,27 @@ class VirtualMachine(object): source = nic.find('source').get('bridge') except AttributeError: source = None + + vlans = set() + vlan_list = nic.find('vlan') + if vlan_list is not None: + for tag in vlan_list.findall('tag'): + tid = tag.get('id') + if tid is not None: + vlans.add(tid) + mode = {'yes': 'tagged', 'no': 'untagged'}[vlan_list.get('trunk', 'yes' if len(vlans) > 1 else 'no')] + elif source is not None: + mode = 'untagged' + vlans.add(source[2:]) + else: + mode = 'unknown' + yield NetworkInterface( mac=mac, source=source, model=model, + vlans=vlans, + mode=mode, ) def open_console(self): -- GitLab