Reputation: 461
I'm trying to call a function get_ethname
into another function get_ethSpeed
, but i'm unable to understand how to get it called.
Many thanks for your inputs in advanced.
The output of the first function returns the name of the NIC interface on the system as below..
[root@tss/]# cat intDetail1.py
#!/usr/bin/python
import ethtool
def get_ethname():
inames = ethtool.get_devices()
inameCurr = inames[1]
print inameCurr
return inameCurr
def main():
get_ethname()
main()
[root@tss /]# ./intDetail1.py
eth0
Below is the main code where i'm trying to call it.
#!/usr/bin/python
import ethtool
import subprocess
def get_ethname():
inames = ethtool.get_devices()
inameCurr = inames[1]
print inameCurr
return inameCurr
def get_ethSpeed():
spd = subprocess.popen("['ethtool', 'get_ethname']", stdout=subprocess.PIPE).communicate()[0]
print spd
return spd
def main():
get_ethname()
get_ethSpeed()
main()
When i run the above code it gives the below error .
File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
My aim is get to main running interface name on the systems and and then get the speed determine of the NIC by using linux system utility ethtool
which tells the speed of the Interface:
[root@tss /]# /sbin/ethtool eth0| grep Speed
Speed: 1000Mb/s
Output look of
ethtool eth0
is Below:
[root@tss /]# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: g
Wake-on: g
Link detected: yes
Upvotes: 0
Views: 253
Reputation: 191874
No such device Settings for get_ethname(): No data available
This is still the same problem with the original question. You're passing a literal string and expecting the shell to invoke the Python function?
There's no quotes here except around the actual shell command
spd = subprocess.Popen(['/sbin/ethtool', get_ethname()], stdout=subprocess.PIPE).communicate()[0]
Or, make another variable
iface = get_ethname()
# Or
iface = ethtool.get_devices()[1]
spd = subprocess.Popen(['/sbin/ethtool', iface], stdout=subprocess.PIPE).communicate()
return spd[0]
Note that you'll still need to grep (or scan the output with python) for "Speed"
Upvotes: 1