Developer Community

Reply
Highlighted
Occasional Contributor II

Aruba OS-CX command exec from my Linux shows an "(35) SSL connect error"

Hi experts,

 

We recently bought an OS-CX device which has a very rich set of RESTful API's.

 

I went thru the Swagger page and I wanted to write a script in Python that will get and set some of the interfaces attributes.

 

Looking at the Swagger doc, it says that to get the interfaces info, the CURL command to use is:

curl -X GET --header 'Accept: application/json' 'https://x.x.x.x/rest/v1/system/interfaces'

 

However, when I tried running this command from my Linux server (from which I can ssh and also open the HTTPS UI - so there are no network issues to connect to the OS-CX box from this server), I see this error:
(35) SSL connect error

Can anyone let me know what I am doing wrong here?

 

Note that on the older OS, there was this very helpful tutorial that showed how you can use a Python script to use the RESTful API:
https://arubaos-switch-rest-guide.readthedocs.io/en/latest/

But sadly, I didnt find any documentations about the later OS-CX for off box automation with Python ...

 

Id appreciate any help,

Cheers,

Tom

 

 

Re: Aruba OS-CX command exec from my Linux shows an "(35) SSL connect error"

Hi Tom,

 

You should open a session first, and retrieve a session cookie.

Here is an example of logging request with cURL :

curl -k[ --noproxy <ip_proxy>] POST -c <cookie-file> -H 'Content-Type: application/x-www-form-urlencoded' "https://<ip>/rest/v1/login" --data 'username=<username>&password=<password>'

After that, you should use this cookie in your GET request.

Also, maybe you should use the "--insecure" option with CURL, which avoids the SSL certificate validation, as the one which is used by default is a self-signed.

 

About the documentation, there's a specific one related to REST on CX.

You should find it on the support site - It's named "ArubaOS-CX REST API Guide for 10.01".

Everything is detailed in this doc.

 

Hope that helps.

Occasional Contributor II

Re: Aruba OS-CX command exec from my Linux shows an "(35) SSL connect error"

Thanks a lot for the info Arnaud!

 

The API document you shared is great - there is a section on how to do the RESTful API calls via Python.

 

By any chance, is there a gitHub URL that has any additional Python examples on how to use the REStful API's on the OS-CX?

It would be great to check the code out and will help me in starting the automation framework for this OS.

 

Cheers,

Tom

 

Re: Aruba OS-CX command exec from my Linux shows an "(35) SSL connect error"

Hi Tom,

 

There's a Github for Aruba, where you can find a lot of scripts/workflows (https://github.com/aruba) for Aruba Products, but I don't think we have published Python Scripts for CX yet.

 

But I can share a "minimalist" script in this thread if you need, with at least a logging and a GET or POST requests.

This would be used as an example.

Occasional Contributor II

Re: Aruba OS-CX command exec from my Linux shows an "(35) SSL connect error"

Thanks Arnaud,

 

If you can share a minimalist script that will get the login cookie, and run a get and a simple set command via the RESTful API's in Python on an OS-CX device, it will be great.

 

I am sure that many others in this forum will take advantage of that reference as well for their own automation tasks :-)

 

Thanks again,

Tom

 

Re: Aruba OS-CX command exec from my Linux shows an "(35) SSL connect error"

Hi Tom,

 

Here is an example :

 

import requests
import json
import pprint
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

s = requests.session()
url_login = "https://<switch_ip>/rest/v1/login"
credentials = {"username":"<username>","password":"<password>"}
post_login = s.post(url_login, params=credentials, verify=False)

try :
    print("VLAN informations")
    url_vlan = "https://<switch_ip>/rest/v1/system/bridge/vlans"
    get_vlan = s.get(url_vlan, verify=False)
    pprint.pprint(get_vlan.json())
except Exception as error:
    print('Ran into exception: {}. Logging out..'.format(error))
finally:
    url_logout = "https://<switch_ip>/rest/v1/logout"
    post_logout = s.post(url_logout, verify=False)

Hope that helps,

Occasional Contributor II

Re: Aruba OS-CX command exec from my Linux shows an "(35) SSL connect error"

Great - thanks a lot Aranaud.

This is very helpful!

 

By going thru the doc you shared about the RESTful APIs on the OS-CX, I tweaked the Python code samples and came up with a similar script that sets and gets the device attributes.

 

Thanks again,

Tom

 

 

Search Airheads
cancel
Showing results for 
Search instead for 
Did you mean: