[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH 5/8] Added "ip" object manipulations



Signed-off-by: Dmitry Mishin <dim parallels com>
---
 config/tools/ccs_tool/ccs_tool.c |   17 ++++-
 config/tools/ccs_tool/editconf.c |  155 +++++++++++++++++++++++++++++++++++++-
 config/tools/ccs_tool/editconf.h |    2 +
 3 files changed, 172 insertions(+), 2 deletions(-)

diff --git a/config/tools/ccs_tool/ccs_tool.c b/config/tools/ccs_tool/ccs_tool.c
index bb91389..441f495 100644
--- a/config/tools/ccs_tool/ccs_tool.c
+++ b/config/tools/ccs_tool/ccs_tool.c
@@ -243,6 +243,14 @@ static int tool_main(int argc, char *argv[])
 	    del_node(argc-1, argv+1);
 	    exit(EXIT_SUCCESS);
     }
+    else if(!strcmp(argv[optind], "addip")){
+	    add_ip(argc-1, argv+1);
+	    exit(EXIT_SUCCESS);
+    }
+    else if(!strcmp(argv[optind], "delip")){
+	    del_node(argc-1, argv+1);
+	    exit(EXIT_SUCCESS);
+    }
     else if(!strcmp(argv[optind], "addfence")){
 	    add_fence(argc-1, argv+1);
 	    exit(EXIT_SUCCESS);
@@ -267,6 +275,10 @@ static int tool_main(int argc, char *argv[])
 	    list_scripts(argc-1, argv+1);
 	    exit(EXIT_SUCCESS);
     }
+    else if(!strcmp(argv[optind], "lsip")){
+	    list_ips(argc-1, argv+1);
+	    exit(EXIT_SUCCESS);
+    }
     else if(!strcmp(argv[optind], "create")){
 	    create_skeleton(argc-1, argv+1);
 	    exit(EXIT_SUCCESS);
@@ -313,7 +325,10 @@ static void tool_print_usage(FILE *stream){
 	  "  delfence <fencedev> Delete a fence device\n"
 	  "  addscript <name>    Add a script resource\n"
 	  "  delscript <name>    Delete a script resource\n"
-          "  lsscript            List script resources\n"
+	  "  lsscript            List script resources\n"
+	  "  addip <name>        Add an IP address resource\n"
+	  "  delip <name>        Delete an IP address resource\n"
+	  "  lsip                List IP address resources\n"
 	  "  create              Create a skeleton config file\n"
 	  "  addnodeids          Assign node ID numbers to all nodes\n"
 	  "\n");
diff --git a/config/tools/ccs_tool/editconf.c b/config/tools/ccs_tool/editconf.c
index 313f83f..0f642e6 100644
--- a/config/tools/ccs_tool/editconf.c
+++ b/config/tools/ccs_tool/editconf.c
@@ -140,6 +140,16 @@ static void addscript_usage(const char *name)
 	exit(0);
 }
 
+static void addip_usage(const char *name)
+{
+	fprintf(stderr, "Usage: %s %s [options] <IP_address>\n",
+			prog_name, name);
+	config_usage(1);
+	help_usage();
+
+	exit(0);
+}
+
 static void addnodeid_usage(const char *name)
 {
 	fprintf(stderr, "Add node IDs to all nodes in the config file that don't have them.\n");
@@ -471,7 +481,12 @@ static xmlNode *find_script_ref(xmlNode *root, const char *name)
 
 static xmlNode *find_ip_resource(xmlNode *root, const char *name)
 {
-	return do_find_node(root, name, "ip", "name");
+	return do_find_node(root, name, "ip", "address");
+}
+
+static xmlNode *find_ip_ref(xmlNode *root, const char *name)
+{
+	return do_find_resource_ref(root, name, "ip");
 }
 
 /* Print name=value pairs for a (n XML) node.
@@ -773,6 +788,45 @@ static void del_clusterscript(xmlNode *root_element, struct option_info *ninfo)
 	xmlUnlinkNode(node);
 }
 
+static void del_clusterip(xmlNode *root_element, struct option_info *ninfo)
+{
+	xmlNode *rm, *rs;
+	xmlNode *node;
+
+	rm = findnode(root_element, "rm");
+	if (!rm)
+	{
+		fprintf(stderr, "Can't find \"rm\" in %s\n", ninfo->configfile);
+		exit(1);
+	}
+
+	rs = findnode(rm, "resources");
+	if (!rs)
+	{
+		fprintf(stderr, "Can't find \"resources\" in %s\n", ninfo->configfile);
+		exit(1);
+	}
+
+	/* Check that not used */
+	node = find_ip_ref(rm, ninfo->name);
+	if (node)
+	{
+		fprintf(stderr, "IP %s is referenced in service in %s,"
+			" please remove reference first.\n", ninfo->name,
+			ninfo->configfile);
+		exit(1);
+	}
+
+	node = find_ip_resource(rs, ninfo->name);
+	if (!node)
+	{
+		fprintf(stderr, "IP %s does not exist in %s\n", ninfo->name, ninfo->configfile);
+		exit(1);
+	}
+
+	xmlUnlinkNode(node);
+}
+
 struct option addnode_options[] =
 {
       { "votes", required_argument, NULL, 'v'},
@@ -1129,6 +1183,8 @@ void del_node(int argc, char **argv)
 		del_clusterservice(root_element, &ninfo);
 	else if (!strcmp(argv[0], "delscript"))
 		del_clusterscript(root_element, &ninfo);
+	else if (!strcmp(argv[0], "delip"))
+		del_clusterip(root_element, &ninfo);
 
 	/* Write it out */
 	save_file(doc, &ninfo);
@@ -1417,6 +1473,52 @@ void add_script(int argc, char **argv)
 	xmlCleanupParser();
 }
 
+void add_ip(int argc, char **argv)
+{
+	struct option_info ninfo;
+	xmlDoc *doc;
+	xmlNode *root_element;
+	xmlNode *rm, *rs, *node;
+
+	if (parse_commonw_options(argc, argv, &ninfo))
+		addip_usage(argv[0]);
+
+	if (optind < argc)
+		ninfo.ip_addr = strdup(argv[optind]);
+	else
+		addip_usage(argv[0]);
+
+	doc = open_configfile(&ninfo);
+
+	root_element = xmlDocGetRootElement(doc);
+
+	increment_version(root_element);
+
+	rm = findnode(root_element, "rm");
+	if (!rm)
+		die("Can't find \"rm\" %s\n", ninfo.configfile);
+
+	rs = findnode(rm, "resources");
+	if (!rs)
+		die("Can't find \"resources\" %s\n", ninfo.configfile);
+
+	/* Check it doesn't already exist */
+	if (find_ip_resource(rs, ninfo.ip_addr))
+		die("IP %s already exists\n", ninfo.ip_addr);
+
+	/* Add it */
+	node = xmlNewNode(NULL, BAD_CAST "ip");
+	xmlSetProp(node, BAD_CAST "address", BAD_CAST ninfo.ip_addr);
+	xmlSetProp(node, BAD_CAST "monitor_link", BAD_CAST "1");
+	xmlAddChild(rs, node);
+
+	/* Write it out */
+	save_file(doc, &ninfo);
+
+	/* Shutdown libxml */
+	xmlCleanupParser();
+}
+
 void create_skeleton(int argc, char **argv)
 {
 	xmlNode *root_element;
@@ -1681,3 +1783,54 @@ void list_scripts(int argc, char **argv)
 		}
 	}
 }
+
+void list_ips(int argc, char **argv)
+{
+	xmlNode *cur_node;
+	xmlNode *root_element;
+	xmlNode *rm, *rs;
+	xmlDocPtr doc;
+	struct option_info ninfo;
+	int opt;
+	int verbose=0;
+
+	memset(&ninfo, 0, sizeof(ninfo));
+
+	while ( (opt = getopt_long(argc, argv, "c:hv?", list_options, NULL)) != EOF)
+	{
+		switch(opt)
+		{
+		case 'c':
+			ninfo.configfile = strdup(optarg);
+			break;
+		case 'v':
+			verbose++;
+			break;
+		case '?':
+		default:
+			list_usage(argv[0]);
+		}
+	}
+	doc = open_configfile(&ninfo);
+	root_element = xmlDocGetRootElement(doc);
+
+	rm = findnode(root_element, "rm");
+	if (!rm)
+		die("Can't find \"rm\" in %s\n", ninfo.configfile);
+
+	rs = findnode(rm, "resources");
+	if (!rs)
+		die("Can't find \"resources\" in %s\n", ninfo.configfile);
+
+	printf("IP\n");
+	for (cur_node = rs->children; cur_node; cur_node = cur_node->next)
+	{
+		if (cur_node->type == XML_ELEMENT_NODE &&
+			strcmp((char *)cur_node->name, "ip") == 0)
+		{
+			xmlChar *ip  = xmlGetProp(cur_node, BAD_CAST "address");
+
+			printf("%s\n", ip);
+		}
+	}
+}
diff --git a/config/tools/ccs_tool/editconf.h b/config/tools/ccs_tool/editconf.h
index c83af1d..a1119d7 100644
--- a/config/tools/ccs_tool/editconf.h
+++ b/config/tools/ccs_tool/editconf.h
@@ -2,6 +2,7 @@ void add_node(int argc, char **argv);
 void add_nodeids(int argc, char **argv);
 void add_service(int argc, char **argv);
 void add_script(int argc, char **argv);
+void add_ip(int argc, char **argv);
 void add_fence(int argc, char **argv);
 void del_node(int argc, char **argv);
 void del_fence(int argc, char **argv);
@@ -9,4 +10,5 @@ void list_nodes(int argc, char **argv);
 void list_services(int argc, char **argv);
 void list_fences(int argc, char **argv);
 void list_scripts(int argc, char **argv);
+void list_ips(int argc, char **argv);
 void create_skeleton(int argc, char **argv);
-- 
1.7.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]