mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add support for multiple organizations in spacewalk.
This commit is contained in:
parent
b37be236d9
commit
13198c199e
1 changed files with 42 additions and 3 deletions
|
@ -22,6 +22,9 @@ Tested with Ansible 1.1
|
||||||
# Author:: Jon Miller <jonEbird@gmail.com>
|
# Author:: Jon Miller <jonEbird@gmail.com>
|
||||||
# Copyright:: Copyright (c) 2013, Jon Miller
|
# Copyright:: Copyright (c) 2013, Jon Miller
|
||||||
#
|
#
|
||||||
|
# Extended for support of multiple organizations by
|
||||||
|
# Bernhard Lichtinger <bernhard.lichtinger@lrz.de> 2014
|
||||||
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation, either version 2 of the License, or (at
|
# the Free Software Foundation, either version 2 of the License, or (at
|
||||||
|
@ -97,9 +100,26 @@ parser.add_option('--host', default=None, dest="host",
|
||||||
parser.add_option('-H', '--human', dest="human",
|
parser.add_option('-H', '--human', dest="human",
|
||||||
default=False, action="store_true",
|
default=False, action="store_true",
|
||||||
help="Produce a friendlier version of either server list or host detail")
|
help="Produce a friendlier version of either server list or host detail")
|
||||||
|
parser.add_option('-o', '--org', default=None, dest="org_number",
|
||||||
|
help="Limit to spacewalk organization number")
|
||||||
|
parser.add_option('-p', default=False, dest="prefix_org_name", action="store_true",
|
||||||
|
help="Prefix the group name with the organization number")
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
# Generate dictionary for mapping group_id to org_id
|
||||||
|
#------------------------------
|
||||||
|
org_groups = {}
|
||||||
|
try:
|
||||||
|
for group in spacewalk_report('system-groups'):
|
||||||
|
org_groups[group['group_id']] = group['org_id']
|
||||||
|
|
||||||
|
except (OSError), e:
|
||||||
|
print >> sys.stderr, 'Problem executing the command "%s system-groups": %s' % \
|
||||||
|
(SW_REPORT, str(e))
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
# List out the known server from Spacewalk
|
# List out the known server from Spacewalk
|
||||||
#------------------------------
|
#------------------------------
|
||||||
if options.list:
|
if options.list:
|
||||||
|
@ -107,10 +127,29 @@ if options.list:
|
||||||
groups = {}
|
groups = {}
|
||||||
try:
|
try:
|
||||||
for system in spacewalk_report('system-groups-systems'):
|
for system in spacewalk_report('system-groups-systems'):
|
||||||
if system['group_name'] not in groups:
|
# first get org_id of system
|
||||||
groups[system['group_name']] = set()
|
org_id = org_groups[ system['group_id'] ]
|
||||||
|
|
||||||
groups[system['group_name']].add(system['server_name'])
|
# shall we add the org_id as prefix to the group name:
|
||||||
|
if options.prefix_org_name:
|
||||||
|
prefix = org_id + "-"
|
||||||
|
group_name = prefix + system['group_name']
|
||||||
|
else:
|
||||||
|
group_name = system['group_name']
|
||||||
|
|
||||||
|
# if we are limited to one organization:
|
||||||
|
if options.org_number:
|
||||||
|
if org_id == options.org_number:
|
||||||
|
if group_name not in groups:
|
||||||
|
groups[group_name] = set()
|
||||||
|
|
||||||
|
groups[group_name].add(system['server_name'])
|
||||||
|
# or we list all groups and systems:
|
||||||
|
else:
|
||||||
|
if group_name not in groups:
|
||||||
|
groups[group_name] = set()
|
||||||
|
|
||||||
|
groups[group_name].add(system['server_name'])
|
||||||
|
|
||||||
except (OSError), e:
|
except (OSError), e:
|
||||||
print >> sys.stderr, 'Problem executing the command "%s system-groups-systems": %s' % \
|
print >> sys.stderr, 'Problem executing the command "%s system-groups-systems": %s' % \
|
||||||
|
|
Loading…
Reference in a new issue