Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
vmdriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2543f1aa
authored
Sep 25, 2013
by
Guba Sándor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrapping libvirt errors
parent
37627d70
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
5 deletions
+36
-5
vmdriver.py
+36
-5
No files found.
vmdriver.py
View file @
2543f1aa
...
@@ -46,7 +46,18 @@ def req_connection(original_function, *args, **kw):
...
@@ -46,7 +46,18 @@ def req_connection(original_function, *args, **kw):
return
return_value
return
return_value
@decorator
def
wrap_libvirtError
(
original_function
,
*
args
,
**
kw
):
try
:
original_function
(
*
args
,
**
kw
)
except
libvirt
.
libvirtError
as
e
:
new_e
=
Exception
(
e
.
get_error_message
())
new_e
.
libvirtError
=
True
raise
new_e
@celery.task
@celery.task
@wrap_libvirtError
def
connect
(
connection_string
=
'qemu:///system'
):
def
connect
(
connection_string
=
'qemu:///system'
):
'''Connect to the libvirt daemon specified in the
'''Connect to the libvirt daemon specified in the
connection_string or the local root.
connection_string or the local root.
...
@@ -64,6 +75,7 @@ def connect(connection_string='qemu:///system'):
...
@@ -64,6 +75,7 @@ def connect(connection_string='qemu:///system'):
@celery.task
@celery.task
@wrap_libvirtError
def
disconnect
():
def
disconnect
():
'''Disconnect from the active libvirt daemon connection.
'''Disconnect from the active libvirt daemon connection.
'''
'''
...
@@ -81,6 +93,7 @@ def disconnect():
...
@@ -81,6 +93,7 @@ def disconnect():
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
define
(
vm
):
def
define
(
vm
):
'''Define permanent virtual machine from xml
'''Define permanent virtual machine from xml
'''
'''
...
@@ -90,6 +103,7 @@ def define(vm):
...
@@ -90,6 +103,7 @@ def define(vm):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
create
(
vm_desc
):
def
create
(
vm_desc
):
'''Create and start non-permanent virtual machine from xml
'''Create and start non-permanent virtual machine from xml
flags can be:
flags can be:
...
@@ -108,15 +122,16 @@ def create(vm_desc):
...
@@ -108,15 +122,16 @@ def create(vm_desc):
vm
.
dump_xml
(),
libvirt
.
VIR_DOMAIN_NONE
)
vm
.
dump_xml
(),
libvirt
.
VIR_DOMAIN_NONE
)
domain
=
connection
.
lookupByName
(
vm
.
name
)
domain
=
connection
.
lookupByName
(
vm
.
name
)
domain
.
suspend
()
domain
.
suspend
()
# Real driver create
else
:
else
:
connection
.
createXML
(
vm
.
dump_xml
(),
libvirt
.
VIR_DOMAIN_START_PAUSED
)
connection
.
createXML
(
vm
.
dump_xml
(),
libvirt
.
VIR_DOMAIN_START_PAUSED
)
logging
.
info
(
"Virtual machine
%
s is created from xml"
,
vm
.
name
)
logging
.
info
(
"Virtual machine
%
s is created from xml"
,
vm
.
name
)
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
shutdown
(
name
):
def
shutdown
(
name
):
'''Shutdown virtual machine (need ACPI support).
'''Shutdown virtual machine (need ACPI support).
'''
'''
...
@@ -126,6 +141,7 @@ def shutdown(name):
...
@@ -126,6 +141,7 @@ def shutdown(name):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
delete
(
name
):
def
delete
(
name
):
'''Destroy the running called 'name' virtual machine.
'''Destroy the running called 'name' virtual machine.
'''
'''
...
@@ -135,6 +151,7 @@ def delete(name):
...
@@ -135,6 +151,7 @@ def delete(name):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
list_domains
():
def
list_domains
():
'''
'''
:return list: List of domains name in host
:return list: List of domains name in host
...
@@ -148,6 +165,7 @@ def list_domains():
...
@@ -148,6 +165,7 @@ def list_domains():
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
lookupByName
(
name
):
def
lookupByName
(
name
):
'''Return with the requested Domain
'''Return with the requested Domain
'''
'''
...
@@ -159,6 +177,7 @@ def lookupByName(name):
...
@@ -159,6 +177,7 @@ def lookupByName(name):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
undefine
(
name
):
def
undefine
(
name
):
'''Undefine an already defined virtual machine.
'''Undefine an already defined virtual machine.
If it's running it becomes transient (lsot on reboot)
If it's running it becomes transient (lsot on reboot)
...
@@ -169,6 +188,7 @@ def undefine(name):
...
@@ -169,6 +188,7 @@ def undefine(name):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
start
(
name
):
def
start
(
name
):
'''Start an already defined virtual machine.
'''Start an already defined virtual machine.
'''
'''
...
@@ -178,6 +198,7 @@ def start(name):
...
@@ -178,6 +198,7 @@ def start(name):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
suspend
(
name
):
def
suspend
(
name
):
'''Stop virtual machine and save its memory to path.
'''Stop virtual machine and save its memory to path.
'''
'''
...
@@ -187,6 +208,7 @@ def suspend(name):
...
@@ -187,6 +208,7 @@ def suspend(name):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
save
(
name
,
path
):
def
save
(
name
,
path
):
'''Stop virtual machine and save its memory to path.
'''Stop virtual machine and save its memory to path.
'''
'''
...
@@ -196,6 +218,7 @@ def save(name, path):
...
@@ -196,6 +218,7 @@ def save(name, path):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
restore
(
path
):
def
restore
(
path
):
'''Restore a saved virtual machine
'''Restore a saved virtual machine
from the memory image stored at path.'''
from the memory image stored at path.'''
...
@@ -204,6 +227,7 @@ def restore(path):
...
@@ -204,6 +227,7 @@ def restore(path):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
resume
(
name
):
def
resume
(
name
):
'''Resume stopped virtual machines.
'''Resume stopped virtual machines.
'''
'''
...
@@ -213,6 +237,7 @@ def resume(name):
...
@@ -213,6 +237,7 @@ def resume(name):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
reset
(
name
):
def
reset
(
name
):
'''Reset (power reset) virtual machine.
'''Reset (power reset) virtual machine.
'''
'''
...
@@ -222,6 +247,7 @@ def reset(name):
...
@@ -222,6 +247,7 @@ def reset(name):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
reboot
(
name
):
def
reboot
(
name
):
'''Reboot (with guest acpi support) virtual machine.
'''Reboot (with guest acpi support) virtual machine.
'''
'''
...
@@ -231,6 +257,7 @@ def reboot(name):
...
@@ -231,6 +257,7 @@ def reboot(name):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
node_info
():
def
node_info
():
''' Get info from Host as dict:
''' Get info from Host as dict:
model string indicating the CPU model
model string indicating the CPU model
...
@@ -254,6 +281,7 @@ def node_info():
...
@@ -254,6 +281,7 @@ def node_info():
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
domain_info
(
name
):
def
domain_info
(
name
):
'''
'''
state the running state, one of virDomainState
state the running state, one of virDomainState
...
@@ -273,6 +301,7 @@ def domain_info(name):
...
@@ -273,6 +301,7 @@ def domain_info(name):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
network_info
(
name
,
network
):
def
network_info
(
name
,
network
):
'''
'''
rx_bytes
rx_bytes
...
@@ -294,6 +323,7 @@ def network_info(name, network):
...
@@ -294,6 +323,7 @@ def network_info(name, network):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
send_key
(
name
,
key_code
):
def
send_key
(
name
,
key_code
):
''' Sending linux key_code to the name vm
''' Sending linux key_code to the name vm
key_code can be optained from linux_keys.py
key_code can be optained from linux_keys.py
...
@@ -310,6 +340,7 @@ def _stream_handler(stream, buf, opaque):
...
@@ -310,6 +340,7 @@ def _stream_handler(stream, buf, opaque):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
screenshot
(
name
,
path
):
def
screenshot
(
name
,
path
):
"""Save screenshot of virtual machine
"""Save screenshot of virtual machine
to the path as name-screenshot.ppm
to the path as name-screenshot.ppm
...
@@ -339,6 +370,7 @@ def screenshot(name, path):
...
@@ -339,6 +370,7 @@ def screenshot(name, path):
@celery.task
@celery.task
@req_connection
@req_connection
@wrap_libvirtError
def
migrate
(
name
,
host
,
live
=
False
):
def
migrate
(
name
,
host
,
live
=
False
):
'''Migrate domain to host'''
'''Migrate domain to host'''
flags
=
libvirt
.
VIR_MIGRATE_PEER2PEER
flags
=
libvirt
.
VIR_MIGRATE_PEER2PEER
...
@@ -350,4 +382,3 @@ def migrate(name, host, live=False):
...
@@ -350,4 +382,3 @@ def migrate(name, host, live=False):
flags
=
flags
,
flags
=
flags
,
dname
=
name
,
dname
=
name
,
bandwidth
=
0
)
bandwidth
=
0
)
# virDomainResume
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