21 |
21 |
|
22 |
22 |
from pyeole.i18n import i18n
|
23 |
23 |
|
|
24 |
|
24 |
25 |
_ = i18n('eole-purge-interfaces')
|
25 |
26 |
|
26 |
27 |
ENCODING = sys.stdout.encoding
|
27 |
28 |
if ENCODING is None:
|
28 |
29 |
ENCODING = 'UTF-8'
|
29 |
30 |
|
|
31 |
EOLE_RELEASE_FILE="/etc/eole/release"
|
30 |
32 |
|
31 |
33 |
def _exec(cmd):
|
32 |
34 |
"""Execute a command and return the retcode, stdout and stderr
|
... | ... | |
77 |
79 |
virtual_devices.sort()
|
78 |
80 |
return virtual_devices
|
79 |
81 |
|
|
82 |
def get_ignore_list():
|
|
83 |
"""Return the list of interfaces to ignore
|
|
84 |
We have to ignore OpenNebula managed interafaces
|
|
85 |
"""
|
|
86 |
module = "eolebase"
|
|
87 |
if os.path.isfile(EOLE_RELEASE_FILE):
|
|
88 |
for line in open(EOLE_RELEASE_FILE).readlines():
|
|
89 |
if line.startswith("EOLE_MODULE"):
|
|
90 |
module=line.strip().split('=')[1]
|
|
91 |
|
|
92 |
devs = set()
|
|
93 |
if module == "hapy":
|
|
94 |
hapy_br_file = "/etc/eole/hapy-br.csv"
|
|
95 |
# It's Hâpy, it have OpenVswitch installed, do not touch ovs-system device
|
|
96 |
devs.add("ovs-system")
|
|
97 |
|
|
98 |
if os.path.isfile(hapy_br_file):
|
|
99 |
f = open(hapy_br_file,'r')
|
|
100 |
for line in f.readlines():
|
|
101 |
if line.startswith('BRIDGE'):
|
|
102 |
continue
|
|
103 |
devs.add(line.strip())
|
|
104 |
|
|
105 |
print(devs)
|
|
106 |
return list(devs)
|
|
107 |
|
|
108 |
|
80 |
109 |
def down_interface(interface):
|
81 |
110 |
"""Disable the interface `interface`
|
82 |
111 |
|
... | ... | |
131 |
160 |
return False
|
132 |
161 |
|
133 |
162 |
|
|
163 |
|
134 |
164 |
def main():
|
135 |
165 |
"""Flush the IP addresses and delete virtual interfaces
|
136 |
166 |
|
... | ... | |
138 |
168 |
print(_("Purge all interfaces... "))
|
139 |
169 |
ip_interfaces = get_ip_interfaces()
|
140 |
170 |
virtual_interfaces = get_virtual_devices()
|
|
171 |
ignore_interfaces = get_ignore_list()
|
|
172 |
|
141 |
173 |
for interface in ip_interfaces:
|
|
174 |
if interface in ignore_interfaces:
|
|
175 |
continue
|
142 |
176 |
down_interface(interface)
|
143 |
177 |
flush_interface(interface)
|
144 |
178 |
|
145 |
179 |
for interface in virtual_interfaces:
|
|
180 |
if interface in ignore_interfaces:
|
|
181 |
continue
|
|
182 |
if interface.startswith('one-'):
|
|
183 |
continue
|
|
184 |
|
146 |
185 |
delete_interface(interface)
|
147 |
186 |
|
148 |
187 |
if __name__ == '__main__':
|
149 |
|
-
|