tools/ctdb: add "ctdb ipinfo <ip>"
authorStefan Metzmacher <metze@samba.org>
Thu, 17 Dec 2009 10:23:59 +0000 (11:23 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 20 Jan 2010 10:11:00 +0000 (11:11 +0100)
metze

tools/ctdb.c

index 4e5cc036a05df8f5a2bd705a368ca8f9c1ed28bc..5c49dbaa77790eea9f6861c7f28fdef805aad392 100644 (file)
@@ -1679,6 +1679,58 @@ static int control_ip(struct ctdb_context *ctdb, int argc, const char **argv)
        return 0;
 }
 
+/*
+  public ip info
+ */
+static int control_ipinfo(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       int i, ret;
+       ctdb_sock_addr addr;
+       TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
+       struct ctdb_control_public_ip_info *info;
+
+       if (argc != 1) {
+               talloc_free(tmp_ctx);
+               usage();
+       }
+
+       if (parse_ip(argv[0], NULL, 0, &addr) == 0) {
+               DEBUG(DEBUG_ERR,("Wrongly formed ip address '%s'\n", argv[0]));
+               return -1;
+       }
+
+       /* read the public ip info from this node */
+       ret = ctdb_ctrl_get_public_ip_info(ctdb, TIMELIMIT(), options.pnn,
+                                          tmp_ctx, &addr, &info);
+       if (ret != 0) {
+               DEBUG(DEBUG_ERR, ("Unable to get public ip[%s]info from node %u\n",
+                                 argv[0], options.pnn));
+               talloc_free(tmp_ctx);
+               return ret;
+       }
+
+       printf("Public IP[%s] info on node %u\n",
+              ctdb_addr_to_str(&info->ip.addr),
+              options.pnn);
+
+       printf("IP:%s\nCurrentNode:%d\nNumInterfaces:%u\n",
+              ctdb_addr_to_str(&info->ip.addr),
+              info->ip.pnn, info->num);
+
+       for (i=0; i<info->num; i++) {
+               info->ifaces[i].name[CTDB_IFACE_SIZE] = '\0';
+
+               printf("Interface[%u]: Name:%s Link:%s References:%u%s\n",
+                      i+1, info->ifaces[i].name,
+                      info->ifaces[i].link_state?"up":"down",
+                      (unsigned int)info->ifaces[i].references,
+                      (i==info->active_idx)?" (active)":"");
+       }
+
+       talloc_free(tmp_ctx);
+       return 0;
+}
+
 /*
   display interfaces status
  */
@@ -4096,6 +4148,7 @@ static const struct {
        { "statistics",      control_statistics,        false,  false, "show statistics" },
        { "statisticsreset", control_statistics_reset,  true,   false,  "reset statistics"},
        { "ip",              control_ip,                false,  false,  "show which public ip's that ctdb manages" },
+       { "ipinfo",          control_ipinfo,            true,   false,  "show details about a public ip that ctdb manages", "<ip>" },
        { "ifaces",          control_ifaces,            true,   false,  "show which interfaces that ctdb manages" },
        { "setifacelink",    control_setifacelink,      true,   false,  "set interface link status", "<iface> <status>" },
        { "process-exists",  control_process_exists,    true,   false,  "check if a process exists on a node",  "<pid>"},