1755120 Members
2919 Online
108830 Solutions
New Discussion

HP IMC - Restful API example

 
SiyonKart
Occasional Contributor

HP IMC - Restful API example

Hello,

I'm trying to access HP's restful API via scripting and I havn't had any luck. I can access the real-time locate fuction if I use a browser manually; but I'm not going to do that 10,000 an hour - hence why I want to script it.

  showbox So far I can't get it to work and HP support doesn't help. I was wondering if there was a working example of accessing the eAPI via CLI(curl/python) out there? I'm speed test  hoping to copy/modify it.

Thank you

1 REPLY 1
jguse
HPE Pro

Re: HP IMC - Restful API example

Hello,

Please have a look at pyhpeimc, a native Python library for iMC that you can use to easily create your own scripts to interact with iMC via API. I've done this successfully with my lab installations numerous times and it's quite easy - the functions themselves that you can use all provide an example of how to implement them, and while far from all API features are covered by the libraries, it should be easy enough to use the existing ones as a kind of template to create others for your own needs.

https://github.com/HPENetworking/PYHPEIMC

Here is an extract of the comments on get_all_devs function that explains how you could make use of that function:

    """Takes string input of IP address to issue RESTUL call to HP IMC\n
    :param auth: requests auth object #usually auth.creds from auth pyhpeimc.auth.class
    :param url: base url of IMC RS interface #usually auth.url from pyhpeimc.auth.authclass
    :param network_address: str IPv4 Network Address
    :param category: str or int corresponding to device category (0=router, 1=switches, see API docs for other examples)
    :return: dictionary of device details
    :rtype: dict
    >>> from pyhpeimc.auth import *
    >>> from pyhpeimc.plat.device import *
    >>> auth = IMCAuth("http://", "10.101.0.203", "8080", "admin", "admin")
    >>> dev_list = get_all_devs( auth.creds, auth.url, network_address= '10.11.')
    >>> assert type(dev_list) is list
    >>> assert 'sysName' in dev_list[0]
    """

Hope that helps!

Best regards,
Justin

Working @ HPE
Accept or Kudo