Forum Discussion

crosson_16669's avatar
crosson_16669
Icon for Nimbostratus rankNimbostratus
Jul 24, 2013

API Convetion confusions

Consider the following.

ltm = F5::IControl.new(ltm_name, username, password, ["LocalLB.VirtualServer"]).get_interfaces["LocalLB.VirtualServer"]

ltm.add_rule(["temp_vserver"], [[{:rule_name => "new_rule, :priority => 3}]])

The irule object/hash is imbedded in two arrays. The API is shown here.

in LocalLB__VirtualServer__VirtualServerRule [] [] rules

In referncing the API documentation how am I to know that the irule object should be imbedded in two arrays?

It makes sense to me that the irule object is in a hash corresponding with the struct defined in the API.

{:rule_name => "new_rule", :priority => 3}

It also makes sense to me that this object is inside of an array, since you may want to add multiple rules at the same time. [{:rule_name => "new_rule", :priority => 3}, {:rule_name => "other_new_rule", :priority => 4}]

What I don't get is why all of this is embedded in yet another array and I also don't see how I am supposed to tell this from the API. I figured this out by reading others code on the devcentral codeshare.

6 Replies

  • Bumping my own question in hopes of some clarity.

     

    It seems to me anything that is [] [] is followed with syntax [[]]. Can someone confirm this?

     

  • The method in question is defined as

     

    LocalLB.VirtualServer.add_rule(
        in String [] virtual_servers,
        in LocalLB__VirtualServer__VirtualServerRule [] [] rules
    );
    

     

    The brackets indicate that it's an array. When there are 2 brackets, that indicates a 2-D array.

    If you think of it this way, it may make sense: The API is designed to allow you to add multiple rules to a single virtual server. If we only allowed you to act on a single virtual server, the API would look like this

     

    LocalLB.VirtualServer.add_rule(
        in String virtual_server,
        in LocalLB__VirtualServer__VirtualServerRule [] rules
    );
    

     

    This way you pass in a single scalar value for the virtual server in question, and an array of VirtualServerRule structures (one for each rule you want to assign to the Virtual).

    All our APIs are "bulk" enabled - meaning you can act on multiple objects in a single call. So for this situation, we will allow you to add multiple rules to multiple virtual servers in each method call. It may seem a bit confusing, but for folks that want to apply policy to 1000's of objects at once, it makes it a lot easier. Plus reducing roundtrip latency for 1000 calls, can give a significant speed increase on total execution time.

    So, going back to the API. To allow adding rules to multiple virtuals, we need an array for the virtuals. Then for a list of rules for each virtual, we will need a 2-D array for the rules parameter - the first dimension for each virtual, the second with the list of rules for that given virtual.

    Make sense?

  • @crosson, I'm confused. Did that answer your question or not? You posted saying you were looking for confirmation and then followed up with a thanks. Just making sure I got you covered...

     

    -Joe