Files
xen/tools/misc/netfix
T
katzj@redhat.com[iap10] c9505fed46 bitkeeper revision 1.1159.258.97 (42603992S3sF-t0yBth7NEBevozVOg)
[PATCH] Make non-native python path handling a
> > Although I don't really agree with the installing of the
> > python bits to the non-native paths, I can see where it's
> > useful as long as the module ABI doesn't change if you're
> > trying to distribute binary tarballs.  But with the current
> > handling it adds module lookup costs for the native path case
> > (which would be the norm) as well as prevents using
> > PYTHONPATH to look to a different location for the modules.
> >
> > The attached patch changes things so that at first, the xen
> > module is attempted to be imported from the stock paths.  If
> > we get an ImportError exception, then it adds /usr/lib/python
> > to the end of the python path and imports again.
>
> Do you prefer this to just unconditionally addding /usr/lib/python to
> the end of the path rather than the front?

Slightly, but just because having /usr/lib/python in my sys.path is
ugly :-)  I can look over it, though... patch doing that attached

Signed-off-by: Jeremy Katz <katzj@redhat.com>

===== tools/misc/netfix 1.13 vs edited =====
2005-04-15 22:00:50 +00:00

69 lines
2.3 KiB
Python

#!/usr/bin/env python
# -*- mode: python; -*-
#============================================================================
# Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
#============================================================================
# Move the IP address from eth0 onto the Xen bridge (xen-br0).
# Only works if the bridge control utils (brctl) have been installed.
#============================================================================
from getopt import getopt
# add fallback path for non-native python path installs if needed
sys.path.append('/usr/lib/python')
from xen.util.Brctl import *
short_options = 'hvqni:b:c'
long_options = ['help', 'verbose', 'quiet',
'interface=', 'bridge=', 'create']
defaults['interface'] = 'eth0'
defaults['bridge'] = 'xen-br0'
def usage():
print """Usage:
%s [options]
Reconfigure routing so that <bridge> has the IP address from
<interface>. This lets IP carry on working when <interface>
is attached to <bridge> for virtual networking.
Uses brctl to add <interface> to <bridge>,
so this can be run before any domains have been created.
""" % sys.argv[0]
print """
-i, --interface <interface> interface, default %(interface)s.
-b, --bridge <bridge> bridge, default %(bridge)s.
-c, --create create the bridge.
-v, --verbose Print commands.
-q, --quiet Don't print commands.
-n, --dry-run Don't execute commands.
-h, --help Print this help.
""" % defaults
sys.exit(1)
def main():
lopts = set_opts(Opts(defaults))
lopts.dryrun = 0
(options, args) = getopt(sys.argv[1:], short_options, long_options)
if args: usage()
for k, v in options:
if k in ['-h', '--help']:
usage()
elif k in ['-c', '--create']:
lopts.create = 1
elif k in ['-i', '--interface']:
lopts.interface = v
elif k in ['-b', '--bridge']:
lopts.bridge = v
elif k in ['-q', '--quiet']:
lopts.verbose = 0
elif k in ['-v', '--verbose']:
lopts.verbose = 1
elif k in ['-n', '--dry-run']:
lopts.dryrun = 1
reconfigure(lopts.interface, lopts.bridge)
if __name__ == '__main__':
main()