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());
}
}
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;
}
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());
}
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);
}
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);
}
Aggregations