+def create_network_full(neutron_client,
+ net_name,
+ subnet_name,
+ router_name,
+ cidr):
+
+ # Check if the network already exists
+ network_id = get_network_id(neutron_client, net_name)
+ subnet_id = get_subnet_id(neutron_client, subnet_name)
+ router_id = get_router_id(neutron_client, router_name)
+
+ if network_id != '' and subnet_id != '' and router_id != '':
+ logger.info("A network with name '%s' already exists..." % net_name)
+ else:
+ neutron_client.format = 'json'
+ logger.info('Creating neutron network %s...' % net_name)
+ network_id = create_neutron_net(neutron_client, net_name)
+
+ if not network_id:
+ return False
+
+ logger.debug("Network '%s' created successfully" % network_id)
+ logger.debug('Creating Subnet....')
+ subnet_id = create_neutron_subnet(neutron_client, subnet_name,
+ cidr, network_id)
+ if not subnet_id:
+ return None
+
+ logger.debug("Subnet '%s' created successfully" % subnet_id)
+ logger.debug('Creating Router...')
+ router_id = create_neutron_router(neutron_client, router_name)
+
+ if not router_id:
+ return None
+
+ logger.debug("Router '%s' created successfully" % router_id)
+ logger.debug('Adding router to subnet...')
+
+ if not add_interface_router(neutron_client, router_id, subnet_id):
+ return None
+
+ logger.debug("Interface added successfully.")
+
+ logger.debug('Adding gateway to router...')
+ if not add_gateway_router(neutron_client, router_id):
+ return None
+
+ logger.debug("Gateway added successfully.")
+
+ network_dic = {'net_id': network_id,
+ 'subnet_id': subnet_id,
+ 'router_id': router_id}
+ return network_dic
+
+
+def create_shared_network_full(net_name, subnt_name, router_name, subnet_cidr):
+ neutron_client = get_neutron_client()
+
+ network_dic = create_network_full(neutron_client,
+ net_name,
+ subnt_name,
+ router_name,
+ subnet_cidr)
+ if network_dic:
+ if not update_neutron_net(neutron_client,
+ network_dic['net_id'],
+ shared=True):
+ logger.error("Failed to update network %s..." % net_name)
+ return None
+ else:
+ logger.debug("Network '%s' is available..." % net_name)
+ else:
+ logger.error("Network %s creation failed" % net_name)
+ return None
+ return network_dic
+
+
+def create_bgpvpn(neutron_client, **kwargs):
+ # route_distinguishers
+ # route_targets
+ json_body = {"bgpvpn": kwargs}
+ return neutron_client.create_bgpvpn(json_body)
+
+
+def create_network_association(neutron_client, bgpvpn_id, neutron_network_id):
+ json_body = {"network_association": {"network_id": neutron_network_id}}
+ return neutron_client.create_network_association(bgpvpn_id, json_body)
+
+
+def create_router_association(neutron_client, bgpvpn_id, router_id):
+ json_body = {"router_association": {"router_id": router_id}}
+ return neutron_client.create_router_association(bgpvpn_id, json_body)
+
+
+def update_bgpvpn(neutron_client, bgpvpn_id, **kwargs):
+ json_body = {"bgpvpn": kwargs}
+ return neutron_client.update_bgpvpn(bgpvpn_id, json_body)
+
+
+def delete_bgpvpn(neutron_client, bgpvpn_id):
+ return neutron_client.delete_bgpvpn(bgpvpn_id)
+