FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 12-10-2010, 08:00 AM
Dmitry Mishin
 
Default 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
"
" addscript <name> Add a script resource
"
" delscript <name> Delete a script resource
"
- " lsscript List script resources
"
+ " lsscript List script resources
"
+ " addip <name> Add an IP address resource
"
+ " delip <name> Delete an IP address resource
"
+ " lsip List IP address resources
"
" create Create a skeleton config file
"
" addnodeids Assign node ID numbers to all nodes
"
"
");
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>
",
+ 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.
");
@@ -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
", ninfo->configfile);
+ exit(1);
+ }
+
+ rs = findnode(rm, "resources");
+ if (!rs)
+ {
+ fprintf(stderr, "Can't find "resources" in %s
", 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.
", ninfo->name,
+ ninfo->configfile);
+ exit(1);
+ }
+
+ node = find_ip_resource(rs, ninfo->name);
+ if (!node)
+ {
+ fprintf(stderr, "IP %s does not exist in %s
", 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
", ninfo.configfile);
+
+ rs = findnode(rm, "resources");
+ if (!rs)
+ die("Can't find "resources" %s
", ninfo.configfile);
+
+ /* Check it doesn't already exist */
+ if (find_ip_resource(rs, ninfo.ip_addr))
+ die("IP %s already exists
", 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
", ninfo.configfile);
+
+ rs = findnode(rm, "resources");
+ if (!rs)
+ die("Can't find "resources" in %s
", ninfo.configfile);
+
+ printf("IP
");
+ 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
", 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
 
Old 12-10-2010, 12:42 PM
Dmitry Mishin
 
Default 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 9726da2..9df5445 100644
--- a/config/tools/ccs_tool/ccs_tool.c
+++ b/config/tools/ccs_tool/ccs_tool.c
@@ -241,6 +241,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);
@@ -265,6 +273,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);
@@ -311,7 +323,10 @@ static void tool_print_usage(FILE *stream){
" delfence <fencedev> Delete a fence device
"
" addscript <name> Add a script resource
"
" delscript <name> Delete a script resource
"
- " lsscript List script resources
"
+ " lsscript List script resources
"
+ " addip <name> Add an IP address resource
"
+ " delip <name> Delete an IP address resource
"
+ " lsip List IP address resources
"
" create Create a skeleton config file
"
" addnodeids Assign node ID numbers to all nodes
"
"
");
diff --git a/config/tools/ccs_tool/editconf.c b/config/tools/ccs_tool/editconf.c
index 9d81593..9f7709b 100644
--- a/config/tools/ccs_tool/editconf.c
+++ b/config/tools/ccs_tool/editconf.c
@@ -138,6 +138,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>
",
+ 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.
");
@@ -469,7 +479,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.
@@ -774,6 +789,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
", ninfo->configfile);
+ exit(1);
+ }
+
+ rs = findnode(rm, "resources");
+ if (!rs)
+ {
+ fprintf(stderr, "Can't find "resources" in %s
", 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.
", ninfo->name,
+ ninfo->configfile);
+ exit(1);
+ }
+
+ node = find_ip_resource(rs, ninfo->name);
+ if (!node)
+ {
+ fprintf(stderr, "IP %s does not exist in %s
", ninfo->name, ninfo->configfile);
+ exit(1);
+ }
+
+ xmlUnlinkNode(node);
+}
+
struct option addnode_options[] =
{
{ "votes", required_argument, NULL, 'v'},
@@ -1111,6 +1165,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);
@@ -1390,6 +1446,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
", ninfo.configfile);
+
+ rs = findnode(rm, "resources");
+ if (!rs)
+ die("Can't find "resources" %s
", ninfo.configfile);
+
+ /* Check it doesn't already exist */
+ if (find_ip_resource(rs, ninfo.ip_addr))
+ die("IP %s already exists
", 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)
{
char *fencename = NULL;
@@ -1663,3 +1765,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
", ninfo.configfile);
+
+ rs = findnode(rm, "resources");
+ if (!rs)
+ die("Can't find "resources" in %s
", ninfo.configfile);
+
+ printf("IP
");
+ 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
", 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
 

Thread Tools




All times are GMT. The time now is 09:50 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org