Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
slapos
Commits
d5e12001
Commit
d5e12001
authored
Oct 24, 2016
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
free_port: now inherits from GenericBaseRecipe
parent
ce3db678
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
8 deletions
+6
-8
slapos/recipe/free_port.py
slapos/recipe/free_port.py
+6
-8
No files found.
slapos/recipe/free_port.py
View file @
d5e12001
...
@@ -41,20 +41,18 @@ class Recipe(GenericBaseRecipe):
...
@@ -41,20 +41,18 @@ class Recipe(GenericBaseRecipe):
would be the same giving an already-in-use port to the service.
would be the same giving an already-in-use port to the service.
"""
"""
def
__init__
(
self
,
buildout
,
name
,
options
):
def
_options
(
self
,
options
):
super
(
Recipe
,
self
).
__init__
(
buildout
,
name
,
options
)
# If section has already been installed, port is already taken by the
# If section has already been installed, port is already taken by the
# requested service itself.
# requested service itself.
# If this check isn't done, a new port would be picked for every upgrade
# If this check isn't done, a new port would be picked for every upgrade
# of the software release
# 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,
# 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
# so 0 is returned by default. Then, on next run, this recipe is processed
# again until a correct value is returned
# again until a correct value is returned
if
port
!=
'0'
:
if
port
!=
'0'
:
self
.
options
[
'port'
]
=
port
options
[
'port'
]
=
port
return
return
# Otherwise, let's find one
# Otherwise, let's find one
...
@@ -63,7 +61,7 @@ class Recipe(GenericBaseRecipe):
...
@@ -63,7 +61,7 @@ class Recipe(GenericBaseRecipe):
self
.
ip
=
options
.
get
(
'ip'
)
self
.
ip
=
options
.
get
(
'ip'
)
if
self
.
minimum
==
self
.
maximum
:
if
self
.
minimum
==
self
.
maximum
:
self
.
options
[
'port'
]
=
str
(
self
.
minimum
)
options
[
'port'
]
=
str
(
self
.
minimum
)
return
return
if
netaddr
.
valid_ipv4
(
self
.
ip
):
if
netaddr
.
valid_ipv4
(
self
.
ip
):
...
@@ -72,10 +70,10 @@ class Recipe(GenericBaseRecipe):
...
@@ -72,10 +70,10 @@ class Recipe(GenericBaseRecipe):
self
.
inet_family
=
socket
.
AF_INET6
self
.
inet_family
=
socket
.
AF_INET6
else
:
else
:
# address family is unknown, so let's return a general purpose port
# address family is unknown, so let's return a general purpose port
self
.
options
[
'port'
]
=
str
(
0
)
options
[
'port'
]
=
str
(
0
)
return
return
self
.
options
[
'port'
]
=
str
(
self
.
_getFreePort
())
options
[
'port'
]
=
str
(
self
.
_getFreePort
())
def
_getFreePort
(
self
):
def
_getFreePort
(
self
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment