Search in sources :

Example 76 with VMTemplateVO

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;
}
Also used : Answer(com.cloud.agent.api.Answer) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMTemplateVO(com.cloud.storage.VMTemplateVO) BaremetalPxeVO(com.cloud.baremetal.database.BaremetalPxeVO)

Example 77 with VMTemplateVO

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;
}
Also used : DataCenter(com.cloud.dc.DataCenter) User(com.cloud.user.User) VpnUser(com.cloud.network.VpnUser) ServiceOffering(com.cloud.offering.ServiceOffering) AutoScaleVmProfileResponse(org.apache.cloudstack.api.response.AutoScaleVmProfileResponse) VMTemplateVO(com.cloud.storage.VMTemplateVO)

Example 78 with VMTemplateVO

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;
}
Also used : Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host)

Example 79 with VMTemplateVO

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);
}
Also used : Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO)

Example 80 with VMTemplateVO

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;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) AutoScalePolicyVO(com.cloud.network.as.AutoScalePolicyVO) VpcGatewayVO(com.cloud.network.vpc.VpcGatewayVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ApiCommandJobType(org.apache.cloudstack.api.ApiCommandJobType) User(com.cloud.user.User) VMTemplateVO(com.cloud.storage.VMTemplateVO) VMInstanceVO(com.cloud.vm.VMInstanceVO) Host(com.cloud.host.Host) PhysicalNetworkTrafficTypeVO(com.cloud.network.dao.PhysicalNetworkTrafficTypeVO) PhysicalNetworkServiceProvider(com.cloud.network.PhysicalNetworkServiceProvider) StaticRouteVO(com.cloud.network.vpc.StaticRouteVO) SecurityGroup(com.cloud.network.security.SecurityGroup) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) AutoScaleVmProfileVO(com.cloud.network.as.AutoScaleVmProfileVO) AutoScaleVmGroupVO(com.cloud.network.as.AutoScaleVmGroupVO) VolumeVO(com.cloud.storage.VolumeVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ConditionVO(com.cloud.network.as.ConditionVO) IPAddressVO(com.cloud.network.dao.IPAddressVO) CounterVO(com.cloud.network.as.CounterVO)

Aggregations

VMTemplateVO (com.cloud.storage.VMTemplateVO)110 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)28 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)27 Account (com.cloud.user.Account)27 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)24 TemplateDataStoreVO (org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO)22 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)17 Date (java.util.Date)16 ArrayList (java.util.ArrayList)15 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)13 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)13 DataCenterVO (com.cloud.dc.DataCenterVO)12 ActionEvent (com.cloud.event.ActionEvent)11 TemplateProfile (com.cloud.storage.TemplateProfile)11 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)11 VolumeVO (com.cloud.storage.VolumeVO)11 Test (org.junit.Test)11 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)10 VMTemplateZoneVO (com.cloud.storage.VMTemplateZoneVO)9 DB (com.cloud.utils.db.DB)9