diff options
Diffstat (limited to 'os_net_config/cli.py')
-rw-r--r-- | os_net_config/cli.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/os_net_config/cli.py b/os_net_config/cli.py index aeccb26..c2491a2 100644 --- a/os_net_config/cli.py +++ b/os_net_config/cli.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2014 Red Hat, Inc. +# Copyright 2014-2015 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -45,6 +45,9 @@ def parse_opts(argv): help="""The provider to use.""" """One of: ifcfg, eni, iproute.""", default=None) + parser.add_argument('-r', '--root-dir', metavar='ROOT_DIR', + help="""The root directory of the filesystem.""", + default='') parser.add_argument( '-d', '--debug', dest="debug", @@ -119,19 +122,24 @@ def main(argv=sys.argv): provider = None if opts.provider: if opts.provider == 'ifcfg': - provider = impl_ifcfg.IfcfgNetConfig(noop=opts.noop) + provider = impl_ifcfg.IfcfgNetConfig(noop=opts.noop, + root_dir=opts.root_dir) elif opts.provider == 'eni': - provider = impl_eni.ENINetConfig(noop=opts.noop) + provider = impl_eni.ENINetConfig(noop=opts.noop, + root_dir=opts.root_dir) elif opts.provider == 'iproute': - provider = impl_iproute.IPRouteNetConfig(noop=opts.noop) + provider = impl_iproute.IPRouteNetConfig(noop=opts.noop, + root_dir=opts.root_dir) else: logger.error('Invalid provider specified.') return 1 else: - if os.path.exists('/etc/sysconfig/network-scripts/'): - provider = impl_ifcfg.IfcfgNetConfig(noop=opts.noop) - elif os.path.exists('/etc/network/'): - provider = impl_eni.ENINetConfig(noop=opts.noop) + if os.path.exists('%s/etc/sysconfig/network-scripts/' % opts.root_dir): + provider = impl_ifcfg.IfcfgNetConfig(noop=opts.noop, + root_dir=opts.root_dir) + elif os.path.exists('%s/etc/network/' % opts.root_dir): + provider = impl_eni.ENINetConfig(noop=opts.noop, + root_dir=opts.root_dir) else: logger.error('Unable to set provider for this operating system.') return 1 @@ -172,9 +180,9 @@ def main(argv=sys.argv): activate=not opts.no_activate) if opts.noop: for location, data in files_changed.iteritems(): - print "File: %s\n" % location - print data - print "----" + print("File: %s\n" % location) + print(data) + print("----") return 0 |