]> andersk Git - moira.git/commitdiff
Implement support for container related queries.
authorzacheiss <zacheiss>
Thu, 31 May 2001 21:34:31 +0000 (21:34 +0000)
committerzacheiss <zacheiss>
Thu, 31 May 2001 21:34:31 +0000 (21:34 +0000)
clients/moira/cluster.c
clients/moira/defs.h
clients/moira/f_defs.h
clients/moira/menus.c
clients/stella/stella.c

index 627ba4a6ad844a34c1cd577ed4ee8dc3156723a4..d3ac8ec859fcc3716f00a0d42941939867006447 100644 (file)
@@ -49,18 +49,27 @@ int CheckAndRemoveFromCluster(char *name, Bool ask_user);
 int CheckAndRemoveCnames(char *name, Bool ask_user);
 int CheckAndRemoveMachines(char *name, Bool ask_first);
 
-#define MACHINE  0
-#define CLUSTER  1
-#define DATA     2
-#define MAP      3
-#define SUBNET  4
-#define CNAME   5
+static char *PrintContainerInfo(char **info);
+static void RealUpdateContainer(char **info, Bool junk);
+static void RealDeleteContainer(char **info, Bool one_container);
+static void RealRemoveMachineFromContainer(char **info, Bool one_contmap);
+
+#define MACHINE   0
+#define CLUSTER   1
+#define DATA      2
+#define MAP       3
+#define SUBNET   4
+#define CNAME    5
+#define CONTAINER 6
+#define CONTMAP   7
 
 #define M_DEFAULT_TYPE     DEFAULT_NONE
 
 #define C_DEFAULT_DESCRIPT DEFAULT_NONE
 #define C_DEFAULT_LOCATION DEFAULT_NONE
 
+#define CON_DEFAULT_TYPE   DEFAULT_NONE
+
 #define CD_DEFAULT_LABEL   DEFAULT_NONE
 #define CD_DEFAULT_DATA    DEFAULT_NONE
 
@@ -134,6 +143,21 @@ static char **SetClusterDefaults(char **info, char *name)
   return info;
 }
 
+static char **SetContainerDefaults(char **info, char *name)
+{
+  info[CON_NAME] = strdup(name);
+  info[CON_DESCRIPT] = strdup(CON_DEFAULT_TYPE);
+  info[CON_LOCATION] = strdup(CON_DEFAULT_TYPE);
+  info[CON_CONTACT] = strdup(CON_DEFAULT_TYPE);
+  info[CON_OWNER_TYPE] = strdup("NONE");
+  info[CON_OWNER_NAME] = strdup("NONE");
+  info[CON_MEMACE_TYPE] = strdup("NONE");
+  info[CON_MEMACE_NAME] = strdup("NONE");
+  info[CON_MODBY] = info[CON_MODTIME] = info[CON_MODWITH] = NULL;
+  info[CON_END] = NULL;
+  return info;
+}
+
 /*     Function Name: SetSubnetDefaults
  *     Description: sets Subnet defaults.
  *     Arguments: info - an array to put the defaults into.
@@ -451,6 +475,23 @@ struct mqelem *GetMCInfo(int type, char *name1, char *name2)
          com_err(program_name, stat, " in get_cluster_data.");
          return NULL;
        }
+      break;
+    case CONTAINER:
+      args[CON_NAME] = name1;
+      if ((stat = do_mr_query("get_container", 1, &name1, StoreInfo, &elem)))
+       {
+         com_err(program_name, stat, " in get_container.");
+         return NULL;
+       }
+      break;
+    case CONTMAP:
+      args[0] = name1;
+      if ((stat = do_mr_query("get_machine_to_container_map", 1, &name1,
+                             StoreInfo, &elem)))
+       {
+         com_err(program_name, stat, " in get_machine_to_container_map.");
+         return NULL;
+       }
     }
   return QueueTop(elem);
 }
@@ -462,6 +503,7 @@ struct mqelem *GetMCInfo(int type, char *name1, char *name2)
  *                 type - type of information - MACHINE
  *                                              CLUSTER
  *                                              DATA
+ *                                              CONTAINER
  *                 name - T/F : change the name of this type.
  *     Returns: none.
  */
@@ -488,6 +530,10 @@ char **AskMCDInfo(char **info, int type, Bool name)
       sprintf(temp_buf, "Setting the Data for the Cluster %s...",
              info[CD_NAME]);
       break;
+    case CONTAINER:
+      sprintf(temp_buf, "Setting the Data for the Container %s...",
+             info[CON_NAME]);
+      break;
     }
   Put_message(temp_buf);
 
@@ -522,6 +568,12 @@ char **AskMCDInfo(char **info, int type, Bool name)
              SUB_ERROR)
            return NULL;
          break;
+       case CONTAINER:
+         newname = strdup(info[CON_NAME]);
+         if (GetValueFromUser("The new name for this container? ", &newname)
+             == SUB_ERROR)
+           return NULL;
+         break;
        default:
          Put_message("Unknown type in AskMCDInfo, programmer botch");
          return NULL;
@@ -699,6 +751,53 @@ char **AskMCDInfo(char **info, int type, Bool name)
       if (GetValueFromUser("The data itself ? ", &info[CD_DATA]) == SUB_ERROR)
        return NULL;
       break;
+    case CONTAINER:
+      if (GetValueFromUser("Container's Description:", &info[CON_DESCRIPT]) ==
+         SUB_ERROR)
+       return NULL;
+      if (GetValueFromUser("Container's Location:", &info[CON_LOCATION]) ==
+         SUB_ERROR)
+       return NULL;
+      if (GetValueFromUser("Container's Contact:", &info[CON_CONTACT]) == 
+         SUB_ERROR)
+       return NULL;
+      if (GetTypeFromUser("Container's owner type", "ace_type", 
+                         &info[CON_OWNER_TYPE]) == SUB_ERROR)
+       return NULL;
+      if (strcmp(info[CON_OWNER_TYPE], "NONE") &&
+         GetValueFromUser("Owner's Name", &info[CON_OWNER_NAME]) == SUB_ERROR)
+       return NULL;
+      if (!strcmp(info[CON_OWNER_TYPE], "KERBEROS"))
+       {
+         char *canon;
+
+         mrcl_validate_kerberos_member(info[CON_OWNER_NAME], &canon);
+         if (mrcl_get_message())
+           Put_message(mrcl_get_message());
+         free(info[CON_OWNER_NAME]);
+         info[CON_OWNER_NAME] = canon;
+       }
+      if (GetTypeFromUser("Container's Membership ACL", "ace_type",
+                         &info[CON_MEMACE_TYPE]) == SUB_ERROR)
+       return NULL;
+      if (strcmp(info[CON_MEMACE_TYPE], "NONE") &&
+         GetValueFromUser("Membership ACL", &info[CON_MEMACE_NAME])
+         == SUB_ERROR)
+       return NULL;
+      if (!strcmp(info[CON_MEMACE_TYPE], "KERBEROS"))
+       {
+         char *canon;
+
+         mrcl_validate_kerberos_member(info[CON_MEMACE_NAME], &canon);
+         if (mrcl_get_message())
+           Put_message(mrcl_get_message());
+         free(info[CON_MEMACE_NAME]);
+         info[CON_MEMACE_NAME] = canon;
+       }
+      FreeAndClear(&info[CON_MODTIME], TRUE);
+      FreeAndClear(&info[CON_MODBY], TRUE);
+      FreeAndClear(&info[CON_MODWITH], TRUE);
+      break;
     }
 
   /*
@@ -1296,7 +1395,7 @@ static void RealRemoveMachineFromCluster(char **info, Bool one_map)
 int RemoveMachineFromCluster(int argc, char **argv)
 {
   struct mqelem *elem = NULL;
-  char buf[BUFSIZ], * args[10];
+  char buf[BUFSIZ], *args[10];
   int stat;
 
   args[MAP_MACHINE] = canonicalize_hostname(strdup(argv[1]));
@@ -1313,7 +1412,7 @@ int RemoveMachineFromCluster(int argc, char **argv)
                     StoreInfo, &elem);
   if (stat == MR_NO_MATCH)
     {
-      sprintf(buf, "The machine %s is not is the cluster %s.",
+      sprintf(buf, "The machine %s is not in the cluster %s.",
              args[MAP_MACHINE], args[MAP_CLUSTER]);
       Put_message(buf);
       free(args[MAP_MACHINE]);
@@ -1903,3 +2002,445 @@ struct mqelem *GetMachineByOwner(char *type, char *name)
     }
   return QueueTop(elem);
 }
+
+int ShowContainerInfo(int argc, char **argv)
+{
+  struct mqelem *top;
+
+  top = GetMCInfo(CONTAINER, argv[1], NULL);
+  Loop(top, (void (*)(char **)) PrintContainerInfo);
+  FreeQueue(top);
+  return DM_NORMAL;
+}
+
+static char *PrintContainerInfo(char **info)
+{
+  char buf[BUFSIZ], tbuf[256];
+
+  Put_message("");
+  sprintf(buf, "Container:      %-16s", info[CON_NAME]);
+  Put_message(buf);
+  sprintf(buf, "Description:    %-16s", info[CON_DESCRIPT]);
+  Put_message(buf);
+  sprintf(buf, "Location:       %-16s    Contact:     %s", info[CON_LOCATION],
+         info[CON_CONTACT]);
+  Put_message(buf);
+  sprintf(tbuf, "%s %s", info[CON_OWNER_TYPE],
+         strcmp(info[CON_OWNER_TYPE], "NONE") ? info[CON_OWNER_NAME] : "");
+  sprintf(buf, "Owner:          %-16s", tbuf);
+  Put_message(buf);
+  sprintf(tbuf, "%s %s", info[CON_MEMACE_TYPE],
+         strcmp(info[CON_MEMACE_TYPE], "NONE") ? info[CON_MEMACE_NAME] : "");
+  sprintf(buf, "Membership ACL: %-16s", tbuf);
+  Put_message(buf);
+  Put_message("");
+  sprintf(buf, MOD_FORMAT, info[CON_MODBY], info[CON_MODTIME], 
+         info[CON_MODWITH]);
+  Put_message(buf);
+  return info[CON_NAME];
+}
+
+static char *PrintContainer(char **info)
+{
+  char buf[BUFSIZ];
+
+  sprintf(buf, "Container: %s", info[CON_NAME]);
+  Put_message(buf);
+}
+
+static char *PrintMContMap(char **info)
+{
+  char buf[BUFSIZ];
+  sprintf(buf, "Container: %-30s Machine: %-20s",
+         info[1], info[0]);
+  Put_message(buf);
+  return "";
+}
+
+int AddContainer(int argc, char **argv)
+{
+  char **args, *info[MAX_ARGS_SIZE], *name = argv[1];
+  int stat;
+
+  if (!ValidName(name))
+    return DM_NORMAL;
+
+  /* Check if this cluster already exists. */
+  if ((stat = do_mr_query("get_container", 1, &name, NULL, NULL))
+      == MR_SUCCESS)
+    {
+      Put_message("This container already exists.");
+      return DM_NORMAL;
+    }
+  else if (stat != MR_NO_MATCH)
+    {
+      com_err(program_name, stat, " in AddContainer.");
+      return DM_NORMAL;
+    }
+  if (!(args = AskMCDInfo(SetContainerDefaults(info, name), CONTAINER, FALSE)))
+    {
+      Put_message("Aborted.");
+      FreeInfo(info);
+      return DM_NORMAL;
+    }
+
+  /* Create the new container. */
+  if ((stat = do_mr_query("add_container", CountArgs(args), args, NULL, NULL)))
+    com_err(program_name, stat, " in AddContainer.");
+
+  FreeInfo(info);
+  return DM_NORMAL;
+}
+
+int UpdateContainer(int argc, char **argv)
+{
+  struct mqelem *top;
+  top = GetMCInfo(CONTAINER, argv[1], NULL);
+  QueryLoop(top, NullPrint, RealUpdateContainer, "Update the container");
+
+  FreeQueue(top);
+  return DM_NORMAL;
+}
+
+static void RealUpdateContainer(char **info, Bool junk)
+{
+  int stat;
+  char **args = AskMCDInfo(info, CONTAINER, TRUE);
+
+  if (!args)
+    {
+      Put_message("Aborted.");
+      return;
+    }
+  if ((stat = do_mr_query("update_container", CountArgs(args), args,
+                         NULL, NULL)))
+    com_err(program_name, stat, " in UpdateContainer.");
+  else
+    Put_message("Container successfully updated.");
+}
+
+int DeleteContainer(int argc, char **argv)
+{
+  struct mqelem *top;
+
+  top = GetMCInfo(CONTAINER, argv[1], NULL);
+  QueryLoop(top, PrintClusterInfo, RealDeleteContainer, 
+           "Delete the container");
+
+  FreeQueue(top);
+  return DM_NORMAL;
+}
+
+static void RealDeleteContainer(char **info, Bool one_container)
+{
+  int stat;
+  char temp_buf[BUFSIZ];
+
+  sprintf(temp_buf,
+         "Are you sure you want to delete the container %s (y/n) ?",
+         info[CON_NAME]);
+  if (!one_container || Confirm(temp_buf))
+    {
+      if (CheckAndRemoveMachinesFromContainer(info[CON_NAME], TRUE) 
+         != SUB_ERROR)
+       {
+         if ((stat = do_mr_query("delete_container", 1, &info[CON_NAME],
+                                 NULL, NULL)))
+           {
+             com_err(program_name, stat, " in delete_container.");
+             sprintf(temp_buf, "Container %s ** NOT ** deleted.", 
+                     info[CON_NAME]);
+             Put_message(temp_buf);
+           }
+         else
+           {
+             sprintf(temp_buf, "Container %s successfully deleted.",
+                     info[CON_NAME]);
+             Put_message(temp_buf);
+           }
+       }
+    }
+}
+
+int CheckAndRemoveMachinesFromContainer(char *name, Bool ask_first)
+{
+  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] = name;
+  args[1] = "0";
+  stat = do_mr_query("get_machines_of_container", 2, args, StoreInfo, 
+                    &elem);
+  if (stat && stat != MR_NO_MATCH)
+    {
+      com_err(program_name, stat, " in get_machines_of_container");
+      return DM_NORMAL;
+    }
+  if (stat == MR_SUCCESS)
+    {
+      elem = top = QueueTop(elem);
+      if (ask_first)
+       {
+         sprintf(temp_buf,
+                 "The container %s has the following machines in it:", name);
+         Put_message(temp_buf);
+         while (elem)
+           {
+             char **info = elem->q_data;
+             Print(1, &info[0], (char *) NULL);
+             elem = elem->q_forw;
+           }
+         ptr = "Remove ** ALL ** these machines from this container?";
+
+         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)
+       {
+         elem = top;
+         while (elem)
+           {
+             char **info = elem->q_data;
+             if ((stat = do_mr_query("delete_machine_from_container",
+                                     2, info, NULL, NULL)))
+               {
+                 ret_value = SUB_ERROR;
+                 com_err(program_name, stat, 
+                         " in delete_machine_from_container.");
+                 sprintf(temp_buf, 
+                         "Machine %s ** NOT ** removed from container %s.",
+                         info[0], info[1]);
+                 Put_message(temp_buf);
+               }
+             elem = elem->q_forw;
+           }
+       }
+    }
+  return ret_value;
+}
+
+int GetSubContainers(int argc, char **argv)
+{
+  char *args[2];
+  struct mqelem *elem = NULL, *top = NULL;
+  int stat;
+
+  args[0] = argv[1];
+
+  if (YesNoQuestion("Do you want a recursive search?", TRUE) == TRUE)
+    args[1] = "1";
+  else
+    args[1] = "0";
+
+  if (stat = do_mr_query("get_subcontainers_of_container", 2, args,
+                        StoreInfo, &elem))
+    com_err(program_name, stat, " in get_subcontainers_of_container");
+
+  top = QueueTop(elem);
+  Loop(top, ((void (*)(char **)) PrintContainer));
+  FreeQueue(top);
+  return DM_NORMAL;
+}
+
+int MachineToContainerMap(int argc, char **argv)
+{
+  struct mqelem *elem, *top;
+  char *tmpname, temp_buf[256];
+
+  tmpname = canonicalize_hostname(strdup(argv[1]));
+  if (strcasecmp(tmpname, argv[1]) && *argv[1] != '"')
+    {
+      sprintf(temp_buf, "Warning: '%s' canonicalized to '%s'.",
+             argv[1], tmpname);
+      Put_message(temp_buf);
+    }
+  top = elem = GetMCInfo(CONTMAP, tmpname, NULL);
+
+  Put_message("");
+  while (elem)
+    {
+      char **info = elem->q_data;
+      PrintMContMap(info);
+      elem = elem->q_forw;
+    }
+
+  FreeQueue(top);
+  free(tmpname);
+  return DM_NORMAL;
+}
+
+int AddMachineToContainer(int argc, char **argv)
+{
+  int stat;
+  char *machine, *container, temp_buf[BUFSIZ], *args[10];
+  Bool add_it, one_machine, one_container;
+  struct mqelem *melem, *mtop, *celem, *ctop;
+
+  machine = canonicalize_hostname(strdup(argv[1]));
+  if (strcasecmp(machine, argv[1]) && *argv[1] != '"')
+    {
+      sprintf(temp_buf, "Warning: '%s' canonicalized to '%s'.",
+             argv[1], machine);
+      Put_message(temp_buf);
+    }
+  container = argv[2];
+
+  celem = ctop = GetMCInfo(CONTAINER, container, NULL);
+  melem = mtop = GetMCInfo(MACHINE, machine, NULL);
+  free(machine);
+
+  one_machine = (QueueCount(mtop) == 1);
+  one_container = (QueueCount(ctop) == 1);
+
+  while (melem)
+    {
+      char **minfo = melem->q_data;
+      while (celem)
+       {
+         char **cinfo = celem->q_data;
+         if (one_machine && one_container)
+           add_it = TRUE;
+         else
+           {
+             sprintf(temp_buf, "Add machine %s to container %s (y/n/q) ?",
+                     minfo[M_NAME], cinfo[CON_NAME]);
+             switch (YesNoQuestion(temp_buf, FALSE))
+               {
+               case TRUE:
+                 add_it = TRUE;
+                 break;
+               case FALSE:
+                 add_it = FALSE;
+                 break;
+           default:
+             Put_message("Aborting...");
+             FreeQueue(ctop);
+             FreeQueue(mtop);
+             return DM_NORMAL;
+               }
+           }
+         if (add_it)
+           {
+             args[0] = minfo[M_NAME];
+             args[1] = cinfo[CON_NAME];
+             stat = do_mr_query("add_machine_to_container", 2, args, NULL, 
+                                NULL);
+             switch (stat)
+               {
+               case MR_SUCCESS:
+                 break;
+               case MR_EXISTS:
+                 sprintf(temp_buf, "%s is already in container %s",
+                         minfo[M_NAME], cinfo[CON_NAME]);
+                 Put_message(temp_buf);
+                 break;
+               default:
+                 com_err(program_name, stat, " in AddMachineToContainer.");
+                 break;
+               }
+           }
+         celem = celem->q_forw;
+       }
+      celem = ctop;
+      melem = melem->q_forw;
+    }
+  FreeQueue(ctop);
+  FreeQueue(mtop);
+  return DM_NORMAL;
+}
+
+int RemoveMachineFromContainer(int argc, char **argv)
+{
+  struct mqelem *elem = NULL;
+  char buf[BUFSIZ], *args[10];
+  int stat;
+
+  args[0] = canonicalize_hostname(strdup(argv[1]));
+  if (strcasecmp(args[0], argv[1]) && *argv[1] != '"')
+    {
+      sprintf(buf, "Warning: '%s' canonicalized to '%s'.",
+             argv[1], args[0]);
+      Put_message(buf);
+    }
+  args[1] = argv[2];
+  args[2] = NULL;
+
+  stat = do_mr_query("get_machine_to_container_map", 1, args, StoreInfo, 
+                    &elem);
+  if (stat == MR_NO_MATCH)
+    {
+      sprintf(buf, "The machine %s is not in the container %s.",
+             args[0], args[1]);
+      Put_message(buf);
+      free(args[0]);
+      return DM_NORMAL;
+    }
+  if (stat != MR_SUCCESS)
+    com_err(program_name, stat, " in deleter_machine_from_container");
+
+  elem = QueueTop(elem);
+  QueryLoop(elem, PrintMContMap, RealRemoveMachineFromContainer, 
+           "Remove this machine from this container");
+  
+  FreeQueue(elem);
+  free(args[0]);
+  return DM_NORMAL;
+}
+
+static void RealRemoveMachineFromContainer(char **info, Bool one_contmap)
+{
+  char temp_buf[BUFSIZ];
+  int stat;
+
+  sprintf(temp_buf, "Remove %s from the container %s",
+         info[0], info[1]);
+  if (!one_contmap || Confirm(temp_buf))
+    {
+      if ((stat = do_mr_query("delete_machine_from_container", 2,
+                             info, NULL, NULL)))
+       com_err(program_name, stat, " in delete_machine_from_container");
+      else
+       {
+         sprintf(temp_buf, "%s has been removed from the container %s.",
+                 info[0], info[1]);
+         Put_message(temp_buf);
+       }
+    }
+  else
+    Put_message("Machine not removed.");
+}
+
+int GetMachinesOfContainer(int argc, char **argv)
+{
+  char *args[2];
+  struct mqelem *elem = NULL, *top = NULL;
+  int stat;
+
+  args[0] = argv[1];
+
+  if (YesNoQuestion("Do you want a recursive search?", TRUE) == TRUE)
+    args[1] = "1";
+  else
+    args[1] = "0";
+
+  if (stat = do_mr_query("get_machines_of_container", 2, args,
+                        StoreInfo, &elem))
+    com_err(program_name, stat, " in get_machines_of_container");
+
+  top = QueueTop(elem);
+  Loop(top, ((void (*)(char **)) PrintMContMap));
+  FreeQueue(top);
+  return DM_NORMAL;
+}
index 15160dae8107274a20d0175dc91d8e66a35f0604..eb07a5be239c804b1a58c487901027506151ca00 100644 (file)
@@ -50,7 +50,7 @@ typedef int Bool;
 
 /* What version of the queries are we asking for? */
 
-#define QUERY_VERSION 6
+#define QUERY_VERSION 7
 
 /* This is unimplemented in the menu stuff, but would be nice. */
 
index f8e627ea7e87708336dcf6e89bc0c04eabd5463e..fc43b8ca9e2d18e983a7e7edb3c8d9dfa45042d3 100644 (file)
@@ -77,6 +77,16 @@ int ShowCname(int argc, char **argv);
 int AddCname(int argc, char **argv);
 int DeleteCname(int argc, char **argv);
 
+int ShowContainerInfo(int argc, char **argv);
+int AddContainer(int argc, char **argv);
+int UpdateContainer(int argc, char **argv);
+int DeleteContainer(int argc, char **argv);
+int GetSubContainers(int argc, char **argv);
+int MachineToContainerMap(int argc, char **argv);
+int AddMachineToContainer(int argc, char **argv);
+int RemoveMachineFromContainer(int argc, char **argv);
+int GetMachinesOfContainer(int argc, char **argv);
+
 /* delete.c */
 
 int DeleteList(int argc, char **argv);
index 0733dc0730bbf3e0c4c2866464a775a8c1ee21e0..8e62152e85a9a700281aefb91cb162e611a55a01 100644 (file)
@@ -143,6 +143,38 @@ Menu mappings_menu = {
   }
 };
 
+/*
+ * Machine to Container Mappings Menu
+ */
+
+Menu cmappings_menu = {
+  NULLFUNC,
+  NULLFUNC,
+  "Machine to Container Mappings Menu",
+  5,
+  {
+    { MachineToContainerMap, NULLMENU, 2, {
+      {"map", "Show Machine to container mapping"},
+      {"name", "Machine's Name: "}
+    } },
+    { AddMachineToContainer, NULLMENU, 3, {
+      {"addcontainer", "Add machine to a container"},
+      {"name", "Machine's Name: "},
+      {"container", "Container's Name: "},
+    } },
+    { RemoveMachineFromContainer, NULLMENU, 3, {
+      {"remcontainer", "Remove machine from a container"},
+      {"name", "Machine's Name: "},
+      {"container", "Container's Name: "},
+    } },
+    { GetMachinesOfContainer, NULLMENU, 2, {
+      {"machofcont", "Show all machines in a container"},
+      {"name", "Container's Name: "},
+    } },
+    SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode),
+  }
+};
+
 /*
  * Post Office Box Menu
  */
@@ -810,6 +842,41 @@ Menu acl_menu = {
   }
 };
 
+/*
+ * Container Menu
+ */
+
+Menu container_menu = {
+  NULLFUNC,
+  NULLFUNC,
+  "Container Menu",
+  7,
+  {
+    { ShowContainerInfo, NULLMENU, 2, {
+      {"show", "Get container information"},
+      {"name", "Container's Name: "}
+    } },
+    { AddContainer, NULLMENU, 2, {
+      {"add", "Add a new container"},
+      {"name", "Container's Name: "}
+    } },
+    { UpdateContainer, NULLMENU, 2, {
+      {"update", "Update container information"},
+      {"name", "Container's Name: "}
+    } },
+    { DeleteContainer, NULLMENU, 2, {
+      {"delete", "Delete this container"},
+      {"name", "Container's Name: "}
+    } },
+    { GetSubContainers, NULLMENU, 2, {
+      {"subcont", "Get subcontainers of container"},
+      {"name", "Container's Name: "}
+    } },
+    SUBMENU("mappings", "Machine to Container Mappings Menu", &cmappings_menu),
+    SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode)
+  }
+};
+
 /*
  * Miscellaneous Menu
  */
@@ -845,7 +912,7 @@ Menu moira_top_menu = {
   NULLFUNC,
   NULLFUNC,
   "Moira Database Manipulation",
-  11,
+  13,
   {
     SUBMENU("cluster", "Cluster Menu", &cluster_menu),
     SUBMENU("filesys", "Filesystem Menu", &filesys_menu),
@@ -858,6 +925,7 @@ Menu moira_top_menu = {
     SUBMENU("zephyr", "Zephyr ACLS Menu", &zephyr_menu),
     SUBMENU("dcm", "DCM Menu", &dcm_menu),
     SUBMENU("acl", "Generic ACL Menu", &acl_menu),
+    SUBMENU("container", "Container Menu", &container_menu),
     SUBMENU("misc", "Miscellaneous Menu", &misc_menu)
   }
 };
index 163666683281a03c3f891119b10cd46aa5c81783..d24da0fbd2b1cd136f1ffdde11707d56071c40bf 100644 (file)
@@ -51,9 +51,11 @@ struct string_list {
 /* flags from command line */
 int info_flag, update_flag, create_flag, delete_flag, list_map_flag;
 int update_alias_flag, update_map_flag, verbose, noauth;
+int list_container_flag, update_container_flag;
 
 struct string_list *alias_add_queue, *alias_remove_queue;
 struct string_list *map_add_queue, *map_remove_queue;
+struct string_list *container_add_queue, *container_remove_queue;
 
 char *hostname, *whoami;
 
@@ -66,6 +68,7 @@ void usage(char **argv);
 int store_host_info(int argc, char **argv, void *hint);
 void show_host_info(char **argv);
 int show_machine_in_cluster(int argc, char **argv, void *hint);
+int show_machine_in_container(int argc, char **argv, void *hint);
 struct owner_type *parse_member(char *s);
 struct string_list *add_to_string_list(struct string_list *old_list, char *s);
 int wrap_mr_query(char *handle, int argc, char **argv,
@@ -81,11 +84,13 @@ int main(int argc, char **argv)
   /* clear all flags & lists */
   info_flag = update_flag = create_flag = list_map_flag = update_map_flag = 0;
   update_alias_flag = verbose = noauth = 0;
+  list_container_flag = update_container_flag = 0;
   newname = address = network = h_status = vendor = model = NULL;
   os = location = contact = billing_contact = adm_cmt = op_cmt = NULL;
   owner = NULL;
   alias_add_queue = alias_remove_queue = NULL;
   map_add_queue = map_remove_queue = NULL;
+  container_add_queue = container_remove_queue = NULL;
   whoami = argv[0];
 
   success = 1;
@@ -250,6 +255,26 @@ int main(int argc, char **argv)
          }
          else if (argis("lm", "listmap"))
            list_map_flag++;
+         else if (argis("acn", "addcontainer")) {
+           if (arg - argv < argc - 1) {
+             arg++;
+             container_add_queue = 
+               add_to_string_list(container_add_queue, *arg);
+           } else
+             usage(argv);
+           update_container_flag++;
+         }
+         else if (argis("dcn", "deletecontainer")) {
+           if (arg - argv < argc - 1) {
+             arg++;
+             container_remove_queue =
+               add_to_string_list(container_remove_queue, *arg);
+           } else
+             usage(argv);
+           update_container_flag++;
+         }
+         else if (argis("lcn", "listcontainer"))
+           list_container_flag++;
          else if (argis("n", "noauth"))
            noauth++;
          else if (argis("v", "verbose"))
@@ -278,12 +303,13 @@ int main(int argc, char **argv)
   /* default to info_flag if nothing else was specified */
   if(!(info_flag   || update_flag   || create_flag     || \
        delete_flag || list_map_flag || update_map_flag || \
-       update_alias_flag)) {
+       update_alias_flag || update_container_flag || \
+       list_container_flag)) {
     info_flag++;
   }
 
   /* fire up Moira */
-  status = mrcl_connect(server, "stella", 6, !noauth);
+  status = mrcl_connect(server, "stella", 7, !noauth);
   if (status == MRCL_AUTH_ERROR)
     {
       com_err(whoami, 0, "Try the -noauth flag if you don't "
@@ -558,6 +584,50 @@ int main(int argc, char **argv)
     }
   }
 
+  /* add container mappings */
+  if (container_add_queue) {
+    struct string_list *q = container_add_queue;
+
+    while (q) {
+      char *containername = q->string;
+      char *args[2];
+
+      args[0] = canonicalize_hostname(strdup(hostname));
+      args[1] = containername;
+      status = wrap_mr_query("add_machine_to_container", 2, args,
+                            NULL, NULL);
+
+      if (status) {
+       com_err(whoami, status, "while adding container mapping");
+       exit(1);
+      }
+
+      q = q->next;
+    }
+  }
+
+  /* delete container mappings */
+  if (container_remove_queue) {
+    struct string_list *q = container_remove_queue;
+
+    while (q) {
+      char *containername = q->string;
+      char *args[2];
+
+      args[0] = canonicalize_hostname(strdup(hostname));
+      args[1] = containername;
+      status = wrap_mr_query("delete_machine_from_container", 2, args,
+                            NULL, NULL);
+
+      if (status) {
+       com_err(whoami, status, "while deleting container mapping");
+       exit(1);
+      }
+
+      q = q->next;
+    }
+  }
+
   /* display list info if requested to */
   if (info_flag) {
     struct mqelem *elem = NULL;
@@ -589,6 +659,21 @@ int main(int argc, char **argv)
       }
   }
 
+  /* list container mappings if needed */
+  if (list_container_flag) {
+    char *argv[1];
+
+    argv[0] = canonicalize_hostname(strdup(hostname));
+    status = wrap_mr_query("get_machine_to_container_map", 1, argv,
+                          show_machine_in_container, NULL);
+
+    if (status)
+      if (status != MR_NO_MATCH) {
+       com_err(whoami, status, "while getting container mappings");
+       exit(1);
+      }
+  }
+
   if (delete_flag) {
     char *argv[1];
 
@@ -630,10 +715,13 @@ void usage(char **argv)
          "-N   | -network network");
   fprintf(stderr, USAGE_OPTIONS_FORMAT, "-am  | -addmap cluster",
          "-dm  | deletemap cluster");
+  fprintf(stderr, USAGE_OPTIONS_FORMAT, "-acn | -addcontainer container",
+         "-dcn | -deletecontainer container");
   fprintf(stderr, USAGE_OPTIONS_FORMAT, "-lm  | -listmap",
-         "-db  | -database host[:port]");
+         "-lcn | -listcontainer");
   fprintf(stderr, USAGE_OPTIONS_FORMAT, "-v   | -verbose",
          "-n   | -noauth");
+  fprintf(stderr, "  %-39s\n" , "-db  | -database host[:port]");
   exit(1);
 }
 
@@ -731,6 +819,13 @@ int show_machine_in_cluster(int argc, char **argv, void *hint)
   return MR_CONT;
 }
 
+int show_machine_in_container(int argc, char **argv, void *hint)
+{
+  printf("Machine: %-30s Container: %-25s\n", argv[0], argv[1]); 
+
+  return MR_CONT;
+}
+
 /* Parse a line of input, fetching a member.  NULL is returned if a member
  * is not found.  ';' is a comment character.
  */
This page took 0.085884 seconds and 5 git commands to generate.