[blivet][master/rhel7-branch] Add two functions to enable manual addition of ECKD DASDs. (#1070115)
Vratislav Podzimek
vpodzime at redhat.com
Fri Aug 29 07:01:14 UTC 2014
On Thu, 2014-08-28 at 15:18 -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 an appropriate match against DASD device number
> formats.
>
> online_dasd takes a device number as a string and will remove the device
> from the ignore list and attempt to bring it online.
>
> Resolves: rhbz#1070115
> ---
> blivet/devicelibs/dasd.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 44 insertions(+)
>
> diff --git a/blivet/devicelibs/dasd.py b/blivet/devicelibs/dasd.py
> index 5beb11d..4cbdaf3 100644
> --- a/blivet/devicelibs/dasd.py
> +++ b/blivet/devicelibs/dasd.py
> @@ -20,6 +20,7 @@
> #
>
> import os
> +import string
> from blivet.errors import DasdFormatError
> from blivet.devices import deviceNameToDiskByPath
> from blivet import util
> @@ -109,6 +110,49 @@ 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.
> + """
> + 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[:string.rfind(dev, ".") + 1]
> + dev = dev[string.rfind(dev, ".") + 1:]
You don't need to import and use the string module, 'dev.rfind()' would
do.
> + dev = "0" * (4 - len(dev)) + dev
> + if not len(bus):
'if not bus:' would be nicer here.
> + return "0.0." + dev
> + else:
> + return bus + dev
> +
> +def online_dasd(dev):
> + """ Given a device number of format 0.0.abcd, switch the device to be
> + online.
> + """
> + online = "/sys/bus/ccw/drivers/dasd-eckd/%s/online" % (dev)
> +
> + if not os.path.exists(online):
> + log.info("Freeing DASD device %s" % (dev,))
We now use 'log.info("some str", arg1, arg2, ...)' in logging functions.
> + 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))
The parantheses around 'dev' can be dropped here.
> +
> + try:
> + f = open(online, "r")
> + devonline = f.readline().strip()
> + f.close()
> + if devonline == "1":
> + raise ValueError("Device %s is already online." % (dev))
> + else:
> + f = open(online, "w")
> + 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).") \
> + % {'devnum': dev, 'e': e}
I'm pretty sure you meant 'dev' ^here.
--
Vratislav Podzimek
Anaconda Rider | RHCE | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list