Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_instance_ip():
- try:
- p1 = subprocess.Popen(["ip", "addr"], stdout=subprocess.PIPE)
- p2 = subprocess.Popen(["grep", "state UP", "-A2"], stdin=p1.stdout, stdout=subprocess.PIPE)
- p3 = subprocess.Popen(["tail", "-n1"], stdin=p2.stdout, stdout=subprocess.PIPE)
- p4 = subprocess.Popen(["awk", "{print $2}"], stdin=p3.stdout, stdout=subprocess.PIPE)
- p5 = subprocess.Popen(["cut", "-f1", "-d/"], stdin=p4.stdout, stdout=subprocess.PIPE)
- p1.stdout.close()
- p2.stdout.close()
- p3.stdout.close()
- p4.stdout.close()
- return str(p5.communicate()[0][:-1])
- except Exception as e:
- logger.warning("Couldn't determine ip, using localhost")
- return "localhost"
Add Comment
Please, Sign In to add comment