import sqlite3, datetime
db = sqlite3.connect("/opt/friend-cluster/data/friend-cluster-v1.db")
now = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f") + "Z"
print("now:", now)
q = """SELECT d.node_id, d.controller_endpoint, d.network_domain_id, d.status, cc.membership_expires_at
FROM controller_deployments d
JOIN cluster_controllers cc ON cc.node_id=d.node_id
WHERE d.cluster_id='default-cluster-776c43' AND d.status='ready' AND d.controller_endpoint<>'' AND d.network_domain_id<>''"""
for r in db.execute(q).fetchall():
    print("joined:", r)
q2 = q + " AND cc.membership_expires_at > ?"
rows = db.execute(q2, (now,)).fetchall()
print("with membership filter:", rows)
# network attachments for manager server
rows3 = db.execute("SELECT id, network_domain_id, server_id, desired_state FROM network_attachments").fetchall()
for r in rows3: print("attach:", r)
