1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-01-12 16:35:17 +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): def get_rbd_storage_data(stg):
xml = stg.XMLDesc(0) xml = stg.XMLDesc(0)
ceph_user = util.get_xml_path(xml, "/pool/source/auth/@username") 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") def get_ceph_hosts(ctx):
return ceph_user, secrt_uuid, ceph_host 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): class wvmCreate(wvmConnect):
@ -162,15 +170,23 @@ class wvmCreate(wvmConnect):
stg_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type") stg_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
if stg_type == 'rbd': 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'> xml += """<disk type='network' device='disk'>
<driver name='qemu' type='%s'/> <driver name='qemu' type='%s'/>
<auth username='%s'> <auth username='%s'>
<secret type='ceph' uuid='%s'/> <secret type='ceph' uuid='%s'/>
</auth> </auth>
<source protocol='rbd' name='%s'> <source protocol='rbd' name='%s'>""" % (img_type, ceph_user, secret_uuid, image)
<host name='%s' port='6789'/> if isinstance(ceph_hosts, list):
</source>""" % (img_type, ceph_user, secrt_uuid, image, ceph_host) 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: else:
xml += """<disk type='file' device='disk'> xml += """<disk type='file' device='disk'>
<driver name='qemu' type='%s'/> <driver name='qemu' type='%s'/>