class FirewallRuleInfoMissing(nexception.InvalidInput):
    message = _("Missing rule info argument for insert/remove "
                "rule operation.")
# A new class added by Huawei starts.
# used to notify indicate attributes conflicts
class FirewallRulePropertyConflict(nexception.InvalidInput):
    message = _("%(param)s cannot exist at the same time.")
# A new class added by Huawei ends.

# A new class added by Huawei starts.
# used to verify the legal value of Port
class FirewallRuleInvalidPortValue(nexception.InvalidInput):
    message = _("Invalid value for port %(port)s.")
# A new class added by Huawei ends.

# A new class added by Huawei starts.
# used to notify ports exceeds the maximum range
class FirewallRulePortsLengthMax(nexception.InvalidInput):
    message = _("The number of %(param)s-ports exceeds the maximum size 15.")
# A new class added by Huawei ends.

# A new class added by Huawei starts.  
# used to notify ipAddresses exceeds the maximum range
class FirewallRuleIpAddressLengthMax(nexception.InvalidInput):
    message = _("The number of %(param)s ip addresses exceeds the maximum size 800.")
# A new class added by Huawei ends.

# A new class added by Huawei starts.  
# used to notify the same ip address exists in ipAddresses
class FirewallRuleIpAddressDuplicate(nexception.InvalidInput):
    message = _("The same ip address exists in %(param)s.")
# A new class added by Huawei ends.

# A new class added by Huawei starts.  
# used to notify ip addresses do not agree with IP Version
class FirewallIpAddressConflict(nexception.InvalidInput):
    message = _("Invalid input - IP addresses do not agree with IP Version")
# A new class added by Huawei ends.

# A new  method added by Huawei starts.
# used to determine the scope of the ports.
def _validate_ports_range(data, key_specs=None):
    if data is None:
        return
    data = str(data)
    ports = data.split(',')
    for port in ports:
        msg = _validate_port_range(port)
        if msg is not None:
            return msg
# A new  method added by Huawei ends.
        
# A new  method added by Huawei starts.
# used to determine the ip addresses
def _validate_ips_or_subnets_or_none(data, key_specs=None):
    if data is None:
        return
    data = str(data)
    ips = data.split(',')
    for ip in ips:
        msg = _validate_ip_or_subnet_or_none(ip)
        
    if msg is not None:
        return msg
# A new method added by Huawei ends.

attr.validators['type:port_range'] = _validate_port_range
attr.validators['type:ip_or_subnet_or_none'] = _validate_ip_or_subnet_or_none

#New code block added by huawei starts.
#Adding prescription method to Parameters
attr.validators['type:ips_or_subnets_or_none'] = _validate_ips_or_subnets_or_none
attr.validators['type:ports_range'] = _validate_ports_range
#New code block added by huawei ends.



RESOURCE_ATTRIBUTE_MAP = {
    'firewall_rules': {
        #New code block added by huawei starts.    
        #Add four parameters to Firewall_rules.
        'source_ip_addresses': {'allow_post': True, 'allow_put': True,
                              'validate': {'type:ips_or_subnets_or_none': None},
                              'is_visible': True, 'default': None},
        'destination_ip_addresses': {'allow_post': True, 'allow_put': True,
                                   'validate': {'type:ips_or_subnets_or_none':
                                                None},
                                   'is_visible': True, 'default': None},
        'source_ports': {'allow_post': True, 'allow_put': True,
                        'validate': {'type:ports_range': None},
                        'convert_to': convert_port_to_string,
                        'default': None, 'is_visible': True},
        'destination_ports': {'allow_post': True, 'allow_put': True,
                             'validate': {'type:ports_range': None},
                             'convert_to': convert_port_to_string,
                             'default': None, 'is_visible': True},
        #New code block added by huawei ends.