X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=xenserver%2Fopt_xensource_libexec_interface-reconfigure;h=3b5c8617aec89a072a75fde24db121f1ffb7c3c0;hb=85606e05b691be7c2f2d4bcf0e91170b71ec8fbb;hp=153f509ed4abd04f588a43b8e160445b807fa69f;hpb=64ddb6fecfe21a7b50c5907dd88de67a87ec6eca;p=sliver-openvswitch.git diff --git a/xenserver/opt_xensource_libexec_interface-reconfigure b/xenserver/opt_xensource_libexec_interface-reconfigure index 153f509ed..3b5c8617a 100755 --- a/xenserver/opt_xensource_libexec_interface-reconfigure +++ b/xenserver/opt_xensource_libexec_interface-reconfigure @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python # # Copyright (c) 2008,2009 Citrix Systems, Inc. # @@ -34,6 +34,7 @@ --pif-uuid The UUID of a PIF. --force An interface name. --root-prefix=DIR Use DIR as alternate root directory (for testing). + --no-syslog Write log messages to stderr instead of system log. """ # Notes: @@ -49,6 +50,7 @@ import syslog import traceback import re import random +import syslog management_pif = None @@ -143,10 +145,11 @@ def netdev_remap_name(pif, already_renamed=[]): return None def rename_netdev(old_name, new_name): - log("Changing the name of %s to %s" % (old_name, new_name)) - run_command(['/sbin/ifconfig', old_name, 'down']) - if not run_command(['/sbin/ip', 'link', 'set', old_name, 'name', new_name]): - raise Error("Could not rename %s to %s" % (old_name, new_name)) + raise Error("Trying to rename %s to %s - This functionality has been removed" % (old_name, new_name)) + # log("Changing the name of %s to %s" % (old_name, new_name)) + # run_command(['/sbin/ifconfig', old_name, 'down']) + # if not run_command(['/sbin/ip', 'link', 'set', old_name, 'name', new_name]): + # raise Error("Could not rename %s to %s" % (old_name, new_name)) pifrec = db().get_pif_record(pif) device = pifrec['device'] @@ -196,13 +199,19 @@ def ifup(netdev): """Bring up a network interface""" if not os.path.exists(root_prefix() + "/etc/sysconfig/network-scripts/ifcfg-%s" % netdev): raise Error("ifup: device %s exists but ifcfg-%s does not" % (netdev,netdev)) + d = os.getenv("DHCLIENTARGS","") + if os.path.exists("/etc/firstboot.d/data/firstboot_in_progress"): + os.putenv("DHCLIENTARGS", d + " -T 240 " ) run_command(["/sbin/ifup", netdev]) + os.putenv("DHCLIENTARGS", d ) # # # def pif_rename_physical_devices(pif): + if pif_is_tunnel(pif): + return if pif_is_vlan(pif): pif = pif_get_vlan_slave(pif) @@ -233,7 +242,7 @@ def ipdev_configure_static_routes(interface, oc, f): 172.18.0.0/16 via 192.168.0.4 dev xenbr1 """ if oc.has_key('static-routes'): - # The key is present - extract comma seperates entries + # The key is present - extract comma separates entries lines = oc['static-routes'].split(',') else: # The key is not present, i.e. there are no static routes @@ -266,6 +275,7 @@ def ipdev_open_ifcfg(pif): f.write("XEMANAGED=yes\n") f.write("DEVICE=%s\n" % ipdev) f.write("ONBOOT=no\n") + f.write("NOZEROCONF=yes\n") return f @@ -285,7 +295,8 @@ def ipdev_configure_network(pif, dp): """ pifrec = db().get_pif_record(pif) - nwrec = db().get_network_record(pifrec['network']) + nw = pifrec['network'] + nwrec = db().get_network_record(nw) ipdev = pif_ipdev_name(pif) @@ -320,12 +331,13 @@ def ipdev_configure_network(pif, dp): if len(offload): f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload)) - mtu = mtu_setting(nwrec['other_config']) - if mtu: - f.write("MTU=%s\n" % mtu) - ipdev_configure_static_routes(ipdev, nwrec['other_config'], f) + mtu = mtu_setting(nw, "Network", nwrec['other_config']) + if mtu: + f.write("MTU=%s\n" % mtu) + + if pifrec.has_key('DNS') and pifrec['DNS'] != "": ServerList = pifrec['DNS'].split(",") for i in range(len(ServerList)): f.write("DNS%d=%s\n" % (i+1, ServerList[i])) @@ -351,6 +363,10 @@ def ipdev_configure_network(pif, dp): pifs_on_host = [p for p in db().get_all_pifs() if not p in pif_get_bond_masters(pif)] + # now prune out bond slaves as they are not connected to the IP + # stack and so cannot be used as gateway or DNS devices. + pifs_on_host = [ p for p in pifs_on_host if len(pif_get_bond_masters(p)) == 0] + # loop through all the pifs on this host looking for one with # other-config:peerdns = true, and one with # other-config:default-route=true @@ -412,7 +428,7 @@ def action_up(pif, force): pifrec = db().get_pif_record(pif) ipdev = pif_ipdev_name(pif) - dp = DatapathFactory(pif) + dp = DatapathFactory()(pif) log("action_up: %s" % ipdev) @@ -452,7 +468,7 @@ def action_up(pif, force): def action_down(pif): ipdev = pif_ipdev_name(pif) - dp = DatapathFactory(pif) + dp = DatapathFactory()(pif) log("action_down: %s" % ipdev) @@ -460,6 +476,9 @@ def action_down(pif): dp.bring_down() +def action_rewrite(): + DatapathFactory().rewrite() + # This is useful for reconfiguring the mgmt interface after having lost connectivity to the pool master def action_force_rewrite(bridge, config): def getUUID(): @@ -519,6 +538,8 @@ def action_force_rewrite(bridge, config): f.write('\t\t\n') f.write('\t\tOpaqueRef:NULL\n') f.write('\t\t-1\n') + f.write('\t\t\n') + f.write('\t\t\n') f.write('\t\t%s\n' % interface) f.write('\t\t%s\n' % mac) f.write('\t\t\n') @@ -582,6 +603,7 @@ def main(argv=None): "management", "mac=", "device=", "mode=", "ip=", "netmask=", "gateway=", "root-prefix=", + "no-syslog", "help" ] arglist, args = getopt.gnu_getopt(argv[1:], shortops, longops) except getopt.GetoptError, msg: @@ -604,12 +626,15 @@ def main(argv=None): force_rewrite_config[o[2:]] = a elif o == "--root-prefix": set_root_prefix(a) + elif o == "--no-syslog": + set_log_destination("stderr") elif o == "-h" or o == "--help": print __doc__ % {'command-name': os.path.basename(argv[0])} return 0 - syslog.openlog(os.path.basename(argv[0])) - log("Called as " + str.join(" ", argv)) + if get_log_destination() == "syslog": + syslog.openlog(os.path.basename(argv[0])) + log("Called as " + str.join(" ", argv)) if len(args) < 1: raise Usage("Required option not present") @@ -659,7 +684,7 @@ def main(argv=None): pif = db().get_pif_by_uuid(pif_uuid) if action == "rewrite": - pass + action_rewrite() else: if not pif: raise Usage("No PIF given")