From: jparsons@sourceware.org <jparsons@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/fence/agents/apc fence_apc.py
Date: 27 Jun 2007 15:10:28 -0000 [thread overview]
Message-ID: <20070627151028.15483.qmail@sourceware.org> (raw)
CVSROOT: /cvs/cluster
Module name: cluster
Branch: RHEL5
Changes by: jparsons at sourceware.org 2007-06-27 15:10:27
Modified files:
fence/agents/apc: fence_apc.py
Log message:
passwd script capable
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/apc/fence_apc.py.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.1.4.2&r2=1.1.4.3
--- cluster/fence/agents/apc/fence_apc.py 2007/06/27 15:03:44 1.1.4.2
+++ cluster/fence/agents/apc/fence_apc.py 2007/06/27 15:10:27 1.1.4.3
@@ -47,6 +47,7 @@
address = ""
login = ""
passwd = ""
+passwd_script = ""
port = ""
switchnum = ""
action = POWER_REBOOT #default action
@@ -89,6 +90,7 @@
print " -l [login] login name"
print " -n [port] switch port"
print " -p [password] password"
+ print " -S [path] script to run to retrieve password"
print " -o [action] Reboot (default), Off, On, or Status"
print " -v Verbose Verbose mode - writes file to /tmp/apclog"
print " -V Print Version, then exit"
@@ -102,16 +104,16 @@
def main():
- global address, login, passwd, port, action, verbose, logfile, switchnum
+ global address, login, passwd, passwd_script, port, action, verbose, logfile, switchnum
if len(sys.argv) > 1:
try:
- opts, args = getopt.getopt(sys.argv[1:], "a:hl:o:n:p:vV", ["help", "output="])
+ opts, args = getopt.getopt(sys.argv[1:], "a:hl:o:n:p:S:vV", ["help", "output="])
except getopt.GetoptError:
#print help info and quit
usage()
sys.exit(2)
-
+
for o, a in opts:
if o == "-v":
verbose = True
@@ -124,6 +126,8 @@
login = a
if o == "-p":
passwd = a
+ if o == "-S":
+ passwd_script = a
if o == "-n":
dex = a.find(":")
if dex == (-1):
@@ -145,16 +149,17 @@
sys.exit()
if o == "-a":
address = a
- if address == "" or login == "" or passwd == "" or port == "":
+ if address == "" or login == "" or (passwd == "" and passwd_script == "") or port == "":
usage()
sys.exit()
-
+
else: #Take args from stdin...
params = {}
#place params in dict
for line in sys.stdin:
val = line.split("=")
- params[val[0]] = val[1]
+ if len(val) == 2:
+ params[val[0].strip()] = val[1].strip()
try:
address = params["ipaddr"]
@@ -167,9 +172,14 @@
sys.stderr.write("FENCE: Missing login param for fence_apc...exiting")
sys.exit(1)
try:
- passwd = params["passwd"]
- except KeyError, e:
- sys.stderr.write("FENCE: Missing passwd param for fence_apc...exiting")
+ if 'passwd' in params:
+ passwd = params["passwd"]
+ if 'passwd_script' in params:
+ passwd_script = params['passwd_script']
+ if passwd == "" and passwd_script == "":
+ raise "missing password"
+ except:
+ sys.stderr.write("FENCE: Missing passwd for fence_apc...exiting")
sys.exit(1)
try:
port = params["port"]
@@ -196,9 +206,67 @@
action = POWER_REBOOT
except KeyError, e:
action = POWER_REBOOT
-
+
#### End of stdin section
-
+
+
+ # retrieve passwd from passwd_script (if specified)
+ passwd_scr = ''
+ if len(passwd_script):
+ try:
+ if not os.access(passwd_script, os.X_OK):
+ raise 'script not executable'
+ p = os.popen(passwd_script, 'r', 1024)
+ passwd_scr = p.readline().strip()
+ if p.close() != None:
+ raise 'script failed'
+ except:
+ sys.stderr.write('password-script "%s" failed\n' % passwd_script)
+ passwd_scr = ''
+
+ if passwd == "" and passwd_scr == "":
+ sys.stderr.write('password not available, exiting...')
+ sys.exit(1)
+ elif passwd == passwd_scr:
+ pass
+ elif passwd and passwd_scr:
+ # execute self, with password_scr as passwd,
+ # if that fails, continue with "passwd" argument as password
+ if len(sys.argv) > 1:
+ comm = sys.argv[0]
+ skip_next = False
+ for w in sys.argv[1:]:
+ if skip_next:
+ skip_next = False
+ elif w in ['-p', '-S']:
+ skip_next = True
+ else:
+ comm += ' ' + w
+ comm += ' -p ' + passwd_scr
+ ret = os.system(comm)
+ if ret != -1 and os.WIFEXITED(ret) and os.WEXITSTATUS(ret) == 0:
+ # success
+ sys.exit(0)
+ else:
+ sys.stderr.write('Use of password from "passwd_script" failed, trying "passwd" argument\n')
+ else: # use stdin
+ p = os.popen(sys.argv[0], 'w', 1024)
+ for par in params:
+ if par not in ['passwd', 'passwd_script']:
+ p.write(par + '=' + params[par] + '\n')
+ p.write('passwd=' + passwd_scr + '\n')
+ p.flush()
+ if p.close() == None:
+ # success
+ sys.exit(0)
+ else:
+ sys.stderr.write('Use of password from "passwd_script" failed, trying "passwd" argument\n')
+ elif passwd_scr:
+ passwd = passwd_scr
+ # passwd all set
+
+
+
### Order of events
# 0) If verbose, prepare log file handle
# 1) Open socket
@@ -651,7 +719,7 @@
for l in ls:
words = l.strip().split()
if len(words) > 3:
- if words[3].strip() == portval:
+ if '----' not in words[0] and words[3].strip() == portval:
outlet_str = words[0]
dex = outlet_str.find("-")
if dex <= (0):
next reply other threads:[~2007-06-27 15:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-27 15:10 jparsons [this message]
-- strict thread matches above, loose matches on Subject: below --
2007-10-09 14:56 [Cluster-devel] cluster/fence/agents/apc fence_apc.py jparsons
2007-07-17 18:38 rmccabe
2007-07-17 18:34 rmccabe
2007-07-12 3:45 jparsons
2007-07-12 3:39 jparsons
2007-07-11 6:37 jparsons
2007-06-27 15:03 jparsons
2007-02-27 16:07 kupcevic
2007-02-27 15:53 kupcevic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070627151028.15483.qmail@sourceware.org \
--to=jparsons@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).