Skip to content

Commit c11c367

Browse files
Merge pull request RackHD#512 from mtannous/enable_lldp
Script to enable interfaces inorder to send/receive LLDP
2 parents 0e0f296 + 3c4f44a commit c11c367

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

data/templates/set_interfaces.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
import time
3+
count = 0
4+
string= ""
5+
interfaces=[]
6+
for dirname, dirnames, filenames in os.walk('/sys/class/net/'):
7+
for subdirname in dirnames:
8+
if subdirname != "lo":
9+
#Here we are assigning an arbitrary IP which could be a different one. This is just to get the interface up
10+
interfaces.append(subdirname)
11+
ip= 100+count
12+
string += "auto " + subdirname
13+
string += "\niface " + subdirname +" inet static"
14+
string += "\naddress 10.0.0." + str(ip)
15+
if count == 0:
16+
string += "\ngateway 10.0.0.1"
17+
string += "\nnetmask 255.255.255.0\n\n"
18+
count=count+1
19+
20+
with open("/etc/network/interfaces", "w") as text_file:
21+
text_file.write(string)
22+
23+
for item in interfaces:
24+
os.system("sudo ifup "+ item)
25+
f= os.popen("sudo ethtool "+ item + " | grep -i \"Link detected\"")
26+
result = f.read()
27+
count = 0
28+
while result.find("yes") == -1:
29+
time.sleep(5)
30+
f= os.popen("sudo ethtool "+ item + " | grep -i \"Link detected\"" )
31+
result = f.read()
32+
count = count + 1
33+
print result
34+
if count > 20:
35+
break

0 commit comments

Comments
 (0)