|   | 
      | 
  
  
      | 
      | 
  
 
     | 
    | 
  
  
     | 
    | 
  
  
    |   | 
      | 
  
  
    | 
         
xen-api
[Xen-API] [PATCH 14 of 33] interface-reconfigure: Write DNSDEV to	/etc/s
 
instead of rewriteing ifcfg-* to configure PEERDNS=yes|no
This way is much simpler.
Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
diff -r 3e604242abf0 -r af610bc596af 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
@@ -943,8 +943,7 @@
     if oc and oc.has_key('domain'):
         f.write("DOMAIN='%s'\n" % oc['domain'].replace(',', ' '))
 
-    # We only allow one ifcfg-* to have PEERDNS=yes and there can be
-    # only one GATEWAYDEV in /etc/sysconfig/network.
+    # There can be only one DNSDEV and one GATEWAYDEV in 
/etc/sysconfig/network.
     #
     # The peerdns pif will be the one with
     # pif::other-config:peerdns=true, or the mgmt pif if none have
@@ -954,22 +953,20 @@
     # pif::other-config:defaultroute=true, or the mgmt pif if none
     # have this set.
 
-    # Work out which pif on this host should be the one with
-    # PEERDNS=yes and which should be the GATEWAYDEV
+    # Work out which pif on this host should be the DNSDEV and which
+    # should be the GATEWAYDEV
     #
     # Note: we prune out the bond master pif (if it exists). This is
     # because when we are called to bring up an interface with a bond
     # master, it is implicit that we should bring down that master.
-    pifs_on_host = [ __pif for __pif in db.get_all_pifs() if
-                     not  __pif in get_bond_masters_of_pif(pif) ]
-    other_pifs_on_host = [ __pif for __pif in pifs_on_host if __pif != pif ]
 
-    peerdns_pif = None
-    defaultroute_pif = None
+    pifs_on_host = [p for p in db.get_all_pifs() if not p in 
get_bond_masters_of_pif(pif)]
 
     # loop through all the pifs on this host looking for one with
     #   other-config:peerdns = true, and one with
     #   other-config:default-route=true
+    peerdns_pif = None
+    defaultroute_pif = None
     for __pif in pifs_on_host:
         __pifrec = db.get_pif_record(__pif)
         __oc = __pifrec['other_config']
@@ -992,42 +989,28 @@
     if defaultroute_pif == None:
         defaultroute_pif = management_pif
 
-    # Update all the other network's ifcfg files and ensure consistency
-    for __pif in other_pifs_on_host:
-        __f = open_network_ifcfg(__pif)
-        peerdns_line_wanted = 'PEERDNS=%s\n' % ((__pif == peerdns_pif) and 
'yes' or 'no')
-        lines =  __f.readlines()
+    is_dnsdev = peerdns_pif == pif
+    is_gatewaydev = defaultroute_pif == pif
 
-        if not peerdns_line_wanted in lines:
-            # the PIF selected for DNS has changed and as a result this ifcfg 
file needs rewriting
-            for line in lines:
-                if not line.lstrip().startswith('PEERDNS'):
-                    __f.write(line)
-            log("Setting %s in %s" % (peerdns_line_wanted.strip(), __f.path()))
-            __f.write(peerdns_line_wanted)
-            __f.close()
-            f.attach_child(__f)
+    if is_dnsdev or is_gatewaydev:
+        fnetwork = ConfigurationFile("/etc/sysconfig/network")
+        for line in fnetwork.readlines():
+            if is_dnsdev and line.lstrip().startswith('DNSDEV='):
+                fnetwork.write('DNSDEV=%s\n' % bridge)
+                is_dnsdev = False
+            elif is_gatewaydev and line.lstrip().startswith('GATEWAYDEV='):
+                fnetwork.write('GATEWAYDEV=%s\n' % bridge)
+                is_gatewaydev = False
+            else:
+                fnetwork.write(line)
 
-        else:
-            # There is no need to change this ifcfg file.  So don't 
attach_child.
-            pass
+        if is_dnsdev:
+            fnetwork.write('DNSDEV=%s\n' % bridge_name(pif))
+        if is_gatewaydev:
+            fnetwork.write('GATEWAYDEV=%s\n' % bridge_name(pif))
 
-    # ... and for this pif too
-    f.write('PEERDNS=%s\n' % ((pif == peerdns_pif) and 'yes' or 'no'))
-
-    # Update gatewaydev
-    fnetwork = ConfigurationFile("/etc/sysconfig/network")
-    for line in fnetwork.readlines():
-        if line.lstrip().startswith('GATEWAY') :
-            continue
-        fnetwork.write(line)
-    if defaultroute_pif:
-        gatewaydev = bridge_name(defaultroute_pif)
-        if not gatewaydev:
-            gatewaydev = interface_name(defaultroute_pif)
-        fnetwork.write('GATEWAYDEV=%s\n' % gatewaydev)
-    fnetwork.close()
-    f.attach_child(fnetwork)
+        fnetwork.close()
+        f.attach_child(fnetwork)
 
     return
 
_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api
 |   
 
| <Prev in Thread] | 
Current Thread | 
[Next in Thread>
 |  
- [Xen-API] [PATCH 04 of 33] interface-reconfigure: Only include	objects on the current host in the DatabaseCache, (continued)
- [Xen-API] [PATCH 04 of 33] interface-reconfigure: Only include	objects on the current host in the DatabaseCache, Ian Campbell
 
- [Xen-API] [PATCH 05 of 33] interface-reconfigure: Restrict the	fields pulled from XenAPI into DatabaseCache, Ian Campbell
 
- [Xen-API] [PATCH 06 of 33] interface-reconfigure: Explicity cache	database configuration in /var/xapi/network.dbcache, Ian Campbell
 
- [Xen-API] [PATCH 07 of 33] interface-reconfigure: Cleanup whitespace, Ian Campbell
 
- [Xen-API] [PATCH 08 of 33] interface-reconfigure: drop "--force all	down", Ian Campbell
 
- [Xen-API] [PATCH 09 of 33] interface-reconfigure: Reimplement	forced rewrite, Ian Campbell
 
- [Xen-API] [PATCH 10 of 33] interface-reconfigure: Reformat some	comments slightly, move logging function to top of file, Ian Campbell
 
- [Xen-API] [PATCH 11 of 33] interface-reconfigure: Add run_command	utility to encapsulate os.spawnl usage, Ian Campbell
 
- [Xen-API] [PATCH 12 of 33] interface-reconfigure: Add pif_is_vlan	utility function, Ian Campbell
 
- [Xen-API] [PATCH 13 of 33] interface-reconfigure: do not remove	ifcfg files when unplugging a PIF, Ian Campbell
 
- [Xen-API] [PATCH 14 of 33] interface-reconfigure: Write DNSDEV to	/etc/sysconfig/network,
Ian Campbell <=
 
- [Xen-API] [PATCH 17 of 33] interface-reconfigure: Rename some	functions to match vswitch version, Ian Campbell
 
- [Xen-API] [PATCH 15 of 33] interface-reconfigure: Various	refactoring, Ian Campbell
 
- [Xen-API] [PATCH 18 of 33] interface-reconfigure: use the same	other-config:ethtool-* and MTU as vswitch version, Ian Campbell
 
- [Xen-API] [PATCH 20 of 33] interface-reconfigure: add pif_is_bond(), Ian Campbell
 
- [Xen-API] [PATCH 19 of 33] interface-reconfigure: further separate	the concept of ipdev and datapath, Ian Campbell
 
- [Xen-API] [PATCH 21 of 33] interface-reconfigure: explicitly rename	devices early, Ian Campbell
 
- [Xen-API] [PATCH 22 of 33] interface-reconfigure: move	/etc/init.d/management-interface to this repository, Ian Campbell
 
- [Xen-API] [PATCH 23 of 33] interface-reconfigure: Do not try to	bring down interfaces before forcing them up, Ian Campbell
 
- [Xen-API] [PATCH 24 of 33] interface-reconfigure: do not require a	PIF for rewrite action, Ian Campbell
 
- [Xen-API] [PATCH 25 of 33] interface-reconfigure: Refactor the	action_* methods, Ian Campbell
 
 
 
 
 |  
  
 | 
    | 
  
  
    |   | 
    |