Example #1
0
    def _va_config_router_snat_rules(self, ri, plist):
        LOG.debug('_va_config_router_snat_rules: %s', ri.router['id'])

        prefix = va_utils.get_snat_rule_name(ri)
        self.rest.del_cfg_objs(va_utils.REST_URL_CONF_NAT_RULE, prefix)

        if not ri.enable_snat:
            return

        for idx, p in enumerate(ri.internal_ports):
            if p['admin_state_up']:
                dev = self.get_internal_device_name(p['id'])
                pif = self._va_get_port_name(plist, dev)
                if pif:
                    net = netaddr.IPNetwork(p['ip_cidr'])
                    body = {
                        'name': '%s_%d' % (prefix, idx),
                        'ingress-context-type': 'interface',
                        'ingress-index': self._va_pif_2_lif(pif),
                        'source-address': [
                            [str(netaddr.IPAddress(net.first + 2)),
                             str(netaddr.IPAddress(net.last - 1))]
                        ],
                        'flag': 'interface translate-source'
                    }
                    self.rest.rest_api('POST',
                                       va_utils.REST_URL_CONF_NAT_RULE,
                                       body)

        if ri.internal_ports:
            self.rest.commit()
    def _va_config_router_snat_rules(self, ri, plist):
        LOG.debug('_va_config_router_snat_rules: %s', ri.router['id'])

        prefix = va_utils.get_snat_rule_name(ri)
        self.rest.del_cfg_objs(va_utils.REST_URL_CONF_NAT_RULE, prefix)

        if not ri.enable_snat:
            return

        for idx, p in enumerate(ri.internal_ports):
            if p['admin_state_up']:
                dev = self.get_internal_device_name(p['id'])
                pif = self._va_get_port_name(plist, dev)
                if pif:
                    net = netaddr.IPNetwork(p['ip_cidr'])
                    body = {
                        'name':
                        '%s_%d' % (prefix, idx),
                        'ingress-context-type':
                        'interface',
                        'ingress-index':
                        self._va_pif_2_lif(pif),
                        'source-address': [[
                            str(netaddr.IPAddress(net.first + 2)),
                            str(netaddr.IPAddress(net.last - 1))
                        ]],
                        'flag':
                        'interface translate-source'
                    }
                    self.rest.rest_api('POST', va_utils.REST_URL_CONF_NAT_RULE,
                                       body)

        if ri.internal_ports:
            self.rest.commit()
    def test_agent_snat_enable(self):
        router = self._create_router()
        try:
            router.rest.auth()
        except Exception:
            # skip the test, firewall is not deployed
            return

        ri = self._prepare_router_data(enable_snat=True)
        router._router_added(ri.router['id'], ri.router)

        url = varmour_utils.REST_URL_CONF_NAT_RULE
        prefix = varmour_utils.get_snat_rule_name(ri)

        router.process_router(ri)
        n = router.rest.count_cfg_objs(url, prefix)
        self.assertEqual(n, 0, 'prefix %s' % prefix)

        ri.router['enable_snat'] = False
        router.process_router(ri)
        n = router.rest.count_cfg_objs(url, prefix)
        self.assertEqual(n, 0, 'prefix %s' % prefix)

        router._router_removed(ri.router['id'])
        n = router.rest.count_cfg_objs(url, prefix)
        self.assertEqual(n, 0, 'prefix %s' % prefix)
Example #4
0
    def _router_removed(self, router_id):
        LOG.debug("_router_removed: %s", router_id)

        ri = self.router_info[router_id]
        if ri:
            ri.router['gw_port'] = None
            ri.router[l3_constants.INTERFACE_KEY] = []
            ri.router[l3_constants.FLOATINGIP_KEY] = []
            self.process_router(ri)

            name = va_utils.get_snat_rule_name(ri)
            self.rest.del_cfg_objs(va_utils.REST_URL_CONF_NAT_RULE, name)

            name = va_utils.get_dnat_rule_name(ri)
            self.rest.del_cfg_objs(va_utils.REST_URL_CONF_NAT_RULE, name)

            name = va_utils.get_trusted_zone_name(ri)
            self._va_unset_zone_interfaces(name, True)

            name = va_utils.get_untrusted_zone_name(ri)
            self._va_unset_zone_interfaces(name, True)

            del self.router_info[router_id]
    def _router_removed(self, router_id):
        LOG.debug("_router_removed: %s", router_id)

        ri = self.router_info[router_id]
        if ri:
            ri.router['gw_port'] = None
            ri.router[l3_constants.INTERFACE_KEY] = []
            ri.router[l3_constants.FLOATINGIP_KEY] = []
            self.process_router(ri)

            name = va_utils.get_snat_rule_name(ri)
            self.rest.del_cfg_objs(va_utils.REST_URL_CONF_NAT_RULE, name)

            name = va_utils.get_dnat_rule_name(ri)
            self.rest.del_cfg_objs(va_utils.REST_URL_CONF_NAT_RULE, name)

            name = va_utils.get_trusted_zone_name(ri)
            self._va_unset_zone_interfaces(name, True)

            name = va_utils.get_untrusted_zone_name(ri)
            self._va_unset_zone_interfaces(name, True)

            del self.router_info[router_id]