Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
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
b31f9b65
authored
Nov 20, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add Node.update_vm_states()
parent
8f4f5a93
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
circle/vm/models.py
+36
-0
circle/vm/tasks/vm_tasks.py
+5
-0
No files found.
circle/vm/models.py
View file @
b31f9b65
...
...
@@ -75,6 +75,7 @@ class Trait(Model):
class
VirtualMachineDescModel
(
BaseResourceConfigModel
):
"""Abstract base for virtual machine describing models.
"""
access_method
=
CharField
(
max_length
=
10
,
choices
=
ACCESS_METHODS
,
...
...
@@ -157,6 +158,36 @@ class Node(TimeStampedModel):
else
:
return
default
def
update_vm_states
(
self
):
domains
=
{}
for
i
in
self
.
remote_query
(
vm_tasks
.
list_domains_info
,
timeout
=
5
):
# [{'name': 'cloud-1234', 'state': 'RUNNING', ...}, ...]
try
:
id
=
int
(
i
[
'name'
]
.
split
(
'-'
)[
1
])
except
:
pass
# name format doesn't match
else
:
domains
[
id
]
=
i
[
'state'
]
instances
=
self
.
instance_set
.
order_by
(
'id'
)
.
values
(
'id'
,
'state'
)
for
i
in
instances
:
try
:
d
=
domains
[
i
[
'id'
]]
except
KeyError
:
logger
.
info
(
'Node
%
s update: instance
%
s missing from '
'libvirt'
,
self
,
i
[
'id'
])
else
:
if
d
!=
i
[
'state'
]:
logger
.
info
(
'Node
%
s update: instance
%
s state changed '
'(libvirt:
%
s, db:
%
s)'
,
self
,
i
[
'id'
],
d
,
i
[
'state'
])
Instance
.
objects
.
get
(
id
=
i
[
'id'
])
.
state_changed
(
d
)
del
domains
[
i
[
'id'
]]
for
i
in
domains
.
keys
():
logger
.
info
(
'Node
%
s update: domain
%
s in libvirt but not in db.'
,
self
,
i
)
def
__unicode__
(
self
):
return
self
.
name
...
...
@@ -808,6 +839,11 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
return
tmpl
def
state_changed
(
self
,
new_state
):
logger
.
debug
(
'Instance
%
s state changed '
'(db:
%
s, new:
%
s)'
,
self
,
self
.
state
,
new_state
)
class
InstanceActivity
(
ActivityModel
):
instance
=
ForeignKey
(
Instance
,
related_name
=
'activity_log'
,
...
...
circle/vm/tasks/vm_tasks.py
View file @
b31f9b65
...
...
@@ -61,6 +61,11 @@ def list_domains(params):
pass
@celery.task
(
name
=
'vmdriver.list_domains_info'
)
def
list_domains_info
(
params
):
pass
@celery.task
(
name
=
'vmdriver.ping'
)
def
ping
(
params
):
pass
...
...
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