Permalink
Browse files

Added support for printing out full configuration

  • Loading branch information...
1 parent 6438216 commit af8f02b04e222e1c877a299ab7e8fb42d2061253 @feist feist committed Sep 25, 2012
Showing with 129 additions and 7 deletions.
  1. +17 −0 pcs/cluster.py
  2. +2 −0 pcs/pcs.py
  3. +2 −1 pcs/prop.py
  4. +66 −1 pcs/resource.py
  5. +15 −0 pcs/status.py
  6. +9 −5 pcs/usage.py
  7. +18 −0 pcs/utils.py
View
@@ -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"
@@ -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([])
View
@@ -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)
View
@@ -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")
View
@@ -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):
@@ -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)
@@ -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()
+
View
@@ -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()
View
@@ -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
@@ -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
View
@@ -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
@@ -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()
@@ -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()])

0 comments on commit af8f02b

Please sign in to comment.