On Tue, 2014-09-02 at 08:39 -0400, Samantha N. Bueno wrote:
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"))
'if not dev' would be an equivalent condition here, right? Choose what looks better to you. :)
- 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()
You don't have to close the file when using the 'with' block.
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()
Same here.