def dcnm_network_create_event(self, network_info):
<EOL>pre_seg_id = network_info.get('<STR_LIT>')<EOL>pre_project_name = network_info.get('<STR_LIT>')<EOL>pre_partition_name = network_info.get('<STR_LIT>')<EOL>if not pre_seg_id or not pre_partition_name or not pre_project_name:<EOL><INDENT>LOG.error('<STR_LIT>', network_info)<EOL>return<EOL><DEDENT>if pre_partition_name != self.cfg.dcnm.default_partition_name:<EOL><INDENT>LOG.error('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': pre_partition_name,<EOL>'<STR_LIT>': self.cfg.dcnm.default_partition_name})<EOL>return<EOL><DEDENT>query_net = self.get_network_by_segid(pre_seg_id)<EOL>if query_net:<EOL><INDENT>LOG.info('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT:name>': query_net.name})<EOL>return<EOL><DEDENT>dcnm_net_info = self.dcnm_client.get_network(pre_project_name,<EOL>pre_seg_id)<EOL>if not dcnm_net_info:<EOL><INDENT>LOG.info('<STR_LIT>',<EOL>{'<STR_LIT>': pre_project_name, '<STR_LIT>': pre_seg_id})<EOL>return<EOL><DEDENT>net_id = utils.get_uuid()<EOL>pseg_id = dcnm_net_info.get('<STR_LIT>')<EOL>seg_id = self._get_segmentation_id(net_id, pseg_id, '<STR_LIT>')<EOL>cfgp = dcnm_net_info.get('<STR_LIT>')<EOL>net_name = dcnm_net_info.get('<STR_LIT>')<EOL>fwd_mod = self.dcnm_client.config_profile_fwding_mode_get(cfgp)<EOL>tenant_name = dcnm_net_info.get('<STR_LIT>')<EOL>tenant_id = self.get_project_id(tenant_name)<EOL>subnet = dcnm_net_info.get('<STR_LIT>')<EOL>if not subnet:<EOL><INDENT>gw_addr = dcnm_net_info.get('<STR_LIT>')<EOL>net_mask = dcnm_net_info.get('<STR_LIT>')<EOL>cidr = utils.make_cidr(gw_addr, net_mask)<EOL>if not cidr:<EOL><INDENT>LOG.error('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': gw_addr, '<STR_LIT>': net_mask})<EOL>return<EOL><DEDENT>subnet = dict(gateway=gw_addr, subnet=cidr)<EOL><DEDENT>if not (net_name and tenant_id and seg_id and subnet):<EOL><INDENT>LOG.error('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>'<STR_LIT>', {'<STR_LIT:name>': net_name,<EOL>'<STR_LIT>': tenant_id,<EOL>'<STR_LIT>': seg_id,<EOL>'<STR_LIT>': subnet})<EOL>return<EOL><DEDENT>net_ext_name = self.cfg.dcnm.dcnm_net_ext<EOL>self.network[net_id] = dict(segmentation_id=seg_id,<EOL>config_profile=cfgp,<EOL>fwd_mod=fwd_mod,<EOL>tenant_id=tenant_id,<EOL>name=net_name + net_ext_name,<EOL>id=net_id,<EOL>source='<STR_LIT>')<EOL>self.add_network_db(net_id, self.network[net_id], '<STR_LIT>',<EOL>constants.RESULT_SUCCESS)<EOL>try:<EOL><INDENT>updated_net_name = net_name + net_ext_name + str(seg_id)<EOL>body = {'<STR_LIT>': {'<STR_LIT:name>': updated_net_name,<EOL>'<STR_LIT>': tenant_id,<EOL>'<STR_LIT>': True}}<EOL>dcnm_net = self.neutronclient.create_network(<EOL>body=body).get('<STR_LIT>')<EOL>net_id = dcnm_net.get('<STR_LIT:id>')<EOL><DEDENT>except Exception as exc:<EOL><INDENT>del self.network[net_id]<EOL>self.delete_network_db(net_id)<EOL>LOG.exception('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': body, '<STR_LIT>': str(exc)})<EOL>return<EOL><DEDENT>LOG.debug('<STR_LIT>', (<EOL>body))<EOL>pool = subnet.get('<STR_LIT>')<EOL>allocation_pools = []<EOL>if pool:<EOL><INDENT>allocation_pools = [{'<STR_LIT:start>': s, '<STR_LIT:end>': e} for s, e in<EOL>[p.split('<STR_LIT:->') for p in pool.split('<STR_LIT:U+002C>')]]<EOL><DEDENT>try:<EOL><INDENT>body = {'<STR_LIT>': {'<STR_LIT>': subnet.get('<STR_LIT>'),<EOL>'<STR_LIT>': subnet.get('<STR_LIT>'),<EOL>'<STR_LIT>': <NUM_LIT:4>,<EOL>'<STR_LIT>': net_id,<EOL>'<STR_LIT>': tenant_id,<EOL>'<STR_LIT>': not self.dcnm_dhcp,<EOL>'<STR_LIT>': allocation_pools, }}<EOL>if not self.dcnm_dhcp:<EOL><INDENT>body.get('<STR_LIT>').pop('<STR_LIT>')<EOL><DEDENT>LOG.debug('<STR_LIT>', body)<EOL>dcnm_subnet = self.neutronclient.create_subnet(<EOL>body=body).get('<STR_LIT>')<EOL>subnet_id = dcnm_subnet.get('<STR_LIT:id>')<EOL>self.subnet[subnet_id] = {}<EOL>self.subnet[subnet_id].update(body.get('<STR_LIT>'))<EOL><DEDENT>except Exception as exc:<EOL><INDENT>LOG.exception('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>{'<STR_LIT>': body['<STR_LIT>'], '<STR_LIT>': str(exc)})<EOL><DEDENT>LOG.debug('<STR_LIT>', (<EOL>body))<EOL>
Process network create event from DCNM.