use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class DownloadListener method processConnect.
@Override
public void processConnect(final Host agent, final StartupCommand[] startupCommands, final boolean forRebalance) {
for (final StartupCommand startupCommand : startupCommands) {
if (startupCommand instanceof StartupRoutingCommand) {
final List<HypervisorType> hypers = this._resourceMgr.listAvailHypervisorInZone(agent.getId(), agent.getDataCenterId());
final HypervisorType hostHyper = agent.getHypervisorType();
if (hypers.contains(hostHyper)) {
return;
}
this._imageSrv.handleSysTemplateDownload(hostHyper, agent.getDataCenterId());
// update template_zone_ref for cross-zone templates
this._imageSrv.associateCrosszoneTemplatesToZone(agent.getDataCenterId());
} else if (startupCommand instanceof StartupSecondaryStorageCommand) {
try {
final List<DataStore> imageStores = this._storeMgr.getImageStoresByScope(new ZoneScope(agent.getDataCenterId()));
for (final DataStore store : imageStores) {
this._volumeSrv.handleVolumeSync(store);
this._imageSrv.handleTemplateSync(store);
}
} catch (final Exception e) {
s_logger.error("Caught exception while doing template/volume sync ", e);
}
}
}
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class TemplateManagerImpl method createPrivateTemplateRecord.
@Override
@ActionEvent(eventType = EventTypes.EVENT_TEMPLATE_CREATE, eventDescription = "creating template", create = true)
public VMTemplateVO createPrivateTemplateRecord(final CreateTemplateCmd cmd, final Account templateOwner) throws ResourceAllocationException {
final Account caller = CallContext.current().getCallingAccount();
final boolean isAdmin = this._accountMgr.isAdmin(caller.getId());
this._accountMgr.checkAccess(caller, null, true, templateOwner);
final String name = cmd.getTemplateName();
if (name == null || name.length() > 32) {
throw new InvalidParameterValueException("Template name cannot be null and should be less than 32 characters");
}
if (cmd.getTemplateTag() != null) {
if (!this._accountService.isRootAdmin(caller.getId())) {
throw new PermissionDeniedException("Parameter templatetag can only be specified by a Root Admin, permission denied");
}
}
// do some parameter defaulting
final Integer bits = cmd.getBits();
final Boolean passwordEnabled = cmd.isPasswordEnabled();
Boolean isPublic = cmd.isPublic();
Boolean featured = cmd.isFeatured();
final int bitsValue = bits == null ? 64 : bits;
final boolean passwordEnabledValue = passwordEnabled != null && passwordEnabled;
if (isPublic == null) {
isPublic = Boolean.FALSE;
}
final boolean isDynamicScalingEnabled = cmd.isDynamicallyScalable();
// check whether template owner can create public templates
final boolean allowPublicUserTemplates = AllowPublicUserTemplates.valueIn(templateOwner.getId());
if (!isAdmin && !allowPublicUserTemplates && isPublic) {
throw new PermissionDeniedException("Failed to create template " + name + ", only private templates can be created.");
}
final Long volumeId = cmd.getVolumeId();
final Long snapshotId = cmd.getSnapshotId();
if (volumeId == null && snapshotId == null) {
throw new InvalidParameterValueException("Failed to create private template record, neither volume ID nor snapshot ID were specified.");
}
if (volumeId != null && snapshotId != null) {
throw new InvalidParameterValueException("Failed to create private template record, please specify only one of volume ID (" + volumeId + ") and snapshot ID (" + snapshotId + ")");
}
HypervisorType hyperType;
final VolumeVO volume;
SnapshotVO snapshot = null;
final VMTemplateVO privateTemplate;
if (volumeId != null) {
// create template from volume
volume = this._volumeDao.findById(volumeId);
if (volume == null) {
throw new InvalidParameterValueException("Failed to create private template record, unable to find volume " + volumeId);
}
// check permissions
this._accountMgr.checkAccess(caller, null, true, volume);
// created
if (!this._volumeMgr.volumeInactive(volume)) {
final String msg = "Unable to create private template for volume: " + volume.getName() + "; volume is detached or attached to a Running VM";
if (s_logger.isInfoEnabled()) {
s_logger.info(msg);
}
throw new CloudRuntimeException(msg);
}
hyperType = this._volumeDao.getHypervisorType(volumeId);
// Try to find a better one than None
if (hyperType == HypervisorType.None) {
try {
final String hypers = _configDao.getValue(Config.HypervisorList.key());
final String[] hypervisors = hypers.split(",");
final String defaultHyper = hypervisors[0];
hyperType = HypervisorType.valueOf(defaultHyper);
} catch (IllegalArgumentException e) {
s_logger.debug("Unable to get hypervisor from global settings");
hyperType = HypervisorType.None;
}
}
} else {
// create template from snapshot
snapshot = this._snapshotDao.findById(snapshotId);
if (snapshot == null) {
throw new InvalidParameterValueException("Failed to create private template record, unable to find snapshot " + snapshotId);
}
// Volume could be removed so find including removed to record source template id.
volume = this._volumeDao.findByIdIncludingRemoved(snapshot.getVolumeId());
// check permissions
this._accountMgr.checkAccess(caller, null, true, snapshot);
if (snapshot.getState() != Snapshot.State.BackedUp) {
throw new InvalidParameterValueException("Snapshot id=" + snapshotId + " is not in " + Snapshot.State.BackedUp + " state yet and can't be used for template creation");
}
/*
* // bug #11428. Operation not supported if vmware and snapshots
* parent volume = ROOT if(snapshot.getHypervisorType() ==
* HypervisorType.VMware && snapshotVolume.getVolumeType() ==
* Type.DATADISK){ throw new UnsupportedServiceException(
* "operation not supported, snapshot with id " + snapshotId +
* " is created from Data Disk"); }
*/
hyperType = snapshot.getHypervisorType();
}
this._resourceLimitMgr.checkResourceLimit(templateOwner, ResourceType.template);
this._resourceLimitMgr.checkResourceLimit(templateOwner, ResourceType.secondary_storage, volume != null ? volume.getSize() : snapshot.getSize());
if (!isAdmin || featured == null) {
featured = Boolean.FALSE;
}
final Long guestOSId = cmd.getOsTypeId();
final GuestOSVO guestOS = this._guestOSDao.findById(guestOSId);
if (guestOS == null) {
throw new InvalidParameterValueException("GuestOS with ID: " + guestOSId + " does not exist.");
}
final Long nextTemplateId = this._tmpltDao.getNextInSequence(Long.class, "id");
final String description = cmd.getDisplayText();
boolean isExtractable = false;
Long sourceTemplateId = null;
if (volume != null) {
final VMTemplateVO template = ApiDBUtils.findTemplateById(volume.getTemplateId());
isExtractable = template != null && template.isExtractable() && template.getTemplateType() != TemplateType.SYSTEM;
if (volume.getIsoId() != null && volume.getIsoId() != 0) {
sourceTemplateId = volume.getIsoId();
} else if (volume.getTemplateId() != null) {
sourceTemplateId = volume.getTemplateId();
}
}
final String templateTag = cmd.getTemplateTag();
if (templateTag != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Adding template tag: " + templateTag);
}
}
// if specified from the API, use that one
if (cmd.getHypervisor() != null) {
hyperType = HypervisorType.getType(cmd.getHypervisor());
}
privateTemplate = new VMTemplateVO(nextTemplateId, name, ImageFormat.RAW, isPublic, featured, isExtractable, TemplateType.USER, null, bitsValue, templateOwner.getId(), null, description, passwordEnabledValue, guestOS.getId(), true, hyperType, templateTag, cmd.getDetails(), false, isDynamicScalingEnabled);
if (sourceTemplateId != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("This template is getting created from other template, setting source template Id to: " + sourceTemplateId);
}
}
// for region wide storage, set cross zones flag
final List<ImageStoreVO> stores = this._imgStoreDao.findRegionImageStores();
if (stores.size() > 0) {
privateTemplate.setCrossZones(true);
}
privateTemplate.setSourceTemplateId(sourceTemplateId);
final VMTemplateVO template = this._tmpltDao.persist(privateTemplate);
// Increment the number of templates
if (template != null) {
final Map<String, String> details = new HashMap<>();
if (volume != null) {
final Long vmId = volume.getInstanceId();
if (vmId != null) {
final UserVmVO userVm = this._userVmDao.findById(vmId);
if (userVm != null) {
this._userVmDao.loadDetails(userVm);
details.putAll(userVm.getDetails());
}
}
}
if (cmd.getDetails() != null) {
// new password will be generated during vm deployment from password enabled template
details.remove("Encrypted.Password");
details.putAll(cmd.getDetails());
}
if (!details.isEmpty()) {
privateTemplate.setDetails(details);
this._tmpltDao.saveDetails(privateTemplate);
}
this._resourceLimitMgr.incrementResourceCount(templateOwner.getId(), ResourceType.template);
this._resourceLimitMgr.incrementResourceCount(templateOwner.getId(), ResourceType.secondary_storage, new Long(volume != null ? volume.getSize() : snapshot.getSize()));
}
if (template != null) {
return template;
} else {
throw new CloudRuntimeException("Failed to create a template");
}
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class SnapshotManagerImpl method allocSnapshot.
@Override
public Snapshot allocSnapshot(final Long volumeId, final Long policyId, String snapshotName, final boolean fromVmSnapshot) throws ResourceAllocationException {
final Account caller = CallContext.current().getCallingAccount();
final VolumeInfo volume = this.volFactory.getVolume(volumeId);
if (!fromVmSnapshot) {
supportedByHypervisor(volume);
}
// Verify permissions
this._accountMgr.checkAccess(caller, null, true, volume);
final Type snapshotType = Type.MANUAL;
final Account owner = this._accountMgr.getAccount(volume.getAccountId());
try {
this._resourceLimitMgr.checkResourceLimit(owner, ResourceType.snapshot);
this._resourceLimitMgr.checkResourceLimit(owner, ResourceType.secondary_storage, volume.getSize());
} catch (final ResourceAllocationException e) {
throw e;
}
// Determine the name for this snapshot
// Snapshot Name: VMInstancename + volumeName + timeString
final String timeString = DateUtil.getDateDisplayString(DateUtil.GMT_TIMEZONE, new Date(), DateUtil.YYYYMMDD_FORMAT);
final VMInstanceVO vmInstance = this._vmDao.findById(volume.getInstanceId());
String vmDisplayName = "detached";
if (vmInstance != null) {
vmDisplayName = vmInstance.getHostName();
}
if (snapshotName == null) {
snapshotName = vmDisplayName + "_" + volume.getName() + "_" + timeString;
}
HypervisorType hypervisorType;
final StoragePoolVO storagePool = this._storagePoolDao.findById(volume.getDataStore().getId());
if (storagePool.getScope() == ScopeType.ZONE) {
hypervisorType = storagePool.getHypervisor();
// at the time being, managed storage only supports XenServer, ESX(i), and KVM (i.e. not Hyper-V), so the VHD file type can be mapped to XenServer
if (storagePool.isManaged() && HypervisorType.Any.equals(hypervisorType) && ImageFormat.VHD.equals(volume.getFormat())) {
hypervisorType = HypervisorType.XenServer;
}
} else {
hypervisorType = volume.getHypervisorType();
}
final SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), volume.getDiskOfferingId(), snapshotName, (short) snapshotType.ordinal(), snapshotType.name(), volume.getSize(), volume.getMinIops(), volume.getMaxIops(), hypervisorType);
final SnapshotVO snapshot = this._snapshotDao.persist(snapshotVO);
if (snapshot == null) {
throw new CloudRuntimeException("Failed to create snapshot for volume: " + volume.getId());
}
this._resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.snapshot);
this._resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.secondary_storage, new Long(volume.getSize()));
return snapshot;
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class SnapshotManagerImpl method supportedByHypervisor.
private boolean supportedByHypervisor(final VolumeInfo volume) {
final HypervisorType hypervisorType;
final StoragePoolVO storagePool = this._storagePoolDao.findById(volume.getDataStore().getId());
final ScopeType scope = storagePool.getScope();
if (scope.equals(ScopeType.ZONE)) {
hypervisorType = storagePool.getHypervisor();
} else {
hypervisorType = volume.getHypervisorType();
}
if (hypervisorType.equals(HypervisorType.KVM)) {
List<HostVO> hosts = null;
if (scope.equals(ScopeType.CLUSTER)) {
final ClusterVO cluster = this._clusterDao.findById(storagePool.getClusterId());
hosts = this._resourceMgr.listAllHostsInCluster(cluster.getId());
} else if (scope.equals(ScopeType.ZONE)) {
hosts = this._resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(hypervisorType, volume.getDataCenterId());
}
if (hosts != null && !hosts.isEmpty()) {
final HostVO host = hosts.get(0);
if (!hostSupportSnapsthotForVolume(host, volume)) {
throw new CloudRuntimeException("KVM Snapshot is not supported: " + host.getId());
}
}
}
// if volume is attached to a vm in destroyed or expunging state; disallow
if (volume.getInstanceId() != null) {
final UserVmVO userVm = this._vmDao.findById(volume.getInstanceId());
if (userVm != null) {
if (userVm.getState().equals(State.Destroyed) || userVm.getState().equals(State.Expunging)) {
throw new CloudRuntimeException("Creating snapshot failed due to volume:" + volume.getId() + " is associated with vm:" + userVm.getInstanceName() + " is in " + userVm.getState().toString() + " state");
}
if (userVm.getHypervisorType() == HypervisorType.KVM) {
final List<SnapshotVO> activeSnapshots = this._snapshotDao.listByInstanceId(volume.getInstanceId(), Snapshot.State.Creating, Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp);
if (activeSnapshots.size() > 0) {
throw new InvalidParameterValueException("There is other active snapshot tasks on the instance to which the volume is attached, please try again later");
}
}
final List<VMSnapshotVO> activeVMSnapshots = this._vmSnapshotDao.listByInstanceId(userVm.getId(), VMSnapshot.State.Creating, VMSnapshot.State.Reverting, VMSnapshot.State.Expunging);
if (activeVMSnapshots.size() > 0) {
throw new CloudRuntimeException("There is other active vm snapshot tasks on the instance to which the volume is attached, please try again later");
}
}
}
return true;
}
use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.
the class CloudOrchestrator method createVirtualMachineFromScratch.
@Override
public void createVirtualMachineFromScratch(final String id, final String owner, final String isoId, final String hostName, final String displayName, final String hypervisor, final String os, final int cpu, final long memory, final Long diskSize, final List<String> computeTags, final List<String> rootDiskTags, final Map<String, NicProfile> networkNicMap, final DeploymentPlan plan, DiskControllerType diskControllerType) throws InsufficientCapacityException {
final VirtualMachineEntityImpl vmEntity = ComponentContext.inject(VirtualMachineEntityImpl.class);
vmEntity.init(id, owner, hostName, displayName, computeTags, rootDiskTags, new ArrayList<>(networkNicMap.keySet()));
// load vm instance and offerings and call virtualMachineManagerImpl
final VMInstanceVO vm = _vmDao.findByUuid(id);
final ServiceOfferingVO computeOffering = _serviceOfferingDao.findById(vm.getId(), vm.getServiceOfferingId());
final DiskOfferingInfo rootDiskOfferingInfo = new DiskOfferingInfo();
rootDiskOfferingInfo.setDiskOffering(computeOffering);
final Long diskOfferingId = vm.getDiskOfferingId();
if (diskOfferingId == null) {
throw new InvalidParameterValueException("Installing from ISO requires a disk offering to be specified for the root disk.");
}
final DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
if (diskOffering == null) {
throw new InvalidParameterValueException("Unable to find disk offering " + diskOfferingId);
}
Long size = null;
if (diskOffering.getDiskSize() == 0) {
size = diskSize;
if (size == null) {
throw new InvalidParameterValueException("Disk offering " + diskOffering + " requires size parameter.");
}
_volumeMgr.validateVolumeSizeRange(size * 1024 * 1024 * 1024);
}
rootDiskOfferingInfo.setDiskOffering(diskOffering);
rootDiskOfferingInfo.setSize(size);
if (diskOffering.isCustomizedIops() != null && diskOffering.isCustomizedIops()) {
final Map<String, String> userVmDetails = _userVmDetailsDao.listDetailsKeyPairs(vm.getId());
if (userVmDetails != null) {
final String minIops = userVmDetails.get("minIopsDo");
final String maxIops = userVmDetails.get("maxIopsDo");
rootDiskOfferingInfo.setMinIops(minIops != null && minIops.trim().length() > 0 ? Long.parseLong(minIops) : null);
rootDiskOfferingInfo.setMaxIops(maxIops != null && maxIops.trim().length() > 0 ? Long.parseLong(maxIops) : null);
}
}
final LinkedHashMap<Network, List<? extends NicProfile>> networkIpMap = new LinkedHashMap<>();
for (final String uuid : networkNicMap.keySet()) {
final NetworkVO network = _networkDao.findByUuid(uuid);
if (network != null) {
networkIpMap.put(network, new ArrayList<>(Arrays.asList(networkNicMap.get(uuid))));
}
}
final HypervisorType hypervisorType = HypervisorType.valueOf(hypervisor);
_itMgr.allocate(vm.getInstanceName(), _templateDao.findById(new Long(isoId)), computeOffering, rootDiskOfferingInfo, new ArrayList<>(), networkIpMap, plan, hypervisorType, diskControllerType);
}
Aggregations