Commit 821d1bd1 authored by Iustin Pop's avatar Iustin Pop
Browse files

Uniformize some function names in backend.py

Currently, the names of the functions in backend.py that are actually
RPC procedures and are called from ganeti-noded are not corresponding to
the RPC names. This makes it hard to actually see which functions are
exported and which functions are internal to backend.

This patch renames all blockdevice-related functions in backend.py match
the name of the RPC call (without the ‘call’ or ‘perspective’ prefix).
This should make it easier to grep for a given function called in
cmdlib, without having to open and check in ganet-inoded what backend
function it corresponds to.

The patch also does two minor extra cleanups (rename a variable and
change a logging level).

Reviewed-by: ultrotter
parent 82463074
......@@ -113,7 +113,7 @@ class NodeHttpServer(http.server.HttpServer):
bdev = objects.Disk.FromDict(bdev_s)
if bdev is None:
raise ValueError("can't unserialize data!")
return backend.CreateBlockDevice(bdev, size, owner, on_primary, info)
return backend.BlockdevCreate(bdev, size, owner, on_primary, info)
@staticmethod
def perspective_blockdev_remove(params):
......@@ -122,7 +122,7 @@ class NodeHttpServer(http.server.HttpServer):
"""
bdev_s = params[0]
bdev = objects.Disk.FromDict(bdev_s)
return backend.RemoveBlockDevice(bdev)
return backend.BlockdevRemove(bdev)
@staticmethod
def perspective_blockdev_rename(params):
......@@ -130,7 +130,7 @@ class NodeHttpServer(http.server.HttpServer):
"""
devlist = [(objects.Disk.FromDict(ds), uid) for ds, uid in params]
return backend.RenameBlockDevices(devlist)
return backend.BlockdevRename(devlist)
@staticmethod
def perspective_blockdev_assemble(params):
......@@ -141,7 +141,7 @@ class NodeHttpServer(http.server.HttpServer):
bdev = objects.Disk.FromDict(bdev_s)
if bdev is None:
raise ValueError("can't unserialize data!")
return backend.AssembleBlockDevice(bdev, owner, on_primary)
return backend.BlockdevAssemble(bdev, owner, on_primary)
@staticmethod
def perspective_blockdev_shutdown(params):
......@@ -152,7 +152,7 @@ class NodeHttpServer(http.server.HttpServer):
bdev = objects.Disk.FromDict(bdev_s)
if bdev is None:
raise ValueError("can't unserialize data!")
return backend.ShutdownBlockDevice(bdev)
return backend.BlockdevShutdown(bdev)
@staticmethod
def perspective_blockdev_addchildren(params):
......@@ -167,7 +167,7 @@ class NodeHttpServer(http.server.HttpServer):
ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s]
if bdev is None or ndevs.count(None) > 0:
raise ValueError("can't unserialize data!")
return backend.MirrorAddChildren(bdev, ndevs)
return backend.BlockdevAddchildren(bdev, ndevs)
@staticmethod
def perspective_blockdev_removechildren(params):
......@@ -182,7 +182,7 @@ class NodeHttpServer(http.server.HttpServer):
ndevs = [objects.Disk.FromDict(disk_s) for disk_s in ndev_s]
if bdev is None or ndevs.count(None) > 0:
raise ValueError("can't unserialize data!")
return backend.MirrorRemoveChildren(bdev, ndevs)
return backend.BlockdevRemovechildren(bdev, ndevs)
@staticmethod
def perspective_blockdev_getmirrorstatus(params):
......@@ -191,7 +191,7 @@ class NodeHttpServer(http.server.HttpServer):
"""
disks = [objects.Disk.FromDict(dsk_s)
for dsk_s in params]
return backend.GetMirrorStatus(disks)
return backend.BlockdevGetmirrorstatus(disks)
@staticmethod
def perspective_blockdev_find(params):
......@@ -201,7 +201,7 @@ class NodeHttpServer(http.server.HttpServer):
"""
disk = objects.Disk.FromDict(params[0])
return backend.CallBlockdevFind(disk)
return backend.BlockdevFind(disk)
@staticmethod
def perspective_blockdev_snapshot(params):
......@@ -213,7 +213,7 @@ class NodeHttpServer(http.server.HttpServer):
"""
cfbd = objects.Disk.FromDict(params[0])
return backend.SnapshotBlockDevice(cfbd)
return backend.BlockdevSnapshot(cfbd)
@staticmethod
def perspective_blockdev_grow(params):
......@@ -222,7 +222,7 @@ class NodeHttpServer(http.server.HttpServer):
"""
cfbd = objects.Disk.FromDict(params[0])
amount = params[1]
return backend.GrowBlockDevice(cfbd, amount)
return backend.BlockdevGrow(cfbd, amount)
@staticmethod
def perspective_blockdev_close(params):
......@@ -230,7 +230,7 @@ class NodeHttpServer(http.server.HttpServer):
"""
disks = [objects.Disk.FromDict(cf) for cf in params[1]]
return backend.CloseBlockDevices(params[0], disks)
return backend.BlockdevClose(params[0], disks)
# blockdev/drbd specific methods ----------
......@@ -256,7 +256,8 @@ class NodeHttpServer(http.server.HttpServer):
"""
nodes_ip, disks, instance_name, multimaster = params
disks = [objects.Disk.FromDict(cf) for cf in disks]
return backend.DrbdAttachNet(nodes_ip, disks, instance_name, multimaster)
return backend.DrbdAttachNet(nodes_ip, disks,
instance_name, multimaster)
@staticmethod
def perspective_drbd_wait_sync(params):
......@@ -593,7 +594,7 @@ class NodeHttpServer(http.server.HttpServer):
"""Query detailed information about existing OSes.
"""
return [os.ToDict() for os in backend.DiagnoseOS()]
return [os_obj.ToDict() for os_obj in backend.DiagnoseOS()]
@staticmethod
def perspective_os_get(params):
......
......@@ -1070,7 +1070,7 @@ def MigrateInstance(instance, target, live):
return (True, "Migration successfull")
def CreateBlockDevice(disk, size, owner, on_primary, info):
def BlockdevCreate(disk, size, owner, on_primary, info):
"""Creates a block device for an instance.
@type disk: L{objects.Disk}
......@@ -1123,7 +1123,7 @@ def CreateBlockDevice(disk, size, owner, on_primary, info):
return True, physical_id
def RemoveBlockDevice(disk):
def BlockdevRemove(disk):
"""Remove a block device.
@note: This is intended to be called recursively.
......@@ -1149,7 +1149,7 @@ def RemoveBlockDevice(disk):
result = True
if disk.children:
for child in disk.children:
result = result and RemoveBlockDevice(child)
result = result and BlockdevRemove(child)
return result
......@@ -1189,7 +1189,7 @@ def _RecursiveAssembleBD(disk, owner, as_primary):
if children.count(None) >= mcn:
raise
cdev = None
logging.debug("Error in child activation: %s", str(err))
logging.error("Error in child activation: %s", str(err))
children.append(cdev)
if as_primary or disk.AssembleOnSecondary():
......@@ -1206,7 +1206,7 @@ def _RecursiveAssembleBD(disk, owner, as_primary):
return result
def AssembleBlockDevice(disk, owner, as_primary):
def BlockdevAssemble(disk, owner, as_primary):
"""Activate a block device for an instance.
This is a wrapper over _RecursiveAssembleBD.
......@@ -1222,7 +1222,7 @@ def AssembleBlockDevice(disk, owner, as_primary):
return result
def ShutdownBlockDevice(disk):
def BlockdevShutdown(disk):
"""Shut down a block device.
First, if the device is assembled (Attach() is successfull), then
......@@ -1250,11 +1250,11 @@ def ShutdownBlockDevice(disk):
result = True
if disk.children:
for child in disk.children:
result = result and ShutdownBlockDevice(child)
result = result and BlockdevShutdown(child)
return result
def MirrorAddChildren(parent_cdev, new_cdevs):
def BlockdevAddchildren(parent_cdev, new_cdevs):
"""Extend a mirrored block device.
@type parent_cdev: L{objects.Disk}
......@@ -1278,7 +1278,7 @@ def MirrorAddChildren(parent_cdev, new_cdevs):
return True
def MirrorRemoveChildren(parent_cdev, new_cdevs):
def BlockdevRemovechildren(parent_cdev, new_cdevs):
"""Shrink a mirrored block device.
@type parent_cdev: L{objects.Disk}
......@@ -1310,7 +1310,7 @@ def MirrorRemoveChildren(parent_cdev, new_cdevs):
return True
def GetMirrorStatus(disks):
def BlockdevGetmirrorstatus(disks):
"""Get the mirroring status of a list of devices.
@type disks: list of L{objects.Disk}
......@@ -1352,7 +1352,7 @@ def _RecursiveFindBD(disk):
return bdev.FindDevice(disk.dev_type, disk.physical_id, children)
def CallBlockdevFind(disk):
def BlockdevFind(disk):
"""Check if a device is activated.
If it is, return informations about the real device.
......@@ -1638,7 +1638,7 @@ def OSEnvironment(instance, debug=0):
return result
def GrowBlockDevice(disk, amount):
def BlockdevGrow(disk, amount):
"""Grow a stack of block devices.
This function is called recursively, with the childrens being the
......@@ -1664,7 +1664,7 @@ def GrowBlockDevice(disk, amount):
return True, None
def SnapshotBlockDevice(disk):
def BlockdevSnapshot(disk):
"""Create a snapshot copy of a block device.
This function is called recursively, and the snapshot is actually created
......@@ -1679,13 +1679,13 @@ def SnapshotBlockDevice(disk):
if disk.children:
if len(disk.children) == 1:
# only one child, let's recurse on it
return SnapshotBlockDevice(disk.children[0])
return BlockdevSnapshot(disk.children[0])
else:
# more than one child, choose one that matches
for child in disk.children:
if child.size == disk.size:
# return implies breaking the loop
return SnapshotBlockDevice(child)
return BlockdevSnapshot(child)
elif disk.dev_type == constants.LD_LV:
r_dev = _RecursiveFindBD(disk)
if r_dev is not None:
......@@ -1935,7 +1935,7 @@ def RemoveExport(export):
return True
def RenameBlockDevices(devlist):
def BlockdevRename(devlist):
"""Rename a list of block devices.
@type devlist: list of tuples
......@@ -2177,7 +2177,7 @@ def JobQueueSetDrainFlag(drain_flag):
return True
def CloseBlockDevices(instance_name, disks):
def BlockdevClose(instance_name, disks):
"""Closes the given block devices.
This means they will be switched to secondary mode (in case of
......
......@@ -3832,7 +3832,7 @@ def _CreateBlockDev(lu, node, instance, device, force_create,
(this will be represented as a LVM tag)
@type force_open: boolean
@param force_open: this parameter will be passes to the
L{backend.CreateBlockDevice} function where it specifies
L{backend.BlockdevCreate} function where it specifies
whether we run on primary or not, and it affects both
the child assembly and the device own Open() execution
......@@ -3867,7 +3867,7 @@ def _CreateSingleBlockDev(lu, node, instance, device, info, force_open):
(this will be represented as a LVM tag)
@type force_open: boolean
@param force_open: this parameter will be passes to the
L{backend.CreateBlockDevice} function where it specifies
L{backend.BlockdevCreate} function where it specifies
whether we run on primary or not, and it affects both
the child assembly and the device own Open() execution
......
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