Skip to content

Commit

Permalink
Medium: fencing: stonithd: add metadata for stonithd instance attribu…
Browse files Browse the repository at this point in the history
…tes (and support in the shell)

Mercurial revision: 96db6aca5735a1dfb254ae60626121cdd7b94edf
  • Loading branch information
dmuhamedagic committed Nov 16, 2009
1 parent 172715e commit 2238424
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
29 changes: 27 additions & 2 deletions fencing/stonithd/stonithd.c
Expand Up @@ -104,6 +104,7 @@
#include <crm/crm.h>
#include <crm/common/cluster.h>
#include <crm/common/xml.h>
#include <crm/common/util.h>

#undef CL_DROP_PRIVS
#ifndef CL_DROP_PRIVS
Expand Down Expand Up @@ -345,6 +346,7 @@ static stonith_ops_t * new_stonith_ops_t(struct ha_msg * request);
static void free_stonith_ops_t(stonith_ops_t * st_op);
static void free_common_op_t(gpointer data);
static void free_stonith_rsc(stonith_rsc_t * srsc);
static void stonithd_metadata(void);
static stonith_rsc_t * get_started_stonith_resource(const char * rsc_id);
static stonith_rsc_t * get_local_stonithobj_can_stonith(const char * node_name,
const char * begin_rsc_id );
Expand Down Expand Up @@ -425,8 +427,16 @@ static const char * M_STARTUP = "start up successfully.",
* M_STONITH_SUCCEED = "Succeeded to STONITH the node",
* M_STONITH_FAIL = "Failed to STONITH the node";

pe_cluster_option stonithd_opts[] = {
/* name, old-name, validate, default, description */
{ "stonith-timeout", NULL, "time", NULL, "60s", &check_timer,
"How long to wait for the STONITH action to complete. Overrides the stonith-timeout cluster property", NULL },
{ "priority", NULL, "integer", NULL, "0", &check_number,
"The priority of the stonith resource. The lower the number, the higher the priority.", NULL },
};

static const char * simple_help_screen =
"Usage: stonithd [-ahikrsv]\n"
"Usage: stonithd [[-ahikrsv] | metadata]\n"
" -a Start up alone outside of heartbeat.\n"
" By default suppose it be started up and monitored by heartbeat.\n"
" -h This help information\n"
Expand All @@ -435,7 +445,8 @@ static const char * simple_help_screen =
" -r Register to apphbd. Now not register to apphbd by default.\n"
" -s Show the status of the daemons.\n"
" -v Run the stonithd in debug mode. Under debug mode more\n"
" debug information is written to log file.\n";
" debug information is written to log file.\n"
" metadata print stonithd metadata.\n";
/* -t Test mode only.\n" */

static const char * optstr = "ahi:krsvt";
Expand Down Expand Up @@ -578,6 +589,15 @@ init_hb_msg_handler(void)
}
#endif

static void
stonithd_metadata(void)
{
config_metadata("stonithd", "1.0",
"stonithd Options",
"This is a fake resource that details the instance attributes handled by stonithd.",
stonithd_opts, DIMOF(stonithd_opts));
}

int
main(int argc, char ** argv)
{
Expand Down Expand Up @@ -665,6 +685,11 @@ main(int argc, char ** argv)
}
} while (1);

if(argc - optind == 1 && safe_str_eq("metadata", argv[optind])) {
(void)stonithd_metadata();
return 0;
}

cl_inherit_logging_environment(0);

if (cl_read_pidfile(STD_PIDFILE) > 0 ) {
Expand Down
27 changes: 20 additions & 7 deletions tools/crm.in
Expand Up @@ -420,14 +420,14 @@ def lrmadmin(opts, xml = False):
if not xml:
l = l[1:] # skip the first line
return l
def pengine_meta():
def prog_meta(s):
'''
Do pengine metadata.
Do external program metadata.
'''
pengine = "@CRM_DAEMON_DIR@/pengine"
prog = "@CRM_DAEMON_DIR@/%s" % s
l = []
if is_program(pengine):
l = stdin2list("%s metadata" % pengine)
if is_program(prog):
l = stdin2list("%s metadata" % prog)
return l
def get_nodes_text(n,tag):
try:
Expand Down Expand Up @@ -558,6 +558,16 @@ class RAInfo(object):
common_err("%s: %s" % (self.ra_string(), s))
def warn(self, s):
common_warn("%s: %s" % (self.ra_string(), s))
def add_extra_stonith_params(self):
if not self.ra_node or not stonithd_metadata.ra_node:
return
try:
params_node = self.doc.getElementsByTagName("parameters")[0]
except:
params_node = self.doc.createElement("parameters")
self.ra_node.appendChild(params_node)
for n in stonithd_metadata.ra_node.getElementsByTagName("parameter"):
params_node.appendChild(self.doc.importNode(n,1))
def mk_ra_node(self):
'''
Return the resource_agent node.
Expand All @@ -575,6 +585,8 @@ class RAInfo(object):
except:
self.error("meta-data contains no resource-agent element")
self.ra_node = None
if self.ra_class == "stonith":
self.add_extra_stonith_params()
def param_type_default(self,n):
try:
content = n.getElementsByTagName("content")[0]
Expand Down Expand Up @@ -714,8 +726,8 @@ class RAInfo(object):
id = "ra_meta-%s" % self.ra_string()
if wcache.is_cached(id):
return wcache.retrieve(id)
if self.ra_class == "pengine":
l = pengine_meta()
if self.ra_class in ("pengine","stonithd"):
l = prog_meta(self.ra_class)
else:
l = lrmadmin("-M %s %s %s" % (self.ra_class,self.ra_type,self.ra_provider),True)
return wcache.store(id, l)
Expand Down Expand Up @@ -7786,6 +7798,7 @@ cib_factory = CibFactory()
cib_status = CibStatus()
cli_display = CliDisplay()
pe_metadata = RAInfo("pengine","metadata")
stonithd_metadata = RAInfo("stonithd","metadata")
tmpfiles = []

def load_rc(rcfile):
Expand Down

0 comments on commit 2238424

Please sign in to comment.