Example - Managing Snaps on Ubuntu-Core Devices
EdgeIQ provides robust capabilities for managing devices and their applications using Snap packages. This guide will help you use HTTP Sender type commands to manage Snaps on Ubuntu-Core based devices.
The EdgeIQ CODA is able to manage snaps on the device using Snapd REST API provided by Ubuntu Core.
Prerequisites
- You are using custom build CODA snap
- snapd-control plug must be connected to CODA snap to get access to
/run/snapd.socket
Setting Up HTTP Sender Type Command
For doing you need to create User-Defined device commands on the Platform
Key Fields for HTTP Sender
Field Descriptions:
url
: The full URI or URL of the endpoint. Please refer to the complete Snapd specification.- Example: http://localhost/v2/snaps
method
: The HTTP method to be used. Only POST and PUT are supported for some operations; GET is also supported for retrieval operations.- Example:
POST
- Example:
GET
- Example:
headers
: HTTP request headers as key-value pairs. Common headers include Content-Type and Accept.
{
"Content-Type": "application/json",
"Accept": "application/json"
}
unix-socket
: Path to the Unix socket file which is used as transport of the HTTP client. In this example it should be path to snapd socket.- Example:
/run/snapd.socket
- Example:
timeout
: (Optional) Timeout in seconds before returning with an error. Default value is 30 seconds.- Example: 5
Example: Listing Installed Snaps
This command allow to see list of the all installed applications (snaps) on the device.
The same as snap list
cli command. API Ref: GET /v2/apps
Command Configuration
{
"name": "List Installed Snaps",
"sender_type": "http_sender",
"description": "Command to list all installed Snaps on an Ubuntu Core device using Snap API.",
"sender": {
"method": "GET",
"unix_socket": "/run/snapd.socket",
"url": "http://localhost/v2/apps"
},
"options": {}
}
Example: Installing Hello Snap
This command allows to installs hello snap on the device.
API Ref: POST /v2/snaps
Command Configuration
{
"name": "Install Hello Snap",
"sender_type": "http_sender",
"description": "This command installs the Hello Snap on the device.",
"sender": {
"method": "POST",
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"unix_socket": "/run/snapd.socket",
"url": "http://localhost/v2/snaps/hello"
},
"payload": {
"action": "install",
"channel": "stable"
},
"options": {}
}
Example: Remove Hello Snap
This command allows to remove snap from the device.
API Ref: POST /v2/snaps
Command Configuration
{
"name": "Remove Hello Snap",
"sender_type": "http_sender",
"description": "This command removes the Hello Snap from the device.",
"sender": {
"method": "POST",
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"unix_socket": "/run/snapd.socket",
"url": "http://localhost/v2/snaps/hello"
},
"payload": {
"action": "remove"
},
"options": {}
}
Updated 6 months ago