WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-api

[Xen-API] [PATCH 16 of 33] interface-reconfigure: hang all configuration

To: xen-api@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-API] [PATCH 16 of 33] interface-reconfigure: hang all configuration off of the ipdev
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Fri, 18 Dec 2009 14:17:11 +0000
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Fri, 18 Dec 2009 06:24:01 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1261145815@xxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-api-request@lists.xensource.com?subject=help>
List-id: Discussion of API issues surrounding Xen <xen-api.lists.xensource.com>
List-post: <mailto:xen-api@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-api>, <mailto:xen-api-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-api-bounces@xxxxxxxxxxxxxxxxxxx
instead of hanging the ipdev configuration off the physical device.

The ipdev is the device which carries (or, could carry in the case of
IP-configure-mode==None) the IP address. The ipdev is configured in
the same way no matter which datapath is in use (Bridge or Vswitch)
and is conceptually the thing we are really trying to configure.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r b12c62cd92e1 -r 4b5e8e06b548 scripts/interface-reconfigure
--- a/scripts/interface-reconfigure     Fri Dec 18 14:16:32 2009 +0000
+++ b/scripts/interface-reconfigure     Fri Dec 18 14:16:32 2009 +0000
@@ -319,12 +319,12 @@
     except ValueError, x:
         log("Invalid value for mtu = %s" % mtu)
 
-def __open_ifcfg(interface):
-    """Open a network interface configuration file.
+def open_pif_ifcfg(pif):
+    pifrec = db.get_pif_record(pif)
 
-    Opens the configuration file for interface, writes a header and
-    common options and returns the file object.
-    """
+    interface = pif_netdev_name(pif)
+    log("Configuring %s (%s)" % (interface, pifrec['MAC']))
+
     f = ConfigurationFile("/etc/sysconfig/network-scripts/ifcfg-%s" % 
interface)
 
     f.write("# DO NOT EDIT: This file (%s) was autogenerated by %s\n" % \
@@ -332,24 +332,6 @@
     f.write("XEMANAGED=yes\n")
     f.write("DEVICE=%s\n" % interface)
     f.write("ONBOOT=no\n")
-
-    return f
-
-def open_network_ifcfg(pif):
-    bridge = bridge_name(pif)
-    interface = pif_netdev_name(pif)
-    if bridge:
-        return __open_ifcfg(bridge)
-    else:
-        return __open_ifcfg(interface)
-
-
-def open_pif_ifcfg(pif):
-    pifrec = db.get_pif_record(pif)
-
-    log("Configuring %s (%s)" % (pif_netdev_name(pif), pifrec['MAC']))
-
-    f = __open_ifcfg(pif_netdev_name(pif))
 
     if pifrec.has_key('other_config'):
         configure_ethtool(pifrec['other_config'], f)
@@ -767,6 +749,26 @@
     else:
         return pifrec['device']
 
+#
+# IP Network Devices -- network devices with IP configuration
+#
+
+def pif_ipdev_name(pif):
+    """Return the ipdev name associated with pif"""
+    pifrec = db.get_pif_record(pif)
+    nwrec = db.get_network_record(pifrec['network'])
+
+    if nwrec['bridge']:
+        # TODO: sanity check that nwrec['bridgeless'] != 'true'
+        return nwrec['bridge']
+    else:
+        # TODO: sanity check that nwrec['bridgeless'] == 'true'
+        return pif_netdev_name(pif)
+
+#
+# Bridges
+#
+
 def bridge_name(pif):
     """Return the bridge name associated with pif, or None if network is 
bridgeless"""
     pifrec = db.get_pif_record(pif)
@@ -1018,7 +1020,6 @@
     """
 
     slave = configure_pif(get_vlan_slave_of_pif(pif))
-    slave.close()
 
     f = open_pif_ifcfg(pif)
     f.write("VLAN=yes\n")
@@ -1047,6 +1048,8 @@
     bridge = bridge_name(pif)
     if bridge:
         f.write("BRIDGE=%s\n" % bridge)
+
+    f.close()
 
     return f
 
@@ -1201,7 +1204,22 @@
     except ValueError, e:
         log("Error in other-config['static-routes'] format for network %s: %s" 
% (interface, e))
 
-def ipdev_configure_network(pif, f):
+def ipdev_open_ifcfg(pif):
+    ipdev = pif_ipdev_name(pif)
+
+    log("Writing network configuration for %s" % ipdev)
+
+    f = ConfigurationFile("/etc/sysconfig/network-scripts/ifcfg-%s" % ipdev)
+
+    f.write("# DO NOT EDIT: This file (%s) was autogenerated by %s\n" % \
+            (os.path.basename(f.path()), os.path.basename(sys.argv[0])))
+    f.write("XEMANAGED=yes\n")
+    f.write("DEVICE=%s\n" % ipdev)
+    f.write("ONBOOT=no\n")
+
+    return f
+
+def ipdev_configure_network(pif):
     """Write the configuration file for a network.
 
     Writes configuration derived from the network object into the relevant
@@ -1213,34 +1231,29 @@
 
     params:
         pif:  Opaque_ref of pif
-        f :   ConfigurationFile(/path/to/ifcfg) to which we append network 
configuration
     """
 
     pifrec = db.get_pif_record(pif)
-    nw = pifrec['network']
-    nwrec = db.get_network_record(nw)
+    nwrec = db.get_network_record(pifrec['network'])
+
+    ipdev = pif_ipdev_name(pif)
+
+    f = ipdev_open_ifcfg(pif)
+
+    mode = pifrec['ip_configuration_mode']
+    log("Configuring %s using %s configuration" % (ipdev, mode))
+
     oc = None
-    bridge = bridge_name(pif)
-    interface = pif_netdev_name(pif)
-    if bridge:
-        device = bridge
-    else:
-        device = interface
-
-    if nwrec.has_key('other_config'):
-        configure_ethtool(nwrec['other_config'], f)
-        configure_mtu(nwrec['other_config'], f)
-        ipdev_configure_static_routes(device, nwrec['other_config'], f)
-
-
     if pifrec.has_key('other_config'):
         oc = pifrec['other_config']
 
-    if device == bridge:
+    if ipdev != pif_netdev_name(pif):
         f.write("TYPE=Bridge\n")
         f.write("DELAY=0\n")
         f.write("STP=off\n")
         f.write("PIFDEV=%s\n" % pif_netdev_name(pif))
+    else:
+        f.write("TYPE=Ethernet\n")
 
     if pifrec['ip_configuration_mode'] == "DHCP":
         f.write("BOOTPROTO=dhcp\n")
@@ -1254,6 +1267,12 @@
         f.write("BOOTPROTO=none\n")
     else:
         raise Error("Unknown ip-configuration-mode %s" % 
pifrec['ip_configuration_mode'])
+
+    if nwrec.has_key('other_config'):
+        configure_ethtool(nwrec['other_config'], f)
+        configure_mtu(nwrec['other_config'], f)
+
+        ipdev_configure_static_routes(ipdev, nwrec['other_config'], f)
 
     if pifrec.has_key('DNS') and pifrec['DNS'] != "":
         ServerList = pifrec['DNS'].split(",")
@@ -1301,7 +1320,8 @@
                 log('Warning: multiple pifs with "defaultroute=true" - 
choosing %s and ignoring %s' % \
                         (db.get_pif_record(defaultroute_pif)['device'], 
__pifrec['device']))
 
-    # If no pif is explicitly specified then use the mgmt pif for 
peerdns/defaultroute
+    # If no pif is explicitly specified then use the mgmt pif for
+    # peerdns/defaultroute.
     if peerdns_pif == None:
         peerdns_pif = management_pif
     if defaultroute_pif == None:
@@ -1314,47 +1334,38 @@
         fnetwork = ConfigurationFile("/etc/sysconfig/network")
         for line in fnetwork.readlines():
             if is_dnsdev and line.lstrip().startswith('DNSDEV='):
-                fnetwork.write('DNSDEV=%s\n' % bridge)
+                fnetwork.write('DNSDEV=%s\n' % ipdev)
                 is_dnsdev = False
             elif is_gatewaydev and line.lstrip().startswith('GATEWAYDEV='):
-                fnetwork.write('GATEWAYDEV=%s\n' % bridge)
+                fnetwork.write('GATEWAYDEV=%s\n' % ipdev)
                 is_gatewaydev = False
             else:
                 fnetwork.write(line)
 
         if is_dnsdev:
-            fnetwork.write('DNSDEV=%s\n' % bridge_name(pif))
+            fnetwork.write('DNSDEV=%s\n' % ipdev)
         if is_gatewaydev:
-            fnetwork.write('GATEWAYDEV=%s\n' % bridge_name(pif))
+            fnetwork.write('GATEWAYDEV=%s\n' % ipdev)
 
         fnetwork.close()
         f.attach_child(fnetwork)
 
-    return
+    return f
 
 #
 # Toplevel actions
 #
 
 def action_up(pif):
-
     pifrec = db.get_pif_record(pif)
 
-    f = configure_pif(pif)
+    f = ipdev_configure_network(pif)
 
-    interface = pif_netdev_name(pif)
     bridge = bridge_name(pif)
-    mode = pifrec['ip_configuration_mode']
 
     if bridge:
-        log("Configuring %s using %s configuration" % (bridge, mode))
-        br = open_network_ifcfg(pif)
-        ipdev_configure_network(pif, br)
-        br.close()
-        f.attach_child(br)
-    else:
-        log("Configuring %s using %s configuration" % (interface, mode))
-        ipdev_configure_network(pif, f)
+        pf = configure_pif(pif)
+        f.attach_child(pf)
 
     f.close()
 
@@ -1408,24 +1419,15 @@
     bring_down_interface(pif, destroy=True)
 
 def action_rewrite(pif):
-
     pifrec = db.get_pif_record(pif)
 
-    f = configure_pif(pif)
+    f = ipdev_configure_network(pif)
 
-    interface = pif_netdev_name(pif)
     bridge = bridge_name(pif)
-    mode = pifrec['ip_configuration_mode']
 
     if bridge:
-        log("Configuring %s using %s configuration" % (bridge, mode))
-        br = open_network_ifcfg(pif)
-        ipdev_configure_network(pif, br)
-        br.close()
-        f.attach_child(br)
-    else:
-        log("Configuring %s using %s configuration" % (interface, mode))
-        ipdev_configure_network(pif, f)
+        pf = configure_pif(pif)
+        f.attach_child(pf)
 
     f.close()
 

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api