Commit 84e101ff authored by Antoine Millet's avatar Antoine Millet

Implemented nic*_vlans and nic*_mode tags on VMs

parent 8aad7a20
......@@ -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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment