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()
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:
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:
# 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:
# 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:
if gw:
cmd = 'route -p add default %s' % gw
if record:
- print cmd
+ output += "\n" + cmd
else:
(out, err) = runcmd(cmd)
if err:
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: