From: rohitagarwalla roagarwa@cisco.com <> Date: Wed, 13 Jul 2011 19:39:09 +0000 (-0700) Subject: Porting shell script get-vif.sh to python module get-vif.py for cisco ucsm module X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7fb19f22ce31c1023568cdd6ba9e5b35b15f5cf9;p=openstack-build%2Fneutron-build.git Porting shell script get-vif.sh to python module get-vif.py for cisco ucsm module --- diff --git a/quantum/plugins/cisco/get-vif.py b/quantum/plugins/cisco/get-vif.py new file mode 100644 index 000000000..0512ecb0d --- /dev/null +++ b/quantum/plugins/cisco/get-vif.py @@ -0,0 +1,37 @@ +import sys +import subprocess + + +def get_next_dynic(argv=[]): + cmd = ["ifconfig", "-a"] + f_cmd_output = subprocess.Popen(cmd, stdout=subprocess.PIPE).\ + communicate()[0] + eths = [lines.split(' ')[0] for lines in f_cmd_output.splitlines() \ + if "eth" in lines] + #print eths + for eth in eths: + cmd = ["ethtool", "-i", eth] + f_cmd_output = subprocess.Popen(cmd, stdout=subprocess.PIPE).\ + communicate()[0] + bdf = [lines.split(' ')[1] for lines in f_cmd_output.splitlines() \ + if "bus-info" in lines] + #print bdf + cmd = ["lspci", "-n", "-s", bdf[0]] + f_cmd_output = subprocess.Popen(cmd, stdout=subprocess.PIPE).\ + communicate()[0] + deviceid = [(lines.split(':')[3]).split(' ')[0] \ + for lines in f_cmd_output.splitlines()] + #print deviceid + if deviceid[0] == "0044": + cmd = ["/usr/sbin/ip", "link", "show", eth] + f_cmd_output = subprocess.Popen(cmd, stdout=subprocess.PIPE).\ + communicate()[0] + used = [lines for lines in f_cmd_output.splitlines() \ + if "UP" in lines] + if not used: + break + return eth + +if __name__ == '__main__': + nic = get_next_dynic(sys.argv) + print nic