def addGroupsToKey(server, activation_key, groups):
 try:
  (client, key) = _get_session(server)
 except Exception as exc:
  err_msg = 'Exception raised when connecting to spacewalk server ({0}): {1}'.format(server, exc)
  log.error(err_msg)
  return {'Error': err_msg}
 all_groups = client.systemgroup.listAllGroups(key)
 groupIds = []
 for group in all_groups:
  if (group['name'] in groups):
   groupIds.append(group['id'])
 if (client.activationkey.addServerGroups(key, activation_key, groupIds) == 1):
  return {activation_key: groups}
 else:
  return {activation_key: 'Failed to add groups to activation key'}

def addGroupsToKey ( server , activation_key , groups ) : try : ( client , key ) = _get_session ( server ) except Exception as exc : err_msg = 'Exception raised when connecting to spacewalk server ({0}): {1}' . format ( server , exc ) log . error ( err_msg ) return { 'Error' : err_msg } all_groups = client . systemgroup . listAllGroups ( key ) groupIds = [ ] for group in all_groups : if ( group [ 'name' ] in groups ) : groupIds . append ( group [ 'id' ] ) if ( client . activationkey . addServerGroups ( key , activation_key , groupIds ) == 1 ) : return { activation_key : groups } else : return { activation_key : 'Failed to add groups to activation key' }
add server groups to a activation key cli example: .