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
80ef8890
Commit
80ef8890
authored
12 years ago
by
Anael Beutot
Browse files
Options
Downloads
Patches
Plain Diff
Getting libvirt event loop to work.
TODO: Need to handle event.
parent
2468362c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
ccnode/hypervisor/__init__.py
+34
-14
34 additions, 14 deletions
ccnode/hypervisor/__init__.py
ccnode/hypervisor/lib.py
+0
-12
0 additions, 12 deletions
ccnode/hypervisor/lib.py
with
34 additions
and
26 deletions
ccnode/hypervisor/__init__.py
+
34
−
14
View file @
80ef8890
...
...
@@ -33,7 +33,7 @@ class Handler(HostHandler):
# register domains
proxy
=
kwargs
.
pop
(
'
proxy
'
)
for
dom
in
hypervisor
.
domains
:
for
dom
in
hypervisor
.
domains
.
itervalues
()
:
name
=
dom
.
name
logger
.
debug
(
u
'
Registered domain %s
'
%
name
)
proxy
.
register
(
name
,
'
vm
'
)
...
...
@@ -75,29 +75,49 @@ class Handler(HostHandler):
class
Hypervisor
(
object
):
"""
Container for all hypervisor related state.
"""
def
__init__
(
self
):
# initialize connection to libvirt
self
.
event_loop
=
EventLoop
()
# This tells libvirt what event loop implementation it
# should use
libvirt
.
virEventRegisterImpl
(
self
.
event_loop
.
add_handle
,
self
.
event_loop
.
update_handle
,
self
.
event_loop
.
remove_handle
,
self
.
event_loop
.
add_timer
,
self
.
event_loop
.
update_timer
,
self
.
event_loop
.
remove_timer
,
)
self
.
event_loop
.
start
()
# TODO cleanup connection on stop
_libvirt
.
connection
=
libvirt
.
open
(
'
qemu:///system
'
)
# currently only support KVM
#: domains: vms, containers...
self
.
domains
=
[
VirtualMachine
(
_libvirt
.
connection
.
lookupByID
(
id
),
)
for
id
in
_libvirt
.
connection
.
listDomainsID
()
]
self
.
domains
=
dict
()
# find defined domains
for
dom_name
in
_libvirt
.
connection
.
listDefinedDomains
():
dom
=
_libvirt
.
connection
.
lookupByName
(
dom_name
)
self
.
domains
[
dom
.
UUID
()]
=
VirtualMachine
(
dom
)
# find started domains
for
dom_id
in
_libvirt
.
connection
.
listDomainsID
():
dom
=
_libvirt
.
connection
.
lookupByID
(
dom_id
)
self
.
domains
[
dom
.
UUID
()]
=
VirtualMachine
(
dom
)
logger
.
debug
(
'
Domains: %s
'
,
self
.
domains
)
self
.
event_loop
=
EventLoop
()
self
.
event_loop
.
start
()
self
.
event_loop
.
register_callbacks
(
self
.
callback
)
# TODO cleanup connection on stop
def
callback
(
self
,
conn
,
dom
,
event
,
detail
,
opaque
):
"""
Callback for libv
r
it event loop.
"""
"""
Callback for libvi
r
t 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
)
def
get_domain_by_name
(
self
,
name
):
"""
Get a domain by name.
"""
for
d
in
self
.
domains
:
for
d
in
self
.
domains
.
itervalues
()
:
if
d
.
name
==
name
:
return
d
...
...
@@ -106,7 +126,7 @@ class Hypervisor(object):
def
_count_domain
(
self
,
filter
=
lambda
d
:
True
):
count
=
0
for
dom
in
self
.
domains
:
for
dom
in
self
.
domains
.
itervalues
()
:
if
filter
(
dom
):
count
+=
1
...
...
This diff is collapsed.
Click to expand it.
ccnode/hypervisor/lib.py
+
0
−
12
View file @
80ef8890
...
...
@@ -141,22 +141,10 @@ class EventLoop(object):
self
.
debug
(
"
Self pipe watch %d write %d
"
%
(
self
.
pipetrick
[
0
],
self
.
pipetrick
[
1
]))
self
.
poll
.
register
(
self
.
pipetrick
[
0
],
select
.
POLLIN
)
# This tells libvirt what event loop implementation it
# should use
libvirt
.
virEventRegisterImpl
(
self
.
add_handle
,
self
.
update_handle
,
self
.
remove_handle
,
self
.
add_timer
,
self
.
update_timer
,
self
.
remove_timer
,
)
def
debug
(
self
,
msg
):
if
self
.
debugOn
:
print
msg
def
next_timeout
(
self
):
"""
Calculate when the next timeout is due to occurr, returning
the absolute timestamp for the next timeout, or 0 if there is
...
...
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