Skip to content

Binding library v0.3.x usage

lakshmi-enjeti edited this page Jan 11, 2018 · 3 revisions

Library version 0.3.x usage

Starting from version 0.4.0 the API has been completely reviewed, this wiki page depicts the library usage for any 0.3.x library version, though its usage is strongly discouraged.

This wrapper uses the REST API interface provided by the vTM, version 3.8.

Resources defined in the schema

The following is the list of the resources managed by the API. The list is a limited subset of all the resources exposed by the Pulse vTM REST API Server and, moreover, for some of them the set of defined attributes is far from being complete (though representing the minimal subset that provides most of the resource usage). The schema is bond to version 3.8 of the Pulse vTM REST API Server. The schema is not going to be upgraded to current and future releases of the REST API schema.

Resource Name Resource URI Create Read Update Delete
DNS Zone dns_server/zones Y Y Y Y
DNS Zone File dns_server/zone_files Y Y Y Y
GLB Service glb_services Y Y Y Y
Location locations Y Y Y Y
Monitor monitors Y Y Y Y
Pool pools Y Y Y Y
Rule rules Y Y Y Y
SSL Key Pair ssl/server_keys Y Y Y Y
Traffic IP Group traffic_ip_groups Y Y Y Y
Traffic Manager traffic_managers Y Y Y Y
User Authenticator user_authenticators Y Y Y Y
User Group user_groups Y Y Y Y
Virtual Server virtual_servers Y Y Y Y

Usage

Import library

What follows is consistent for any release of the binding prior to 0.4.0 and is a set of examples that do not cover the complete list of exposed resources, though the API being pretty consistent (so what is depicted basically works with any resource)

import(
    "github.com/sky-uk/go-pulse-vtm"
)

Get a client object

In order to get a client object authentication credentials needs to be provided. The REST API transport protocol is by default HTTPS and hence SSL encryption is used by default. Certificate handling behaviour can be controlled via the ignoreSSL flag. More information about the client and the Base API may be found here https://github.com/sky-uk/go-rest-api.

Working with Locations

Required Import

In order to work with locations, import the location package section:

import (
    "github.com/sky-uk/go-pulse-vtm/api/location"
)

Getting the list of locations

    api := location.NewGetAll()
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    locations := api.ResponseObject().(*location.Locations)

Retrieving a single location

    api := location.NewGet( name )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    location := api.ResponseObject().(*location.Location)

Creating a location

    newLocation := location.Location{
        ...
    }

    api := location.NewCreate( name, newLocation )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    createdLocation := api.ResponseObject().(*location.Location)

Updating a location

    updateLocation := location.Location{
        ...
    }

    api := location.NewUpdate( name, updateLocation )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    updatedLocation := api.ResponseObject().(*location.Location)

Deleting a location

    api := location.NewDelete( name )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    } else {
        log.Printf("Location %s deleted", name)
    }

Working with Monitors

Required Import

In order to work with monitors, import the monitor package section:

import (
    "github.com/sky-uk/go-pulse-vtm/api/monitor"
)

Getting the list of active monitors

    api := monitor.NewGetAll()
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    monitors := api.ResponseObject().(*monitor.MonitorsList)

Retrieving a single monitor

    api := monitor.NewGet( name )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    monitor := api.ResponseObject().(*monitor.Monitor)

Creating a monitor

    newMonitor := monitor.Monitor{
        ...
    }

    api := monitor.NewCreate( name, newMonitor )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    monCreated := api.ResponseObject().(*monitor.Monitor)

Updating a monitor

    updateMonitor := monitor.Monitor{
        ...
    }

    api := monitor.NewUpdate( name, updateMonitor )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    monUpdated := api.ResponseObject().(*monitor.Monitor)

Deleting a monitor

    api := monitor.NewDelete( name )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    } else {
        log.Printf("Monitor %s deleted", name)
    }

Working with Pools

Required Import

In order to work with pools, import the pool package section:

import (
    "github.com/sky-uk/go-pulse-vtm/api/pool"
)

Getting the list of pools

    api := monitor.NewGetAll()
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    pools := api.ResponseObject().(*pool.LBPoolList)

Retrieving a single pool

    api := monitor.NewGet(name)
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    pool := api.ResponseObject().(*pool.Pool)

Creating a pool

    newPool := pool.Pool{
        ...
    }

    api := pool.NewCreate( name, newPool )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    poolCreated := api..ResponseObject().(*pool.Pool)

Updating a pool

    updatePool := pool.Pool{
        ...
    }

    api := pool.NewUpdate( name, updatePool )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    poolUpdated := api.ResponseObject().(*pool.Pool)

Deleting a pool

    api := pool.NewDelete( name )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    } else {
        log.Printf("Pool %s deleted", name)
    }

Working with Server keys

Required Import

In order to work with server keys, import the pool package section:

import (
    "github.com/sky-uk/go-pulse-vtm/api/sslServerKey"
)

Getting the list of server keys

    api := monitor.NewGetAll()
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    keys := api.ResponseObject().(*sslServerKey.SSLServerKeysList)

Retrieving a single server key

    api := sslServerKey.NewGet(name)
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    key := api.ResponseObject().(*sslServerKey.SSLServerKey)

Creating a server key

    newKey := sslServerKey.SSLServerKey{
        ...
    }

    api := sslServerKey.NewCreate( name, newKey )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    keyCreated := api.ResponseObject().(*sslServerKey.SSLServerKey)

Updating a server key

    updateKey := sslServerKey.SSLServerKey{
        ...
    }

    api := sslServerKey.NewUpdate( name, updateKey )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    keyUpdated := api.ResponseObject().(*sslServerKey.SSLServerKey)

Deleting a server key

    api := sslServerKey.NewDelete( name )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    } else {
        log.Printf("Server key %s deleted", name)
    }

Working with traffic IP groups

Required Import

In order to work with traffic IP groups, import the traffic IP package section:

import (
    "github.com/sky-uk/go-pulse-vtm/api/trafficIpGroups"
)

Getting the list of traffic IP groups

    // to get the list of all traffic managers
    api := trafficIpGroups.NewGetAll()
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    trafficIPGroups := api.ResponseObject().(*trafficIpGroups.TrafficIPGroupList)

Retrieving a single traffic IP group

    api := trafficIpGroups.NewGet(name)
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    trafficIPGroup := api.ResponseObject().(*trafficIpGroups.TrafficIPGroup)

Creating a traffic IP group

    newTipg := trafficIpGroups.TrafficIPGroup{
        ...
    }

    api := trafficIpGroups.NewCreate( name, newTipg )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    tipgCreated := api.ResponseObject().(*trafficIpGroups.TrafficIPGroup)

Updating a traffic IP group

    updateTipg := trafficIpGroups.TrafficIPGroup{
        ...
    }

    api := trafficIpGroups.NewUpdate( name, updateTipg )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    tipgUpdated := api.ResponseObject().(*trafficIpGroups.TrafficIPGroup)

Deleting a traffic IP group

    api := trafficIpGroups.NewDelete( name )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    } else {
        log.Printf("Traffic IP group %s deleted", name)
    }

Working with Traffic IP Group Managers

Traffic IP Group Managers are only used by Traffic IP Group to retrieve a list of Traffic Mangers when creating a Traffic IP Group.

Required Import

In order to work with Traffic IP Group Managers, import the Traffic IP Group package section:

import (
    "github.com/sky-uk/go-pulse-vtm/api/traffic_ip_group_managers"
)

Getting the list of Traffic IP Group Managers

    api := trafficIpGroupManager.NewGetAll()
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    trafficIPGroupManagers := api.ResponseObject().(*trafficIpGroupManager.TrafficManagerChildren)

Working with virtual servers

Required Import

In order to work with virtual servers, import the virtual server package section:

import (
    "github.com/sky-uk/go-pulse-vtm/api/virtualserver"
)

Getting the list of virtual servers

    api := virtualserver.NewGetAll()
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    virtualServer := api.ResponseObject().(*virtualserver.VirtualServersList)

Retrieving a single virtual server

    api := virtualserver.NewGet(name)
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    virtualServer := api.ResponseObject().(*virtualserver.VirtualServer)

Creating a virtual server

    newVS := virtualserver.VirtualServer{
        ...
    }

    api := virtualserver.NewCreate( name, newVS )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    vsCreated := api.ResponseObject().(*virtualserver.VirtualServer)

Updating a virtual server

    updateVS := virtualserver.VirtualServer{
        ...
    }

    api := virtualserver.NewUpdate( name, updateVS )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    vsUpdated := api.ResponseObject().(*virtualserver.VirtualServer)

Deleting a virtual server

    api := virtualserver.NewDelete( name )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    } else {
        log.Printf("Virtual server %s deleted", name)
    }

Working with rules

Required Import

 In order to work with rules, import the rule package section:
 
 ```
 import (
     "github.com/sky-uk/go-pulse-vtm/api/rule"
 )
 ```

Getting the list of rules

    api := rule.NewGetAll()
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    rules := api.ResponseObject().(*rule.Rules)

Retrieving a single rule

    api := rule.NewGet(name)
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

    // Returns the traffic script as a string
    trafficScript := api.ResponseObject().(*[]byte)

Creating a rule

    ruleName := "my-rule"
    trafficScript := []byte(`
            if( string.ipmaskmatch( request.getremoteip(), "192.168.123.10" ) ){
                    connection.discard();
            }`)
    
    api := rule.NewCreate( ruleName, trafficScript )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }
    

Updating a rule

    ruleName := "my-rule"
    updatedTrafficScript := []byte(`
                                     if( string.ipmaskmatch( request.getremoteip(), "192.168.123.10" ) ){
                                             connection.discard();
                                     }`)
                                     
    api := rule.NewUpdate( ruleName, updatedTrafficScript )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    }

Deleting a rule

    nameRuleToDelete := "my-rule"

    api := rule.NewDelete( nameRuleToDelete )
    err := client.Do(api)
    if err != nil {
        log.Fatal(err)
    } else {
        log.Printf("Rule %s deleted", nameRuleToDelete)
    }