xend/xenapi: Initialize a VLAN PIF's record with the MAC and MTU size
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 11 Aug 2008 15:51:02 +0000 (16:51 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 11 Aug 2008 15:51:02 +0000 (16:51 +0100)
of the created network interface

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
tools/python/xen/xend/XendPIF.py

index ee39ec5413ccd6be313d30f1e85915c50431ea8c..2a2e78acc2c8409f7eb4612ef92109d3888cd1d5 100644 (file)
@@ -95,6 +95,22 @@ def linux_set_mtu(iface, mtu):
     except ValueError:
         return False
 
+def linux_get_mtu(device):
+    return _linux_get_pif_param(device, 'mtu')
+
+def linux_get_mac(device):
+    return _linux_get_pif_param(device, 'link/ether')
+
+def _linux_get_pif_parm(device, param_name):
+    ip_get_dev_data = 'ip link show %s' % device
+    rc, output = commands.getstatusoutput(ip_get_dev_data)
+    if rc == 0:
+        params = output.split(' ')
+        for i in xrange(len(params)):
+            if params[i] == param_name:
+                return params[i+1]
+    return ''
+
 def _create_VLAN(dev, vlan):
     rc, _ = commands.getstatusoutput('vconfig add %s %d' %
                                      (dev, vlan))
@@ -259,8 +275,8 @@ class XendPIF(XendBase):
         # Create the record
         record = {
             "device":  device,
-            "MAC":     '',
-            "MTU":     '',
+            "MAC":     linux_get_mac('%s.%d' % (device, vlan)),
+            "MTU":     linux_get_mtu('%s.%d' % (device, vlan)),
             "network": network_uuid,
             "VLAN":    vlan
             }