]>
Commit | Line | Data |
---|---|---|
d486dd0d JF |
1 | #!/usr/bin/python |
2 | # | |
3 | # Copyright 2017 Cumulus Networks, Inc. All rights reserved. | |
4 | # Authors: | |
5 | # Julien Fortin, julien@cumulusnetworks.com | |
6 | # | |
7 | # ifupdown2 -- | |
8 | # tool to configure network interfaces | |
9 | # | |
10 | ||
11 | import os | |
12 | import resource | |
13 | ||
14 | IFUPDOWN2_ADDON_DROPIN_FOLDER = '/usr/share/ifupdown2/addons' | |
15 | ||
16 | # ifupdown2/core/config.py -> we need to use dirname twice. | |
17 | _ = { | |
18 | IFUPDOWN2_ADDON_DROPIN_FOLDER, | |
19 | '%s/addons' % (os.path.dirname(os.path.dirname(os.path.realpath(__file__)))) | |
20 | } | |
21 | ||
22 | try: | |
23 | addon_module_dir_list = list(_) | |
24 | if addon_module_dir_list[0] is not IFUPDOWN2_ADDON_DROPIN_FOLDER: | |
25 | addon_module_dir_list.remove(IFUPDOWN2_ADDON_DROPIN_FOLDER) | |
26 | ADDON_MODULES_DIR = [IFUPDOWN2_ADDON_DROPIN_FOLDER] + addon_module_dir_list | |
27 | else: | |
28 | ADDON_MODULES_DIR = addon_module_dir_list | |
29 | except: | |
30 | ADDON_MODULES_DIR = [IFUPDOWN2_ADDON_DROPIN_FOLDER] | |
31 | ||
32 | __version__ = '' | |
33 | ||
34 | ||
35 | def get_configuration_file_real_path(path_to_file): | |
36 | """ | |
37 | When install via pypi or `pip install .` ifupdown2 is install in a virtualenv | |
38 | config file that should be installed in /etc/network/ifupdown2 end-up being | |
39 | installed in /usr/local/lib/python2.7/dist-packages/etc/network/ifupdown2/ | |
40 | """ | |
41 | if not os.path.exists(path_to_file): | |
42 | # we will try to resolve the location of our conf file | |
43 | # otherwise default to the input argument | |
44 | package_dir = os.path.dirname(os.path.realpath(__file__)) | |
45 | parent_dir = os.path.dirname(package_dir) | |
46 | resolved_path = '%s%s' % (parent_dir, path_to_file) | |
47 | ||
48 | if os.path.exists(resolved_path): | |
49 | return resolved_path | |
50 | ||
51 | return path_to_file | |
52 | ||
53 | ||
54 | IFUPDOWN2_CONF_PATH = get_configuration_file_real_path('/etc/network/ifupdown2/ifupdown2.conf') | |
55 | ADDONS_CONF_PATH = get_configuration_file_real_path('/etc/network/ifupdown2/addons.conf') | |
56 | ||
57 | resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) |