X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=xenserver%2Fopt_xensource_libexec_interface-reconfigure;h=eae198b914823d23bdc819922b5e638efe4861d6;hb=5990cd46192920da5faedde84b6123b854ec0555;hp=61027c5fc886268868e3fdfc03813a431a6cde6f;hpb=f1acd62b54376a425a975f9af501c4c8c5689b39;p=openvswitch diff --git a/xenserver/opt_xensource_libexec_interface-reconfigure b/xenserver/opt_xensource_libexec_interface-reconfigure index 61027c5f..eae198b9 100755 --- a/xenserver/opt_xensource_libexec_interface-reconfigure +++ b/xenserver/opt_xensource_libexec_interface-reconfigure @@ -5,22 +5,26 @@ # """Usage: - %(command-name)s --session --pif [up|down|rewrite] - %(command-name)s --force [up|down|rewrite ] + %(command-name)s up + %(command-name)s down + %(command-name)s [] rewrite + %(command-name)s --force up + %(command-name)s --force down + %(command-name)s --force rewrite --device= %(command-name)s --force all down - where, - = --device= --mode=dhcp - = --device= --mode=static --ip= --netmask= [--gateway=] + where is one of: + --session --pif + --pif-uuid + and is one of: + --mode=dhcp + --mode=static --ip= --netmask= [--gateway=] Options: --session A session reference to use to access the xapi DB - --pif A PIF reference. - --force-interface An interface name. Mutually exclusive with --session/--pif. - - Either both --session and --pif or just --pif-uuid. - - is either "up" or "down" or "rewrite" + --pif A PIF reference within the session. + --pif-uuid The UUID of a PIF. + --force An interface name. """ # @@ -28,7 +32,6 @@ # # --output-directory= Write configuration to . Also disables actually # raising/lowering the interfaces -# --pif-uuid A PIF UUID, use instead of --session/--pif. # # # @@ -38,24 +41,6 @@ # 3. A network may have an associated bridge, allowing vifs to be attached # 4. A network may be bridgeless (there's no point having a bridge over a storage pif) -# XXX: --force-interface=all down - -# XXX: --force-interface rewrite - -# XXX: Sometimes this leaves "orphaned" datapaths, e.g. a datapath whose -# only port is the local port. Should delete those. - -# XXX: This can leave crud in ovs-vswitchd.conf in this scenario: -# - Create bond in XenCenter. -# - Create VLAN on bond in XenCenter. -# - Attempt to delete bond in XenCenter (this will fail because there -# is a VLAN on the bond, although the error may not be reported -# until the next step) -# - Delete VLAN in XenCenter. -# - Delete bond in XenCenter. -# At this point there will still be some configuration data for the bond -# or the VLAN in ovs-vswitchd.conf. - import XenAPI import os, sys, getopt, time, signal import syslog @@ -71,8 +56,8 @@ output_directory = None db = None management_pif = None -dbcache_file = "/etc/ovs-vswitch.dbcache" -vswitch_config_dir = "/etc/openvswitch" +vswitch_state_dir = "/var/lib/openvswitch/" +dbcache_file = vswitch_state_dir + "dbcache" class Usage(Exception): def __init__(self, msg): @@ -370,6 +355,12 @@ PIF_ATTRS = { 'uuid': (str_to_xml,str_from_xml), 'MAC': (str_to_xml,str_from_xml), 'other_config': (lambda x, p, t, v: otherconfig_to_xml(x, p, v, PIF_OTHERCONFIG_ATTRS), lambda n: otherconfig_from_xml(n, PIF_OTHERCONFIG_ATTRS)), + + # Special case: We write the current value + # PIF.currently-attached to the cache but since it will + # not be valid when we come to use the cache later + # (i.e. after a reboot) we always read it as False. + 'currently_attached': (bool_to_xml, lambda n: False), } PIF_OTHERCONFIG_ATTRS = [ 'domain', 'peerdns', 'defaultroute', 'mtu', 'static-routes' ] + \ @@ -450,7 +441,11 @@ class DatabaseCache(object): rec = session.xenapi.network.get_record(n) self.__networks[n] = {} for f in NETWORK_ATTRS: - self.__networks[n][f] = rec[f] + if f == "PIFs": + # drop PIFs on other hosts + self.__networks[n][f] = [p for p in rec[f] if self.__pif_on_host(p)] + else: + self.__networks[n][f] = rec[f] self.__networks[n]['other_config'] = {} for f in NETWORK_OTHERCONFIG_ATTRS: if not rec['other_config'].has_key(f): continue @@ -708,10 +703,7 @@ def log_pif_action(action, pif): rec['ip_configuration_mode'] = pifrec['ip_configuration_mode'] rec['action'] = action rec['interface-name'] = interface_name(pif) - if action == "rewrite": - rec['message'] = "Rewrite PIF %(uuid)s configuration" % rec - else: - rec['message'] = "Bring %(action)s PIF %(uuid)s" % rec + rec['message'] = "Bring %(action)s PIF %(uuid)s" % rec log("%(message)s: %(interface-name)s configured as %(ip_configuration_mode)s" % rec) def get_bond_masters_of_pif(pif): @@ -1038,7 +1030,7 @@ def configure_physdev(pif): run_ethtool(device, oc) def modify_config(commands): - run_command(['/root/vswitch/bin/ovs-cfg-mod', '-vANY:console:emer', + run_command(['/usr/bin/ovs-cfg-mod', '-vANY:console:emer', '-F', '/etc/ovs-vswitchd.conf'] + commands + ['-c']) run_command(['/sbin/service', 'vswitch', 'reload']) @@ -1131,9 +1123,9 @@ def action_up(pif): # /etc/xensource/scripts/vif needs to know where to add VIFs. if vlan_slave: - if not os.path.exists(vswitch_config_dir): - os.mkdir(vswitch_config_dir) - br = ConfigurationFile("br-%s" % bridge, vswitch_config_dir) + if not os.path.exists(vswitch_state_dir): + os.mkdir(vswitch_state_dir) + br = ConfigurationFile("br-%s" % bridge, vswitch_state_dir) br.write("VLAN_SLAVE=%s\n" % datapath) br.write("VLAN_VID=%s\n" % pifrec['VLAN']) br.close() @@ -1198,7 +1190,7 @@ def action_up(pif): # - The networks corresponding to any VLANs attached to the # datapath's PIF. network_uuids = [] - for nwpif in db.get_pifs_by_device({'device': pifrec['device']}): + for nwpif in db.get_pifs_by_device(pifrec['device']): net = db.get_pif_record(nwpif)['network'] network_uuids += [db.get_network_record(net)['uuid']] @@ -1233,7 +1225,7 @@ def action_up(pif): argv += ['--add=iface.%s.fake-bridge=true' % (ipdev)] else: try: - os.unlink("%s/br-%s" % (vswitch_config_dir, bridge)) + os.unlink("%s/br-%s" % (vswitch_state_dir, bridge)) except OSError: pass argv += ['--del-match=bridge.%s.xs-network-uuids=*' % datapath] @@ -1245,6 +1237,8 @@ def action_up(pif): # Bring up VLAN slave, plus physical devices other than bond # slaves (which we brought up earlier). + # XXX need to bring up bond itself. + # XXX need to set MAC address on fake bridge if vlan_slave: up_netdev(ipdev_name(vlan_slave)) for physdev_pif in set(physdev_pifs) - set(bond_slave_physdev_pifs): @@ -1321,6 +1315,7 @@ def action_down(pif): log("VLAN masters of %s - %s" % (rec['device'], [interface_name(m) for m in vlan_masters])) for m in vlan_masters: if db.get_pif_record(m)['currently_attached']: + # XXX remove IP address log("Leaving %s up due to currently attached VLAN master %s" % (interface, interface_name(m))) return @@ -1376,6 +1371,9 @@ def action_rewrite(pif): # We have no code of our own to run here. pass +def action_force_rewrite(interface, config): + raise Error("Force rewrite is not implemented yet.") + def main(argv=None): global output_directory, management_pif @@ -1398,7 +1396,6 @@ def main(argv=None): "force=", "force-interface=", "management", - "test-mode", "device=", "mode=", "ip=", "netmask=", "gateway=", "help" ] arglist, args = getopt.gnu_getopt(argv[1:], shortops, longops) @@ -1435,6 +1432,10 @@ def main(argv=None): raise Usage("Too many arguments") action = args[0] + + if not action in ["up", "down", "rewrite", "rewrite-configuration"]: + raise Usage("Unknown action \"%s\"" % action) + # backwards compatibility if action == "rewrite-configuration": action = "rewrite" @@ -1446,6 +1447,8 @@ def main(argv=None): raise Usage("--session and --pif must be used together.") if force_interface and ( session or pif or pif_uuid ): raise Usage("--force is mutually exclusive with --session, --pif and --pif-uuid") + if force_interface == "all" and action != "down": + raise Usage("\"--force all\" only valid for down action") if len(force_rewrite_config) and not (force_interface and action == "rewrite"): raise Usage("\"--force rewrite\" needed for --device, --mode, --ip, --netmask, and --gateway") @@ -1455,7 +1458,10 @@ def main(argv=None): if action == "rewrite": action_force_rewrite(force_interface, force_rewrite_config) - else: + elif action in ["up", "down"]: + if action == "down" and force_interface == "all": + raise Error("Force all interfaces down not implemented yet") + db = DatabaseCache(cache_file=dbcache_file) pif = db.get_pif_by_bridge(force_interface) management_pif = db.get_management_pif() @@ -1464,42 +1470,44 @@ def main(argv=None): action_up(pif) elif action == "down": action_down(pif) - else: - raise Usage("Unknown action %s" % action) + else: + raise Error("Unknown action %s" % action) else: db = DatabaseCache(session_ref=session) if pif_uuid: pif = db.get_pif_by_uuid(pif_uuid) - - if not pif: - raise Usage("No PIF given") - if force_management: - # pif is going to be the management pif - management_pif = pif + if action == "rewrite" and not pif: + pass else: - # pif is not going to be the management pif. - # Search DB cache for pif on same host with management=true - pifrec = db.get_pif_record(pif) - management_pif = db.get_management_pif() + if not pif: + raise Usage("No PIF given") - log_pif_action(action, pif) + if force_management: + # pif is going to be the management pif + management_pif = pif + else: + # pif is not going to be the management pif. + # Search DB cache for pif on same host with management=true + pifrec = db.get_pif_record(pif) + management_pif = db.get_management_pif() - if not check_allowed(pif): - return 0 + log_pif_action(action, pif) - if action == "up": - action_up(pif) - elif action == "down": - action_down(pif) - elif action == "rewrite": - action_rewrite(pif) - else: - raise Usage("Unknown action %s" % action) + if not check_allowed(pif): + return 0 + + if action == "up": + action_up(pif) + elif action == "down": + action_down(pif) + elif action == "rewrite": + action_rewrite(pif) + else: + raise Error("Unknown action %s" % action) # Save cache. - pifrec = db.get_pif_record(pif) db.save(dbcache_file) except Usage, err: