public DeleteStoragePoolCommand(StoragePool pool) {
   this(
       pool,
       LOCAL_PATH_PREFIX
           + File.separator
           + UUID.nameUUIDFromBytes((pool.getHostAddress() + pool.getPath()).getBytes()));
 }
    public boolean shouldAvoid(StoragePool pool) {
      if (_dcIds != null && _dcIds.contains(pool.getDataCenterId())) {
        return true;
      }

      if (_podIds != null && _podIds.contains(pool.getPodId())) {
        return true;
      }

      if (_clusterIds != null && _clusterIds.contains(pool.getClusterId())) {
        return true;
      }

      if (_poolIds != null && _poolIds.contains(pool.getId())) {
        return true;
      }

      return false;
    }
Exemplo n.º 3
0
 /**
  * @param primaryStoragePoolNameLabel The primary storage Pool
  * @param snapshotUuid The UUID of the snapshot which is going to be backed up
  * @param secondaryStoragePoolURL This is what shows up in the UI when you click on Secondary
  *     storage. In the code, it is present as: In the vmops.host_details table, there is a field
  *     mount.parent. This is the value of that field If you have better ideas on how to get it,
  *     you are welcome.
  */
 public SnapshotCommand(
     final StoragePool pool,
     final String secondaryStorageUrl,
     final String snapshotUuid,
     final String snapshotName,
     final Long dcId,
     final Long accountId,
     final Long volumeId) {
   primaryStoragePoolNameLabel = pool.getUuid();
   primaryPool = new StorageFilerTO(pool);
   this.snapshotUuid = snapshotUuid;
   this.secondaryStorageUrl = secondaryStorageUrl;
   this.dcId = dcId;
   this.accountId = accountId;
   this.volumeId = volumeId;
   this.snapshotName = snapshotName;
 }
 protected boolean createStoragePool(long hostId, StoragePool pool) {
   s_logger.debug("creating pool " + pool.getName() + " on  host " + hostId);
   if (pool.getPoolType() != StoragePoolType.NetworkFilesystem
       && pool.getPoolType() != StoragePoolType.Filesystem
       && pool.getPoolType() != StoragePoolType.IscsiLUN
       && pool.getPoolType() != StoragePoolType.Iscsi
       && pool.getPoolType() != StoragePoolType.VMFS
       && pool.getPoolType() != StoragePoolType.SharedMountPoint
       && pool.getPoolType() != StoragePoolType.PreSetup
       && pool.getPoolType() != StoragePoolType.OCFS2
       && pool.getPoolType() != StoragePoolType.RBD
       && pool.getPoolType() != StoragePoolType.CLVM) {
     s_logger.warn(" Doesn't support storage pool type " + pool.getPoolType());
     return false;
   }
   CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool);
   final Answer answer = agentMgr.easySend(hostId, cmd);
   if (answer != null && answer.getResult()) {
     return true;
   } else {
     primaryDataStoreDao.expunge(pool.getId());
     String msg = "";
     if (answer != null) {
       msg =
           "Can not create storage pool through host " + hostId + " due to " + answer.getDetails();
       s_logger.warn(msg);
     } else {
       msg =
           "Can not create storage pool through host "
               + hostId
               + " due to CreateStoragePoolCommand returns null";
       s_logger.warn(msg);
     }
     throw new CloudRuntimeException(msg);
   }
 }
  @Override
  public String reserveVirtualMachine(
      VMEntityVO vmEntityVO, String plannerToUse, DeploymentPlan planToDeploy, ExcludeList exclude)
      throws InsufficientCapacityException, ResourceUnavailableException {

    // call planner and get the deployDestination.
    // load vm instance and offerings and call virtualMachineManagerImpl
    // FIXME: profile should work on VirtualMachineEntity
    VMInstanceVO vm = _vmDao.findByUuid(vmEntityVO.getUuid());
    VirtualMachineProfileImpl<VMInstanceVO> vmProfile =
        new VirtualMachineProfileImpl<VMInstanceVO>(vm);
    DataCenterDeployment plan =
        new DataCenterDeployment(
            vm.getDataCenterId(), vm.getPodIdToDeployIn(), null, null, null, null);
    if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
      plan =
          new DataCenterDeployment(
              planToDeploy.getDataCenterId(),
              planToDeploy.getPodId(),
              planToDeploy.getClusterId(),
              planToDeploy.getHostId(),
              planToDeploy.getPoolId(),
              planToDeploy.getPhysicalNetworkId());
    }

    List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
    if (!vols.isEmpty()) {
      VolumeVO vol = vols.get(0);
      StoragePool pool = (StoragePool) this.dataStoreMgr.getPrimaryDataStore(vol.getPoolId());

      if (!pool.isInMaintenance()) {
        long rootVolDcId = pool.getDataCenterId();
        Long rootVolPodId = pool.getPodId();
        Long rootVolClusterId = pool.getClusterId();
        if (planToDeploy != null && planToDeploy.getDataCenterId() != 0) {
          Long clusterIdSpecified = planToDeploy.getClusterId();
          if (clusterIdSpecified != null && rootVolClusterId != null) {
            if (rootVolClusterId.longValue() != clusterIdSpecified.longValue()) {
              // cannot satisfy the plan passed in to the
              // planner
              throw new ResourceUnavailableException(
                  "Root volume is ready in different cluster, Deployment plan provided cannot be satisfied, unable to create a deployment for "
                      + vm,
                  Cluster.class,
                  clusterIdSpecified);
            }
          }
          plan =
              new DataCenterDeployment(
                  planToDeploy.getDataCenterId(),
                  planToDeploy.getPodId(),
                  planToDeploy.getClusterId(),
                  planToDeploy.getHostId(),
                  vol.getPoolId(),
                  null,
                  null);
        } else {
          plan =
              new DataCenterDeployment(
                  rootVolDcId, rootVolPodId, rootVolClusterId, null, vol.getPoolId(), null, null);
        }
      }
    }

    DeployDestination dest;
    try {
      dest = _dpMgr.planDeployment(vmProfile, plan, exclude);
    } catch (AffinityConflictException e) {
      throw new CloudRuntimeException(
          "Unable to create deployment, affinity rules associted to the VM conflict");
    }

    if (dest != null) {
      // save destination with VMEntityVO
      VMReservationVO vmReservation =
          new VMReservationVO(
              vm.getId(),
              dest.getDataCenter().getId(),
              dest.getPod().getId(),
              dest.getCluster().getId(),
              dest.getHost().getId());
      Map<Long, Long> volumeReservationMap = new HashMap<Long, Long>();

      if (vm.getHypervisorType() != HypervisorType.BareMetal) {
        for (Volume vo : dest.getStorageForDisks().keySet()) {
          volumeReservationMap.put(vo.getId(), dest.getStorageForDisks().get(vo).getId());
        }
        vmReservation.setVolumeReservation(volumeReservationMap);
      }

      vmEntityVO.setVmReservation(vmReservation);
      _vmEntityDao.persist(vmEntityVO);

      return vmReservation.getUuid();
    } else {
      throw new InsufficientServerCapacityException(
          "Unable to create a deployment for " + vmProfile,
          DataCenter.class,
          plan.getDataCenterId());
    }
  }