def METHOD_NAME():
    # Make a tag of the preivous image
    subprocess.run(
        [
            "docker",
            "tag",
            container_image + ":latest",
            container_image + ":previous",
        ],
        check=True,
    )
    # pull new image - if registry is down, better stop here
    subprocess.run(
        [
            "docker",
            "pull",
            container_image + ":latest",
        ],
        check=True,
    )
    # disable all agents
    delete_agents(only_disable=True)
    # putting the server into maintenance mode
    x = botmaster_post("/admin/maintenance_mode/enable", version=1)
    if x.status_code not in [204, 409]:
        print("Failed to enable maintenance mode", x, x.content)
        sys.exit(1)
    # wait for all jobs to finish - cancel the monitors manually
    while True:
        info = botmaster_get("/admin/maintenance_mode/info", version=1)
        if info.status_code not in [200]:
            print("Failed to retrieve maintenance mode info", info, info.content)
            sys.exit(1)
        info = info.json()
        if not info["is_maintenance_mode"]:
            print("Failed to enable maintenance mode", x, x.content)
            sys.exit(1)
        running_systems = info["attributes"]["running_systems"]["building_jobs"]
        if len(running_systems) == 0:
            break
        pipelines = []
        for job in running_systems:
            if job["pipeline_name"] in [
                "SUSE.Repo.Monitor",
                "SUSE.openQA",
                "openSUSE.Repo.Monitor",
                "openSUSE.openQA",
            ]:
                url = f"/stages/{job['pipeline_name']}/{job['pipeline_counter']}/{job['stage_name']}/{job['stage_counter']}/cancel"
                x = botmaster_post(url, version=3)
                if x.status_code not in [200]:
                    print(f"Can't cancel {job['pipline_name']}")
                    print(x, x.content)
                    sys.exit(1)
            else:
                pipelines.append(job["pipeline_name"])
        print("Waiting 2 min for the jobs to finish", sorted(pipelines))
        time.sleep(120)
    # stop all agents
    subprocess.run(["systemctl", "stop", "go-agent-*"], check=True)
    # cleanup
    proc = subprocess.Popen(["docker", "system", "prune"], stdin=subprocess.PIPE)
    proc.communicate(input=b"y\n")
    # stop the server
    subprocess.run(["systemctl", "stop", "go-server.service"])
    cleanup_old_pipelines()
    # start the server again
    subprocess.run(["systemctl", "start", "go-server.service"])
    while True:
        try:
            info = botmaster_get("/admin/maintenance_mode/info", version=1)
            print(info, info.content)
            if info.status_code in [503]:
                # is starting
                time.sleep(5)
                continue
            break
        except requests.exceptions.ConnectionError:
            time.sleep(5)
            continue
    delete_agents()
    cleanup_cache()
    # start the agents on new image
    subprocess.run(["systemctl", "start", "--all", "go-agent-*"], check=True)