use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.
the class BaremetalKickStartServiceImpl method preparePxeInBasicZone.
private boolean preparePxeInBasicZone(VirtualMachineProfile profile, NicProfile nic, DeployDestination dest, ReservationContext context) throws AgentUnavailableException, OperationTimedoutException {
NetworkVO nwVO = _nwDao.findById(nic.getNetworkId());
QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
sc.and(sc.entity().getDeviceType(), Op.EQ, BaremetalPxeType.KICK_START.toString());
sc.and(sc.entity().getPhysicalNetworkId(), Op.EQ, nwVO.getPhysicalNetworkId());
BaremetalPxeVO pxeVo = sc.find();
if (pxeVo == null) {
throw new CloudRuntimeException("No kickstart PXE server found in pod: " + dest.getPod().getId() + ", you need to add it before starting VM");
}
VMTemplateVO template = _tmpDao.findById(profile.getTemplateId());
List<String> tuple = parseKickstartUrl(profile);
String ks = tuple.get(0);
String kernel = tuple.get(1);
String initrd = tuple.get(2);
PrepareKickstartPxeServerCommand cmd = new PrepareKickstartPxeServerCommand();
cmd.setKsFile(ks);
cmd.setInitrd(initrd);
cmd.setKernel(kernel);
cmd.setMac(nic.getMacAddress());
cmd.setTemplateUuid(template.getUuid());
Answer aws = _agentMgr.send(pxeVo.getHostId(), cmd);
if (!aws.getResult()) {
s_logger.warn("Unable to set host: " + dest.getHost().getId() + " to PXE boot because " + aws.getDetails());
return false;
}
return true;
}
use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.
the class ApiResponseHelper method createAutoScaleVmProfileResponse.
@Override
public AutoScaleVmProfileResponse createAutoScaleVmProfileResponse(AutoScaleVmProfile profile) {
AutoScaleVmProfileResponse response = new AutoScaleVmProfileResponse();
response.setId(profile.getUuid());
if (profile.getZoneId() != null) {
DataCenter zone = ApiDBUtils.findZoneById(profile.getZoneId());
if (zone != null) {
response.setZoneId(zone.getUuid());
}
}
if (profile.getServiceOfferingId() != null) {
ServiceOffering so = ApiDBUtils.findServiceOfferingById(profile.getServiceOfferingId());
if (so != null) {
response.setServiceOfferingId(so.getUuid());
}
}
if (profile.getTemplateId() != null) {
VMTemplateVO template = ApiDBUtils.findTemplateById(profile.getTemplateId());
if (template != null) {
response.setTemplateId(template.getUuid());
}
}
response.setOtherDeployParams(profile.getOtherDeployParams());
response.setCounterParams(profile.getCounterParams());
response.setDestroyVmGraceperiod(profile.getDestroyVmGraceperiod());
User user = ApiDBUtils.findUserById(profile.getAutoScaleUserId());
if (user != null) {
response.setAutoscaleUserId(user.getUuid());
}
response.setObjectName("autoscalevmprofile");
// Populates the account information in the response
populateOwner(response, profile);
return response;
}
use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.
the class FirstFitAllocator method allocateTo.
@Override
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, List<? extends Host> hosts, int returnUpTo, boolean considerReservedCapacity) {
long dcId = plan.getDataCenterId();
Long podId = plan.getPodId();
Long clusterId = plan.getClusterId();
ServiceOffering offering = vmProfile.getServiceOffering();
VMTemplateVO template = (VMTemplateVO) vmProfile.getTemplate();
Account account = vmProfile.getOwner();
List<Host> suitableHosts = new ArrayList<Host>();
List<Host> hostsCopy = new ArrayList<Host>(hosts);
if (type == Host.Type.Storage) {
// routing or not.
return suitableHosts;
}
String hostTagOnOffering = offering.getHostTag();
String hostTagOnTemplate = template.getTemplateTag();
boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false;
boolean hasTemplateTag = hostTagOnTemplate != null ? true : false;
String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
if (haVmTag != null) {
hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag));
} else {
if (hostTagOnOffering == null && hostTagOnTemplate == null) {
hostsCopy.retainAll(_resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId));
} else {
if (hasSvcOfferingTag) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering);
}
hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering));
if (s_logger.isDebugEnabled()) {
s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsCopy);
}
}
if (hasTemplateTag) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate);
}
hostsCopy.retainAll(_hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate));
if (s_logger.isDebugEnabled()) {
s_logger.debug("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsCopy);
}
}
}
}
if (!hostsCopy.isEmpty()) {
suitableHosts = allocateTo(plan, offering, template, avoid, hostsCopy, returnUpTo, considerReservedCapacity, account);
}
return suitableHosts;
}
use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.
the class FirstFitAllocator method allocateTo.
@Override
public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) {
long dcId = plan.getDataCenterId();
Long podId = plan.getPodId();
Long clusterId = plan.getClusterId();
ServiceOffering offering = vmProfile.getServiceOffering();
VMTemplateVO template = (VMTemplateVO) vmProfile.getTemplate();
Account account = vmProfile.getOwner();
if (type == Host.Type.Storage) {
// FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of routing or not
return new ArrayList<Host>();
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
}
String hostTagOnOffering = offering.getHostTag();
String hostTagOnTemplate = template.getTemplateTag();
boolean hasSvcOfferingTag = hostTagOnOffering != null ? true : false;
boolean hasTemplateTag = hostTagOnTemplate != null ? true : false;
List<HostVO> clusterHosts = new ArrayList<HostVO>();
String haVmTag = (String) vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
if (haVmTag != null) {
clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, haVmTag);
} else {
if (hostTagOnOffering == null && hostTagOnTemplate == null) {
clusterHosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId);
} else {
List<HostVO> hostsMatchingOfferingTag = new ArrayList<HostVO>();
List<HostVO> hostsMatchingTemplateTag = new ArrayList<HostVO>();
if (hasSvcOfferingTag) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering);
}
hostsMatchingOfferingTag = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnOffering);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsMatchingOfferingTag);
}
}
if (hasTemplateTag) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Looking for hosts having tag specified on Template:" + hostTagOnTemplate);
}
hostsMatchingTemplateTag = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsMatchingTemplateTag);
}
}
if (hasSvcOfferingTag && hasTemplateTag) {
hostsMatchingOfferingTag.retainAll(hostsMatchingTemplateTag);
clusterHosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTagOnTemplate);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Found " + hostsMatchingOfferingTag.size() + " Hosts satisfying both tags, host ids are:" + hostsMatchingOfferingTag);
}
clusterHosts = hostsMatchingOfferingTag;
} else {
if (hasSvcOfferingTag) {
clusterHosts = hostsMatchingOfferingTag;
} else {
clusterHosts = hostsMatchingTemplateTag;
}
}
}
}
// add all hosts that we are not considering to the avoid list
List<HostVO> allhostsInCluster = _hostDao.listAllUpAndEnabledNonHAHosts(type, clusterId, podId, dcId, null);
allhostsInCluster.removeAll(clusterHosts);
for (HostVO host : allhostsInCluster) {
avoid.addHost(host.getId());
}
return allocateTo(plan, offering, template, avoid, clusterHosts, returnUpTo, considerReservedCapacity, account);
}
use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.
the class ApiDBUtils method findJobInstanceUuid.
public static String findJobInstanceUuid(AsyncJob job) {
if (job == null) {
return null;
}
String jobInstanceId = null;
ApiCommandJobType jobInstanceType = EnumUtils.fromString(ApiCommandJobType.class, job.getInstanceType(), ApiCommandJobType.None);
if (job.getInstanceId() == null) {
// when assert is hit, implement 'getInstanceId' of BaseAsyncCmd and return appropriate instance id
assert (false);
return null;
}
if (jobInstanceType == ApiCommandJobType.Volume) {
VolumeVO volume = ApiDBUtils.findVolumeById(job.getInstanceId());
if (volume != null) {
jobInstanceId = volume.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Template || jobInstanceType == ApiCommandJobType.Iso) {
VMTemplateVO template = ApiDBUtils.findTemplateById(job.getInstanceId());
if (template != null) {
jobInstanceId = template.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.VirtualMachine || jobInstanceType == ApiCommandJobType.ConsoleProxy || jobInstanceType == ApiCommandJobType.SystemVm || jobInstanceType == ApiCommandJobType.DomainRouter) {
VMInstanceVO vm = ApiDBUtils.findVMInstanceById(job.getInstanceId());
if (vm != null) {
jobInstanceId = vm.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Snapshot) {
Snapshot snapshot = ApiDBUtils.findSnapshotById(job.getInstanceId());
if (snapshot != null) {
jobInstanceId = snapshot.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Host) {
Host host = ApiDBUtils.findHostById(job.getInstanceId());
if (host != null) {
jobInstanceId = host.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.StoragePool) {
StoragePoolVO spool = ApiDBUtils.findStoragePoolById(job.getInstanceId());
if (spool != null) {
jobInstanceId = spool.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.IpAddress) {
IPAddressVO ip = ApiDBUtils.findIpAddressById(job.getInstanceId());
if (ip != null) {
jobInstanceId = ip.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.SecurityGroup) {
SecurityGroup sg = ApiDBUtils.findSecurityGroupById(job.getInstanceId());
if (sg != null) {
jobInstanceId = sg.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PhysicalNetwork) {
PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(job.getInstanceId());
if (pnet != null) {
jobInstanceId = pnet.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.TrafficType) {
PhysicalNetworkTrafficTypeVO trafficType = ApiDBUtils.findPhysicalNetworkTrafficTypeById(job.getInstanceId());
if (trafficType != null) {
jobInstanceId = trafficType.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PhysicalNetworkServiceProvider) {
PhysicalNetworkServiceProvider sp = ApiDBUtils.findPhysicalNetworkServiceProviderById(job.getInstanceId());
if (sp != null) {
jobInstanceId = sp.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.FirewallRule) {
FirewallRuleVO fw = ApiDBUtils.findFirewallRuleById(job.getInstanceId());
if (fw != null) {
jobInstanceId = fw.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Account) {
Account acct = ApiDBUtils.findAccountById(job.getInstanceId());
if (acct != null) {
jobInstanceId = acct.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.User) {
User usr = ApiDBUtils.findUserById(job.getInstanceId());
if (usr != null) {
jobInstanceId = usr.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.StaticRoute) {
StaticRouteVO route = ApiDBUtils.findStaticRouteById(job.getInstanceId());
if (route != null) {
jobInstanceId = route.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.PrivateGateway) {
VpcGatewayVO gateway = ApiDBUtils.findVpcGatewayById(job.getInstanceId());
if (gateway != null) {
jobInstanceId = gateway.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Counter) {
CounterVO counter = ApiDBUtils.getCounter(job.getInstanceId());
if (counter != null) {
jobInstanceId = counter.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Condition) {
ConditionVO condition = ApiDBUtils.findConditionById(job.getInstanceId());
if (condition != null) {
jobInstanceId = condition.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.AutoScalePolicy) {
AutoScalePolicyVO policy = ApiDBUtils.findAutoScalePolicyById(job.getInstanceId());
if (policy != null) {
jobInstanceId = policy.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.AutoScaleVmProfile) {
AutoScaleVmProfileVO profile = ApiDBUtils.findAutoScaleVmProfileById(job.getInstanceId());
if (profile != null) {
jobInstanceId = profile.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.AutoScaleVmGroup) {
AutoScaleVmGroupVO group = ApiDBUtils.findAutoScaleVmGroupById(job.getInstanceId());
if (group != null) {
jobInstanceId = group.getUuid();
}
} else if (jobInstanceType == ApiCommandJobType.Network) {
NetworkVO networkVO = ApiDBUtils.findNetworkById(job.getInstanceId());
if (networkVO != null) {
jobInstanceId = networkVO.getUuid();
}
} else if (jobInstanceType != ApiCommandJobType.None) {
// entity table mapping
assert (false);
}
return jobInstanceId;
}
Aggregations