mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
virt-install: Wire up --disk vol= for network volumes
This involves convering pool/vol XML to disk source bits
This commit is contained in:
parent
214872498d
commit
464ebabc5a
@ -90,7 +90,7 @@
|
||||
<target dev="sdc" bus="scsi"/>
|
||||
</disk>
|
||||
<disk type="network" device="disk">
|
||||
<source protocol="gluster" name="/test-volume/test-gluster.qcow2">
|
||||
<source protocol="gluster" name="test-volume/test-gluster.qcow2">
|
||||
<host name="192.168.1.100"/>
|
||||
</source>
|
||||
<target dev="sdd" bus="scsi"/>
|
||||
@ -102,11 +102,17 @@
|
||||
<target dev="sde" bus="scsi"/>
|
||||
</disk>
|
||||
<disk type="network" device="disk">
|
||||
<source protocol="http" name="/my/path">
|
||||
<source protocol="http" name="my/path">
|
||||
<host name="1:2:3:4:1:2:3:4" port="5522"/>
|
||||
</source>
|
||||
<target dev="sdf" bus="scsi"/>
|
||||
</disk>
|
||||
<disk type="network" device="disk">
|
||||
<source protocol="gluster" name="test-volume/test-gluster.raw">
|
||||
<host name="192.168.1.100"/>
|
||||
</source>
|
||||
<target dev="sdg" bus="scsi"/>
|
||||
</disk>
|
||||
<controller type="usb" index="0" model="ich9-ehci1">
|
||||
<address type="pci" domain="0" bus="0" slot="4" function="7"/>
|
||||
</controller>
|
||||
@ -269,7 +275,7 @@
|
||||
<target dev="sdc" bus="scsi"/>
|
||||
</disk>
|
||||
<disk type="network" device="disk">
|
||||
<source protocol="gluster" name="/test-volume/test-gluster.qcow2">
|
||||
<source protocol="gluster" name="test-volume/test-gluster.qcow2">
|
||||
<host name="192.168.1.100"/>
|
||||
</source>
|
||||
<target dev="sdd" bus="scsi"/>
|
||||
@ -281,11 +287,17 @@
|
||||
<target dev="sde" bus="scsi"/>
|
||||
</disk>
|
||||
<disk type="network" device="disk">
|
||||
<source protocol="http" name="/my/path">
|
||||
<source protocol="http" name="my/path">
|
||||
<host name="1:2:3:4:1:2:3:4" port="5522"/>
|
||||
</source>
|
||||
<target dev="sdf" bus="scsi"/>
|
||||
</disk>
|
||||
<disk type="network" device="disk">
|
||||
<source protocol="gluster" name="test-volume/test-gluster.raw">
|
||||
<host name="192.168.1.100"/>
|
||||
</source>
|
||||
<target dev="sdg" bus="scsi"/>
|
||||
</disk>
|
||||
<controller type="usb" index="0" model="ich9-ehci1">
|
||||
<address type="pci" domain="0" bus="0" slot="4" function="7"/>
|
||||
</controller>
|
||||
|
@ -561,6 +561,7 @@ c.add_compare("""--hvm --pxe \
|
||||
--disk gluster://192.168.1.100/test-volume/test-gluster.qcow2,bus=scsi \
|
||||
--disk qemu+nbd:///var/foo/bar/socket,bus=scsi \
|
||||
--disk path=http://[1:2:3:4:1:2:3:4]:5522/my/path?query=foo,bus=scsi \
|
||||
--disk vol=gluster-pool/test-gluster.raw,bus=scsi \
|
||||
--serial tcp,host=:2222,mode=bind,protocol=telnet \
|
||||
--filesystem /source,/target,mode=squash \
|
||||
--network user,mac=12:34:56:78:11:22,portgroup=foo \
|
||||
|
@ -39,7 +39,7 @@
|
||||
<disk type="network" device="cdrom">
|
||||
<target dev="sda" bus="scsi"/>
|
||||
<readonly/>
|
||||
<source protocol="http" name="/my/file">
|
||||
<source protocol="http" name="my/file">
|
||||
<host name="1:2:3:4:5:6:7:8" port="1122"/>
|
||||
</source>
|
||||
</disk>
|
||||
|
@ -605,7 +605,7 @@ class VirtualDisk(VirtualDevice):
|
||||
source_host_transport = XMLProperty("./source/host/@transport")
|
||||
source_host_socket = XMLProperty("./source/host/@socket")
|
||||
|
||||
def _set_source_from_url(self, uri):
|
||||
def _set_source_network_from_url(self, uri):
|
||||
uriinfo = URISplit(uri)
|
||||
if uriinfo.scheme:
|
||||
self.source_protocol = uriinfo.scheme
|
||||
@ -620,6 +620,29 @@ class VirtualDisk(VirtualDevice):
|
||||
self.source_host_socket = uriinfo.path
|
||||
else:
|
||||
self.source_name = uriinfo.path
|
||||
if self.source_name.startswith("/"):
|
||||
self.source_name = self.source_name[1:]
|
||||
|
||||
def _set_source_network_from_storage(self, volxml, poolxml):
|
||||
self.source_protocol = poolxml.type
|
||||
if poolxml.hosts:
|
||||
self.source_host_name = poolxml.hosts[0].name
|
||||
self.source_host_port = poolxml.hosts[0].port
|
||||
|
||||
path = ""
|
||||
if poolxml.source_name:
|
||||
path += poolxml.source_name + "/"
|
||||
path += volxml.name
|
||||
self.source_name = path
|
||||
|
||||
def _set_network_source_from_backend(self):
|
||||
if (self._storage_backend.get_vol_object() or
|
||||
self._storage_backend.get_vol_install()):
|
||||
volxml = self._storage_backend.get_vol_xml()
|
||||
poolxml = self._storage_backend.get_parent_pool_xml()
|
||||
self._set_source_network_from_storage(volxml, poolxml)
|
||||
elif self._storage_backend.get_path():
|
||||
self._set_source_network_from_url(self._storage_backend.get_path())
|
||||
|
||||
def _build_url_from_network_source(self):
|
||||
ret = self.source_protocol
|
||||
@ -692,7 +715,7 @@ class VirtualDisk(VirtualDevice):
|
||||
self._clear_source_xml()
|
||||
|
||||
if self._storage_backend.get_dev_type() == "network":
|
||||
self._set_source_from_url(val)
|
||||
self._set_network_source_from_backend()
|
||||
return
|
||||
|
||||
propname = self._disk_type_to_object_prop_name()
|
||||
|
@ -171,6 +171,7 @@ class _StorageBase(object):
|
||||
"""
|
||||
def __init__(self, conn):
|
||||
self._conn = conn
|
||||
self._parent_pool_xml = None
|
||||
|
||||
def get_size(self):
|
||||
raise NotImplementedError()
|
||||
@ -182,6 +183,13 @@ class _StorageBase(object):
|
||||
raise NotImplementedError()
|
||||
def get_vol_object(self):
|
||||
raise NotImplementedError()
|
||||
def get_parent_pool(self):
|
||||
raise NotImplementedError()
|
||||
def get_parent_pool_xml(self):
|
||||
if not self._parent_pool_xml and self.get_parent_pool():
|
||||
self._parent_pool_xml = StoragePool(self._conn,
|
||||
parsexml=self.get_parent_pool().XMLDesc(0))
|
||||
return self._parent_pool_xml
|
||||
def validate(self, disk):
|
||||
raise NotImplementedError()
|
||||
def get_path(self):
|
||||
@ -275,6 +283,8 @@ class _StorageCreator(_StorageBase):
|
||||
return True
|
||||
def get_vol_object(self):
|
||||
return None
|
||||
def get_vol_xml(self):
|
||||
return None
|
||||
def get_parent_pool(self):
|
||||
if self._vol_install:
|
||||
return self._vol_install.pool
|
||||
@ -438,35 +448,30 @@ class StorageBackend(_StorageBase):
|
||||
|
||||
# Cached bits
|
||||
self._vol_xml = None
|
||||
self._parent_pool_xml = None
|
||||
self._exists = None
|
||||
self._size = None
|
||||
self._dev_type = None
|
||||
|
||||
|
||||
################
|
||||
# Internal API #
|
||||
################
|
||||
|
||||
def _get_vol_xml(self):
|
||||
if self._vol_xml is None:
|
||||
self._vol_xml = StorageVolume(self._conn,
|
||||
parsexml=self._vol_object.XMLDesc(0))
|
||||
return self._vol_xml
|
||||
|
||||
##############
|
||||
# Public API #
|
||||
##############
|
||||
|
||||
def get_path(self):
|
||||
if self._vol_object:
|
||||
return self._get_vol_xml().target_path
|
||||
return self.get_vol_xml().target_path
|
||||
return self._path
|
||||
|
||||
def get_vol_object(self):
|
||||
return self._vol_object
|
||||
def get_vol_xml(self):
|
||||
if self._vol_xml is None:
|
||||
self._vol_xml = StorageVolume(self._conn,
|
||||
parsexml=self._vol_object.XMLDesc(0))
|
||||
return self._vol_xml
|
||||
|
||||
def get_parent_pool(self):
|
||||
if not self._parent_pool and self._vol_object:
|
||||
self._parent_pool = self._vol_object.storagePoolLookupByVolume()
|
||||
return self._parent_pool
|
||||
|
||||
def get_size(self):
|
||||
@ -476,7 +481,7 @@ class StorageBackend(_StorageBase):
|
||||
if self._size is None:
|
||||
ret = 0
|
||||
if self._vol_object:
|
||||
ret = self._get_vol_xml().capacity
|
||||
ret = self.get_vol_xml().capacity
|
||||
elif self._path:
|
||||
ignore, ret = util.stat_disk(self._path)
|
||||
self._size = (float(ret) / 1024.0 / 1024.0 / 1024.0)
|
||||
@ -513,8 +518,8 @@ class StorageBackend(_StorageBase):
|
||||
"""
|
||||
if self._dev_type is None:
|
||||
if self._vol_object:
|
||||
if self._get_vol_xml().type:
|
||||
self._dev_type = self._get_vol_xml().type
|
||||
if self.get_vol_xml().type:
|
||||
self._dev_type = self.get_vol_xml().type
|
||||
else:
|
||||
t = self._vol_object.info()[0]
|
||||
if t == StorageVolume.TYPE_FILE:
|
||||
@ -543,7 +548,7 @@ class StorageBackend(_StorageBase):
|
||||
|
||||
def get_driver_type(self):
|
||||
if self._vol_object:
|
||||
return self._get_vol_xml().format
|
||||
return self.get_vol_xml().format
|
||||
return None
|
||||
|
||||
def validate(self, disk):
|
||||
|
Loading…
Reference in New Issue
Block a user