def create_network_postcommit(self, context): """Send network parameters to the VSM.""" network = context.current segment = context.network_segments[0] network_type = segment['network_type'] # NoOp for unsupported network types if not self._is_segment_valid_for_n1kv(segment['segmentation_id'], network_type): return session = context._plugin_context.session binding = n1kv_db.get_network_binding(network['id'], session) netp = n1kv_db.get_network_profile_by_uuid(binding.profile_id, session) network[providernet.SEGMENTATION_ID] = binding.segmentation_id try: self.n1kvclient.create_network_segment(network, netp) except (n1kv_exc.VSMError, n1kv_exc.VSMConnectionFailed): raise ml2_exc.MechanismDriverError() LOG.info( _LI("Create network(postcommit) succeeded for network: " "%(network_id)s of type: %(network_type)s with segment " "id: %(segment_id)s"), { "network_id": network['id'], "network_type": network_type, "segment_id": segment['segmentation_id'] })
def process_create_network(self, context, data, result): """Implementation of abstract method from ExtensionDriver class.""" net_id = result.get('id') prov_net_type = data.get(providernet.NETWORK_TYPE) net_prof_attr = data.get(constants.N1KV_PROFILE) tenant_id = context.tenant_id if not bc_attr.is_attr_set(net_prof_attr): if not bc_attr.is_attr_set(prov_net_type): network_type = cfg.CONF.ml2.tenant_network_types[0] else: network_type = prov_net_type if network_type == p_const.TYPE_VLAN: net_prof_attr = constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME elif network_type == p_const.TYPE_VXLAN: net_prof_attr = constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME else: # This network type is not supported with network profiles return with context.session.begin(subtransactions=True): try: if not uuidutils.is_uuid_like(net_prof_attr): net_prof_attr = n1kv_db.get_network_profile_by_name( net_prof_attr, context.session) else: net_prof_attr = n1kv_db.get_network_profile_by_uuid( net_prof_attr, context.session) n1kv_db.get_profile_binding(db_session=context.session, tenant_id=tenant_id, profile_id=net_prof_attr.id) except n1kv_exc.NetworkProfileNotFound: LOG.error(_LE("Network Profile %s does " "not exist.") % net_prof_attr) raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2') except n1kv_exc.ProfileTenantBindingNotFound: if (cfg.CONF.ml2_cisco_n1kv.restrict_network_profiles and net_prof_attr.name not in [ constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME, constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME]): LOG.error(_LE("Network Profile %s is " "not owned by this tenant.") % net_prof_attr.name) raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2') segment_type = net_prof_attr.segment_type n1kv_db.add_network_binding(net_id, segment_type, 0, net_prof_attr.id, context.session) data[providernet.NETWORK_TYPE] = segment_type result[constants.N1KV_PROFILE] = net_prof_attr.id
def process_create_network(self, context, data, result): """Implementation of abstract method from ExtensionDriver class.""" net_id = result.get('id') prov_net_type = data.get(bc.providernet.NETWORK_TYPE) net_prof_attr = data.get(constants.N1KV_PROFILE) tenant_id = context.tenant_id if not bc.is_attr_set(net_prof_attr): if not bc.is_attr_set(prov_net_type): network_type = cfg.CONF.ml2.tenant_network_types[0] else: network_type = prov_net_type if network_type == p_const.TYPE_VLAN: net_prof_attr = constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME elif network_type == p_const.TYPE_VXLAN: net_prof_attr = constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME else: # This network type is not supported with network profiles return with context.session.begin(subtransactions=True): try: if not uuidutils.is_uuid_like(net_prof_attr): net_prof_attr = n1kv_db.get_network_profile_by_name( net_prof_attr, context.session) else: net_prof_attr = n1kv_db.get_network_profile_by_uuid( net_prof_attr, context.session) n1kv_db.get_profile_binding(db_session=context.session, tenant_id=tenant_id, profile_id=net_prof_attr.id) except n1kv_exc.NetworkProfileNotFound: LOG.error("Network Profile %s does " "not exist." % net_prof_attr) raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2') except n1kv_exc.ProfileTenantBindingNotFound: if (cfg.CONF.ml2_cisco_n1kv.restrict_network_profiles and net_prof_attr.name not in [ constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME, constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME]): LOG.error("Network Profile %s is " "not owned by this tenant." % net_prof_attr.name) raise ml2_exc.ExtensionDriverError(driver='N1Kv ML2') segment_type = net_prof_attr.segment_type n1kv_db.add_network_binding(net_id, segment_type, 0, net_prof_attr.id, context.session) data[bc.providernet.NETWORK_TYPE] = segment_type result[constants.N1KV_PROFILE] = net_prof_attr.id
def _sync_bridge_domains(self, combined_res_info, vsm_ip): """ Sync bridge domains by creating/deleting them on the VSM. :param combined_res_info: a two tuple storing the list of VSM BDs and the list of neutron networks :param vsm_ip: IP of the VSM being synced """ # create missing BDs on VSM (vsm_bds, neutron_vxlan_nets) = combined_res_info need_bd_sync = False for network in neutron_vxlan_nets: bd_name = network['id'] + n1kv_const.BRIDGE_DOMAIN_SUFFIX if bd_name not in vsm_bds: binding = n1kv_db.get_network_binding(network['id']) netp = n1kv_db.get_network_profile_by_uuid(binding.profile_id) network[providernet.SEGMENTATION_ID] = binding.segmentation_id network[providernet.NETWORK_TYPE] = binding.network_type # create this BD on VSM try: self.n1kvclient.create_bridge_domain(network, netp, vsm_ip=vsm_ip) except (n1kv_exc.VSMConnectionFailed, n1kv_exc.VSMError): LOG.warning( _LW('Sync Exception: Bridge domain creation ' 'failed for %s.') % bd_name) need_bd_sync = True # delete extraneous BDs from VSM neutron_bds = { net_id + n1kv_const.BRIDGE_DOMAIN_SUFFIX for net_id in self._get_uuids(n1kv_const.NETWORKS, neutron_vxlan_nets) } for bd in vsm_bds - neutron_bds: try: # delete this BD from VSM self.n1kvclient.delete_bridge_domain(bd, vsm_ip=vsm_ip) except (n1kv_exc.VSMError, n1kv_exc.VSMConnectionFailed): LOG.warning( _LW('Sync Exception: Bridge domain deletion ' 'failed for %s.') % bd) need_bd_sync = True self.sync_bds[vsm_ip] = need_bd_sync
def _sync_bridge_domains(self, combined_res_info, vsm_ip): """ Sync bridge domains by creating/deleting them on the VSM. :param combined_res_info: a two tuple storing the list of VSM BDs and the list of neutron networks :param vsm_ip: IP of the VSM being synced """ # create missing BDs on VSM (vsm_bds, neutron_vxlan_nets) = combined_res_info need_bd_sync = False for network in neutron_vxlan_nets: bd_name = network['id'] + n1kv_const.BRIDGE_DOMAIN_SUFFIX if bd_name not in vsm_bds: binding = n1kv_db.get_network_binding(network['id']) netp = n1kv_db.get_network_profile_by_uuid(binding.profile_id) network[providernet.SEGMENTATION_ID] = binding.segmentation_id network[providernet.NETWORK_TYPE] = binding.network_type # create this BD on VSM try: self.n1kvclient.create_bridge_domain(network, netp, vsm_ip=vsm_ip) except(n1kv_exc.VSMConnectionFailed, n1kv_exc.VSMError): LOG.warning(_LW('Sync Exception: Bridge domain creation ' 'failed for %s.') % bd_name) need_bd_sync = True # delete extraneous BDs from VSM neutron_bds = {net_id + n1kv_const.BRIDGE_DOMAIN_SUFFIX for net_id in self._get_uuids(n1kv_const.NETWORKS, neutron_vxlan_nets)} for bd in vsm_bds - neutron_bds: try: # delete this BD from VSM self.n1kvclient.delete_bridge_domain(bd, vsm_ip=vsm_ip) except (n1kv_exc.VSMError, n1kv_exc.VSMConnectionFailed): LOG.warning(_LW('Sync Exception: Bridge domain deletion ' 'failed for %s.') % bd) need_bd_sync = True self.sync_bds[vsm_ip] = need_bd_sync
def process_create_network(self, context, data, result): """Implementation of abstract method from ExtensionDriver class.""" net_id = result.get('id') prov_net_type = data.get(providernet.NETWORK_TYPE) net_prof_attr = data.get(constants.N1KV_PROFILE) if not attributes.is_attr_set(net_prof_attr): if not attributes.is_attr_set(prov_net_type): network_type = cfg.CONF.ml2.tenant_network_types[0] else: network_type = prov_net_type if network_type == p_const.TYPE_VLAN: net_prof_attr = constants.DEFAULT_VLAN_NETWORK_PROFILE_NAME elif network_type == p_const.TYPE_VXLAN: net_prof_attr = constants.DEFAULT_VXLAN_NETWORK_PROFILE_NAME else: # This network type is not supported with network profiles return with context.session.begin(subtransactions=True): try: if not uuidutils.is_uuid_like(net_prof_attr): net_prof_attr = n1kv_db.get_network_profile_by_name( net_prof_attr, context.session) else: net_prof_attr = n1kv_db.get_network_profile_by_uuid( net_prof_attr, context.session) # TODO(sopatwar) Handle restrict_network_profiles = True # Add logic to check for network profile :: tenant binding except n1kv_exc.NetworkProfileNotFound: LOG.error(_LE("Network Profile %(profile)s does " "not exist."), {"profile": net_prof_attr}) raise ml2_exc.ExtensionDriverError() segment_type = net_prof_attr.segment_type n1kv_db.add_network_binding(net_id, segment_type, 0, net_prof_attr.id, context.session) data[providernet.NETWORK_TYPE] = segment_type result[constants.N1KV_PROFILE] = net_prof_attr.id
def create_network_postcommit(self, context): """Send network parameters to the VSM.""" network = context.current segment = context.network_segments[0] network_type = segment['network_type'] # NoOp for unsupported network types if not self._is_segment_valid_for_n1kv(segment['segmentation_id'], network_type): return session = context._plugin_context.session binding = n1kv_db.get_network_binding(network['id'], session) netp = n1kv_db.get_network_profile_by_uuid(binding.profile_id, session) network[providernet.SEGMENTATION_ID] = binding.segmentation_id try: self.n1kvclient.create_network_segment(network, netp) except(n1kv_exc.VSMError, n1kv_exc.VSMConnectionFailed): raise ml2_exc.MechanismDriverError() LOG.info(_LI("Create network(postcommit) succeeded for network: " "%(network_id)s of type: %(network_type)s with segment " "id: %(segment_id)s"), {"network_id": network['id'], "network_type": network_type, "segment_id": segment['segmentation_id']})