summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-rpc-ops.c39
-rw-r--r--cli/src/cli-xml-output.c47
2 files changed, 86 insertions, 0 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index ee7d3b2c841..b7c6691abd5 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -215,6 +215,31 @@ out:
}
int
+gf_cli_output_peer_hostnames (dict_t *dict, int count, char *prefix)
+{
+ int ret = -1;
+ char key[256] = {0,};
+ int i = 0;
+ char *hostname = NULL;
+
+ cli_out ("Other names:");
+ /* Starting from friend.hostname1, as friend.hostname0 will be the same
+ * as friend.hostname
+ */
+ for (i = 1; i < count; i++) {
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "%s.hostname%d", prefix, i);
+ ret = dict_get_str (dict, key, &hostname);
+ if (ret)
+ break;
+ cli_out ("%s", hostname);
+ hostname = NULL;
+ }
+
+ return ret;
+}
+
+int
gf_cli_output_peer_status (dict_t *dict, int count)
{
int ret = -1;
@@ -225,6 +250,7 @@ gf_cli_output_peer_status (dict_t *dict, int count)
char *state = NULL;
int32_t connected = 0;
char *connected_str = NULL;
+ int hostname_count = 0;
cli_out ("Number of Peers: %d", count);
i = 1;
@@ -256,6 +282,19 @@ gf_cli_output_peer_status (dict_t *dict, int count)
cli_out ("\nHostname: %s\nUuid: %s\nState: %s (%s)",
hostname_buf, uuid_buf, state, connected_str);
+
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "friend%d.hostname_count", i);
+ ret = dict_get_int32 (dict, key, &hostname_count);
+ /* Print other addresses only if there are more than 1.
+ */
+ if ((ret == 0) && (hostname_count > 1)) {
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "friend%d", i);
+ ret = gf_cli_output_peer_hostnames (dict,
+ hostname_count,
+ key);
+ }
i++;
}
diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c
index dd38a51c6c0..78d131583e9 100644
--- a/cli/src/cli-xml-output.c
+++ b/cli/src/cli-xml-output.c
@@ -3018,6 +3018,41 @@ out:
#endif
}
+#if (HAVE_LIB_XML)
+static int
+cli_xml_output_peer_hostnames (xmlTextWriterPtr writer, dict_t *dict,
+ const char *prefix, int count)
+{
+ int ret = -1;
+ int i = 0;
+ char *hostname = NULL;
+ char key[1024] = {0,};
+
+ /* <hostnames> */
+ ret = xmlTextWriterStartElement (writer, (xmlChar *)"hostnames");
+ XML_RET_CHECK_AND_GOTO (ret, out);
+
+ for (i = 0; i < count; i++) {
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "%s.hostname%d", prefix, i);
+ ret = dict_get_str (dict, key, &hostname);
+ if (ret)
+ goto out;
+ ret = xmlTextWriterWriteFormatElement
+ (writer, (xmlChar *)"hostname", "%s", hostname);
+ XML_RET_CHECK_AND_GOTO (ret, out);
+ hostname = NULL;
+ }
+
+ /* </hostnames> */
+ ret = xmlTextWriterEndElement (writer);
+
+out:
+ gf_log ("cli", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+#endif
+
int
cli_xml_output_peer_status (dict_t *dict, int op_ret, int op_errno,
char *op_errstr)
@@ -3032,6 +3067,7 @@ cli_xml_output_peer_status (dict_t *dict, int op_ret, int op_errno,
int connected = 0;
int state_id = 0;
char *state_str = NULL;
+ int hostname_count = 0;
int i = 1;
char key[1024] = {0,};
@@ -3082,6 +3118,17 @@ cli_xml_output_peer_status (dict_t *dict, int op_ret, int op_errno,
XML_RET_CHECK_AND_GOTO (ret, out);
memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "friend%d.hostname_count", i);
+ ret = dict_get_int32 (dict, key, &hostname_count);
+ if ((ret == 0) && (hostname_count > 0)) {
+ memset (key, 0, sizeof (key));
+ snprintf (key, sizeof (key), "friend%d", i);
+ ret = cli_xml_output_peer_hostnames (writer, dict, key,
+ hostname_count);
+ XML_RET_CHECK_AND_GOTO (ret, out);
+ }
+
+ memset (key, 0, sizeof (key));
snprintf (key, sizeof (key), "friend%d.connected", i);
ret = dict_get_int32 (dict, key, &connected);
if (ret)