feat(host_agent): a group's updates and reboots on a weekly cadence, one host at a time (#5768)
#5768 "A maintenance cadence: a group's updates and reboots, one host at a time, on a schedule". A plan names an inventory group, a weekday and time in a time zone, a window and a reboot policy (only when required by default). At its slot a run takes the group's hosts in order and gives each a #5767 maintenance job. The next host starts only when the last is back in service: its agent is posting and, for a swarm node, the node is active and every replicated service is at its replicas. A failure stops the run, and no host is started once the window has passed. A host's latest failure shows as host_agent/<host>/maintenance_failed, for an ordinary alert rule. The page is Hosts → Maintenance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""host_agent: a group's maintenance cadence and its runs (#5768)
|
||||
|
||||
Revision ID: host_agent_008_maint_plans
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
revision: str = "host_agent_008_maint_plans"
|
||||
down_revision: Union[str, None] = "host_agent_007_maint_jobs"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
# ansible_groups (core 0016) must exist before the group_id key.
|
||||
depends_on: Union[str, Sequence[str], None] = ("0016_ansible_inventory_groups",)
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"host_maintenance_plans",
|
||||
sa.Column("id", sa.String(36), primary_key=True),
|
||||
sa.Column("name", sa.String(128), nullable=False),
|
||||
sa.Column("group_id", sa.String(36), sa.ForeignKey("ansible_groups.id", ondelete="CASCADE"),
|
||||
nullable=False),
|
||||
sa.Column("weekday", sa.Integer(), nullable=False),
|
||||
sa.Column("at_time", sa.String(5), nullable=False),
|
||||
sa.Column("time_zone", sa.String(64), nullable=False, server_default="UTC"),
|
||||
sa.Column("window_minutes", sa.Integer(), nullable=False, server_default="240"),
|
||||
sa.Column("reboot_policy", sa.String(16), nullable=False, server_default="if_required"),
|
||||
sa.Column("enabled", sa.Boolean(), nullable=False, server_default=sa.true()),
|
||||
sa.Column("last_slot_at", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("created_by", sa.String(36), sa.ForeignKey("users.id", ondelete="SET NULL"),
|
||||
nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
)
|
||||
op.create_table(
|
||||
"host_maintenance_runs",
|
||||
sa.Column("id", sa.String(36), primary_key=True),
|
||||
sa.Column("plan_id", sa.String(36),
|
||||
sa.ForeignKey("host_maintenance_plans.id", ondelete="CASCADE"), nullable=False),
|
||||
sa.Column("state", sa.String(16), nullable=False),
|
||||
sa.Column("host_ids", sa.Text(), nullable=False, server_default="[]"),
|
||||
sa.Column("position", sa.Integer(), nullable=False, server_default="0"),
|
||||
sa.Column("skipped", sa.Text(), nullable=False, server_default="[]"),
|
||||
sa.Column("settle_since", sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column("detail", sa.Text(), nullable=True),
|
||||
sa.Column("manual", sa.Boolean(), nullable=False, server_default=sa.false()),
|
||||
sa.Column("started_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("finished_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
op.create_index("ix_host_maintenance_runs_plan_id", "host_maintenance_runs", ["plan_id"])
|
||||
op.create_index("ix_host_maintenance_runs_state", "host_maintenance_runs", ["state"])
|
||||
op.add_column("host_maintenance_jobs", sa.Column(
|
||||
"run_id", sa.String(36), sa.ForeignKey("host_maintenance_runs.id", ondelete="SET NULL"),
|
||||
nullable=True))
|
||||
op.create_index("ix_host_maintenance_jobs_run_id", "host_maintenance_jobs", ["run_id"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("ix_host_maintenance_jobs_run_id", "host_maintenance_jobs")
|
||||
op.drop_column("host_maintenance_jobs", "run_id")
|
||||
op.drop_table("host_maintenance_runs")
|
||||
op.drop_table("host_maintenance_plans")
|
||||
Reference in New Issue
Block a user