chiradeep / go-nitro

A Golang client to the Citrix ADC API
Apache License 2.0
18 stars 21 forks source link

Unable to Delete route #14

Closed sagarnikam123 closed 6 years ago

sagarnikam123 commented 6 years ago

Using Nitro-ide for local testing.

package main

import (
    "fmt"

    "github.com/chiradeep/go-nitro/config/network"
    "github.com/chiradeep/go-nitro/netscaler"
)

func main() {
    client, _ := netscaler.NewNitroClientFromEnv()
    route := network.Route{
        Network: "192.168.13.15",
        Netmask: "255.255.255.0",
        Gateway: "192.168.13.2",
    }
    result, err := client.AddResource(netscaler.Route.Type(), "abcRoute", &route)
    if err == nil {
        client.SaveConfig()
    }
    fmt.Println(result)
}

Actual result -

Expected result -

chiradeep commented 6 years ago

Thanks for the test code. Testing against Docker image store/citrix/netscalercpx:12.0-56.20:

2018/05/11 12:03:34 [TRACE] go-nitro: Resourcejson is {"route":{"gateway":"192.168.13.2","netmask":"255.255.255.0","network":"192.168.13.15"}}
2018/05/11 12:03:34 [DEBUG] go-nitro: Creating resource of type  route
2018/05/11 12:03:34 [TRACE] go-nitro: url is  http://localhost:32768/nitro/v1/config/route?idempotent=yes
2018/05/11 12:03:34 [DEBUG] go-nitro: response Status: 599 Netscaler specific error
2018/05/11 12:03:34 [INFO] go-nitro: error = { "errorcode": 604, "message": "The gateway is not directly reachable", "severity": "ERROR" }

Changing the payload (so that the route is valid):

2018/05/11 12:06:15 [TRACE] go-nitro: Resourcejson is {"route":{"gateway":"172.17.0.2","netmask":"255.255.255.0","network":"192.168.13.15"}}
2018/05/11 12:06:15 [DEBUG] go-nitro: Creating resource of type  route
2018/05/11 12:06:15 [TRACE] go-nitro: url is  http://localhost:32768/nitro/v1/config/route?idempotent=yes
2018/05/11 12:06:15 [DEBUG] go-nitro: response Status: 201 Created
2018/05/11 12:06:15 saveJSON is {"nsconfig":{}}
2018/05/11 12:06:15 [DEBUG] go-nitro: Saving config
2018/05/11 12:06:19 [DEBUG] go-nitro: response Status: 200 OK
sagarnikam123 commented 6 years ago

Thanks, @chiradeep , using netscalercpx image with given payload solves the problem. But another issue appears as Route don't have any unique name or idfor identification in its parameters.

While deleting we unable to delete it with the available functions in current nitro-client. As DeleteResource(resourceType string, resourceName string) will not be useful. So I used below one, but its kind of in-sufficient.

package main

import (
    "fmt"

    "github.com/chiradeep/go-nitro/config/network"
    "github.com/chiradeep/go-nitro/netscaler"
)

func main() {
    client, _ := netscaler.NewNitroClientFromEnv()
    route := network.Route{
        Network: "192.168.15.0",
        Netmask: "255.255.255.0",
        Gateway: "172.17.0.2",
    }
    // adding route
    result, err := client.AddResource(netscaler.Route.Type(), "awsRoute", &route)
    if err == nil {
        client.SaveConfig()
    }
    fmt.Println(result)
    // deleting route
    var argsBundle = []string{"192.168.15.0", "255.255.255.0", "172.17.0.2"}
    err2 := client.DeleteResourceWithArgs(netscaler.Route.Type(), "192.168.15.0", argsBundle)
    if err2 != nil {
        fmt.Println(err2)
    }
}
chiradeep commented 6 years ago

Fixed by 1aaf4aad6