[1665] in Moira
Re: Feature request: removing cnames for hosts being expunged
daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Wed Sep 6 02:01:34 2000
Message-Id: <200009060601.CAA01956@x15-cruise-basselope.mit.edu>
To: Matt Braun <matt@MIT.EDU>
cc: bug-moira@MIT.EDU
In-Reply-To: Your message of "Wed, 06 Sep 2000 00:01:39 EDT."
<200009060401.AAA26705@forever.mit.edu>
Date: Wed, 06 Sep 2000 02:01:30 -0400
From: Garry Zacheiss <zacheiss@MIT.EDU>
>> Could this feature be implemented for CNAMES as well so they don't
>> need to be deleted by hand?
Sure, here you go.
Index: cluster.c
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/clients/moira/cluster.c,v
retrieving revision 1.43
diff -c -r1.43 cluster.c
*** cluster.c 2000/04/20 20:12:15 1.43
--- cluster.c 2000/09/06 06:00:33
***************
*** 46,51 ****
--- 46,52 ----
struct mqelem *GetMachineByOwner(char *type, char *name);
char **AskMCDInfo(char **info, int type, Bool name);
int CheckAndRemoveFromCluster(char *name, Bool ask_user);
+ int CheckAndRemoveCnames(char *name, Bool ask_user);
int CheckAndRemoveMachines(char *name, Bool ask_first);
#define MACHINE 0
***************
*** 879,885 ****
/* Function Name: CheckAndRemoveFromCluster
* Description: This func tests to see if a machine is in a cluster.
* and if so then removes it
! * Arguments: name - name of the machine (already Canonocalized).
* ask_user- query the user before removing if from clusters?
* Returns: MR_ERROR if machine left in a cluster, or mr_error.
*/
--- 880,886 ----
/* Function Name: CheckAndRemoveFromCluster
* Description: This func tests to see if a machine is in a cluster.
* and if so then removes it
! * Arguments: name - name of the machine (already Canonicalized).
* ask_user- query the user before removing if from clusters?
* Returns: MR_ERROR if machine left in a cluster, or mr_error.
*/
***************
*** 944,949 ****
--- 945,1017 ----
return ret_value;
}
+ /* Function Name: CheckAndRemoveCnames
+ * Description: This func tests to see if a machine has cnames,
+ * and if so then removes them.
+ * Arguments: name - name of the machine (already Canonicalized).
+ * ask_user- query the user before removing cnames?
+ * Returns: MR_ERROR if machine left in a cluster, or mr_error.
+ */
+
+ int CheckAndRemoveCnames(char *name, Bool ask_user)
+ {
+ int stat, ret_value;
+ Bool delete_it;
+ char *args[10], temp_buf[BUFSIZ], *ptr;
+ struct mqelem *top, *elem = NULL;
+
+ ret_value = SUB_NORMAL;
+ args[0] = "*";
+ args[1] = name;
+ stat = do_mr_query("get_hostalias", 2, args, StoreInfo, &elem);
+ if (stat && stat != MR_NO_MATCH)
+ {
+ com_err(program_name, stat, " in get_hostalias.");
+ return DM_NORMAL;
+ }
+ if (stat == MR_SUCCESS)
+ {
+ elem = top = QueueTop(elem);
+ if (ask_user)
+ {
+ sprintf(temp_buf, "%s has the following cnames.", name);
+ Put_message(temp_buf);
+ Loop(top, (void (*)(char **)) PrintCname);
+ ptr = "Remove ** ALL ** these cnames?";
+ if (YesNoQuestion(ptr, FALSE) == TRUE) /* may return -1. */
+ delete_it = TRUE;
+ else
+ {
+ Put_message("Aborting...");
+ FreeQueue(top);
+ return SUB_ERROR;
+ }
+ }
+ else
+ delete_it = TRUE;
+
+ if (delete_it)
+ {
+ while (elem)
+ {
+ char **info = elem->q_data;
+ if ((stat = do_mr_query("delete_hostalias", 2, info,
+ NULL, NULL)))
+ {
+ ret_value = SUB_ERROR;
+ com_err(program_name, stat, " in delete_hostalias.");
+ sprintf(temp_buf,
+ "Cname %s ** NOT ** removed from host %s.",
+ info[0], info[1]);
+ Put_message(temp_buf);
+ }
+ elem = elem->q_forw;
+ }
+ }
+ }
+ return ret_value;
+ }
+
/* Function Name: RealDeleteMachine
* Description: Actually Deletes the Machine.
* Arguments: info - nescessary information stored as an array of char *'s
***************
*** 963,985 ****
{
if (CheckAndRemoveFromCluster(info[M_NAME], TRUE) != SUB_ERROR)
{
! if ((stat = do_mr_query("delete_host", 1,
! &info[M_NAME], NULL, NULL)))
! {
! com_err(program_name, stat, " in DeleteMachine.");
! sprintf(temp_buf, "%s ** NOT ** deleted.",
! info[M_NAME]);
! Put_message(temp_buf);
! }
! else
{
! sprintf(temp_buf, "%s successfully Deleted.", info[M_NAME]);
! Put_message(temp_buf);
}
}
}
}
-
/* Function Name: DeleteMachine
* Description: This function removes a machine from the data base.
* Arguments: argc, argv - the machines name int argv[1].
--- 1031,1055 ----
{
if (CheckAndRemoveFromCluster(info[M_NAME], TRUE) != SUB_ERROR)
{
! if (CheckAndRemoveCnames(info[M_NAME], TRUE) != SUB_ERROR)
{
! if ((stat = do_mr_query("delete_host", 1,
! &info[M_NAME], NULL, NULL)))
! {
! com_err(program_name, stat, " in DeleteMachine.");
! sprintf(temp_buf, "%s ** NOT ** deleted.",
! info[M_NAME]);
! Put_message(temp_buf);
! }
! else
! {
! sprintf(temp_buf, "%s successfully Deleted.", info[M_NAME]);
! Put_message(temp_buf);
! }
}
}
}
}
/* Function Name: DeleteMachine
* Description: This function removes a machine from the data base.
* Arguments: argc, argv - the machines name int argv[1].