[PATCH] Fix kimchi vlan tagged bridge name

Before we use 'kimchi-{iface_name}-{vlan_id}' as the new created bridge name. It will exceed the maximum length of bridge name when the interface name is too long. For example, when the udev rule of renaming interface name by pci slot is enabled, the interface name could look like 'enP3p9s0f2', which indicates the pci address of nic device. According to systemd udev code, the prefix 'en' stands for 'ethernet'. We don't need preserve it in the bridge name. So this patch change the bridge name convention to 'kb-{iface_name}[-8:]- {vlan_id}'. It can keep the interface information with length less than 16 chars. Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com> --- src/kimchi/model/networks.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/kimchi/model/networks.py b/src/kimchi/model/networks.py index 8f77c12..3786969 100644 --- a/src/kimchi/model/networks.py +++ b/src/kimchi/model/networks.py @@ -32,6 +32,9 @@ from kimchi.rollbackcontext import RollbackContext from kimchi.utils import kimchi_log +KIMCHI_BRIDGE_PREFIX = 'kb' + + class NetworksModel(object): def __init__(self, **kargs): self.conn = kargs['conn'] @@ -180,7 +183,9 @@ class NetworksModel(object): return interfaces def _create_vlan_tagged_bridge(self, interface, vlan_id): - br_name = '-'.join(('kimchi', interface, vlan_id)) + # Truncate the interface name if it exceeds 8 characters to make sure + # the length of bridge name is less than 15 (its maximum value). + br_name = KIMCHI_BRIDGE_PREFIX + interface[-8:] + '-' + vlan_id br_xml = networkxml.create_vlan_tagged_bridge_xml(br_name, interface, vlan_id) conn = self.conn.get() @@ -341,7 +346,7 @@ class NetworkModel(object): except libvirt.libvirtError: pass else: - if bridge.startswith('kimchi-'): + if bridge.startswith(KIMCHI_BRIDGE_PREFIX): conn = self.conn.get() iface = conn.interfaceLookupByName(bridge) iface.destroy(0) -- 1.8.4.2

Applied. Thanks. Regards, Aline Manera
participants (2)
-
Aline Manera
-
Mark Wu