Commit 8d1a2a64 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Move cmdlib._HasValidVG to utils.CheckVolumeGroupSize

This is required for splitting the cluster initialization code.

Reviewed-by: iustinp
parent d9c02ca6
...@@ -305,22 +305,6 @@ def _BuildInstanceHookEnvByObject(instance, override=None): ...@@ -305,22 +305,6 @@ def _BuildInstanceHookEnvByObject(instance, override=None):
return _BuildInstanceHookEnv(**args) return _BuildInstanceHookEnv(**args)
def _HasValidVG(vglist, vgname):
"""Checks if the volume group list is valid.
A non-None return value means there's an error, and the return value
is the error message.
"""
vgsize = vglist.get(vgname, None)
if vgsize is None:
return "volume group '%s' missing" % vgname
elif vgsize < 20480:
return ("volume group '%s' too small (20480MiB required, %dMib found)" %
(vgname, vgsize))
return None
def _InitSSHSetup(node): def _InitSSHSetup(node):
"""Setup the SSH configuration for the cluster. """Setup the SSH configuration for the cluster.
...@@ -465,7 +449,8 @@ class LUInitCluster(LogicalUnit): ...@@ -465,7 +449,8 @@ class LUInitCluster(LogicalUnit):
self.op.vg_name = None self.op.vg_name = None
# if vg_name not None, checks if volume group is valid # if vg_name not None, checks if volume group is valid
if self.op.vg_name: if self.op.vg_name:
vgstatus = _HasValidVG(utils.ListVolumeGroups(), self.op.vg_name) vgstatus = utils.CheckVolumeGroupSize(utils.ListVolumeGroups(), vg_name,
constants.MIN_VG_SIZE)
if vgstatus: if vgstatus:
raise errors.OpPrereqError("Error: %s\nspecify --no-lvm-storage if" raise errors.OpPrereqError("Error: %s\nspecify --no-lvm-storage if"
" you are not using lvm" % vgstatus) " you are not using lvm" % vgstatus)
...@@ -632,7 +617,8 @@ class LUVerifyCluster(LogicalUnit): ...@@ -632,7 +617,8 @@ class LUVerifyCluster(LogicalUnit):
(node,)) (node,))
bad = True bad = True
else: else:
vgstatus = _HasValidVG(vglist, self.cfg.GetVGName()) vgstatus = utils.CheckVolumeGroupSize(vglist, self.cfg.GetVGName(),
constants.MIN_VG_SIZE)
if vgstatus: if vgstatus:
feedback_fn(" - ERROR: %s on node %s" % (vgstatus, node)) feedback_fn(" - ERROR: %s on node %s" % (vgstatus, node))
bad = True bad = True
...@@ -1211,7 +1197,8 @@ class LUSetClusterParams(LogicalUnit): ...@@ -1211,7 +1197,8 @@ class LUSetClusterParams(LogicalUnit):
node_list = self.cfg.GetNodeList() node_list = self.cfg.GetNodeList()
vglist = rpc.call_vg_list(node_list) vglist = rpc.call_vg_list(node_list)
for node in node_list: for node in node_list:
vgstatus = _HasValidVG(vglist[node], self.op.vg_name) vgstatus = utils.CheckVolumeGroupSize(vglist[node], self.op.vg_name,
constants.MIN_VG_SIZE)
if vgstatus: if vgstatus:
raise errors.OpPrereqError("Error on node '%s': %s" % raise errors.OpPrereqError("Error on node '%s': %s" %
(node, vgstatus)) (node, vgstatus))
......
...@@ -161,6 +161,7 @@ TCP_PING_TIMEOUT = 10 ...@@ -161,6 +161,7 @@ TCP_PING_TIMEOUT = 10
GANETI_RUNAS = "root" GANETI_RUNAS = "root"
DEFAULT_VG = "xenvg" DEFAULT_VG = "xenvg"
BIND_ADDRESS_GLOBAL = "0.0.0.0" BIND_ADDRESS_GLOBAL = "0.0.0.0"
MIN_VG_SIZE = 20480
# valid os status # valid os status
OS_VALID_STATUS = "VALID" OS_VALID_STATUS = "VALID"
......
...@@ -1130,3 +1130,19 @@ def FindFile(name, search_path, test=os.path.exists): ...@@ -1130,3 +1130,19 @@ def FindFile(name, search_path, test=os.path.exists):
if test(item_name): if test(item_name):
return item_name return item_name
return None return None
def CheckVolumeGroupSize(vglist, vgname, minsize):
"""Checks if the volume group list is valid.
A non-None return value means there's an error, and the return value
is the error message.
"""
vgsize = vglist.get(vgname, None)
if vgsize is None:
return "volume group '%s' missing" % vgname
elif vgsize < minsize:
return ("volume group '%s' too small (%s MiB required, %d MiB found)" %
(vgname, minsize, vgsize))
return None
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment