api: added maintenance command into API.
This commit is contained in:
parent
74042e1c35
commit
1ea2e3e49f
2 changed files with 81 additions and 10 deletions
|
|
@ -29,6 +29,7 @@ from rhodecode.api.utils import (
|
|||
get_user_group_or_error, get_user_or_error, validate_repo_permissions,
|
||||
get_perm_or_error, parse_args, get_origin, build_commit_data,
|
||||
validate_set_owner_permissions)
|
||||
from rhodecode.lib import repo_maintenance
|
||||
from rhodecode.lib.auth import HasPermissionAnyApi, HasUserGroupPermissionAnyApi
|
||||
from rhodecode.lib.utils2 import str2bool, time_to_datetime
|
||||
from rhodecode.lib.ext_json import json
|
||||
|
|
@ -1986,3 +1987,65 @@ def set_repo_settings(request, apiuser, repoid, settings):
|
|||
|
||||
# Indicate success.
|
||||
return True
|
||||
|
||||
|
||||
@jsonrpc_method()
|
||||
def maintenance(request, apiuser, repoid):
|
||||
"""
|
||||
Triggers a maintenance on the given repository.
|
||||
|
||||
This command can only be run using an |authtoken| with admin
|
||||
rights to the specified repository. For more information,
|
||||
see :ref:`config-token-ref`.
|
||||
|
||||
This command takes the following options:
|
||||
|
||||
:param apiuser: This is filled automatically from the |authtoken|.
|
||||
:type apiuser: AuthUser
|
||||
:param repoid: The repository name or repository ID.
|
||||
:type repoid: str or int
|
||||
|
||||
Example output:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
id : <id_given_in_input>
|
||||
result : {
|
||||
"msg": "executed maintenance command",
|
||||
"executed_actions": [
|
||||
<action_message>, <action_message2>...
|
||||
],
|
||||
"repository": "<repository name>"
|
||||
}
|
||||
error : null
|
||||
|
||||
Example error output:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
id : <id_given_in_input>
|
||||
result : null
|
||||
error : {
|
||||
"Unable to execute maintenance on `<reponame>`"
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
repo = get_repo_or_error(repoid)
|
||||
if not has_superadmin_permission(apiuser):
|
||||
_perms = ('repository.admin',)
|
||||
validate_repo_permissions(apiuser, repoid, repo, _perms)
|
||||
|
||||
try:
|
||||
maintenance = repo_maintenance.RepoMaintenance()
|
||||
executed_actions = maintenance.execute(repo)
|
||||
|
||||
return {
|
||||
'msg': 'executed maintenance command',
|
||||
'executed_actions': executed_actions,
|
||||
'repository': repo.repo_name
|
||||
}
|
||||
except Exception:
|
||||
log.exception("Exception occurred while trying to run maintenance")
|
||||
raise JSONRPCError(
|
||||
'Unable to execute maintenance on `%s`' % repo.repo_name)
|
||||
|
|
|
|||
|
|
@ -4,19 +4,27 @@
|
|||
</div>
|
||||
<div class="panel-body">
|
||||
|
||||
% if c.executable_tasks:
|
||||
<h4>${_('Perform maintenance tasks for this repo')}</h4>
|
||||
|
||||
<span>${_('Following tasks will be performed')}:</span>
|
||||
<ol>
|
||||
% for task in c.executable_tasks:
|
||||
<li>${task}</li>
|
||||
% endfor
|
||||
</ol>
|
||||
<p>
|
||||
% if c.executable_tasks:
|
||||
${_('Perform maintenance tasks for this repo, following tasks will be performed')}:
|
||||
<ol>
|
||||
% for task in c.executable_tasks:
|
||||
<li>${task}</li>
|
||||
% endfor
|
||||
</ol>
|
||||
% else:
|
||||
${_('No maintenance tasks for this repo available')}
|
||||
% endif
|
||||
${_('Maintenance can be automated by such api call. Can be called periodically in crontab etc.')}
|
||||
<br/>
|
||||
<code>
|
||||
${h.api_call_example(method='maintenance', args={"repoid": c.repo_info.repo_name})}
|
||||
</code>
|
||||
</p>
|
||||
|
||||
% else:
|
||||
<h4>${_('No maintenance tasks for this repo available')}</h4>
|
||||
% endif
|
||||
|
||||
<div id="results" style="display:none; padding: 10px 0px;"></div>
|
||||
|
||||
% if c.executable_tasks:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue