/usr/share/system-config-lvm/Cluster.py is in system-config-lvm 1.1.16-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | from execute import execWithCapture, execWithCaptureErrorStatus, execWithCaptureStatus, execWithCaptureProgress, execWithCaptureErrorStatusProgress, execWithCaptureStatusProgress
from CommandError import *
import xml
import xml.dom
from xml.dom import minidom
import os
class Cluster:
cluster_name = None
cluster_lock = None
cluster_nodes = None
cluster_conf_mtime = None
def __init__(self):
return
def get_name(self):
return self.__get_info()[0]
def get_lock_type(self):
return self.__get_info()[1]
def get_nodes_num(self):
return self.__get_info()[2]
def __get_info(self):
try:
mtime = os.stat('/etc/cluster/cluster.conf').st_mtime
except:
return (None, None, None)
if Cluster.cluster_conf_mtime != None and Cluster.cluster_conf_mtime == mtime:
return (Cluster.cluster_name, Cluster.cluster_lock, Cluster.cluster_nodes)
else:
Cluster.cluster_conf_mtime = mtime
try:
c_conf = minidom.parseString(file('/etc/cluster/cluster.conf').read(10000000)).firstChild
name = c_conf.getAttribute('name')
lock = 'dlm'
nodes_num = 0
for node in c_conf.childNodes:
if node.nodeType == xml.dom.Node.ELEMENT_NODE:
if node.nodeName == 'cman':
lock = 'dlm'
elif node.nodeName == 'gulm':
lock = 'gulm'
elif node.nodeName == 'clusternodes':
nodes = node
for node in nodes.childNodes:
if node.nodeType == xml.dom.Node.ELEMENT_NODE:
if node.nodeName == 'clusternode':
nodes_num += 1
if nodes_num != 0:
Cluster.cluster_name = name
Cluster.cluster_lock = lock
Cluster.cluster_nodes = nodes_num
except:
Cluster.cluster_name = None
Cluster.cluster_lock = None
Cluster.cluster_nodes = None
return (Cluster.cluster_name, Cluster.cluster_lock, Cluster.cluster_nodes)
def running(self):
if self.get_name() == None:
return False
try:
# try magma_tool
args = ['/sbin/magma_tool', 'quorum']
o, e, s = execWithCaptureErrorStatus('/sbin/magma_tool', args)
if s == 0:
if o.find('Quorate') != -1:
return True
except:
pass
try:
# try cman_tool
cman_tool_path = '/sbin/cman_tool'
if os.access(cman_tool_path, os.X_OK) == False:
cman_tool_path = '/usr/sbin/cman_tool'
args = [cman_tool_path, 'status']
o, e, s = execWithCaptureErrorStatus(cman_tool_path, args)
if s != 0:
return False
quorum = -1
votes = -1
lines = o.splitlines()
for line in lines:
words = line.split()
if len(words) < 2:
continue
if words[0] == 'Quorum:':
quorum = int(words[1])
elif words[0] == 'Total_votes:':
votes = int(words[1])
if len(words) < 3:
continue
if words[0] == 'Total' and words[1] == 'votes:':
votes = int(words[2])
if quorum <= 0 or votes < 0:
raise 'Unable to retrieve cluster quorum info'
return votes >= quorum
except:
return False
|