self.ha_port = None
self.keepalived_manager = None
- def _verify_ha(self):
- # TODO(Carl) Remove when is_ha below is removed.
- if not self.is_ha:
- raise ValueError(_('Router %s is not a HA router') %
- self.router_id)
-
@property
def is_ha(self):
# TODO(Carl) Remove when refactoring to use sub-classes is complete.
@property
def ha_priority(self):
- self._verify_ha()
return self.router.get('priority', keepalived.HA_DEFAULT_PRIORITY)
@property
def ha_vr_id(self):
- self._verify_ha()
return self.router.get('ha_vr_id')
@property
def ha_state(self):
- self._verify_ha()
- ha_state_path = self.keepalived_manager._get_full_config_file_path(
+ ha_state_path = self.keepalived_manager.get_full_config_file_path(
'state')
try:
with open(ha_state_path, 'r') as f:
@ha_state.setter
def ha_state(self, new_state):
- self._verify_ha()
- ha_state_path = self.keepalived_manager._get_full_config_file_path(
+ ha_state_path = self.keepalived_manager.get_full_config_file_path(
'state')
try:
with open(ha_state_path, 'w') as f:
instance = self._get_keepalived_instance()
instance.remove_vips_vroutes_by_interface(interface)
- def _ha_get_existing_cidrs(self, interface_name):
+ def _get_cidrs_from_keepalived(self, interface_name):
instance = self._get_keepalived_instance()
return instance.get_existing_vip_ip_addresses(interface_name)
def get_router_cidrs(self, device):
- return set(self._ha_get_existing_cidrs(device.name))
+ return set(self._get_cidrs_from_keepalived(device.name))
def routes_updated(self):
new_routes = self.router['routes']
keepalived.KeepalivedVirtualRoute(
default_gw, gw_ip, interface_name))
- def _get_ipv6_lladdr(self, mac_addr):
- return '%s/64' % netaddr.EUI(mac_addr).ipv6_link_local()
-
def _should_delete_ipv6_lladdr(self, ipv6_lladdr):
"""Only the master should have any IP addresses configured.
Let keepalived manage IPv6 link local addresses, the same way we let
will only be present on the master.
"""
device = ip_lib.IPDevice(interface_name, namespace=self.ns_name)
- ipv6_lladdr = self._get_ipv6_lladdr(device.link.address)
+ ipv6_lladdr = ip_lib.get_ipv6_lladdr(device.link.address)
if self._should_delete_ipv6_lladdr(ipv6_lladdr):
device.addr.flush(n_consts.IP_VERSION_6)
conf_dir = os.path.join(confs_dir, self.resource_id)
return conf_dir
- def _get_full_config_file_path(self, filename, ensure_conf_dir=True):
+ def get_full_config_file_path(self, filename, ensure_conf_dir=True):
conf_dir = self.get_conf_dir()
if ensure_conf_dir:
utils.ensure_dir(conf_dir)
def _output_config_file(self):
config_str = self.config.get_config_str()
- config_path = self._get_full_config_file_path('keepalived.conf')
+ config_path = self.get_full_config_file_path('keepalived.conf')
utils.replace_file(config_path, config_str)
return config_path
def get_conf_on_disk(self):
- config_path = self._get_full_config_file_path('keepalived.conf')
+ config_path = self.get_full_config_file_path('keepalived.conf')
try:
with open(config_path) as conf:
return conf.read()
ha_device_name = router.get_ha_device_name(router.ha_port['id'])
ha_device_cidr = router.ha_port['ip_cidr']
external_port = router.get_ex_gw_port()
- ex_port_ipv6 = router._get_ipv6_lladdr(
- external_port['mac_address'])
+ ex_port_ipv6 = ip_lib.get_ipv6_lladdr(external_port['mac_address'])
external_device_name = router.get_external_device_name(
external_port['id'])
external_device_cidr = external_port['ip_cidr']
internal_port = router.router[l3_constants.INTERFACE_KEY][0]
- int_port_ipv6 = router._get_ipv6_lladdr(
- internal_port['mac_address'])
+ int_port_ipv6 = ip_lib.get_ipv6_lladdr(internal_port['mac_address'])
internal_device_name = router.get_internal_device_name(
internal_port['id'])
internal_device_cidr = internal_port['ip_cidr']