[1796] in Moira
stella container support
daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Sun May 20 00:30:50 2001
Message-Id: <200105200430.AAA04539@riff-raff.mit.edu>
To: moiradev@MIT.EDU
Date: Sun, 20 May 2001 00:30:48 -0400
From: Garry Zacheiss <zacheiss@MIT.EDU>
This adds support for adding and removing machines from a
containers in stella, and for listing what container a machine is in.
It assumes the server patch I just submitted is in effect.
Garry
Index: stella.c
===================================================================
RCS file: /afs/athena.mit.edu/astaff/project/moiradev/repository/moira/clients/stella/stella.c,v
retrieving revision 1.9
diff -u -r1.9 stella.c
--- stella.c 2000/12/20 09:39:46 1.9
+++ stella.c 2001/05/20 04:26:05
@@ -51,9 +51,11 @@
/* 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 @@
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 @@
/* 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 @@
}
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 @@
/* 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 @@
}
}
+ /* 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 @@
}
}
+ /* 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 @@
"-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);
}
@@ -727,6 +815,13 @@
int show_machine_in_cluster(int argc, char **argv, void *hint)
{
printf("Machine: %-30s Cluster: %-30s\n", argv[0], argv[1]);
+
+ 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;
}