Skip to content

About

A Go client library for Cisco Crosswork.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

30 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Tests

go-crosswork

go-crosswork is a Go client library for Cisco Crosswork Network Controller. It features a simple, extensible API and advanced JSON manipulation.

Getting Started

Installing

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

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

Basic Usage

package main

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

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

    res, _ := client.Get("/crosswork/inventory/v1/nodes/count")
    println(res.Get("number_of_nodes").String())
}

This will print something like:

33

Result manipulation

crosswork.Res uses GJSON to simplify handling JSON results. See the GJSON documentation for more detail.

res, _ := client.Post("/crosswork/inventory/v1/nodes/query", `{"limit":10}`)

for _, node := range res.Get("data").Array() {
    println(node.Get("host_name").String())
}

POST data creation

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

body := crosswork.Body{}.
    Set("data.0.profile", "example").
    Set("data.0.user_pass.0.user_name", "admin").
    Set("data.0.user_pass.0.password", "secret").
    Set("data.0.user_pass.0.type", "ROBOT_USERPASS_SSH")
client.Post("/crosswork/inventory/v1/credentials", body.Str, crosswork.NoLogPayload)

Testing

The unit tests need nothing but Go:

go test -race -v -cover ./...

The live tests talk to a real Crosswork and are skipped unless CW_URL, CW_USERNAME and CW_PASSWORD are set. Copy .env.sample to .env, fill in the values and load them into the shell:

cp .env.sample .env
set -a; source .env; set +a

Run all tests, unit and live:

go test -race -v -cover ./...

Run only the live tests:

go test -race -v -run TestLive ./...

The live tests that change the cluster also need CW_WRITE=1. They create objects named cwtest- and remove them again.

Documentation

See the documentation for more details.

About

A Go client library for Cisco Crosswork.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages