Created
April 4, 2013 15:29
-
-
Save djoreilly/5311384 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import pprint | |
import time | |
from quantumclient.quantum import client as qclient | |
from novaclient.v1_1 import client as nclient | |
import novaclient.exceptions as nova_exc | |
logging.basicConfig(level=logging.INFO) | |
#logging.basicConfig(level=logging.DEBUG) | |
KEYSTONE_URL='http://10.0.10.10:5000/v2.0' | |
qc = qclient.Client('2.0', auth_url=KEYSTONE_URL, username='admin', | |
tenant_name='demo', password='secrete') | |
nc = nclient.Client('admin', 'secrete', 'demo', KEYSTONE_URL, | |
service_type='compute') | |
net1 = qc.create_network({'network': {'name': 'net1', | |
'admin_state_up': True} }) | |
pprint.pprint(net1) | |
net1_id = net1['network']['id'] | |
sub1 = qc.create_subnet({'subnet': {'name': 'sub2', | |
'network_id': net1_id, | |
'ip_version': 4, | |
'cidr': '10.0.33.0/24'} }) | |
pprint.pprint(sub1) | |
ext_net = qc.create_network({'network': {'name': 'ext-net', | |
'admin_state_up': True, | |
'provider:network_type': 'local', | |
'router:external': True} }) | |
pprint.pprint(ext_net) | |
ext_net_id = ext_net['network']['id'] | |
ext_sub = qc.create_subnet({'subnet': {'name': 'ext-sub', | |
'network_id': ext_net_id, | |
'ip_version': 4, | |
'cidr': '192.168.101.0/24', | |
'enable_dhcp': False} }) | |
pprint.pprint(ext_sub) | |
router1 = qc.create_router( { 'router': { 'name': 'router1', | |
'admin_state_up': True} }) | |
router1_id = router1['router']['id'] | |
qc.add_gateway_router(router1_id, {'network_id': ext_net_id} ) | |
qc.add_interface_router(router1_id, {'subnet_id': sub1['subnet']['id']}) | |
pprint.pprint(qc.list_routers(name='router1')['routers'][0]) | |
try: | |
micro_flavor = nc.flavors.create('micro', 48, 1, 0, 6) | |
except nova_exc.ClientException: | |
micro_flavor = nc.flavors.get(6) | |
cirros_img = [i for i in nc.images.list() if i.name=='cirros-0.3.0-x86_64'][0] | |
vm1 = nc.servers.create('vm1', cirros_img, micro_flavor, | |
nics=[{'net-id': net1_id}] ) | |
while True: | |
print 'polling until quantum port for vm1 is ready...' | |
time.sleep(1) | |
ports = qc.list_ports(fields=['id'], device_id=vm1.id)['ports'] | |
if len(ports) > 0: | |
vm1_port_id = ports[0]['id'] | |
break | |
fip = qc.create_floatingip({'floatingip':{'floating_network_id':ext_net_id, | |
'port_id': vm1_port_id } }) | |
pprint.pprint(fip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment