1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-10-31 19:44:16 +00:00

Retreive all RBD hosts (and their port if defined) from pool definition during instance creation

This commit is contained in:
Benjamin Renard 2016-04-16 15:04:28 +02:00
parent 2f63d35804
commit ee2b97d62f

View file

@ -7,9 +7,17 @@ from webvirtcloud.settings import QEMU_CONSOLE_DEFAULT_TYPE
def get_rbd_storage_data(stg):
xml = stg.XMLDesc(0)
ceph_user = util.get_xml_path(xml, "/pool/source/auth/@username")
ceph_host = util.get_xml_path(xml, "/pool/source/host/@name")
secrt_uuid = util.get_xml_path(xml, "/pool/source/auth/secret/@uuid")
return ceph_user, secrt_uuid, ceph_host
def get_ceph_hosts(ctx):
hosts = []
for host in ctx.xpathEval("/pool/source/host"):
name = host.prop("name")
if name:
hosts.append({'name': name, 'port': host.prop("port")})
return hosts
ceph_hosts = util.get_xml_path(xml, func=get_ceph_hosts)
secret_uuid = util.get_xml_path(xml, "/pool/source/auth/secret/@uuid")
return ceph_user, secret_uuid, ceph_hosts
class wvmCreate(wvmConnect):
@ -162,15 +170,23 @@ class wvmCreate(wvmConnect):
stg_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
if stg_type == 'rbd':
ceph_user, secrt_uuid, ceph_host = get_rbd_storage_data(stg)
ceph_user, secret_uuid, ceph_hosts = get_rbd_storage_data(stg)
xml += """<disk type='network' device='disk'>
<driver name='qemu' type='%s'/>
<auth username='%s'>
<secret type='ceph' uuid='%s'/>
</auth>
<source protocol='rbd' name='%s'>
<host name='%s' port='6789'/>
</source>""" % (img_type, ceph_user, secrt_uuid, image, ceph_host)
<source protocol='rbd' name='%s'>""" % (img_type, ceph_user, secret_uuid, image)
if isinstance(ceph_hosts, list):
for host in ceph_hosts:
if host.get('port'):
xml += """
<host name='%s' port='%s'/>""" % (host.get('name'), host.get('port'))
else:
xml += """
<host name='%s'/>""" % host.get('name')
xml += """
</source>"""
else:
xml += """<disk type='file' device='disk'>
<driver name='qemu' type='%s'/>