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
Commit
aa402b6f
authored
Aug 01, 2013
by
tarokkk
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of git.cloud.ik.bme.hu:circle/vmdriver
parents
4ca7d780
20423300
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
4 deletions
+67
-4
vm.py
+9
-3
vmdriver.py
+58
-1
No files found.
vm.py
View file @
aa402b6f
...
...
@@ -16,6 +16,7 @@ class VMInstance:
disk_list
=
list
()
graphics
=
dict
context
=
dict
raw_data
=
None
def
__init__
(
self
,
name
,
...
...
@@ -29,7 +30,8 @@ class VMInstance:
disk_list
=
None
,
context
=
None
,
graphics
=
None
,
acpi
=
True
):
acpi
=
True
,
raw_data
=
None
):
'''Default Virtual Machine constructor
name - unique name for the instance
vcpu - nubmer of processors
...
...
@@ -56,6 +58,7 @@ class VMInstance:
self
.
conext
=
context
self
.
graphics
=
graphics
self
.
acpi
=
acpi
self
.
raw_data
=
raw_data
def
build_xml
(
self
):
'''Return the root Element Tree object
...
...
@@ -95,10 +98,13 @@ class VMInstance:
'port'
:
self
.
graphics
[
'port'
],
'passwd'
:
self
.
graphics
[
'passwd'
],
})
# Features
# Features
(TODO: features as list)
features
=
ET
.
SubElement
(
xml_top
,
'features'
)
if
self
.
acpi
:
ET
.
SubElement
(
features
,
'acpi'
)
# Building raw data into xml
if
self
.
raw_data
is
not
None
:
xml_top
.
append
(
ET
.
fromstring
(
self
.
raw_data
))
return
xml_top
def
dump_xml
(
self
):
...
...
@@ -174,7 +180,7 @@ class VMNetwork:
model -- available models in libvirt
QoS -- CIRCLE QoS class?
comment -- Any comment
managed -- Apply managed flow rules
like Ip and mac
spoofing prevent
managed -- Apply managed flow rules
for
spoofing prevent
script -- Executable network script /bin/true by default
'''
# Class attributes
...
...
vmdriver.py
View file @
aa402b6f
...
...
@@ -6,6 +6,16 @@ import logging
connection
=
None
state_dict
=
{
0
:
'NOSTATE'
,
1
:
'RUNNING'
,
2
:
'BLOCKED'
,
3
:
'PAUSED'
,
4
:
'SHUTDOWN'
,
5
:
'SHUTOFF'
,
6
:
'CRASHED'
,
7
:
'PMSUSPENDED'
}
def
req_connection
(
original_function
):
'''Connection checking decorator for libvirt.
...
...
@@ -82,7 +92,14 @@ def delete(name):
@req_connection
def
list_domains
():
return
connection
.
listDefinedDomains
()
'''
:return list: List of domains name in host
'''
domain_list
=
[]
for
i
in
connection
.
listDomainsID
():
dom
=
connection
.
lookupByID
(
i
)
domain_list
+=
dom
.
name
()
return
domain_list
@req_connection
...
...
@@ -142,4 +159,44 @@ def reboot(name):
'''
domain
=
lookupByName
(
name
)
domain
.
reboot
()
@req_connection
def
node_info
():
''' Get info from Host as dict:
model string indicating the CPU model
memory memory size in kilobytes
cpus the number of active CPUs
mhz expected CPU frequency
nodes the number of NUMA cell, 1 for unusual NUMA
topologies or uniform memory access;
check capabilities XML for the actual NUMA topology
sockets number of CPU sockets per node if nodes > 1,
1 in case of unusual NUMA topology
cores number of cores per socket, total number of
processors in case of unusual NUMA topolog
threads number of threads per core, 1 in case of unusual numa topology
'''
keys
=
[
'model'
,
'memory'
,
'cpus'
,
'mhz'
,
'nodes'
,
'sockets'
,
'cores'
,
'threads'
]
values
=
connection
.
getInfo
()
return
dict
(
zip
(
keys
,
values
))
@req_connection
def
domain_info
(
name
):
'''
state the running state, one of virDomainState
maxmem the maximum memory in KBytes allowed
memory the memory in KBytes used by the domain
virtcpunum the number of virtual CPUs for the domain
cputime the CPU time used in nanoseconds
'''
keys
=
[
'state'
,
'maxmem'
,
'memory'
,
'virtcpunum'
,
'cputime'
]
dom
=
lookupByName
(
name
)
values
=
dom
.
info
()
# Change state to proper ENUM
info
=
dict
(
zip
(
keys
,
values
))
info
[
'state'
]
=
state_dict
[
info
[
'state'
]]
return
info
# 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