#NEWLINE# def _do_create_networks( self , context , label , cidr , multi_host , num_networks , network_size , cidr_v6 , gateway , gateway_v6 , bridge , bridge_interface , dns1 = None , dns2 = None , fixed_cidr = None , mtu = None , dhcp_server = None , enable_dhcp = None , share_address = None , allowed_start = None , allowed_end = None , **kwargs ) : #NEWLINE# #INDENT# 'Create networks based on parameters.' #NEWLINE# fixed_net_v4 = netaddr . IPNetwork ( '0/32' ) #NEWLINE# fixed_net_v6 = netaddr . IPNetwork ( '::0/128' ) #NEWLINE# subnets_v4 = [ ] #NEWLINE# subnets_v6 = [ ] #NEWLINE# if kwargs . get ( 'ipam' ) : #NEWLINE# #INDENT# if cidr_v6 : #NEWLINE# #INDENT# subnets_v6 = [ netaddr . IPNetwork ( cidr_v6 ) ] #NEWLINE# #UNINDENT# if cidr : #NEWLINE# #INDENT# subnets_v4 = [ netaddr . IPNetwork ( cidr ) ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# subnet_bits = int ( math . ceil ( math . log ( network_size , 2 ) ) ) #NEWLINE# if cidr_v6 : #NEWLINE# #INDENT# fixed_net_v6 = netaddr . IPNetwork ( cidr_v6 ) #NEWLINE# prefixlen_v6 = ( 128 - subnet_bits ) #NEWLINE# if ( prefixlen_v6 > 64 ) : #NEWLINE# #INDENT# prefixlen_v6 = 64 #NEWLINE# #UNINDENT# subnets_v6 = fixed_net_v6 . subnet ( prefixlen_v6 , count = num_networks ) #NEWLINE# #UNINDENT# if cidr : #NEWLINE# #INDENT# fixed_net_v4 = netaddr . IPNetwork ( cidr ) #NEWLINE# prefixlen_v4 = ( 32 - subnet_bits ) #NEWLINE# subnets_v4 = list ( fixed_net_v4 . subnet ( prefixlen_v4 , count = num_networks ) ) #NEWLINE# #UNINDENT# #UNINDENT# if cidr : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# nets = objects . NetworkList . get_all ( context ) #NEWLINE# #UNINDENT# except exception . NoNetworksFound : #NEWLINE# #INDENT# nets = [ ] #NEWLINE# #UNINDENT# num_used_nets = len ( nets ) #NEWLINE# self . _validate_cidr ( context , nets , subnets_v4 , fixed_net_v4 ) #NEWLINE# #UNINDENT# networks = objects . NetworkList ( context = context , objects = [ ] ) #NEWLINE# subnets = six . moves . zip_longest ( subnets_v4 , subnets_v6 ) #NEWLINE# for ( index , ( subnet_v4 , subnet_v6 ) ) in enumerate ( subnets ) : #NEWLINE# #INDENT# net = objects . Network ( context = context ) #NEWLINE# uuid = kwargs . get ( 'uuid' ) #NEWLINE# if uuid : #NEWLINE# #INDENT# net . uuid = uuid #NEWLINE# #UNINDENT# net . bridge = bridge #NEWLINE# net . bridge_interface = bridge_interface #NEWLINE# net . multi_host = multi_host #NEWLINE# net . dns1 = dns1 #NEWLINE# net . dns2 = dns2 #NEWLINE# net . mtu = mtu #NEWLINE# net . enable_dhcp = enable_dhcp #NEWLINE# net . share_address = share_address #NEWLINE# net . project_id = kwargs . get ( 'project_id' ) #NEWLINE# if ( num_networks > 1 ) : #NEWLINE# #INDENT# net . label = ( '%s_%d' % ( label , index ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# net . label = label #NEWLINE# #UNINDENT# bottom_reserved = self . _bottom_reserved_ips #NEWLINE# top_reserved = self . _top_reserved_ips #NEWLINE# extra_reserved = [ ] #NEWLINE# if ( cidr and subnet_v4 ) : #NEWLINE# #INDENT# current = subnet_v4 [ 1 ] #NEWLINE# if allowed_start : #NEWLINE# #INDENT# val = self . _index_of ( subnet_v4 , allowed_start ) #NEWLINE# current = netaddr . IPAddress ( allowed_start ) #NEWLINE# bottom_reserved = val #NEWLINE# #UNINDENT# if allowed_end : #NEWLINE# #INDENT# val = self . _index_of ( subnet_v4 , allowed_end ) #NEWLINE# top_reserved = ( ( subnet_v4 . size - 1 ) - val ) #NEWLINE# #UNINDENT# net . cidr = str ( subnet_v4 ) #NEWLINE# net . netmask = str ( subnet_v4 . netmask ) #NEWLINE# net . broadcast = str ( subnet_v4 . broadcast ) #NEWLINE# if gateway : #NEWLINE# #INDENT# net . gateway = gateway #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# net . gateway = current #NEWLINE# current += 1 #NEWLINE# #UNINDENT# net . dhcp_server = ( dhcp_server or net . gateway ) #NEWLINE# net . dhcp_start = current #NEWLINE# current += 1 #NEWLINE# if ( net . dhcp_start == net . dhcp_server ) : #NEWLINE# #INDENT# net . dhcp_start = current #NEWLINE# #UNINDENT# extra_reserved . append ( str ( net . dhcp_server ) ) #NEWLINE# extra_reserved . append ( str ( net . gateway ) ) #NEWLINE# #UNINDENT# if ( cidr_v6 and subnet_v6 ) : #NEWLINE# #INDENT# net . cidr_v6 = str ( subnet_v6 ) #NEWLINE# if gateway_v6 : #NEWLINE# #INDENT# net . gateway_v6 = str ( gateway_v6 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# net . gateway_v6 = str ( subnet_v6 [ 1 ] ) #NEWLINE# #UNINDENT# net . netmask_v6 = str ( subnet_v6 . netmask ) #NEWLINE# #UNINDENT# if ( CONF . network_manager == 'nova.network.manager.VlanManager' ) : #NEWLINE# #INDENT# vlan = kwargs . get ( 'vlan' , None ) #NEWLINE# if ( not vlan ) : #NEWLINE# #INDENT# index_vlan = ( index + num_used_nets ) #NEWLINE# vlan = ( kwargs [ 'vlan_start' ] + index_vlan ) #NEWLINE# used_vlans = [ x . vlan for x in nets ] #NEWLINE# if ( vlan in used_vlans ) : #NEWLINE# #INDENT# used_vlans . sort ( ) #NEWLINE# vlan = ( used_vlans [ ( - 1 ) ] + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# net . vpn_private_address = net . dhcp_start #NEWLINE# extra_reserved . append ( str ( net . vpn_private_address ) ) #NEWLINE# net . dhcp_start = ( net . dhcp_start + 1 ) #NEWLINE# net . vlan = vlan #NEWLINE# net . bridge = ( 'br%s' % vlan ) #NEWLINE# index_vpn = ( index + num_used_nets ) #NEWLINE# net . vpn_public_port = ( kwargs [ 'vpn_start' ] + index_vpn ) #NEWLINE# #UNINDENT# net . create ( ) #NEWLINE# networks . objects . append ( net ) #NEWLINE# if ( cidr and subnet_v4 ) : #NEWLINE# #INDENT# self . _create_fixed_ips ( context , net . id , fixed_cidr , extra_reserved , bottom_reserved , top_reserved ) #NEWLINE# #UNINDENT# #UNINDENT# return obj_base . obj_to_primitive ( networks )