[Openstack] Neutronclient python bindings

George Shuklin george.shuklin at gmail.com
Thu Jan 23 07:30:15 UTC 2014


Good day.

I search for documentation but found almost none. After some 
head-scratching and experiments code starts to look like this (see 
below). IMHO it looks horrible and I just a bit curious, is any more 
nice bindings without double dictionary as argument? Keystone bindings 
are much better...

Or may be I just using a wrong library/using it in the wrong way?

Thanks.

Code:

from neutronclient.neutron import client
neutron = client.Client('2.0', endpoint_url = neutron_endpoint, 
token=keystone.auth_token)
network=neutron.create_network( {'network':{
                 'name':'network name',
                 'admin_state_up':True,
                 'tenant_id': tenant.id
                 }
         } )
print "Create network", network['network']['id']
subnet=neutron.create_subnet({
         'subnet':{
                 'network_id':network['network']['id'],
                 'ip_version':4,
                 "cidr":'100.64.0.0/16',
                 'tenant_id': tenant.id
                 }
         } )
print "Create subnet:", subnet['subnet']['id']
external=[e for e in neutron.list_networks()['networks'] if 
e['router:external']==True][0]['id']
print external
router=neutron.create_router(   {'router':{
                         'name':'router',
                         'external_gateway_info':{
                                 "network_id": external,
                                 "enable_snat": True
                         },
                         'tenant_id': tenant.id
         }
         }
  )
print 'Create router:', router['router']['id']
floating=neutron.create_floatingip({'floatingip':{'floating_network_id':external, 
'tenant_id': tenant.id}})
print "Allocate floating IP:", floating
port=neutron.add_interface_router(router['router']['id'], 
{'subnet_id':subnet['subnet']['id'], 'tenant_id': tenant.id} )
print "Adding port to router to internal network", port





More information about the Openstack mailing list