go-aci

command module
v0.0.0-...-c11f831 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

README

go-aci

Go API wrapper for Cisco ACI

GoDoc Go Report Card stability-experimental

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/robphoenix/go-aci/aci"
)

func main() {

	// create client
	client, err := aci.NewClient(aci.Config{
		Host:     "sandboxapicdc.cisco.com",
		Username: "admin",
		Password: "ciscopsdt",
	})
	if err != nil {
		log.Fatal(err)
		return
	}

	ctx := context.Background()

	// login
	err = client.Login(ctx)
	if err != nil {
		log.Fatal(err)
		return
	}

	// define nodes
	node401, err := client.FabricMembership.NewNode(
		"leaf-401",    // name
		"401",         // id
		"1",           // pod id
		"FOC0849N1BD", // serial number
		"leaf",        // role
	)
	if err != nil {
		log.Fatal(err)
		return
	}

	node402, err := client.FabricMembership.NewNode(
		"leaf-402",    // name
		"402",         // id
		"1",           // pod id
		"FOC0456N2BC", // serial number
		"leaf",        // role
	)
	if err != nil {
		log.Fatal(err)
		return
	}

	// mark node for creation
	node401.SetCreated()

	// mark node for deletion
	node402.SetDeleted()

	nodes := []*aci.Node{
		node401,
		node402,
	}

	// update ACI Fabric Membership
	resp, err := client.FabricMembership.Update(ctx, nodes...)
	if err != nil {
		log.Fatal(err)
		return
	}

	fmt.Printf("resp = %+v\n", resp)

	// see a nodes current status (defaults to create)
	status401 := node401.Status()
	fmt.Println(status401) // Output: "created"
	status402 := node402.Status()
	fmt.Println(status402) // Output: "deleted"

	node402.SetCreated()

	resp, err = client.FabricMembership.Update(ctx, node402)
	if err != nil {
		log.Fatal(err)
		return
	}

	// list nodes
	nodes, err = client.FabricMembership.List(ctx)
	if err != nil {
		log.Fatal(err)
		return
	}

	for i, node := range nodes {
		fmt.Printf("%d: %s\n", i+1, node)
	}
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL