X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=xenserver%2Fopt_xensource_libexec_interface-reconfigure;h=301251f7623a640d5a9d0e3cbfc2a8c5c6341d1e;hb=431d8ad2a0a2e20d1719f77dda66da70acf0d38f;hp=0b84d3795a788624bcf54f7e9541a76763b2ec7d;hpb=05e2ad788d25615602a5fe01acaa6d5617280945;p=openvswitch diff --git a/xenserver/opt_xensource_libexec_interface-reconfigure b/xenserver/opt_xensource_libexec_interface-reconfigure index 0b84d379..301251f7 100755 --- a/xenserver/opt_xensource_libexec_interface-reconfigure +++ b/xenserver/opt_xensource_libexec_interface-reconfigure @@ -265,16 +265,12 @@ def get_netdev_tx_queue_len(device): return None def get_netdev_by_mac(mac): - maybe = None for device in os.listdir("/sys/class/net"): dev_mac = get_netdev_mac(device) - if dev_mac and mac.lower() == dev_mac.lower(): - if get_netdev_tx_queue_len(device): + if (dev_mac and mac.lower() == dev_mac.lower() and + get_netdev_tx_queue_len(device)): return device - if not maybe: - # Probably a datapath internal port. - maybe = device - return maybe + return None class DatabaseCache(object): def __init__(self, session_ref=None, cache_file=None): @@ -471,7 +467,7 @@ For a non-VLAN, non-bond master PIF, the PIF is its own physical device PIF. pifrec = db.get_pif_record(pif) if pifrec['VLAN'] != '-1': - return [get_vlan_slave_of_pif(pif)] + return get_physdev_pifs(get_vlan_slave_of_pif(pif)) elif len(pifrec['bond_master_of']) != 0: return get_bond_slaves_of_pif(pif) else: @@ -746,7 +742,7 @@ def mtu_setting(oc): log("Invalid value for mtu = %s" % mtu) return [] -def configure_netdev(pif): +def configure_local_port(pif): pifrec = db.get_pif_record(pif) datapath = datapath_name(pif) ipdev = ipdev_name(pif) @@ -755,6 +751,10 @@ def configure_netdev(pif): nw = pifrec['network'] nwrec = db.get_network_record(nw) + pif_oc = pifrec['other_config'] + nw_oc = nwrec['other_config'] + + # IP (except DHCP) and MTU. ifconfig_argv = ['/sbin/ifconfig', ipdev, 'up'] gateway = '' if pifrec['ip_configuration_mode'] == "DHCP": @@ -768,35 +768,37 @@ def configure_netdev(pif): pass else: raise Error("Unknown IP-configuration-mode %s" % pifrec['ip_configuration_mode']) - ifconfig_argv += mtu_setting(oc) + ifconfig_argv += mtu_setting(nw_oc) run_command(ifconfig_argv) (peerdns_pif, defaultroute_pif) = find_distinguished_pifs(pif) + # /etc/resolv.conf if peerdns_pif == pif: f = ConfigurationFile('resolv.conf', "/etc") - if oc.has_key('domain'): - f.write("search %s\n" % oc['domain']) + if pif_oc.has_key('domain'): + f.write("search %s\n" % pif_oc['domain']) for dns in pifrec['DNS'].split(","): f.write("nameserver %s\n" % dns) f.close() f.apply() f.commit() + # Routing. if defaultroute_pif == pif and gateway != '': run_command(['/sbin/ip', 'route', 'replace', 'default', 'via', gateway, 'dev', ipdev]) - - if oc.has_key('static-routes'): - for line in oc['static-routes'].split(','): + if nw_oc.has_key('static-routes'): + for line in nw_oc['static-routes'].split(','): network, masklen, gateway = line.split('/') run_command(['/sbin/ip', 'route', 'add', '%s/%s' % (network, masklen), 'via', gateway, 'dev', ipdev]) # Ethtool. - run_ethtool(ipdev, oc) + run_ethtool(ipdev, nw_oc) + # DHCP. if pifrec['ip_configuration_mode'] == "DHCP": print print "Determining IP information for %s..." % ipdev, @@ -809,6 +811,14 @@ def configure_netdev(pif): else: print 'failed.' +def configure_physdev(pif): + pifrec = db.get_pif_record(pif) + device = pifrec['device'] + oc = pifrec['other_config'] + + run_command(['/sbin/ifconfig', device, 'up'] + mtu_setting(oc)) + run_ethtool(device, oc) + def modify_config(commands): run_command(['/root/vswitch/bin/ovs-cfg-mod', '-vANY:console:emer', '-F', '/etc/ovs-vswitchd.conf'] @@ -829,7 +839,7 @@ def configure_bond(pif): argv = ['--del-match=bonding.%s.[!0-9]*' % interface] argv += ["--add=bonding.%s.slave=%s" % (interface, slave) for slave in physdev_names] - argv += ['--add=bonding.%s.fake-iface=true'] + argv += ['--add=bonding.%s.fake-iface=true' % interface] if pifrec['MAC'] != "": argv += ['--add=port.%s.mac=%s' % (interface, pifrec['MAC'])] @@ -979,11 +989,11 @@ def action_up(pif): # enables or disables bond slaves based on whether carrier is # detected when they are added, and a network device that is down # always reports "no carrier". - bond_slave_physdev_names = [] + bond_slave_physdev_pifs = [] for slave in bond_slaves: - bond_slave_physdev_names += physdev_names(slave) - for slave_physdev_name in bond_slave_physdev_names: - up_netdev(slave_physdev_name) + bond_slave_physdev_pifs += get_physdev_pifs(slave) + for slave_physdev_pif in set(bond_slave_physdev_pifs): + configure_physdev(slave_physdev_pif) # Now modify the ovs-vswitchd config file. argv = [] @@ -1020,11 +1030,11 @@ def action_up(pif): # slaves (which we brought up earlier). if vlan_slave: up_netdev(ipdev_name(vlan_slave)) - for physdev_name in set(physdev_names) - set(bond_slave_physdev_names): - up_netdev(physdev_name) + for physdev_pif in set(physdev_pifs) - set(bond_slave_physdev_pifs): + configure_physdev(physdev_pif) - # Configure network devices. - configure_netdev(pif) + # Configure network device for local port. + configure_local_port(pif) # Update /etc/issue (which contains the IP address of the management interface) os.system("/sbin/update-issue")