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
258adab7
authored
Nov 22, 2015
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm, vmdriver: add CephVMDisk attach and detach functionality
parent
2934eb08
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
19 deletions
+21
-19
vm.py
+7
-14
vmdriver.py
+14
-5
No files found.
vm.py
View file @
258adab7
...
...
@@ -76,7 +76,9 @@ class VMInstance:
@classmethod
def
deserialize
(
cls
,
desc
):
desc
[
'disk_list'
]
=
[
VMDisk
.
deserialize
(
d
)
for
d
in
desc
[
'disk_list'
]]
desc
[
'disk_list'
]
=
[
CephVMDisk
.
deserialize
(
d
)
if
d
[
"data_store_type"
]
==
"ceph_block"
else
VMDisk
.
deserialize
(
d
)
for
d
in
desc
[
'disk_list'
]]
desc
[
'network_list'
]
=
[
VMNetwork
.
deserialize
(
n
)
for
n
in
desc
[
'network_list'
]]
return
cls
(
**
desc
)
...
...
@@ -211,6 +213,7 @@ class VMDisk(object):
@classmethod
def
deserialize
(
cls
,
desc
):
del
desc
[
"data_store_type"
]
return
cls
(
**
desc
)
def
build_xml
(
self
):
...
...
@@ -276,6 +279,7 @@ class CephVMDisk(VMDisk):
@classmethod
def
deserialize
(
cls
,
desc
):
del
desc
[
"data_store_type"
]
return
cls
(
**
desc
)
def
build_xml
(
self
):
...
...
@@ -286,9 +290,9 @@ class CephVMDisk(VMDisk):
attrib
=
{
"name"
:
self
.
source
,
"protocol"
:
self
.
protocol
})
for
hos
t
in
self
.
hosts
:
for
name
,
por
t
in
self
.
hosts
:
ET
.
SubElement
(
source
,
"host"
,
attrib
=
self
.
__attrib_from_host
(
host
)
)
attrib
=
{
"name"
:
name
,
"port"
:
unicode
(
port
)}
)
if
self
.
ceph_user
is
not
None
and
self
.
secret_uuid
is
not
None
:
auth
=
ET
.
SubElement
(
xml_top
,
"auth"
,
...
...
@@ -298,17 +302,6 @@ class CephVMDisk(VMDisk):
return
xml_top
def
__attrib_from_host
(
self
,
host
):
port_pos
=
host
.
rfind
(
':'
)
port
=
""
name
=
host
if
port_pos
!=
-
1
and
port_pos
<
len
(
host
):
port
=
host
[
port_pos
+
1
:]
name
=
host
[:
port_pos
]
return
{
"name"
:
name
,
"port"
:
port
}
class
VMNetwork
:
...
...
vmdriver.py
View file @
258adab7
...
...
@@ -12,7 +12,7 @@ from psutil import NUM_CPUS, virtual_memory, cpu_percent
from
celery.contrib.abortable
import
AbortableTask
from
vm
import
VMInstance
,
VMDisk
,
VMNetwork
from
vm
import
VMInstance
,
VMDisk
,
CephVMDisk
,
VMNetwork
from
vmcelery
import
celery
,
lib_connection
,
to_bool
...
...
@@ -550,20 +550,29 @@ def migrate(name, host, live=False):
@celery.task
@req_connection
@wrap_libvirtError
def
attach_disk
(
name
,
disk
):
def
attach_disk
(
name
,
disk
_desc
):
""" Attach Disk to a running virtual machine. """
domain
=
lookupByName
(
name
)
disk
=
VMDisk
.
deserialize
(
disk
)
disk
=
None
if
disk_desc
[
"data_store_type"
]
==
"ceph_block"
:
disk
=
CephVMDisk
.
deserialize
(
disk_desc
)
else
:
disk
=
VMDisk
.
deserialize
(
disk_desc
)
domain
.
attachDevice
(
disk
.
dump_xml
())
@celery.task
@req_connection
@wrap_libvirtError
def
detach_disk
(
name
,
disk
):
def
detach_disk
(
name
,
disk
_desc
):
""" Detach disk from a running virtual machine. """
domain
=
lookupByName
(
name
)
disk
=
VMDisk
.
deserialize
(
disk
)
disk
=
None
if
disk_desc
[
"data_store_type"
]
==
"ceph_block"
:
disk
=
CephVMDisk
.
deserialize
(
disk_desc
)
else
:
disk
=
VMDisk
.
deserialize
(
disk_desc
)
domain
.
detachDevice
(
disk
.
dump_xml
())
# Libvirt does NOT report failed detach so test it.
__check_detach
(
domain
,
disk
.
source
)
...
...
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