def _va_config_floating_ips(self, ri): LOG.debug(_('_va_config_floating_ips: %s'), ri.router['id']) prefix = va_utils.get_dnat_rule_name(ri) self.rest.del_cfg_objs(va_utils.REST_URL_CONF_NAT_RULE, prefix) # add new dnat rules for idx, fip in enumerate(ri.floating_ips): body = { 'name': '%s_%d' % (prefix, idx), 'ingress-context-type': 'zone', 'ingress-index': va_utils.get_untrusted_zone_name(ri), 'destination-address': [[fip['floating_ip_address'], fip['floating_ip_address']]], 'static': [fip['fixed_ip_address'], fip['fixed_ip_address']], 'flag': 'translate-destination' } self.rest.rest_api('POST', va_utils.REST_URL_CONF_NAT_RULE, body) if ri.floating_ips: self.rest.commit()
def test_agent_remove_floating_ips(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) self._add_internal_ports(ri.router, port_count=1) self._add_floating_ips(ri.router, port_count=2) router._router_added(ri.router['id'], ri.router) url = varmour_utils.REST_URL_CONF_NAT_RULE prefix = varmour_utils.get_dnat_rule_name(ri) router.process_router(ri) n = router.rest.count_cfg_objs(url, prefix) self.assertEqual(n, 2, 'prefix %s' % prefix) self._del_floating_ips(ri.router, 0) router.process_router(ri) n = router.rest.count_cfg_objs(url, prefix) self.assertEqual(n, 1, 'prefix %s' % prefix) self._del_all_floating_ips(ri.router) 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)
def _va_config_floating_ips(self, ri): LOG.debug(_("_va_config_floating_ips: %s"), ri.router["id"]) prefix = va_utils.get_dnat_rule_name(ri) self.rest.del_cfg_objs(va_utils.REST_URL_CONF_NAT_RULE, prefix) # add new dnat rules for idx, fip in enumerate(ri.floating_ips): body = { "name": "%s_%d" % (prefix, idx), "ingress-context-type": "zone", "ingress-index": va_utils.get_untrusted_zone_name(ri), "destination-address": [[fip["floating_ip_address"], fip["floating_ip_address"]]], "static": [fip["fixed_ip_address"], fip["fixed_ip_address"]], "flag": "translate-destination", } self.rest.rest_api("POST", va_utils.REST_URL_CONF_NAT_RULE, body) if ri.floating_ips: self.rest.commit()
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]