00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "asterisk.h"
00032
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 294535 $");
00034
00035 #include <stdlib.h>
00036 #include <stdio.h>
00037 #include <string.h>
00038 #include <unistd.h>
00039 #include <errno.h>
00040
00041 #include "ais.h"
00042
00043 #include "asterisk/module.h"
00044 #include "asterisk/utils.h"
00045 #include "asterisk/cli.h"
00046 #include "asterisk/logger.h"
00047
00048 SaClmHandleT clm_handle;
00049 static SaAisErrorT clm_init_res;
00050
00051 static void clm_node_get_cb(SaInvocationT invocation,
00052 const SaClmClusterNodeT *cluster_node, SaAisErrorT error);
00053 static void clm_track_cb(const SaClmClusterNotificationBufferT *notif_buffer,
00054 SaUint32T num_members, SaAisErrorT error);
00055
00056 static const SaClmCallbacksT clm_callbacks = {
00057 .saClmClusterNodeGetCallback = clm_node_get_cb,
00058 .saClmClusterTrackCallback = clm_track_cb,
00059 };
00060
00061 static void clm_node_get_cb(SaInvocationT invocation,
00062 const SaClmClusterNodeT *cluster_node, SaAisErrorT error)
00063 {
00064
00065 }
00066
00067 static void clm_track_cb(const SaClmClusterNotificationBufferT *notif_buffer,
00068 SaUint32T num_members, SaAisErrorT error)
00069 {
00070
00071 }
00072
00073 static char *ais_clm_show_members(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
00074 {
00075 int i;
00076 SaClmClusterNotificationBufferT buf;
00077 SaClmClusterNotificationT notif[64];
00078 SaAisErrorT ais_res;
00079
00080 switch (cmd) {
00081 case CLI_INIT:
00082 e->command = "ais clm show members";
00083 e->usage =
00084 "Usage: ais clm show members\n"
00085 " List members of the cluster using the CLM (Cluster Membership) service.\n";
00086 return NULL;
00087
00088 case CLI_GENERATE:
00089 return NULL;
00090 }
00091
00092 if (a->argc != e->args)
00093 return CLI_SHOWUSAGE;
00094
00095 buf.notification = notif;
00096 buf.numberOfItems = ARRAY_LEN(notif);
00097
00098 ais_res = saClmClusterTrack(clm_handle, SA_TRACK_CURRENT, &buf);
00099 if (ais_res != SA_AIS_OK) {
00100 ast_cli(a->fd, "Error retrieving current cluster members.\n");
00101 return CLI_FAILURE;
00102 }
00103
00104 ast_cli(a->fd, "\n"
00105 "=============================================================\n"
00106 "=== Cluster Members =========================================\n"
00107 "=============================================================\n"
00108 "===\n");
00109
00110 for (i = 0; i < buf.numberOfItems; i++) {
00111 SaClmClusterNodeT *node = &buf.notification[i].clusterNode;
00112
00113 ast_cli(a->fd, "=== ---------------------------------------------------------\n"
00114 "=== Node Name: %s\n"
00115 "=== ==> ID: 0x%x\n"
00116 "=== ==> Address: %s\n"
00117 "=== ==> Member: %s\n",
00118 (char *) node->nodeName.value, (int) node->nodeId,
00119 (char *) node->nodeAddress.value,
00120 node->member ? "Yes" : "No");
00121
00122 ast_cli(a->fd, "=== ---------------------------------------------------------\n"
00123 "===\n");
00124 }
00125
00126 ast_cli(a->fd, "=============================================================\n"
00127 "\n");
00128
00129 return CLI_SUCCESS;
00130 }
00131
00132 static struct ast_cli_entry ais_cli[] = {
00133 AST_CLI_DEFINE(ais_clm_show_members, "List current members of the cluster"),
00134 };
00135
00136 int ast_ais_clm_load_module(void)
00137 {
00138 clm_init_res = saClmInitialize(&clm_handle, &clm_callbacks, &ais_version);
00139 if (clm_init_res != SA_AIS_OK) {
00140 ast_log(LOG_ERROR, "Could not initialize cluster membership service: %s\n",
00141 ais_err2str(clm_init_res));
00142 return -1;
00143 }
00144
00145 ast_cli_register_multiple(ais_cli, ARRAY_LEN(ais_cli));
00146
00147 return 0;
00148 }
00149
00150 int ast_ais_clm_unload_module(void)
00151 {
00152 SaAisErrorT ais_res;
00153
00154 if (clm_init_res != SA_AIS_OK) {
00155 return 0;
00156 }
00157
00158 ast_cli_unregister_multiple(ais_cli, ARRAY_LEN(ais_cli));
00159
00160 ais_res = saClmFinalize(clm_handle);
00161 if (ais_res != SA_AIS_OK) {
00162 ast_log(LOG_ERROR, "Problem stopping cluster membership service: %s\n",
00163 ais_err2str(ais_res));
00164 return -1;
00165 }
00166
00167 return 0;
00168 }