Skip to content
Snippets Groups Projects
Commit d1687c6f authored by Iustin Pop's avatar Iustin Pop
Browse files

lvmstrap: allow removable devices too

For testing or just in case a device is exported by a bad driver with
the 'removable' flag set, this patch adds a flag to lvmstrap that allows
it to use these devices too.

Reviewed-by: ultrotter
parent 216842d7
No related branches found
No related tags found
No related merge requests found
...@@ -47,8 +47,9 @@ import time ...@@ -47,8 +47,9 @@ import time
from ganeti.utils import RunCmd from ganeti.utils import RunCmd
from ganeti import constants from ganeti import constants
USAGE = ("\tlvmstrap.py diskinfo\n" USAGE = ("\tlvmstrap diskinfo\n"
"\tlvmstrap.py [--vgname=NAME] { --alldisks | --disks DISKLIST }" "\tlvmstrap [--vgname=NAME] [--allow-removable]"
" { --alldisks | --disks DISKLIST }"
" create") " create")
verbose_flag = False verbose_flag = False
...@@ -143,6 +144,9 @@ def ParseOptions(): ...@@ -143,6 +144,9 @@ def ParseOptions():
parser.add_option("-v", "--verbose", parser.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=False, action="store_true", dest="verbose", default=False,
help="print command execution messages to stdout") help="print command execution messages to stdout")
parser.add_option("-r", "--allow-removable",
action="store_true", dest="removable_ok", default=False,
help="allow and use removable devices too")
parser.add_option("-g", "--vg-name", type="string", parser.add_option("-g", "--vg-name", type="string",
dest="vgname", default="xenvg", metavar="NAME", dest="vgname", default="xenvg", metavar="NAME",
help="the volume group to be created [default: xenvg]") help="the volume group to be created [default: xenvg]")
...@@ -353,7 +357,7 @@ def ReadPV(name): ...@@ -353,7 +357,7 @@ def ReadPV(name):
return vgname return vgname
def GetDiskList(): def GetDiskList(opts):
"""Computes the block device list for this system. """Computes the block device list for this system.
This function examines the /sys/block tree and using information This function examines the /sys/block tree and using information
...@@ -386,7 +390,7 @@ def GetDiskList(): ...@@ -386,7 +390,7 @@ def GetDiskList():
removable = int(f.read().strip()) removable = int(f.read().strip())
f.close() f.close()
if removable: if removable and not opts.removable_ok:
continue continue
dev = ReadDev("/sys/block/%s" % name) dev = ReadDev("/sys/block/%s" % name)
...@@ -471,7 +475,7 @@ def DevInfo(name, dev, mountinfo): ...@@ -471,7 +475,7 @@ def DevInfo(name, dev, mountinfo):
return mpath, whatvg, fileinfo return mpath, whatvg, fileinfo
def ShowDiskInfo(): def ShowDiskInfo(opts):
"""Shows a nicely formatted block device list for this system. """Shows a nicely formatted block device list for this system.
This function shows the user a table with the informations gathered This function shows the user a table with the informations gathered
...@@ -480,7 +484,7 @@ def ShowDiskInfo(): ...@@ -480,7 +484,7 @@ def ShowDiskInfo():
""" """
mounts = GetMountInfo() mounts = GetMountInfo()
dlist = GetDiskList() dlist = GetDiskList(opts)
print "------- Disk information -------" print "------- Disk information -------"
print ("%5s %7s %4s %5s %-10s %s" % print ("%5s %7s %4s %5s %-10s %s" %
...@@ -650,7 +654,7 @@ def ValidateDiskList(options): ...@@ -650,7 +654,7 @@ def ValidateDiskList(options):
a list of disk names, e.g. ['sda', 'sdb'] a list of disk names, e.g. ['sda', 'sdb']
""" """
sysdisks = GetDiskList() sysdisks = GetDiskList(options)
if not sysdisks: if not sysdisks:
raise PrereqError("no disks found (I looked for" raise PrereqError("no disks found (I looked for"
" non-removable block devices).") " non-removable block devices).")
...@@ -689,7 +693,7 @@ def BootStrap(): ...@@ -689,7 +693,7 @@ def BootStrap():
vgname = options.vgname vgname = options.vgname
command = args.pop(0) command = args.pop(0)
if command == "diskinfo": if command == "diskinfo":
ShowDiskInfo() ShowDiskInfo(options)
return return
if command != "create": if command != "create":
Usage() Usage()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment