Package ganeti :: Module config :: Class ConfigWriter
[hide private]
[frames] | no frames]

Class ConfigWriter

source code

The interface to the cluster configuration.

Instance Methods [hide private]
 
__init__(self, cfg_file=None, offline=False) source code
 
_GenerateOneMAC(self)
Generate one mac address
source code
 
GenerateMAC(self, ec_id)
Generate a MAC for an instance.
source code
 
ReserveMAC(self, mac, ec_id)
Reserve a MAC for an instance.
source code
 
ReserveLV(self, lv_name, ec_id)
Reserve an VG/LV pair for an instance.
source code
 
GenerateDRBDSecret(self, ec_id)
Generate a DRBD secret.
source code
 
_AllLVs(self)
Compute the list of all LVs.
source code
set
_AllIDs(self, include_temporary)
Compute the list of all UUIDs and names we have.
source code
string
_GenerateUniqueID(self, ec_id)
Generate an unique UUID.
source code
 
GenerateUniqueID(self, ec_id)
Generate an unique ID.
source code
list
_AllMACs(self)
Return all MACs present in the config.
source code
list
_AllDRBDSecrets(self)
Return all DRBD secrets present in the config.
source code
list
_CheckDiskIDs(self, disk, l_ids, p_ids)
Compute duplicate disk IDs
source code
list
_UnlockedVerifyConfig(self)
Verify function.
source code
list
VerifyConfig(self)
Verify function.
source code
 
_UnlockedSetDiskID(self, disk, node_name)
Convert the unique ID to the ID needed on the target nodes.
source code
 
SetDiskID(self, disk, node_name)
Convert the unique ID to the ID needed on the target nodes.
source code
 
AddTcpUdpPort(self, port)
Adds a new port to the available port pool.
source code
 
GetPortList(self)
Returns a copy of the current port list.
source code
 
AllocatePort(self)
Allocate a port.
source code
(dict, list)
_UnlockedComputeDRBDMap(self)
Compute the used DRBD minor/nodes.
source code
 
ComputeDRBDMap(self)
Compute the used DRBD minor/nodes.
source code
 
AllocateDRBDMinor(self, nodes, instance)
Allocate a drbd minor.
source code
 
_UnlockedReleaseDRBDMinors(self, instance)
Release temporary drbd minors allocated for a given instance.
source code
 
ReleaseDRBDMinors(self, instance)
Release temporary drbd minors allocated for a given instance.
source code
 
GetConfigVersion(self)
Get the configuration version.
source code
 
GetClusterName(self)
Get cluster name.
source code
 
GetMasterNode(self)
Get the hostname of the master node for this cluster.
source code
 
GetMasterIP(self)
Get the IP of the master node for this cluster.
source code
 
GetMasterNetdev(self)
Get the master network device for this cluster.
source code
 
GetFileStorageDir(self)
Get the file storage dir for this cluster.
source code
 
GetHypervisorType(self)
Get the hypervisor type for this cluster.
source code
string
GetHostKey(self)
Return the rsa hostkey from the config.
source code
 
GetDefaultIAllocator(self)
Get the default instance allocator for this cluster.
source code
 
AddInstance(self, instance, ec_id)
Add an instance to the config.
source code
 
_EnsureUUID(self, item, ec_id)
Ensures a given object has a valid UUID.
source code
 
_SetInstanceStatus(self, instance_name, status)
Set the instance's status to a given value.
source code
 
MarkInstanceUp(self, instance_name)
Mark the instance status to up in the config.
source code
 
RemoveInstance(self, instance_name)
Remove the instance from the configuration.
source code
 
RenameInstance(self, old_name, new_name)
Rename an instance.
source code
 
MarkInstanceDown(self, instance_name)
Mark the status of an instance to down in the configuration.
source code
 
_UnlockedGetInstanceList(self)
Get the list of instances.
source code
 
GetInstanceList(self)
Get the list of instances.
source code
 
ExpandInstanceName(self, short_name)
Attempt to expand an incomplete instance name.
source code
 
_UnlockedGetInstanceInfo(self, instance_name)
Returns information about an instance.
source code
objects.Instance
GetInstanceInfo(self, instance_name)
Returns information about an instance.
source code
dict
GetAllInstancesInfo(self)
Get the configuration of all instances.
source code
 
AddNode(self, node, ec_id)
Add a node to the configuration.
source code
 
RemoveNode(self, node_name)
Remove a node from the configuration.
source code
 
ExpandNodeName(self, short_name)
Attempt to expand an incomplete instance name.
source code
objects.Node
_UnlockedGetNodeInfo(self, node_name)
Get the configuration of a node, as stored in the config.
source code
objects.Node
GetNodeInfo(self, node_name)
Get the configuration of a node, as stored in the config.
source code
list
_UnlockedGetNodeList(self)
Return the list of nodes which are in the configuration.
source code
 
GetNodeList(self)
Return the list of nodes which are in the configuration.
source code
 
_UnlockedGetOnlineNodeList(self)
Return the list of nodes which are online.
source code
 
GetOnlineNodeList(self)
Return the list of nodes which are online.
source code
dict
GetAllNodesInfo(self)
Get the configuration of all nodes.
source code
tuple
_UnlockedGetMasterCandidateStats(self, exceptions=None)
Get the number of current and maximum desired and possible candidates.
source code
tuple
GetMasterCandidateStats(self, exceptions=None)
Get the number of current and maximum possible candidates.
source code
list
MaintainCandidatePool(self, exceptions)
Try to grow the candidate pool to the desired size.
source code
 
_BumpSerialNo(self)
Bump up the serial number of the config.
source code
 
_AllUUIDObjects(self)
Returns all objects with uuid attributes.
source code
 
_OpenConfig(self)
Read the config data from disk.
source code
 
_UpgradeConfig(self)
Run upgrade steps that cannot be done purely in the objects.
source code
 
_DistributeConfig(self, feedback_fn)
Distribute the configuration to the other nodes.
source code
 
_WriteConfig(self, destination=None, feedback_fn=None)
Write the configuration data to persistent storage.
source code
dict
_UnlockedGetSsconfValues(self)
Return the values needed by ssconf.
source code
 
GetVGName(self)
Return the volume group name.
source code
 
SetVGName(self, vg_name)
Set the volume group name.
source code
 
GetDRBDHelper(self)
Return DRBD usermode helper.
source code
 
SetDRBDHelper(self, drbd_helper)
Set DRBD usermode helper.
source code
 
GetMACPrefix(self)
Return the mac prefix.
source code
objects.Cluster
GetClusterInfo(self)
Returns information about the cluster
source code
 
HasAnyDiskOfType(self, dev_type)
Check if in there is at disk of the given type in the configuration.
source code
 
Update(self, target, feedback_fn)
Notify function to be called after updates.
source code
 
DropECReservations(self, ec_id)
Drop per-execution-context reservations
source code
Static Methods [hide private]
 
IsCluster()
Check if the cluster is configured.
source code
Instance Variables [hide private]
  _all_rms
a list of all temporary reservation managers
  _temporary_lvs
reservation manager for temporary LVs
Method Details [hide private]

GenerateMAC(self, ec_id)

source code 

Generate a MAC for an instance.

This should check the current instances for duplicates.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

ReserveMAC(self, mac, ec_id)

source code 

Reserve a MAC for an instance.

This only checks instances managed by this cluster, it does not check for potential collisions elsewhere.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

ReserveLV(self, lv_name, ec_id)

source code 

Reserve an VG/LV pair for an instance.

Parameters:
  • lv_name (string) - the logical volume name to reserve
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GenerateDRBDSecret(self, ec_id)

source code 

Generate a DRBD secret.

This checks the current disks for duplicates.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

_AllIDs(self, include_temporary)

source code 

Compute the list of all UUIDs and names we have.

Parameters:
  • include_temporary (boolean) - whether to include the _temporary_ids set
Returns: set
a set of IDs

_GenerateUniqueID(self, ec_id)

source code 

Generate an unique UUID.

This checks the current node, instances and disk names for duplicates.

Returns: string
the unique id

GenerateUniqueID(self, ec_id)

source code 

Generate an unique ID.

This is just a wrapper over the unlocked version.

Parameters:
  • ec_id (string) - unique id for the job to reserve the id to
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

_AllMACs(self)

source code 

Return all MACs present in the config.

Returns: list
the list of all MACs

_AllDRBDSecrets(self)

source code 

Return all DRBD secrets present in the config.

Returns: list
the list of all DRBD secrets

_CheckDiskIDs(self, disk, l_ids, p_ids)

source code 

Compute duplicate disk IDs

Parameters:
  • disk (objects.Disk) - the disk at which to start searching
  • l_ids (list) - list of current logical ids
  • p_ids (list) - list of current physical ids
Returns: list
a list of error messages

_UnlockedVerifyConfig(self)

source code 

Verify function.

Returns: list
a list of error messages; a non-empty list signifies configuration errors

VerifyConfig(self)

source code 

Verify function.

This is just a wrapper over _UnlockedVerifyConfig.

Returns: list
a list of error messages; a non-empty list signifies configuration errors
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

_UnlockedSetDiskID(self, disk, node_name)

source code 

Convert the unique ID to the ID needed on the target nodes.

This is used only for drbd, which needs ip/port configuration.

The routine descends down and updates its children also, because this helps when the only the top device is passed to the remote node.

This function is for internal use, when the config lock is already held.

SetDiskID(self, disk, node_name)

source code 

Convert the unique ID to the ID needed on the target nodes.

This is used only for drbd, which needs ip/port configuration.

The routine descends down and updates its children also, because this helps when the only the top device is passed to the remote node.

Decorators:
  • @locking.ssynchronized(_config_lock)

AddTcpUdpPort(self, port)

source code 

Adds a new port to the available port pool.

Decorators:
  • @locking.ssynchronized(_config_lock)

GetPortList(self)

source code 

Returns a copy of the current port list.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

AllocatePort(self)

source code 

Allocate a port.

The port will be taken from the available port pool or from the default port range (and in this case we increase highest_used_port).

Decorators:
  • @locking.ssynchronized(_config_lock)

_UnlockedComputeDRBDMap(self)

source code 

Compute the used DRBD minor/nodes.

Returns: (dict, list)
dictionary of node_name: dict of minor: instance_name; the returned dict will have all the nodes in it (even if with an empty list), and a list of duplicates; if the duplicates list is not empty, the configuration is corrupted and its caller should raise an exception

ComputeDRBDMap(self)

source code 

Compute the used DRBD minor/nodes.

This is just a wrapper over _UnlockedComputeDRBDMap.

Returns:
dictionary of node_name: dict of minor: instance_name; the returned dict will have all the nodes in it (even if with an empty list).
Decorators:
  • @locking.ssynchronized(_config_lock)

AllocateDRBDMinor(self, nodes, instance)

source code 

Allocate a drbd minor.

The free minor will be automatically computed from the existing devices. A node can be given multiple times in order to allocate multiple minors. The result is the list of minors, in the same order as the passed nodes.

Parameters:
  • instance (string) - the instance for which we allocate minors
Decorators:
  • @locking.ssynchronized(_config_lock)

_UnlockedReleaseDRBDMinors(self, instance)

source code 

Release temporary drbd minors allocated for a given instance.

Parameters:
  • instance (string) - the instance for which temporary minors should be released

ReleaseDRBDMinors(self, instance)

source code 

Release temporary drbd minors allocated for a given instance.

This should be called on the error paths, on the success paths it's automatically called by the ConfigWriter add and update functions.

This function is just a wrapper over _UnlockedReleaseDRBDMinors.

Parameters:
  • instance (string) - the instance for which temporary minors should be released
Decorators:
  • @locking.ssynchronized(_config_lock)

GetConfigVersion(self)

source code 

Get the configuration version.

Returns:
Config version
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetClusterName(self)

source code 

Get cluster name.

Returns:
Cluster name
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetMasterNode(self)

source code 

Get the hostname of the master node for this cluster.

Returns:
Master hostname
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetMasterIP(self)

source code 

Get the IP of the master node for this cluster.

Returns:
Master IP
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetMasterNetdev(self)

source code 

Get the master network device for this cluster.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetFileStorageDir(self)

source code 

Get the file storage dir for this cluster.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetHypervisorType(self)

source code 

Get the hypervisor type for this cluster.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetHostKey(self)

source code 

Return the rsa hostkey from the config.

Returns: string
the rsa hostkey
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetDefaultIAllocator(self)

source code 

Get the default instance allocator for this cluster.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

AddInstance(self, instance, ec_id)

source code 

Add an instance to the config.

This should be used after creating a new instance.

Parameters:
Decorators:
  • @locking.ssynchronized(_config_lock)

_EnsureUUID(self, item, ec_id)

source code 

Ensures a given object has a valid UUID.

Parameters:
  • item - the instance or node to be checked
  • ec_id - the execution context id for the uuid reservation

MarkInstanceUp(self, instance_name)

source code 

Mark the instance status to up in the config.

Decorators:
  • @locking.ssynchronized(_config_lock)

RemoveInstance(self, instance_name)

source code 

Remove the instance from the configuration.

Decorators:
  • @locking.ssynchronized(_config_lock)

RenameInstance(self, old_name, new_name)

source code 

Rename an instance.

This needs to be done in ConfigWriter and not by RemoveInstance combined with AddInstance as only we can guarantee an atomic rename.

Decorators:
  • @locking.ssynchronized(_config_lock)

MarkInstanceDown(self, instance_name)

source code 

Mark the status of an instance to down in the configuration.

Decorators:
  • @locking.ssynchronized(_config_lock)

_UnlockedGetInstanceList(self)

source code 

Get the list of instances.

This function is for internal use, when the config lock is already held.

GetInstanceList(self)

source code 

Get the list of instances.

Returns:
array of instances, ex. ['instance2.example.com', 'instance1.example.com']
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

ExpandInstanceName(self, short_name)

source code 

Attempt to expand an incomplete instance name.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

_UnlockedGetInstanceInfo(self, instance_name)

source code 

Returns information about an instance.

This function is for internal use, when the config lock is already held.

GetInstanceInfo(self, instance_name)

source code 

Returns information about an instance.

It takes the information from the configuration file. Other information of an instance are taken from the live systems.

Parameters:
  • instance_name - name of the instance, e.g. instance1.example.com
Returns: objects.Instance
the instance object
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetAllInstancesInfo(self)

source code 

Get the configuration of all instances.

Returns: dict
dict of (instance, instance_info), where instance_info is what would GetInstanceInfo return for the node
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

AddNode(self, node, ec_id)

source code 

Add a node to the configuration.

Parameters:
Decorators:
  • @locking.ssynchronized(_config_lock)

RemoveNode(self, node_name)

source code 

Remove a node from the configuration.

Decorators:
  • @locking.ssynchronized(_config_lock)

ExpandNodeName(self, short_name)

source code 

Attempt to expand an incomplete instance name.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

_UnlockedGetNodeInfo(self, node_name)

source code 

Get the configuration of a node, as stored in the config.

This function is for internal use, when the config lock is already held.

Parameters:
  • node_name - the node name, e.g. node1.example.com
Returns: objects.Node
the node object

GetNodeInfo(self, node_name)

source code 

Get the configuration of a node, as stored in the config.

This is just a locked wrapper over _UnlockedGetNodeInfo.

Parameters:
  • node_name - the node name, e.g. node1.example.com
Returns: objects.Node
the node object
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

_UnlockedGetNodeList(self)

source code 

Return the list of nodes which are in the configuration.

This function is for internal use, when the config lock is already held.

Returns: list

GetNodeList(self)

source code 

Return the list of nodes which are in the configuration.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetOnlineNodeList(self)

source code 

Return the list of nodes which are online.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetAllNodesInfo(self)

source code 

Get the configuration of all nodes.

Returns: dict
dict of (node, node_info), where node_info is what would GetNodeInfo return for the node
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

_UnlockedGetMasterCandidateStats(self, exceptions=None)

source code 

Get the number of current and maximum desired and possible candidates.

Parameters:
  • exceptions (list) - if passed, list of nodes that should be ignored
Returns: tuple
tuple of (current, desired and possible, possible)

GetMasterCandidateStats(self, exceptions=None)

source code 

Get the number of current and maximum possible candidates.

This is just a wrapper over _UnlockedGetMasterCandidateStats.

Parameters:
  • exceptions (list) - if passed, list of nodes that should be ignored
Returns: tuple
tuple of (current, max)
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

MaintainCandidatePool(self, exceptions)

source code 

Try to grow the candidate pool to the desired size.

Parameters:
  • exceptions (list) - if passed, list of nodes that should be ignored
Returns: list
list with the adjusted nodes (objects.Node instances)
Decorators:
  • @locking.ssynchronized(_config_lock)

_UpgradeConfig(self)

source code 

Run upgrade steps that cannot be done purely in the objects.

This is because some data elements need uniqueness across the whole configuration, etc.

Warning: this function will call _WriteConfig(), but also DropECReservations so it needs to be called only from a "safe" place (the constructor). If one wanted to call it with the lock held, a DropECReservationUnlocked would need to be created first, to avoid causing deadlock.

_DistributeConfig(self, feedback_fn)

source code 

Distribute the configuration to the other nodes.

Currently, this only copies the configuration file. In the future, it could be used to encapsulate the 2/3-phase update mechanism.

_UnlockedGetSsconfValues(self)

source code 

Return the values needed by ssconf.

Returns: dict
a dictionary with keys the ssconf names and values their associated value

GetVGName(self)

source code 

Return the volume group name.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

SetVGName(self, vg_name)

source code 

Set the volume group name.

Decorators:
  • @locking.ssynchronized(_config_lock)

GetDRBDHelper(self)

source code 

Return DRBD usermode helper.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

SetDRBDHelper(self, drbd_helper)

source code 

Set DRBD usermode helper.

Decorators:
  • @locking.ssynchronized(_config_lock)

GetMACPrefix(self)

source code 

Return the mac prefix.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

GetClusterInfo(self)

source code 

Returns information about the cluster

Returns: objects.Cluster
the cluster object
Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

HasAnyDiskOfType(self, dev_type)

source code 

Check if in there is at disk of the given type in the configuration.

Decorators:
  • @locking.ssynchronized(_config_lock, shared= 1)

Update(self, target, feedback_fn)

source code 

Notify function to be called after updates.

This function must be called when an object (as returned by GetInstanceInfo, GetNodeInfo, GetCluster) has been updated and the caller wants the modifications saved to the backing store. Note that all modified objects will be saved, but the target argument is the one the caller wants to ensure that it's saved.

Parameters:
Decorators:
  • @locking.ssynchronized(_config_lock)

DropECReservations(self, ec_id)

source code 

Drop per-execution-context reservations

Decorators:
  • @locking.ssynchronized(_config_lock)