Skip to content

netascode/go-aci

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Tests

go-aci

go-aci is a Go client library for Cisco ACI. It is based on Nathan's excellent goaci module and features a simple, extensible API and advanced JSON manipulation.

Getting Started

Installing

To start using go-aci, install Go and go get:

$ go get -u github.com/netascode/go-aci

Basic Usage

package main

import "github.com/netascode/go-aci"

func main() {
    client, _ := aci.NewClient("https://1.1.1.1", "user", "pwd")

    res, _ = client.Get("/api/mo/uni/tn-infra")
    println(res.Get("imdata.0.*.attributes.name"))
}

This will print:

infra

Result manipulation

aci.Result uses GJSON to simplify handling JSON results. See the GJSON documentation for more detail.

res, _ := client.GetClass("fvBD")
res.Get("0.fvBD.attributes.name").Str // name of first BD
res.Get("0.*.attributes.name").Str // name of first BD (if you don't know the class)

for _, bd := range res.Array() {
    println(res.Get("*.attributes|@pretty")) // pretty print BD attributes
}

for _, bd := range res.Get("#.fvBD.attributes").Array() {
    println(res.Get("@pretty")) // pretty print BD attributes
}

Helpers for common patterns

res, _ := client.GetDn("uni/tn-infra")
res, _ := client.GetClass("fvTenant")

Query parameters

Pass the aci.Query object to the Get request to add query paramters:

queryInfra := aci.Query("query-target-filter", `eq(fvTenant.name,"infra")`)
res, _ := client.GetClass("fvTenant", queryInfra)

Pass as many paramters as needed:

res, _ := client.GetClass("isisRoute",
    aci.Query("rsp-subtree-include", "relations"),
    aci.Query("query-target-filter", `eq(isisRoute.pfx,"10.66.0.1/32")`),
)

POST data creation

aci.Body is a wrapper for SJSON. SJSON supports a path syntax simplifying JSON creation.

exampleTenant := aci.Body{}.Set("fvTenant.attributes.name", "aci-example").Str
client.Post("/api/mo/uni/tn-aci-example", exampleTenant)

These can be chained:

tenantA := aci.Body{}.
    Set("fvTenant.attributes.name", "aci-example-a").
    Set("fvTenant.attributes.descr", "Example tenant A")

...or nested:

attrs := aci.Body{}.
    Set("name", "aci-example-b").
    Set("descr", "Example tenant B").
    Str
tenantB := aci.Body{}.SetRaw("fvTenant.attributes", attrs).Str

Token refresh

Token refresh is handled automatically. The client keeps a timer and checks elapsed time on each request, refreshing the token every 8 minutes. This can be handled manually if desired:

res, _ := client.Get("/api/...", aci.NoRefresh)
client.Refresh()

Documentation

See the documentation for more details.

About

A Go client library for Cisco ACI.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages