Developer

 View Only
last person joined: 2 days ago 

Expand all | Collapse all

CXOS API call to add/update VLAN interface IP Address

This thread has been viewed 22 times
  • 1.  CXOS API call to add/update VLAN interface IP Address

    Posted May 20, 2022 05:12 PM
    Hi all,

    I've written some code to upload CXOS configs to devices. This works very well, but I'm struggling to add/edit IP addresses.

    As an example, I have a valid session which I have just used to update the switch's config and the this code to add the IP address to the vlan 204 interface.

    session = Session(switch, "10.08")
    
    ip_address = "10.10.10.1"
    
    interface = Interface(session, "vlan204")
    interface.ip4_address = ip_address
    interface.update()
    ​
    The interface.update() method returns True and the http response in the pyaoscx code turns 200. However, checking the switch's config reveals that vlan 204 has no IP address. Furthermore, there is no indication of the call/response or logging messages in the switch's log.

    I'm currently stumped and out of ideas, so if anyone has some experience here, I'd love to hear what you have done.

    Cheers,

    C

    ------------------------------
    Conor Cunningham
    ------------------------------


  • 2.  RE: CXOS API call to add/update VLAN interface IP Address

    Posted May 21, 2022 09:09 AM
    Should it be of interest to anyone, here is the solution.

    # instantiate session
    session = Session(switch, "10.08")
    session.open("admin", "password124")
    
    # example of how to upload config
    config = Configuration(session)
    config.upload_switch_config_from_local(
        config_name="running-config",
        config_json=base_config_file
    )
    
    # here's the critical part. Instantiate the interface you want.
    # In my case I want the SVI vlan 204
    interface = Interface(session, "vlan204")
    
    # now you need to get the interface.
    interface.get()
    
    # now you can assign an IPv4 address to the interfaace
    interface.add_ipv4_address(ip_address=ip_address)
    interface.update() # update the interface to save the new IP
    
    # for anyone who is interested, this is how you create a static route
    
    # first, instantiate the VRF you that you want, in my case the default VRF
    vrf = Vrf(session, "default")
    vrf.get() # fetch the vrf object
    
    # now add the route. The variable default_network is an IP address
    # as a string, e.g., "10.10.10.1"
    route = StaticRoute(session, default_network, vrf)
    
    # important to close the session otherwise you'll fill
    # the session table and not be able to login until
    # you clear the https sessions
    session.close()​


    ------------------------------
    Conor Cunningham
    ------------------------------



  • 3.  RE: CXOS API call to add/update VLAN interface IP Address

    MVP GURU
    Posted May 21, 2022 09:33 AM
    Missing the mask on the ip_address ?

    do you have try 10.10.10.1/24 ? (and may be also

    ------------------------------
    PowerArubaSW : Powershell Module to use Aruba Switch API for Vlan, VlanPorts, LACP, LLDP...

    PowerArubaCP: Powershell Module to use ClearPass API (create NAD, Guest...)

    PowerArubaCL: Powershell Module to use Aruba Central

    PowerArubaCX: Powershell Module to use ArubaCX API (get interface/vlan/ports info)..

    ACEP / ACMX #107 / ACDX #1281
    ------------------------------



  • 4.  RE: CXOS API call to add/update VLAN interface IP Address

    Posted May 25, 2022 09:28 AM

    G'day,

    Well spotted. The IP address in my first post is missing the mask. It was edited in browser but the address in the code was with the mask. The solution I posted shows how I managed to get it working.

    On a different note, I'm looking for the developer docs for pyaoscx - do you know where I can find them?

    Cheers.



    ------------------------------
    Conor Cunningham
    ------------------------------



  • 5.  RE: CXOS API call to add/update VLAN interface IP Address

    EMPLOYEE
    Posted Jun 02, 2022 06:21 PM
    Hi Conor,
    We're working on more documentation for pyaoscx v2 to be uploaded onto our developer hub at devhub.arubanetworks.com.  Keep an eye out in the near future for it.

    Thanks,
    Alvin
    Aruba Automation PLM/TME

    ------------------------------
    Alvin Castro
    ------------------------------



  • 6.  RE: CXOS API call to add/update VLAN interface IP Address

    Posted Jun 03, 2022 12:36 PM

    Hi Alvin,

    Thanks for the heads up - I'll keep an eye out for the docs.

    Again, thank you.

    Cheers,

    Conor



    ------------------------------
    Conor Cunningham
    ------------------------------