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
cf09c0eb
Commit
cf09c0eb
authored
Aug 22, 2016
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
free_port: new port shouldn't be returned everytime the instance is processed
parent
d21c3415
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
8 deletions
+24
-8
slapos/recipe/free_port.py
slapos/recipe/free_port.py
+24
-8
No files found.
slapos/recipe/free_port.py
View file @
cf09c0eb
...
...
@@ -25,6 +25,7 @@
#
##############################################################################
import
ConfigParser
import
socket
import
netaddr
...
...
@@ -39,11 +40,30 @@ class Recipe(object):
"""
def
__init__
(
self
,
buildout
,
name
,
options
):
self
.
options
=
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
try
:
parser
=
ConfigParser
.
RawConfigParser
()
with
open
(
buildout
[
'buildout'
][
'installed'
])
as
config_file
:
parser
.
readfp
(
config_file
)
port
=
parser
.
get
(
name
,
'port'
)
self
.
options
[
'port'
]
=
port
return
except
(
IOError
,
ConfigParser
.
NoSectionError
,
ConfigParser
.
NoOptionError
):
pass
# Otherwise, let's find one
self
.
minimum
=
int
(
options
.
get
(
'minimum'
,
1024
))
self
.
maximum
=
int
(
options
.
get
(
'maximum'
,
49151
))
self
.
ip
=
options
.
get
(
'ip'
)
self
.
options
=
options
.
copy
()
if
self
.
minimum
==
self
.
maximum
:
self
.
options
[
'port'
]
=
str
(
self
.
minimum
)
return
if
netaddr
.
valid_ipv4
(
self
.
ip
):
self
.
inet_family
=
socket
.
AF_INET
...
...
@@ -51,10 +71,10 @@ class Recipe(object):
self
.
inet_family
=
socket
.
AF_INET6
else
:
# address family is unknown, so let's return a general purpose port
self
.
options
[
'port'
]
=
0
self
.
options
[
'port'
]
=
str
(
0
)
return
self
.
options
[
'port'
]
=
s
elf
.
_getFreePort
(
)
self
.
options
[
'port'
]
=
s
tr
(
self
.
_getFreePort
()
)
def
_getFreePort
(
self
):
"""
...
...
@@ -77,8 +97,4 @@ class Recipe(object):
return
port
def
install
(
self
):
pass
def
update
(
self
):
pass
install
=
update
=
lambda
self
:
[]
\ No newline at end of file
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