Exemplo n.º 1
0
def convert_security_group_rule_to_classifier(context, sgr, group):
    cl1 = cl2 = cl3 = cl4 = cl5 = None

    # Ethertype
    if validators.is_ethernetclassifier_valid(sgr, validators.SG_RULE_TYPE):
        cl1 = models.EthernetClassifier()
        cl1.ethertype = security_group_ethertype_to_ethertype_value(
            sgr['ethertype'])

    # protocol
    if validators.is_protocolclassifier_valid(sgr, validators.SG_RULE_TYPE):
        if cl1 and cl1.ethertype == constants.ETHERTYPE_IPV6:
            cl2 = models.Ipv6Classifier()
            cl2.next_header = sgr['protocol']
        else:
            cl2 = models.Ipv4Classifier()
            cl2.protocol = sgr['protocol']

    # remote ip
    if validators.is_ipclassifier_valid(sgr, validators.SG_RULE_TYPE):
        cl3 = models.IpClassifier()
        cl3.source_ip_prefix = sgr['remote_ip_prefix']

    # Ports
    if validators.is_transportclassifier_valid(sgr, validators.SG_RULE_TYPE):
        cl4 = models.TransportClassifier(
            destination_port_range_min=sgr['port_range_min'],
            destination_port_range_max=sgr['port_range_max'])

    # Direction
    if validators.is_directionclassifier_valid(sgr, validators.SG_RULE_TYPE):
        cl5 = models.DirectionClassifier(direction=sgr['direction'])

    classifiers = [cl1, cl2, cl3, cl4, cl5]
    create_classifier_chain(group, classifiers)
Exemplo n.º 2
0
def convert_firewall_rule_to_classifier(context, fwr, group):
    cl1 = cl2 = cl3 = cl4 = None

    # ip_version
    if validators.is_ethernetclassifier_valid(fwr, validators.FW_RULE_TYPE):
        cl1 = models.EthernetClassifier()
        cl1.ethertype = fwr['ip_version']

    # protocol
    if validators.is_protocolclassifier_valid(fwr, validators.FW_RULE_TYPE):
        if cl1.ethertype == constants.IP_VERSION_6:
            cl2 = models.Ipv6Classifier()
            cl2.next_header = fwr['protocol']
        else:
            cl2 = models.Ipv4Classifier()
            cl2.protocol = fwr['protocol']

    # Source and destination ip
    if validators.is_ipclassifier_valid(fwr, validators.FW_RULE_TYPE):
        cl3 = models.IpClassifier()
        cl3.source_ip_prefix = fwr['source_ip_address']
        cl3.destination_ip_prefix = fwr['destination_ip_address']

    # Ports
    if validators.is_transportclassifier_valid(fwr, validators.FW_RULE_TYPE):
        cl4 = models.TransportClassifier(
            source_port_range_min=fwr['source_port_range_min'],
            source_port_range_max=fwr['source_port_range_max'],
            destination_port_range_min=fwr['destination_port_range_min'],
            destination_port_range_max=fwr['destination_port_range_max'])

    classifiers = [cl1, cl2, cl3, cl4]
    create_classifier_chain(group, classifiers)