]> git.proxmox.com Git - mirror_ifupdown2.git/blobdiff - sbin/ifupdown
execute 'up' on upper devices if ifup is called with --with-depends
[mirror_ifupdown2.git] / sbin / ifupdown
index d12e6d2e09c5f50cdc33dec5cc193c3b2da500c2..8e1b21c5b6c34c4b406f83e774628378ae1eee48 100755 (executable)
@@ -1,7 +1,9 @@
 #!/usr/bin/python
+# PYTHON_ARGCOMPLETE_OK
 
 import sys
 import os
+import argcomplete
 import argparse
 from ifupdown.ifupdownmain import *
 
@@ -26,9 +28,16 @@ def run_up(args):
                                        perfmode=args.perfmode,
                                        njobs=args.jobs,
                                        dryrun=args.noact,
-                                       cache=cachearg)
+                                       cache=cachearg,
+                                       addons_enable=not args.noaddons,
+                                       statemanager_enable=not args.noaddons)
 
-        ifupdown_handle.up(['pre-up', 'up', 'post-up'],
+        if args.noaddons:
+            ifupdown_handle.up(['up'], args.all, args.CLASS, iflist,
+                               excludepats=args.excludepats,
+                               printdependency=args.printdependency)
+        else:
+            ifupdown_handle.up(['pre-up', 'up', 'post-up'],
                                args.all, args.CLASS, iflist,
                                excludepats=args.excludepats,
                                printdependency=args.printdependency)
@@ -49,12 +58,15 @@ def run_down(args):
                                        perfmode=args.perfmode,
                                        njobs=args.jobs,
                                        dryrun=args.noact,
-                                       cache=cachearg)
+                                       cache=cachearg,
+                                       addons_enable=not args.noaddons,
+                                       statemanager_enable=not args.noaddons)
 
         ifupdown_handle.down(['pre-down', 'down', 'post-down'],
                              args.all, args.CLASS, iflist,
                              excludepats=args.excludepats,
-                             printdependency=args.printdependency)
+                             printdependency=args.printdependency,
+                             usecurrentconfig=args.usecurrentconfig)
     except:
         raise
 
@@ -66,9 +78,6 @@ def run_query(args):
         if args.checkcurr:
             qop='query-checkcurr'
         elif args.running:
-            if not iflist:
-                iflist = [i for i in os.listdir('/sys/class/net/')
-                                    if os.path.isdir('/sys/class/net/%s' %i)]
             qop='query-running'
         elif args.raw:
             qop='query-raw'
@@ -76,13 +85,17 @@ def run_query(args):
             qop = 'query-syntax'
         elif args.printdependency:
             qop = 'query-dependency'
+        elif args.printsavedstate:
+            qop = 'query-savedstate'
         else:
             qop='query'
-
         cachearg=(False if (iflist or args.nocache or
                             args.perfmode or args.syntaxhelp or
                             (qop != 'query-checkcurr' and
                             qop != 'query-running')) else True)
+        if not iflist and qop == 'query-running':
+            iflist = [i for i in os.listdir('/sys/class/net/')
+                        if os.path.isdir('/sys/class/net/%s' %i)]
         logger.debug('creating ifupdown object ..')
         ifupdown_handle = ifupdownMain(withdepends=args.withdepends,
                                        perfmode=args.perfmode,
@@ -96,7 +109,6 @@ def run_query(args):
     except:
         raise
 
-
 def run_reload(args):
     logger.debug('args = %s' %str(args))
 
@@ -108,7 +120,9 @@ def run_reload(args):
                                             perfmode=args.perfmode,
                                             njobs=args.jobs,
                                             cache=cachearg)
-        ifupdown_handle.reload(args.all, None, None,
+        ifupdown_handle.reload(['pre-up', 'up', 'post-up'],
+                               ['pre-down', 'down', 'post-down'],
+                               args.all, None, None,
                                excludepats=args.excludepats,
                                downchangediface=args.downchangediface)
     except:
@@ -172,18 +186,31 @@ def update_ifupdown_argparser(argparser):
     argparser.add_argument('-f', '--force', dest='force',
                 action='store_true',
                 help='force run all operations')
-    argparser.add_argument('-n', '--no-act', dest='noact',
+    group = argparser.add_mutually_exclusive_group(required=False)
+    group.add_argument('-n', '--no-act', dest='noact',
                 action='store_true', help='print out what would happen,' +
                 'but don\'t do it')
-    argparser.add_argument('--print-dependency',
+    group.add_argument('--print-dependency',
                 dest='printdependency', choices=['list', 'dot'],
                 help='print iface dependency')
+    group.add_argument('--no-scripts', '--no-addons',
+                dest='noaddons',  action='store_true',
+                help='dont run any addon modules or scripts. Runs only link ' +
+                     'up/down')
 
 def update_ifup_argparser(argparser):
     update_ifupdown_argparser(argparser)
 
 def update_ifdown_argparser(argparser):
     update_ifupdown_argparser(argparser)
+    argparser.add_argument('--use-current-config',
+                dest='usecurrentconfig',  action='store_true',
+                help=argparse.SUPPRESS)
+                #help='By default ifdown looks at the saved state for ' +
+                #'interfaces to bring down. This option allows ifdown to ' +
+                #'look at the current interfaces file. Useful when your ' +
+                #'state file is corrupted or you want down to use the latest '
+                #'from the interfaces file')
 
 def update_ifquery_argparser(argparser):
     """ arg parser for ifquery options """
@@ -201,6 +228,9 @@ def update_ifquery_argparser(argparser):
                        'running state of an interface')
     group.add_argument('--raw', action='store_true', dest='raw',
                        help='print raw config file entries')
+    group.add_argument('--print-savedstate', action='store_true',
+                       dest='printsavedstate',
+                       help=argparse.SUPPRESS)
     argparser.add_argument('--format', dest='format', default='native',
                        choices=['native', 'json'], help=argparse.SUPPRESS)
     argparser.add_argument('--print-dependency',
@@ -257,6 +287,9 @@ def parse_args(argsv, op):
             update_ifquery_argparser(argparser)
         elif op == 'reload':
             update_ifreload_argparser(argparser)
+
+    argcomplete.autocomplete(argparser)
+
     return argparser.parse_args(argsv)
 
 handlers = {'up' : run_up,