/** @param network */
  private void mockDAOs(final NetworkVO network, final NetworkOfferingVO offering) {
    when(_networkDao.acquireInLockTable(
            network.getId(), NetworkOrchestrationService.NetworkLockTimeout.value()))
        .thenReturn(network);
    when(_networksDao.acquireInLockTable(
            network.getId(), NetworkOrchestrationService.NetworkLockTimeout.value()))
        .thenReturn(network);
    when(_physicalProviderDao.findByServiceProvider(0L, "VirtualRouter"))
        .thenReturn(new PhysicalNetworkServiceProviderVO());
    when(_vrProviderDao.findByNspIdAndType(0L, Type.VirtualRouter))
        .thenReturn(new VirtualRouterProviderVO());
    when(_networkOfferingDao.findById(0L)).thenReturn(offering);
    // watchit: (in this test) there can be only one
    when(_routerDao.getNextInSequence(Long.class, "id")).thenReturn(0L);
    final ServiceOfferingVO svcoff =
        new ServiceOfferingVO(
            "name",
            /* cpu */ 1,
            /* ramsize */ 1024 * 1024,
            /* (clock?)speed */ 1024 * 1024 * 1024,
            /* rateMbps */ 1,
            /* multicastRateMbps */ 0,
            /* offerHA */ false,
            "displayText",
            ProvisioningType.THIN,
            /* useLocalStorage */ false,
            /* recreatable */ false,
            "tags",
            /* systemUse */ false,
            VirtualMachine.Type.DomainRouter,
            /* defaultUse */ false);
    when(_serviceOfferingDao.findById(0L)).thenReturn(svcoff);
    final DomainRouterVO router =
        new DomainRouterVO(
            /* id */ 1L,
            /* serviceOfferingId */ 1L,
            /* elementId */ 0L,
            "name",
            /* templateId */ 0L,
            HypervisorType.XenServer,
            /* guestOSId */ 0L,
            /* domainId */ 0L,
            /* accountId */ 1L,
            /* userId */ 1L,
            /* isRedundantRouter */ false,
            RedundantState.UNKNOWN,
            /* haEnabled */ false,
            /* stopPending */ false,
            /* vpcId */ null);

    when(_routerDao.getNextInSequence(Long.class, "id")).thenReturn(1L);
    when(_templateDao.findRoutingTemplate(
            HypervisorType.XenServer, "SystemVM Template (XenServer)"))
        .thenReturn(new VMTemplateVO());
    when(_routerDao.persist(any(DomainRouterVO.class))).thenReturn(router);
    when(_routerDao.findById(router.getId())).thenReturn(router);
  }
 /**
  * @param networks
  * @param offerings
  * @throws ConcurrentOperationException
  */
 private void mockMgrs() throws ConcurrentOperationException {
   final Service service = Service.Connectivity;
   testNetwork.setState(Network.State.Implementing);
   testNetwork.setTrafficType(TrafficType.Guest);
   when(_networkMdl.isProviderEnabledInPhysicalNetwork(0L, "VirtualRouter")).thenReturn(true);
   when(_networkMdl.isProviderSupportServiceInNetwork(
           testNetwork.getId(), service, Network.Provider.VirtualRouter))
       .thenReturn(true);
   when(_networkMdl.isProviderForNetwork(Network.Provider.VirtualRouter, 0L)).thenReturn(true);
   when(testVMProfile.getType()).thenReturn(VirtualMachine.Type.User);
   when(testVMProfile.getHypervisorType()).thenReturn(HypervisorType.XenServer);
   final List<NetworkVO> networks = new ArrayList<NetworkVO>(1);
   networks.add(testNetwork);
   final List<NetworkOfferingVO> offerings = new ArrayList<NetworkOfferingVO>(1);
   offerings.add(testOffering);
   doReturn(offerings)
       .when(_networkModel)
       .getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
   doReturn(networks)
       .when(_networkMgr)
       .setupNetwork(
           any(Account.class),
           any(NetworkOffering.class),
           any(DeploymentPlan.class),
           any(String.class),
           any(String.class),
           anyBoolean());
   // being anti-social and testing my own case first
   doReturn(HypervisorType.XenServer).when(_resourceMgr).getDefaultHypervisor(anyLong());
   doReturn(new AccountVO()).when(_accountMgr).getAccount(testNetwork.getAccountId());
 }
Ejemplo n.º 3
0
  @Override
  public boolean replaceNetworkACL(NetworkACL acl, NetworkVO network)
      throws ResourceUnavailableException {

    NetworkOffering guestNtwkOff =
        _entityMgr.findById(NetworkOffering.class, network.getNetworkOfferingId());

    if (guestNtwkOff == null) {
      throw new InvalidParameterValueException(
          "Can't find network offering associated with network: " + network.getUuid());
    }

    // verify that ACLProvider is supported by network offering
    if (!_ntwkModel.areServicesSupportedByNetworkOffering(
        guestNtwkOff.getId(), Service.NetworkACL)) {
      throw new InvalidParameterValueException(
          "Cannot apply NetworkACL. Network Offering does not support NetworkACL service");
    }

    if (network.getNetworkACLId() != null) {
      // Revoke ACL Items of the existing ACL if the new ACL is empty
      // Existing rules won't be removed otherwise
      List<NetworkACLItemVO> aclItems = _networkACLItemDao.listByACL(acl.getId());
      if (aclItems == null || aclItems.isEmpty()) {
        s_logger.debug("New network ACL is empty. Revoke existing rules before applying ACL");
        if (!revokeACLItemsForNetwork(network.getId())) {
          throw new CloudRuntimeException(
              "Failed to replace network ACL. Error while removing existing ACL items for network: "
                  + network.getId());
        }
      }
    }

    network.setNetworkACLId(acl.getId());
    // Update Network ACL
    if (_networkDao.update(network.getId(), network)) {
      s_logger.debug(
          "Updated network: "
              + network.getId()
              + " with Network ACL Id: "
              + acl.getId()
              + ", Applying ACL items");
      // Apply ACL to network
      return applyACLToNetwork(network.getId());
    }
    return false;
  }
Ejemplo n.º 4
0
  @Override
  public boolean release(
      NicProfile nic, VirtualMachineProfile<? extends VirtualMachine> vm, String reservationId) {

    if (Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key()))) {
      return true;
    }

    NetworkVO network = _networkDao.findById(nic.getNetworkId());

    if (network != null
        && _networkModel.networkIsConfiguredForExternalNetworking(
            network.getDataCenterId(), network.getId())) {
      return true;
    } else {
      return super.release(nic, vm, reservationId);
    }
  }
Ejemplo n.º 5
0
  @Override
  public boolean applyNetworkACL(long aclId) throws ResourceUnavailableException {
    boolean handled = true;
    boolean aclApplyStatus = true;

    List<NetworkACLItemVO> rules = _networkACLItemDao.listByACL(aclId);
    // Find all networks using this ACL and apply the ACL
    List<NetworkVO> networks = _networkDao.listByAclId(aclId);
    for (NetworkVO network : networks) {
      if (!applyACLItemsToNetwork(network.getId(), rules)) {
        handled = false;
        break;
      }
    }

    List<VpcGatewayVO> vpcGateways =
        _vpcGatewayDao.listByAclIdAndType(aclId, VpcGateway.Type.Private);
    for (VpcGatewayVO vpcGateway : vpcGateways) {
      PrivateGateway privateGateway = _vpcMgr.getVpcPrivateGateway(vpcGateway.getId());
      if (!applyACLToPrivateGw(privateGateway)) {
        aclApplyStatus = false;
        s_logger.debug(
            "failed to apply network acl item on private gateway "
                + privateGateway.getId()
                + "acl id "
                + aclId);
        break;
      }
    }

    if (handled && aclApplyStatus) {
      for (NetworkACLItem rule : rules) {
        if (rule.getState() == NetworkACLItem.State.Revoke) {
          removeRule(rule);
        } else if (rule.getState() == NetworkACLItem.State.Add) {
          NetworkACLItemVO ruleVO = _networkACLItemDao.findById(rule.getId());
          ruleVO.setState(NetworkACLItem.State.Active);
          _networkACLItemDao.update(ruleVO.getId(), ruleVO);
        }
      }
    }
    return handled && aclApplyStatus;
  }
Ejemplo n.º 6
0
  @Override
  public Network design(
      NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {

    if (Boolean.parseBoolean(_configDao.getValue(Config.OvsTunnelNetwork.key()))) {
      return null;
    }

    NetworkVO config = (NetworkVO) super.design(offering, plan, userSpecified, owner);
    if (config == null) {
      return null;
    } else if (_networkModel.networkIsConfiguredForExternalNetworking(
        plan.getDataCenterId(), config.getId())) {
      /* In order to revert userSpecified network setup */
      config.setState(State.Allocated);
    }

    return config;
  }