mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-24 02:04:13 +03:00
diskbackend: Check if the passed path is a url
This commit is contained in:
parent
c5ccd68e4d
commit
1c79b936f5
@ -515,7 +515,7 @@ class VirtualDisk(VirtualDevice):
|
||||
if xmlpath:
|
||||
return xmlpath
|
||||
|
||||
self._storage_backend = self._make_default_storage_backend()
|
||||
self._set_default_storage_backend()
|
||||
return self._storage_backend.path
|
||||
def _set_path(self, val):
|
||||
if (self._storage_backend and
|
||||
@ -717,7 +717,7 @@ class VirtualDisk(VirtualDevice):
|
||||
# Validation assistance methods #
|
||||
#################################
|
||||
|
||||
def _make_default_storage_backend(self):
|
||||
def _set_default_storage_backend(self):
|
||||
path = None
|
||||
vol_object = None
|
||||
parent_pool = None
|
||||
@ -749,8 +749,7 @@ class VirtualDisk(VirtualDevice):
|
||||
if vol_object is None and path is None:
|
||||
path = self._get_xmlpath()
|
||||
|
||||
return diskbackend.StorageBackend(self.conn, path,
|
||||
vol_object, parent_pool, is_network=is_network)
|
||||
self._change_backend(path, vol_object, parent_pool)
|
||||
|
||||
def set_local_disk_to_clone(self, disk, sparse):
|
||||
"""
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import statvfs
|
||||
|
||||
import libvirt
|
||||
@ -151,6 +152,15 @@ def manage_path(conn, path):
|
||||
return vol, pool
|
||||
|
||||
|
||||
def path_is_url(path):
|
||||
"""
|
||||
Detect if path is a URL
|
||||
"""
|
||||
if not path:
|
||||
return False
|
||||
return bool(re.match("[a-zA-Z]+(\+[a-zA-Z]+)?://.*", path))
|
||||
|
||||
|
||||
##############################################
|
||||
# Classes for tracking storage media details #
|
||||
##############################################
|
||||
@ -411,14 +421,12 @@ class StorageBackend(_StorageBase):
|
||||
Class that carries all the info about any existing storage that
|
||||
the disk references
|
||||
"""
|
||||
def __init__(self, conn, path, vol_object, parent_pool,
|
||||
is_network=False):
|
||||
def __init__(self, conn, path, vol_object, parent_pool):
|
||||
_StorageBase.__init__(self, conn)
|
||||
|
||||
self._vol_object = vol_object
|
||||
self._parent_pool = parent_pool
|
||||
self._path = path
|
||||
self._is_network = is_network
|
||||
|
||||
if self._vol_object is not None:
|
||||
self._path = None
|
||||
@ -440,6 +448,10 @@ class StorageBackend(_StorageBase):
|
||||
parsexml=self._vol_object.XMLDesc(0))
|
||||
return self._vol_xml
|
||||
|
||||
def _is_network(self):
|
||||
if self._path:
|
||||
return path_is_url(self._path)
|
||||
return False
|
||||
|
||||
##############
|
||||
# Public API #
|
||||
@ -477,13 +489,13 @@ class StorageBackend(_StorageBase):
|
||||
self._exists = True
|
||||
elif self._vol_object:
|
||||
self._exists = True
|
||||
elif (not self._is_network and
|
||||
elif (not self._is_network() and
|
||||
not self._conn.is_remote() and
|
||||
os.path.exists(self._path)):
|
||||
self._exists = True
|
||||
elif self._parent_pool:
|
||||
self._exists = False
|
||||
elif self._is_network:
|
||||
elif self._is_network():
|
||||
self._exists = True
|
||||
elif (self._conn.is_remote() and
|
||||
not _can_auto_manage(self._path)):
|
||||
@ -510,7 +522,7 @@ class StorageBackend(_StorageBase):
|
||||
else:
|
||||
self._dev_type = "file"
|
||||
|
||||
elif (not self._is_network and
|
||||
elif (not self._is_network() and
|
||||
self._path and
|
||||
not self._conn.is_remote()):
|
||||
if os.path.isdir(self._path):
|
||||
|
Loading…
x
Reference in New Issue
Block a user