Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c18fabea
authored
Oct 17, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: automatically find an unused port for VNC when changing host node of VM
parent
2ada70e6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
3 deletions
+19
-3
circle/vm/migrations/0006_auto__add_unique_instance_node_vnc_port.py
+0
-0
circle/vm/models.py
+19
-3
No files found.
circle/vm/migrations/0006_auto__add_unique_instance_node_vnc_port.py
0 → 100644
View file @
c18fabea
This diff is collapsed.
Click to expand it.
circle/vm/models.py
View file @
c18fabea
...
...
@@ -27,6 +27,7 @@ ACCESS_METHODS = [(key, name) for key, (name, port, transport)
in
ACCESS_PROTOCOLS
.
iteritems
()]
ARCHITECTURES
=
((
'x86_64'
,
'x86-64 (64 bit)'
),
(
'i686'
,
'x86 (32 bit)'
))
VNC_PORT_RANGE
=
(
2000
,
65536
)
# inclusive start, exclusive end
class
BaseResourceConfigModel
(
Model
):
...
...
@@ -316,7 +317,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
access_method
=
CharField
(
max_length
=
10
,
choices
=
ACCESS_METHODS
,
help_text
=
_
(
"Primary remote access method."
),
verbose_name
=
_
(
'access method'
))
vnc_port
=
IntegerField
(
verbose_name
=
_
(
'vnc_port'
),
vnc_port
=
IntegerField
(
default
=
2000
,
verbose_name
=
_
(
'vnc_port'
),
help_text
=
_
(
"TCP port where VNC console listens."
))
owner
=
ForeignKey
(
User
)
destoryed
=
DateTimeField
(
blank
=
True
,
null
=
True
,
...
...
@@ -326,6 +327,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
class
Meta
:
ordering
=
[
'pk'
,
]
permissions
=
()
unique_together
=
(
'node'
,
'vnc_port'
)
verbose_name
=
_
(
'instance'
)
verbose_name_plural
=
_
(
'instances'
)
...
...
@@ -523,6 +525,21 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
self
.
time_of_delete
=
timezone
.
now
()
+
self
.
lease
.
delete_interval
self
.
save
()
def
change_node
(
self
,
new_node
):
if
self
.
node
==
new_node
:
return
self
.
node
=
new_node
if
self
.
node
:
used
=
self
.
node
.
instance_set
.
values_list
(
'vnc_port'
,
flat
=
True
)
for
p
in
xrange
(
*
VNC_PORT_RANGE
):
if
p
not
in
used
:
self
.
vnc_port
=
p
break
else
:
raise
Exception
(
"No unused port could be found for VNC."
)
self
.
save
()
def
deploy
(
self
,
user
=
None
,
task_uuid
=
None
):
"""Deploy new virtual machine with network
...
...
@@ -540,8 +557,7 @@ class Instance(BaseResourceConfigModel, TimeStampedModel):
task_uuid
=
task_uuid
,
user
=
user
)
as
act
:
# Schedule
self
.
node
=
scheduler
.
get_node
(
self
,
Node
.
objects
.
all
())
self
.
save
()
self
.
change_node
(
scheduler
.
get_node
(
self
,
Node
.
objects
.
all
()))
# Deploy virtual images
with
act
.
sub_activity
(
'deploying_disks'
):
...
...
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