class RouterInfo(object):
- def __init__(self, router_id, root_helper):
+ def __init__(self, router_id, root_helper, use_namespaces):
self.router_id = router_id
self.ex_gw_port = None
self.internal_ports = []
self.floating_ips = []
self.root_helper = root_helper
+ self.use_namespaces = use_namespaces
self.iptables_manager = iptables_manager.IptablesManager(
root_helper=root_helper,
namespace=self.ns_name())
def ns_name(self):
- return NS_PREFIX + self.router_id
+ if self.use_namespaces:
+ return NS_PREFIX + self.router_id
class L3NATAgent(object):
#FIXME(danwent): not currently used
cfg.BoolOpt('send_arp_for_ha',
default=True,
- help="Send gratuitious ARP when router IP is configured")
+ help="Send gratuitious ARP when router IP is configured"),
+ cfg.BoolOpt('use_namespaces', default=True,
+ help="Allow overlapping IP."),
+ cfg.StrOpt('router_id', default='',
+ help="If namespaces is disabled, the l3 agent can only"
+ " confgure a router that has the matching router ID.")
]
def __init__(self, conf):
elif d.name.startswith(EXTERNAL_DEV_PREFIX):
self.driver.unplug(d.name,
bridge=self.conf.external_network_bridge)
- ns_ip.netns.delete(namespace)
+ if self.conf.use_namespaces:
+ ns_ip.netns.delete(namespace)
def _create_router_namespace(self, ri):
ip_wrapper_root = ip_lib.IPWrapper(self.conf.root_helper)
for r in self.qclient.list_routers()['routers']:
#FIXME(danwent): handle admin state
- cur_router_ids.add(r['id'])
+ # If namespaces are disabled, only process the router associated
+ # with the configured agent id.
+ if (self.conf.use_namespaces or
+ r['id'] == self.conf.router_id):
+ cur_router_ids.add(r['id'])
+ else:
+ continue
if r['id'] not in self.router_info:
- self.router_info[r['id']] = RouterInfo(r['id'],
- self.conf.root_helper)
- self._create_router_namespace(self.router_info[r['id']])
+ self.router_info[r['id']] = RouterInfo(
+ r['id'], self.conf.root_helper, self.conf.use_namespaces)
+ if self.conf.use_namespaces:
+ self._create_router_namespace(self.router_info[r['id']])
ri = self.router_info[r['id']]
self.process_router(ri)
cmd = ['route', 'add', 'default', 'gw', gw_ip]
ip_wrapper = ip_lib.IPWrapper(self.conf.root_helper,
namespace=ri.ns_name())
- ip_wrapper.netns.execute(cmd)
+ if self.conf.use_namespaces:
+ ip_wrapper.netns.execute(cmd)
for (c, r) in self.external_gateway_filter_rules():
ri.iptables_manager.ipv4['filter'].add_rule(c, r)
def testRouterInfoCreate(self):
id = _uuid()
- ri = l3_agent.RouterInfo(id, self.conf.root_helper)
+ ri = l3_agent.RouterInfo(id, self.conf.root_helper,
+ self.conf.use_namespaces)
self.assertTrue(ri.ns_name().endswith(id))
port_id = _uuid()
router_id = _uuid()
network_id = _uuid()
- ri = l3_agent.RouterInfo(router_id, self.conf.root_helper)
+ ri = l3_agent.RouterInfo(router_id, self.conf.root_helper,
+ self.conf.use_namespaces)
agent = l3_agent.L3NATAgent(self.conf)
interface_name = agent.get_internal_device_name(port_id)
cidr = '99.0.1.9/24'
def _test_external_gateway_action(self, action):
router_id = _uuid()
- ri = l3_agent.RouterInfo(router_id, self.conf.root_helper)
+ ri = l3_agent.RouterInfo(router_id, self.conf.root_helper,
+ self.conf.use_namespaces)
agent = l3_agent.L3NATAgent(self.conf)
internal_cidrs = ['100.0.1.0/24', '200.74.0.0/16']
ex_gw_port = {'fixed_ips': [{'ip_address': '20.0.0.30',
def _test_floating_ip_action(self, action):
router_id = _uuid()
- ri = l3_agent.RouterInfo(router_id, self.conf.root_helper)
+ ri = l3_agent.RouterInfo(router_id, self.conf.root_helper,
+ self.conf.use_namespaces)
agent = l3_agent.L3NATAgent(self.conf)
floating_ip = '20.0.0.100'
fixed_ip = '10.0.0.23'
agent = l3_agent.L3NATAgent(self.conf)
router_id = _uuid()
- ri = l3_agent.RouterInfo(router_id, self.conf.root_helper)
+ ri = l3_agent.RouterInfo(router_id, self.conf.root_helper,
+ self.conf.use_namespaces)
# return data so that state is built up
ex_gw_port = {'id': _uuid(),