Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cc-node
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
cc-node
Commits
68be0af6
Commit
68be0af6
authored
12 years ago
by
Anael Beutot
Browse files
Options
Downloads
Patches
Plain Diff
Finished libvirt events handling for vm lifecycle.
parent
5a78eded
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ccnode/hypervisor/__init__.py
+30
-5
30 additions, 5 deletions
ccnode/hypervisor/__init__.py
with
30 additions
and
5 deletions
ccnode/hypervisor/__init__.py
+
30
−
5
View file @
68be0af6
...
...
@@ -9,7 +9,7 @@ from ccnode.host import Handler as HostHandler
from
ccnode.tags
import
Tag
,
tag_inspector
,
get_tags
from
ccnode.hypervisor
import
tags
from
ccnode.hypervisor
import
lib
as
_libvirt
from
ccnode.hypervisor.lib
import
EVENTS
,
STORAGE_STATES
,
EventLoop
from
ccnode.hypervisor.lib
import
DOMAIN_STATES
,
EVENTS
,
STORAGE_STATES
,
EventLoop
from
ccnode.hypervisor.domains
import
VirtualMachine
...
...
@@ -33,7 +33,10 @@ class Handler(HostHandler):
# initialize hypervisor instance
global
hypervisor
if
hypervisor
is
None
:
hypervisor
=
Hypervisor
(
kwargs
.
pop
(
'
hypervisor_name
'
,
None
))
hypervisor
=
Hypervisor
(
name
=
kwargs
.
pop
(
'
hypervisor_name
'
,
None
),
proxy
=
kwargs
[
'
proxy
'
],
)
self
.
hypervisor
=
weakref
.
proxy
(
hypervisor
)
...
...
@@ -91,7 +94,13 @@ class Handler(HostHandler):
class
Hypervisor
(
object
):
"""
Container for all hypervisor related state.
"""
def
__init__
(
self
,
name
=
None
):
def
__init__
(
self
,
name
,
proxy
):
"""
:param str name: name of hypervisor instance
:param proxy: sjRpc proxy
"""
self
.
sjproxy
=
weakref
.
proxy
(
proxy
)
#: hv attributes
self
.
name
=
name
self
.
type
=
u
'
kvm
'
...
...
@@ -136,11 +145,27 @@ class Hypervisor(object):
def
callback
(
self
,
conn
,
dom
,
event
,
detail
,
opaque
):
"""
Callback for libvirt event loop.
"""
logger
.
debug
(
"
myDomainEventCallback1 EVENT: Domain %s(%s) %s %d
"
%
(
dom
.
name
(),
dom
.
UUIDString
(),
EVENTS
[
event
],
detail
))
event
=
EVENTS
[
event
]
if
event
==
'
Added
'
:
self
.
domains
[
dom
.
UUID
()]
=
VirtualMachine
(
dom
)
vm
=
VirtualMachine
(
dom
,
self
)
self
.
domains
[
vm
.
uuid
]
=
vm
self
.
sjproxy
.
register
(
vm
.
name
,
'
vm
'
)
logger
.
debug
(
'
Add domain: %s (%s)
'
,
vm
.
name
,
vm
.
uuid
)
elif
event
==
'
Removed
'
:
vm
=
self
.
domains
.
pop
(
dom
.
UUID
())
self
.
sjproxy
.
unregister
(
vm
.
name
)
logger
.
debug
(
'
Delete domain: %s (%s)
'
,
vm
.
name
,
vm
.
uuid
)
elif
event
in
(
'
Started
'
,
'
Suspended
'
,
'
Resumed
'
,
'
Stopped
'
,
'
Saved
'
,
'
Restored
'
):
vm
=
self
.
domains
.
get
(
dom
.
UUID
())
# sometimes libvirt sent a start event before a created event so be
# careful
if
vm
is
not
None
:
state
=
DOMAIN_STATES
[
dom
.
info
()[
0
]]
logger
.
debug
(
'
Domain change state from %s to %s
'
,
vm
.
state
,
state
)
vm
.
state
=
state
def
get_domain_by_name
(
self
,
name
):
"""
Get a domain by name.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment