• L
    virsh: add iface-bridge and iface-unbridge commands · 1ae8eed1
    Laine Stump 提交于
    One of the top questions by libvirt users is how to create a host
    bridge device so that guests can be directly on the physical
    network. There are several example documents that explain how to do
    this manually, but following them often results in confusion and
    failure. virt-manager does a good job of creating a bridge based on an
    existing network device, but not everyone wants to use virt-manager.
    
    This patch adds a new command, iface-bridge that makes it just about
    as simple as possible to create a new bridge device based on an
    existing ethernet/vlan/bond device (including associating IP
    configuration with the bridge rather than the now-attached device),
    and start that new bridge up ready for action, eg:
    
        virsh iface-bridge eth0 br0
    
    For symmetry's sake, it also adds a command to remove a device from a
    bridge, restoring the IP config to the now-unattached device:
    
        virsh iface-unbridge br0
    
    (I had a short debate about whether to do "iface-unbridge eth0"
    instead, but that would involve searching through all bridge devices
    for the one that contained eth0, which seems like a bit too much
    trouble).
    
    NOTE: These two commands require that the netcf library be available
    on the host. Hopefully this will provide some extra incentive for
    people using suse, debian, ubuntu, and other similar systems to polish
    up (and push downstream) the ports to those distros recently pushed to
    the upstream netcf repo by Dan Berrange. Anyone interested in helping
    with that effort in any way should join the netcf-devel mailing list
    (subscription info at
    https://fedorahosted.org/mailman/listinfo/netcf-devel)
    
    During creation of the bridge, it's possible to specify whether or not
    the STP protocol should be started up on the bridge and, if so, how
    many seconds the bridge should squelch traffic from newly added
    devices while learning new topology (defaults are stp='on' and
    delay='0', which seems to usually work best for bridges used in the
    context of libvirt guests).
    
    There is also an option to not immediately start the bridge (and a
    similar option to not immediately start the un-attached device after
    destroying the bridge. Default is to start the new device, because in
    the case of iface-unbridge not starting is strongly discouraged as it
    will leave the system with no network connectivity on that interface
    (because it's necessary to destroy/undefine the bridge device before
    the unattached device can be defined), and it seemed better to make
    the option for iface-bridge behave consistently.
    
    NOTE TO THOSE TRYING THESE COMMANDS FOR THE FIRST TIME: to guard
    against any "unexpected" change to configuration, it is advisable to
    issue an "virsh iface-begin" command before starting any interface
    config changes, and "virsh iface-commit" only after you've verified
    that everything is working as you expect. If something goes wrong,
    you can always run "virsh iface-rollback" or reboot the system (which
    should automatically do iface-rollback).
    
    Aside from adding the code for these two functions, and the two
    entries into the command table, the only other change to virsh.c was
    to add the option name to vshCommandOptInterfaceBy(), because the
    iface-unbridge command names its interface option as "bridge".
    
    virsh.pod has also been updated with short descriptions of these two
    new commands.
    1ae8eed1
virsh.pod 86.6 KB