Mellanox OnyxにはjsonのREST-APIが搭載されています。

Pythonにてアクセスするサンプルは以下。



	
import urllib3
import json

def onyx_authenticate(ip_addr, user, password,):

    encoded_body = ("f_user_id=%s&f_password=%s" % (user,password)).encode('ascii')
    http=urllib3.PoolManager(cert_reqs='CERT_NONE')
    url = 'https://%s/admin/launch?script=rh&template=login&action=login' % ip_addr
    method = 'POST'
    header = {'User-Agent':'curl/7.58.0',
              'Content-Type': 'application/x-www-form-urlencoded',
              'Accept':'*/*',
              'Content-Length': '32',
              'Connection': 'keep-alive',
              }
    r = http.request(method,url,headers=header,body=encoded_body,retries=False)
    return r

def onyx_send_cmd(r, ip_addr, cmd):
    url='https://%s/admin/launch?script=json' % ip_addr
    encoded_body = ("{\"cmd\":\"%s\"}" % cmd).encode('ascii')
    http=urllib3.PoolManager(cert_reqs='CERT_NONE')
    url = 'https://%s/admin/launch?script=json' % ip_addr
    method = 'POST'
    cookie = r.headers['Set-Cookie'].split(";")[0]
    header = {'User-Agent':'curl/7.58.0',
              'Content-Type': 'application/x-www-form-urlencoded',
              'Accept':'*/*',
              'Connection': 'keep-alive',
              'Cookie': cookie
              }
    r = http.request(method,url,headers=header,body=encoded_body,retries=False)
    return r.data.decode('ascii')

def onyx_get_hostname(r, ip_addr):
    json_str = onyx_send_cmd(r, ip_addr, "show hosts")
    jsonObj = json.loads(json_str)
    return jsonObj['data'][0]['Hostname']

r = onyx_authenticate(ip_addr="10.12.50.101",user="admin",password="admin")
print(onyx_get_hostname(r,"10.12.50.101"))

何かにお役立てください。