# Path: networking_sfc/services/sfc/drivers/ovs/rpc_topics.py
# AGENT = 'q-agent-notifier'
# SFC_PLUGIN = 'q-sfc-plugin'
# SFC_AGENT = 'q-sfc-agent'
# SFC_FLOW = 'q-sfc-flow'
# PORTFLOW = 'portflowrule'


from oslo_log import log as logging
from neutron_lib.agent import topics
from neutron_lib import rpc as n_rpc
from networking_sfc.services.sfc.drivers.ovs import rpc_topics as sfc_topics
import oslo_messaging


class SfcRpcCallback():
    """Sfc RPC server."""

    def __init__(self, driver):
        self.target = oslo_messaging.Target(version='1.0')
        self.driver = driver

    def get_flowrules_by_host_portid(self, context, **kwargs):
        host = kwargs.get('host')
        port_id = kwargs.get('port_id')
        LOG.debug('from port-chain service plugin')
        pcfrs = self.driver.get_flowrules_by_host_portid(
            context, host, port_id)
        LOG.debug('host: %s, port_id: %s', host, port_id)
        return pcfrs

    def update_flowrules_status(self, context, **kwargs):
        flowrules_status = kwargs.get('flowrules_status')
        LOG.info('update_flowrules_status: %s', flowrules_status)
        for flowrule_dict in flowrules_status:
            self.driver.update_flowrule_status(context,
                                               flowrule_dict['id'],
                                               flowrule_dict['status'])


class SfcAgentRpcClient():
    """RPC client for ovs sfc agent."""


# Path: networking_sfc/services/sfc/drivers/ovs/rpc_topics.py
# AGENT = 'q-agent-notifier'
# SFC_PLUGIN = 'q-sfc-plugin'
# SFC_AGENT = 'q-sfc-agent'
# SFC_FLOW = 'q-sfc-flow'
# PORTFLOW = 'portflowrule'


# Path: networking_sfc/services/sfc/drivers/ovs/rpc.py
from oslo_log import log as logging
from neutron_lib.agent import topics
from neutron_lib import rpc as n_rpc
from networking_sfc.services.sfc.drivers.ovs import rpc_topics as sfc_topics
import oslo_messaging



class SfcRpcCallback():
    """Sfc RPC server."""

    def __init__(self, driver):
        self.target = oslo_messaging.Target(version='1.0')
        self.driver = driver

    def get_flowrules_by_host_portid(self, context, **kwargs):
        host = kwargs.get('host')
        port_id = kwargs.get('port_id')
        LOG.debug('from port-chain service plugin')
        pcfrs = self.driver.get_flowrules_by_host_portid(
            context, host, port_id)
        LOG.debug('host: %s, port_id: %s', host, port_id)
        return pcfrs

    def update_flowrules_status(self, context, **kwargs):
        flowrules_status = kwargs.get('flowrules_status')
        LOG.info('update_flowrules_status: %s', flowrules_status)
        for flowrule_dict in flowrules_status:
            self.driver.update_flowrule_status(context,
                                               flowrule_dict['id'],
                                               flowrule_dict['status'])


class SfcAgentRpcClient():
    """RPC client for ovs sfc agent."""


    def __init__(self, topic=sfc_topics.SFC_AGENT):