# Path: networking_odl/common/constants.py
# ODL_NETWORK = 'network'
# ODL_NETWORKS = 'networks'
# ODL_SUBNET = 'subnet'
# ODL_SUBNETS = 'subnets'
# ODL_PORT = 'port'
# ODL_PORTS = 'ports'
# ODL_SG = 'security_group'
# ODL_SGS = 'security_groups'
# ODL_SG_RULE = 'security_group_rule'
# ODL_SG_RULES = 'security_group_rules'
# ODL_ROUTER = 'router'
# ODL_ROUTERS = 'routers'
# ODL_FLOATINGIP = 'floatingip'
# ODL_FLOATINGIPS = 'floatingips'
# ODL_QOS = 'qos'
# ODL_QOS_POLICY = 'policy'
# ODL_QOS_POLICIES = 'policies'
# ODL_SFC = 'sfc'
# ODL_SFC_FLOW_CLASSIFIER = 'flowclassifier'
# ODL_SFC_FLOW_CLASSIFIERS = 'flowclassifiers'
# ODL_SFC_PORT_PAIR = 'portpair'
# ODL_SFC_PORT_PAIRS = 'portpairs'
# ODL_SFC_PORT_PAIR_GROUP = 'portpairgroup'
# ODL_SFC_PORT_PAIR_GROUPS = 'portpairgroups'
# ODL_SFC_PORT_CHAIN = 'portchain'
# ODL_SFC_PORT_CHAINS = 'portchains'
# NETWORKING_SFC_FLOW_CLASSIFIER = 'flow_classifier'
# NETWORKING_SFC_FLOW_CLASSIFIERS = 'flow_classifiers'
# NETWORKING_SFC_PORT_PAIR = 'port_pair'
# NETWORKING_SFC_PORT_PAIRS = 'port_pairs'
# NETWORKING_SFC_PORT_PAIR_GROUP = 'port_pair_group'
# NETWORKING_SFC_PORT_PAIR_GROUPS = 'port_pair_groups'
# NETWORKING_SFC_PORT_CHAIN = 'port_chain'
# NETWORKING_SFC_PORT_CHAINS = 'port_chains'
# ODL_TRUNK = 'trunk'
# ODL_TRUNKS = 'trunks'
# ODL_L2GATEWAY = 'l2_gateway'
# ODL_L2GATEWAYS = 'l2_gateways'
# ODL_L2GATEWAY_CONNECTION = 'l2gateway_connection'
# ODL_L2GATEWAY_CONNECTIONS = 'l2_gateway_connections'
# ODL_BGPVPN = 'bgpvpn'
# ODL_BGPVPNS = 'bgpvpns'
# ODL_BGPVPN_NETWORK_ASSOCIATION = 'bgpvpn_network_association'
# ODL_BGPVPN_NETWORK_ASSOCIATIONS = 'bgpvpn_network_associations'
# ODL_BGPVPN_ROUTER_ASSOCIATION = 'bgpvpn_router_association'
# ODL_BGPVPN_ROUTER_ASSOCIATIONS = 'bgpvpn_router_associations'
# ODL_ML2_MECH_DRIVER_V2 = "opendaylight_v2"
# ODL_DEVICE_ID_START = 'OpenDaylight'
# ODL_CREATE = 'create'
# ODL_UPDATE = 'update'
# ODL_DELETE = 'delete'
# PENDING = 'pending'
# PROCESSING = 'processing'
# FAILED = 'failed'
# COMPLETED = 'completed'
# BEFORE_COMPLETE = 'before_complete'
# AFTER_DELETE = 'after_delete'
# RESOURCE_URL_MAPPINGS = {
#     ODL_QOS_POLICY: "%s/%s" % (ODL_QOS, ODL_QOS_POLICIES),
#     ODL_SFC_FLOW_CLASSIFIER: "%s/%s" % (ODL_SFC, ODL_SFC_FLOW_CLASSIFIERS),
#     ODL_SFC_PORT_CHAIN: "%s/%s" % (ODL_SFC, ODL_SFC_PORT_CHAINS),
#     ODL_SFC_PORT_PAIR: "%s/%s" % (ODL_SFC, ODL_SFC_PORT_PAIRS),
#     ODL_SFC_PORT_PAIR_GROUP: "%s/%s" % (ODL_SFC, ODL_SFC_PORT_PAIR_GROUPS)
# }
# 
# Path: networking_odl/common/utils.py
# def try_del(d, keys):
# def make_url_object(object_type):
# def neutronify(name):
# def get_odl_url(path=''):


from neutron_lib import constants as n_const
from oslo_log import log
from oslo_serialization import jsonutils
from networking_odl.common import constants as odl_const
from networking_odl.common import utils as odl_utils
    #   Null-value for an unmapped element causes next mapped
    #   collection to contain a null value
    #   JSON: { "unmappedField": null, "mappedCollection": [ "a" ] }
    #
    #   Java Object:
    #   class Root {
    #     Collection<String> mappedCollection = new ArrayList<String>;
    #   }
    #
    #   Result:
    #   Field B contains one element; null
    #
    # TODO(yamahata): update along side with neutron and ODL
    #   add when neutron adds more extensions
    #   delete when ODL neutron northbound supports it
    # TODO(yamahata): do same thing for other resources
    keys_to_del = [key for key in unmapped_keys
                   if resource_dict.get(key) is None]
    if keys_to_del:
        odl_utils.try_del(resource_dict, keys_to_del)


_NETWORK_UNMAPPED_KEYS = ['qos_policy_id']
_SUBNET_UNMAPPED_KEYS = ['segment_id', 'subnetpool_id']
_PORT_UNMAPPED_KEYS = ['binding:profile', 'dns_name',
                       'port_security_enabled', 'qos_policy_id']
_FIP_UNMAPPED_KEYS = ['port_id', 'fixed_ip_address', 'router_id']


def _filter_network_create(network):

# Path: networking_odl/common/constants.py
# ODL_NETWORK = 'network'
# ODL_NETWORKS = 'networks'
# ODL_SUBNET = 'subnet'
# ODL_SUBNETS = 'subnets'
# ODL_PORT = 'port'
# ODL_PORTS = 'ports'
# ODL_SG = 'security_group'
# ODL_SGS = 'security_groups'
# ODL_SG_RULE = 'security_group_rule'
# ODL_SG_RULES = 'security_group_rules'
# ODL_ROUTER = 'router'
# ODL_ROUTERS = 'routers'
# ODL_FLOATINGIP = 'floatingip'
# ODL_FLOATINGIPS = 'floatingips'
# ODL_QOS = 'qos'
# ODL_QOS_POLICY = 'policy'
# ODL_QOS_POLICIES = 'policies'
# ODL_SFC = 'sfc'
# ODL_SFC_FLOW_CLASSIFIER = 'flowclassifier'
# ODL_SFC_FLOW_CLASSIFIERS = 'flowclassifiers'
# ODL_SFC_PORT_PAIR = 'portpair'
# ODL_SFC_PORT_PAIRS = 'portpairs'
# ODL_SFC_PORT_PAIR_GROUP = 'portpairgroup'
# ODL_SFC_PORT_PAIR_GROUPS = 'portpairgroups'
# ODL_SFC_PORT_CHAIN = 'portchain'
# ODL_SFC_PORT_CHAINS = 'portchains'
# NETWORKING_SFC_FLOW_CLASSIFIER = 'flow_classifier'
# NETWORKING_SFC_FLOW_CLASSIFIERS = 'flow_classifiers'
# NETWORKING_SFC_PORT_PAIR = 'port_pair'
# NETWORKING_SFC_PORT_PAIRS = 'port_pairs'
# NETWORKING_SFC_PORT_PAIR_GROUP = 'port_pair_group'
# NETWORKING_SFC_PORT_PAIR_GROUPS = 'port_pair_groups'
# NETWORKING_SFC_PORT_CHAIN = 'port_chain'
# NETWORKING_SFC_PORT_CHAINS = 'port_chains'
# ODL_TRUNK = 'trunk'
# ODL_TRUNKS = 'trunks'
# ODL_L2GATEWAY = 'l2_gateway'
# ODL_L2GATEWAYS = 'l2_gateways'
# ODL_L2GATEWAY_CONNECTION = 'l2gateway_connection'
# ODL_L2GATEWAY_CONNECTIONS = 'l2_gateway_connections'
# ODL_BGPVPN = 'bgpvpn'
# ODL_BGPVPNS = 'bgpvpns'
# ODL_BGPVPN_NETWORK_ASSOCIATION = 'bgpvpn_network_association'
# ODL_BGPVPN_NETWORK_ASSOCIATIONS = 'bgpvpn_network_associations'
# ODL_BGPVPN_ROUTER_ASSOCIATION = 'bgpvpn_router_association'
# ODL_BGPVPN_ROUTER_ASSOCIATIONS = 'bgpvpn_router_associations'
# ODL_ML2_MECH_DRIVER_V2 = "opendaylight_v2"
# ODL_DEVICE_ID_START = 'OpenDaylight'
# ODL_CREATE = 'create'
# ODL_UPDATE = 'update'
# ODL_DELETE = 'delete'
# PENDING = 'pending'
# PROCESSING = 'processing'
# FAILED = 'failed'
# COMPLETED = 'completed'
# BEFORE_COMPLETE = 'before_complete'
# AFTER_DELETE = 'after_delete'
# RESOURCE_URL_MAPPINGS = {
#     ODL_QOS_POLICY: "%s/%s" % (ODL_QOS, ODL_QOS_POLICIES),
#     ODL_SFC_FLOW_CLASSIFIER: "%s/%s" % (ODL_SFC, ODL_SFC_FLOW_CLASSIFIERS),
#     ODL_SFC_PORT_CHAIN: "%s/%s" % (ODL_SFC, ODL_SFC_PORT_CHAINS),
#     ODL_SFC_PORT_PAIR: "%s/%s" % (ODL_SFC, ODL_SFC_PORT_PAIRS),
#     ODL_SFC_PORT_PAIR_GROUP: "%s/%s" % (ODL_SFC, ODL_SFC_PORT_PAIR_GROUPS)
# }
# 
# Path: networking_odl/common/utils.py
# def try_del(d, keys):
# def make_url_object(object_type):
# def neutronify(name):
# def get_odl_url(path=''):


# Path: networking_odl/common/filters.py
from neutron_lib import constants as n_const
from oslo_log import log
from oslo_serialization import jsonutils
from networking_odl.common import constants as odl_const
from networking_odl.common import utils as odl_utils

    #   Null-value for an unmapped element causes next mapped
    #   collection to contain a null value
    #   JSON: { "unmappedField": null, "mappedCollection": [ "a" ] }
    #
    #   Java Object:
    #   class Root {
    #     Collection<String> mappedCollection = new ArrayList<String>;
    #   }
    #
    #   Result:
    #   Field B contains one element; null
    #
    # TODO(yamahata): update along side with neutron and ODL
    #   add when neutron adds more extensions
    #   delete when ODL neutron northbound supports it
    # TODO(yamahata): do same thing for other resources
    keys_to_del = [key for key in unmapped_keys
                   if resource_dict.get(key) is None]
    if keys_to_del:
        odl_utils.try_del(resource_dict, keys_to_del)


_NETWORK_UNMAPPED_KEYS = ['qos_policy_id']
_SUBNET_UNMAPPED_KEYS = ['segment_id', 'subnetpool_id']
_PORT_UNMAPPED_KEYS = ['binding:profile', 'dns_name',
                       'port_security_enabled', 'qos_policy_id']
_FIP_UNMAPPED_KEYS = ['port_id', 'fixed_ip_address', 'router_id']


def _filter_network_create(network):

    odl_utils.try_del(network, ['status', 'subnets'])