Search in sources :

Example 91 with UserVmVO

use of com.cloud.vm.UserVmVO in project cloudstack by apache.

the class VolumeOrchestrator method allocateTemplatedVolume.

@Override
public DiskProfile allocateTemplatedVolume(Type type, String name, DiskOffering offering, Long rootDisksize, Long minIops, Long maxIops, VirtualMachineTemplate template, VirtualMachine vm, Account owner) {
    assert (template.getFormat() != ImageFormat.ISO) : "ISO is not a template really....";
    Long size = _tmpltMgr.getTemplateSize(template.getId(), vm.getDataCenterId());
    if (rootDisksize != null) {
        rootDisksize = rootDisksize * 1024 * 1024 * 1024;
        if (rootDisksize > size) {
            s_logger.debug("Using root disk size of " + rootDisksize + " Bytes for volume " + name);
            size = rootDisksize;
        } else {
            s_logger.debug("Using root disk size of " + size + " Bytes for volume " + name + "since specified root disk size of " + rootDisksize + " Bytes is smaller than template");
        }
    }
    minIops = minIops != null ? minIops : offering.getMinIops();
    maxIops = maxIops != null ? maxIops : offering.getMaxIops();
    VolumeVO vol = new VolumeVO(type, name, vm.getDataCenterId(), owner.getDomainId(), owner.getId(), offering.getId(), offering.getProvisioningType(), size, minIops, maxIops, null);
    vol.setFormat(getSupportedImageFormatForCluster(template.getHypervisorType()));
    if (vm != null) {
        vol.setInstanceId(vm.getId());
    }
    vol.setTemplateId(template.getId());
    if (type.equals(Type.ROOT)) {
        vol.setDeviceId(0l);
        if (!vm.getType().equals(VirtualMachine.Type.User)) {
            vol.setRecreatable(true);
        }
    } else {
        vol.setDeviceId(1l);
    }
    if (vm.getType() == VirtualMachine.Type.User) {
        UserVmVO userVm = _userVmDao.findById(vm.getId());
        vol.setDisplayVolume(userVm.isDisplayVm());
    }
    vol = _volsDao.persist(vol);
    // Create event and update resource count for volumes if vm is a user vm
    if (vm.getType() == VirtualMachine.Type.User) {
        Long offeringId = null;
        if (offering.getType() == DiskOffering.Type.Disk) {
            offeringId = offering.getId();
        }
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), offeringId, vol.getTemplateId(), size, Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
        _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.volume, vol.isDisplayVolume());
        _resourceLimitMgr.incrementResourceCount(vm.getAccountId(), ResourceType.primary_storage, vol.isDisplayVolume(), new Long(vol.getSize()));
    }
    return toDiskProfile(vol, offering);
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) VolumeVO(com.cloud.storage.VolumeVO) VmWorkMigrateVolume(com.cloud.vm.VmWorkMigrateVolume) VmWorkAttachVolume(com.cloud.vm.VmWorkAttachVolume) Volume(com.cloud.storage.Volume)

Example 92 with UserVmVO

use of com.cloud.vm.UserVmVO in project cosmic by MissionCriticalCloud.

the class RulesManagerImpl method revokePortForwardingRulesForVm.

@Override
public boolean revokePortForwardingRulesForVm(final long vmId) {
    boolean success = true;
    final UserVmVO vm = _vmDao.findByIdIncludingRemoved(vmId);
    if (vm == null) {
        return false;
    }
    final List<PortForwardingRuleVO> rules = _portForwardingDao.listByVm(vmId);
    final Set<Long> ipsToReprogram = new HashSet<>();
    if (rules == null || rules.isEmpty()) {
        s_logger.debug("No port forwarding rules are found for vm id=" + vmId);
        return true;
    }
    for (final PortForwardingRuleVO rule : rules) {
        // Mark port forwarding rule as Revoked, but don't revoke it yet (apply=false)
        revokePortForwardingRuleInternal(rule.getId(), _accountMgr.getSystemAccount(), Account.ACCOUNT_ID_SYSTEM, false);
        ipsToReprogram.add(rule.getSourceIpAddressId());
    }
    // apply rules for all ip addresses
    for (final Long ipId : ipsToReprogram) {
        s_logger.debug("Applying port forwarding rules for ip address id=" + ipId + " as a part of vm expunge");
        if (!applyPortForwardingRules(ipId, true, _accountMgr.getSystemAccount())) {
            s_logger.warn("Failed to apply port forwarding rules for ip id=" + ipId);
            success = false;
        }
    }
    return success;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) HashSet(java.util.HashSet)

Example 93 with UserVmVO

use of com.cloud.vm.UserVmVO in project cosmic by MissionCriticalCloud.

the class DedicatedResourceManagerImpl method getVmsOnHost.

private List<UserVmVO> getVmsOnHost(final long hostId) {
    final List<UserVmVO> vms = _userVmDao.listUpByHostId(hostId);
    final List<UserVmVO> vmsByLastHostId = _userVmDao.listByLastHostId(hostId);
    if (vmsByLastHostId.size() > 0) {
        // check if any VMs are within skip.counting.hours, if yes we have to consider the host.
        for (final UserVmVO stoppedVM : vmsByLastHostId) {
            final long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - stoppedVM.getUpdateTime().getTime()) / 1000;
            if (secondsSinceLastUpdate < capacityReleaseInterval) {
                vms.add(stoppedVM);
            }
        }
    }
    return vms;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO)

Example 94 with UserVmVO

use of com.cloud.vm.UserVmVO in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method prepareMigration.

@Override
public boolean prepareMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) {
    if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
        return true;
    }
    if (vm.getType() == VirtualMachine.Type.DomainRouter) {
        assert vm instanceof DomainRouterVO;
        final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
        try {
            networkTopology.setupDhcpForPvlan(false, router, router.getHostId(), nic);
        } catch (final ResourceUnavailableException e) {
            s_logger.warn("Timed Out", e);
        }
    } else if (vm.getType() == VirtualMachine.Type.User) {
        assert vm instanceof UserVmVO;
        final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
        _userVmMgr.setupVmForPvlan(false, userVm.getHostId(), nic);
    }
    return true;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 95 with UserVmVO

use of com.cloud.vm.UserVmVO in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method commitMigration.

@Override
public void commitMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst) {
    if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
        return;
    }
    if (vm.getType() == VirtualMachine.Type.DomainRouter) {
        assert vm instanceof DomainRouterVO;
        final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
        try {
            networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nic);
        } catch (final ResourceUnavailableException e) {
            s_logger.warn("Timed Out", e);
        }
    } else if (vm.getType() == VirtualMachine.Type.User) {
        assert vm instanceof UserVmVO;
        final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
        _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic);
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

UserVmVO (com.cloud.vm.UserVmVO)190 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)79 Account (com.cloud.user.Account)50 ArrayList (java.util.ArrayList)45 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)39 HostVO (com.cloud.host.HostVO)34 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)33 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)31 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)30 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)28 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)25 VolumeVO (com.cloud.storage.VolumeVO)25 VMInstanceVO (com.cloud.vm.VMInstanceVO)24 ActionEvent (com.cloud.event.ActionEvent)23 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)22 GuestOSVO (com.cloud.storage.GuestOSVO)20 HashMap (java.util.HashMap)19 ConfigurationException (javax.naming.ConfigurationException)19 Test (org.junit.Test)19 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)18