RFC: 'snap connections' command

pstolowski
upcoming

#1

Hi,

I’d like to open the proposed addtion of snap connections command for discussion. Before diving into the details of the API, I suggest we focus on the user story. The aim of connections command is to list connected plugs/slots of all snaps (or given snap) in more readable output than snap interfaces.

Proposed ouput (note plug comes first, this is reverse order compared to interfaces command):

  1. All existing connections, no filtering
$ snap connections

Plug                                 Slot
spotify:home                         core:home 
spotify:mount-observe                core:mount-observe
spotify:unity7                       core:unity7
vlc:unity7                           core:unity7
vlc:removable-media                  core:removable-media
.....
  1. Connections of specific snap(s) matched on both plug and slot side:
$ snap connections spotify

Plug                                 Slot
spotify:home                         core:home 
spotify:mount-observe                core:mount-observe
spotify:unity7                       core:unity7

Alternatively, we could break down the output into four columns (no colons between snap-plug/slot names). Is there anything more we want in terms of filtering?

CC @niemeyer and @zyga


#2

Why not fix snap interfaces to be more readable? What use case is there for having both interfaces and connections - when would I use one over the other?


#3

I like the ordering by plug name, then by slot name. This matches how we work on connect/disconnect (order of plug and slot) and how people think of connections (mostly about what a given snap contains, so by-snap order makes sense).

Questions:

  • Should we abbreviate core:home to just :home?
  • Should we print the plug/slot headers?
  • How should it look like before we have any connections?
  • What should happen if we ask about a specific connection snap connection spotify:home

Note that I used the singular word connection in my last question above.


#4

The old snap interfaces command is going to get deprecated and go away over time. We don’t want to break how it works for now.


#5

Per zyga’s suggestion, we can turn core:foo into :foo as that’s both cleaner and supported in the connect and disconnect commands.

We should have some better details there, otherwise it feels like we’re not really improving much over what we have today. How about starting with an “Interface” column, and adding a “Notes” at the end:

Plug           Slot     Interface  Notes
spotify:home   :home    home       -
spotify:video  :camera  camera     manual

Also, how about filtering the list so that:

  1. Without any parameters, only show connected interfaces
  2. With --all, show both connected and disconnected interfaces
  3. With a snap name, show both connected and disconnected interfaces

Update: I’ve inverted the order of the columns so Plug and Slot come first. That seems better because those are the two most relevant things, which are actually typed in command lines for connections and disconnections.


#6

Let’s say I only had the core snap installed, and I wanted to see all slots available on it. Would that look like this?

$ snap connections core

Plug                    Slot
-                       core:home 
-                       core:mount-observe
-                       core:unity7
# ...

#7

Per my suggestion above at least, no… it would have extra columns and the “core” string wouldn’t be present in all of those lines.


#8

Did some experiments, and this is what I have.

Connections of a single snap:

$ snap connections gnome-sudoku        
Plug                          Slot                             Interface       Notes
gnome-sudoku:desktop          :desktop                         desktop         -
gnome-sudoku:desktop-legacy   :desktop-legacy                  desktop-legacy  -
gnome-sudoku:gnome-3-26-1604  gnome-3-26-1604:gnome-3-26-1604  content         -
gnome-sudoku:gsettings        :gsettings                       gsettings       -
gnome-sudoku:gtk-3-themes     gtk-common-themes:gtk-3-themes   content         -
gnome-sudoku:icon-themes      gtk-common-themes:icon-themes    content         -
gnome-sudoku:pulseaudio       :pulseaudio                      pulseaudio      -
gnome-sudoku:sound-themes     gtk-common-themes:sound-themes   content         -
gnome-sudoku:unity7           :unity7                          unity7          -
gnome-sudoku:wayland          :wayland                         wayland         -

Snap that is content provider:

$ snap connections gtk-common-themes
Plug                           Slot                            Interface  Notes
gnome-calculator:gtk-3-themes  gtk-common-themes:gtk-3-themes  content    -
gnome-calculator:icon-themes   gtk-common-themes:icon-themes   content    -
gnome-calculator:sound-themes  gtk-common-themes:sound-themes  content    -
gnome-sudoku:gtk-3-themes      gtk-common-themes:gtk-3-themes  content    -
gnome-sudoku:icon-themes       gtk-common-themes:icon-themes   content    -
gnome-sudoku:sound-themes      gtk-common-themes:sound-themes  content    -

Snap that does not use content:

$ snap connections vlc              
Plug                        Slot                     Interface               Notes
vlc:desktop                 :desktop                 desktop                 -
vlc:desktop-legacy          :desktop-legacy          desktop-legacy          -
vlc:home                    :home                    home                    -
vlc:network                 :network                 network                 -
vlc:network-bind            :network-bind            network-bind            -
vlc:opengl                  :opengl                  opengl                  -
vlc:optical-drive           :optical-drive           optical-drive           -
vlc:pulseaudio              :pulseaudio              pulseaudio              -
vlc:removable-media         :removable-media         removable-media         -
vlc:screen-inhibit-control  :screen-inhibit-control  screen-inhibit-control  -
vlc:unity7                  :unity7                  unity7                  -
vlc:x11                     :x11                     x11                     -

But has some disconnected interfaces:

$ snap connections vlc -a
Plug                        Slot                     Interface               Notes
vlc:camera                  -                        camera                  -
vlc:desktop                 :desktop                 desktop                 -
vlc:desktop-legacy          :desktop-legacy          desktop-legacy          -
vlc:home                    :home                    home                    -
vlc:mount-observe           -                        mount-observe           -
vlc:network                 :network                 network                 -
vlc:network-bind            :network-bind            network-bind            -
vlc:opengl                  :opengl                  opengl                  -
vlc:optical-drive           :optical-drive           optical-drive           -
vlc:pulseaudio              :pulseaudio              pulseaudio              -
vlc:removable-media         :removable-media         removable-media         -
vlc:screen-inhibit-control  :screen-inhibit-control  screen-inhibit-control  -
vlc:unity7                  :unity7                  unity7                  -
vlc:x11                     :x11                     x11                     -
-                           vlc:mpris                mpris                   -

Snap that has just one plug but it’s not connected by default:

$ snap connections test-services-25269
no connections found
$ snap connections test-services-25269 -a
Plug                               Slot  Interface      Notes
test-services-25269:daemon-notify  -     daemon-notify  -

I would like to get to the following for manually connected plugs:

$ snap connections test-services-25269        
Plug                               Slot            Interface      Notes
test-services-25269:daemon-notify  :daemon-notify  daemon-notify  manual

Extending this further for hotplug:

$ snap connections test-services-25269        
Plug           Slot            Interface    Notes
service1:uart  :qemuserialusb  serial-port  manual,hotplug
service2:uart  :qemuserialusb  serial-port  hotplug

This involves some changes to the daemon API. The information on whether a connection is manua/hotplug related is not directly available through the API at this point.

A quick observation, maybe it’s just implementation/formatting detail, but this output feels a bit overwhelming and takes a 1.5 full pages on my terminal:

$ snap connections -a
Plug                              Slot                  Interface                 Notes
gnome-calculator:desktop          :desktop              desktop                   -
gnome-calculator:desktop-legacy   :desktop-legacy       desktop-legacy            -
...
-                                 :screencast-legacy    screencast-legacy         -
-                                 :shutdown             shutdown                  -
-                                 :ssh-keys             ssh-keys                  -
-                                 :ssh-public-keys      ssh-public-keys           -
-                                 :system-trace         system-trace              -
-                                 :time-control         time-control              -
-                                 :timeserver-control   timeserver-control        -
-                                 :timezone-control     timezone-control          -
-                                 :tpm                  tpm                       -
...

Perhaps we could make the snap name required and instead suggest to the user to use snap connections system instead.


#9

wan’t the plan to also add a new api endpoint for this as well? maybe @zyga remembers whether that was the case


#10

AFAIK we 100% wanted a new endpoint for this.


#11

FYI I’ve opened https://github.com/snapcore/snapd/pull/6079 a while ago where we can discuss output formatting and so on. The code does this on the old endpoints, so it’s obviously missing the data on why an interface is connected or disconnected.

Since the output is there, maybe it would make sense to land it at some point just to introduce the command and then work on the backend bits to fill the notes column with useful info.