Getting the revision of a snap from snapd

In the context of snapcraft pushing its own snap into the LXD container, along with the core snap, I was looking at how to get the relevant information. While I know the SNAP_REVISION for snapcraft itself, I don’t know what core snap revision is currently being used.

There seem to be several ways to get a revision right now:

  • readlink /var/snap/core/current 1689
  • snap list core Name Version Rev Developer Notes core 16-2 1689 canonical - Not very suitable for parsing. Is this format stable?
  • snap info core name: core summary: “snapd runtime environment” publisher: canonical description: | The core runtime environment for snapd type: core tracking: stable installed: 16-2 (1689) 83MB - refreshed: 2017-04-11 14:28:54 +0200 CEST channels: The installed value is what I’d be interested in, except it doesn’t seem to lend itself well to parsing.

I think using the snapd API is a good option:

$ curl -s --unix-socket /run/snapd.socket http:/v2/snaps/core
{"type":"sync","status-code":200,"status":"OK","result":{"apps":[],"broken":"","channel":"stable","confinement":"strict","contact":"mailto:snappy-canonical-storeaccount@canonical.com","description":"The core runtime environment for snapd","developer":"canonical","devmode":false,"icon":"","id":"99T7MUlRhtI3U0QFgl5mXXESAiSwt776","install-date":"2017-04-11T05:28:54-07:00","installed-size":83349504,"jailmode":false,"name":"core","private":false,"resource":"/v2/snaps/core","revision":"1689","status":"active","summary":"snapd runtime environment","tracking-channel":"stable","trymode":false,"type":"os","version":"16-2"}}

Question, can we always install any revision?

Like, install core rev 1000 even when the latest released core is rev 5000?

I think the goal is to install the version of core on the host, right? Which is a simple matter of grabbing the snap out of /var/lib/snapd/snaps/, as well as its assertion from snap known.

2 Likes

That’s indeed what I’m doing in my PR and also the only way to do it (because the store only allows for the publisher to download specific revisions).

btw you probably also need to set a refresh schedule so that you don’t get a refresh in the middle of things inside inside the lxd

What would I set it to, though? Can I set it to eg. “never” and take care of it manually? The example given in the announcement of that feature uses specific times when it “might” run.

no, “never” is not supported

How should this be used then? The snaps snapcraft cares about will be the versions it specifically injected, so it would be counter-productive for them to be updated.

Perhaps that’s a case for not getting their assertions. Then they can’t be updated.