chiradeep / go-nitro

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

Servicegroupservicegroupmemberbinding module gives invalid servername error #10

Closed sanket4373 closed 6 years ago

sanket4373 commented 6 years ago

I was doing the same as you had suggested in your response to my previous issue. Here is my code snippet:

        createSvcGrp := basic.Servicegroup{
        Servicegroupname: "test-svc-grp",
        Servicetype: "TCP",
        }

        client.AddResource(netscaler.Servicegroup.Type(), "test-svc-grp", &createSvcGrp)

        createServer :=  basic.Server{
            Ipaddress: "x.x.x.x",
            Name: "test-server",
        }

        client.AddResource(netscaler.Server.Type(), "test-server", &createServer)

       // TO DO: Get the basic.Servicegroupservicegroupmemberbinding fixed in the library and add back the bind function
        bindSvcGrpToServer := basic.Servicegroupservicegroupmemberbinding{
            Servicegroupname: "test-svc-grp",
            Servername: "test-server",
            Port: 22,
        }

        client.BindResource(netscaler.Server.Type(), "test-server", netscaler.Servicegroup.Type(), "test-svc-grp", &bindSvcGrpToServer)

However, I am getting the following error at the server_servicegroup_binding when I execute the above functionality:

2018/01/24 14:51:10 [TRACE] go-nitro: Resourcejson is {"servicegroup":{"servicegroupname":"test-svc-grp","servicetype":"TCP"}}
2018/01/24 14:51:10 [DEBUG] go-nitro: Creating resource of type  servicegroup
2018/01/24 14:51:10 [TRACE] go-nitro: url is  http://x.x.x.x/nitro/v1/config/servicegroup?idempotent=yes
2018/01/24 14:51:10 [DEBUG] go-nitro: response Status: 201 Created
2018/01/24 14:51:10 [TRACE] go-nitro: Resourcejson is {"server":{"ipaddress":"x.x.x.x","name":"test-server"}}
2018/01/24 14:51:10 [DEBUG] go-nitro: Creating resource of type  server
2018/01/24 14:51:10 [TRACE] go-nitro: url is  http://x.x.x.x/nitro/v1/config/server?idempotent=yes
2018/01/24 14:51:10 [DEBUG] go-nitro: response Status: 201 Created
2018/01/24 14:51:10 [DEBUG] go-nitro: listing resource of type  server , name:  test-server
2018/01/24 14:51:10 [DEBUG] go-nitro: response Status: 200 OK
2018/01/24 14:51:10 [INFO] go-nitro: server test-server is already present
2018/01/24 14:51:10 [DEBUG] go-nitro: listing resource of type  servicegroup , name:  test-svc-grp
2018/01/24 14:51:10 [DEBUG] go-nitro: response Status: 200 OK
2018/01/24 14:51:10 [INFO] go-nitro: servicegroup test-svc-grp is already present
2018/01/24 14:51:10 [DEBUG] go-nitro: Creating resource of type  server_servicegroup_binding
2018/01/24 14:51:10 [TRACE] go-nitro: url is  http://x.x.x.x/nitro/v1/config/server_servicegroup_binding
2018/01/24 14:51:10 [DEBUG] go-nitro: response Status: 599 Netscaler specific error
2018/01/24 14:51:10 [INFO] go-nitro: error = { "errorcode": 278, "message": "Invalid argument [servername]", "severity": "ERROR" }

I have added the mandatory variables to the binding struct i.e. servername, port, servicegroupname. Not sure why I am getting an invalid servername error ? The library also suggests the same: https://developer-docs.citrix.com/projects/netscaler-nitro-api/en/12.0/configuration/basic/servicegroup_servicegroupmember_binding/servicegroup_servicegroupmember_binding/

And this curl call also suggests the same in terms of passing the parameters for binding the server and the servicegroup.

Bind the Server to an Existing Service Group:

# curl -s -i -k -H “Content-Type:application/vnd.com.citrix.netscaler.servicegroup_servicegroupmember_binding+json” –basic –user automation:password -X POST -d ‘{“servicegroup_servicegroupmember_binding”:{“servicegroupname”:”test_service_group”,”servername”:”test1″,”port”:”80″}}’ https://[nsip]/nitro/v1/config/servicegroup_servicegroupmember_binding/test_service_group?action=bind
chiradeep commented 6 years ago

Try client.BindResource(netscaler.Servicegroup.Type(), "test-svc-grp", netscaler.Server.Type(), "test-server", &bindSvcGrpToServer)

sanket4373 commented 6 years ago

According to the reference guide, the api call should be having this as a url: http://<netscaler-ip-address/nitro/v1/config/servicegroup_servicegroupmember_binding . Whereas, in the logs I see it as http://x.x.x.x/nitro/v1/config/server_servicegroup_binding .. Not sure if I am passing the resource types incorrectly in the BindResource function.

chiradeep commented 6 years ago

you are. please see comment above

sanket4373 commented 6 years ago

Had already tried that.. My bad forgot to post the error for that.. Nevertheless I gave it a shot again. Still the same error, got a 400 Bad Request:

go-nitro: Creating resource of type  servicegroup_server_binding
2018/01/25 10:32:00 [TRACE] go-nitro: url is  http://x.x.x.x/nitro/v1/config/servicegroup_server_binding
2018/01/25 10:32:00 [DEBUG] go-nitro: response Status: 400 Bad Request
2018/01/25 10:32:00 [INFO] go-nitro: error = { "errorcode": 1232, "message": "Invalid object name [servicegroup_server_binding]", "severity": "ERROR" }

This doesn't look right: servicegroup_server_binding. At no point I am getting the expected output in the logs: servicegroup_servicegroupmember_binding. Initially I thought the Nitro API for the servicegroup_servicegroupmember_binding must have been broken, but I was able to confirm that it works by running curl call.

For my client script as a work around i wrote a go client based on that curl request for the servicegroup_servicegroupmember_binding call.

Again, I don't see what else I might have missed here.

chiradeep commented 6 years ago

This particular API is pretty confusing. I have added an example f2c3659

chiradeep commented 6 years ago

see f2c3659