Package ganeti :: Package storage :: Module drbd :: Class DRBD8Dev
[hide private]
[frames] | no frames]

Class DRBD8Dev

source code


DRBD v8.x block device.

This implements the local host part of the DRBD device, i.e. it doesn't do anything to the supposed peer. If you need a fully connected DRBD pair, you need to use this class on both hosts.

The unique_id for the drbd device is a (local_ip, local_port, remote_ip, remote_port, local_minor, secret) tuple, and it must have two children: the data device and the meta_device. The meta device is checked for valid size and is zeroed on create.

Instance Methods [hide private]
 
__init__(self, unique_id, children, size, params)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
_SetFromMinor(self, minor)
Set our parameters based on the given minor.
source code
string
_GetShowData(self, minor)
Return the `drbdsetup show` data.
source code
dict as described in drbd_info.BaseShowInfo.GetDevInfo
_GetShowInfo(self, minor)
Return parsed information from `drbdsetup show`.
source code
boolean
_MatchesLocal(self, info)
Test if our local config matches with an existing device.
source code
boolean
_MatchesNet(self, info)
Test if our network config matches with an existing device.
source code
 
_AssembleLocal(self, minor, backend, meta, size)
Configure the local part of a DRBD device.
source code
 
_AssembleNet(self, minor, net_info, dual_pri=False, hmac=None, secret=None)
Configure the network part of the device.
source code
 
AddChildren(self, devices)
Add a disk to the DRBD device.
source code
 
RemoveChildren(self, devices)
Detach the drbd device from local storage.
source code
list
_SetMinorSyncParams(self, minor, params)
Set the parameters of the DRBD syncer.
source code
list
SetSyncParams(self, params)
Set the synchronization parameters of the DRBD syncer.
source code
 
PauseResumeSync(self, pause)
Pauses or resumes the sync of a DRBD device.
source code
DRBD8Status
GetProcStatus(self)
Return the current status data from /proc/drbd for this device.
source code
objects.BlockDevStatus
GetSyncStatus(self)
Returns the sync status of the device.
source code
 
Open(self, force=False)
Make the local state primary.
source code
 
Close(self)
Make the local state secondary.
source code
 
DisconnectNet(self)
Removes network configuration.
source code
 
AttachNet(self, multimaster)
Reconnects the network.
source code
 
Attach(self)
Check if our minor is configured.
source code
 
Assemble(self)
Assemble the drbd.
source code
 
_SlowAssemble(self)
Assembles the DRBD device from a (partially) configured device.
source code
 
_FastAssemble(self)
Assemble the drbd device from zero.
source code
 
_ShutdownLocal(self, minor)
Detach from the local device.
source code
 
_ShutdownNet(self, minor)
Disconnect from the remote peer.
source code
 
Shutdown(self)
Shutdown the DRBD device.
source code
 
Remove(self)
Stub remove for DRBD devices.
source code
 
Rename(self, new_id)
Rename a device.
source code
 
Grow(self, amount, dryrun, backingstore, excl_stor)
Resize the DRBD device and its backing storage.
source code

Inherited from base.BlockDev: CombinedSyncStatus, GetActualDimensions, GetActualSize, GetActualSpindles, SetInfo, __repr__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
 
_InitMeta(cls, minor, dev_path)
Initialize a meta device.
source code
BlockDev
Create(cls, unique_id, children, size, spindles, params, excl_stor)
Create a new DRBD8 device.
source code
Static Methods [hide private]
string
_DevPath(minor)
Return the path to a drbd device for a given minor.
source code
 
_CheckMetaSize(meta_device)
Check if the given meta device looks like a valid one.
source code
 
_GetNetFamily(minor, lhost, rhost) source code
Class Variables [hide private]
  _DRBD_MAJOR = 147
  _NET_RECONFIG_TIMEOUT = 60
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, unique_id, children, size, params)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

_DevPath(minor)
Static Method

source code 

Return the path to a drbd device for a given minor.

Parameters:
  • minor (int)
Returns: string

_SetFromMinor(self, minor)

source code 

Set our parameters based on the given minor.

This sets our minor variable and our dev_path.

Parameters:
  • minor (int)

_CheckMetaSize(meta_device)
Static Method

source code 

Check if the given meta device looks like a valid one.

This currently only checks the size, which must be around 128MiB.

Parameters:
  • meta_device (string) - the path to the device to check

_GetShowData(self, minor)

source code 

Return the `drbdsetup show` data.

Parameters:
  • minor (int) - the minor to collect show output for
Returns: string

_GetShowInfo(self, minor)

source code 

Return parsed information from `drbdsetup show`.

Parameters:
  • minor (int) - the minor to return information for
Returns: dict as described in drbd_info.BaseShowInfo.GetDevInfo

_MatchesLocal(self, info)

source code 

Test if our local config matches with an existing device.

The parameter should be as returned from `_GetShowInfo()`. This method tests if our local backing device is the same as the one in the info parameter, in effect testing if we look like the given device.

Parameters:
Returns: boolean

_MatchesNet(self, info)

source code 

Test if our network config matches with an existing device.

The parameter should be as returned from `_GetShowInfo()`. This method tests if our network configuration is the same as the one in the info parameter, in effect testing if we look like the given device.

Parameters:
Returns: boolean

_AssembleLocal(self, minor, backend, meta, size)

source code 

Configure the local part of a DRBD device.

Parameters:
  • minor (int) - the minor to assemble locally
  • backend (string) - path to the data device to use
  • meta (string) - path to the meta device to use
  • size (int) - size in MiB

_AssembleNet(self, minor, net_info, dual_pri=False, hmac=None, secret=None)

source code 

Configure the network part of the device.

Parameters:
  • minor (int) - the minor to assemble the network for
  • net_info ((string, int, string, int)) - tuple containing the local address, local port, remote address and remote port
  • dual_pri (boolean) - whether two primaries should be allowed or not
  • hmac (string) - the HMAC algorithm to use
  • secret (string) - the shared secret to use

AddChildren(self, devices)

source code 

Add a disk to the DRBD device.

Parameters:
  • devices (list of BlockDev) - a list of exactly two BlockDev objects; the first denotes the data device, the second the meta device for this DRBD device

RemoveChildren(self, devices)

source code 

Detach the drbd device from local storage.

Parameters:
  • devices (list of BlockDev) - a list of exactly two BlockDev objects; the first denotes the data device, the second the meta device for this DRBD device

_SetMinorSyncParams(self, minor, params)

source code 

Set the parameters of the DRBD syncer.

This is the low-level implementation.

Parameters:
  • minor (int) - the drbd minor whose settings we change
  • params (dict) - LD level disk parameters related to the synchronization
Returns: list
a list of error messages

SetSyncParams(self, params)

source code 

Set the synchronization parameters of the DRBD syncer.

See BlockDev.SetSyncParams for parameter description.

Parameters:
  • params - dictionary of LD level disk parameters related to the synchronization.
Returns: list
a list of error messages, emitted both by the current node and by children. An empty list means no errors.
Overrides: base.BlockDev.SetSyncParams

PauseResumeSync(self, pause)

source code 

Pauses or resumes the sync of a DRBD device.

See BlockDev.PauseResumeSync for parameter description.

Parameters:
  • pause - Whether to pause or resume
Overrides: base.BlockDev.PauseResumeSync

GetSyncStatus(self)

source code 

Returns the sync status of the device.

If sync_percent is None, it means all is ok If estimated_time is None, it means we can't estimate the time needed, otherwise it's the time left in seconds.

We set the is_degraded parameter to True on two conditions: network not connected or local disk missing.

We compute the ldisk parameter based on whether we have a local disk or not.

Returns: objects.BlockDevStatus
Overrides: base.BlockDev.GetSyncStatus

Open(self, force=False)

source code 

Make the local state primary.

If the 'force' parameter is given, DRBD is instructed to switch the device into primary mode. Since this is a potentially dangerous operation, the force flag should be only given after creation, when it actually is mandatory.

Overrides: base.BlockDev.Open

Close(self)

source code 

Make the local state secondary.

This will, of course, fail if the device is in use.

Overrides: base.BlockDev.Close

DisconnectNet(self)

source code 

Removes network configuration.

This method shutdowns the network side of the device.

The method will wait up to a hardcoded timeout for the device to go into standalone after the 'disconnect' command before re-configuring it, as sometimes it takes a while for the disconnect to actually propagate and thus we might issue a 'net' command while the device is still connected. If the device will still be attached to the network and we time out, we raise an exception.

AttachNet(self, multimaster)

source code 

Reconnects the network.

This method connects the network side of the device with a specified multi-master flag. The device needs to be 'Standalone' but have valid network configuration data.

Parameters:
  • multimaster (boolean) - init the network in dual-primary mode

Attach(self)

source code 

Check if our minor is configured.

This doesn't do any device configurations - it only checks if the minor is in a state different from Unconfigured.

Note that this function will not change the state of the system in any way (except in case of side-effects caused by reading from /proc).

Overrides: base.BlockDev.Attach

Assemble(self)

source code 

Assemble the drbd.

Method:

  • if we have a configured device, we try to ensure that it matches our config
  • if not, we create it from zero
  • anyway, set the device parameters
Overrides: base.BlockDev.Assemble

_SlowAssemble(self)

source code 

Assembles the DRBD device from a (partially) configured device.

In case of partially attached (local device matches but no network setup), we perform the network attach. If successful, we re-test the attach if can return success.

_FastAssemble(self)

source code 

Assemble the drbd device from zero.

This is run when in Assemble we detect our minor is unused.

_ShutdownLocal(self, minor)

source code 

Detach from the local device.

I/Os will continue to be served from the remote device. If we don't have a remote device, this operation will fail.

Parameters:
  • minor (int) - the device to detach from the local device

_ShutdownNet(self, minor)

source code 

Disconnect from the remote peer.

This fails if we don't have a local device.

Parameters:
  • minor (boolean) - the device to disconnect from the remote peer

Shutdown(self)

source code 

Shutdown the DRBD device.

Overrides: base.BlockDev.Shutdown

Remove(self)

source code 

Stub remove for DRBD devices.

Overrides: base.BlockDev.Remove

Rename(self, new_id)

source code 

Rename a device.

This is not supported for drbd devices.

Overrides: base.BlockDev.Rename

Grow(self, amount, dryrun, backingstore, excl_stor)

source code 

Resize the DRBD device and its backing storage.

See BlockDev.Grow for parameter description.

Parameters:
  • amount - the amount (in mebibytes) to grow with
  • dryrun - whether to execute the operation in simulation mode only, without actually increasing the size
  • backingstore - whether to execute the operation on backing storage only, or on "logical" storage only; e.g. DRBD is logical storage, whereas LVM, file, RBD are backing storage
  • excl_stor - Whether exclusive_storage is active
Overrides: base.BlockDev.Grow

_InitMeta(cls, minor, dev_path)
Class Method

source code 

Initialize a meta device.

This will not work if the given minor is in use.

Parameters:
  • minor (int) - the DRBD minor whose (future) meta device should be initialized
  • dev_path (string) - path to the meta device to initialize

Create(cls, unique_id, children, size, spindles, params, excl_stor)
Class Method

source code 

Create a new DRBD8 device.

Since DRBD devices are not created per se, just assembled, this function only initializes the metadata.

Parameters:
  • unique_id - unique identifier; the details depend on the actual device type
  • children - for hierarchical devices, the child devices
  • size - size in MiB
  • spindles - number of physical disk to dedicate to the device
  • params - device-specific options/parameters
  • excl_stor - whether exclusive_storage is active
Returns: BlockDev
the created device, or None in case of an error
Overrides: base.BlockDev.Create