Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
vmdriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
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
92240946
authored
Aug 29, 2024
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migration to IK
parent
c0bfc619
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
36 deletions
+39
-36
celeryconfig.py
+0
-1
netdriver.py
+7
-3
vm.py
+4
-4
vmdriver.py
+28
-28
No files found.
celeryconfig.py
View file @
92240946
CELERY_RESULT_BACKEND
=
'amqp://'
CELERY_RESULT_BACKEND
=
'amqp://'
CELERY_TASK_RESULT_EXPIRES
=
300
CELERY_TASK_RESULT_EXPIRES
=
300
CELERY_TIMEZONE
=
'UTC'
CELERY_ENABLE_UTC
=
True
CELERY_ENABLE_UTC
=
True
CELERY_ACCEPT_CONTENT
=
[
'pickle'
,
'json'
,
'msgpack'
,
'yaml'
]
CELERY_ACCEPT_CONTENT
=
[
'pickle'
,
'json'
,
'msgpack'
,
'yaml'
]
netdriver.py
View file @
92240946
...
@@ -6,8 +6,12 @@ from netcelery import celery
...
@@ -6,8 +6,12 @@ from netcelery import celery
from
os
import
getenv
from
os
import
getenv
from
vm
import
VMNetwork
from
vm
import
VMNetwork
from
vmcelery
import
native_ovs
from
vmcelery
import
native_ovs
from
celery.utils.log
import
get_task_logger
driver
=
getenv
(
"HYPERVISOR_TYPE"
,
"test"
)
driver
=
getenv
(
"HYPERVISOR_TYPE"
,
"test"
)
logger
=
get_task_logger
(
__name__
)
@celery.task
@celery.task
def
create
(
network
):
def
create
(
network
):
...
@@ -40,7 +44,7 @@ def ovs_command_execute(command):
...
@@ -40,7 +44,7 @@ def ovs_command_execute(command):
"""
"""
command
=
[
'sudo'
,
'ovs-vsctl'
]
+
command
command
=
[
'sudo'
,
'ovs-vsctl'
]
+
command
return_val
=
subprocess
.
call
(
command
)
return_val
=
subprocess
.
call
(
command
)
logg
ing
.
info
(
'OVS command:
%
s executed.'
,
command
)
logg
er
.
info
(
'OVS command:
%
s executed.'
,
command
)
return
return_val
return
return_val
...
@@ -53,7 +57,7 @@ def ofctl_command_execute(command):
...
@@ -53,7 +57,7 @@ def ofctl_command_execute(command):
"""
"""
command
=
[
'sudo'
,
'ovs-ofctl'
]
+
command
command
=
[
'sudo'
,
'ovs-ofctl'
]
+
command
return_val
=
subprocess
.
call
(
command
)
return_val
=
subprocess
.
call
(
command
)
logg
ing
.
info
(
'OVS flow command:
%
s executed.'
,
command
)
logg
er
.
info
(
'OVS flow command:
%
s executed.'
,
command
)
return
return_val
return
return_val
...
@@ -304,7 +308,7 @@ def pull_up_interface(network):
...
@@ -304,7 +308,7 @@ def pull_up_interface(network):
"""
"""
command
=
[
'sudo'
,
'ip'
,
'link'
,
'set'
,
'up'
,
network
.
name
]
command
=
[
'sudo'
,
'ip'
,
'link'
,
'set'
,
'up'
,
network
.
name
]
return_val
=
subprocess
.
call
(
command
)
return_val
=
subprocess
.
call
(
command
)
logg
ing
.
info
(
'IP command:
%
s executed.'
,
command
)
logg
er
.
info
(
'IP command:
%
s executed.'
,
command
)
return
return_val
return
return_val
...
...
vm.py
View file @
92240946
...
@@ -21,8 +21,8 @@ class VMInstance:
...
@@ -21,8 +21,8 @@ class VMInstance:
raw_data
=
None
raw_data
=
None
def
__init__
(
self
,
def
__init__
(
self
,
name
,
name
=
None
,
vcpu
,
vcpu
=
None
,
vcpu_max
=
None
,
vcpu_max
=
None
,
memory_max
=
None
,
memory_max
=
None
,
memory
=
None
,
memory
=
None
,
...
@@ -228,8 +228,8 @@ class VMDisk:
...
@@ -228,8 +228,8 @@ class VMDisk:
cache_size
=
None
cache_size
=
None
def
__init__
(
self
,
def
__init__
(
self
,
name
,
name
=
None
,
source
,
source
=
None
,
disk_type
=
"file"
,
disk_type
=
"file"
,
disk_device
=
"disk"
,
disk_device
=
"disk"
,
driver_name
=
"qemu"
,
driver_name
=
"qemu"
,
...
...
vmdriver.py
View file @
92240946
...
@@ -7,14 +7,11 @@ import socket
...
@@ -7,14 +7,11 @@ import socket
import
json
import
json
from
decorator
import
decorator
from
decorator
import
decorator
import
lxml.etree
as
ET
import
lxml.etree
as
ET
from
psutil
import
cpu_count
,
virtual_memory
,
cpu_percent
from
psutil
import
cpu_count
,
virtual_memory
,
cpu_percent
from
celery.contrib.abortable
import
AbortableTask
from
celery.contrib.abortable
import
AbortableTask
from
vm
import
VMInstance
,
VMDisk
,
VMNetwork
from
vm
import
VMInstance
,
VMDisk
,
VMNetwork
from
vmcelery
import
celery
,
lib_connection
,
to_bool
from
vmcelery
import
celery
,
lib_connection
,
to_bool
from
celery.utils.log
import
get_task_logger
sys
.
path
.
append
(
os
.
path
.
dirname
(
os
.
path
.
basename
(
__file__
)))
sys
.
path
.
append
(
os
.
path
.
dirname
(
os
.
path
.
basename
(
__file__
)))
...
@@ -31,6 +28,8 @@ state_dict = {0: 'NOSTATE',
...
@@ -31,6 +28,8 @@ state_dict = {0: 'NOSTATE',
}
}
logger
=
get_task_logger
(
__name__
)
# class Singleton(type):
# class Singleton(type):
#
#
# """ Singleton class."""
# """ Singleton class."""
...
@@ -74,18 +73,18 @@ def req_connection(original_function, *args, **kw):
...
@@ -74,18 +73,18 @@ def req_connection(original_function, *args, **kw):
Return the decorateed function
Return the decorateed function
"""
"""
logg
ing
.
debug
(
"Decorator running"
)
logg
er
.
debug
(
"Decorator running"
)
if
Connection
.
get
()
is
None
:
if
Connection
.
get
()
is
None
:
connect
()
connect
()
try
:
try
:
logg
ing
.
debug
(
"Decorator calling original function"
)
logg
er
.
debug
(
"Decorator calling original function"
)
return_value
=
original_function
(
*
args
,
**
kw
)
return_value
=
original_function
(
*
args
,
**
kw
)
finally
:
finally
:
logg
ing
.
debug
(
"Finally part of decorator"
)
logg
er
.
debug
(
"Finally part of decorator"
)
disconnect
()
disconnect
()
return
return_value
return
return_value
else
:
else
:
logg
ing
.
debug
(
"Decorator calling original
\
logg
er
.
debug
(
"Decorator calling original
\
function with active connection"
)
function with active connection"
)
return_value
=
original_function
(
*
args
,
**
kw
)
return_value
=
original_function
(
*
args
,
**
kw
)
return
return_value
return
return_value
...
@@ -101,7 +100,7 @@ def wrap_libvirtError(original_function, *args, **kw):
...
@@ -101,7 +100,7 @@ def wrap_libvirtError(original_function, *args, **kw):
try
:
try
:
return
original_function
(
*
args
,
**
kw
)
return
original_function
(
*
args
,
**
kw
)
except
libvirt
.
libvirtError
as
e
:
except
libvirt
.
libvirtError
as
e
:
logg
ing
.
error
(
e
.
get_error_message
())
logg
er
.
error
(
e
.
get_error_message
())
e_msg
=
e
.
get_error_message
()
e_msg
=
e
.
get_error_message
()
if
vm_xml_dump
is
not
None
:
if
vm_xml_dump
is
not
None
:
e_msg
+=
"
\n
"
e_msg
+=
"
\n
"
...
@@ -122,12 +121,12 @@ def connect(connection_string='qemu:///system'):
...
@@ -122,12 +121,12 @@ def connect(connection_string='qemu:///system'):
if
not
to_bool
(
os
.
getenv
(
'LIBVIRT_KEEPALIVE'
,
"False"
)):
if
not
to_bool
(
os
.
getenv
(
'LIBVIRT_KEEPALIVE'
,
"False"
)):
if
Connection
.
get
()
is
None
:
if
Connection
.
get
()
is
None
:
Connection
.
set
(
libvirt
.
open
(
connection_string
))
Connection
.
set
(
libvirt
.
open
(
connection_string
))
logg
ing
.
debug
(
"Connection estabilished to libvirt."
)
logg
er
.
debug
(
"Connection estabilished to libvirt."
)
else
:
else
:
logg
ing
.
debug
(
"There is already an active connection to libvirt."
)
logg
er
.
debug
(
"There is already an active connection to libvirt."
)
else
:
else
:
Connection
.
set
(
lib_connection
)
Connection
.
set
(
lib_connection
)
logg
ing
.
debug
(
"Using celery libvirt connection connection."
)
logg
er
.
debug
(
"Using celery libvirt connection connection."
)
@wrap_libvirtError
@wrap_libvirtError
...
@@ -135,13 +134,13 @@ def disconnect():
...
@@ -135,13 +134,13 @@ def disconnect():
""" Disconnect from the active libvirt daemon connection."""
""" Disconnect from the active libvirt daemon connection."""
if
os
.
getenv
(
'LIBVIRT_KEEPALIVE'
)
is
None
:
if
os
.
getenv
(
'LIBVIRT_KEEPALIVE'
)
is
None
:
if
Connection
.
get
()
is
None
:
if
Connection
.
get
()
is
None
:
logg
ing
.
debug
(
'There is no available libvirt conection.'
)
logg
er
.
debug
(
'There is no available libvirt conection.'
)
else
:
else
:
Connection
.
get
()
.
close
()
Connection
.
get
()
.
close
()
logg
ing
.
debug
(
'Connection closed to libvirt.'
)
logg
er
.
debug
(
'Connection closed to libvirt.'
)
Connection
.
set
(
None
)
Connection
.
set
(
None
)
else
:
else
:
logg
ing
.
debug
(
'Keepalive connection should not close.'
)
logg
er
.
debug
(
'Keepalive connection should not close.'
)
@celery.task
@celery.task
...
@@ -150,7 +149,7 @@ def disconnect():
...
@@ -150,7 +149,7 @@ def disconnect():
def
define
(
vm
):
def
define
(
vm
):
""" Define permanent virtual machine from xml. """
""" Define permanent virtual machine from xml. """
Connection
.
get
()
.
defineXML
(
vm
.
dump_xml
())
Connection
.
get
()
.
defineXML
(
vm
.
dump_xml
())
logg
ing
.
info
(
"Virtual machine
%
s is defined from xml"
,
vm
.
name
)
logg
er
.
info
(
"Virtual machine
%
s is defined from xml"
,
vm
.
name
)
@celery.task
@celery.task
...
@@ -174,7 +173,7 @@ def create(vm_desc):
...
@@ -174,7 +173,7 @@ def create(vm_desc):
if
vm
.
vm_type
==
"test"
:
if
vm
.
vm_type
==
"test"
:
vm
.
arch
=
"i686"
vm
.
arch
=
"i686"
vm_xml_dump
=
vm
.
dump_xml
()
vm_xml_dump
=
vm
.
dump_xml
()
logg
ing
.
info
(
vm_xml_dump
)
logg
er
.
info
(
vm_xml_dump
)
# Emulating DOMAIN_START_PAUSED FLAG behaviour on test driver
# Emulating DOMAIN_START_PAUSED FLAG behaviour on test driver
if
vm
.
vm_type
==
"test"
:
if
vm
.
vm_type
==
"test"
:
Connection
.
get
()
.
createXML
(
Connection
.
get
()
.
createXML
(
...
@@ -183,10 +182,10 @@ def create(vm_desc):
...
@@ -183,10 +182,10 @@ def create(vm_desc):
domain
.
suspend
()
domain
.
suspend
()
# Real driver create
# Real driver create
else
:
else
:
logg
ing
.
info
(
"Virtual machine
%
s being created from xml"
,
vm
.
name
)
logg
er
.
info
(
"Virtual machine
%
s being created from xml"
,
vm
.
name
)
Connection
.
get
()
.
createXML
(
Connection
.
get
()
.
createXML
(
vm_xml_dump
,
libvirt
.
VIR_DOMAIN_START_PAUSED
)
vm_xml_dump
,
libvirt
.
VIR_DOMAIN_START_PAUSED
)
logg
ing
.
info
(
"Virtual machine
%
s is created from xml"
,
vm
.
name
)
logg
er
.
info
(
"Virtual machine
%
s is created from xml"
,
vm
.
name
)
# context
# context
try
:
try
:
sock
=
socket
.
create_connection
((
'127.0.0.1'
,
1235
),
3
)
sock
=
socket
.
create_connection
((
'127.0.0.1'
,
1235
),
3
)
...
@@ -195,7 +194,7 @@ def create(vm_desc):
...
@@ -195,7 +194,7 @@ def create(vm_desc):
sock
.
sendall
(
json
.
dumps
(
data
))
sock
.
sendall
(
json
.
dumps
(
data
))
sock
.
close
()
sock
.
close
()
except
socket
.
error
:
except
socket
.
error
:
logg
ing
.
error
(
'Unable to connect to context server'
)
logg
er
.
error
(
'Unable to connect to context server'
)
return
vm_xml_dump
return
vm_xml_dump
...
@@ -211,12 +210,12 @@ class shutdown(AbortableTask):
...
@@ -211,12 +210,12 @@ class shutdown(AbortableTask):
def
run
(
self
,
args
):
def
run
(
self
,
args
):
from
time
import
sleep
from
time
import
sleep
name
,
=
args
name
,
=
args
logg
ing
.
info
(
"Shutdown started for vm:
%
s"
,
name
)
logg
er
.
info
(
"Shutdown started for vm:
%
s"
,
name
)
try
:
try
:
domain
=
lookupByName
(
name
)
domain
=
lookupByName
(
name
)
logg
ing
.
info
(
"
%
s domain found in shutdown"
,
name
)
logg
er
.
info
(
"
%
s domain found in shutdown"
,
name
)
domain
.
shutdown
()
domain
.
shutdown
()
logg
ing
.
info
(
"Domain shutdown called for vm:
%
s"
,
name
)
logg
er
.
info
(
"Domain shutdown called for vm:
%
s"
,
name
)
while
True
:
while
True
:
try
:
try
:
Connection
.
get
()
.
lookupByName
(
name
)
Connection
.
get
()
.
lookupByName
(
name
)
...
@@ -227,7 +226,7 @@ class shutdown(AbortableTask):
...
@@ -227,7 +226,7 @@ class shutdown(AbortableTask):
raise
raise
else
:
else
:
if
self
.
is_aborted
():
if
self
.
is_aborted
():
logg
ing
.
info
(
"Shutdown aborted on vm:
%
s"
,
name
)
logg
er
.
info
(
"Shutdown aborted on vm:
%
s"
,
name
)
return
return
sleep
(
5
)
sleep
(
5
)
except
libvirt
.
libvirtError
as
e
:
except
libvirt
.
libvirtError
as
e
:
...
@@ -607,7 +606,7 @@ def __check_detach(domain, disk):
...
@@ -607,7 +606,7 @@ def __check_detach(domain, disk):
def
attach_network
(
name
,
net
):
def
attach_network
(
name
,
net
):
domain
=
lookupByName
(
name
)
domain
=
lookupByName
(
name
)
net
=
VMNetwork
.
deserialize
(
net
)
net
=
VMNetwork
.
deserialize
(
net
)
logg
ing
.
error
(
net
.
dump_xml
())
logg
er
.
error
(
net
.
dump_xml
())
domain
.
attachDevice
(
net
.
dump_xml
())
domain
.
attachDevice
(
net
.
dump_xml
())
...
@@ -628,7 +627,7 @@ def resize_disk(name, path, size):
...
@@ -628,7 +627,7 @@ def resize_disk(name, path, size):
# domain.blockResize(path, int(size),
# domain.blockResize(path, int(size),
# flags=libvirt.VIR_DOMAIN_BLOCK_RESIZE_BYTES)
# flags=libvirt.VIR_DOMAIN_BLOCK_RESIZE_BYTES)
# To be compatible with libvirt < 0.9.11
# To be compatible with libvirt < 0.9.11
logg
ing
.
debug
(
" === Resize : "
+
size
)
logg
er
.
debug
(
" === Resize : "
+
size
)
domain
.
blockResize
(
path
,
int
(
size
)
//
1024
,
0
)
domain
.
blockResize
(
path
,
int
(
size
)
//
1024
,
0
)
...
@@ -648,7 +647,7 @@ def get_architecture():
...
@@ -648,7 +647,7 @@ def get_architecture():
@celery.task
@celery.task
def
get_core_num
():
def
get_core_num
():
return
cpu_count
return
cpu_count
()
@celery.task
@celery.task
...
@@ -667,12 +666,13 @@ def get_driver_version():
...
@@ -667,12 +666,13 @@ def get_driver_version():
'commit_text'
:
lc
.
summary
,
'commit_text'
:
lc
.
summary
,
'is_dirty'
:
repo
.
is_dirty
()}
'is_dirty'
:
repo
.
is_dirty
()}
except
Exception
as
e
:
except
Exception
as
e
:
logg
ing
.
exception
(
"Unhandled exception:
%
s"
,
e
)
logg
er
.
exception
(
"Unhandled exception:
%
s"
,
e
)
return
None
return
None
@celery.task
@celery.task
def
get_info
():
def
get_info
():
logger
.
debug
(
"Get_Info"
)
return
{
'core_num'
:
get_core_num
(),
return
{
'core_num'
:
get_core_num
(),
'ram_size'
:
get_ram_size
(),
'ram_size'
:
get_ram_size
(),
'architecture'
:
get_architecture
(),
'architecture'
:
get_architecture
(),
...
...
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