]> git.datanom.net - netconf.git/commitdiff
fix test for record. Better output for record
authorMichael Rasmussen <mir@datanom.net>
Wed, 5 Apr 2017 21:11:12 +0000 (21:11 +0000)
committerMichael Rasmussen <mir@datanom.net>
Wed, 5 Apr 2017 21:11:12 +0000 (21:11 +0000)
netconf

diff --git a/netconf b/netconf
index 25d3bff8f2f62af7886f4def1bd701d5b4c960a9..3dd1d377490630a19ec45e613eb75cf2803a4a0d 100644 (file)
--- a/netconf
+++ b/netconf
@@ -185,11 +185,11 @@ def parse_input():
                assert False, 'Unhandled option'
 
        if (record):
-           if not (bool(address) ^ bool(interface)):
-               print 'Error: missing options'
+           if (bool(address) ^ bool(interface)):
+                print 'Error: missing options'
                usage()
                sys.exit(2)
-       else:
+        else:
            if not address or not interface or error:
                print 'Error: missing options'
                usage()
@@ -200,16 +200,20 @@ def parse_input():
        if not netmask:
            netmask = '24'
     
-       options = (interface, address, netmask, gateway, nameserver)
+       options = (interface, address, netmask, gateway, nameserver, record)
     
     return options
 
 def main():
     interactive = True
+    record = False
+    output = ''
 
     options = parse_input()
     if options:
-       interactive = False
+        record = options[5]
+        if (options[0]):
+           interactive = False
 
     p = Parser()
     try:
@@ -236,12 +240,12 @@ def main():
                    gw = options[3]
                 cmd = 'ipadm delete-if %s' % nic[0]
                if record:
-                   print cmd
+                   output += cmd
                else:
                    runcmd(cmd)
                 cmd = 'ipadm create-if %s' % nic[0]
                if record:
-                   print cmd
+                   output += "\n" + cmd
                else:
                    (out, err) = runcmd(cmd)
                    if err:
@@ -250,7 +254,7 @@ def main():
                     # use DHCP
                     cmd = 'ipadm create-addr -T dhcp %s/v4' % nic[0]
                    if record:
-                       print cmd
+                       output += "\n" + cmd
                    else:
                        (out, err) = runcmd(cmd)
                        if err:
@@ -259,7 +263,7 @@ def main():
                     # use STATIC
                     cmd = 'ipadm create-addr -T static -a %s/%s %s/v4' % (ip, mask, nic[0])
                    if record:
-                       print cmd
+                       output += "\n" + cmd
                    else:
                        (out, err) = runcmd(cmd)
                        if err:
@@ -267,7 +271,7 @@ def main():
                     if gw:
                         cmd = 'route -p add default %s' % gw
                        if record:
-                           print cmd
+                           output += "\n" + cmd
                        else:
                            (out, err) = runcmd(cmd)
                            if err:
@@ -296,11 +300,13 @@ def main():
                     cmd += '&& cp /etc/nsswitch.conf{,.bak} '
                     cmd += '&& cp /etc/nsswitch.{dns,conf}'
                    if record:
-                       print cmd
+                       output += "\n" + cmd
                    else:
                        (out, err) = runcmd(cmd)
                        if err:
                            raise RuntimeError(err)
+                if record:
+                    print output
         else:
             print "Found no unassigned interfaces"
     except ParserError as e:
This page took 0.038282 seconds and 5 git commands to generate.