Beispiel #1
0
def rename_host(params):
    """Rename a host"""
    if activate_changes.get_pending_changes_info():
        return problem(
            status=409,
            title="Pending changes are present",
            detail=
            "Please activate all pending changes before executing a host rename process",
        )
    host_name = params['host_name']
    host: watolib.CREHost = watolib.Host.host(host_name)
    if host is None:
        return _missing_host_problem(host_name)

    new_name = params['body']["new_name"]
    _, auth_problems = perform_rename_hosts([(host.folder(), host_name,
                                              new_name)])
    if auth_problems:
        return problem(
            status=422,
            title="Rename process failed",
            detail=
            f"It was not possible to rename the host {host_name} to {new_name}",
        )
    return _serve_host(host, False)
Beispiel #2
0
def rename_host(params):
    """Rename a host"""
    user.need_permission("wato.rename_hosts")
    if activate_changes.get_pending_changes_info():
        return problem(
            status=409,
            title="Pending changes are present",
            detail="Please activate all pending changes before executing a host rename process",
        )
    host_name = params["host_name"]
    host: watolib.CREHost = watolib.Host.load_host(host_name)
    new_name = params["body"]["new_name"]
    _, auth_problems = perform_rename_hosts([(host.folder(), host_name, new_name)])
    if auth_problems:
        return problem(
            status=422,
            title="Rename process failed",
            detail=f"It was not possible to rename the host {host_name} to {new_name}",
        )
    return _serve_host(host, effective_attributes=False)
Beispiel #3
0
def rename_hosts(renamings, job_interface=None):
    action_counts, auth_problems = perform_rename_hosts(renamings, job_interface)
    action_texts = render_renaming_actions(action_counts)
    return action_texts, auth_problems