mininet / mininet / moduledeps.py @ 824afb84
History | View | Annotate | Download (2.39 KB)
1 | b055728f | Brandon Heller | "Module dependency utility functions for Mininet."
|
---|---|---|---|
2 | |||
3 | from mininet.util import quietRun |
||
4 | from mininet.log import info, error, debug |
||
5 | b47cdfea | Bob Lantz | from os import environ |
6 | b055728f | Brandon Heller | |
7 | def lsmod(): |
||
8 | "Return output of lsmod."
|
||
9 | return quietRun( 'lsmod' ) |
||
10 | |||
11 | def rmmod( mod ): |
||
12 | """Return output of lsmod.
|
||
13 | mod: module string"""
|
||
14 | return quietRun( [ 'rmmod', mod ] ) |
||
15 | |||
16 | def modprobe( mod ): |
||
17 | """Return output of modprobe
|
||
18 | mod: module string"""
|
||
19 | return quietRun( [ 'modprobe', mod ] ) |
||
20 | |||
21 | OF_KMOD = 'ofdatapath'
|
||
22 | 28c2cdc2 | Bob Lantz | OVS_KMOD = 'openvswitch_mod' # Renamed 'openvswitch' in OVS 1.7+/Linux 3.5+ |
23 | b055728f | Brandon Heller | TUN = 'tun'
|
24 | |||
25 | 8abc3472 | Bob Lantz | def moduleDeps( subtract=None, add=None ): |
26 | b055728f | Brandon Heller | """Handle module dependencies.
|
27 | subtract: string or list of module names to remove, if already loaded
|
||
28 | add: string or list of module names to add, if not already loaded"""
|
||
29 | 8abc3472 | Bob Lantz | subtract = subtract if subtract is not None else [] |
30 | add = add if add is not None else [] |
||
31 | b055728f | Brandon Heller | if type( subtract ) is str: |
32 | subtract = [ subtract ] |
||
33 | if type( add ) is str: |
||
34 | add = [ add ] |
||
35 | for mod in subtract: |
||
36 | if mod in lsmod(): |
||
37 | info( '*** Removing ' + mod + '\n' ) |
||
38 | rmmodOutput = rmmod( mod ) |
||
39 | if rmmodOutput:
|
||
40 | 4c85d6d3 | Bob Lantz | error( 'Error removing ' + mod + ': "%s">\n' % rmmodOutput ) |
41 | b055728f | Brandon Heller | exit( 1 ) |
42 | if mod in lsmod(): |
||
43 | error( 'Failed to remove ' + mod + '; still there!\n' ) |
||
44 | exit( 1 ) |
||
45 | for mod in add: |
||
46 | if mod not in lsmod(): |
||
47 | info( '*** Loading ' + mod + '\n' ) |
||
48 | modprobeOutput = modprobe( mod ) |
||
49 | if modprobeOutput:
|
||
50 | 55ca2d0c | Bob Lantz | error( 'Error inserting ' + mod +
|
51 | edf60032 | Brandon Heller | ' - is it installed and available via modprobe?\n' +
|
52 | 'Error was: "%s"\n' % modprobeOutput )
|
||
53 | b055728f | Brandon Heller | if mod not in lsmod(): |
54 | f9654e56 | Bob Lantz | error( 'Failed to insert ' + mod + ' - quitting.\n' ) |
55 | b055728f | Brandon Heller | exit( 1 ) |
56 | else:
|
||
57 | 8abc3472 | Bob Lantz | debug( '*** ' + mod + ' already loaded\n' ) |
58 | b47cdfea | Bob Lantz | |
59 | 4876b43f | Bob Lantz | |
60 | f9654e56 | Bob Lantz | def pathCheck( *args, **kwargs ): |
61 | b47cdfea | Bob Lantz | "Make sure each program in *args can be found in $PATH."
|
62 | f9654e56 | Bob Lantz | moduleName = kwargs.get( 'moduleName', 'it' ) |
63 | b47cdfea | Bob Lantz | for arg in args: |
64 | if not quietRun( 'which ' + arg ): |
||
65 | f9654e56 | Bob Lantz | error( 'Cannot find required executable %s.\n' % arg +
|
66 | edf60032 | Brandon Heller | 'Please make sure that %s is installed ' % moduleName +
|
67 | 'and available in your $PATH:\n(%s)\n' % environ[ 'PATH' ] ) |
||
68 | b47cdfea | Bob Lantz | exit( 1 ) |