Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
Marco Masetti edited this page Sep 21, 2017 · 37 revisions

skyinfoblox - Go library for the Infoblox appliance

Skyinfoblox is the GoLang API wrapper for Infoblox. The wrapper uses the REST API interface provided by Infoblox. Skyinfoblox currently supports v2.6.1 of the Infoblox API. There is also a command line interface which can be built by running make in the root of this repo.

The Infoblox API documentation may be accessed by appending /wapidoc/ to the Infoblox server URL. E.g https://example-infoblox.example.com/wapidoc/

Run Unit tests

make test

Building the cli binary

make all

This will give you skyinfoblox-cli file which you can use to interact with InfoBlox API.

Using the library

Note: starting from release 0.1.0, a new API has been provided. The new API supports CRUD operations on all object types.

WAPI version used

The Server WAPI version can be configured at client creation time (it defaults anyhow to v2.6.1). Support for older versions schemes is driven by the Infoblox WAPI server itself (query your server schema to find out the list of supported versions).

Importing the skyinfoblox library

import(
    "github.com/sky-uk/skyinfoblox"
    "github.com/sky-uk/skyinfoblox/api/common/v261" // only if you want to use (a limited set of) v261 objects as defined structs
    )

Getting an API client object

In order to get an API client object first set a list of connnection parameters and pass it to the Connect() function:

	params := Params{
		WapiVersion: "v2.6.1", // this is anyhow the default...
		URL:         server,
		User:        username,
		Password:    password,
		IgnoreSSL:   true,
		Debug:       true,
	}

    client := Connect(params)

Creating an object

You can create any object you like setting object profile in a map:

	adminRole := make(map[string]interface{})
	adminRole["name"] = "a role name"
	adminRole["comment"] = "An initial comment"

	refObj, err := client.Create("adminrole", adminRole)

Or, for a limited selection of objects we directly support, you can use our provided structs:

		disable := true
		superUser := false

		adminGroup := model.IBXAdminGroup{
			AccessMethod:   []string{"API"},
			Comment:        "API Access only",
			Disable:        &disable,
			EmailAddresses: []string{"test@example-test.com"},
			Name:           "test",
			Roles:          []string{"test-role"},
			SuperUser:      &superUser,
		}

        refObj, err := client.Create("admingroup", adminGroup)

Deleting an object

    refObj, err = client.Delete(refObj)

The Delete() function returns the deleted object reference or an error otherwise

Reading an object

    obj := make(map[string]interface{})
    err = client.Read(objRef, []string{<list of attrs you want back>}, &obj)

Updating an object

    updatedRefObj, err := client.Update(refObj, newObjectProfileAsMap)

Creating and reading an object

This function can come handy if you like to get anyhow the created object back instead of only its reference. It returns the created object as map[string]interface{} You can create any object you like setting object profile in a map:

	adminRole := make(map[string]interface{})
	adminRole["name"] = "a role name"
	adminRole["comment"] = "An initial comment"

	myObj, err := client.CreateAndRead("adminrole", adminRole)

Updating and reading an object

Again this can be handy to get the updated object back

    updatedObj, err := client.UpdateAndRead(refObj, newObjectProfileAsMap)

Using the CLI

Building the CLI

The CLI may be built by running make in the root of the repo. Make will build the skyinfoblox binary.

$ make

Shell environment variables for the CLI

The Infoblox server credentials may either be passed as options to skyinfoblox on the command line or by setting environment variables.

Passing credentials as options

./skyinfoblox -username example-user -password examplePassword -server https://example-infoblox.example.com ....

Setting credentials through environment variables

$ export IBX_USERNAME="example-user"
$ export IBX_PASSWORD="examplePassword"
$ export IBX_SERVER="https://example-infoblox.example.com"

CLI help

General help

$ ./skyinfoblox-cli -h

Help for a sub-command. E.g. zone-create

$ ./skyinfoblox-cli sub-command -h

CLI options

The CLI has sub-commands for each Infoblox object type. Please see the links under Infoblox Objects for specific examples.

Using the library (up to release 0.0.30)

Import

import(
    "github.com/sky-uk/skyinfoblox"
)

Create a client object

client := skyinfoblox.NewInfobloxClient(
        infobloxServer, // e.g. https://example-infoblox.example.com
        infobloxUsername,
        infobloxPassword,
        allowUnverifiedSSL, // ignore certificate errors (boolean)
        debug, // enable debugging (boolean)
    )

    // create a new client
    client := skyinfoblox.NewInfobloxClient(infobloxServer, infobloxUsername, infobloxPassword, true, true)

Perform a request

This is an example of how to perform a request. More detailed examples may be found under Infoblox Objects below.

E.g. admingroup

// Prepare a request...

    // returnFields is specific to each object type and determines which attributes are returned from the Infoblox API.
    returnFields := []string{"name", "comment", "disable", "roles", "email_addresses", "superuser", "access_method"}
    adminGroupName := "example-group"
    getAdminGroupAPI := admingroup.NewGet(adminGroupName, returnFields)

// Perform the request...
    err := client.Do(getAdminGroupAPI)
    if err != nil {
        // handle errors....
    }

Working with the response object

E.g. returned response object is an interface and we need to cast it as an *admingroup.IBXAdminGroup.

    response := *adminGroupShowAPI.ResponseObject().(*admingroup.IBXAdminGroup)
    
    adminGroupName := response.Name

Finding the response HTTP status

httpStatus := getAdminGroupAPI.StatusCode()

Infoblox Objects

The following Infoblox Objects may be managed through these bindings:

Using the library (from 0.1.0 onward)

Note: starting from release 0.1.0, a new API has been provided. The new API supports CRUD operations on all object types. The old API is still present but considered deprecated. At some point in the future of the 0.1 release the old API may be deleted.

WAPI version used

The Server WAPI version can be configured at client creation time (it defaults anyhow to v2.6.1). Support for older versions schemes is driven by the Infoblox WAPI server itself (query your server schema to find out the list of supported versions).

Importing the library

Same as before:

import "github.com/sky-uk/skyinfoblox"

Getting an API client object

In order to get an API client object first set a list of connnection parameters and pass it to the Connect() function:

	params := Params{
		WapiVersion: "v2.6.1", // this is anyhow the default...
		URL:         server,
		User:        username,
		Password:    password,
		IgnoreSSL:   true,
		Debug:       true,
	}

    client := Connect(params)

Creating an object using the API

You can create any object you like setting object profile in a map:

	adminRole := make(map[string]interface{})
	adminRole["name"] = "a role name"
	adminRole["comment"] = "An initial comment"

	refObj, err := client.Create("adminrole", adminRole)

Or, for a limited selection of objects we directly support, you can use our provided structs:

		disable := true
		superUser := false

		adminGroup := model.IBXAdminGroup{
			AccessMethod:   []string{"API"},
			Comment:        "API Access only",
			Disable:        &disable,
			EmailAddresses: []string{"test@example-test.com"},
			Name:           "test",
			Roles:          []string{"test-role"},
			SuperUser:      &superUser,
		}

        refObj, err := client.Create("admingroup", adminGroup)

Deleting an object with the API

    refObj, err = client.Delete(refObj)

The Delete() function returns the deleted object reference or an error otherwise

Reading an object with the API

    obj := make(map[string]interface{})
    err = client.Read(objRef, []string{<list of attrs you want back>}, &obj)

Updating and object with the API

    updatedRefObj, err := client.Update(refObj, newObjectProfileAsMap)

Run Unit tests

$ make test
Clone this wiki locally