Search in sources :

Example 11 with Pod

use of com.cloud.legacymodel.dc.Pod in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method orchestrateReboot.

private void orchestrateReboot(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    // if there are active vm snapshots task, state change is not allowed
    if (_vmSnapshotMgr.hasActiveVMSnapshotTasks(vm.getId())) {
        s_logger.error("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
        throw new CloudRuntimeException("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
    }
    final Zone zone = _zoneRepository.findById(vm.getDataCenterId()).orElse(null);
    final Host host = _hostDao.findById(vm.getHostId());
    if (host == null) {
        // Should findById throw an Exception is the host is not found?
        throw new CloudRuntimeException("Unable to retrieve host with id " + vm.getHostId());
    }
    final Cluster cluster = _entityMgr.findById(Cluster.class, host.getClusterId());
    final Pod pod = _entityMgr.findById(Pod.class, host.getPodId());
    final DeployDestination dest = new DeployDestination(zone, pod, cluster, host);
    try {
        final Commands cmds = new Commands(Command.OnError.Stop);
        cmds.addCommand(new RebootCommand(vm.getInstanceName(), getExecuteInSequence(vm.getHypervisorType())));
        _agentMgr.send(host.getId(), cmds);
        final Answer rebootAnswer = cmds.getAnswer(RebootAnswer.class);
        if (rebootAnswer != null && rebootAnswer.getResult()) {
            return;
        }
        s_logger.info("Unable to reboot VM " + vm + " on " + dest.getHost() + " due to " + (rebootAnswer == null ? " no reboot answer" : rebootAnswer.getDetails()));
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Unable to send the reboot command to host " + dest.getHost() + " for the vm " + vm + " due to operation timeout", e);
        throw new CloudRuntimeException("Failed to reboot the vm on host " + dest.getHost());
    }
}
Also used : UnPlugNicAnswer(com.cloud.legacymodel.communication.answer.UnPlugNicAnswer) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.legacymodel.communication.answer.ClusterVMMetaDataSyncAnswer) RestoreVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RestoreVMSnapshotAnswer) RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) StartAnswer(com.cloud.legacymodel.communication.answer.StartAnswer) PlugNicAnswer(com.cloud.legacymodel.communication.answer.PlugNicAnswer) CheckVirtualMachineAnswer(com.cloud.legacymodel.communication.answer.CheckVirtualMachineAnswer) StopAnswer(com.cloud.legacymodel.communication.answer.StopAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) RebootCommand(com.cloud.legacymodel.communication.command.RebootCommand) Pod(com.cloud.legacymodel.dc.Pod) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) TimeZone(java.util.TimeZone) Zone(com.cloud.db.model.Zone) DeployDestination(com.cloud.deploy.DeployDestination) Commands(com.cloud.agent.manager.Commands) Cluster(com.cloud.legacymodel.dc.Cluster) Host(com.cloud.legacymodel.dc.Host)

Example 12 with Pod

use of com.cloud.legacymodel.dc.Pod in project cosmic by MissionCriticalCloud.

the class VmWorkMigrate method getDeployDestination.

public DeployDestination getDeployDestination() {
    final Zone zone = zoneId != null ? s_zoneRepository.findById(zoneId).orElse(null) : null;
    final Pod pod = podId != null ? s_entityMgr.findById(Pod.class, podId) : null;
    final Cluster cluster = clusterId != null ? s_entityMgr.findById(Cluster.class, clusterId) : null;
    final Host host = hostId != null ? s_entityMgr.findById(Host.class, hostId) : null;
    Map<Volume, StoragePool> vols = null;
    if (storage != null) {
        vols = new HashMap<>(storage.size());
        for (final Map.Entry<String, String> entry : storage.entrySet()) {
            vols.put(s_entityMgr.findByUuid(Volume.class, entry.getKey()), s_entityMgr.findByUuid(StoragePool.class, entry.getValue()));
        }
    }
    final DeployDestination dest = new DeployDestination(zone, pod, cluster, host, vols);
    return dest;
}
Also used : StoragePool(com.cloud.legacymodel.storage.StoragePool) Pod(com.cloud.legacymodel.dc.Pod) Volume(com.cloud.legacymodel.storage.Volume) Zone(com.cloud.db.model.Zone) DeployDestination(com.cloud.deploy.DeployDestination) Cluster(com.cloud.legacymodel.dc.Cluster) Host(com.cloud.legacymodel.dc.Host) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with Pod

use of com.cloud.legacymodel.dc.Pod in project cosmic by MissionCriticalCloud.

the class VolumeOrchestrator method moveVolume.

@Override
public VolumeInfo moveVolume(final VolumeInfo volume, final long destPoolDcId, final Long destPoolPodId, final Long destPoolClusterId, final HypervisorType dataDiskHyperType) throws ConcurrentOperationException, StorageUnavailableException {
    // Find a destination storage pool with the specified criteria
    final DiskOffering diskOffering = this._entityMgr.findById(DiskOffering.class, volume.getDiskOfferingId());
    final DiskProfile dskCh = new DiskProfile(volume.getId(), volume.getVolumeType(), volume.getName(), diskOffering.getId(), diskOffering.getDiskSize(), diskOffering.getTagsArray(), diskOffering.getUseLocalStorage(), diskOffering.isRecreatable(), null);
    dskCh.setHyperType(dataDiskHyperType);
    final DataCenter destPoolDataCenter = this._entityMgr.findById(DataCenter.class, destPoolDcId);
    final Pod destPoolPod = this._entityMgr.findById(Pod.class, destPoolPodId);
    final StoragePool destPool = findStoragePool(dskCh, destPoolDataCenter, destPoolPod, destPoolClusterId, null, null, new HashSet<>());
    if (destPool == null) {
        throw new CloudRuntimeException("Failed to find a storage pool with enough capacity to move the volume to.");
    }
    final Volume newVol = migrateVolume(volume, destPool);
    return this.volFactory.getVolume(newVol.getId());
}
Also used : DiskOffering(com.cloud.legacymodel.storage.DiskOffering) DataCenter(com.cloud.legacymodel.dc.DataCenter) StoragePool(com.cloud.legacymodel.storage.StoragePool) Pod(com.cloud.legacymodel.dc.Pod) Volume(com.cloud.legacymodel.storage.Volume) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) DiskProfile(com.cloud.legacymodel.storage.DiskProfile)

Example 14 with Pod

use of com.cloud.legacymodel.dc.Pod in project cosmic by MissionCriticalCloud.

the class StorageNetworkGuru method reserve.

@Override
public void reserve(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    if (!_sNwMgr.isStorageIpRangeAvailable(dest.getZone().getId())) {
        super.reserve(nic, network, vm, dest, context);
        return;
    }
    final Pod pod = dest.getPod();
    final Integer vlan;
    final StorageNetworkIpAddressVO ip = _sNwMgr.acquireIpAddress(pod.getId());
    if (ip == null) {
        throw new InsufficientAddressCapacityException("Unable to get a storage network ip address", Pod.class, pod.getId());
    }
    vlan = ip.getVlan();
    nic.setIPv4Address(ip.getIpAddress());
    nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.getMac())));
    nic.setFormat(IpAddressFormat.Ip4);
    nic.setIPv4Netmask(ip.getNetmask());
    nic.setBroadcastType(BroadcastDomainType.Storage);
    nic.setIPv4Gateway(ip.getGateway());
    if (vlan != null) {
        nic.setBroadcastUri(BroadcastDomainType.Storage.toUri(vlan));
    } else {
        nic.setBroadcastUri(null);
    }
    nic.setIsolationUri(null);
    s_logger.debug("Allocated a storage nic " + nic + " for " + vm);
}
Also used : Pod(com.cloud.legacymodel.dc.Pod) StorageNetworkIpAddressVO(com.cloud.dc.StorageNetworkIpAddressVO) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)

Example 15 with Pod

use of com.cloud.legacymodel.dc.Pod in project cosmic by MissionCriticalCloud.

the class PodBasedNetworkGuru method reserve.

@Override
public void reserve(final NicProfile nic, final Network config, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
    final Pod pod = dest.getPod();
    Pair<String, Long> ip = null;
    _ipAllocDao.releaseIpAddress(nic.getId());
    final DataCenterIpAddressVO vo = _ipAllocDao.takeIpAddress(dest.getZone().getId(), dest.getPod().getId(), nic.getId(), context.getReservationId());
    if (vo != null) {
        ip = new Pair<>(vo.getIpAddress(), vo.getMacAddress());
    }
    if (ip == null) {
        throw new InsufficientAddressCapacityException("Unable to get a management ip address", Pod.class, pod.getId());
    }
    nic.setIPv4Address(ip.first());
    nic.setMacAddress(NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ip.second())));
    nic.setIPv4Gateway(pod.getGateway());
    nic.setFormat(IpAddressFormat.Ip4);
    final String netmask = NetUtils.getCidrNetmask(pod.getCidrSize());
    nic.setIPv4Netmask(netmask);
    nic.setBroadcastType(BroadcastDomainType.Native);
    nic.setBroadcastUri(null);
    nic.setIsolationUri(null);
    s_logger.debug("Allocated a nic " + nic + " for " + vm);
}
Also used : Pod(com.cloud.legacymodel.dc.Pod) InsufficientAddressCapacityException(com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException) DataCenterIpAddressVO(com.cloud.dc.DataCenterIpAddressVO)

Aggregations

Pod (com.cloud.legacymodel.dc.Pod)15 Zone (com.cloud.db.model.Zone)5 StoragePool (com.cloud.legacymodel.storage.StoragePool)5 Cluster (com.cloud.legacymodel.dc.Cluster)4 DataCenter (com.cloud.legacymodel.dc.DataCenter)4 Host (com.cloud.legacymodel.dc.Host)4 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)4 Volume (com.cloud.legacymodel.storage.Volume)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 PodResponse (com.cloud.api.response.PodResponse)3 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)3 DiskOffering (com.cloud.legacymodel.storage.DiskOffering)3 DB (com.cloud.utils.db.DB)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ServerApiException (com.cloud.api.ServerApiException)2 VlanVO (com.cloud.dc.VlanVO)2 DeployDestination (com.cloud.deploy.DeployDestination)2 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)2