Set the current router to primary
(self)
| 303 | logging.info("Router switched to backup mode") |
| 304 | |
| 305 | def set_primary(self): |
| 306 | """ Set the current router to primary """ |
| 307 | if not self.cl.is_redundant(): |
| 308 | logging.error("Set primary called on non-redundant router") |
| 309 | return |
| 310 | |
| 311 | self.set_lock() |
| 312 | logging.debug("Setting router to primary") |
| 313 | |
| 314 | dev = '' |
| 315 | interfaces = [interface for interface in self.address.get_interfaces() if interface.is_public()] |
| 316 | route = CsRoute() |
| 317 | for interface in interfaces: |
| 318 | if dev == interface.get_device(): |
| 319 | continue |
| 320 | dev = interface.get_device() |
| 321 | logging.info("Will proceed configuring device ==> %s" % dev) |
| 322 | cmd = "ip link set %s up" % dev |
| 323 | if CsDevice(dev, self.config).waitfordevice(): |
| 324 | CsHelper.execute(cmd) |
| 325 | logging.info("Bringing public interface %s up" % dev) |
| 326 | |
| 327 | try: |
| 328 | gateway = interface.get_gateway() |
| 329 | logging.info("Adding gateway ==> %s to device ==> %s" % (gateway, dev)) |
| 330 | if dev == CsHelper.PUBLIC_INTERFACES[self.cl.get_type()]: |
| 331 | route.add_defaultroute(gateway) |
| 332 | except Exception: |
| 333 | logging.error("ERROR getting gateway from device %s" % dev) |
| 334 | if dev == CsHelper.PUBLIC_INTERFACES[self.cl.get_type()]: |
| 335 | try: |
| 336 | self._add_ipv6_to_interface(interface, interface.get_ip6()) |
| 337 | if interface.get_gateway6(): |
| 338 | route.add_defaultroute_v6(interface.get_gateway6()) |
| 339 | except Exception as e: |
| 340 | logging.error("ERROR adding IPv6, getting IPv6 gateway from device %s: %s" % (dev, e)) |
| 341 | else: |
| 342 | logging.error("Device %s was not ready could not bring it up" % dev) |
| 343 | |
| 344 | self._add_ipv6_guest_gateway() |
| 345 | |
| 346 | logging.debug("Configuring static routes") |
| 347 | static_routes = CsStaticRoutes("staticroutes", self.config) |
| 348 | static_routes.process() |
| 349 | |
| 350 | cmd = "%s -C %s" % (self.CONNTRACKD_BIN, self.CONNTRACKD_CONF) |
| 351 | CsHelper.execute("%s -c" % cmd) |
| 352 | CsHelper.execute("%s -f" % cmd) |
| 353 | CsHelper.execute("%s -R" % cmd) |
| 354 | CsHelper.execute("%s -B" % cmd) |
| 355 | CsHelper.service("ipsec", "restart") |
| 356 | CsHelper.service("xl2tpd", "restart") |
| 357 | |
| 358 | interfaces = [interface for interface in self.address.get_interfaces() if interface.needs_vrrp()] |
| 359 | for interface in interfaces: |
| 360 | if interface.is_added(): |
| 361 | CsPasswdSvc(interface.get_gateway() + "," + interface.get_ip()).restart() |
| 362 |
no test coverage detected