]>
Commit | Line | Data |
---|---|---|
1 | #ifndef lint | |
2 | static char rcsid_module_c[] = "$Header$"; | |
3 | #endif lint | |
4 | ||
5 | /* This is the file cluseter.c for allmaint, the SMS client that allows | |
6 | * a user to maintaint most important parts of the SMS database. | |
7 | * It Contains: | |
8 | * | |
9 | * Created: 4/22/88 | |
10 | * By: Chris D. Peterson | |
11 | * Based upon: Clusermaint.c by marcus: 87/07/22 | |
12 | * | |
13 | * $Source$ | |
14 | * $Author$ | |
15 | * $Header$ | |
16 | * | |
17 | * Copyright 1987, 1988 by the Massachusetts Institute of Technology. | |
18 | * | |
19 | * For further information on copyright and distribution | |
20 | * see the file mit-copyright.h | |
21 | */ | |
22 | ||
23 | /* BTW: for anyone who cares MCD is short for Machine, Cluster, Data. */ | |
24 | ||
25 | #include <stdio.h> | |
26 | #include <strings.h> | |
27 | #include <sms.h> | |
28 | #include <menu.h> | |
29 | ||
30 | #include "mit-copyright.h" | |
31 | #include "allmaint.h" | |
32 | #include "allmaint_funcs.h" | |
33 | #include "globals.h" | |
34 | #include "infodefs.h" | |
35 | ||
36 | #define MACHINE 0 | |
37 | #define CLUSTER 1 | |
38 | #define DATA 2 | |
39 | #define MAP 3 | |
40 | ||
41 | /* Function Name: PrintMachInfo | |
42 | * Description: This function Prints out the Machine info in | |
43 | * a coherent form. | |
44 | * Arguments: info - array of information about a machine. | |
45 | * Returns: none. | |
46 | */ | |
47 | ||
48 | void | |
49 | PrintMachInfo(info) | |
50 | char ** info; | |
51 | { | |
52 | char buf[BUFSIZ]; | |
53 | ||
54 | sprintf(buf, "Machine: %s\tType: %s", info[M_NAME], info[M_TYPE]); | |
55 | Put_message(buf); | |
56 | sprintf(buf, "Last Modified at %s, by %s with %s",info[M_MODTIME], | |
57 | info[M_MODBY], info[M_MODWITH]); | |
58 | Put_message(buf); | |
59 | } | |
60 | ||
61 | /* Function Name: PrintClusterInfo | |
62 | * Description: This function Prints out the cluster info | |
63 | * in a coherent form. | |
64 | * Arguments: info - array of information about a cluster. | |
65 | * Returns: none. | |
66 | */ | |
67 | ||
68 | void | |
69 | PrintClusterInfo(info) | |
70 | char ** info; | |
71 | { | |
72 | char buf[BUFSIZ]; | |
73 | ||
74 | sprintf(buf, "Cluster: %s", info[C_NAME]); | |
75 | Put_message(buf); | |
76 | sprintf(buf,"Description: %-20s, Location: %-20s", info[C_DESCRIPT], | |
77 | info[C_LOCATION]); | |
78 | Put_message(buf); | |
79 | sprintf(buf, "Last Modified at %s, by %s with %s",info[C_MODTIME], | |
80 | info[C_MODBY], info[C_MODWITH]); | |
81 | Put_message(buf); | |
82 | } | |
83 | ||
84 | /* Function Name: PrintClusterData | |
85 | * Description: Prints the Data on a cluster | |
86 | * Arguments: info a pointer to the data array. | |
87 | * Returns: none | |
88 | */ | |
89 | ||
90 | void | |
91 | PrintClusterData(info) | |
92 | char ** info; | |
93 | { | |
94 | char buf[BUFSIZ]; | |
95 | sprintf(buf, "Cluster: %-30s Label: %-20s Data: %-20s", | |
96 | info[CD_NAME], info[CD_LABEL], info[CD_DATA]); | |
97 | Put_message(buf); | |
98 | } | |
99 | ||
100 | /* Function Name: PrintMCMap | |
101 | * Description: Prints the data about a machine to cluster mapping. | |
102 | * Arguments: info a pointer to the data array. | |
103 | * Returns: none | |
104 | */ | |
105 | ||
106 | void | |
107 | PrintMCMap(info) | |
108 | char ** info; | |
109 | { | |
110 | char buf[BUFSIZ]; | |
111 | sprintf(buf, "Cluster: %-30s Machine: %-20s", | |
112 | info[MAP_CLUSTER], info[MAP_MACHINE]); | |
113 | Put_message(buf); | |
114 | } | |
115 | ||
116 | /* Function Name: GetMCInfo. | |
117 | * Description: This function stores info about a machine. | |
118 | * type - type of data we are trying to retrieve. | |
119 | * name1 - the name of argv[0] for the call. | |
120 | * name2 - the name of argv[1] for the call. | |
121 | * Returns: the top element of a queue containing the data or NULL. | |
122 | */ | |
123 | ||
124 | struct qelem * | |
125 | GetMCInfo(type, name1, name2) | |
126 | int type; | |
127 | char * name1, *name2; | |
128 | { | |
129 | ||
130 | int stat; | |
131 | struct qelem * elem = NULL; | |
132 | char * args[2]; | |
133 | ||
134 | switch (type) { | |
135 | case MACHINE: | |
136 | if ( (stat = sms_query("get_machine", 1, &name1, | |
137 | StoreInfo, &elem)) != 0) { | |
138 | com_err(program_name, stat, " in get_machine."); | |
139 | return(NULL); | |
140 | } | |
141 | break; | |
142 | case CLUSTER: | |
143 | if ( (stat = sms_query("get_cluster", 1, &name1, | |
144 | StoreInfo, &elem)) != 0) { | |
145 | com_err(program_name, stat, " in get_cluster."); | |
146 | return(NULL); | |
147 | } | |
148 | break; | |
149 | case MAP: | |
150 | args[MAP_MACHINE] = name1; | |
151 | args[MAP_CLUSTER] = name2; | |
152 | if ( (stat = sms_query("get_machine_to_cluster_map", 2, args, | |
153 | StoreInfo, &elem)) != 0) { | |
154 | com_err(program_name, stat, " in get_machine_to_cluster_map."); | |
155 | return(NULL); | |
156 | } | |
157 | break; | |
158 | case DATA: | |
159 | args[CD_NAME] = name1; | |
160 | args[CD_LABEL] = name2; | |
161 | if ( (stat = sms_query("get_cluster_data", 2, args, | |
162 | StoreInfo, &elem)) != 0) { | |
163 | com_err(program_name, stat, " in get_cluster_data."); | |
164 | return(NULL); | |
165 | } | |
166 | } | |
167 | return(QueueTop(elem)); | |
168 | } | |
169 | ||
170 | /* Function Name: AskMCDInfo. | |
171 | * Description: This function askes the user for information about a | |
172 | * machine and saves it into a structure. | |
173 | * Arguments: info - a pointer the information to ask about | |
174 | * type - type of information - MACHINE | |
175 | * CLUSTER | |
176 | * DATA | |
177 | * name - T/F : change the name of this type. | |
178 | * Returns: none. | |
179 | */ | |
180 | ||
181 | char ** | |
182 | AskMCDInfo(info, type, name) | |
183 | char ** info; | |
184 | int type; | |
185 | Bool name; | |
186 | { | |
187 | char temp_buf[BUFSIZ], *newname; | |
188 | ||
189 | switch (type) { | |
190 | case MACHINE: | |
191 | sprintf(temp_buf, "Changing the information for the Machine %s.", | |
192 | name); | |
193 | break; | |
194 | case CLUSTER: | |
195 | sprintf(temp_buf, "Changing the information for the Cluster %s.", | |
196 | name); | |
197 | break; | |
198 | case DATA: | |
199 | sprintf(temp_buf, "Changing the Data for the Cluster %s.", | |
200 | name); | |
201 | break; | |
202 | } | |
203 | Put_message(temp_buf); | |
204 | ||
205 | if (name) { | |
206 | switch (type) { | |
207 | case MACHINE: | |
208 | newname = Strsave(info[M_NAME]); | |
209 | GetValueFromUser("The new name for this machine? ", | |
210 | &newname); | |
211 | break; | |
212 | case CLUSTER: | |
213 | newname = Strsave(info[C_NAME]); | |
214 | GetValueFromUser("The new name for this cluster? ", | |
215 | &newname); | |
216 | break; | |
217 | default: | |
218 | Put_message("Unknown type in AskMCDInfo, programmer botch"); | |
219 | return(NULL); | |
220 | } | |
221 | } | |
222 | ||
223 | switch(type) { | |
224 | case MACHINE: | |
225 | GetValueFromUser("Machine's Type:", &info[M_TYPE]); | |
226 | FreeAndClear(&info[M_MODTIME], TRUE); | |
227 | FreeAndClear(&info[M_MODBY], TRUE); | |
228 | FreeAndClear(&info[M_MODWITH], TRUE); | |
229 | break; | |
230 | case CLUSTER: | |
231 | GetValueFromUser("Cluster's Description:", &info[C_DESCRIPT]); | |
232 | GetValueFromUser("Cluster's Location:", &info[C_LOCATION]); | |
233 | FreeAndClear(&info[C_MODTIME], TRUE); | |
234 | FreeAndClear(&info[C_MODBY], TRUE); | |
235 | FreeAndClear(&info[C_MODWITH], TRUE); | |
236 | break; | |
237 | case DATA: | |
238 | GetValueFromUser("Label defining this data?", &info[CD_LABEL]); | |
239 | GetValueFromUser("The data itself ? ", &info[CD_DATA]); | |
240 | break; | |
241 | } | |
242 | ||
243 | /* | |
244 | * Slide the newname into the #2 slot, this screws up all future references | |
245 | * to this list. | |
246 | */ | |
247 | if (name) | |
248 | SlipInNewName(info, newname); | |
249 | ||
250 | return(info); | |
251 | } | |
252 | ||
253 | /* ----------- Machine Menu ----------- */ | |
254 | ||
255 | /* Function Name: ShowMachineInfo | |
256 | * Description: This function shows the information about a machine. | |
257 | * Arguments: argc, argv - the name of the machine in argv[1]. | |
258 | * Returns: DM_NORMAL. | |
259 | */ | |
260 | ||
261 | /* ARGSUSED */ | |
262 | int | |
263 | ShowMachineInfo(argc, argv) | |
264 | int argc; | |
265 | char **argv; | |
266 | { | |
267 | char **info; | |
268 | struct qelem *elem, *top; | |
269 | ||
270 | top = elem = GetMCInfo(MACHINE, CanonicalizeHostname(argv[1]), | |
271 | (char *) NULL); | |
272 | ||
273 | while (elem != NULL) { | |
274 | info = (char **) elem->q_data; | |
275 | PrintMachInfo(info); | |
276 | elem = elem->q_forw; | |
277 | } | |
278 | ||
279 | FreeQueue(top); | |
280 | return(DM_NORMAL); | |
281 | } | |
282 | ||
283 | /* Function Name: AddMachine | |
284 | * Description: This function adds a new machine to the database. | |
285 | * Arguments: argc, argv - the name of the machine in argv[1]. | |
286 | * Returns: DM_NORMAL. | |
287 | */ | |
288 | ||
289 | /* ARGSUSED */ | |
290 | int | |
291 | AddMachine(argc, argv) | |
292 | int argc; | |
293 | char **argv; | |
294 | { | |
295 | char **args, *info[MAX_ARGS_SIZE], *name; | |
296 | int stat; | |
297 | /* | |
298 | * Check to see if this machine already exists. | |
299 | */ | |
300 | name = CanonicalizeHostname(argv[1]); | |
301 | ||
302 | if ( (stat = sms_query("get_machine", 1, &name, NullFunc, NULL)) == 0) { | |
303 | Put_message("This machine already exists."); | |
304 | return(DM_NORMAL); | |
305 | } | |
306 | else if (stat != SMS_NO_MATCH) { | |
307 | com_err(program_name, stat, " in AddMachine."); | |
308 | return(DM_NORMAL); | |
309 | } | |
310 | ||
311 | info[0] = name; | |
312 | args = AskMCDInfo(info, MACHINE, FALSE); | |
313 | ||
314 | /* | |
315 | * Actually create the new Machine. | |
316 | */ | |
317 | ||
318 | if ( (stat = sms_query("add_machine", CountArgs(args), | |
319 | args, Scream, NULL)) != 0) | |
320 | com_err(program_name, stat, " in AddMachine."); | |
321 | ||
322 | FreeInfo(info); | |
323 | return(DM_NORMAL); | |
324 | } | |
325 | ||
326 | /* Function Name: UpdateMachine | |
327 | * Description: This function adds a new machine to the database. | |
328 | * Arguments: argc, argv - the name of the machine in argv[1]. | |
329 | * Returns: DM_NORMAL. | |
330 | */ | |
331 | ||
332 | /* ARGSUSED */ | |
333 | int | |
334 | UpdateMachine(argc, argv) | |
335 | int argc; | |
336 | char **argv; | |
337 | { | |
338 | struct qelem *elem, *top; | |
339 | int stat; | |
340 | ||
341 | elem = top = GetMCInfo( MACHINE, CanonicalizeHostname(argv[1]), | |
342 | (char *) NULL); | |
343 | ||
344 | while (elem != NULL) { | |
345 | char ** args; | |
346 | char ** info = (char **) elem->q_data; | |
347 | args = AskMCDInfo(info, MACHINE, TRUE); | |
348 | if ( (stat = sms_query("update_machine", CountArgs(args), | |
349 | args, Scream, NULL)) != 0) | |
350 | com_err(program_name, stat, " in UpdateMachine."); | |
351 | elem = elem->q_forw; | |
352 | } | |
353 | ||
354 | FreeQueue(top); | |
355 | return(DM_NORMAL); | |
356 | } | |
357 | ||
358 | /* Function Name: DeleteMachine | |
359 | * Description: This function removes a machine from the data base. | |
360 | * Arguments: argc, argv - the machines name int argv[1]. | |
361 | * Returns: DM_NORMAL. | |
362 | */ | |
363 | ||
364 | /* ARGSUSED */ | |
365 | int | |
366 | DeleteMachine(argc, argv) | |
367 | int argc; | |
368 | char **argv; | |
369 | { | |
370 | int stat; | |
371 | char * args[2], *name, temp_buf[BUFSIZ]; | |
372 | struct qelem *top, *elem = NULL; | |
373 | ||
374 | name = CanonicalizeHostname(argv[1]); | |
375 | ||
376 | /* Should probabally check for wildcards, none allowed. */ | |
377 | /* Perhaps we should remove the cluster if it has no machine now. */ | |
378 | ||
379 | args[0] = name; | |
380 | args[1] = "*"; | |
381 | stat = sms_query("get_machine_to_cluster_map", 2, args, StoreInfo, &elem); | |
382 | if (stat && stat != SMS_NO_MATCH) { | |
383 | com_err(program_name, stat, " in DeleteMachine."); | |
384 | return(DM_NORMAL); | |
385 | } | |
386 | if (stat == 0) { | |
387 | top = elem; | |
388 | while (elem != NULL) { | |
389 | sprintf(temp_buf, "%s is assigned to cluster %s.", | |
390 | args[0], args[1]); | |
391 | Put_message(temp_buf); | |
392 | if ( YesNoQuestion( | |
393 | "Would you like to remove it from this cluster?", FALSE)) { | |
394 | if ( (stat = sms_query( "delete_machine_from_cluster", | |
395 | 1, args, Scream, NULL)) != 0) | |
396 | com_err(program_name, stat, | |
397 | " in delete_machine_from_cluster."); | |
398 | else { | |
399 | Put_message("Aborting..."); | |
400 | FreeQueue(top); | |
401 | return(DM_NORMAL); | |
402 | } | |
403 | } | |
404 | elem = elem->q_forw; | |
405 | } | |
406 | } | |
407 | if(Confirm("Are you sure that you want to delete this machine?")) { | |
408 | if ( (stat = sms_query("delete_machine", 1, &name, Scream, NULL)) != 0) | |
409 | com_err(program_name, stat, " in DeleteMachine."); | |
410 | } | |
411 | else | |
412 | Put_message("Operation aborted."); | |
413 | ||
414 | return(DM_NORMAL); | |
415 | } | |
416 | ||
417 | /* Function Name: AddMachineToCluster | |
418 | * Description: This function adds a machine to a cluster | |
419 | * Arguments: argc, argv - The machine name is argv[1]. | |
420 | * The cluster name in argv[2]. | |
421 | * Returns: DM_NORMAL. | |
422 | */ | |
423 | ||
424 | /* ARGSUSED */ | |
425 | int | |
426 | AddMachineToCluster(argc, argv) | |
427 | int argc; | |
428 | char ** argv; | |
429 | { | |
430 | int stat; | |
431 | ||
432 | if ( (stat = sms_query("add_machine_to_cluster", 2, argv + 1, | |
433 | Scream, NULL) != 0)) | |
434 | com_err(program_name, stat, " in AddMachineToCluster."); | |
435 | ||
436 | return(DM_NORMAL); | |
437 | } | |
438 | ||
439 | /* Function Name: RemoveMachineFromCluster | |
440 | * Description: Removes this machine form a specific cluster. | |
441 | * Arguments: argc, argv - Name of machine in argv[1]. | |
442 | * Returns: none. | |
443 | */ | |
444 | ||
445 | /* ARGSUSED */ | |
446 | int | |
447 | RemoveMachineFromCluster(argc, argv) | |
448 | int argc; | |
449 | char ** argv; | |
450 | { | |
451 | int stat, ans; | |
452 | struct qelem *elem, *top; | |
453 | char ** info, buf[BUFSIZ]; | |
454 | ||
455 | elem = top = GetMCInfo(CLUSTER, CanonicalizeHostname(argv[1]), "*"); | |
456 | ||
457 | Put_message("This machine is the following clusters:"); | |
458 | while (elem != NULL) { | |
459 | info = (char **) elem->q_data; | |
460 | Put_message(info[MAP_CLUSTER]); | |
461 | elem = elem->q_forw; | |
462 | } | |
463 | elem = top; | |
464 | ||
465 | if ( Confirm("Remove this machine from ** ALL ** these clusters?") ) { | |
466 | while (elem != NULL) { /* delete all */ | |
467 | info = (char **) elem->q_data; | |
468 | if ( (stat =sms_query("delete_machine_from_cluster", 2, | |
469 | info, Scream, NULL)) != 0 ) | |
470 | com_err(program_name, stat, " in delete_machine_from_cluster"); | |
471 | elem = elem->q_forw; | |
472 | } | |
473 | } | |
474 | else | |
475 | while (elem != NULL) { /* query delete. */ | |
476 | info = (char **) elem->q_data; | |
477 | sprintf(buf, "Remove %13s from the cluster %30s? (y/n/q)", | |
478 | info[MAP_MACHINE], info[MAP_CLUSTER]); | |
479 | ans = YesNoQuitQuestion(buf, FALSE); | |
480 | if (ans == TRUE) | |
481 | if ( (stat =sms_query("delete_machine_from_cluster", 2, | |
482 | info, Scream, NULL)) != 0 ) | |
483 | com_err(program_name, stat, " in delete_machine_from_cluster"); | |
484 | else if (ans != FALSE) /* quit. or ^C */ | |
485 | break; | |
486 | elem = elem->q_forw; | |
487 | } | |
488 | ||
489 | FreeQueue(top); | |
490 | return(DM_NORMAL); | |
491 | } | |
492 | ||
493 | /* ---------- Cluster Menu -------- */ | |
494 | ||
495 | /* Function Name: ShowClusterInfo | |
496 | * Description: Gets information about a cluser given its name. | |
497 | * Arguments: argc, argc - the name of the cluster in in argv[1]. | |
498 | * Returns: DM_NORMAL. | |
499 | */ | |
500 | ||
501 | /* ARGSUSED */ | |
502 | int | |
503 | ShowClusterInfo(argc, argv) | |
504 | int argc; | |
505 | char ** argv; | |
506 | { | |
507 | char **info; | |
508 | struct qelem *elem, *top; | |
509 | ||
510 | top = elem = GetMCInfo( MACHINE, CanonicalizeHostname(argv[1]), | |
511 | (char *) NULL); | |
512 | while (elem != NULL) { | |
513 | info = (char **) elem->q_data; | |
514 | PrintClusterInfo(info); | |
515 | elem = elem->q_forw; | |
516 | } | |
517 | FreeQueue(top); | |
518 | return(DM_NORMAL); | |
519 | } | |
520 | ||
521 | /* Function Name: AddCluster | |
522 | * Description: Creates a new cluster. | |
523 | * Arguments: argc, argv - the name of the new cluster is argv[1]. | |
524 | * Returns: DM_NORMAL. | |
525 | */ | |
526 | ||
527 | /* ARGSUSED */ | |
528 | int | |
529 | AddCluster(argc, argv) | |
530 | int argc; | |
531 | char ** argv; | |
532 | { | |
533 | char **args, *info[MAX_ARGS_SIZE], *name; | |
534 | int stat; | |
535 | /* | |
536 | * Check to see if this machine already exists. | |
537 | */ | |
538 | name = argv[1]; | |
539 | ||
540 | if ( (stat = sms_query("get_cluster", 1, &name, NullFunc, NULL)) == 0) { | |
541 | Put_message("This cluster already exists."); | |
542 | return(DM_NORMAL); | |
543 | } | |
544 | else if (stat != SMS_NO_MATCH) { | |
545 | com_err(program_name, stat, " in AddCluster."); | |
546 | return(DM_NORMAL); | |
547 | } | |
548 | ||
549 | info[0] = name; | |
550 | args = AskMCDInfo(info, CLUSTER, FALSE); | |
551 | ||
552 | /* | |
553 | * Actually create the new Cluster. | |
554 | */ | |
555 | ||
556 | if ( (stat = sms_query("add_cluster", CountArgs(args), | |
557 | args, Scream, NULL)) != 0) | |
558 | com_err(program_name, stat, " in AddCluster."); | |
559 | ||
560 | FreeInfo(info); | |
561 | return(DM_NORMAL); | |
562 | } | |
563 | ||
564 | /* Function Name: UpdateCluster | |
565 | * Description: This Function Updates a cluster | |
566 | * Arguments: name of the cluster in argv[1]. | |
567 | * Returns: DM_NORMAL. | |
568 | */ | |
569 | ||
570 | /* ARGSUSED */ | |
571 | int | |
572 | UpdateCluster(argc, argv) | |
573 | int argc; | |
574 | char ** argv; | |
575 | { | |
576 | struct qelem *elem, *top; | |
577 | char **args, **info; | |
578 | int stat; | |
579 | ||
580 | elem = top = GetMCInfo( CLUSTER, argv[1], (char *) NULL ); | |
581 | ||
582 | while (elem != NULL) { | |
583 | info = (char **) elem->q_data; | |
584 | args = AskMCDInfo(info, CLUSTER, TRUE); | |
585 | if ( (stat = sms_query("update_cluter", CountArgs(args), | |
586 | args, Scream, NULL)) != 0) | |
587 | com_err(program_name, stat, " in UpdateCluster."); | |
588 | elem = elem->q_forw; | |
589 | } | |
590 | ||
591 | FreeQueue(top); | |
592 | return(DM_NORMAL); | |
593 | } | |
594 | ||
595 | /* Function Name: DeleteCluster | |
596 | * Description: This function removes a cluster from the database. | |
597 | * Arguments: argc, argv - the name of the cluster is stored in argv[1]. | |
598 | * Returns: DM_NORMAL. | |
599 | */ | |
600 | ||
601 | /* ARGSUSED */ | |
602 | int | |
603 | DeleteCluster(argc, argv) | |
604 | int argc; | |
605 | char ** argv; | |
606 | { | |
607 | char * args[3], temp_buf[BUFSIZ]; | |
608 | int stat; | |
609 | ||
610 | /* Should probabally check for wildcards, none allowed. */ | |
611 | ||
612 | args[MAP_MACHINE] = "*"; | |
613 | args[MAP_CLUSTER] = argv[1]; | |
614 | ||
615 | stat = sms_query("get_machine_to_cluster_map", 2, args, | |
616 | NullFunc, (char *) NULL); | |
617 | if (stat & stat != SMS_NO_MATCH) { | |
618 | com_err(program_name, stat, " in DeleteCluster."); | |
619 | return(DM_NORMAL); | |
620 | } | |
621 | if (stat != SMS_NO_MATCH) { | |
622 | sprintf(temp_buf, "Cluster %s still has machines in it.",argv[1]); | |
623 | Put_message(temp_buf); | |
624 | if ( YesNoQuestion("Would you like a list? (y/n)", TRUE) == TRUE ) { | |
625 | args[0] = "foo"; /* not used. */ | |
626 | args[1] = "*"; | |
627 | args[2] = argv[1]; | |
628 | MachineToClusterMap(3, args); | |
629 | } | |
630 | return(DM_NORMAL); | |
631 | } | |
632 | if(Confirm("Are you sure that you want to delete this cluster? ")) { | |
633 | if ( (stat = sms_query("delete_cluster", | |
634 | 1, &args[MAP_CLUSTER], Scream, NULL)) != 0) | |
635 | com_err(program_name, stat, " in DeleteCluster."); | |
636 | } | |
637 | else | |
638 | Put_message("Operation aborted."); | |
639 | ||
640 | return(DM_NORMAL); | |
641 | } | |
642 | ||
643 | /* ----------- Cluster Data Menu -------------- */ | |
644 | ||
645 | /* Function Name: ShowClusterData | |
646 | * Description: This function shows the services for one cluster. | |
647 | * Arguments: argc, argv - The name of the cluster is argv[1]. | |
648 | * The label of the data in argv[2]. | |
649 | * Returns: DM_NORMAL. | |
650 | */ | |
651 | ||
652 | int | |
653 | ShowClusterData(argc, argv) | |
654 | int argc; | |
655 | char ** argv; | |
656 | { | |
657 | struct qelem *elem, *top; | |
658 | char **info; | |
659 | ||
660 | top = elem = GetMCInfo(DATA, argv[1], argv[2]); | |
661 | while (elem != NULL) { | |
662 | info = (char **) elem->q_data; | |
663 | PrintClusterData(info); | |
664 | elem = elem->q_forw; | |
665 | } | |
666 | FreeQueue(top); | |
667 | return(DM_NORMAL); | |
668 | } | |
669 | ||
670 | /* Function Name: AddClusterData | |
671 | * Description: This function adds some data to the cluster. | |
672 | * Arguments: argv, argc: argv[1] - the name of the cluster. | |
673 | * argv[2] - the label of the data. | |
674 | * argv[3] - the data. | |
675 | * Returns: DM_NORMAL. | |
676 | */ | |
677 | ||
678 | /* ARGSUSED */ | |
679 | int | |
680 | AddClusterData(argc, argv) | |
681 | int argc; | |
682 | char ** argv; | |
683 | { | |
684 | int stat; | |
685 | ||
686 | if( (stat = sms_query("add_cluster_data", 3, argv + 1, | |
687 | Scream, (char *) NULL)) != 0) | |
688 | com_err(program_name, stat, " in AddClusterData."); | |
689 | ||
690 | } | |
691 | ||
692 | /* Function Name: RemoveClusterData | |
693 | * Description: This function removes data on a given cluster. | |
694 | * Arguments: argv, argc: argv[1] - the name of the cluster. | |
695 | * argv[2] - the label of the data. | |
696 | * argv[3] - the data. | |
697 | * Returns: DM_NORMAL. | |
698 | */ | |
699 | ||
700 | /* ARGSUSED */ | |
701 | int | |
702 | RemoveClusterData(argc, argv) | |
703 | int argc; | |
704 | char ** argv; | |
705 | { | |
706 | int stat; | |
707 | ||
708 | if(Confirm("Do you really want to delete this data?")) { | |
709 | if( (stat = sms_query("delete_cluster_data", 3, argv + 1, | |
710 | Scream, (char *) NULL)) != 0) | |
711 | com_err(program_name, stat, " in DeleteClusterData."); | |
712 | } else | |
713 | Put_message("Operation aborted.\n"); | |
714 | ||
715 | return(DM_NORMAL); | |
716 | } | |
717 | ||
718 | /* Perhaps an interactive delete cluster data would be nice. */ | |
719 | ||
720 | /* Function Name: MachineToClusterMap | |
721 | * Description: This Retrieves the mapping between machine and cluster | |
722 | * Arguments: argc, argv - argv[1] -> machine name or wildcard. | |
723 | * argv[2] -> cluster name or wildcard. | |
724 | * Returns: none. | |
725 | */ | |
726 | ||
727 | /* ARGSUSED */ | |
728 | int | |
729 | MachineToClusterMap(argc,argv) | |
730 | int argc; | |
731 | char **argv; | |
732 | { | |
733 | struct qelem *elem, *top; | |
734 | ||
735 | top = elem = GetMCInfo(MAP, CanonicalizeHostname(argv[1]), argv[2]); | |
736 | ||
737 | while (elem != NULL) { | |
738 | char ** info = (char **) elem->q_data; | |
739 | PrintMCMap(info); | |
740 | elem = elem->q_forw; | |
741 | } | |
742 | ||
743 | FreeQueue(top); | |
744 | return(DM_NORMAL); | |
745 | } | |
746 | ||
747 | /* Function Name: MachinesInCluster | |
748 | * Description: Shows all machines in a give cluster. | |
749 | * Arguments: argv, argc - name of cluster in argv[1]. | |
750 | * Returns: DM_NORMAL; | |
751 | */ | |
752 | ||
753 | /* ARGSUSED */ | |
754 | int | |
755 | MachinesInCluster(argv,argc) | |
756 | int argc; | |
757 | char **argv; | |
758 | { | |
759 | char *info[10]; | |
760 | info[0] = argv[0]; | |
761 | info[2] = argv[1]; | |
762 | info[1] = "*"; | |
763 | return(MachineToClusterMap(3, info)); | |
764 | } | |
765 | ||
766 | /* | |
767 | * Local Variables: | |
768 | * mode: c | |
769 | * c-indent-level: 4 | |
770 | * c-continued-statement-offset: 4 | |
771 | * c-brace-offset: -4 | |
772 | * c-argdecl-indent: 4 | |
773 | * c-label-offset: -4 | |
774 | * End: | |
775 | */ | |
776 | ||
777 | ||
778 |