예제 #1
0
 private Optional<OpenstackPort> routerIfacePort(String osNetId) {
   // FIXME router interface is subnet specific, not network
   return openstackService
       .ports()
       .stream()
       .filter(
           p ->
               p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE)
                   && p.networkId().equals(osNetId))
       .findAny();
 }
예제 #2
0
 private Set<OpenstackSubnet> routableSubNets(String osRouterId) {
   return openstackService
       .ports()
       .stream()
       .filter(
           p ->
               p.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE)
                   && p.deviceId().equals(osRouterId))
       .map(p -> openstackService.subnet(p.fixedIps().keySet().stream().findFirst().get()))
       .collect(Collectors.toSet());
 }
예제 #3
0
  @Override
  public void updateRouter(OpenstackRouter osRouter) {
    if (osRouter.gatewayExternalInfo().externalFixedIps().size() > 0) {
      openstackService
          .ports()
          .stream()
          .filter(
              osPort ->
                  osPort.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE)
                      && osPort.deviceId().equals(osRouter.id()))
          .forEach(
              osPort -> {
                String subnetId = osPort.fixedIps().keySet().stream().findFirst().get();
                setExternalConnection(osRouter, subnetId);
              });

      log.info(
          "Connected external gateway {} to router {}",
          osRouter.gatewayExternalInfo().externalFixedIps(),
          osRouter.name());
    } else {
      openstackService
          .ports()
          .stream()
          .filter(
              osPort ->
                  osPort.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE)
                      && osPort.deviceId().equals(osRouter.id()))
          .forEach(
              osPort -> {
                String subnetId = osPort.fixedIps().keySet().stream().findFirst().get();
                OpenstackSubnet osSubNet = openstackService.subnet(subnetId);
                unsetExternalConnection(osRouter, osPort.networkId(), osSubNet.cidr());
              });

      log.info("Disconnected external gateway from router {}", osRouter.name());
    }
  }
예제 #4
0
  private void reloadRoutingRules() {
    eventExecutor.execute(
        () ->
            openstackService
                .ports()
                .stream()
                .filter(osPort -> osPort.deviceOwner().equals(DEVICE_OWNER_ROUTER_INTERFACE))
                .forEach(
                    osPort -> {
                      OpenstackRouter osRouter = openstackRouter(osPort.deviceId());

                      setGatewayIcmp(
                          Ip4Address.valueOf(
                              openstackService
                                  .subnet(osPort.fixedIps().keySet().stream().findAny().get())
                                  .gatewayIp()));

                      setRoutes(osRouter, Optional.empty());
                      if (osRouter.gatewayExternalInfo().externalFixedIps().size() > 0) {
                        String subnetId = osPort.fixedIps().keySet().stream().findFirst().get();
                        setExternalConnection(osRouter, subnetId);
                      }
                    }));
  }