Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.0:Ports
pssh
0008-openSUSE-add-C-pcmk_nodes-option-to-get-li...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0008-openSUSE-add-C-pcmk_nodes-option-to-get-list-of-node.patch of Package pssh
From 755b1ce33d6f726c54891eadb9bd61c7893f5252 Mon Sep 17 00:00:00 2001 From: Dejan Muhamedagic <dejan@suse.de> Date: Fri, 10 Jan 2014 12:17:23 +0100 Subject: [PATCH 8/8] openSUSE: add -C/--pcmk_nodes option to get list of nodes from Pacemaker --- bin/pnuke | 4 +++- bin/prsync | 4 +++- bin/pscp | 4 +++- bin/pslurp | 4 +++- bin/pssh | 6 +++++- psshlib/cli.py | 2 ++ psshlib/psshutil.py | 30 ++++++++++++++++++++++++++++++ 7 files changed, 49 insertions(+), 5 deletions(-) diff --git a/bin/pnuke b/bin/pnuke index 884ac25a1d35..ec314f3858e8 100755 --- a/bin/pnuke +++ b/bin/pnuke @@ -40,7 +40,7 @@ def parse_args(): if len(args) > 1: parser.error('Extra arguments given after the pattern.') - if not opts.host_files and not opts.host_strings: + if not opts.host_files and not opts.host_strings and not opts.pcmk_nodes: parser.error('Hosts not specified.') return opts, args @@ -93,4 +93,6 @@ if __name__ == "__main__": if opts.host_strings: for s in opts.host_strings: hosts.extend(psshutil.parse_host_string(s, default_user=opts.user)) + if opts.pcmk_nodes: + hosts += psshutil.get_pcmk_nodes() do_pnuke(hosts, pattern, opts) diff --git a/bin/prsync b/bin/prsync index 5e25786a90e8..d7868c87a945 100755 --- a/bin/prsync +++ b/bin/prsync @@ -52,7 +52,7 @@ def parse_args(): if len(args) < 2: parser.error('Remote path not specified.') - if not opts.host_files and not opts.host_strings: + if not opts.host_files and not opts.host_strings and not opts.pcmk_nodes: parser.error('Hosts not specified.') return opts, args @@ -117,4 +117,6 @@ if __name__ == "__main__": if opts.host_strings: for s in opts.host_strings: hosts.extend(psshutil.parse_host_string(s, default_user=opts.user)) + if opts.pcmk_nodes: + hosts += psshutil.get_pcmk_nodes() do_prsync(hosts, local, remote, opts) diff --git a/bin/pscp b/bin/pscp index d569be7d5404..4408913ce077 100755 --- a/bin/pscp +++ b/bin/pscp @@ -47,7 +47,7 @@ def parse_args(): if len(args) < 2: parser.error('Remote path not specified.') - if not opts.host_files and not opts.host_strings: + if not opts.host_files and not opts.host_strings and not opts.pcmk_nodes: parser.error('Hosts not specified.') return opts, args @@ -102,4 +102,6 @@ if __name__ == "__main__": if opts.host_strings: for s in opts.host_strings: hosts.extend(psshutil.parse_host_string(s, default_user=opts.user)) + if opts.pcmk_nodes: + hosts += psshutil.get_pcmk_nodes() do_pscp(hosts, localargs, remote, opts) diff --git a/bin/pslurp b/bin/pslurp index c7dece656f1b..0f17b5bc87d9 100755 --- a/bin/pslurp +++ b/bin/pslurp @@ -52,7 +52,7 @@ def parse_args(): if len(args) > 2: parser.error('Extra arguments given after the local path.') - if not opts.host_files and not opts.host_strings: + if not opts.host_files and not opts.host_strings and not opts.pcmk_nodes: parser.error('Hosts not specified.') return opts, args @@ -126,4 +126,6 @@ if __name__ == "__main__": if opts.host_strings: for s in opts.host_strings: hosts.extend(psshutil.parse_host_string(s, default_user=opts.user)) + if opts.pcmk_nodes: + hosts += psshutil.get_pcmk_nodes() do_pslurp(hosts, remote, local, opts) diff --git a/bin/pssh b/bin/pssh index 5b6c2a5e4661..cf02f40c2fbd 100755 --- a/bin/pssh +++ b/bin/pssh @@ -54,7 +54,7 @@ def parse_args(): if len(args) == 0 and not opts.send_input: parser.error('Command not specified.') - if not opts.host_files and not opts.host_strings: + if not opts.host_files and not opts.host_strings and not opts.pcmk_nodes: parser.error('Hosts not specified.') return opts, args @@ -112,6 +112,10 @@ if __name__ == "__main__": _, e, _ = sys.exc_info() sys.stderr.write('Could not open hosts file: %s\n' % e.strerror) sys.exit(1) + if opts.pcmk_nodes: + hosts = psshutil.get_pcmk_nodes() + if not hosts: + sys.exit(1) if opts.host_strings: for s in opts.host_strings: hosts.extend(psshutil.parse_host_string(s, default_user=opts.user)) diff --git a/psshlib/cli.py b/psshlib/cli.py index 611fadb6eb16..09e2571f3c6c 100644 --- a/psshlib/cli.py +++ b/psshlib/cli.py @@ -31,6 +31,8 @@ def common_parser(): parser.add_option('-H', '--host', dest='host_strings', action='append', metavar='HOST_STRING', help='additional host entries ("[user@]host[:port]")') + parser.add_option('-C', '--pcmk_nodes', dest='pcmk_nodes', action='store_true', + help='get nodes from pacemaker') parser.add_option('-l', '--user', dest='user', help='username (OPTIONAL)') parser.add_option('-p', '--par', dest='par', type='int', diff --git a/psshlib/psshutil.py b/psshlib/psshutil.py index 6c67f667637e..274b3b92546c 100644 --- a/psshlib/psshutil.py +++ b/psshlib/psshutil.py @@ -4,6 +4,7 @@ import fcntl import string import sys +import subprocess HOST_FORMAT = 'Host format is [user@]host[:port] [user]' @@ -98,6 +99,33 @@ def parse_host(host, default_user=None, default_port=None): host, port = host.rsplit(':', 1) return (host, port, user) +def get_pcmk_nodes(): + """Get the list of nodes from crm_node -l. + + Returns a list of (host, port, user) triples. + """ + hosts = [] + if subprocess.call("which crm_node >/dev/null 2>&1", shell=True) != 0: + sys.stderr.write('crm_node not available\n') + return hosts + cmd = "crm_node -l" + p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) + try: + outp = p.communicate()[0] + p.wait() + rc = p.returncode + except IOError, msg: + sys.stderr.write('%s failed: %s\n' % (cmd,msg)) + return hosts + if rc != 0: + sys.stderr.write('%s failed: exit code %d\n' % (cmd,rc)) + return hosts + for s in outp.split('\n'): + a = s.split() + if len(a) < 2: + continue + hosts.append((a[1], None, None)) + return hosts def set_cloexec(filelike): """Sets the underlying filedescriptor to automatically close on exec. @@ -106,3 +134,5 @@ def set_cloexec(filelike): not require the close_fds option. """ fcntl.fcntl(filelike.fileno(), fcntl.FD_CLOEXEC, 1) + +# vim:ts=4:sw=4:et: -- 1.8.4
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor