From: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
When we only supportted cdrom attachment, we check if a cdrom is
a valid block device by reading /proc info.
Now we added disk attachment support, when a file is neither regular file
nor url, we need to see if it is a block device according to its stats.
Signed-off-by: Royce Lv <lvroyce(a)linux.vnet.ibm.com>
---
src/kimchi/model/vmstorages.py | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/src/kimchi/model/vmstorages.py b/src/kimchi/model/vmstorages.py
index 91c2ab8..f11bcec 100644
--- a/src/kimchi/model/vmstorages.py
+++ b/src/kimchi/model/vmstorages.py
@@ -20,6 +20,7 @@
import os
import re
import socket
+import stat
import string
import urlparse
@@ -90,16 +91,8 @@ def _check_path(path):
if os.path.isfile(path):
src_type = 'file'
else:
- # Check if path is a valid cdrom drive
- with open('/proc/sys/dev/cdrom/info') as cdinfo:
- content = cdinfo.read()
-
- cds = re.findall("drive name:\t\t(.*)", content)
- if not cds:
- raise InvalidParameter("KCHVMSTOR0003E", {'value':
path})
-
- drives = [os.path.join('/dev', p) for p in
cds[0].split('\t')]
- if path not in drives:
+ r_path = os.path.realpath(path)
+ if not stat.S_ISBLK(os.stat(r_path).st_mode):
raise InvalidParameter("KCHVMSTOR0003E", {'value':
path})
src_type = 'block'
--
1.8.3.2