Ask Your Question

how to execute python API's for load balancer?

asked 2014-12-29 03:12:50 -0600

amitabh sinha gravatar image

I want to execute python API'S for balancer. please guide and share link or document if anybody have it.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-12-30 01:27:07 -0600

Ranjit gravatar image

updated 2014-12-30 01:29:06 -0600

link for all the neutron API:

below are some ways to call API:

  • Using curl

1.Get the keystone token

curl -i '' -X POST -H "Content-Type: application/json" -H "Accept: application/json"  -d '{"auth": {"tenantName": "admin", "passwordCredentials": {"username": "admin", "password": "admin_pass"}}}'

{"access": {"token": {"issued_at": "2014-12-30T06:56:08.718473", "expires": "2014-12-30T07:56:08Z", "id": "afc877f644b94eed95b71100eab17bb9", "tenant": {"description": "Admin Tenant", "enabled": true, "id": "fd987a8fb1b845fbb04b28e8f680d040", "name": "admin"},

2.Use that token in curl request

    curl -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token:afc877f644b94eed95b71100eab17bb9" http://openstackJuno:9696/v2.0/networks

{"networks": [{"status": "ACTIVE", "subnets": ["a285caf5-f032-46e6-b359-34029269671a"], "name": "flatNetwork", "provider:physical_network": "ph-enp4s0f1", "admin_state_up": true, "tenant_id": "fd987a8fb1b845fbb04b28e8f680d040", "provider:network_type": "flat", "router:external": false, "shared": false, "id": "18cb4b31-d131-42d7-bcd2-b2ec92a40e7d", "provider:segmentation_id": null}]}
  • in python code

neutron API will be used by importing neutronclient module.

Interface for all the API (including load-balancer API's) are in the file: (neutronclient Installation dir)/v2_0/

sample code for calling API which will list all the subnets. Before calling this script you need to set the keystone credentials.

#!/usr/bin/env python

import os
from oslo.config import cfg
from neutronclient.v2_0 import client

def get_keystone_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['password'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['tenant_name'] = os.environ['OS_TENANT_NAME']
    return d

def listNetwork():
    creds = get_keystone_creds()
    myNeutronClient = client.Client(**creds)
    print myNeutronClient.list_subnets()

if __name__ == "__main__":

[root@openstackJuno ~]# python 
{'subnets': [{u'name': u'flatSubNet', u'enable_dhcp': True, u'network_id': u'18cb4b31-d131-42d7-bcd2-b2ec92a40e7d', u'tenant_id': u'fd987a8fb1b845fbb04b28e8f680d040', u'dns_nameservers': [], u'ipv6_ra_mode': None, u'allocation_pools': [{u'start': u'', u'end': u''}], u'gateway_ip': u'', u'ipv6_address_mode': None, u'ip_version': 4, u'host_routes': [], u'cidr': u'', u'id': u'a285caf5-f032-46e6-b359-34029269671a'}]}
edit flag offensive delete link more


thanks for help! It worked :-)

amitabh sinha gravatar imageamitabh sinha ( 2014-12-30 23:07:23 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2014-12-29 03:12:50 -0600

Seen: 946 times

Last updated: Dec 30 '14