Thursday, 4 April 2013

Using the python-quantumclient

I was not able to find any doc except this, so I used the client source for clues on the functions/arguments and the API guide for the make-up of the request/response dictionaries.

This script creates a network (net1) and configures the external network. Then a router is created with its gateway is set to the external network and it is given an interface on net1. An instance is created with an nic connected to net1, and a floating IP is created and associated with the port the vm's nic is plugged into. Here is the CLI doing the same.

Sample output:

vagrant@controller:/vagrant$ python sample.py
{u'network': {u'admin_state_up': True,
              u'id': u'aeac6081-9cb3-411e-b927-36c110b80798',
              u'name': u'net1',
              u'provider:network_type': u'gre',
              u'provider:physical_network': None,
              u'provider:segmentation_id': 1,
              u'router:external': False,
              u'shared': False,
              u'status': u'ACTIVE',
              u'subnets': [],
              u'tenant_id': u'5d3ca208a1d2478e8a9cefb309513fa5'}}

{u'subnet': {u'allocation_pools': [{u'end': u'10.0.33.254',
                                    u'start': u'10.0.33.2'}],
             u'cidr': u'10.0.33.0/24',
             u'dns_nameservers': [],
             u'enable_dhcp': True,
             u'gateway_ip': u'10.0.33.1',
             u'host_routes': [],
             u'id': u'ead47f5d-a72d-4202-9b8c-4a3b96049c9b',
             u'ip_version': 4,
             u'name': u'sub2',
             u'network_id': u'aeac6081-9cb3-411e-b927-36c110b80798',
             u'tenant_id': u'5d3ca208a1d2478e8a9cefb309513fa5'}}

{u'network': {u'admin_state_up': True,
              u'id': u'e50eddff-49e7-4a3e-a4e7-2b282552e2b4',
              u'name': u'ext-net',
              u'provider:network_type': u'local',
              u'provider:physical_network': None,
              u'provider:segmentation_id': None,
              u'router:external': True,
              u'shared': False,
              u'status': u'ACTIVE',
              u'subnets': [],
              u'tenant_id': u'5d3ca208a1d2478e8a9cefb309513fa5'}}

{u'subnet': {u'allocation_pools': [{u'end': u'192.168.101.254',
                                    u'start': u'192.168.101.2'}],
             u'cidr': u'192.168.101.0/24',
             u'dns_nameservers': [],
             u'enable_dhcp': False,
             u'gateway_ip': u'192.168.101.1',
             u'host_routes': [],
             u'id': u'2b3dffc3-72ac-447c-abab-a2747abf67e2',
             u'ip_version': 4,
             u'name': u'ext-sub',
             u'network_id': u'e50eddff-49e7-4a3e-a4e7-2b282552e2b4',
             u'tenant_id': u'5d3ca208a1d2478e8a9cefb309513fa5'}}

{u'admin_state_up': True,
 u'external_gateway_info': {u'network_id': u'e50eddff-49e7-4a3e-a4e7-2b282552e2b4'},
 u'id': u'2d34e275-8504-44ff-ad92-142d184b7cb6',
 u'name': u'router1',
 u'status': u'ACTIVE',
 u'tenant_id': u'5d3ca208a1d2478e8a9cefb309513fa5'}

polling until quantum port for vm1 is ready...
polling until quantum port for vm1 is ready...

{u'floatingip': {u'fixed_ip_address': u'10.0.33.3',
                 u'floating_ip_address': u'192.168.101.3',
                 u'floating_network_id': u'e50eddff-49e7-4a3e-a4e7-2b282552e2b4',
                 u'id': u'd26f1bc9-9941-4761-8cc7-f9d987eb30a3',
                 u'port_id': u'89378092-b300-461e-b71a-e2990a324284',
                 u'router_id': u'2d34e275-8504-44ff-ad92-142d184b7cb6',
                 u'tenant_id': u'5d3ca208a1d2478e8a9cefb309513fa5'}}

And a cleanup script: