Exemplo n.º 1
0
  @Override
  public long getEntityOwnerId() {
    VirtualRouter router = _entityMgr.findById(VirtualRouter.class, getId());
    if (router != null) {
      return router.getAccountId();
    }

    return Account
        .ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events
                            // are tracked
  }
  private Boolean testUserVM(VirtualMachine vm, Nic nic, VirtualRouter router) {
    String privateIp = nic.getIp4Address();
    String routerPrivateIp = router.getPrivateIpAddress();

    List<Long> otherHosts = new ArrayList<Long>();
    if (vm.getHypervisorType() == HypervisorType.XenServer
        || vm.getHypervisorType() == HypervisorType.KVM) {
      otherHosts.add(router.getHostId());
    } else {
      otherHosts = findHostByPod(router.getPodIdToDeployIn(), null);
    }
    for (Long hostId : otherHosts) {
      try {
        Answer pingTestAnswer =
            _agentMgr.easySend(hostId, new PingTestCommand(routerPrivateIp, privateIp));
        if (pingTestAnswer != null && pingTestAnswer.getResult()) {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug(
                "user vm's "
                    + vm.getHostName()
                    + " ip address "
                    + privateIp
                    + "  has been successfully pinged from the Virtual Router "
                    + router.getHostName()
                    + ", returning that vm is alive");
          }
          return Boolean.TRUE;
        }
      } catch (Exception e) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("Couldn't reach due to", e);
        }
        continue;
      }
    }
    if (s_logger.isDebugEnabled()) {
      s_logger.debug(vm + " could not be pinged, returning that it is unknown");
    }
    return null;
  }
Exemplo n.º 3
0
 @Override
 @DB
 public void addRouterToGuestNetwork(VirtualRouter router, Network guestNetwork) {
   if (_routerNetworkDao.findByRouterAndNetwork(router.getId(), guestNetwork.getId()) == null) {
     NetworkOffering off = _offDao.findById(guestNetwork.getNetworkOfferingId());
     if (!(off.getName().equalsIgnoreCase(NetworkOffering.SystemPrivateGatewayNetworkOffering))) {
       TransactionLegacy txn = TransactionLegacy.currentTxn();
       txn.start();
       // 1) add router to network
       RouterNetworkVO routerNtwkMap =
           new RouterNetworkVO(router.getId(), guestNetwork.getId(), guestNetwork.getGuestType());
       _routerNetworkDao.persist(routerNtwkMap);
       // 2) create user stats entry for the network
       UserStatisticsVO stats =
           _userStatsDao.findBy(
               router.getAccountId(),
               router.getDataCenterId(),
               guestNetwork.getId(),
               null,
               router.getId(),
               router.getType().toString());
       if (stats == null) {
         stats =
             new UserStatisticsVO(
                 router.getAccountId(),
                 router.getDataCenterId(),
                 null,
                 router.getId(),
                 router.getType().toString(),
                 guestNetwork.getId());
         _userStatsDao.persist(stats);
       }
       txn.commit();
     }
   }
 }
  @Override
  public boolean applyStaticRoutes(
      final List<StaticRouteProfile> staticRoutes, final List<DomainRouterVO> routers)
      throws ResourceUnavailableException {

    s_logger.debug("APPLYING STATIC ROUTES RULES");

    if (staticRoutes == null || staticRoutes.isEmpty()) {
      s_logger.debug("No static routes to apply");
      return true;
    }

    final StaticRoutesRules routesRules = new StaticRoutesRules(staticRoutes);

    boolean result = true;
    for (final VirtualRouter router : routers) {
      if (router.getState() == State.Running) {

        result = result && routesRules.accept(_advancedVisitor, router);

      } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug(
            "Router "
                + router.getInstanceName()
                + " is in "
                + router.getState()
                + ", so not sending StaticRoute command to the backend");
      } else {
        s_logger.warn(
            "Unable to apply StaticRoute, virtual router is not in the right state "
                + router.getState());

        throw new ResourceUnavailableException(
            "Unable to apply StaticRoute on the backend,"
                + " virtual router is not in the right state",
            DataCenter.class,
            router.getDataCenterId());
      }
    }
    return result;
  }