Skip to content

Commit

Permalink
Allow refresh of all system pillar data via API and spacecmd
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalmer committed Jan 10, 2025
1 parent dde0d80 commit a19513c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9072,7 +9072,7 @@ public int setPillar(User loggedInUser, String minionId, String category, Map<St
*
* @apidoc.doc refresh all the pillar data of a list of systems.
* @apidoc.param #session_key()
* @apidoc.param #array_single("int", "sids")
* @apidoc.param #array_single("int", "sids", "System IDs to be refreshed. If empty, all systems will be refreshed")
* @apidoc.returntype #array_single("int", "skippedIds", "System IDs which couldn't be refreshed")
*/
public List<Integer> refreshPillar(User loggedInUser, List<Integer> sids) {
Expand All @@ -9091,17 +9091,24 @@ public List<Integer> refreshPillar(User loggedInUser, List<Integer> sids) {
* and can be one of 'general', 'group_membership', 'virtualization' or 'custom_info'.
* @apidoc.param #session_key()
* @apidoc.param #param("string", "subset", "subset of the pillar to refresh.")
* @apidoc.param #array_single("int", "sids")
* @apidoc.param #array_single("int", "sids", "System IDs to be refreshed. If empty, all systems will be refreshed")
* @apidoc.returntype #array_single("int", "skippedIds", "System IDs which couldn't be refreshed")
*/
public List<Integer> refreshPillar(User loggedInUser, String subset, List<Integer> sids) {
List<Integer> skipped = new ArrayList<>();
MinionPillarManager.PillarSubset subsetValue = subset != null ?
MinionPillarManager.PillarSubset.valueOf(subset.toUpperCase()) :
null;
for (Integer sysId : sids) {
if (SystemManager.isAvailableToUser(loggedInUser, sysId.longValue())) {
Server system = SystemManager.lookupByIdAndUser(Long.valueOf(sysId), loggedInUser);
List<Long> sysids;
if (sids == null || sids.isEmpty()) {
sysids = MinionServerFactory.lookupVisibleToUser(loggedInUser).map(MinionServer::getId).toList();
}
else {
sysids = sids.stream().map(Integer::longValue).toList();
}
for (Long sysId : sysids) {
if (SystemManager.isAvailableToUser(loggedInUser, sysId)) {
Server system = SystemManager.lookupByIdAndUser(sysId, loggedInUser);
system.asMinionServer().ifPresentOrElse(
minionServer -> {
if (subsetValue != null) {
Expand All @@ -9113,13 +9120,13 @@ public List<Integer> refreshPillar(User loggedInUser, String subset, List<Intege
},
() -> {
log.warn("system {} is not a salt minion, hence pillar will not be updated", sysId);
skipped.add(sysId);
skipped.add(sysId.intValue());
}
);
}
else {
log.warn("system {} is not available to user, hence pillar will not be refreshed", sysId);
skipped.add(sysId);
skipped.add(sysId.intValue());
}
}
return skipped;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Modify system.refreshPillar API to allow refresh pillar data
of all systems

Check failure on line 2 in java/spacewalk-java.changes.mcalmer.api-for-pillar-refresh-all-systems

View workflow job for this annotation

GitHub Actions / Changelog tests

Wrong capitalization in file java/spacewalk-java.changes.mcalmer.api-for-pillar-refresh-all-systems#L1-2

Check failure on line 2 in java/spacewalk-java.changes.mcalmer.api-for-pillar-refresh-all-systems

View workflow job for this annotation

GitHub Actions / Changelog tests

Wrong spacing in file java/spacewalk-java.changes.mcalmer.api-for-pillar-refresh-all-systems#L1-2
6 changes: 5 additions & 1 deletion python/spacewalk/satellite_tools/mgr-sign-metadata-ctl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ function regenerate_metadata {
systemctl restart taskomatic
echo "done."
echo
echo "Scheduling repo metadata regeneration..."
read_spacecmd_user_pass
echo "Refreshing pillar data..."
spacecmd -q -u $SPACECMD_USER -p $SPACECMD_PASS "system_refreshpillar"
echo "Scheduling repo metadata regeneration..."
spacecmd -q -u $SPACECMD_USER -p $SPACECMD_PASS "softwarechannel_regenerateyumcache -f *"
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
Expand Down Expand Up @@ -317,5 +319,7 @@ if [[ $ACTION = "enable" || $ACTION = "disable" ]]; then
echo
echo "NOTE. For the changes to become effective run:"
echo " mgr-sign-metadata-ctl regen-metadata"
echo "and schedule a highstate for all your systems to"
echo "apply the new repository configuration."
echo
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Refresh pillar data together with regenration of channel metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add command to refresh systems pillar data
39 changes: 39 additions & 0 deletions spacecmd/src/spacecmd/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,45 @@ def do_system_rename(self, args):
####################


def help_system_refreshpillar(self):
print(_('system_refreshpillar: Refresh pillar data of system(s) '))
print(_('usage: system_refreshpillar [<SYSTEMS>]'))
print('')
print(self.HELP_SYSTEM_OPTS)

def complete_system_refreshpillar(self, text, line, beg, end):
return self.tab_complete_systems(text)

def do_system_refreshpillar(self, args):
arg_parser = get_argument_parser()

(args, _options) = parse_command_arguments(args, arg_parser)

sids = []
# use the systems listed in the SSM
if args:
if re.match('ssm', args[0], re.I):
systems = self.ssm.keys()
else:
systems = self.expand_systems(args)

for system in sorted(systems):
system_id = self.get_system_id(system)
if not system_id:
continue
sids.append(system_id)

self.client.system.refreshPillar(self.session, sids)

num = "%s" % len(sids)
if (num == "0"):
num = "all"
print('Refreshed Pillar data for "%s" systems' % (num))
return 0

####################


def help_system_listcustomvalues(self):
print(_('system_listcustomvalues: List the custom values for a system'))
print(_('usage: system_listcustomvalues <SYSTEMS>'))
Expand Down

0 comments on commit a19513c

Please sign in to comment.