'Function to return the FIP Agent GW port.
This function will create a FIP Agent GW port
if required. If the port already exists, it
will return the existing port and will not
create a new one.'

def create_fip_agent_gw_port_if_not_exists(self, context, network_id, host):

    l3_agent_db = self._get_agent_by_type_and_host(context, const.AGENT_TYPE_L3, host)
    if l3_agent_db:
        LOG.debug('Agent    ID    exists:    %s', l3_agent_db['id'])
        f_port = self._get_agent_gw_ports_exist_for_network(context, network_id, host, l3_agent_db['id'])
        if (not f_port):
            LOG.info(_LI('Agent    Gateway    port    does    not    exist,    so    create    one:    %s'), f_port)
            port_data = {'tenant_id': '', 'network_id': network_id, 'device_id': l3_agent_db['id'], 'device_owner': const.DEVICE_OWNER_AGENT_GW, portbindings.HOST_ID: host, 'admin_state_up': True, 'name': ''}
            agent_port = p_utils.create_port(self._core_plugin, context, {'port': port_data})
            if agent_port:
                self._populate_mtu_and_subnets_for_ports(context, [agent_port])
                return agent_port
            msg = _('Unable    to    create    the    Agent    Gateway    Port')
            raise n_exc.BadRequest(resource='router', msg=msg)
        else:
            self._populate_mtu_and_subnets_for_ports(context, [f_port])
            return f_port
