diff --git a/lib/charms/grafana_agent/v0/cos_agent.py b/lib/charms/grafana_agent/v0/cos_agent.py index b18c271..d3617b3 100644 --- a/lib/charms/grafana_agent/v0/cos_agent.py +++ b/lib/charms/grafana_agent/v0/cos_agent.py @@ -254,7 +254,7 @@ class _MetricsEndpointDict(TypedDict): LIBID = "dc15fa84cef84ce58155fb84f6c6213a" LIBAPI = 0 -LIBPATCH = 20 +LIBPATCH = 21 PYDEPS = ["cosl >= 0.0.50", "pydantic"] @@ -472,7 +472,7 @@ def dump(self, databag: Optional[MutableMapping] = None, clear: bool = True): return databag -class CosAgentProviderUnitData(DatabagModel): +class CosAgentProviderUnitData(DatabagModel): # type: ignore """Unit databag model for `cos-agent` relation.""" # The following entries are the same for all units of the same principal. @@ -499,7 +499,7 @@ class CosAgentProviderUnitData(DatabagModel): KEY: ClassVar[str] = "config" -class CosAgentPeersUnitData(DatabagModel): +class CosAgentPeersUnitData(DatabagModel): # type: ignore """Unit databag model for `peers` cos-agent machine charm peer relation.""" # We need the principal unit name and relation metadata to be able to render identifiers @@ -598,7 +598,7 @@ class Receiver(pydantic.BaseModel): ) -class CosAgentRequirerUnitData(DatabagModel): # noqa: D101 +class CosAgentRequirerUnitData(DatabagModel): # type: ignore """Application databag model for the COS-agent requirer.""" receivers: List[Receiver] = pydantic.Field( diff --git a/lib/charms/operator_libs_linux/v2/snap.py b/lib/charms/operator_libs_linux/v2/snap.py index 4370eb1..a706c16 100644 --- a/lib/charms/operator_libs_linux/v2/snap.py +++ b/lib/charms/operator_libs_linux/v2/snap.py @@ -109,7 +109,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 13 +LIBPATCH = 14 PYDEPS = ["opentelemetry-api"] @@ -149,6 +149,7 @@ class _SnapDict(TypedDict, total=True): name: str channel: str revision: str + version: str confinement: str apps: NotRequired[list[dict[str, JSONType]] | None] @@ -309,6 +310,7 @@ class Snap: - channel: "stable", "candidate", "beta", and "edge" are common - revision: a string representing the snap's revision - confinement: "classic", "strict", or "devmode" + - version: a string representing the snap's version, if set by the snap author """ def __init__( @@ -320,6 +322,8 @@ def __init__( confinement: str, apps: list[dict[str, JSONType]] | None = None, cohort: str | None = None, + *, + version: str | None = None, ) -> None: self._name = name self._state = state @@ -328,6 +332,7 @@ def __init__( self._confinement = confinement self._cohort = cohort or "" self._apps = apps or [] + self._version = version self._snap_client = SnapClient() def __eq__(self, other: object) -> bool: @@ -783,6 +788,11 @@ def held(self) -> bool: info = self._snap("info") return "hold:" in info + @property + def version(self) -> str | None: + """Returns the version for a snap.""" + return self._version + class _UnixSocketConnection(http.client.HTTPConnection): """Implementation of HTTPConnection that connects to a named Unix socket.""" @@ -1048,6 +1058,7 @@ def _load_installed_snaps(self) -> None: revision=i["revision"], confinement=i["confinement"], apps=i.get("apps"), + version=i.get("version"), ) self._snap_map[snap.name] = snap @@ -1067,6 +1078,7 @@ def _load_info(self, name: str) -> Snap: revision=info["revision"], confinement=info["confinement"], apps=None, + version=info.get("version"), )