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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#
#
# pingd OCF Resource Agent
# Records (in the CIB) the current number of ping nodes a
# cluster node can connect to.
#
# Copyright (c) 2006 Andrew Beekhof
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like. Any license provided herein, whether implied or
# otherwise, applies only to this software file. Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
#######################################################################
import crm_utils as utl
class HelpRequest(Exception):
"""Exception raised when a help listing is required."""
class ReparseRequest(Exception):
"""Exception raised when a command changed the command-line."""
def up(*args, **cmdoptions):
l = len(utl.topic_stack)
if l > 1:
utl.topic_stack.pop()
utl.set_topic(utl.topic_stack[-1])
else:
utl.log_debug("Already at the top of the stack")
def toggle_flag(*args, **cmdoptions):
flag = cmdoptions["flag"]
if utl.global_opts[flag]:
utl.global_opts[flag] = 0
else:
utl.global_opts[flag] = 1
return utl.global_opts[flag]
def cd_(*args, **cmdoptions):
utl.log_dev("args: %s\nopts: %s" % (repr(args), repr(cmdoptions)))
if not cmdoptions["topic"]:
utl.log_err("No topic specified")
return 1
if cmdoptions["topic"]:
utl.set_topic(cmdoptions["topic"])
if args:
raise ReparseRequest()
if utl.crm_topic not in utl.topic_stack:
utl.topic_stack.append(cmdoptions["topic"])
if not utl.global_opts["interactive"]:
help(cmdoptions["topic"])
return 0
def exit(*args, **cmdoptions):
sys.exit(0)
def help(*args, **cmdoptions):
if args:
raise HelpRequest(args[0])
raise HelpRequest(utl.crm_topic)
def debugstate(*args, **cmdoptions):
utl.log_info("Global Options: ")
for opt in utl.global_opts.keys():
utl.log_info(" * %s:\t%s" % (opt, utl.global_opts[opt]))
utl.log_info("Stack: "+repr(utl.topic_stack))
utl.log_info("Stack Head: "+utl.crm_topic)
return 0
def do_list(*args, **cmdoptions):
topic = utl.crm_topic
if cmdoptions.has_key("topic") and cmdoptions["topic"]:
topic = cmdoptions["topic"]
utl.log_debug("Complete '%s' listing" % topic)
if topic == "resources":
utl.os_system("crm_resource -l", True)
elif topic == "nodes":
lines = utl.os_system("cibadmin -Q -o nodes", False)
for line in lines:
if line.find("node ") >= 0:
print line.rstrip()
else:
utl.log_err("%s: Topic %s is not (yet) supported" % ("list", topic))
return 1
return 0
def do_status(*args, **cmdoptions):
topic = utl.crm_topic
if cmdoptions.has_key("topic") and cmdoptions["topic"]:
topic = cmdoptions["topic"]
if topic == "resources":
if not args:
utl.os_system("crm_resource -L", True)
for rsc in args:
utl.os_system("crm_resource -W -r %s"%rsc, True)
elif topic == "nodes":
lines = utl.os_system("cibadmin -Q -o status", False)
for line in lines:
line = line.rstrip()
utl.log_dev("status line: "+line)
if line.find("node_state ") >= 0:
if not args:
print line
for node in args:
if line.find(node) >= 0:
print line
else:
utl.log_err("Topic %s is not (yet) supported" % topic)
return 1
return 0
|