[blivet][master/rhel7-branch] Add two functions to enable manual addition of ECKD DASDs. (#1070115)
Samantha N. Bueno
sbueno+anaconda at redhat.com
Tue Sep 2 12:39:55 UTC 2014
This just adds a couple of functions which aid in manually adding DASDs.
sanitize_dasd_dev_input takes a device number as a string and verifies
whether its format is acceptable as a match against DASD device numbers.
online_dasd takes a device number as a string and fill remove the device
from the ignore list and attempt to bring it online.
Resolves: rhbz#1070115
---
blivet/devicelibs/dasd.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/blivet/devicelibs/dasd.py b/blivet/devicelibs/dasd.py
index 5beb11d..5072c0a 100644
--- a/blivet/devicelibs/dasd.py
+++ b/blivet/devicelibs/dasd.py
@@ -109,6 +109,55 @@ def dasd_needs_format(dasd):
return False
+def sanitize_dasd_dev_input(dev):
+ """ Given a user-supplied device number, make sure the input is sane, and
+ raise an error if it is not.
+
+ :param dev: string representing a DASD device number
+ """
+ if dev is None or dev == "":
+ raise ValueError(_("You have not specified a device number or the number is invalid"))
+ dev = dev.lower()
+ bus = dev[:dev.rfind(".") + 1]
+ dev = dev[dev.rfind(".") + 1:]
+
+ dev = "0" * (4 - len(dev)) + dev
+ if not bus:
+ return "0.0." + dev
+ else:
+ return bus + dev
+
+def online_dasd(dev):
+ """ Given a device number, switch the device to be online.
+
+ :param dev: string representing a DASD device number; acceptable formats
+ include 0.0.abcd, 0.0.ABCD, abcd, ABCD, where 'abcd' are
+ hexadecimal numbers.
+ """
+ online = "/sys/bus/ccw/drivers/dasd-eckd/%s/online" % (dev)
+
+ if not os.path.exists(online):
+ log.info("Freeing DASD device %s" % dev)
+ util.run_program(["dasd_cio_free", "-d", dev])
+
+ if not os.path.exists(online):
+ raise ValueError(_("DASD device %s not found, not even in device ignore list.")
+ % dev)
+
+ try:
+ with open(online, "r") as f:
+ devonline = f.readline().strip()
+ f.close()
+ if devonline == "1":
+ raise ValueError(_("Device %s is already online.") % dev)
+ else:
+ with open(online, "w") as f:
+ log.debug("echo %s > %s" % ("1", online))
+ f.write("%s\n" % ("1"))
+ f.close()
+ except IOError as e:
+ raise ValueError(_("Could not set DASD device %(dev)s online (%(e)s).") \
+ % {'dev': dev, 'e': e})
def write_dasd_conf(disks, root):
""" Write /etc/dasd.conf to target system for all DASD devices
--
1.9.3
More information about the anaconda-patches
mailing list