Developer

 View Only
last person joined: yesterday 

Expand all | Collapse all

MM API config_path algorithm

This thread has been viewed 31 times
  • 1.  MM API config_path algorithm

    Posted Dec 08, 2020 04:37 PM
    This python function recursively searches searches the hierarchy for a group name or controller name and returns the config_path.

    def buildConfigPath(hierarchy , name):
        """
        Returns the config path (string) of the 'name' parameter, or a null
        string if not found.
        Cannot be used to search by name of the standby MM because MM hostnames
        do not appear in the configuration hierarchy; you will need to search by
        the standby MM MAC (lower case colon delimited). For the active MM, search 'mynode'.
    
        Params:
        hierarchy: json formated dict with the node hierarchy from
        GET /object/node_hierarchy (make sure to use json() method from requests.Response
        or it may not work)
        name: string of a controller hostname, group name, 'mynode' (active MM), 'md', 'mm',
        MAC of standby MM, or '/' (root)
        """
        
        if name == '/':
            return '/'
    
        elif hierarchy["name"] == name: # this controller matches 'name'
            return hierarchy["mac"]
    
        elif (hierarchy["type"] == "group" or hierarchy["type"] == "root"):
            for controller in hierarchy["devices"]: # iterate through device list. A "device" is a controller.
                mac = buildConfigPath(controller , name)
                if mac != '': # a controller in the device list matches 'name'
                  return '/' + mac 
    
            for childNode in hierarchy["childnodes"]: # iterate through the list of childnodes. A childnode is a subgroup.
                if childNode["name"] == name: 
                  return '/' + name # a group directly below this group matches 'name'
    
                path = buildConfigPath(childNode , name)
                if path != '':
                  return '/' + childNode["name"] + path # a controller was found 2 or more levels below this childnode
    
            return '' # 'name was not found in this group or any subgroup
        
        return "" # this controller doesn't match 'name'



  • 2.  RE: MM API config_path algorithm

    EMPLOYEE
    Posted Dec 11, 2020 03:35 PM
    Alternatively, you could use the "showcommand" API endpoint to obtain easily consumable data structure.

    Endpoint: https://<controller-ip>:4343/v1/configuration/showcommand?command=<cli-show-command>

    Sample Output:
    {
      "Configuration node hierarchy": [
        {
          "Config Node": "/",
          "Name": null,
          "Type": "System"
        },
        {
          "Config Node": "/md",
          "Name": null,
          "Type": "System"
        },
        {
          "Config Node": "/md/00:50:56:xx:xx:xx",
          "Name": "ArubaMC-VA",
          "Type": "Device"
        },
        {
          "Config Node": "/md/00:50:56:xx:xx:xy",
          "Name": "Aruba-MC-2",
          "Type": "Device"
        },
        {
          "Config Node": "/md/SJC",
          "Name": null,
          "Type": "Group"
        },
        {
          "Config Node": "/md/SJC/00:50:56:xx:xx:xz",
          "Name": null,
          "Type": "Device"
        },
        {
          "Config Node": "/md/us_west",
          "Name": null,
          "Type": "Group"
        },
        {
          "Config Node": "/md/us_west/site_A",
          "Name": null,
          "Type": "Group"
        },
        {
          "Config Node": "/mm",
          "Name": null,
          "Type": "System"
        },
        {
          "Config Node": "/mm/mynode",
          "Name": null,
          "Type": "System"
        }
      ],
      "_data": [
        "Default-node is /md. Autopark is enabled."
      ],
      "_meta": [
        "Config Node",
        "Type",
        "Name"
      ]
    }


    ------------------------------
    Karthikeyan Dhandapani
    ------------------------------