Commit cd3b4ff4 authored by Helga Velroyen's avatar Helga Velroyen

Replace LD_* constants with DT_* constants

LD_* constants are basically like DT_* constants, except
for that both file and shared file were mapped to file.
In order to not having to maintain three slightly different
sets of disk-related constants (DT, LD and ST), we merge
DT and LD here. This patch does the renaming of the
various constants and then fixes the handling of shared
file disks.
Signed-off-by: default avatarHelga Velroyen <helgav@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 2de59e2c
......@@ -895,7 +895,7 @@ Beside the per-hypervisor attributes, we also have disk attributes,
which are queried directly on the node (without hypervisor
involvment). The are stored in a separate attribute (``disk_state``),
which is indexed per storage type and name; currently this will be just
``LD_LV`` and the volume name as key.
``DT_PLAIN`` and the volume name as key.
+-------------+-------------------------+--------------------+--------+
|Name |Description |Current state |Type |
......
......@@ -2845,9 +2845,9 @@ def OSEnvironment(instance, inst_os, debug=0):
if constants.HV_DISK_TYPE in instance.hvparams:
result["DISK_%d_FRONTEND_TYPE" % idx] = \
instance.hvparams[constants.HV_DISK_TYPE]
if disk.dev_type in constants.LDS_BLOCK:
if disk.dev_type in constants.DTS_BLOCK:
result["DISK_%d_BACKEND_TYPE" % idx] = "block"
elif disk.dev_type == constants.LD_FILE:
elif disk.dev_type in [constants.DT_FILE, constants.DT_SHARED_FILE]:
result["DISK_%d_BACKEND_TYPE" % idx] = \
"file:%s" % disk.physical_id[0]
......@@ -2969,12 +2969,12 @@ def BlockdevSnapshot(disk):
@return: snapshot disk ID as (vg, lv)
"""
if disk.dev_type == constants.LD_DRBD8:
if disk.dev_type == constants.DT_DRBD8:
if not disk.children:
_Fail("DRBD device '%s' without backing storage cannot be snapshotted",
disk.unique_id)
return BlockdevSnapshot(disk.children[0])
elif disk.dev_type == constants.LD_LV:
elif disk.dev_type == constants.DT_PLAIN:
r_dev = _RecursiveFindBD(disk)
if r_dev is not None:
# FIXME: choose a saner value for the snapshot size
......
......@@ -919,7 +919,7 @@ def _FormatDiskDetails(dev_type, dev, roman):
"""Formats the logical_id of a disk.
"""
if dev_type == constants.LD_DRBD8:
if dev_type == constants.DT_DRBD8:
drbd_info = dev["drbd_info"]
data = [
("nodeA", "%s, minor=%s" %
......@@ -933,7 +933,7 @@ def _FormatDiskDetails(dev_type, dev, roman):
("port", str(compat.TryToRoman(drbd_info["port"], convert=roman))),
("auth key", str(drbd_info["secret"])),
]
elif dev_type == constants.LD_LV:
elif dev_type == constants.DT_PLAIN:
vg_name, lv_name = dev["logical_id"]
data = ["%s/%s" % (vg_name, lv_name)]
else:
......@@ -968,7 +968,7 @@ def _FormatBlockDevInfo(idx, top_level, dev, roman):
"""Format one line for physical device status.
@type dtype: str
@param dtype: a constant from the L{constants.LDS_BLOCK} set
@param dtype: a constant from the L{constants.DTS_BLOCK} set
@type status: tuple
@param status: a tuple as returned from L{backend.FindBlockDevice}
@return: the string representing the status
......@@ -989,7 +989,7 @@ def _FormatBlockDevInfo(idx, top_level, dev, roman):
minor_string = str(compat.TryToRoman(minor, convert=roman))
txt += ("%s (%s:%s)" % (path, major_string, minor_string))
if dtype in (constants.LD_DRBD8, ):
if dtype in (constants.DT_DRBD8, ):
if syncp is not None:
sync_text = "*RECOVERING* %5.2f%%," % syncp
if estt:
......@@ -1009,7 +1009,7 @@ def _FormatBlockDevInfo(idx, top_level, dev, roman):
else:
ldisk_text = ""
txt += (" %s, status %s%s" % (sync_text, degr_text, ldisk_text))
elif dtype == constants.LD_LV:
elif dtype == constants.DT_PLAIN:
if ldisk_status == constants.LDS_FAULTY:
ldisk_text = " *FAILED* (failed drive?)"
else:
......
......@@ -341,7 +341,7 @@ class LUBackupExport(LogicalUnit):
# instance disk type verification
# TODO: Implement export support for file-based disks
for disk in self.instance.disks:
if disk.dev_type == constants.LD_FILE:
if disk.dev_type in [constants.DT_FILE, constants.DT_SHARED_FILE]:
raise errors.OpPrereqError("Export not supported for instances with"
" file-based disks", errors.ECODE_INVAL)
......
......@@ -495,7 +495,7 @@ class LUClusterRepairDiskSizes(NoHooksLU):
@param disk: an L{ganeti.objects.Disk} object
"""
if disk.dev_type == constants.LD_DRBD8:
if disk.dev_type == constants.DT_DRBD8:
assert disk.children, "Empty children for DRBD8?"
fchild = disk.children[0]
mismatch = fchild.size < disk.size
......@@ -757,7 +757,7 @@ class LUClusterSetParams(LogicalUnit):
" enabling lvm-based disk-templates.")
if self.op.vg_name is not None and not self.op.vg_name:
if self.cfg.HasAnyDiskOfType(constants.LD_LV):
if self.cfg.HasAnyDiskOfType(constants.DT_PLAIN):
raise errors.OpPrereqError("Cannot disable lvm storage while lvm-based"
" instances exist", errors.ECODE_INVAL)
......@@ -859,7 +859,7 @@ class LUClusterSetParams(LogicalUnit):
"""
if self.op.drbd_helper is not None and not self.op.drbd_helper:
if self.cfg.HasAnyDiskOfType(constants.LD_DRBD8):
if self.cfg.HasAnyDiskOfType(constants.DT_DRBD8):
raise errors.OpPrereqError("Cannot disable drbd helper while"
" drbd-based instances exist",
errors.ECODE_INVAL)
......
......@@ -1705,7 +1705,8 @@ class LUInstanceMove(LogicalUnit):
bep = self.cfg.GetClusterInfo().FillBE(self.instance)
for idx, dsk in enumerate(self.instance.disks):
if dsk.dev_type not in (constants.LD_LV, constants.LD_FILE):
if dsk.dev_type not in (constants.DT_PLAIN, constants.DT_FILE,
constants.DT_SHARED_FILE):
raise errors.OpPrereqError("Instance disk %d has a complex layout,"
" cannot copy" % idx, errors.ECODE_STATE)
......
......@@ -55,16 +55,6 @@ _DISK_TEMPLATE_NAME_PREFIX = {
}
_DISK_TEMPLATE_DEVICE_TYPE = {
constants.DT_PLAIN: constants.LD_LV,
constants.DT_FILE: constants.LD_FILE,
constants.DT_SHARED_FILE: constants.LD_FILE,
constants.DT_BLOCK: constants.LD_BLOCKDEV,
constants.DT_RBD: constants.LD_RBD,
constants.DT_EXT: constants.LD_EXT,
}
def CreateSingleBlockDev(lu, node_uuid, instance, device, info, force_open,
excl_stor):
"""Create a single block device on a given node.
......@@ -390,16 +380,16 @@ def _GenerateDRBD8Branch(lu, primary_uuid, secondary_uuid, size, vgnames, names,
port = lu.cfg.AllocatePort()
shared_secret = lu.cfg.GenerateDRBDSecret(lu.proc.GetECId())
dev_data = objects.Disk(dev_type=constants.LD_LV, size=size,
dev_data = objects.Disk(dev_type=constants.DT_PLAIN, size=size,
logical_id=(vgnames[0], names[0]),
params={})
dev_data.uuid = lu.cfg.GenerateUniqueID(lu.proc.GetECId())
dev_meta = objects.Disk(dev_type=constants.LD_LV,
dev_meta = objects.Disk(dev_type=constants.DT_PLAIN,
size=constants.DRBD_META_SIZE,
logical_id=(vgnames[1], names[1]),
params={})
dev_meta.uuid = lu.cfg.GenerateUniqueID(lu.proc.GetECId())
drbd_dev = objects.Disk(dev_type=constants.LD_DRBD8, size=size,
drbd_dev = objects.Disk(dev_type=constants.DT_DRBD8, size=size,
logical_id=(primary_uuid, secondary_uuid, port,
p_minor, s_minor,
shared_secret),
......@@ -493,7 +483,7 @@ def GenerateDiskTemplate(
else:
raise errors.ProgrammerError("Unknown disk template '%s'" % template_name)
dev_type = _DISK_TEMPLATE_DEVICE_TYPE[template_name]
dev_type = template_name
for idx, disk in enumerate(disk_info):
params = {}
......@@ -819,7 +809,7 @@ class LUInstanceRecreateDisks(LogicalUnit):
continue
# update secondaries for disks, if needed
if self.op.node_uuids and disk.dev_type == constants.LD_DRBD8:
if self.op.node_uuids and disk.dev_type == constants.DT_DRBD8:
# need to update the nodes and minors
assert len(self.op.node_uuids) == 2
assert len(disk.logical_id) == 6 # otherwise disk internals
......@@ -840,7 +830,7 @@ class LUInstanceRecreateDisks(LogicalUnit):
for idx, new_id, changes in mods:
disk = self.instance.disks[idx]
if new_id is not None:
assert disk.dev_type == constants.LD_DRBD8
assert disk.dev_type == constants.DT_DRBD8
disk.logical_id = new_id
if changes:
disk.Update(size=changes.get(constants.IDISK_SIZE, None),
......@@ -2261,11 +2251,11 @@ class TLReplaceDisks(Tasklet):
(data_disk, meta_disk) = dev.children
vg_data = data_disk.logical_id[0]
lv_data = objects.Disk(dev_type=constants.LD_LV, size=dev.size,
lv_data = objects.Disk(dev_type=constants.DT_PLAIN, size=dev.size,
logical_id=(vg_data, names[0]),
params=data_disk.params)
vg_meta = meta_disk.logical_id[0]
lv_meta = objects.Disk(dev_type=constants.LD_LV,
lv_meta = objects.Disk(dev_type=constants.DT_PLAIN,
size=constants.DRBD_META_SIZE,
logical_id=(vg_meta, names[1]),
params=meta_disk.params)
......@@ -2541,7 +2531,7 @@ class TLReplaceDisks(Tasklet):
iv_names[idx] = (dev, dev.children, new_net_id)
logging.debug("Allocated new_minor: %s, new_logical_id: %s", new_minor,
new_net_id)
new_drbd = objects.Disk(dev_type=constants.LD_DRBD8,
new_drbd = objects.Disk(dev_type=constants.DT_DRBD8,
logical_id=new_alone_id,
children=dev.children,
size=dev.size,
......
......@@ -891,7 +891,7 @@ class ConfigWriter:
if disk.logical_id is None and disk.physical_id is not None:
return
if disk.dev_type == constants.LD_DRBD8:
if disk.dev_type == constants.DT_DRBD8:
pnode, snode, port, pminor, sminor, secret = disk.logical_id
if node_uuid not in (pnode, snode):
raise errors.ConfigurationError("DRBD device not knowing node %s" %
......@@ -981,7 +981,7 @@ class ConfigWriter:
"""
def _AppendUsedMinors(get_node_name_fn, instance, disk, used):
duplicates = []
if disk.dev_type == constants.LD_DRBD8 and len(disk.logical_id) >= 5:
if disk.dev_type == constants.DT_DRBD8 and len(disk.logical_id) >= 5:
node_a, node_b, _, minor_a, minor_b = disk.logical_id[:5]
for node_uuid, minor in ((node_a, minor_a), (node_b, minor_b)):
assert node_uuid in used, \
......@@ -1570,7 +1570,7 @@ class ConfigWriter:
inst.name = new_name
for (idx, disk) in enumerate(inst.disks):
if disk.dev_type == constants.LD_FILE:
if disk.dev_type in [constants.DT_FILE, constants.DT_SHARED_FILE]:
# rename the file paths in logical and physical id
file_storage_dir = os.path.dirname(os.path.dirname(disk.logical_id[1]))
disk.logical_id = (disk.logical_id[0],
......
......@@ -564,28 +564,12 @@ DTS_NO_FREE_SPACE_CHECK = compat.UniqueFrozenset([
DT_EXT,
])
# logical disk types
LD_LV = "lvm"
LD_DRBD8 = "drbd8"
LD_FILE = "file"
LD_BLOCKDEV = "blockdev"
LD_RBD = "rbd"
LD_EXT = "ext"
LOGICAL_DISK_TYPES = compat.UniqueFrozenset([
LD_LV,
LD_DRBD8,
LD_FILE,
LD_BLOCKDEV,
LD_RBD,
LD_EXT,
])
LDS_BLOCK = compat.UniqueFrozenset([
LD_LV,
LD_DRBD8,
LD_BLOCKDEV,
LD_RBD,
LD_EXT,
DTS_BLOCK = compat.UniqueFrozenset([
DT_PLAIN,
DT_DRBD8,
DT_BLOCK,
DT_RBD,
DT_EXT,
])
# drbd constants
......@@ -623,7 +607,7 @@ FD_LOOP = "loop"
FD_BLKTAP = "blktap"
# the set of drbd-like disk types
LDS_DRBD = compat.UniqueFrozenset([LD_DRBD8])
LDS_DRBD = compat.UniqueFrozenset([DT_DRBD8])
# disk access mode
DISK_RDONLY = "ro"
......@@ -1119,7 +1103,7 @@ DSS_PARAMETER_TYPES = {
}
DSS_PARAMETERS = frozenset(DSS_PARAMETER_TYPES.keys())
DS_VALID_TYPES = compat.UniqueFrozenset([LD_LV])
DS_VALID_TYPES = compat.UniqueFrozenset([DT_PLAIN])
# Backend parameter names
BE_MEMORY = "memory" # deprecated and replaced by max and min mem
......@@ -2203,8 +2187,8 @@ NDC_GLOBALS = compat.UniqueFrozenset([
ND_EXCLUSIVE_STORAGE,
])
DISK_LD_DEFAULTS = {
LD_DRBD8: {
DISK_DT_DEFAULTS = {
DT_DRBD8: {
LDP_RESYNC_RATE: CLASSIC_DRBD_SYNC_SPEED,
LDP_BARRIERS: _autoconf.DRBD_BARRIERS,
LDP_NO_META_FLUSH: _autoconf.DRBD_NO_META_FLUSH,
......@@ -2225,24 +2209,25 @@ DISK_LD_DEFAULTS = {
LDP_MAX_RATE: CLASSIC_DRBD_SYNC_SPEED, # KiB/s
LDP_MIN_RATE: 4 * 1024, # KiB/s
},
LD_LV: {
DT_PLAIN: {
LDP_STRIPES: _autoconf.LVM_STRIPECOUNT
},
LD_FILE: {},
LD_BLOCKDEV: {},
LD_RBD: {
DT_FILE: {},
DT_SHARED_FILE: {},
DT_BLOCK: {},
DT_RBD: {
LDP_POOL: "rbd"
},
LD_EXT: {},
DT_EXT: {},
}
# readability shortcuts
_LV_DEFAULTS = DISK_LD_DEFAULTS[LD_LV]
_DRBD_DEFAULTS = DISK_LD_DEFAULTS[LD_DRBD8]
_LV_DEFAULTS = DISK_DT_DEFAULTS[DT_PLAIN]
_DRBD_DEFAULTS = DISK_DT_DEFAULTS[DT_DRBD8]
DISK_DT_DEFAULTS = {
DT_PLAIN: {
LV_STRIPES: DISK_LD_DEFAULTS[LD_LV][LDP_STRIPES],
LV_STRIPES: DISK_DT_DEFAULTS[DT_PLAIN][LDP_STRIPES],
},
DT_DRBD8: {
DRBD_RESYNC_RATE: _DRBD_DEFAULTS[LDP_RESYNC_RATE],
......@@ -2266,7 +2251,7 @@ DISK_DT_DEFAULTS = {
DT_SHARED_FILE: {},
DT_BLOCK: {},
DT_RBD: {
RBD_POOL: DISK_LD_DEFAULTS[LD_RBD][LDP_POOL]
RBD_POOL: DISK_DT_DEFAULTS[DT_RBD][LDP_POOL]
},
DT_EXT: {},
}
......
......@@ -295,7 +295,7 @@ def _GetConfigFileDiskData(block_devices, blockdev_prefix,
else:
mode = "r"
if cfdev.dev_type == constants.LD_FILE:
if cfdev.dev_type in [constants.DT_FILE, constants.DT_SHARED_FILE]:
driver = _FILE_DRIVER_MAP[cfdev.physical_id[0]]
else:
driver = "phy"
......
......@@ -1184,8 +1184,8 @@ class ExportInstanceHelper:
" result '%s'", idx, src_node, result.payload)
else:
disk_id = tuple(result.payload)
disk_params = constants.DISK_LD_DEFAULTS[constants.LD_LV].copy()
new_dev = objects.Disk(dev_type=constants.LD_LV, size=disk.size,
disk_params = constants.DISK_DT_DEFAULTS[constants.DT_PLAIN].copy()
new_dev = objects.Disk(dev_type=constants.DT_PLAIN, size=disk.size,
logical_id=disk_id, physical_id=disk_id,
iv_name=disk.iv_name,
params=disk_params)
......
......@@ -418,7 +418,7 @@ class ConfigData(ConfigObject):
def HasAnyDiskOfType(self, dev_type):
"""Check if in there is at disk of the given type in the configuration.
@type dev_type: L{constants.LDS_BLOCK}
@type dev_type: L{constants.DTS_BLOCK}
@param dev_type: the type to look for
@rtype: boolean
@return: boolean indicating if a disk of the given type was found or not
......@@ -447,7 +447,7 @@ class ConfigData(ConfigObject):
# To decide if we set an helper let's check if at least one instance has
# a DRBD disk. This does not cover all the possible scenarios but it
# gives a good approximation.
if self.HasAnyDiskOfType(constants.LD_DRBD8):
if self.HasAnyDiskOfType(constants.DT_DRBD8):
self.cluster.drbd_usermode_helper = constants.DEFAULT_DRBD_HELPER
if self.networks is None:
self.networks = {}
......@@ -511,15 +511,15 @@ class Disk(ConfigObject):
def CreateOnSecondary(self):
"""Test if this device needs to be created on a secondary node."""
return self.dev_type in (constants.LD_DRBD8, constants.LD_LV)
return self.dev_type in (constants.DT_DRBD8, constants.DT_PLAIN)
def AssembleOnSecondary(self):
"""Test if this device needs to be assembled on a secondary node."""
return self.dev_type in (constants.LD_DRBD8, constants.LD_LV)
return self.dev_type in (constants.DT_DRBD8, constants.DT_PLAIN)
def OpenOnSecondary(self):
"""Test if this device needs to be opened on a secondary node."""
return self.dev_type in (constants.LD_LV,)
return self.dev_type in (constants.DT_PLAIN,)
def StaticDevPath(self):
"""Return the device path if this device type has a static one.
......@@ -532,11 +532,11 @@ class Disk(ConfigObject):
should check that it is a valid path.
"""
if self.dev_type == constants.LD_LV:
if self.dev_type == constants.DT_PLAIN:
return "/dev/%s/%s" % (self.logical_id[0], self.logical_id[1])
elif self.dev_type == constants.LD_BLOCKDEV:
elif self.dev_type == constants.DT_BLOCK:
return self.logical_id[1]
elif self.dev_type == constants.LD_RBD:
elif self.dev_type == constants.DT_RBD:
return "/dev/%s/%s" % (self.logical_id[0], self.logical_id[1])
return None
......@@ -552,14 +552,14 @@ class Disk(ConfigObject):
-1.
"""
if self.dev_type == constants.LD_DRBD8:
if self.dev_type == constants.DT_DRBD8:
return 0
return -1
def IsBasedOnDiskType(self, dev_type):
"""Check if the disk or its children are based on the given type.
@type dev_type: L{constants.LDS_BLOCK}
@type dev_type: L{constants.DTS_BLOCK}
@param dev_type: the type to look for
@rtype: boolean
@return: boolean indicating if a device of the given type was found or not
......@@ -580,9 +580,9 @@ class Disk(ConfigObject):
devices needs to (or can) be assembled.
"""
if self.dev_type in [constants.LD_LV, constants.LD_FILE,
constants.LD_BLOCKDEV, constants.LD_RBD,
constants.LD_EXT]:
if self.dev_type in [constants.DT_PLAIN, constants.DT_FILE,
constants.DT_BLOCK, constants.DT_RBD,
constants.DT_EXT, constants.DT_SHARED_FILE]:
result = [node_uuid]
elif self.dev_type in constants.LDS_DRBD:
result = [self.logical_id[0], self.logical_id[1]]
......@@ -638,9 +638,9 @@ class Disk(ConfigObject):
@return: a dictionary of volume-groups and the required size
"""
if self.dev_type == constants.LD_LV:
if self.dev_type == constants.DT_PLAIN:
return {self.logical_id[0]: amount}
elif self.dev_type == constants.LD_DRBD8:
elif self.dev_type == constants.DT_DRBD8:
if self.children:
return self.children[0].ComputeGrowth(amount)
else:
......@@ -657,10 +657,11 @@ class Disk(ConfigObject):
actual algorithms from bdev.
"""
if self.dev_type in (constants.LD_LV, constants.LD_FILE,
constants.LD_RBD, constants.LD_EXT):
if self.dev_type in (constants.DT_PLAIN, constants.DT_FILE,
constants.DT_RBD, constants.DT_EXT,
constants.DT_SHARED_FILE):
self.size += amount
elif self.dev_type == constants.LD_DRBD8:
elif self.dev_type == constants.DT_DRBD8:
if self.children:
self.children[0].RecordGrow(amount)
self.size += amount
......@@ -672,7 +673,7 @@ class Disk(ConfigObject):
"""Apply changes to size, spindles and mode.
"""
if self.dev_type == constants.LD_DRBD8:
if self.dev_type == constants.DT_DRBD8:
if self.children:
self.children[0].Update(size=size, mode=mode)
else:
......@@ -775,7 +776,7 @@ class Disk(ConfigObject):
"""Custom str() formatter for disks.
"""
if self.dev_type == constants.LD_LV:
if self.dev_type == constants.DT_PLAIN:
val = "<LogicalVolume(/dev/%s/%s" % self.logical_id
elif self.dev_type in constants.LDS_DRBD:
node_a, node_b, port, minor_a, minor_b = self.logical_id[:5]
......@@ -851,7 +852,7 @@ class Disk(ConfigObject):
result = list()
dt_params = disk_params[disk_template]
if disk_template == constants.DT_DRBD8:
result.append(FillDict(constants.DISK_LD_DEFAULTS[constants.LD_DRBD8], {
result.append(FillDict(constants.DISK_DT_DEFAULTS[constants.DT_DRBD8], {
constants.LDP_RESYNC_RATE: dt_params[constants.DRBD_RESYNC_RATE],
constants.LDP_BARRIERS: dt_params[constants.DRBD_DISK_BARRIERS],
constants.LDP_NO_META_FLUSH: dt_params[constants.DRBD_META_BARRIERS],
......@@ -868,33 +869,33 @@ class Disk(ConfigObject):
}))
# data LV
result.append(FillDict(constants.DISK_LD_DEFAULTS[constants.LD_LV], {
result.append(FillDict(constants.DISK_DT_DEFAULTS[constants.DT_PLAIN], {
constants.LDP_STRIPES: dt_params[constants.DRBD_DATA_STRIPES],
}))
# metadata LV
result.append(FillDict(constants.DISK_LD_DEFAULTS[constants.LD_LV], {
result.append(FillDict(constants.DISK_DT_DEFAULTS[constants.DT_PLAIN], {
constants.LDP_STRIPES: dt_params[constants.DRBD_META_STRIPES],
}))
elif disk_template in (constants.DT_FILE, constants.DT_SHARED_FILE):
result.append(constants.DISK_LD_DEFAULTS[constants.LD_FILE])
result.append(constants.DISK_DT_DEFAULTS[disk_template])
elif disk_template == constants.DT_PLAIN:
result.append(FillDict(constants.DISK_LD_DEFAULTS[constants.LD_LV], {
result.append(FillDict(constants.DISK_DT_DEFAULTS[constants.DT_PLAIN], {
constants.LDP_STRIPES: dt_params[constants.LV_STRIPES],
}))
elif disk_template == constants.DT_BLOCK:
result.append(constants.DISK_LD_DEFAULTS[constants.LD_BLOCKDEV])
result.append(constants.DISK_DT_DEFAULTS[constants.DT_BLOCK])
elif disk_template == constants.DT_RBD:
result.append(FillDict(constants.DISK_LD_DEFAULTS[constants.LD_RBD], {
result.append(FillDict(constants.DISK_DT_DEFAULTS[constants.DT_RBD], {
constants.LDP_POOL: dt_params[constants.RBD_POOL],
}))
elif disk_template == constants.DT_EXT:
result.append(constants.DISK_LD_DEFAULTS[constants.LD_EXT])
result.append(constants.DISK_DT_DEFAULTS[constants.DT_EXT])
return result
......@@ -1140,7 +1141,7 @@ class Instance(TaggableObject):
devs = self.disks
for dev in devs:
if dev.dev_type == constants.LD_LV:
if dev.dev_type == constants.DT_PLAIN:
lvmap[node_uuid].append(dev.logical_id[0] + "/" + dev.logical_id[1])
elif dev.dev_type in constants.LDS_DRBD:
......
......@@ -662,7 +662,7 @@ def _AnnotateDParamsDRBD(disk, (drbd_params, data_params, meta_params)):
"""Annotates just DRBD disks layouts.
"""
assert disk.dev_type == constants.LD_DRBD8
assert disk.dev_type == constants.DT_DRBD8
disk.params = objects.FillDict(drbd_params, disk.params)
(dev_data, dev_meta) = disk.children
......@@ -676,7 +676,7 @@ def _AnnotateDParamsGeneric(disk, (params, )):
"""Generic disk parameter annotation routine.
"""
assert disk.dev_type != constants.LD_DRBD8
assert disk.dev_type != constants.DT_DRBD8
disk.params = objects.FillDict(params, disk.params)
......
......@@ -1718,12 +1718,13 @@ def _VolumeLogName(kind, es_name, volume):
DEV_MAP = {
constants.LD_LV: LogicalVolume,
constants.LD_DRBD8: drbd.DRBD8Dev,
constants.LD_BLOCKDEV: PersistentBlockDevice,
constants.LD_RBD: RADOSBlockDevice,
constants.LD_EXT: ExtStorageDevice,
constants.LD_FILE: FileStorage,
constants.DT_PLAIN: LogicalVolume,
constants.DT_DRBD8: drbd.DRBD8Dev,
constants.DT_BLOCK: PersistentBlockDevice,
constants.DT_RBD: RADOSBlockDevice,
constants.DT_EXT: ExtStorageDevice,
constants.DT_FILE: FileStorage,
constants.DT_SHARED_FILE: FileStorage,
}
......@@ -1736,7 +1737,7 @@ def _VerifyDiskParams(disk):
"""Verifies if all disk parameters are set.
"""
missing = set(constants.DISK_LD_DEFAULTS[disk.dev_type]) - set(disk.params)
missing = set(constants.DISK_DT_DEFAULTS[disk.dev_type]) - set(disk.params)
if missing:
raise errors.ProgrammerError("Block device is missing disk parameters: %s" %
missing)
......
......@@ -95,7 +95,7 @@ def GetInstanceInfo(instance):
drbd_min = {}
for (count, diskinfo) in enumerate(info["Disks"]):
(dtype, _) = diskinfo["disk/%s" % count].split(",", 1)
if dtype == constants.LD_DRBD8:
if dtype == constants.DT_DRBD8:
for child in diskinfo["child devices"]:
vols.append(child["logical_id"])
for key in ["nodeA", "nodeB"]:
......@@ -106,7 +106,7 @@ def GetInstanceInfo(instance):
minor = int(m.group(2))
minorlist = drbd_min.setdefault(node, [])
minorlist.append(minor)
elif dtype == constants.LD_LV:
elif dtype == constants.DT_PLAIN:
vols.append(diskinfo["logical_id"])
assert nodes
......
......@@ -41,7 +41,6 @@ module Ganeti.Objects
, FileDriver(..)
, BlockDriver(..)
, DiskMode(..)
, DiskType(..)
, DiskLogicalId(..)
, Disk(..)
, includesLogicalId
......@@ -303,16 +302,6 @@ $(declareSADT "DiskMode"
])
$(makeJSONInstance ''DiskMode)
$(declareSADT "DiskType"
[ ("LD_LV", 'C.ldLv)
, ("LD_DRBD8", 'C.ldDrbd8)
, ("LD_FILE", 'C.ldFile)
, ("LD_BLOCKDEV", 'C.ldBlockdev)
, ("LD_RADOS", 'C.ldRbd)
, ("LD_EXT", 'C.ldExt)
])
$(makeJSONInstance ''DiskType)
-- | The persistent block driver type. Currently only one type is allowed.
$(declareSADT "BlockDriver"
[ ("BlockDrvManual", 'C.blockdevDriverManual)
......@@ -332,19 +321,21 @@ data DiskLogicalId
| LIDDrbd8 String String Int Int Int String
-- ^ NodeA, NodeB, Port, MinorA, MinorB, Secret
| LIDFile FileDriver String -- ^ Driver, path
| LIDSharedFile FileDriver String -- ^ Driver, path
| LIDBlockDev BlockDriver String -- ^ Driver, path (must be under /dev)
| LIDRados String String -- ^ Unused, path
| LIDExt String String -- ^ ExtProvider, unique name
deriving (Show, Eq)
-- | Mapping from a logical id to a disk type.
lidDiskType :: DiskLogicalId -> DiskType
lidDiskType (LIDPlain {}) = LD_LV
lidDiskType (LIDDrbd8 {}) = LD_DRBD8
lidDiskType (LIDFile {}) = LD_FILE
lidDiskType (LIDBlockDev {}) = LD_BLOCKDEV
lidDiskType (LIDRados {}) = LD_RADOS
lidDiskType (LIDExt {}) = LD_EXT
lidDiskType :: DiskLogicalId -> DiskTemplate
lidDiskType (LIDPlain {}) = DTPlain
lidDiskType (LIDDrbd8 {}) = DTDrbd8
lidDiskType (LIDFile {}) = DTFile
lidDiskType (LIDSharedFile {}) = DTSharedFile
lidDiskType (LIDBlockDev {}) = DTBlock
lidDiskType (LIDRados {}) = DTRbd
lidDiskType (LIDExt {}) = DTExt
-- | Builds the extra disk_type field for a given logical id.
lidEncodeType :: DiskLogicalId -> [(String, JSValue)]
......@@ -358,6 +349,8 @@ encodeDLId (LIDDrbd8 nodeA nodeB port minorA minorB key) =
, showJSON minorA, showJSON minorB, showJSON key ]
encodeDLId (LIDRados pool name) = JSArray [showJSON pool, showJSON name]
encodeDLId (LIDFile driver name) = JSArray [showJSON driver, showJSON name]
encodeDLId (LIDSharedFile driver name) =
JSArray [showJSON driver, showJSON name]
encodeDLId (LIDBlockDev driver name) = JSArray [showJSON driver, showJSON name]
encodeDLId (LIDExt extprovider name) =
JSArray [showJSON extprovider, showJSON name]
......@@ -373,7 +366,7 @@ decodeDLId :: [(String, JSValue)] -> JSValue -> J.Result DiskLogicalId
decodeDLId obj lid = do
dtype <- fromObj obj devType
case dtype of
LD_DRBD8 ->
DTDrbd8 ->
case lid of
JSArray [nA, nB, p, mA, mB, k] -> do
nA' <- readJSON nA
......@@ -384,41 +377,50 @@ decodeDLId obj lid = do
k' <- readJSON k
return $ LIDDrbd8 nA' nB' p' mA' mB' k'
_ -> fail "Can't read logical_id for DRBD8 type"
LD_LV ->
DTPlain ->
case lid of
JSArray [vg, lv] -> do
vg' <- readJSON vg
lv' <- readJSON lv
return $ LIDPlain vg' lv'
_ -> fail "Can't read logical_id for plain type"
LD_FILE ->
DTFile ->
case lid of
JSArray [driver, path] -> do
driver' <- readJSON driver
path' <- readJSON path
return $ LIDFile driver' path'
_ -> fail "Can't read logical_id for file type"
LD_BLOCKDEV ->
DTSharedFile ->
case lid of
JSArray [driver, path] -> do
driver' <- readJSON driver
path' <- readJSON path
return $ LIDSharedFile driver' path'
_ -> fail "Can't read logical_id for shared file type"
DTBlock ->
case lid of
JSArray [driver, path] -> do
driver' <- readJSON driver
path' <- readJSON path
return $ LIDBlockDev driver' path'
_ -> fail "Can't read logical_id for blockdev type"