class ResourcesPushRpcApi(object):
    """Plugin-side RPC for plugin-to-agents interaction.

    This interface is designed to push versioned object updates to interested
    agents using fanout topics.

    This class implements the caller side of an rpc interface.  The receiver
    side can be found below: ResourcesPushRpcCallback.
    """

    # added by Huawei start
    # used to notify Controller that vm is migrating
    # and get the segment id from Controller
    def get_dynamic_segment(self, plugin, port_context, host):
        segment_dict = {}
        self._set_segment(plugin, port_context, host, segment_dict)
        return segment_dict.get('segment')
    # added by Huawei end

    # added by Huawei start
    # send the event of port_migration to huawei plugin,
    # notify Controller vm is migrating
    @staticmethod
    def _set_segment(plugin, port_context, host, segment_dict):
        # REVISIT(rawlin): add BridgeName as a nullable column to the Port
        # model and simply check here if it's set and insert it into the
        # vif_details.
        from neutron.callbacks import registry
        from neutron.callbacks import resources

        def set_segment_inner(segment):
            segment_dict['segment'] = segment

        port_migration_event = 'port_migration'
        registry.notify(
            resources.PORT, port_migration_event,
            set_segment_inner, plugin=plugin, port_context=port_context,
            host=host)
    # added by Huawei end

    def _push(self, context, resource_type, resource_list, event_type):
        """Push an event and list of resources of the same type to agents."""
        _validate_resource_type(resource_type)

        for version in version_manager.get_resource_versions(resource_type):
            cctxt = self._prepare_object_fanout_context(
                resource_list[0], version, rpc_version='1.1')

            # added by Huawei start
            import copy
            from neutron.objects import ports
            from neutron_lib.plugins import directory
            copied_list = copy.deepcopy(resource_list)
            if resource_type == ports.Port.obj_name():
                for resource in copied_list:
                    if not resource.binding_levels:
                        return

                    if "migrating_to" in resource.binding.profile and \
                            resource.binding_levels and \
                            resource.device_owner.startswith('compute:') and \
                            resource.binding.profile["migrating_to"] != \
                            resource.binding.host:
                        for binding_level in resource.binding_levels:
                            if binding_level.level > 0 and \
                                    binding_level.segment.network_type == 'vlan':
                                plugin = directory.get_plugin()
                                port_context = plugin.get_bound_port_context(
                                    context, resource.id)
                                segment = self.get_dynamic_segment(
                                    plugin, port_context,
                                    resource.binding.profile["migrating_to"])
                                binding_level.segment.segmentation_id = \
                                    segment['segmentation_id']

            dehydrated_resources = [
                resource.obj_to_primitive(target_version=version)
                for resource in copied_list]
            # added by Huawei end

            cctxt.cast(context, 'push',
                       resource_list=dehydrated_resources,
                       event_type=event_type)
