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
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_TASK_RESULT_EXPIRES
=
300
CELERY_TIMEZONE
=
'UTC'
CELERY_ENABLE_UTC
=
True
CELERY_ACCEPT_CONTENT
=
[
'pickle'
,
'json'
,
'msgpack'
,
'yaml'
]
netdriver.py
View file @
92240946
...
...
@@ -6,8 +6,12 @@ from netcelery import celery
from
os
import
getenv
from
vm
import
VMNetwork
from
vmcelery
import
native_ovs
from
celery.utils.log
import
get_task_logger
driver
=
getenv
(
"HYPERVISOR_TYPE"
,
"test"
)
logger
=
get_task_logger
(
__name__
)
@celery.task
def
create
(
network
):
...
...
@@ -40,7 +44,7 @@ def ovs_command_execute(command):
"""
command
=
[
'sudo'
,
'ovs-vsctl'
]
+
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
...
...
@@ -53,7 +57,7 @@ def ofctl_command_execute(command):
"""
command
=
[
'sudo'
,
'ovs-ofctl'
]
+
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
...
...
@@ -304,7 +308,7 @@ def pull_up_interface(network):
"""
command
=
[
'sudo'
,
'ip'
,
'link'
,
'set'
,
'up'
,
network
.
name
]
return_val
=
subprocess
.
call
(
command
)
logg
ing
.
info
(
'IP command:
%
s executed.'
,
command
)
logg
er
.
info
(
'IP command:
%
s executed.'
,
command
)
return
return_val
...
...
vm.py
View file @
92240946
...
...
@@ -21,8 +21,8 @@ class VMInstance:
raw_data
=
None
def
__init__
(
self
,
name
,
vcpu
,
name
=
None
,
vcpu
=
None
,
vcpu_max
=
None
,
memory_max
=
None
,
memory
=
None
,
...
...
@@ -228,8 +228,8 @@ class VMDisk:
cache_size
=
None
def
__init__
(
self
,
name
,
source
,
name
=
None
,
source
=
None
,
disk_type
=
"file"
,
disk_device
=
"disk"
,
driver_name
=
"qemu"
,
...
...
vmdriver.py
View file @
92240946
...
...
@@ -7,14 +7,11 @@ import socket
import
json
from
decorator
import
decorator
import
lxml.etree
as
ET
from
psutil
import
cpu_count
,
virtual_memory
,
cpu_percent
from
celery.contrib.abortable
import
AbortableTask
from
vm
import
VMInstance
,
VMDisk
,
VMNetwork
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__
)))
...
...
@@ -31,6 +28,8 @@ state_dict = {0: 'NOSTATE',
}
logger
=
get_task_logger
(
__name__
)
# class Singleton(type):
#
# """ Singleton class."""
...
...
@@ -74,18 +73,18 @@ def req_connection(original_function, *args, **kw):
Return the decorateed function
"""
logg
ing
.
debug
(
"Decorator running"
)
logg
er
.
debug
(
"Decorator running"
)
if
Connection
.
get
()
is
None
:
connect
()
try
:
logg
ing
.
debug
(
"Decorator calling original function"
)
logg
er
.
debug
(
"Decorator calling original function"
)
return_value
=
original_function
(
*
args
,
**
kw
)
finally
:
logg
ing
.
debug
(
"Finally part of decorator"
)
logg
er
.
debug
(
"Finally part of decorator"
)
disconnect
()
return
return_value
else
:
logg
ing
.
debug
(
"Decorator calling original
\
logg
er
.
debug
(
"Decorator calling original
\
function with active connection"
)
return_value
=
original_function
(
*
args
,
**
kw
)
return
return_value
...
...
@@ -101,7 +100,7 @@ def wrap_libvirtError(original_function, *args, **kw):
try
:
return
original_function
(
*
args
,
**
kw
)
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
()
if
vm_xml_dump
is
not
None
:
e_msg
+=
"
\n
"
...
...
@@ -122,12 +121,12 @@ def connect(connection_string='qemu:///system'):
if
not
to_bool
(
os
.
getenv
(
'LIBVIRT_KEEPALIVE'
,
"False"
)):
if
Connection
.
get
()
is
None
:
Connection
.
set
(
libvirt
.
open
(
connection_string
))
logg
ing
.
debug
(
"Connection estabilished to libvirt."
)
logg
er
.
debug
(
"Connection estabilished to libvirt."
)
else
:
logg
ing
.
debug
(
"There is already an active connection to libvirt."
)
logg
er
.
debug
(
"There is already an active connection to libvirt."
)
else
:
Connection
.
set
(
lib_connection
)
logg
ing
.
debug
(
"Using celery libvirt connection connection."
)
logg
er
.
debug
(
"Using celery libvirt connection connection."
)
@wrap_libvirtError
...
...
@@ -135,13 +134,13 @@ def disconnect():
""" Disconnect from the active libvirt daemon connection."""
if
os
.
getenv
(
'LIBVIRT_KEEPALIVE'
)
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
:
Connection
.
get
()
.
close
()
logg
ing
.
debug
(
'Connection closed to libvirt.'
)
logg
er
.
debug
(
'Connection closed to libvirt.'
)
Connection
.
set
(
None
)
else
:
logg
ing
.
debug
(
'Keepalive connection should not close.'
)
logg
er
.
debug
(
'Keepalive connection should not close.'
)
@celery.task
...
...
@@ -150,7 +149,7 @@ def disconnect():
def
define
(
vm
):
""" Define permanent virtual machine from 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
...
...
@@ -174,7 +173,7 @@ def create(vm_desc):
if
vm
.
vm_type
==
"test"
:
vm
.
arch
=
"i686"
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
if
vm
.
vm_type
==
"test"
:
Connection
.
get
()
.
createXML
(
...
...
@@ -183,10 +182,10 @@ def create(vm_desc):
domain
.
suspend
()
# Real driver create
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
(
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
try
:
sock
=
socket
.
create_connection
((
'127.0.0.1'
,
1235
),
3
)
...
...
@@ -195,7 +194,7 @@ def create(vm_desc):
sock
.
sendall
(
json
.
dumps
(
data
))
sock
.
close
()
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
...
...
@@ -211,12 +210,12 @@ class shutdown(AbortableTask):
def
run
(
self
,
args
):
from
time
import
sleep
name
,
=
args
logg
ing
.
info
(
"Shutdown started for vm:
%
s"
,
name
)
logg
er
.
info
(
"Shutdown started for vm:
%
s"
,
name
)
try
:
domain
=
lookupByName
(
name
)
logg
ing
.
info
(
"
%
s domain found in shutdown"
,
name
)
logg
er
.
info
(
"
%
s domain found in shutdown"
,
name
)
domain
.
shutdown
()
logg
ing
.
info
(
"Domain shutdown called for vm:
%
s"
,
name
)
logg
er
.
info
(
"Domain shutdown called for vm:
%
s"
,
name
)
while
True
:
try
:
Connection
.
get
()
.
lookupByName
(
name
)
...
...
@@ -227,7 +226,7 @@ class shutdown(AbortableTask):
raise
else
:
if
self
.
is_aborted
():
logg
ing
.
info
(
"Shutdown aborted on vm:
%
s"
,
name
)
logg
er
.
info
(
"Shutdown aborted on vm:
%
s"
,
name
)
return
sleep
(
5
)
except
libvirt
.
libvirtError
as
e
:
...
...
@@ -607,7 +606,7 @@ def __check_detach(domain, disk):
def
attach_network
(
name
,
net
):
domain
=
lookupByName
(
name
)
net
=
VMNetwork
.
deserialize
(
net
)
logg
ing
.
error
(
net
.
dump_xml
())
logg
er
.
error
(
net
.
dump_xml
())
domain
.
attachDevice
(
net
.
dump_xml
())
...
...
@@ -628,7 +627,7 @@ def resize_disk(name, path, size):
# domain.blockResize(path, int(size),
# flags=libvirt.VIR_DOMAIN_BLOCK_RESIZE_BYTES)
# 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
)
...
...
@@ -648,7 +647,7 @@ def get_architecture():
@celery.task
def
get_core_num
():
return
cpu_count
return
cpu_count
()
@celery.task
...
...
@@ -667,12 +666,13 @@ def get_driver_version():
'commit_text'
:
lc
.
summary
,
'is_dirty'
:
repo
.
is_dirty
()}
except
Exception
as
e
:
logg
ing
.
exception
(
"Unhandled exception:
%
s"
,
e
)
logg
er
.
exception
(
"Unhandled exception:
%
s"
,
e
)
return
None
@celery.task
def
get_info
():
logger
.
debug
(
"Get_Info"
)
return
{
'core_num'
:
get_core_num
(),
'ram_size'
:
get_ram_size
(),
'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