README
¶
snapctl
Go wrapper library for the snapctl tool.
Wrappers for following subcommands are implemented:
-
fde-setup-request
: Obtain full disk encryption setup request -
fde-setup-result
: Set result for full disk encryption -
get
: The get command prints configuration and interface connection settings. -
is-connected
: Return success if the given plug or slot is connected, and failure otherwise -
reboot
: Control the reboot behavior of the system -
restart
: Restart services -
services
: Query the status of services -
set
: Changes configuration options -
set-health
: Report the health status of a snap -
start
: Start services -
stop
: Stop services -
system-mode
: Get the current system mode and associated details -
unset
: Remove configuration options
The commands and descriptions are from snapctl --help
.
Usage
package main
import (
"fmt"
"github.com/canonical/edgex-snap-hooks/v2/snapctl"
)
func main() {
// unset
err := snapctl.Unset("http").Run()
if err != nil {
panic(err)
}
// set values
err = snapctl.Set("http.bind-address", "0.0.0.0").Run()
if err != nil {
panic(err)
}
err = snapctl.Set("http.bind-port", "8080").Run()
if err != nil {
panic(err)
}
// set values with a JSON object
err = snapctl.Set("http.tls",
`{
"enabled":"true",
"cert":"./cert.pem",
"privkey":"./key.pem"
}`).Document().Run()
if err != nil {
panic(err)
}
// get one value
value, err := snapctl.Get("http.bind-port").Run()
if err != nil {
panic(err)
}
fmt.Println(value)
// Outputs:
// 8080
// get values as JSON object
value, err = snapctl.Get("http").Document().Run()
if err != nil {
panic(err)
}
fmt.Println(value)
// Outputs:
// {
// "bind-address": "0.0.0.0",
// "bind-port": 8080,
// "tls": {
// "cert": "./cert.pem",
// "enabled": "true",
// "privkey": "./key.pem"
// }
// }
// start and enable a service
err := snapctl.Start("snap-name.service-name").Enable().Run()
if err != nil {
panic(err)
}
// start all services
err := snapctl.Start("snap.name").Run()
if err != nil {
panic(err)
}
}
Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
func Get(key ...string) (cmd get)
Get reads config options or interface attributes It takes an arbitrary number of keys as input It returns an object for setting the CLI arguments before running the command
func Restart ¶
func Restart(service ...string) (cmd restart)
Restart restarts the services of the snap It takes an arbitrary number of service names as input It returns an object for setting the CLI arguments before running the command
func Services ¶
func Services(name ...string) (cmd services)
Services lists information about the services It takes zero or more service names as input It returns an object for setting the CLI arguments before running the command
func Set ¶
func Set(keyValue ...string) (cmd set)
Set writes config options or interface attributes It takes one or more key-value pairs as input It returns an object for setting optional CLI arguments before running the command
func Start ¶
func Start(service ...string) (cmd start)
Start starts the services of the snap It takes an arbitrary number of service names as input It returns an object for setting the CLI arguments before running the command
Types ¶
This section is empty.