Skip to content

Commit

Permalink
feat: python-libjuju without AllWatcher
Browse files Browse the repository at this point in the history
refactor all things!

demo! use both async (old) and wrapped async (new) to get same data

cleanup🧼

shorter helper thread code

wip

note about exposed

Simon says

implement Application.exposed

typed decorator for the win

wip

plain decorator works better

cleanup🧼

name is entity id

wip

fix: missing file

type up .wait_for_idle()

better code style

write down next steps

chore: refactor jrpc response type coercion for testing

chore: refactor jrpc response type coercion for testing, missing files

chore: document different ways .wait_for_idle(...) may be called

chore: refactor for testability

chore: wip / squash me

chore: clarify wait for idle params

chore: clarify wait for idle params

wip

chore: more hookup

chore: mock out everything needed for old idle loop

chore: refactor test setup

chore: more tests

chore: start on app and unit counting mechanics

chore: more app and unit counting mechanics

reimplement unset status back fill

chore: refactor legacy loop, fix error condition; note that status compounding is ineffective

chore: refactor new loop checker, note to do

chore: kidna finish the idle loop, hopefully?

chore: fill in wait_for_at_least_units=N

chore: wait_for_exact_units

chore: exact and at least units are exclusive

cleanup🧼
  • Loading branch information
dimaqq committed Oct 15, 2024
1 parent 79aac2c commit 3f98b53
Show file tree
Hide file tree
Showing 19 changed files with 1,735 additions and 191 deletions.
61 changes: 61 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import logging
import pprint

from juju import jasyncio
from juju.model import Model


async def main() -> None:
m = Model()
await m.connect(model_name="testm")
# from juju.client._client import CharmsFacade
# f = CharmsFacade.from_connection(m.connection())
# rv = await f.CharmInfo("local:noble/fake-ingress-0")
# print(rv)
# print()

#rv = await f.ApplicationsInfo(entities=[{"tag": "application-database"}])
#print(rv)
#print()

for app_name, app in m.applications.items():
pprint.pprint(app.model.state.state["application"][app_name][-1])
print(f"""{app_name}:
name............... {app.name!r}
charm_name......... {app.charm_name!r}
exposed............ {app.exposed!r}
charm_url.......... {app.charm_url!r}
owner_tag.......... {app.owner_tag!r}
life............... {app.life!r}
min_units.......... {app.min_units!r}
constraints["arch"] {app.constraints["arch"]!r}
subordinate........ {app.subordinate!r}
status............. {app.status!r}
workload_version... {app.workload_version!r}
""")
for u in app.units:
print(f"{u.name}: {u.agent_status!r} {u.workload_status!r}")

await m.wait_for_idle()

await m.disconnect()


class SymbolFilter(logging.Filter):
DEBUG = '🐛'
INFO = 'ℹ️'
WARNING = '⚠️'
ERROR = '❌'
CRITICAL = '🔥'

def filter(self, record):
record.symbol = getattr(self, record.levelname, '#')
# FIXME can control log record origin here if needed
return True


if __name__ == "__main__":
# FIXME why is level=DEBUG broken?
#logging.basicConfig(level="INFO", format="%(symbol)s %(message)s")
#logging.root.addFilter(SymbolFilter())
jasyncio.run(main())
322 changes: 322 additions & 0 deletions fullstatus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
{
"request-id": 7,
"response": {
"applications": {
"grafana-agent-k8s": {
"base": {
"channel": "22.04/stable",
"name": "ubuntu"
},
"can-upgrade-to": "",
"charm": "ch:arm64/jammy/grafana-agent-k8s-75",
"charm-channel": "latest/stable",
"charm-profile": "",
"charm-version": "",
"endpoint-bindings": {
"": "alpha",
"certificates": "alpha",
"grafana-cloud-config": "alpha",
"grafana-dashboards-consumer": "alpha",
"grafana-dashboards-provider": "alpha",
"logging-consumer": "alpha",
"logging-provider": "alpha",
"metrics-endpoint": "alpha",
"peers": "alpha",
"receive-ca-cert": "alpha",
"send-remote-write": "alpha",
"tracing": "alpha"
},
"exposed": false,
"int": 1,
"life": "",
"meter-statuses": null,
"provider-id": "4ecc75be-f038-4452-b1af-640d1b46f1c6",
"public-address": "10.152.183.55",
"relations": {
"peers": [
"grafana-agent-k8s"
]
},
"status": {
"data": {},
"info": "installing agent",
"kind": "",
"life": "",
"since": "2024-09-30T07:44:15.63582531Z",
"status": "waiting",
"version": ""
},
"subordinate-to": [],
"units": {
"grafana-agent-k8s/0": {
"address": "10.1.121.164",
"agent-status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-09-30T07:44:15.469295423Z",
"status": "idle",
"version": "3.5.1"
},
"charm": "",
"leader": true,
"machine": "",
"opened-ports": [],
"provider-id": "grafana-agent-k8s-0",
"public-address": "",
"subordinates": null,
"workload-status": {
"data": {},
"info": "Missing incoming (\"requires\") relation: metrics-endpoint|logging-provider|grafana-dashboards-consumer",
"kind": "",
"life": "",
"since": "2024-09-30T07:43:41.649319444Z",
"status": "blocked",
"version": ""
},
"workload-version": "0.35.2"
}
},
"workload-version": "0.35.2"
},
"hexanator": {
"base": {
"channel": "24.04/stable",
"name": "ubuntu"
},
"can-upgrade-to": "",
"charm": "local:noble/hexanator-1",
"charm-profile": "",
"charm-version": "",
"endpoint-bindings": {
"": "alpha",
"ingress": "alpha",
"rate-limit": "alpha"
},
"exposed": false,
"int": 1,
"life": "",
"meter-statuses": null,
"provider-id": "b5efccf2-5a15-41a0-af0f-689a8d93a129",
"public-address": "10.152.183.113",
"relations": {},
"status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-09-30T00:12:47.878239549Z",
"status": "active",
"version": ""
},
"subordinate-to": [],
"units": {
"hexanator/0": {
"address": "10.1.121.184",
"agent-status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-09-30T00:13:16.731257044Z",
"status": "idle",
"version": "3.5.1"
},
"charm": "",
"leader": true,
"machine": "",
"opened-ports": [],
"provider-id": "hexanator-0",
"public-address": "",
"subordinates": null,
"workload-status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-09-30T00:12:47.878239549Z",
"status": "active",
"version": ""
},
"workload-version": ""
}
},
"workload-version": ""
},
"mysql-test-app": {
"base": {
"channel": "22.04/stable",
"name": "ubuntu"
},
"can-upgrade-to": "",
"charm": "ch:arm64/jammy/mysql-test-app-62",
"charm-channel": "latest/edge",
"charm-profile": "",
"charm-version": "",
"endpoint-bindings": {
"": "alpha",
"application-peers": "alpha",
"database": "alpha",
"mysql": "alpha"
},
"exposed": false,
"int": 2,
"life": "",
"meter-statuses": null,
"provider-id": "4338786a-a337-4779-820d-679a59ba1665",
"public-address": "10.152.183.118",
"relations": {
"application-peers": [
"mysql-test-app"
]
},
"status": {
"data": {},
"info": "installing agent",
"kind": "",
"life": "",
"since": "2024-09-30T07:48:25.106109123Z",
"status": "waiting",
"version": ""
},
"subordinate-to": [],
"units": {
"mysql-test-app/0": {
"address": "10.1.121.142",
"agent-status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-10-01T00:15:03.216904329Z",
"status": "idle",
"version": "3.5.1"
},
"charm": "",
"leader": true,
"machine": "",
"opened-ports": [],
"provider-id": "mysql-test-app-0",
"public-address": "",
"subordinates": null,
"workload-status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-09-30T07:47:54.212959856Z",
"status": "waiting",
"version": ""
},
"workload-version": "0.0.2"
},
"mysql-test-app/1": {
"address": "10.1.121.190",
"agent-status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-09-30T23:49:39.923901864Z",
"status": "idle",
"version": "3.5.1"
},
"charm": "",
"machine": "",
"opened-ports": [],
"provider-id": "mysql-test-app-1",
"public-address": "",
"subordinates": null,
"workload-status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-09-30T07:47:54.211414881Z",
"status": "waiting",
"version": ""
},
"workload-version": "0.0.2"
}
},
"workload-version": "0.0.2"
}
},
"branches": {},
"controller-timestamp": "2024-10-01T07:25:22.51380313Z",
"machines": {},
"model": {
"available-version": "",
"cloud-tag": "cloud-microk8s",
"meter-status": {
"color": "",
"message": ""
},
"model-status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-09-27T08:21:45.368693216Z",
"status": "available",
"version": ""
},
"name": "testm",
"region": "localhost",
"sla": "unsupported",
"type": "caas",
"version": "3.5.1"
},
"offers": {},
"relations": [
{
"endpoints": [
{
"application": "grafana-agent-k8s",
"name": "peers",
"role": "peer",
"subordinate": false
}
],
"id": 0,
"interface": "grafana_agent_replica",
"key": "grafana-agent-k8s:peers",
"scope": "global",
"status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-09-30T07:43:31.018463595Z",
"status": "joined",
"version": ""
}
},
{
"endpoints": [
{
"application": "mysql-test-app",
"name": "application-peers",
"role": "peer",
"subordinate": false
}
],
"id": 1,
"interface": "application-peers",
"key": "mysql-test-app:application-peers",
"scope": "global",
"status": {
"data": {},
"info": "",
"kind": "",
"life": "",
"since": "2024-09-30T07:47:52.823202648Z",
"status": "joined",
"version": ""
}
}
],
"remote-applications": {}
}
}
Loading

0 comments on commit 3f98b53

Please sign in to comment.