コード例 #1
0
    def save_routes_data(self, ctx, form, data):
        def _save_additional_route_to_rdf(rdf_node, fda):
            uidatahelpers.create_rdf_route(rdf_node, fda['subnet'], fda['network_connection'], fda['gateway'], ns_ui.route)    
        
        def _save_ppp_firewall_rule_to_rdf(rdf_node, fda):
            if isinstance(fda['ip_subnet'], datatypes.IPv4Address):
                rdf_node.setS(ns_ui.ipAddress, rdf.IPv4Address, fda['ip_subnet'])
            elif isinstance(fda['ip_subnet'], datatypes.IPv4Subnet):
                rdf_node.setS(ns_ui.subnet, rdf.IPv4Subnet, fda['ip_subnet'])
            else:
                raise uidatahelpers.FormDataError('Firewall rule IP/subnet is neither IPv4Address nor IPv4Subnet')
                    
            if fda['protocol'] == 'any':
                pass
            else:
                rdf_node.setS(ns_ui.protocol, rdf.String, fda['protocol'])

            uidatahelpers.save_optional_field_to_rdf(rdf_node, ns_ui.port, rdf.Integer, fda, 'port')    

            rdf_node.setS(ns_ui.action, rdf.String, fda['action'])
            
        toplevel_fda = formalutils.FormDataAccessor(form, [], ctx)
        ui_root = helpers.get_new_ui_config()

        # Default route
        droute_fda = toplevel_fda.descend('dr_group') 
        uidatahelpers.create_rdf_route(ui_root, None, droute_fda['network_connection'], droute_fda['gateway'], ns_ui.defaultRoute)

        # Additional routes
        add_route_fda = toplevel_fda.descend('ar_group')
        uidatahelpers.save_dynamic_list_to_rdf(ui_root, ns_ui.routes, ns_ui.Route, add_route_fda, _save_additional_route_to_rdf)

        # Source routing (forced routing)
        source_fda = toplevel_fda.descend('sr_group')
        if source_fda['source_routing_selection'] == 'off':
            ui_root.removeNodes(ns_ui.sourceRouting)
        elif source_fda['source_routing_selection'] == 'on':
            uidatahelpers.create_rdf_route(ui_root, None, source_fda['network_connection'], source_fda['gateway'], ns_ui.sourceRouting)
        else:
            raise uidatahelpers.FormDataError('Forced routing is neither on nor off.')

        # PPP firewall rules
        fwrule_fda = toplevel_fda.descend('fwrule_group')
        uidatahelpers.save_dynamic_list_to_rdf(ui_root, ns_ui.pppFirewallRules, ns_ui.PppFirewallRule, fwrule_fda, _save_ppp_firewall_rule_to_rdf)
コード例 #2
0
 def _save_additional_route_to_rdf(rdf_node, fda):
     uidatahelpers.create_rdf_route(rdf_node, fda['subnet'], fda['network_connection'], fda['gateway'], ns_ui.route)    
コード例 #3
0
 def _save_additional_route_to_rdf(rdf_node, fda):
     uidatahelpers.create_rdf_route(rdf_node, fda['subnet'],
                                    fda['network_connection'],
                                    fda['gateway'], ns_ui.route)
コード例 #4
0
    def save_routes_data(self, ctx, form, data):
        def _save_additional_route_to_rdf(rdf_node, fda):
            uidatahelpers.create_rdf_route(rdf_node, fda['subnet'],
                                           fda['network_connection'],
                                           fda['gateway'], ns_ui.route)

        def _save_ppp_firewall_rule_to_rdf(rdf_node, fda):
            if isinstance(fda['ip_subnet'], datatypes.IPv4Address):
                rdf_node.setS(ns_ui.ipAddress, rdf.IPv4Address,
                              fda['ip_subnet'])
            elif isinstance(fda['ip_subnet'], datatypes.IPv4Subnet):
                rdf_node.setS(ns_ui.subnet, rdf.IPv4Subnet, fda['ip_subnet'])
            else:
                raise uidatahelpers.FormDataError(
                    'Firewall rule IP/subnet is neither IPv4Address nor IPv4Subnet'
                )

            if fda['protocol'] == 'any':
                pass
            else:
                rdf_node.setS(ns_ui.protocol, rdf.String, fda['protocol'])

            uidatahelpers.save_optional_field_to_rdf(rdf_node, ns_ui.port,
                                                     rdf.Integer, fda, 'port')

            rdf_node.setS(ns_ui.action, rdf.String, fda['action'])

        toplevel_fda = formalutils.FormDataAccessor(form, [], ctx)
        ui_root = helpers.get_new_ui_config()

        # Default route
        droute_fda = toplevel_fda.descend('dr_group')
        uidatahelpers.create_rdf_route(ui_root, None,
                                       droute_fda['network_connection'],
                                       droute_fda['gateway'],
                                       ns_ui.defaultRoute)

        # Additional routes
        add_route_fda = toplevel_fda.descend('ar_group')
        uidatahelpers.save_dynamic_list_to_rdf(ui_root, ns_ui.routes,
                                               ns_ui.Route, add_route_fda,
                                               _save_additional_route_to_rdf)

        # Source routing (forced routing)
        source_fda = toplevel_fda.descend('sr_group')
        if source_fda['source_routing_selection'] == 'off':
            ui_root.removeNodes(ns_ui.sourceRouting)
        elif source_fda['source_routing_selection'] == 'on':
            uidatahelpers.create_rdf_route(ui_root, None,
                                           source_fda['network_connection'],
                                           source_fda['gateway'],
                                           ns_ui.sourceRouting)
        else:
            raise uidatahelpers.FormDataError(
                'Forced routing is neither on nor off.')

        # PPP firewall rules
        fwrule_fda = toplevel_fda.descend('fwrule_group')
        uidatahelpers.save_dynamic_list_to_rdf(ui_root, ns_ui.pppFirewallRules,
                                               ns_ui.PppFirewallRule,
                                               fwrule_fda,
                                               _save_ppp_firewall_rule_to_rdf)