Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
vmdriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
3ad6d364
authored
Jul 16, 2013
by
tarokkk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vmdriver basic functions
parent
fba0d6f5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
vmdriver.py
+53
-0
No files found.
vmdriver.py
0 → 100755
View file @
3ad6d364
#!/usr/bin/env python
import
libvirt
import
vm
import
logging
class
VMDriver
:
'''Circle Virtal Machin driver main class
'''
connection
=
None
def
req_connection
(
original_function
):
'''Connection checking decorator for libvirt.
'''
def
new_function
(
*
args
,
**
kwargs
):
if
args
[
0
]
.
connection
is
None
:
logging
.
error
(
"No connection to libvirt daemon."
)
else
:
return
original_function
(
*
args
,
**
kwargs
)
return
new_function
def
connect
(
self
,
connection_string
=
'qemu:///system'
):
if
self
.
connection
is
None
:
self
.
connection
=
libvirt
.
open
(
connection_string
)
else
:
logging
.
error
(
"There is already an active connection to libvirt."
)
@req_connection
def
disconnect
(
self
,
connection_string
=
'qemu:///system'
):
self
.
connection
.
close
()
self
.
connection
=
None
@req_connection
def
vm_define
(
self
,
vm
):
self
.
connection
.
defineXML
(
vm
.
dump_xml
())
logging
.
info
(
"Virtual machine
%
s is defined from xml"
,
vm
.
name
)
def
vm_create
(
self
,
vm
):
self
.
connection
.
createXML
(
vm
.
dump_xml
())
logging
.
info
(
"Virtual machine
%
s is created from xml"
,
vm
.
name
)
@req_connection
def
list_domains
(
self
):
return
self
.
connection
.
listDefinedDomains
()
#Create VM
a
=
vm
.
VMNetwork
(
name
=
"vm-88"
,
mac
=
"02:00:00:00:00:00"
)
b
=
vm
.
VMDisk
(
name
=
"asd"
,
source
=
'/asdasd/adasds/asd'
)
testvm
=
vm
.
VMInstance
(
name
=
"Thisthename"
,
vcpu
=
"1"
,
memory_max
=
"2048"
,
disk_list
=
[
a
],
network_list
=
[
b
])
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