Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f70812a3
authored
Feb 28, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: extract generic functionality
vm: refactor find_unused_port function
parent
fb783308
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
5 deletions
+19
-5
circle/vm/models/instance.py
+19
-5
No files found.
circle/vm/models/instance.py
View file @
f70812a3
...
...
@@ -40,12 +40,26 @@ ACCESS_METHODS = [(key, name) for key, (name, port, transport)
VNC_PORT_RANGE
=
(
2000
,
65536
)
# inclusive start, exclusive end
def
find_unused_port
(
port_range
,
used_ports
=
[]):
"""Find an unused port in the specified range.
The list of used ports can be specified optionally.
:param port_range: a tuple representing a port range (w/ exclusive end)
e.g. (6000, 7000) represents ports 6000 through 6999
"""
ports
=
xrange
(
*
port_range
)
used
=
set
(
used_ports
)
unused
=
(
port
for
port
in
ports
if
port
not
in
used
)
return
next
(
unused
,
None
)
# first or None
def
find_unused_vnc_port
():
used
=
set
(
Instance
.
objects
.
values_list
(
'vnc_port'
,
flat
=
True
))
for
p
in
xrange
(
*
VNC_PORT_RANGE
):
if
p
not
in
used
:
return
p
els
e
:
port
=
find_unused_port
(
port_range
=
VNC_PORT_RANGE
,
used_ports
=
Instance
.
objects
.
values_list
(
'vnc_port'
,
flat
=
True
))
if
port
is
Non
e
:
raise
Exception
(
"No unused port could be found for VNC."
)
...
...
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