private Long getMaxTemplateSizeInBytes() {
   try {
     return Long.parseLong(_configDao.getValue("max.template.iso.size")) * 1024L * 1024L * 1024L;
   } catch (NumberFormatException e) {
     return null;
   }
 }
 @Override
 public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
   _name = name;
   String elbEnabledString = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
   _elbEnabled = Boolean.parseBoolean(elbEnabledString);
   s_logger.info("Firewall provider list is " + _firewallElements.iterator().next());
   return true;
 }
  private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDeployment plan) {
    DataCenterVO mockDc = mock(DataCenterVO.class);
    VMInstanceVO vm = mock(VMInstanceVO.class);
    UserVmVO userVm = mock(UserVmVO.class);
    ServiceOfferingVO offering = mock(ServiceOfferingVO.class);

    AccountVO account = mock(AccountVO.class);
    when(account.getId()).thenReturn(accountId);
    when(account.getAccountId()).thenReturn(accountId);
    when(vmProfile.getOwner()).thenReturn(account);
    when(vmProfile.getVirtualMachine()).thenReturn(vm);
    when(vmProfile.getId()).thenReturn(12L);
    when(vmDao.findById(12L)).thenReturn(userVm);
    when(userVm.getAccountId()).thenReturn(accountId);

    when(vm.getDataCenterId()).thenReturn(dataCenterId);
    when(dcDao.findById(1L)).thenReturn(mockDc);
    when(plan.getDataCenterId()).thenReturn(dataCenterId);
    when(plan.getClusterId()).thenReturn(null);
    when(plan.getPodId()).thenReturn(null);
    when(configDao.getValue(anyString())).thenReturn("false").thenReturn("CPU");

    // Mock offering details.
    when(vmProfile.getServiceOffering()).thenReturn(offering);
    when(offering.getId()).thenReturn(offeringId);
    when(vmProfile.getServiceOfferingId()).thenReturn(offeringId);
    when(offering.getCpu()).thenReturn(noOfCpusInOffering);
    when(offering.getSpeed()).thenReturn(cpuSpeedInOffering);
    when(offering.getRamSize()).thenReturn(ramInOffering);

    List<Long> clustersWithEnoughCapacity = new ArrayList<Long>();
    clustersWithEnoughCapacity.add(1L);
    clustersWithEnoughCapacity.add(2L);
    clustersWithEnoughCapacity.add(3L);
    when(capacityDao.listClustersInZoneOrPodByHostCapacities(
            dataCenterId,
            noOfCpusInOffering * cpuSpeedInOffering,
            ramInOffering * 1024L * 1024L,
            CapacityVO.CAPACITY_TYPE_CPU,
            true))
        .thenReturn(clustersWithEnoughCapacity);

    Map<Long, Double> clusterCapacityMap = new HashMap<Long, Double>();
    clusterCapacityMap.put(1L, 2048D);
    clusterCapacityMap.put(2L, 2048D);
    clusterCapacityMap.put(3L, 2048D);
    Pair<List<Long>, Map<Long, Double>> clustersOrderedByCapacity =
        new Pair<List<Long>, Map<Long, Double>>(clustersWithEnoughCapacity, clusterCapacityMap);
    when(capacityDao.orderClustersByAggregateCapacity(
            dataCenterId, CapacityVO.CAPACITY_TYPE_CPU, true))
        .thenReturn(clustersOrderedByCapacity);

    List<Long> disabledClusters = new ArrayList<Long>();
    List<Long> clustersWithDisabledPods = new ArrayList<Long>();
    when(clusterDao.listDisabledClusters(dataCenterId, null)).thenReturn(disabledClusters);
    when(clusterDao.listClustersWithDisabledPods(dataCenterId))
        .thenReturn(clustersWithDisabledPods);
  }
 private Long getMaxVolumeSizeInBytes() {
   try {
     return Long.parseLong(_configDao.getValue("storage.max.volume.upload.size"))
         * 1024L
         * 1024L
         * 1024L;
   } catch (NumberFormatException e) {
     return null;
   }
 }
  @Override
  public List<StorageTagVO> searchByIds(Long... stIds) {
    String batchCfg = _configDao.getValue("detail.batch.query.size");

    final int detailsBatchSize = batchCfg != null ? Integer.parseInt(batchCfg) : 2000;

    // query details by batches
    List<StorageTagVO> uvList = new ArrayList<StorageTagVO>();
    int curr_index = 0;

    if (stIds.length > detailsBatchSize) {
      while ((curr_index + detailsBatchSize) <= stIds.length) {
        Long[] ids = new Long[detailsBatchSize];

        for (int k = 0, j = curr_index; j < curr_index + detailsBatchSize; j++, k++) {
          ids[k] = stIds[j];
        }

        SearchCriteria<StorageTagVO> sc = stSearch.create();

        sc.setParameters("idIN", (Object[]) ids);

        List<StorageTagVO> vms = searchIncludingRemoved(sc, null, null, false);

        if (vms != null) {
          uvList.addAll(vms);
        }

        curr_index += detailsBatchSize;
      }
    }

    if (curr_index < stIds.length) {
      int batch_size = (stIds.length - curr_index);
      // set the ids value
      Long[] ids = new Long[batch_size];

      for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) {
        ids[k] = stIds[j];
      }

      SearchCriteria<StorageTagVO> sc = stSearch.create();

      sc.setParameters("idIN", (Object[]) ids);

      List<StorageTagVO> vms = searchIncludingRemoved(sc, null, null, false);

      if (vms != null) {
        uvList.addAll(vms);
      }
    }

    return uvList;
  }
 private String generateCopyUrl(String ipAddress, String dir, String path) {
   String hostname = ipAddress;
   String scheme = "http";
   boolean _sslCopy = false;
   String sslCfg = _configDao.getValue(Config.SecStorageEncryptCopy.toString());
   if (sslCfg != null) {
     _sslCopy = Boolean.parseBoolean(sslCfg);
   }
   if (_sslCopy) {
     hostname = ipAddress.replace(".", "-");
     hostname = hostname + ".realhostip.com";
     scheme = "https";
   }
   return scheme + "://" + hostname + "/copy/SecStorage/" + dir + "/" + path;
 }
 private String generateCopyUrl(String ipAddress, String dir, String path) {
   String hostname = ipAddress;
   String scheme = "http";
   boolean _sslCopy = false;
   String sslCfg = _configDao.getValue(Config.SecStorageEncryptCopy.toString());
   String _ssvmUrlDomain = _configDao.getValue("secstorage.ssl.cert.domain");
   if (sslCfg != null) {
     _sslCopy = Boolean.parseBoolean(sslCfg);
   }
   if (_sslCopy && (_ssvmUrlDomain == null || _ssvmUrlDomain.isEmpty())) {
     s_logger.warn("Empty secondary storage url domain, ignoring SSL");
     _sslCopy = false;
   }
   if (_sslCopy) {
     if (_ssvmUrlDomain.startsWith("*")) {
       hostname = ipAddress.replace(".", "-");
       hostname = hostname + _ssvmUrlDomain.substring(1);
     } else {
       hostname = _ssvmUrlDomain;
     }
     scheme = "https";
   }
   return scheme + "://" + hostname + "/copy/SecStorage/" + dir + "/" + path;
 }
 @Override
 public List<ResourceTagJoinVO> searchByIds(Long... tagIds) {
   // set detail batch query size
   int DETAILS_BATCH_SIZE = 2000;
   String batchCfg = _configDao.getValue("detail.batch.query.size");
   if (batchCfg != null) {
     DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg);
   }
   // query details by batches
   List<ResourceTagJoinVO> uvList = new ArrayList<ResourceTagJoinVO>();
   // query details by batches
   int curr_index = 0;
   if (tagIds.length > DETAILS_BATCH_SIZE) {
     while ((curr_index + DETAILS_BATCH_SIZE) <= tagIds.length) {
       Long[] ids = new Long[DETAILS_BATCH_SIZE];
       for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) {
         ids[k] = tagIds[j];
       }
       SearchCriteria<ResourceTagJoinVO> sc = tagSearch.create();
       sc.setParameters("idIN", ids);
       List<ResourceTagJoinVO> vms = searchIncludingRemoved(sc, null, null, false);
       if (vms != null) {
         uvList.addAll(vms);
       }
       curr_index += DETAILS_BATCH_SIZE;
     }
   }
   if (curr_index < tagIds.length) {
     int batch_size = (tagIds.length - curr_index);
     // set the ids value
     Long[] ids = new Long[batch_size];
     for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) {
       ids[k] = tagIds[j];
     }
     SearchCriteria<ResourceTagJoinVO> sc = tagSearch.create();
     sc.setParameters("idIN", ids);
     List<ResourceTagJoinVO> vms = searchIncludingRemoved(sc, null, null, false);
     if (vms != null) {
       uvList.addAll(vms);
     }
   }
   return uvList;
 }
 public String getBaseDn() {
   return _configDao.getValue("ldap.basedn");
 }
 public String getGroupObject() {
   final String groupObject = _configDao.getValue("ldap.group.object");
   return groupObject == null ? "groupOfUniqueNames" : groupObject;
 }
 public String getGroupUniqueMemeberAttribute() {
   final String uniqueMemberAttribute = _configDao.getValue("ldap.group.user.uniquemember");
   return uniqueMemberAttribute == null ? "uniquemember" : uniqueMemberAttribute;
 }
 public String getUsernameAttribute() {
   final String usernameAttribute = _configDao.getValue("ldap.username.attribute");
   return usernameAttribute == null ? "uid" : usernameAttribute;
 }
 public String getUserObject() {
   final String userObject = _configDao.getValue("ldap.user.object");
   return userObject == null ? "inetOrgPerson" : userObject;
 }
  @Override
  public boolean addUserData(NicProfile nic, VirtualMachineProfile profile) {
    UserVmVO vm = _vmDao.findById(profile.getVirtualMachine().getId());
    _vmDao.loadDetails(vm);

    String serviceOffering =
        _serviceOfferingDao
            .findByIdIncludingRemoved(vm.getId(), vm.getServiceOfferingId())
            .getDisplayText();
    String zoneName = _dcDao.findById(vm.getDataCenterId()).getName();
    NicVO nvo = _nicDao.findById(nic.getId());
    VmDataCommand cmd =
        new VmDataCommand(
            nvo.getIPv4Address(), vm.getInstanceName(), _ntwkModel.getExecuteInSeqNtwkElmtCmd());
    // if you add new metadata files, also edit
    // systemvm/patches/debian/config/var/www/html/latest/.htaccess
    cmd.addVmData("userdata", "user-data", vm.getUserData());
    cmd.addVmData("metadata", "service-offering", StringUtils.unicodeEscape(serviceOffering));
    cmd.addVmData("metadata", "availability-zone", StringUtils.unicodeEscape(zoneName));
    cmd.addVmData("metadata", "local-ipv4", nic.getIPv4Address());
    cmd.addVmData("metadata", "local-hostname", StringUtils.unicodeEscape(vm.getInstanceName()));
    cmd.addVmData("metadata", "public-ipv4", nic.getIPv4Address());
    cmd.addVmData("metadata", "public-hostname", StringUtils.unicodeEscape(vm.getInstanceName()));
    cmd.addVmData("metadata", "instance-id", String.valueOf(vm.getId()));
    cmd.addVmData("metadata", "vm-id", String.valueOf(vm.getInstanceName()));
    cmd.addVmData("metadata", "public-keys", null);
    String cloudIdentifier = _configDao.getValue("cloud.identifier");
    if (cloudIdentifier == null) {
      cloudIdentifier = "";
    } else {
      cloudIdentifier = "CloudStack-{" + cloudIdentifier + "}";
    }
    cmd.addVmData("metadata", "cloud-identifier", cloudIdentifier);

    List<PhysicalNetworkVO> phys = _phynwDao.listByZone(vm.getDataCenterId());
    if (phys.isEmpty()) {
      throw new CloudRuntimeException(
          String.format("Cannot find physical network in zone %s", vm.getDataCenterId()));
    }
    if (phys.size() > 1) {
      throw new CloudRuntimeException(
          String.format(
              "Baremetal only supports one physical network in zone, but zone %s has %s physical networks",
              vm.getDataCenterId(), phys.size()));
    }
    PhysicalNetworkVO phy = phys.get(0);

    QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
    // TODO: handle both kickstart and PING
    // sc.addAnd(sc.getEntity().getPodId(), Op.EQ, vm.getPodIdToDeployIn());
    sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, phy.getId());
    BaremetalPxeVO pxeVo = sc.find();
    if (pxeVo == null) {
      throw new CloudRuntimeException(
          "No PXE server found in pod: "
              + vm.getPodIdToDeployIn()
              + ", you need to add it before starting VM");
    }

    try {
      Answer ans = _agentMgr.send(pxeVo.getHostId(), cmd);
      if (!ans.getResult()) {
        s_logger.debug(
            String.format(
                "Add userdata to vm:%s failed because %s", vm.getInstanceName(), ans.getDetails()));
        return false;
      } else {
        return true;
      }
    } catch (Exception e) {
      s_logger.debug(String.format("Add userdata to vm:%s failed", vm.getInstanceName()), e);
      return false;
    }
  }
 public String getLastnameAttribute() {
   final String lastnameAttribute = _configDao.getValue("ldap.lastname.attribute");
   return lastnameAttribute == null ? "sn" : lastnameAttribute;
 }
 public String getEmailAttribute() {
   final String emailAttribute = _configDao.getValue("ldap.email.attribute");
   return emailAttribute == null ? "mail" : emailAttribute;
 }
 public String getBindPassword() {
   return _configDao.getValue("ldap.bind.password");
 }
  private boolean preparePxeInAdvancedZone(
      VirtualMachineProfile profile,
      NicProfile nic,
      Network network,
      DeployDestination dest,
      ReservationContext context)
      throws Exception {
    DomainRouterVO vr = getVirtualRouter(network);
    List<NicVO> nics = _nicDao.listByVmId(vr.getId());
    NicVO mgmtNic = null;
    for (NicVO nicvo : nics) {
      if (ControlNetworkGuru.class.getSimpleName().equals(nicvo.getReserver())) {
        mgmtNic = nicvo;
        break;
      }
    }

    if (mgmtNic == null) {
      throw new CloudRuntimeException(
          String.format("cannot find management nic on virtual router[id:%s]", vr.getId()));
    }

    String internalServerIp = _configDao.getValue(Config.BaremetalInternalStorageServer.key());
    if (internalServerIp == null) {
      throw new CloudRuntimeException(
          String.format(
              "please specify 'baremetal.internal.storage.server.ip', which is the http server/nfs server storing kickstart files and ISO files, in global setting"));
    }

    List<String> tuple = parseKickstartUrl(profile);
    String cmd =
        String.format(
            "/usr/bin/prepare_pxe.sh %s %s %s %s %s %s",
            tuple.get(1),
            tuple.get(2),
            profile.getTemplate().getUuid(),
            String.format("01-%s", nic.getMacAddress().replaceAll(":", "-")).toLowerCase(),
            tuple.get(0),
            nic.getMacAddress().toLowerCase());
    s_logger.debug(
        String.format(
            "prepare pxe on virtual router[ip:%s], cmd: %s", mgmtNic.getIp4Address(), cmd));
    Pair<Boolean, String> ret =
        SshHelper.sshExecute(
            mgmtNic.getIp4Address(), 3922, "root", getSystemVMKeyFile(), null, cmd);
    if (!ret.first()) {
      throw new CloudRuntimeException(
          String.format(
              "failed preparing PXE in virtual router[id:%s], because %s",
              vr.getId(), ret.second()));
    }

    // String internalServerIp = "10.223.110.231";
    cmd =
        String.format(
            "/usr/bin/baremetal_snat.sh %s %s %s",
            mgmtNic.getIp4Address(), internalServerIp, mgmtNic.getGateway());
    s_logger.debug(
        String.format(
            "prepare SNAT on virtual router[ip:%s], cmd: %s", mgmtNic.getIp4Address(), cmd));
    ret =
        SshHelper.sshExecute(
            mgmtNic.getIp4Address(), 3922, "root", getSystemVMKeyFile(), null, cmd);
    if (!ret.first()) {
      throw new CloudRuntimeException(
          String.format(
              "failed preparing PXE in virtual router[id:%s], because %s",
              vr.getId(), ret.second()));
    }

    return true;
  }
 public String getBindPrincipal() {
   return _configDao.getValue("ldap.bind.principal");
 }
 public String getSearchGroupPrinciple() {
   return _configDao.getValue("ldap.search.group.principle");
 }
 public String getFirstnameAttribute() {
   final String firstnameAttribute = _configDao.getValue("ldap.firstname.attribute");
   return firstnameAttribute == null ? "givenname" : firstnameAttribute;
 }
 public String getTrustStore() {
   return _configDao.getValue("ldap.truststore");
 }
Exemplo n.º 23
0
  @Override
  public boolean start() {
    Integer apiPort = null; // api port, null by default
    SearchCriteria<ConfigurationVO> sc = _configDao.createSearchCriteria();
    sc.addAnd("name", SearchCriteria.Op.EQ, Config.IntegrationAPIPort.key());
    List<ConfigurationVO> values = _configDao.search(sc, null);
    if ((values != null) && (values.size() > 0)) {
      ConfigurationVO apiPortConfig = values.get(0);
      if (apiPortConfig.getValue() != null) {
        apiPort = Integer.parseInt(apiPortConfig.getValue());
      }
    }

    Map<String, String> configs = _configDao.getConfiguration();
    String strSnapshotLimit = configs.get(Config.ConcurrentSnapshotsThresholdPerHost.key());
    if (strSnapshotLimit != null) {
      Long snapshotLimit = NumbersUtil.parseLong(strSnapshotLimit, 1L);
      if (snapshotLimit.longValue() <= 0) {
        s_logger.debug(
            "Global config parameter "
                + Config.ConcurrentSnapshotsThresholdPerHost.toString()
                + " is less or equal 0; defaulting to unlimited");
      } else {
        _dispatcher.setCreateSnapshotQueueSizeLimit(snapshotLimit);
      }
    }

    Set<Class<?>> cmdClasses = new HashSet<Class<?>>();
    for (PluggableService pluggableService : _pluggableServices) {
      cmdClasses.addAll(pluggableService.getCommands());
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("Discovered plugin " + pluggableService.getClass().getSimpleName());
      }
    }

    for (Class<?> cmdClass : cmdClasses) {
      APICommand at = cmdClass.getAnnotation(APICommand.class);
      if (at == null) {
        throw new CloudRuntimeException(
            String.format(
                "%s is claimed as a API command, but it doesn't have @APICommand annotation",
                cmdClass.getName()));
      }
      String apiName = at.name();
      if (_apiNameCmdClassMap.containsKey(apiName)) {
        s_logger.error("API Cmd class " + cmdClass.getName() + " has non-unique apiname" + apiName);
        continue;
      }
      _apiNameCmdClassMap.put(apiName, cmdClass);
    }

    encodeApiResponse = Boolean.valueOf(_configDao.getValue(Config.EncodeApiResponse.key()));
    String jsonType = _configDao.getValue(Config.JavaScriptDefaultContentType.key());
    if (jsonType != null) {
      jsonContentType = jsonType;
    }

    if (apiPort != null) {
      ListenerThread listenerThread = new ListenerThread(this, apiPort);
      listenerThread.start();
    }

    return true;
  }
 public String getTrustStorePassword() {
   return _configDao.getValue("ldap.truststore.password");
 }