Software Defined Networking
cancel
Showing results for 
Search instead for 
Did you mean: 

Python language bindings for the REST API - hp-sdn-client

 
dave_tucker
Advisor

Python language bindings for the REST API - hp-sdn-client

hp-sdn-client

A Python library that makes interaction with the HP SDN Controller REST API easy

 

This is a free open-source (Apache 2.0) library, that you can use to develop your own applications in Python.

It tries to abstract the complexity of dealing wth the REST API (JSON, Token Management etc..) and allows you to focus on your application logic.

 

You can install it from PyPi by using  pip:

 

    pip install hp-sdn-client

 

If you find this library useful, please star the repo on GitHub and if you'd like to contribute please fork it, make your changes and send me a pull request!


Code:

https://github.com/dave-tucker/hp-sdn-client

 

Docs:

https://hp-sdn-client.readthedocs.org/en/latest/index.html

 

Example:

 

import hpsdnclient as hp

controller = '10.44.254.129'
# Set up Authentication
auth = hp.XAuthToken(user='sdn',password='skyline', server=controller)
# Create an API object
api = hp.Api(controller=controller, auth=auth)

#API calls are then just a method call using "natural language"
datapaths = api.get_datapaths()
for datapath in datapaths:
    flows = api.get_flows(datapath.dpid)
    for flow in flows:
        print "This is a flow from {} to {} on DPID: {}".format(flow.eth_src, 
                                                                                       flow.eth_dst, 
                                                                                       datapath.dpid)

 

 

Technical Marketing Engineer @ HP and self-proclaimed SDN ninja. Words are my own...
10 REPLIES 10
RemiBatist
Regular Visitor

Re: Python language bindings for the REST API - hp-sdn-client

Hi Dave,

 

just starting with the sdn controller and a couple of hp 5900 switches.

want to use python to create some apps, so found your information and tried to install...but failed...

 

I installed the sdn-controller on a virtual ubuntu server and tested it with my 5900 switches...succes!

Now i installed pip on this same server: "sudo apt-get install python-pip"

after this i tried to start "pip install hp-sdn-client", but failed.

 

can you help me with this?

 

 

root@ubuntu-server-12:/# pip install hp-sdn-client
Downloading/unpacking hp-sdn-client
  Downloading hp-sdn-client-1.0.2.tar.gz (633Kb): 633Kb downloaded
  Running setup.py egg_info for package hp-sdn-client
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/build/hp-sdn-client/setup.py", line 18, in <module>
        from hpsdnclient import __version__
      File "hpsdnclient/__init__.py", line 17, in <module>
        from hpsdnclient.api import __version__, Api
      File "hpsdnclient/api.py", line 23, in <module>
        from hpsdnclient.core import CoreMixin
      File "hpsdnclient/core.py", line 28, in <module>
        import requests
    ImportError: No module named requests
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/build/hp-sdn-client/setup.py", line 18, in <module>

    from hpsdnclient import __version__

  File "hpsdnclient/__init__.py", line 17, in <module>

    from hpsdnclient.api import __version__, Api

  File "hpsdnclient/api.py", line 23, in <module>

    from hpsdnclient.core import CoreMixin

  File "hpsdnclient/core.py", line 28, in <module>

    import requests

ImportError: No module named requests

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /root/.pip/pip.log

dave_tucker
Advisor

Re: Python language bindings for the REST API - hp-sdn-client

Yes I can...

 

    pip install requests

 

... then you can try

 

    pip install hp-sdn-client

 

 

For some reason this dependency isn't being installed automatically. I'm looking in to it, but for now the workaround above should get you started!

 

-- Dave

Technical Marketing Engineer @ HP and self-proclaimed SDN ninja. Words are my own...
Highlighted
RemiBatist
Regular Visitor

Re: Python language bindings for the REST API - hp-sdn-client

PERFECT!

 

Thank you Dave!

 

root@ubuntu-server-12:/# pip install requests
Downloading/unpacking requests
  Downloading requests-2.2.1.tar.gz (421Kb): 421Kb downloaded
  Running setup.py egg_info for package requests

Installing collected packages: requests
  Running setup.py install for requests

Successfully installed requests
Cleaning up...
root@ubuntu-server-12:/# pip install hp-sdn-client
Downloading/unpacking hp-sdn-client
  Downloading hp-sdn-client-1.0.2.tar.gz (633Kb): 633Kb downloaded
  Running setup.py egg_info for package hp-sdn-client

Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.7/dist-packages (from hp-sdn-client)
Requirement already satisfied (use --upgrade to upgrade): distribute in /usr/lib/python2.7/dist-packages (from hp-sdn-client)
Installing collected packages: hp-sdn-client
  Running setup.py install for hp-sdn-client

Successfully installed hp-sdn-client
Cleaning up...
root@ubuntu-server-12:/#

Mehdi_Ad
Frequent Visitor

Re: Python language bindings for the REST API - hp-sdn-client

Thank you Dave it's done ;)

atul12345
Occasional Advisor

Re: Python language bindings for the REST API - hp-sdn-client

Hi Dave,

 

Thanks for the code. I was able to execute the same on Ubuntu.

 

However the same does not work on Windows machine. Can you guide in this case?

 

Regards


Atul

dave_tucker
Advisor

Re: Python language bindings for the REST API - hp-sdn-client

Windows is a little more tricky.

I'll try and put together some comprehensive instructions for windows in the next few days...

 

-- Dave

Technical Marketing Engineer @ HP and self-proclaimed SDN ninja. Words are my own...
dave_tucker
Advisor

Re: Python language bindings for the REST API - hp-sdn-client

v1.0.3 is now released which fixes the dependency errors mentioned in this thread

Technical Marketing Engineer @ HP and self-proclaimed SDN ninja. Words are my own...
vandewilly
Advisor

Re: Python language bindings for the REST API - hp-sdn-client

I'm using this python library to make some end to end tests on mininet. It's awesome and very helpfully because mininet is written in python too. I expect to send some pull requests soon.

 

Thanks.

dave_tucker
Advisor

Re: Python language bindings for the REST API - hp-sdn-client

If you want some help with installation and first steps or you would like some demos and code walkthroughs of example applications please check out these videos on YouTube

 

http://www.youtube.com/playlist?list=PLhpgNkL46_235AgToyrhEMykVLaBTt6Bw

 

This also covers installation on Windows as requested.

 

@dave_tucker

Technical Marketing Engineer @ HP and self-proclaimed SDN ninja. Words are my own...