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