Skip to content

Commit

Permalink
Added support for printing out full configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
feist committed Sep 25, 2012
1 parent 6438216 commit af8f02b
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 7 deletions.
17 changes: 17 additions & 0 deletions pcs/cluster.py
Expand Up @@ -7,6 +7,9 @@
import sys
import getpass
import status
import prop
import resource
import constraint

pcs_dir = os.path.dirname(os.path.realpath(__file__))
COROSYNC_CONFIG_TEMPLATE = pcs_dir + "/corosync.conf.template"
Expand Down Expand Up @@ -414,3 +417,17 @@ def cluster_get_corosync_conf(argv):
node = argv[0]
retval, output = utils.getCorosyncConfig(node)
print output

def print_config():
status.nodes_status(["config"])
print ""
print ""
print "Resources: "
utils.pcs_options["--all"] = 1
resource.resource_show([])
print ""
constraint.location_show([])
constraint.order_show([])
constraint.colocation_show([])
print ""
prop.list_property([])
2 changes: 2 additions & 0 deletions pcs/pcs.py
Expand Up @@ -77,6 +77,8 @@ def main(argv):
constraint.constraint_cmd(argv)
elif (command == "status"):
status.status_cmd(argv)
elif (command == "config"):
cluster.print_config()
else:
usage.main()
sys.exit(1)
Expand Down
3 changes: 2 additions & 1 deletion pcs/prop.py
Expand Up @@ -50,6 +50,7 @@ def list_property(argv):
dom = parseString(output)
de = dom.documentElement
properties = de.getElementsByTagName("nvpair")
print "Cluster Properties:"
for prop in properties:
if print_all == True or (argv[0] == prop.getAttribute("name")):
print prop.getAttribute("name") + ": " + prop.getAttribute("value")
print " " + prop.getAttribute("name") + ": " + prop.getAttribute("value")
67 changes: 66 additions & 1 deletion pcs/resource.py
Expand Up @@ -7,7 +7,7 @@
import utils
import re
import textwrap
import xml.etree.ElementTree
import xml.etree.ElementTree as ET
import constraint

def resource_cmd(argv):
Expand Down Expand Up @@ -887,6 +887,13 @@ def resource_group_list(argv):
print ""

def resource_show(argv):
if "--all" in utils.pcs_options:
root = utils.get_cib_etree()
resources = root.find(".//resources")
for child in resources:
print_node(child,1)
return

if len(argv) == 0:
args = ["crm_resource","-L"]
output,retval = utils.run(args)
Expand Down Expand Up @@ -992,3 +999,61 @@ def set_default(def_type, argv):
print "Invalid Property: " + arg
continue
utils.setAttribute(def_type, args[0], args[1])

def print_node(node, tab = 0):
spaces = " " * tab
if node.tag == "group":
print spaces + "Group: " + node.attrib["id"] + get_attrs(node,' (',')')
ivar_string = get_instance_vars_string(node)
if ivar_string != "":
print spaces + " " + get_instance_vars_string(node)
for child in node:
print_node(child, tab + 1)
if node.tag == "clone":
print spaces + "Clone: " + node.attrib["id"] + get_attrs(node,' (',')')
ivar_string = get_instance_vars_string(node)
if ivar_string != "":
print spaces + " " + get_instance_vars_string(node)
for child in node:
print_node(child, tab + 1)
if node.tag == "primitive":
print spaces + "Resource: " + node.attrib["id"] + get_attrs(node,' (',')')
ivar_string = get_instance_vars_string(node)
if ivar_string != "":
print spaces + " Attributes: " + get_instance_vars_string(node)
ops_string = get_operations(node)
if ops_string != "":
print spaces + " Operations: " + ops_string
for child in node:
print_node(child, tab + 1)

def get_instance_vars_string(node):
output = ""
ivars = node.findall("instance_attributes/nvpair")
for ivar in ivars:
output += ivar.attrib["name"] + "=" + ivar.attrib["value"] + " "

return output

def get_operations(node):
output = ""
ops = node.findall("operations/op")
for op in ops:
output += op.attrib["name"] + " "
for attr,val in op.attrib.items():
if attr in ["id","name"] :
continue
output += attr + "=" + val + " "
return output.rstrip()

def get_attrs(node, prepend_string = "", append_string = ""):
output = ""
for attr,val in node.attrib.items():
if attr in ["id"]:
continue
output += attr + "=" + val + " "
if output != "":
return prepend_string + output.rstrip() + append_string
else:
return output.rstrip()

15 changes: 15 additions & 0 deletions pcs/status.py
Expand Up @@ -51,6 +51,21 @@ def actions_status(argv):

# Parse crm_mon for status
def nodes_status(argv):
if len(argv) == 1 and (argv[0] == "config"):
corosync_nodes = utils.getNodesFromCorosyncConf()
pacemaker_nodes = utils.getNodesFromPacemaker()
print "Corosync Nodes:"
print "",
for node in corosync_nodes:
print node.strip(),
print ""
print "Pacemaker Nodes:"
print "",
for node in pacemaker_nodes:
print node.strip(),

return

if len(argv) == 1 and (argv[0] == "corosync" or argv[0] == "both"):
all_nodes = utils.getNodesFromCorosyncConf()
online_nodes = utils.getCorosyncActiveNodes()
Expand Down
14 changes: 9 additions & 5 deletions pcs/usage.py
Expand Up @@ -14,16 +14,18 @@ def main():
property Set pacemaker properties
constraint Set resource constraints
status View cluster status
config Print full cluster configuration
"""

def resource():
print """
Usage: pcs resource [commands]...
Manage pacemaker resources
Commands:
show [resource_id]
show [resource_id] [--all]
Show all currently configured resources or if a resource is specified
show the options for the configured resource
show the options for the configured resource. If --all is specified
resource options will be displayed
start <resource_id>
Start resource specified by resource_id
Expand Down Expand Up @@ -364,9 +366,11 @@ def status():
status corosync
View current corosync status
status nodes [corosync]
View current status of nodes from pacemaker, or if corosync is
specified, print nodes currently configured in corosync
status nodes [corosync|both|config]
View current status of nodes from pacemaker. If 'corosync' is
specified, print nodes currently configured in corosync, if 'both'
is specified, print nodes from both corosync & pacemaker. If 'config'
is specified, print nodes from corosync & pacemaker configuration.
status actions
View failed actions
Expand Down
18 changes: 18 additions & 0 deletions pcs/utils.py
Expand Up @@ -4,6 +4,7 @@
import xml.dom.minidom
import urllib,urllib2
from xml.dom.minidom import parseString
import xml.etree.ElementTree as ET
import re
import json

Expand Down Expand Up @@ -151,6 +152,15 @@ def getNodesFromCorosyncConf():

return nodes

def getNodesFromPacemaker():
ret_nodes = []
root = get_cib_etree()
nodes = root.findall(".//node")
for node in nodes:
ret_nodes.append(node.attrib["uname"])
ret_nodes.sort()
return ret_nodes

def getCorosyncConf(conf='/etc/corosync/corosync.conf'):
try:
out = open(conf).read()
Expand Down Expand Up @@ -364,6 +374,14 @@ def get_cib_dom():
print "Error: unable to get cib"
sys.exit(1)

def get_cib_etree():
try:
root = ET.fromstring(get_cib())
return root
except:
print "Error: unable to get cib"
sys.exit(1)

# Replace only configuration section of cib with dom passed
def replace_cib_configuration(dom):
output, retval = run(["cibadmin", "--replace", "-o", "configuration", "-X", dom.toxml()])
Expand Down

0 comments on commit af8f02b

Please sign in to comment.