Reply

Help... Adding new host using JAVA WAPI client

Techie
Posts: 6
3809     0

Hi,

 

I am trying to use the JAVA libraries provided in this LINK to create a host with the following data:

- next available ip

- configure for dhcp enabled

 

I forked my own method and tried to convert it to add a host, but I keep getting error:

"Error": "AdmConProtoError: List value expected for field: ipv4addrs",   "code": "Client.Ibap.Proto",   "text": "List value expected for field: ipv4addrs"

 

This is the class I built:

    /**

     * Perform some operations with Hosts with JSON.

     * 

     * @param port

     */

    public static void hostJSON(WapiPort port) {

        IWapiDAO<JSONObject, JSONObject> network = new WapiDAO<JSONObject, JSONObject>(

                port"record:host", JSONObject.class, JSONObject.class); //$NON-NLS-1$

        try {

            JSONObject object = new JSONObject();

            object.put("ipv4addrs"""); //$NON-NLS-1$ //$NON-NLS-2$

            object.put("ipv4addr","func:nextavailableip:10.1.0.0/16"); //$NON-NLS-1$ //$NON-NLS-2$

            object.put("configure_for_dhcp","true"); //$NON-NLS-1$ //$NON-NLS-2$

            object.put("mac","aa:bb:cc:41:22:31"); //$NON-NLS-1$ //$NON-NLS-2$

            object.put("name","naorproj-tal3.weizmann.ac.il"); //$NON-NLS-1$ //$NON-NLS-2$

 

            String ref = network.create(object);

 

 

        } catch (JSONException e) {

            logger.error("An exception occurred when creating JSON"e); //$NON-NLS-1$

            throw new RuntimeException(e);

        }

    }

 

Can someone please put me in the right direction? or at least head me to a guid how to use these libraries?

 

Thanks!

 

Naor.

Re: Help... Adding new host using JAVA WAPI client

Adviser
Posts: 63
3809     0

Hi,

 

I don't know the API but the lines :

 

object.put("ipv4addrs""");

object.put("ipv4addr","func:nextavailableip:10.1.0.0/16");

 

Seems weird to me.

 

You are adding an empty list of ipv4addrs, and then try to add a single ipv4addr again. Sending these options are a bit contradictory and the ivp4addrs cannot indeed be empty, hence your error "list value expected for field: ipv4addrs". Try to send just the ipv4addr or fill in a list in ipv4addrs, maybe something along :

 

object.put("ipv4addrs""[10.1.1.1, 10.1.1.2]");

 

 

Re: Help... Adding new host using JAVA WAPI client

Community Manager
Community Manager
Posts: 248
3809     0

the ipv4addrs list is an array of objects, not addreses (an IP can also have a MAC, etc). so the format should look like this

 

"ipv4addrs":[
      { "ipv4addr":"1.1.1.21" }
    ],

 

Re: Help... Adding new host using JAVA WAPI client

Techie
Posts: 6
3809     0

In the end I had to do reverse engineering to the Java client, But it works.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You