Skip to content

Commit

Permalink
Merge pull request #1405 from crate/m/grrrrrrraceful
Browse files Browse the repository at this point in the history
M/grrrrrrraceful
  • Loading branch information
mfelsche committed Nov 27, 2014
2 parents 6df932d + 5878a84 commit 3adbad4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
11 changes: 11 additions & 0 deletions docs/src/crate/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

import socket

def public_ip():
"""
take first public interface
sorted by getaddrinfo - see RFC 3484
should have the real public ip as first
"""
for addrinfo in socket.getaddrinfo(socket.gethostname(), None):
if addrinfo[1] in (socket.SOCK_STREAM, socket.SOCK_DGRAM):
return addrinfo[4][0]


def random_available_port():
"""return some available port reported by the kernel"""
sock = socket.socket()
Expand Down
5 changes: 1 addition & 4 deletions docs/src/crate/process_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
from crate.testing.layer import CrateLayer
from crate.client.http import Client
from .paths import crate_path
from .ports import random_available_port
from .ports import public_ip, random_available_port
from lovely.testlayers.layer import CascadedLayer

def public_ip():
return socket.gethostbyname(socket.gethostname())


class GracefulStopCrateLayer(CrateLayer):

Expand Down

0 comments on commit 3adbad4

Please sign in to comment.