Last active
August 29, 2015 14:06
-
-
Save bot11/4ac9977e931cd1713fc8 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
__author__ = 'root' | |
from keystoneclient.v2_0 import client as keystoneclient | |
from neutronclient.neutron import client as neutronclient | |
import sys | |
kclient = keystoneclient.Client(auth_url="http://localhost:35357/v2.0/", | |
username="admin", tenant_name="admin", | |
password="devstack") | |
nclient = neutronclient.Client('2.0', auth_url="http://localhost:35357/v2.0/", | |
username="admin", tenant_name="admin", | |
password="devstack") | |
nclient.format = 'json' | |
kclient.format = 'json' | |
def create_dmz(): | |
try: | |
current_tenant_list = kclient.tenants.list() | |
for tenant in current_tenant_list: | |
print tenant | |
network = nclient.create_network( | |
body={"network": {"name": "dmz_network_name", | |
"admin_state_up": "true", | |
"tenant_id": "19fc3b00df2e4078aea6097dcbfe4612"}}) | |
network_id = network['network']['id'] | |
print "Network ID: %s" % network_id | |
subnet = nclient.create_subnet( | |
body={"subnet": {"name": "dmz_network_name", | |
"network_id": network_id, | |
"tenant_id": "19fc3b00df2e4078aea6097dcbfe4612", | |
"ip_version": 4, | |
"cidr": "24.0.0.0/32"}}) | |
subnet_id = subnet['subnet']['id'] | |
print "Subnet ID: %s" % subnet_id | |
router = nclient.create_router( | |
body={"router": {"name": "router_dmz", | |
"tenant_id": "19fc3b00df2e4078aea6097dcbfe4612"}}) | |
router_id = router['router']['id'] | |
print "Router ID: %s" % router_id | |
nclient.add_gateway_router(router=router_id, body={"network_id": network_id,"enable_snat": False}) | |
#nclient.set_gateway(router=router_id, body={"network_id": network_id, "enable_snat": False}) | |
print "Gateway added." | |
except: | |
print "Unexpected error:", sys.exc_info()[0] | |
finally: | |
for network in nclient.list_networks()['networks']: | |
#print network | |
if network['name'] == "dmz_network_name": | |
nclient.delete_network(network['id']) | |
for router in nclient.list_routers()['routers']: | |
if router['name'] == "router_dmz": | |
nclient.delete_router(router['id']) | |
print "delete done" | |
def create_conexus(): | |
network = nclient.create_network( | |
body={"network": {"name": "transient_network", | |
"admin_state_up": "true", "router:external": "true", | |
"router:private": "true", "tenant_id": "", | |
"provider:network_type": "vlan", | |
"provider:physical_network": "conexus", | |
"provider:segmentation_id": "123"}}) | |
transit_network_id= network['network']['id'] | |
#neutron subnet-create < CONEXUS_TRANSIT_NETNAME > <CONEXUS_CIDR> --disable-dhcp --allocation-pool start=<6th IP>,end=<6th IP> | |
subnet = nclient.create_subnet( | |
body={"subnet" : {"name":"transit_subnet_name", | |
"network_id":transit_network_id, | |
"tenant_id":"", "ip_version":4, | |
"cidr":transit_subnet,'enable_dhcp':False, | |
"allocation_pools":[ | |
{"start":subnet_allocation_start, | |
"end":subnet_allocation_end}]}})['subnet']['id'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment