Skip to content

Instantly share code, notes, and snippets.

@mjs
Last active June 26, 2017 03:14
Show Gist options
  • Save mjs/d9d016433e4348b4aa990a8f81d65d03 to your computer and use it in GitHub Desktop.
Save mjs/d9d016433e4348b4aa990a8f81d65d03 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/juju/juju/api"
"github.com/juju/juju/api/controller"
"github.com/juju/juju/juju"
"github.com/juju/juju/jujuclient"
"github.com/kr/pretty"
)
func connectAPI() api.Connection {
store := jujuclient.NewFileClientStore()
controllerName, err := store.CurrentController()
checkErr("CurrentController", err)
accountDetails, err := store.AccountDetails(controllerName)
checkErr("AccountDetails", err)
params := juju.NewAPIConnectionParams{
ControllerName: controllerName,
Store: store,
AccountDetails: accountDetails,
}
conn, err := juju.NewAPIConnection(params)
checkErr("NewAPIConnection", err)
return conn
}
func checkErr(label string, err error) {
if err != nil {
panic(fmt.Sprintf("%s: %v", label, err))
}
}
func main() {
conn := connectAPI()
client := controller.NewClient(conn)
watcher, err := client.WatchAllModels()
checkErr("watch", err)
for {
d, err := watcher.Next()
checkErr("next", err)
pretty.Println(d)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment