gfs2-utils: master - libgfs2: Add a small testing language UI
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=be4c9608...
Commit: be4c96088702582b49f9d0c28404606eee5bd055
Parent: 3d97bf215fb429aabec3fbe7553688aa5e6a9d00
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Nov 8 10:32:37 2012 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Thu Nov 8 11:32:50 2012 +0000
libgfs2: Add a small testing language UI
This adds a minimal 'gfs2l' command to allow easy use of the testing
language. It takes one -f option to specify a script file and a single
argument to specify the path to the fs.
It can be used to build a rudimentary REPL e.g.
# while read s; do echo "$s" | gfs2l -f- /dev/foo; done
get sb
...
But it's mainly intended to be used as a component of in-tree test
scripts and will not be installed by the build system.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/Makefile.am | 6 ++
gfs2/libgfs2/gfs2l.c | 146 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 152 insertions(+), 0 deletions(-)
diff --git a/gfs2/libgfs2/Makefile.am b/gfs2/libgfs2/Makefile.am
index 7103e09..9c4e96b 100644
--- a/gfs2/libgfs2/Makefile.am
+++ b/gfs2/libgfs2/Makefile.am
@@ -9,6 +9,8 @@ noinst_HEADERS = libgfs2.h lang.h
noinst_LTLIBRARIES = libgfs2.la
+noinst_PROGRAMS = gfs2l
+
libgfs2_la_SOURCES = block_list.c fs_bits.c gfs1.c misc.c rgrp.c super.c \
buf.c fs_geometry.c gfs2_disk_hash.c ondisk.c \
device_geometry.c fs_ops.c gfs2_log.c recovery.c \
@@ -19,6 +21,10 @@ libgfs2_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 \
-D_GNU_SOURCE \
-I$(top_srcdir)/gfs2/include
+gfs2l_SOURCES = gfs2l.c
+gfs2l_CPPFLAGS = -I$(top_srcdir)/gfs2/include
+gfs2l_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la
+
# Autotools can't handle header files output by flex so we have to generate it manually
lexer.h: lexer.l
$(LEX) -o lexer.c $(AM_LFLAGS) $^
diff --git a/gfs2/libgfs2/gfs2l.c b/gfs2/libgfs2/gfs2l.c
new file mode 100644
index 0000000..2eacb2d
--- /dev/null
+++ b/gfs2/libgfs2/gfs2l.c
@@ -0,0 +1,146 @@
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include "libgfs2.h"
+
+static void usage(const char *cmd)
+{
+ fprintf(stderr, "Usage: %s -f <script_path> <fs_path>\n", cmd);
+ fprintf(stderr, "Use -f - for stdin\n");
+}
+
+struct cmdopts {
+ char *fspath;
+ FILE *src;
+};
+
+static int getopts(int argc, char *argv[], struct cmdopts *opts)
+{
+ int opt;
+ while ((opt = getopt(argc, argv, "f:")) != -1) {
+ switch (opt) {
+ case 'f':
+ if (!strcmp("-", optarg)) {
+ opts->src = stdin;
+ } else {
+ opts->src = fopen(optarg, "r");
+ if (opts->src == NULL) {
+ perror("Failed to open source file");
+ return 1;
+ }
+ }
+ break;
+ default:
+ usage(argv[0]);
+ return 1;
+ }
+ }
+
+ if (argc - optind != 1) {
+ usage(argv[0]);
+ return 1;
+ }
+
+ opts->fspath = strdup(argv[optind]);
+ if (opts->fspath == NULL) {
+ perror("getopts");
+ return 1;
+ }
+ return 0;
+}
+
+static struct gfs2_sbd *openfs(const char *path)
+{
+ int fd;
+ int ret;
+ int sane;
+ int count;
+ struct gfs2_sbd *sdp = calloc(1, sizeof(struct gfs2_sbd));
+ if (sdp == NULL) {
+ perror("calloc");
+ return NULL;
+ }
+
+ fd = open(path, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to open %s\n", path);
+ free(sdp);
+ return NULL;
+ }
+
+ memset(sdp, 0, sizeof(*sdp));
+ sdp->bsize = GFS2_BASIC_BLOCK;
+ sdp->device_fd = fd;
+ compute_constants(sdp);
+ lgfs2_get_dev_info(fd, &sdp->dinfo);
+ fix_device_geometry(sdp);
+
+ ret = read_sb(sdp);
+ if (ret != 0) {
+ perror("Could not read sb");
+ return NULL;
+ }
+
+ sdp->master_dir = lgfs2_inode_read(sdp, sdp->sd_sb.sb_master_dir.no_addr);
+ gfs2_lookupi(sdp->master_dir, "rindex", 6, &sdp->md.riinode);
+ sdp->fssize = sdp->device.length;
+ if (sdp->md.riinode) {
+ rindex_read(sdp, 0, &count, &sane);
+ } else {
+ perror("Failed to look up rindex");
+ free(sdp);
+ return NULL;
+ }
+ return sdp;
+}
+
+int main(int argc, char *argv[])
+{
+ int ret;
+ struct cmdopts opts = {NULL, NULL};
+ struct gfs2_sbd *sdp;
+ struct lgfs2_lang_result *result;
+ struct lgfs2_lang_state *state;
+
+ if (getopts(argc, argv, &opts)) {
+ exit(1);
+ }
+
+ sdp = openfs(argv[optind]);
+ if (sdp == NULL) {
+ exit(1);
+ }
+
+ state = lgfs2_lang_init();
+ if (state == NULL) {
+ perror("lgfs2_lang_init failed");
+ exit(1);
+ }
+
+ ret = lgfs2_lang_parsef(state, opts.src);
+ if (ret != 0) {
+ fprintf(stderr, "Parse failed\n");
+ return ret;
+ }
+
+ for (result = lgfs2_lang_result_next(state, sdp);
+ result != NULL;
+ result = lgfs2_lang_result_next(state, sdp)) {
+ if (result == NULL) {
+ fprintf(stderr, "Failed to interpret script\n");
+ return -1;
+ }
+ lgfs2_lang_result_print(result);
+ lgfs2_lang_result_free(&result);
+ }
+
+ gfs2_rgrp_free(&sdp->rgtree);
+ inode_put(&sdp->md.riinode);
+ inode_put(&sdp->master_dir);
+ lgfs2_lang_free(&state);
+ free(opts.fspath);
+ return 0;
+}
+
+// libgfs2 still requires an external print_it function
+void print_it(const char *label, const char *fmt, const char *fmt2, ...) { return; }
11 years, 5 months
fence-agents: master - fence_scsi: change on_target metadata attribute
by rohara
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=0cda86...
Commit: 0cda864a22c34d87537f9bbaf1b7f51744894c05
Parent: ff21e947b5aed25bc1842f43deecf4d3c2230725
Author: Ryan O'Hara <rohara(a)redhat.com>
AuthorDate: Thu Nov 8 11:48:21 2012 -0600
Committer: Ryan O'Hara <rohara(a)redhat.com>
CommitterDate: Thu Nov 8 11:48:21 2012 -0600
fence_scsi: change on_target metadata attribute
This patch simply changes the on_target metadata attribute to use
value of "1" instead of "true".
Signed-off-by: Ryan O'Hara <rohara(a)redhat.com>
---
fence/agents/scsi/fence_scsi.pl | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/fence/agents/scsi/fence_scsi.pl b/fence/agents/scsi/fence_scsi.pl
index e3c78b4..f596c14 100644
--- a/fence/agents/scsi/fence_scsi.pl
+++ b/fence/agents/scsi/fence_scsi.pl
@@ -746,7 +746,7 @@ sub print_metadata ()
print "\t</parameter>\n";
print "</parameters>\n";
print "<actions>\n";
- print "\t<action name=\"on\" on_target=\"true\"/>\n";
+ print "\t<action name=\"on\" on_target=\"1\"/>\n";
print "\t<action name=\"off\"/>\n";
print "\t<action name=\"status\"/>\n";
print "\t<action name=\"metadata\"/>\n";
11 years, 5 months
cluster: STABLE32 - libccs: don't use uninitialized value in xpathlite
by Fabio M. Di Nitto
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=016ee0de517...
Commit: 016ee0de51798782fc4036836ad740e0c42e586e
Parent: 4118eaa46e9d2c61c59178dfe17df33d683669f9
Author: Fabio M. Di Nitto <fdinitto(a)redhat.com>
AuthorDate: Thu Nov 8 13:36:44 2012 +0100
Committer: Fabio M. Di Nitto <fdinitto(a)redhat.com>
CommitterDate: Thu Nov 8 13:36:44 2012 +0100
libccs: don't use uninitialized value in xpathlite
Resolves: rhbz#874538
Signed-off-by: Fabio M. Di Nitto <fdinitto(a)redhat.com>
---
config/libs/libccsconfdb/xpathlite.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/config/libs/libccsconfdb/xpathlite.c b/config/libs/libccsconfdb/xpathlite.c
index e57b5c7..6ffbf63 100644
--- a/config/libs/libccsconfdb/xpathlite.c
+++ b/config/libs/libccsconfdb/xpathlite.c
@@ -300,10 +300,10 @@ static int get_data(confdb_handle_t handle, hdb_handle_t connection_handle,
value--;
}
- resval = malloc(datalen + keyvallen + 2);
+ resval = malloc(datalen + 2);
if (!resval)
goto fail;
- snprintf(resval, datalen + keyvallen + 2, "%s=%s", data, keyval);
+ snprintf(resval, datalen + 2, "%s=", data);
*rtn = resval;
} else if (!strncmp(curpos, "@*", strlen("@*"))) {
11 years, 5 months
fence-agents: master - fence_hds_cb: Push exception handling to fencing library
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=ff21e9...
Commit: ff21e947b5aed25bc1842f43deecf4d3c2230725
Parent: af5da579e90acb9c70ad0f97eff42cd14fd708b5
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Thu Nov 8 10:29:14 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Thu Nov 8 10:39:30 2012 +0100
fence_hds_cb: Push exception handling to fencing library
Exception handling of network failures should be handled in fencing library. Old fence agents are already
ported to this new behaviour.
---
fence/agents/hds_cb/fence_hds_cb.py | 150 ++++++++++++++++-------------------
1 files changed, 67 insertions(+), 83 deletions(-)
diff --git a/fence/agents/hds_cb/fence_hds_cb.py b/fence/agents/hds_cb/fence_hds_cb.py
index 1f944b3..ab44e2f 100755
--- a/fence/agents/hds_cb/fence_hds_cb.py
+++ b/fence/agents/hds_cb/fence_hds_cb.py
@@ -23,39 +23,34 @@ BUILD_DATE="November, 2012"
RE_STATUS_LINE = "^([0-9]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$"
def get_power_status(conn, options):
- try:
- #### Maybe should put a conn.log_expect here to make sure
- #### we have properly entered into the main menu
- conn.sendline("S") # Enter System Command Mode
- conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
- conn.sendline("PC") # Enter partition control
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- result = {}
- # Status can now be obtained from the output of the PC
- # command. Line looks like the following:
- # "P Power Condition LID lamp Mode Auto power on"
- # "0 On Normal Off Basic Synchronized"
- # "1 On Normal Off Basic Synchronized"
- for line in conn.before.splitlines():
- # populate the relevant fields based on regex
- partition = re.search(RE_STATUS_LINE, line)
- if( partition != None):
- # find the blade number defined in args
- if( partition.group(1) == options["--plug"] ):
- result = partition.group(2).lower()
- # We must make sure we go back to the main menu as the
- # status is checked before any fencing operations are
- # executed. We could in theory save some time by staying in
- # the partition control, but the logic is a little cleaner
- # this way.
- conn.sendline("Q") # Back to system command mode
- conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
- conn.sendline("EX") # Back to system console main menu
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ #### Maybe should put a conn.log_expect here to make sure
+ #### we have properly entered into the main menu
+ conn.sendline("S") # Enter System Command Mode
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
+ conn.sendline("PC") # Enter partition control
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
+ result = {}
+ # Status can now be obtained from the output of the PC
+ # command. Line looks like the following:
+ # "P Power Condition LID lamp Mode Auto power on"
+ # "0 On Normal Off Basic Synchronized"
+ # "1 On Normal Off Basic Synchronized"
+ for line in conn.before.splitlines():
+ # populate the relevant fields based on regex
+ partition = re.search(RE_STATUS_LINE, line)
+ if( partition != None):
+ # find the blade number defined in args
+ if( partition.group(1) == options["--plug"] ):
+ result = partition.group(2).lower()
+ # We must make sure we go back to the main menu as the
+ # status is checked before any fencing operations are
+ # executed. We could in theory save some time by staying in
+ # the partition control, but the logic is a little cleaner
+ # this way.
+ conn.sendline("Q") # Back to system command mode
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
+ conn.sendline("EX") # Back to system console main menu
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
return result
@@ -67,56 +62,47 @@ def set_power_status(conn, options):
}[options["--action"]]
- try:
- conn.sendline("S") # Enter System Command Mode
- conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
- conn.sendline("PC") # Enter partition control
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- conn.sendline("P") # Enter power control menu
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- conn.sendline(action) # Execute action from array above
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- conn.sendline(options["--plug"]) # Select blade number from args
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- conn.sendline("Y") # Confirm action
- conn.log_expect(options, "Hit enter key.", int(options["--shell-timeout"]))
- conn.sendline("") # Press the any key
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- conn.sendline("Q") # Quit back to partition control
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- conn.sendline("Q") # Quit back to system command mode
- conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
- conn.sendline("EX") # Quit back to system console menu
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+ conn.sendline("S") # Enter System Command Mode
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
+ conn.sendline("PC") # Enter partition control
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
+ conn.sendline("P") # Enter power control menu
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
+ conn.sendline(action) # Execute action from array above
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
+ conn.sendline(options["--plug"]) # Select blade number from args
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
+ conn.sendline("Y") # Confirm action
+ conn.log_expect(options, "Hit enter key.", int(options["--shell-timeout"]))
+ conn.sendline("") # Press the any key
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
+ conn.sendline("Q") # Quit back to partition control
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
+ conn.sendline("Q") # Quit back to system command mode
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
+ conn.sendline("EX") # Quit back to system console menu
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
def get_blades_list(conn, options):
outlets = { }
- try:
- conn.sendline("S") # Enter System Command Mode
- conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
- conn.sendline("PC") # Enter partition control
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- # Status can now be obtained from the output of the PC
- # command. Line looks like the following:
- # "P Power Condition LID lamp Mode Auto power on"
- # "0 On Normal Off Basic Synchronized"
- # "1 On Normal Off Basic Synchronized"
- for line in conn.before.splitlines():
- partition = re.search(RE_STATUS_LINE, line)
- if( partition != None):
- outlets[partition.group(1)] = (partition.group(2), "")
- conn.sendline("Q") # Quit back to system command mode
- conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
- conn.sendline("EX") # Quit back to system console menu
- conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
- except pexpect.EOF:
- fail(EC_CONNECTION_LOST)
- except pexpect.TIMEOUT:
- fail(EC_TIMED_OUT)
+
+ conn.sendline("S") # Enter System Command Mode
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
+ conn.sendline("PC") # Enter partition control
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
+ # Status can now be obtained from the output of the PC
+ # command. Line looks like the following:
+ # "P Power Condition LID lamp Mode Auto power on"
+ # "0 On Normal Off Basic Synchronized"
+ # "1 On Normal Off Basic Synchronized"
+ for line in conn.before.splitlines():
+ partition = re.search(RE_STATUS_LINE, line)
+ if( partition != None):
+ outlets[partition.group(1)] = (partition.group(2), "")
+ conn.sendline("Q") # Quit back to system command mode
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
+ conn.sendline("EX") # Quit back to system console menu
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
return outlets
@@ -152,9 +138,7 @@ includes telnet support."
try:
conn.sendline("X")
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
11 years, 5 months
fence-agents: master - fence_hds_cb: Port fence agent to longopts
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=af5da5...
Commit: af5da579e90acb9c70ad0f97eff42cd14fd708b5
Parent: d26ddc7daa4b1e1d85374d7bf557f01075e5073d
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Thu Nov 8 10:27:49 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Thu Nov 8 10:36:34 2012 +0100
fence_hds_cb: Port fence agent to longopts
---
fence/agents/hds_cb/fence_hds_cb.py | 42 +++++++++++++++++-----------------
1 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/fence/agents/hds_cb/fence_hds_cb.py b/fence/agents/hds_cb/fence_hds_cb.py
index 859f255..1f944b3 100755
--- a/fence/agents/hds_cb/fence_hds_cb.py
+++ b/fence/agents/hds_cb/fence_hds_cb.py
@@ -27,9 +27,9 @@ def get_power_status(conn, options):
#### Maybe should put a conn.log_expect here to make sure
#### we have properly entered into the main menu
conn.sendline("S") # Enter System Command Mode
- conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
conn.sendline("PC") # Enter partition control
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
result = {}
# Status can now be obtained from the output of the PC
# command. Line looks like the following:
@@ -41,7 +41,7 @@ def get_power_status(conn, options):
partition = re.search(RE_STATUS_LINE, line)
if( partition != None):
# find the blade number defined in args
- if( partition.group(1) == options["-n"] ):
+ if( partition.group(1) == options["--plug"] ):
result = partition.group(2).lower()
# We must make sure we go back to the main menu as the
# status is checked before any fencing operations are
@@ -49,9 +49,9 @@ def get_power_status(conn, options):
# the partition control, but the logic is a little cleaner
# this way.
conn.sendline("Q") # Back to system command mode
- conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
conn.sendline("EX") # Back to system console main menu
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
@@ -64,30 +64,30 @@ def set_power_status(conn, options):
'on' : "P",
'off': "F",
'reboot' : "H",
- }[options["-o"]]
+ }[options["--action"]]
try:
conn.sendline("S") # Enter System Command Mode
- conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
conn.sendline("PC") # Enter partition control
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
conn.sendline("P") # Enter power control menu
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
conn.sendline(action) # Execute action from array above
- conn.log_expect(options, options["-c"], int(options["-Y"]))
- conn.sendline(options["-n"]) # Select blade number from args
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
+ conn.sendline(options["--plug"]) # Select blade number from args
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
conn.sendline("Y") # Confirm action
- conn.log_expect(options, "Hit enter key.", int(options["-Y"]))
+ conn.log_expect(options, "Hit enter key.", int(options["--shell-timeout"]))
conn.sendline("") # Press the any key
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
conn.sendline("Q") # Quit back to partition control
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
conn.sendline("Q") # Quit back to system command mode
- conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
conn.sendline("EX") # Quit back to system console menu
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
@@ -97,9 +97,9 @@ def get_blades_list(conn, options):
outlets = { }
try:
conn.sendline("S") # Enter System Command Mode
- conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
conn.sendline("PC") # Enter partition control
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
# Status can now be obtained from the output of the PC
# command. Line looks like the following:
# "P Power Condition LID lamp Mode Auto power on"
@@ -110,9 +110,9 @@ def get_blades_list(conn, options):
if( partition != None):
outlets[partition.group(1)] = (partition.group(2), "")
conn.sendline("Q") # Quit back to system command mode
- conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["--shell-timeout"]))
conn.sendline("EX") # Quit back to system console menu
- conn.log_expect(options, options["-c"], int(options["-Y"]))
+ conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
11 years, 5 months
fence-agents: master - fence_hds_cb: Style clean-up
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=d26ddc...
Commit: d26ddc7daa4b1e1d85374d7bf557f01075e5073d
Parent: 49f51a6d70fd7890917087c48b9dc0fe5feee8f3
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Nov 5 14:08:37 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Thu Nov 8 10:36:24 2012 +0100
fence_hds_cb: Style clean-up
---
fence/agents/hds_cb/fence_hds_cb.py | 57 ++++++++++++++++------------------
1 files changed, 27 insertions(+), 30 deletions(-)
diff --git a/fence/agents/hds_cb/fence_hds_cb.py b/fence/agents/hds_cb/fence_hds_cb.py
index fa17b08..859f255 100755
--- a/fence/agents/hds_cb/fence_hds_cb.py
+++ b/fence/agents/hds_cb/fence_hds_cb.py
@@ -20,14 +20,16 @@ REDHAT_COPYRIGHT=""
BUILD_DATE="November, 2012"
#END_VERSION_GENERATION
+RE_STATUS_LINE = "^([0-9]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$"
+
def get_power_status(conn, options):
try:
#### Maybe should put a conn.log_expect here to make sure
#### we have properly entered into the main menu
conn.sendline("S") # Enter System Command Mode
- i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["-Y"]))
conn.sendline("PC") # Enter partition control
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
result = {}
# Status can now be obtained from the output of the PC
# command. Line looks like the following:
@@ -36,7 +38,7 @@ def get_power_status(conn, options):
# "1 On Normal Off Basic Synchronized"
for line in conn.before.splitlines():
# populate the relevant fields based on regex
- partition=re.search("^([0-9]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$", line)
+ partition = re.search(RE_STATUS_LINE, line)
if( partition != None):
# find the blade number defined in args
if( partition.group(1) == options["-n"] ):
@@ -47,16 +49,15 @@ def get_power_status(conn, options):
# the partition control, but the logic is a little cleaner
# this way.
conn.sendline("Q") # Back to system command mode
- i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["-Y"]))
conn.sendline("EX") # Back to system console main menu
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
- return result
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
fail(EC_TIMED_OUT)
- return status.lower().strip()
+ return result
def set_power_status(conn, options):
action = {
@@ -68,25 +69,25 @@ def set_power_status(conn, options):
try:
conn.sendline("S") # Enter System Command Mode
- i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["-Y"]))
conn.sendline("PC") # Enter partition control
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
conn.sendline("P") # Enter power control menu
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
conn.sendline(action) # Execute action from array above
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
conn.sendline(options["-n"]) # Select blade number from args
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
conn.sendline("Y") # Confirm action
- i = conn.log_expect(options, "Hit enter key.", int(options["-Y"]))
+ conn.log_expect(options, "Hit enter key.", int(options["-Y"]))
conn.sendline("") # Press the any key
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
conn.sendline("Q") # Quit back to partition control
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
conn.sendline("Q") # Quit back to system command mode
- i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["-Y"]))
conn.sendline("EX") # Quit back to system console menu
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
@@ -96,24 +97,22 @@ def get_blades_list(conn, options):
outlets = { }
try:
conn.sendline("S") # Enter System Command Mode
- i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["-Y"]))
conn.sendline("PC") # Enter partition control
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
- result = {}
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
# Status can now be obtained from the output of the PC
# command. Line looks like the following:
# "P Power Condition LID lamp Mode Auto power on"
# "0 On Normal Off Basic Synchronized"
# "1 On Normal Off Basic Synchronized"
for line in conn.before.splitlines():
- partition=re.search("^([0-9]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$", line)
+ partition = re.search(RE_STATUS_LINE, line)
if( partition != None):
outlets[partition.group(1)] = (partition.group(2), "")
conn.sendline("Q") # Quit back to system command mode
- i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.log_expect(options, "SVP>", int(options["-Y"]))
conn.sendline("EX") # Quit back to system console menu
- i = conn.log_expect(options, "\) :", int(options["-Y"]))
-
+ conn.log_expect(options, options["-c"], int(options["-Y"]))
except pexpect.EOF:
fail(EC_CONNECTION_LOST)
except pexpect.TIMEOUT:
@@ -122,11 +121,9 @@ def get_blades_list(conn, options):
return outlets
def main():
- device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
- "action", "ipaddr", "login", "passwd", "passwd_script",
- "cmd_prompt", "secure", "port", "identity_file", "separator",
- "inet4_only", "inet6_only", "ipport",
- "power_timeout", "shell_timeout", "login_timeout", "power_wait", "missing_as_off" ]
+ device_opt = [ "ipaddr", "login", "passwd", "passwd_script", "cmd_prompt",
+ "secure", "port", "identity_file", "separator", "inet4_only",
+ "inet6_only", "ipport", "missing_as_off" ]
atexit.register(atexit_handler)
@@ -135,7 +132,7 @@ def main():
options = check_input(device_opt, process_input(device_opt))
- docs = { }
+ docs = { }
docs["shortdesc"] = "Fence agent for Hitachi Compute Blade systems"
docs["longdesc"] = "fence_hds_cb is an I/O Fencing agent \
which can be used with Hitachi Compute Blades with recent enough firmware that \
11 years, 5 months
fence-agents: master - Fixed date of copyright. Copy paste error.
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=49f51a...
Commit: 49f51a6d70fd7890917087c48b9dc0fe5feee8f3
Parent: aabf3ebfe8105686cb1213a25764c5afa4542666
Author: Matt Clark <mattjclark0407(a)hotmail.com>
AuthorDate: Mon Nov 5 13:48:43 2012 +1100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Thu Nov 8 10:36:15 2012 +0100
Fixed date of copyright. Copy paste error.
---
doc/COPYRIGHT | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/doc/COPYRIGHT b/doc/COPYRIGHT
index 53c3ec7..8124c53 100644
--- a/doc/COPYRIGHT
+++ b/doc/COPYRIGHT
@@ -6,7 +6,7 @@ Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
Exceptions:
fence/agents/hds_cb/*:
- Copyright (C) 2011 Matthew Clark.
+ Copyright (C) 2012 Matthew Clark.
Author: Matthew Clark <mattjclark0407 at hotmail.com>
fence/agents/xenapi/*:
11 years, 5 months
fence-agents: master - New fencing script for Hitachi compute blade 2000
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=aabf3e...
Commit: aabf3ebfe8105686cb1213a25764c5afa4542666
Parent: e576afe6fd94028ab9971e29817df617c3aaeb70
Author: Matt Clark <mattjclark0407(a)hotmail.com>
AuthorDate: Mon Nov 5 13:34:51 2012 +1100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Thu Nov 8 10:36:07 2012 +0100
New fencing script for Hitachi compute blade 2000
This script uses the system console functionality of the Hitachi compute
blade 2000 systems to fence a node. Status, list, on, off and reboot
have all been implemented. Can use SSH or telnet as provided by the
underlying fencing.py library.
---
configure.ac | 1 +
doc/COPYRIGHT | 4 +
fence/agents/hds_cb/Makefile.am | 17 ++++
fence/agents/hds_cb/fence_hds_cb.py | 166 +++++++++++++++++++++++++++++++++++
4 files changed, 188 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index 1b0ee22..e30581c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -290,6 +290,7 @@ AC_CONFIG_FILES([Makefile
fence/agents/wti/Makefile
fence/agents/xcat/Makefile
fence/agents/xenapi/Makefile
+ fence/agents/hds_cb/Makefile
fence/agents/zvm/Makefile
doc/Makefile])
diff --git a/doc/COPYRIGHT b/doc/COPYRIGHT
index 5afc642..53c3ec7 100644
--- a/doc/COPYRIGHT
+++ b/doc/COPYRIGHT
@@ -5,6 +5,10 @@ Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
Exceptions:
+fence/agents/hds_cb/*:
+ Copyright (C) 2011 Matthew Clark.
+ Author: Matthew Clark <mattjclark0407 at hotmail.com>
+
fence/agents/xenapi/*:
Copyright (C) 2011 Matthew Clark.
Author: Matthew Clark <mattjclark0407 at hotmail.com>
diff --git a/fence/agents/hds_cb/Makefile.am b/fence/agents/hds_cb/Makefile.am
new file mode 100644
index 0000000..0763d5a
--- /dev/null
+++ b/fence/agents/hds_cb/Makefile.am
@@ -0,0 +1,17 @@
+MAINTAINERCLEANFILES = Makefile.in
+
+TARGET = fence_hds_cb
+
+SRC = $(TARGET).py
+
+EXTRA_DIST = $(SRC)
+
+sbin_SCRIPTS = $(TARGET)
+
+man_MANS = $(TARGET).8
+
+include $(top_srcdir)/make/fencebuild.mk
+include $(top_srcdir)/make/fenceman.mk
+
+clean-local: clean-man
+ rm -f $(TARGET)
diff --git a/fence/agents/hds_cb/fence_hds_cb.py b/fence/agents/hds_cb/fence_hds_cb.py
new file mode 100755
index 0000000..fa17b08
--- /dev/null
+++ b/fence/agents/hds_cb/fence_hds_cb.py
@@ -0,0 +1,166 @@
+#!/usr/bin/python
+
+#####
+##
+## The Following Agent Has Been Tested On:
+##
+## Model Modle/Firmware
+## +--------------------+---------------------------+
+## (1) Main application CB2000/A0300-E-6617
+##
+#####
+
+import sys, re, pexpect, exceptions
+sys.path.append("@FENCEAGENTSLIBDIR@")
+from fencing import *
+
+#BEGIN_VERSION_GENERATION
+RELEASE_VERSION="New Compute Blade 2000 Agent - test release on steroids"
+REDHAT_COPYRIGHT=""
+BUILD_DATE="November, 2012"
+#END_VERSION_GENERATION
+
+def get_power_status(conn, options):
+ try:
+ #### Maybe should put a conn.log_expect here to make sure
+ #### we have properly entered into the main menu
+ conn.sendline("S") # Enter System Command Mode
+ i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.sendline("PC") # Enter partition control
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ result = {}
+ # Status can now be obtained from the output of the PC
+ # command. Line looks like the following:
+ # "P Power Condition LID lamp Mode Auto power on"
+ # "0 On Normal Off Basic Synchronized"
+ # "1 On Normal Off Basic Synchronized"
+ for line in conn.before.splitlines():
+ # populate the relevant fields based on regex
+ partition=re.search("^([0-9]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$", line)
+ if( partition != None):
+ # find the blade number defined in args
+ if( partition.group(1) == options["-n"] ):
+ result = partition.group(2).lower()
+ # We must make sure we go back to the main menu as the
+ # status is checked before any fencing operations are
+ # executed. We could in theory save some time by staying in
+ # the partition control, but the logic is a little cleaner
+ # this way.
+ conn.sendline("Q") # Back to system command mode
+ i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.sendline("EX") # Back to system console main menu
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ return result
+ except pexpect.EOF:
+ fail(EC_CONNECTION_LOST)
+ except pexpect.TIMEOUT:
+ fail(EC_TIMED_OUT)
+
+ return status.lower().strip()
+
+def set_power_status(conn, options):
+ action = {
+ 'on' : "P",
+ 'off': "F",
+ 'reboot' : "H",
+ }[options["-o"]]
+
+
+ try:
+ conn.sendline("S") # Enter System Command Mode
+ i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.sendline("PC") # Enter partition control
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.sendline("P") # Enter power control menu
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.sendline(action) # Execute action from array above
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.sendline(options["-n"]) # Select blade number from args
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.sendline("Y") # Confirm action
+ i = conn.log_expect(options, "Hit enter key.", int(options["-Y"]))
+ conn.sendline("") # Press the any key
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.sendline("Q") # Quit back to partition control
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ conn.sendline("Q") # Quit back to system command mode
+ i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.sendline("EX") # Quit back to system console menu
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ except pexpect.EOF:
+ fail(EC_CONNECTION_LOST)
+ except pexpect.TIMEOUT:
+ fail(EC_TIMED_OUT)
+
+def get_blades_list(conn, options):
+ outlets = { }
+ try:
+ conn.sendline("S") # Enter System Command Mode
+ i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.sendline("PC") # Enter partition control
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+ result = {}
+ # Status can now be obtained from the output of the PC
+ # command. Line looks like the following:
+ # "P Power Condition LID lamp Mode Auto power on"
+ # "0 On Normal Off Basic Synchronized"
+ # "1 On Normal Off Basic Synchronized"
+ for line in conn.before.splitlines():
+ partition=re.search("^([0-9]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+).*$", line)
+ if( partition != None):
+ outlets[partition.group(1)] = (partition.group(2), "")
+ conn.sendline("Q") # Quit back to system command mode
+ i = conn.log_expect(options, "SVP>", int(options["-Y"]))
+ conn.sendline("EX") # Quit back to system console menu
+ i = conn.log_expect(options, "\) :", int(options["-Y"]))
+
+ except pexpect.EOF:
+ fail(EC_CONNECTION_LOST)
+ except pexpect.TIMEOUT:
+ fail(EC_TIMED_OUT)
+
+ return outlets
+
+def main():
+ device_opt = [ "help", "version", "agent", "quiet", "verbose", "debug",
+ "action", "ipaddr", "login", "passwd", "passwd_script",
+ "cmd_prompt", "secure", "port", "identity_file", "separator",
+ "inet4_only", "inet6_only", "ipport",
+ "power_timeout", "shell_timeout", "login_timeout", "power_wait", "missing_as_off" ]
+
+ atexit.register(atexit_handler)
+
+ all_opt["power_wait"]["default"] = "5"
+ all_opt["cmd_prompt"]["default"] = "\) :"
+
+ options = check_input(device_opt, process_input(device_opt))
+
+ docs = { }
+ docs["shortdesc"] = "Fence agent for Hitachi Compute Blade systems"
+ docs["longdesc"] = "fence_hds_cb is an I/O Fencing agent \
+which can be used with Hitachi Compute Blades with recent enough firmware that \
+includes telnet support."
+ docs["vendorurl"] = "http://www.hds.com"
+ show_docs(options, docs)
+
+ ##
+ ## Operate the fencing device
+ ######
+ conn = fence_login(options)
+ result = fence_action(conn, options, set_power_status, get_power_status, get_blades_list)
+
+ ##
+ ## Logout from system
+ ######
+ try:
+ conn.sendline("X")
+ conn.close()
+ except exceptions.OSError:
+ pass
+ except pexpect.ExceptionPexpect:
+ pass
+
+ sys.exit(result)
+
+if __name__ == "__main__":
+ main()
11 years, 5 months
fence-agents: master - fence agents: Transfer SNMP fence agents to long-opts + transfer script
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=e576af...
Commit: e576afe6fd94028ab9971e29817df617c3aaeb70
Parent: c737522f0bd8e5663b7d57a62528c78ce002aefe
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Nov 5 17:32:34 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Thu Nov 8 10:20:42 2012 +0100
fence agents: Transfer SNMP fence agents to long-opts + transfer script
---
fence/agents/apc_snmp/fence_apc_snmp.py | 24 ++++++++--------
fence/agents/cisco_mds/fence_cisco_mds.py | 6 ++--
fence/agents/ibmblade/fence_ibmblade.py | 4 +-
fence/agents/ifmib/fence_ifmib.py | 6 ++--
fence/agents/intelmodular/fence_intelmodular.py | 4 +-
fence/agents/ipdu/fence_ipdu.py | 10 +++---
fence/agents/lib/fencing_snmp.py.py | 33 ++++++++++++-----------
fence/agents/lib/transfer.py | 16 +++++++++++
8 files changed, 60 insertions(+), 43 deletions(-)
diff --git a/fence/agents/apc_snmp/fence_apc_snmp.py b/fence/agents/apc_snmp/fence_apc_snmp.py
index 6f95f37..8a97ae4 100644
--- a/fence/agents/apc_snmp/fence_apc_snmp.py
+++ b/fence/agents/apc_snmp/fence_apc_snmp.py
@@ -94,16 +94,16 @@ def apc_resolv_port_id(conn, options):
apc_set_device(conn, options)
# Now we resolv port_id/switch_id
- if ((options["-n"].isdigit()) and ((not device.has_switches) or (options["-s"].isdigit()))):
- port_id = int(options["-n"])
+ if ((options["--plug"].isdigit()) and ((not device.has_switches) or (options["--switch"].isdigit()))):
+ port_id = int(options["--plug"])
if (device.has_switches):
- switch_id = int(options["-s"])
+ switch_id = int(options["--switch"])
else:
table = conn.walk(device.outlet_table_oid, 30)
for x in table:
- if (x[1].strip('"') == options["-n"]):
+ if (x[1].strip('"') == options["--plug"]):
t = x[0].split('.')
if (device.has_switches):
port_id = int(t[len(t)-1])
@@ -112,7 +112,7 @@ def apc_resolv_port_id(conn, options):
port_id = int(t[len(t)-1])
if (port_id == None):
- fail_usage("Can't find port with name %s!"%(options["-n"]))
+ fail_usage("Can't find port with name %s!"%(options["--plug"]))
def get_power_status(conn, options):
if (port_id == None):
@@ -129,7 +129,7 @@ def set_power_status(conn, options):
oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id))
- conn.set(oid, (options["-o"]=="on" and device.turn_on or device.turn_off))
+ conn.set(oid, (options["--action"]=="on" and device.turn_on or device.turn_off))
def get_outlets_status(conn, options):
@@ -172,14 +172,14 @@ def main():
options = check_input(device_opt, process_input(device_opt))
## Support for -n [switch]:[plug] notation that was used before
- if ((options.has_key("-n")) and (-1 != options["-n"].find(":"))):
- (switch, plug) = options["-n"].split(":", 1)
+ if ((options.has_key("--plug")) and (-1 != options["--plug"].find(":"))):
+ (switch, plug) = options["--plug"].split(":", 1)
if ((switch.isdigit()) and (plug.isdigit())):
- options["-s"] = switch
- options["-n"] = plug
+ options["--switch"] = switch
+ options["--plug"] = plug
- if (not (options.has_key("-s"))):
- options["-s"] = "1"
+ if (not (options.has_key("--switch"))):
+ options["--switch"] = "1"
docs = { }
docs["shortdesc"] = "Fence agent for APC over SNMP"
diff --git a/fence/agents/cisco_mds/fence_cisco_mds.py b/fence/agents/cisco_mds/fence_cisco_mds.py
index 8ebce8a..cb45d73 100644
--- a/fence/agents/cisco_mds/fence_cisco_mds.py
+++ b/fence/agents/cisco_mds/fence_cisco_mds.py
@@ -47,7 +47,7 @@ def get_power_status(conn, options):
return (status=="1" and "on" or "off")
def set_power_status(conn, options):
- conn.set(PORT_OID, (options["-o"]=="on" and 1 or 2))
+ conn.set(PORT_OID, (options["--action"]=="on" and 1 or 2))
# Convert array of format [[key1, value1], [key2, value2], ... [keyN, valueN]] to dict, where key is
# in format a.b.c.d...z and returned dict has key only z
@@ -96,8 +96,8 @@ which can be used with any Cisco MDS 9000 series with SNMP enabled device."
docs["vendorurl"] = "http://www.cisco.com"
show_docs(options, docs)
- if (not (options["-o"] in ["list","monitor"])):
- PORT_OID = cisco_port2oid(options["-n"])
+ if (not (options["--action"] in ["list","monitor"])):
+ PORT_OID = cisco_port2oid(options["--plug"])
# Operate the fencing device
result = fence_action(FencingSnmp(options), options, set_power_status, get_power_status, get_outlets_status)
diff --git a/fence/agents/ibmblade/fence_ibmblade.py b/fence/agents/ibmblade/fence_ibmblade.py
index ceb747d..759bfc4 100644
--- a/fence/agents/ibmblade/fence_ibmblade.py
+++ b/fence/agents/ibmblade/fence_ibmblade.py
@@ -27,11 +27,11 @@ STATUS_SET_ON = 1
### FUNCTIONS ###
def get_power_status(conn, options):
- (_, status) = conn.get("%s.%s"% (STATUSES_OID, options["-n"]))
+ (_, status) = conn.get("%s.%s"% (STATUSES_OID, options["--plug"]))
return (status == str(STATUS_UP) and "on" or "off")
def set_power_status(conn, options):
- conn.set("%s.%s"%(CONTROL_OID, options["-n"]), (options["-o"]=="on" and STATUS_SET_ON or STATUS_SET_OFF))
+ conn.set("%s.%s"%(CONTROL_OID, options["--plug"]), (options["--action"]=="on" and STATUS_SET_ON or STATUS_SET_OFF))
def get_outlets_status(conn, _):
result = {}
diff --git a/fence/agents/ifmib/fence_ifmib.py b/fence/agents/ifmib/fence_ifmib.py
index 170134e..9a17257 100644
--- a/fence/agents/ifmib/fence_ifmib.py
+++ b/fence/agents/ifmib/fence_ifmib.py
@@ -59,7 +59,7 @@ def get_power_status(conn, options):
global port_num
if (port_num==None):
- port_num = port2index(conn, options["-n"])
+ port_num = port2index(conn, options["--plug"])
(oid, status) = conn.get("%s.%d"%(STATUSES_OID, port_num))
return (status==str(STATUS_UP) and "on" or "off")
@@ -68,9 +68,9 @@ def set_power_status(conn, options):
global port_num
if (port_num==None):
- port_num = port2index(conn, options["-n"])
+ port_num = port2index(conn, options["--plug"])
- conn.set("%s.%d"%(STATUSES_OID, port_num), (options["-o"]=="on" and STATUS_UP or STATUS_DOWN))
+ conn.set("%s.%d"%(STATUSES_OID, port_num), (options["--action"]=="on" and STATUS_UP or STATUS_DOWN))
# Convert array of format [[key1, value1], [key2, value2], ... [keyN, valueN]] to dict, where key is
# in format a.b.c.d...z and returned dict has key only z
diff --git a/fence/agents/intelmodular/fence_intelmodular.py b/fence/agents/intelmodular/fence_intelmodular.py
index 3fd9822..a590ced 100644
--- a/fence/agents/intelmodular/fence_intelmodular.py
+++ b/fence/agents/intelmodular/fence_intelmodular.py
@@ -38,11 +38,11 @@ STATUS_SET_OFF = 3
### FUNCTIONS ###
def get_power_status(conn, options):
- (oid, status) = conn.get("%s.%s"% (STATUSES_OID, options["-n"]))
+ (oid, status) = conn.get("%s.%s"% (STATUSES_OID, options["--plug"]))
return (status==str(STATUS_UP) and "on" or "off")
def set_power_status(conn, options):
- conn.set("%s.%s"%(STATUSES_OID, options["-n"]), (options["-o"]=="on" and STATUS_SET_ON or STATUS_SET_OFF))
+ conn.set("%s.%s"%(STATUSES_OID, options["--plug"]), (options["--action"]=="on" and STATUS_SET_ON or STATUS_SET_OFF))
def get_outlets_status(conn, options):
result = {}
diff --git a/fence/agents/ipdu/fence_ipdu.py b/fence/agents/ipdu/fence_ipdu.py
index da7f192..6c93b53 100644
--- a/fence/agents/ipdu/fence_ipdu.py
+++ b/fence/agents/ipdu/fence_ipdu.py
@@ -66,8 +66,8 @@ def ipdu_resolv_port_id(conn, options):
ipdu_set_device(conn, options)
# Now we resolv port_id/switch_id
- if ((options["-n"].isdigit()) and ((not device.has_switches) or (options["-s"].isdigit()))):
- port_id = int(options["-n"])
+ if ((options["--plug"].isdigit()) and ((not device.has_switches) or (options["-s"].isdigit()))):
+ port_id = int(options["--plug"])
if (device.has_switches):
switch_id = int(options["-s"])
@@ -75,7 +75,7 @@ def ipdu_resolv_port_id(conn, options):
table = conn.walk(device.outlet_table_oid, 30)
for x in table:
- if (x[1].strip('"')==options["-n"]):
+ if (x[1].strip('"')==options["--plug"]):
t = x[0].split('.')
if (device.has_switches):
port_id = int(t[len(t)-1])
@@ -84,7 +84,7 @@ def ipdu_resolv_port_id(conn, options):
port_id = int(t[len(t)-1])
if (port_id==None):
- fail_usage("Can't find port with name %s!"%(options["-n"]))
+ fail_usage("Can't find port with name %s!"%(options["--plug"]))
def get_power_status(conn, options):
if (port_id==None):
@@ -101,7 +101,7 @@ def set_power_status(conn, options):
oid = ((device.has_switches) and device.control_oid%(switch_id, port_id) or device.control_oid%(port_id))
- conn.set(oid,(options["-o"]=="on" and device.turn_on or device.turn_off))
+ conn.set(oid,(options["--action"]=="on" and device.turn_on or device.turn_off))
def get_outlets_status(conn, options):
diff --git a/fence/agents/lib/fencing_snmp.py.py b/fence/agents/lib/fencing_snmp.py.py
index e4c4636..89f8ece 100644
--- a/fence/agents/lib/fencing_snmp.py.py
+++ b/fence/agents/lib/fencing_snmp.py.py
@@ -31,8 +31,8 @@ class FencingSnmp:
def complete_missed_params(self):
mapping = [
- [['P','p','!E'],'self.options["-E"]="authPriv"'],
- [['!d','c','!l','!P','!p'],'self.options["-d"]="2c"']
+ [['snmp-priv-passwd','password','!snmp-sec-level'],'self.options["--snmp-sec-level"]="authPriv"'],
+ [['!snmp-version','community','!username','!snmp-priv-passwd','!password'],'self.options["--snmp-version"]="2c"']
]
for val in mapping:
@@ -41,11 +41,11 @@ class FencingSnmp:
res = True
for item in e:
- if ((item[0]=='!') and (self.options.has_key("-"+item[1]))):
+ if ((item[0]=='!') and (self.options.has_key("--"+item[1:]))):
res = False
break
- if ((item[0]!='!') and (not self.options.has_key("-"+item[0]))):
+ if ((item[0]!='!') and (not self.options.has_key("--"+item[0:]))):
res = False
break
@@ -58,37 +58,38 @@ class FencingSnmp:
self.complete_missed_params()
#mapping from our option to snmpcmd option
- mapping = (('d', 'v'),('c', 'c'))
+ mapping = (('snmp-version', 'v'),('community', 'c'))
for item in mapping:
- if (self.options.has_key("-"+item[0])):
- cmd += " -%s '%s'"% (item[1], self.quote_for_run(self.options["-" + item[0]]))
+ if (self.options.has_key("--" + item[0])):
+ cmd += " -%s '%s'"% (item[1], self.quote_for_run(self.options["--" + item[0]]))
# Some options make sense only for v3 (and for v1/2c can cause "problems")
- if (self.options.has_key("-d")) and (self.options["-d"] == "3"):
+ if (self.options.has_key("--snmp-version")) and (self.options["--snmp-version"] == "3"):
# Mapping from our options to snmpcmd options for v3
- mapping_v3 = (('b','a'),('E','l'),('B','x'),('P','X'),('p','A'),('l','u'))
+ mapping_v3 = (('snmp-auth-prot','a'), ('snmp-sec-level','l'), ('snmp-priv-prot','x'), \
+ ('snmp-priv-passwd','X'),('password','A'),('username','u'))
for item in mapping_v3:
- if (self.options.has_key("-"+item[0])):
- cmd += " -%s '%s'"% (item[1], self.quote_for_run(self.options["-" + item[0]]))
+ if (self.options.has_key("--"+item[0])):
+ cmd += " -%s '%s'"% (item[1], self.quote_for_run(self.options["--" + item[1]]))
force_ipvx = ""
- if (self.options.has_key("-6")):
+ if (self.options.has_key("--inet6-only")):
force_ipvx = "udp6:"
- if (self.options.has_key("-4")):
+ if (self.options.has_key("--inet4-only")):
force_ipvx = "udp:"
- cmd += " '%s%s%s'"% (force_ipvx, self.quote_for_run(self.options["-a"]),
- self.options.has_key("-u") and self.quote_for_run(":" + str (self.options["-u"])) or "")
+ cmd += " '%s%s%s'"% (force_ipvx, self.quote_for_run(self.options["--ip"]),
+ self.options.has_key("--udpport") and self.quote_for_run(":" + str (self.options["--udpport"])) or "")
return cmd
def run_command(self, command, additional_timemout=0):
try:
self.log_command(command)
- (res_output, res_code) = pexpect.run(command, int(self.options["-Y"]) + int(self.options["-y"]) + additional_timemout, True)
+ (res_output, res_code) = pexpect.run(command, int(self.options["--shell-timeout"]) + int(self.options["--login-timeout"]) + additional_timemout, True)
if (res_code==None):
fail(EC_TIMED_OUT)
diff --git a/fence/agents/lib/transfer.py b/fence/agents/lib/transfer.py
new file mode 100755
index 0000000..ddf2486
--- /dev/null
+++ b/fence/agents/lib/transfer.py
@@ -0,0 +1,16 @@
+#!/usr/bin/python
+
+from fencing import *
+
+def main():
+ for key in all_opt.keys():
+ if all_opt[key].has_key("getopt") and all_opt[key].has_key("longopt"):
+ print "s/options\[\"-" + all_opt[key]["getopt"].rstrip(":") + "\"\]/options[\"--" + \
+ all_opt[key]["longopt"] + "\"]/g"
+ print "s/options.has_key(\"-" + all_opt[key]["getopt"].rstrip(":") + "\")/options.has_key(" + \
+ "\"--" + all_opt[key]["longopt"] + "\")/g"
+
+
+
+if __name__ == "__main__":
+ main()
\ No newline at end of file
11 years, 5 months
fence-agents: master - fencing: Simplify exceptions catching when closing connection
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=c73752...
Commit: c737522f0bd8e5663b7d57a62528c78ce002aefe
Parent: a5a8c1fae0a55ef6d4558e83bffd4c9c04fcd559
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Mon Nov 5 16:28:38 2012 +0100
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Thu Nov 8 10:20:31 2012 +0100
fencing: Simplify exceptions catching when closing connection
When we are closing connection we do not care about exceptions. For example
if action 'exit' failed, fencing is succesful anyway because our goal was to fence machine.
---
fence/agents/alom/fence_alom.py | 4 +---
fence/agents/apc/fence_apc.py | 4 +---
fence/agents/bladecenter/fence_bladecenter.py | 4 +---
fence/agents/drac5/fence_drac5.py | 4 +---
fence/agents/hpblade/fence_hpblade.py | 4 +---
fence/agents/ilo_mp/fence_ilo_mp.py | 4 +---
fence/agents/lpar/fence_lpar.py | 4 +---
fence/agents/rsa/fence_rsa.py | 4 +---
fence/agents/rsb/fence_rsb.py | 4 +---
fence/agents/virsh/fence_virsh.py | 4 +---
fence/agents/wti/fence_wti.py | 4 +---
11 files changed, 11 insertions(+), 33 deletions(-)
diff --git a/fence/agents/alom/fence_alom.py b/fence/agents/alom/fence_alom.py
index abe0a1a..f1810d2 100644
--- a/fence/agents/alom/fence_alom.py
+++ b/fence/agents/alom/fence_alom.py
@@ -57,9 +57,7 @@ agent which can be used with ALOM connected machines."
try:
conn.send_eol("logout")
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
diff --git a/fence/agents/apc/fence_apc.py b/fence/agents/apc/fence_apc.py
index 9236a30..e98d9ce 100644
--- a/fence/agents/apc/fence_apc.py
+++ b/fence/agents/apc/fence_apc.py
@@ -217,9 +217,7 @@ will block any necessary fencing actions."
try:
conn.send_eol("4")
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
diff --git a/fence/agents/bladecenter/fence_bladecenter.py b/fence/agents/bladecenter/fence_bladecenter.py
index cf38e10..2a0caf9 100644
--- a/fence/agents/bladecenter/fence_bladecenter.py
+++ b/fence/agents/bladecenter/fence_bladecenter.py
@@ -110,9 +110,7 @@ and uses the command line interface to power on and off blades."
try:
conn.send_eol("exit")
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
diff --git a/fence/agents/drac5/fence_drac5.py b/fence/agents/drac5/fence_drac5.py
index bce8cef..47d8db7 100644
--- a/fence/agents/drac5/fence_drac5.py
+++ b/fence/agents/drac5/fence_drac5.py
@@ -114,9 +114,7 @@ By default, the telnet interface is not enabled."
conn.send_eol("exit")
time.sleep(1)
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
diff --git a/fence/agents/hpblade/fence_hpblade.py b/fence/agents/hpblade/fence_hpblade.py
index 6532065..6cea46a 100644
--- a/fence/agents/hpblade/fence_hpblade.py
+++ b/fence/agents/hpblade/fence_hpblade.py
@@ -88,9 +88,7 @@ and uses the command line interface to power on and off blades."
try:
conn.send_eol("exit")
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
diff --git a/fence/agents/ilo_mp/fence_ilo_mp.py b/fence/agents/ilo_mp/fence_ilo_mp.py
index 85764c6..1e14935 100644
--- a/fence/agents/ilo_mp/fence_ilo_mp.py
+++ b/fence/agents/ilo_mp/fence_ilo_mp.py
@@ -61,9 +61,7 @@ def main():
try:
conn.send_eol("exit")
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
diff --git a/fence/agents/lpar/fence_lpar.py b/fence/agents/lpar/fence_lpar.py
index 0bae359..252a659 100644
--- a/fence/agents/lpar/fence_lpar.py
+++ b/fence/agents/lpar/fence_lpar.py
@@ -138,10 +138,8 @@ def main():
try:
conn.send("quit\r\n")
conn.close()
- except exceptions.OSError:
+ except:
pass
- except pexpect.ExceptionPexpect:
- pass
sys.exit(result)
if __name__ == "__main__":
diff --git a/fence/agents/rsa/fence_rsa.py b/fence/agents/rsa/fence_rsa.py
index e1e303f..578e34d 100644
--- a/fence/agents/rsa/fence_rsa.py
+++ b/fence/agents/rsa/fence_rsa.py
@@ -70,9 +70,7 @@ will block any necessary fencing actions."
try:
conn.send_eol("exit")
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
diff --git a/fence/agents/rsb/fence_rsb.py b/fence/agents/rsb/fence_rsb.py
index 395a844..87ed53a 100755
--- a/fence/agents/rsb/fence_rsb.py
+++ b/fence/agents/rsb/fence_rsb.py
@@ -88,9 +88,7 @@ will block any necessary fencing actions."
try:
conn.send_eol("0")
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
diff --git a/fence/agents/virsh/fence_virsh.py b/fence/agents/virsh/fence_virsh.py
index b157385..113de8f 100644
--- a/fence/agents/virsh/fence_virsh.py
+++ b/fence/agents/virsh/fence_virsh.py
@@ -91,9 +91,7 @@ must allow ssh login in your sshd_config."
try:
conn.sendline("quit")
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index 80b5e96..063352e 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -151,9 +151,7 @@ is running because the connection will block any necessary fencing actions."
try:
conn.send("/X"+"\r\n")
conn.close()
- except exceptions.OSError:
- pass
- except pexpect.ExceptionPexpect:
+ except:
pass
sys.exit(result)
11 years, 5 months