summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2012-07-17 21:15:57 +1000
committerMartin Schwenke <martin@meltin.net>2012-09-28 17:05:34 +1000
commit860d75747598d68c16594244d3140994093cc965 (patch)
tree40b380a063b48b4fb994b66822a5c799c5d46647
parentbd0e34a9fdfd0eb9141f2dd9a5f9a880927a85e6 (diff)
downloadsamba-860d75747598d68c16594244d3140994093cc965.tar.gz
samba-860d75747598d68c16594244d3140994093cc965.tar.xz
samba-860d75747598d68c16594244d3140994093cc965.zip
tools/ctdb: natgwlist output is either human readable or machine readable
The first line is currently human readable and the rest is machine readable. This doesn't make sense. Do one or the other... Signed-off-by: Martin Schwenke <martin@meltin.net> (This used to be ctdb commit b29d5bbaa7048291c4b3a39bf12e04f0436f67da)
-rw-r--r--ctdb/tools/ctdb.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index edf8d065d4..bc6c11b88f 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -1001,6 +1001,8 @@ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **a
struct natgw_node *natgw_nodes = NULL;
struct natgw_node *natgw_node;
struct ctdb_node_map *nodemap=NULL;
+ uint32_t mypnn;
+ const char *fmt;
/* read the natgw nodes file into a linked list */
@@ -1066,7 +1068,14 @@ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **a
}
i++;
- }
+ }
+
+ if (options.machinereadable) {
+ printf(":Node:IP:\n");
+ fmt = ":%d:%s:\n";
+ } else {
+ fmt = "%d %s\n";
+ }
/* pick a node to be natgwmaster
* we dont allow STOPPED, DELETED, BANNED or UNHEALTHY nodes to become the natgwmaster
@@ -1081,7 +1090,7 @@ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **a
if (!(capabilities&CTDB_CAP_NATGW)) {
continue;
}
- printf("%d %s\n", nodemap->nodes[i].pnn,ctdb_addr_to_str(&nodemap->nodes[i].addr));
+ printf(fmt, nodemap->nodes[i].pnn,ctdb_addr_to_str(&nodemap->nodes[i].addr));
break;
}
}
@@ -1097,7 +1106,7 @@ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **a
if (!(capabilities&CTDB_CAP_NATGW)) {
continue;
}
- printf("%d %s\n", nodemap->nodes[i].pnn,ctdb_addr_to_str(&nodemap->nodes[i].addr));
+ printf(fmt, nodemap->nodes[i].pnn,ctdb_addr_to_str(&nodemap->nodes[i].addr));
break;
}
}
@@ -1114,29 +1123,36 @@ static int control_natgwlist(struct ctdb_context *ctdb, int argc, const char **a
if (!(capabilities&CTDB_CAP_NATGW)) {
continue;
}
- printf("%d %s\n", nodemap->nodes[i].pnn, ctdb_addr_to_str(&nodemap->nodes[i].addr));
+ printf(fmt, nodemap->nodes[i].pnn, ctdb_addr_to_str(&nodemap->nodes[i].addr));
break;
}
}
/* or if we still can not find any */
if (i == nodemap->num) {
- printf("-1 0.0.0.0\n");
+ printf(fmt, -1, "0.0.0.0");
ret = 2; /* matches ENOENT */
}
}
/* print the pruned list of nodes belonging to this natgw list */
+ if (!ctdb_getpnn(ctdb_connection, options.pnn, &mypnn)) {
+ DEBUG(DEBUG_ERR, ("Unable to get PNN from node %u\n", options.pnn));
+ return -1;
+ }
+ if (options.machinereadable) {
+ control_status_header_machine();
+ } else {
+ printf("Number of nodes:%d\n", nodemap->num);
+ }
for(i=0;i<nodemap->num;i++){
if (nodemap->nodes[i].flags & NODE_FLAGS_DELETED) {
continue;
}
- printf(":%d:%s:%d:%d:%d:%d:%d\n", nodemap->nodes[i].pnn,
- ctdb_addr_to_str(&nodemap->nodes[i].addr),
- !!(nodemap->nodes[i].flags&NODE_FLAGS_DISCONNECTED),
- !!(nodemap->nodes[i].flags&NODE_FLAGS_BANNED),
- !!(nodemap->nodes[i].flags&NODE_FLAGS_PERMANENTLY_DISABLED),
- !!(nodemap->nodes[i].flags&NODE_FLAGS_UNHEALTHY),
- !!(nodemap->nodes[i].flags&NODE_FLAGS_STOPPED));
+ if (options.machinereadable) {
+ control_status_1_machine(mypnn, &(nodemap->nodes[i]));
+ } else {
+ control_status_1_human(mypnn, &(nodemap->nodes[i]));
+ }
}
return ret;