Index: juju/lib/port.py |
=== added file 'juju/lib/port.py' |
--- juju/lib/port.py 1970-01-01 00:00:00 +0000 |
+++ juju/lib/port.py 2013-01-31 18:38:30 +0000 |
@@ -0,0 +1,13 @@ |
+import socket |
+ |
+ |
+def get_open_port(host=""): |
+ """Get an open port on the machine. |
+ """ |
+ temp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
+ temp_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
+ temp_sock.bind((host, 0)) |
+ port = temp_sock.getsockname()[1] |
+ temp_sock.close() |
+ del temp_sock |
+ return port |