diff options
author | 2015-02-05 22:17:42 +0100 | |
---|---|---|
committer | 2015-08-02 18:19:37 +0200 | |
commit | 103b87aa82cfd298b664fe1314e987bd953ec20d (patch) | |
tree | e5691490fff33868291a6e8de946b8b8ac427ffe /os_net_config/cli.py | |
parent | cb578ed9b94ff9a34b41d91ada94e3375436b60c (diff) |
Allow to specify the root directory of the filesystem
Change-Id: Ice1b8d17804cf7a0aafd308945a5e960fe927bbc
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 |