Commit d5e12001 authored by Nicolas Wavrant's avatar Nicolas Wavrant

free_port: now inherits from GenericBaseRecipe

parent ce3db678
......@@ -41,20 +41,18 @@ class Recipe(GenericBaseRecipe):
would be the same giving an already-in-use port to the service.
"""
def __init__(self, buildout, name, options):
super(Recipe, self).__init__(buildout, name, options)
def _options(self, options):
# If section has already been installed, port is already taken by the
# requested service itself.
# If this check isn't done, a new port would be picked for every upgrade
# of the software release
port = self.getValueFromPreviousRun(name, 'port')
port = self.getValueFromPreviousRun(self.name, 'port')
# Port can be 0 in case of upgrade: some old service still runs on port,
# so 0 is returned by default. Then, on next run, this recipe is processed
# again until a correct value is returned
if port != '0':
self.options['port'] = port
options['port'] = port
return
# Otherwise, let's find one
......@@ -63,7 +61,7 @@ class Recipe(GenericBaseRecipe):
self.ip = options.get('ip')
if self.minimum == self.maximum:
self.options['port'] = str(self.minimum)
options['port'] = str(self.minimum)
return
if netaddr.valid_ipv4(self.ip):
......@@ -72,10 +70,10 @@ class Recipe(GenericBaseRecipe):
self.inet_family = socket.AF_INET6
else:
# address family is unknown, so let's return a general purpose port
self.options['port'] = str(0)
options['port'] = str(0)
return
self.options['port'] = str(self._getFreePort())
options['port'] = str(self._getFreePort())
def _getFreePort(self):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment