Code Monkey home page Code Monkey logo

goaci's Introduction

goACI
ACI client library for Go


GoACI is a Go client library for Cisco ACI. It features a simple, extensible API, advanced JSON manipulation, and a backup client for running queries against the backup file.

Getting Started

Installing

To start using GoACI, install Go and go get:

$ go get -u github.com/brightpuddle/goaci

Basic Usage

package main

import "github.com/brightpuddle/goaci"

func main() {
    client, _ := goaci.NewClient("1.1.1.1", "user", "pwd")
    if err := client.Login(); err != nil {
        panic(err)
    }

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

This will print:

infra

Result manipulation

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

res, _ := 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, _ := GetDn("uni/tn-infra")
res, _ := GetClass("fvTenant")

Query parameters

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

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

Pass as many paramters as needed:

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

POST data creation

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

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

These can be chained:

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

...or nested:

attrs := goaci.Body{}.
    Set("name", "goaci-example-b").
    Set("descr", "Example tenant B").
    Str
tenantB := goaaci.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/...", goaci.NoRefresh)
client.Refresh()

Backup client

goACI also features a backup file client for querying ACI .tar.gz backup files. This client partially mirrors the API of the HTTP client. Note that this must be imported separately.

package main

import "github.com/brightpuddle/goaci/backup"

func main() {
    client, _ := backup.NewClient("config.tar.gz")

    res, _ := client.GetDn("uni/tn-infra")
    println(res.Get("@pretty"))

    res, _ = client.GetClass("fvBD")
    for _, bd := range res.Get("#.fvBD.attributes").Array() {
        fmt.Priintln(bd)
    }

}

Documenatation and examples

See here for various examples.

And, the documentation for more details.

goaci's People

Contributors

brightpuddle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

goaci's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.