skyinfoblox

package module
v0.0.0-...-4c513d9 Latest Latest
Warning

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

Go to latest
Published: May 6, 2019 License: BSD-3-Clause Imports: 9 Imported by: 1

README

skyinfoblox - Go library for the Infoblox appliance

This is the GoLang API wrapper for Infoblox. This is currently used for building terraform provider for the same appliance. This package is based on the Infoblox WAPI library version v2.6.1. Wapi library documentation can be accessed directly on Infoblox web site.

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)

CLI Usage

If called without parameters, the cli will print its needed input parameters and the provided commands

$ ./skyinfoblox-cli
  -debug
    	Debug output. Default:false
  -password string
    	Authentication password (Env: IBX_PASSWORD)
  -port int
    	Infoblox API server port. Default:443 (default 443)
  -server string
    	Infoblox API server hostname or address. (Env: IBX_SERVER)
  -username string
    	Authentication username (Env: IBX_USERNAME)
  -wapiVersion string
    	WAPI version (defaults to v2.6.1) 
  Commands:
    create-and-read-object
    create-object
    delete-object
    read-all-objects
    read-object
    update-and-read-object
    update-object

Creating an object with the CLI

To create an object, define first its profile in a json-encoded file, then issue the command:

./skyinfoblox-cli <all needed input params> create-object -type <object type> -profile <json-file with encoded object profile>

The command should print the created object reference or the error returned by the Infoblox REST API (note: passing the -debug parameter will result in the detailed request and response being dumped on screen).

Deleting

To delete an object:

./skyinfoblox-cli <all needed input params> delete-object -ref <the object reference>
Reading all objects of a given type

To get the list of all objects of a given type:

./skyinfoblox-cli <all needed input params> read-all-objects -type <object type>

You should get back the list of objects (default fields)

Reading an object

To get the profile of an object:

./skyinfoblox-cli <all needed input params> read-object -ref <object reference> -return-params <comma-separated list of attributes to get back>
To update an object

To update an object:

./skyinfoblox-cli <all needed input params> update-object -ref <object reference> -profile <json-encoded file with updated object profile>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterProfileKeys

func FilterProfileKeys(profile map[string]interface{}, validKeys []string) map[string]interface{}

FilterProfileKeys - filters the keys of the provided map, deleting the ones not contained in the valid keys list

func FilterReturnFields

func FilterReturnFields(required, allowed []string) []string

FilterReturnFields - filters the list of required return fields based on the list of readable ones

func GetObjectTypeFromRef

func GetObjectTypeFromRef(ref string) string

GetObjectTypeFromRef - returns the object type given an object reference Object reference format: wapitype / refdata [ : name1 [ { / nameN }... ] ]

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client : the infoblox client

func Connect

func Connect(params Params) *Client

Connect - creates a client object and returns it

func (Client) Create

func (client Client) Create(objType string, profile interface{}) (string, error)

Create - creates an object returns an array with these fields: - the created object reference ("" in case of errors) - the error (nil in case of success)

func (Client) CreateAndRead

func (client Client) CreateAndRead(objType string, profile interface{}) (map[string]interface{}, error)

CreateAndRead - Creates the object and, upon success, reads it back returns the newly create object profile or error otherwise

func (Client) Delete

func (client Client) Delete(objRef string) (string, error)

Delete - deletes an object returns an array with these fields: - the deleted object reference ("" in case of errors) - the error (nil in case of success)

func (Client) FilterProfileAttrs

func (client Client) FilterProfileAttrs(objType string, profile map[string]interface{}, filter []string)

FilterProfileAttrs - filters out profile attributes Workflow:

  • as the object can have nested structs, we need to proceed in this way:
  • we have the object type
  • we get the object schema
  • for each schema attr we get:
  • the type(s)
  • the authentication rules
  • the is_array boolean flag
  • we also have a global map of schemas for structs in the model package SO:
  • for each object attr:
  • for each attribute type
  • if type is not in global struct map
  • delete attribute from profile if not valid
  • else (it's a struct, we have hence metadata for it from model...):
  • if is_array:
  • for each array item (needs to have a pointer to the struct):
  • for each attr in item:
  • delete from item if not valid

------------------------------------------------------------------------------

func (Client) GetObjectSchema

func (client Client) GetObjectSchema(objType string) (map[string]interface{}, error)

GetObjectSchema - retrieves the object schmea

func (Client) GetValidKeys

func (client Client) GetValidKeys(objType string, filter []string) []string

GetValidKeys - retrieves the list of valid keys for the performed operation from the object schema

func (Client) Read

func (client Client) Read(objRef string, returnFields []string, obj interface{}) error

Read - reads an object given its reference id The pointer to the object is passed as input param returns an error (nil in case of success)

func (Client) ReadAll

func (client Client) ReadAll(objType string) ([]map[string]interface{}, error)

ReadAll - reads all objects

func (Client) Update

func (client Client) Update(objRef string, newProfile interface{}) (string, error)

Update - updates an object returns an array with these fields: - the updated object reference ("" in case of errors) - the error (nil in case of success)

func (Client) UpdateAndRead

func (client Client) UpdateAndRead(objRef string, newProfile interface{}) (map[string]interface{}, error)

UpdateAndRead - updates an object and returns the updated object back

type Params

type Params struct {
	URL         string
	User        string
	Password    string
	IgnoreSSL   bool
	Debug       bool
	Timeout     time.Duration
	WapiVersion string
}

Params : client connection parameters

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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