@@ -143,6 +143,30 @@ remove_cb(const gchar *option_name, const gchar *optarg, gpointer data, GError *
143
143
return TRUE;
144
144
}
145
145
146
+ PCMK__OUTPUT_ARGS ("node-id" , "uint32_t" )
147
+ static int
148
+ node_id_default (pcmk__output_t * out , va_list args ) {
149
+ uint32_t node_id = va_arg (args , uint32_t );
150
+
151
+ out -> info (out , "%" PRIu32 , node_id );
152
+ return pcmk_rc_ok ;
153
+ }
154
+
155
+ PCMK__OUTPUT_ARGS ("node-id" , "uint32_t" )
156
+ static int
157
+ node_id_xml (pcmk__output_t * out , va_list args ) {
158
+ uint32_t node_id = va_arg (args , uint32_t );
159
+
160
+ char * id_s = crm_strdup_printf ("%" PRIu32 , node_id );
161
+
162
+ pcmk__output_create_xml_node (out , "node-info" ,
163
+ "nodeid" , id_s ,
164
+ NULL );
165
+
166
+ free (id_s );
167
+ return pcmk_rc_ok ;
168
+ }
169
+
146
170
PCMK__OUTPUT_ARGS ("node-name" , "uint32_t" , "const char *" )
147
171
static int
148
172
node_name_default (pcmk__output_t * out , va_list args ) {
@@ -191,6 +215,8 @@ quorum_xml(pcmk__output_t *out, va_list args) {
191
215
}
192
216
193
217
static pcmk__message_entry_t fmt_functions [] = {
218
+ { "node-id" , "default" , node_id_default },
219
+ { "node-id" , "xml" , node_id_xml },
194
220
{ "node-name" , "default" , node_name_default },
195
221
{ "node-name" , "xml" , node_name_xml },
196
222
{ "quorum" , "default" , quorum_default },
@@ -242,23 +268,6 @@ controller_event_cb(pcmk_ipc_api_t *controld_api,
242
268
243
269
// Parse desired info from reply and display to user
244
270
switch (options .command ) {
245
- case 'i' :
246
- if (reply -> reply_type != pcmk_controld_reply_info ) {
247
- exit_code = CRM_EX_PROTOCOL ;
248
- g_set_error (& error , PCMK__EXITC_ERROR , exit_code ,
249
- "Unknown reply type %d from controller" ,
250
- reply -> reply_type );
251
- goto done ;
252
- }
253
- if (reply -> data .node_info .id == 0 ) {
254
- exit_code = CRM_EX_PROTOCOL ;
255
- g_set_error (& error , PCMK__EXITC_ERROR , exit_code ,
256
- "Controller reply did not contain node ID" );
257
- goto done ;
258
- }
259
- printf ("%d\n" , reply -> data .node_info .id );
260
- break ;
261
-
262
271
case 'l' :
263
272
case 'p' :
264
273
if (reply -> reply_type != pcmk_controld_reply_nodes ) {
@@ -352,6 +361,32 @@ run_controller_mainloop(uint32_t nodeid, bool list_nodes)
352
361
pcmk_free_ipc_api (controld_api );
353
362
}
354
363
364
+ static void
365
+ print_node_id (void )
366
+ {
367
+ uint32_t nodeid ;
368
+ int rc = pcmk__query_node_info (out , & nodeid , NULL , NULL , NULL , NULL , NULL ,
369
+ false, 0 );
370
+
371
+ if (rc != pcmk_rc_ok ) {
372
+ /* pcmk__query_node_info already sets an error message on the output object,
373
+ * so there's no need to call g_set_error here. That would just create a
374
+ * duplicate error message in the output.
375
+ */
376
+ exit_code = pcmk_rc2exitc (rc );
377
+ return ;
378
+ }
379
+
380
+ rc = out -> message (out , "node-id" , nodeid );
381
+
382
+ if (rc != pcmk_rc_ok ) {
383
+ g_set_error (& error , PCMK__RC_ERROR , rc , "Could not print node ID: %s" ,
384
+ pcmk_rc_str (rc ));
385
+ }
386
+
387
+ exit_code = pcmk_rc2exitc (rc );
388
+ }
389
+
355
390
static void
356
391
print_node_name (uint32_t nodeid )
357
392
{
@@ -705,6 +740,10 @@ main(int argc, char **argv)
705
740
pcmk__register_messages (out , fmt_functions );
706
741
707
742
switch (options .command ) {
743
+ case 'i' :
744
+ print_node_id ();
745
+ break ;
746
+
708
747
case 'n' :
709
748
print_node_name (0 );
710
749
break ;
@@ -721,13 +760,6 @@ main(int argc, char **argv)
721
760
remove_node (options .target_uname );
722
761
break ;
723
762
724
- case 'i' :
725
- /* FIXME: Use pcmk__query_node_name() after conversion to formatted
726
- * output
727
- */
728
- run_controller_mainloop (options .nodeid , false);
729
- break ;
730
-
731
763
case 'l' :
732
764
case 'p' :
733
765
run_controller_mainloop (0 , true);
0 commit comments