Search in sources :

Example 71 with VMTemplateVO

use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.

the class ResourceManagerImpl method getDefaultHypervisor.

@Override
public HypervisorType getDefaultHypervisor(final long zoneId) {
    HypervisorType defaultHyper = HypervisorType.None;
    if (_defaultSystemVMHypervisor != HypervisorType.None) {
        defaultHyper = _defaultSystemVMHypervisor;
    }
    final DataCenterVO dc = _dcDao.findById(zoneId);
    if (dc == null) {
        return HypervisorType.None;
    }
    _dcDao.loadDetails(dc);
    final String defaultHypervisorInZone = dc.getDetail("defaultSystemVMHypervisorType");
    if (defaultHypervisorInZone != null) {
        defaultHyper = HypervisorType.getType(defaultHypervisorInZone);
    }
    final List<VMTemplateVO> systemTemplates = _templateDao.listAllSystemVMTemplates();
    boolean isValid = false;
    for (final VMTemplateVO template : systemTemplates) {
        if (template.getHypervisorType() == defaultHyper) {
            isValid = true;
            break;
        }
    }
    if (isValid) {
        final List<ClusterVO> clusters = _clusterDao.listByDcHyType(zoneId, defaultHyper.toString());
        if (clusters.size() <= 0) {
            isValid = false;
        }
    }
    if (isValid) {
        return defaultHyper;
    } else {
        return HypervisorType.None;
    }
}
Also used : HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) VMTemplateVO(com.cloud.storage.VMTemplateVO)

Example 72 with VMTemplateVO

use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final SshKeyToRouterRules sshkey) throws ResourceUnavailableException {
    final VirtualRouter router = sshkey.getRouter();
    final VirtualMachineProfile profile = sshkey.getProfile();
    final String sshKeystr = sshkey.getSshPublicKey();
    final UserVmVO userVM = sshkey.getUserVM();
    final Commands commands = new Commands(Command.OnError.Stop);
    final NicVO nicVo = sshkey.getNicVo();
    final VMTemplateVO template = sshkey.getTemplate();
    if (template != null && template.getEnablePassword()) {
        _commandSetupHelper.createPasswordCommand(router, profile, nicVo, commands);
    }
    _commandSetupHelper.createVmDataCommand(router, userVM, nicVo, sshKeystr, commands);
    return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) Commands(com.cloud.agent.manager.Commands) VMTemplateVO(com.cloud.storage.VMTemplateVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 73 with VMTemplateVO

use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.

the class VmwareServerDiscoverer method createVmwareToolsIso.

private void createVmwareToolsIso() {
    String isoName = "vmware-tools.iso";
    VMTemplateVO tmplt = _tmpltDao.findByTemplateName(isoName);
    Long id;
    if (tmplt == null) {
        id = _tmpltDao.getNextInSequence(Long.class, "id");
        VMTemplateVO template = VMTemplateVO.createPreHostIso(id, isoName, isoName, ImageFormat.ISO, true, true, TemplateType.PERHOST, null, null, true, 64, Account.ACCOUNT_ID_SYSTEM, null, "VMware Tools Installer ISO", false, 1, false, HypervisorType.VMware);
        _tmpltDao.persist(template);
    } else {
        id = tmplt.getId();
        tmplt.setTemplateType(TemplateType.PERHOST);
        tmplt.setUrl(null);
        _tmpltDao.update(id, tmplt);
    }
}
Also used : VMTemplateVO(com.cloud.storage.VMTemplateVO)

Example 74 with VMTemplateVO

use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.

the class ApiResponseHelper method createSystemVmResponse.

@Override
public SystemVmResponse createSystemVmResponse(VirtualMachine vm) {
    SystemVmResponse vmResponse = new SystemVmResponse();
    if (vm.getType() == Type.SecondaryStorageVm || vm.getType() == Type.ConsoleProxy || vm.getType() == Type.DomainRouter) {
        // SystemVm vm = (SystemVm) systemVM;
        vmResponse.setId(vm.getUuid());
        // vmResponse.setObjectId(vm.getId());
        vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
        vmResponse.setName(vm.getHostName());
        if (vm.getPodIdToDeployIn() != null) {
            HostPodVO pod = ApiDBUtils.findPodById(vm.getPodIdToDeployIn());
            if (pod != null) {
                vmResponse.setPodId(pod.getUuid());
            }
        }
        VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
        if (template != null) {
            vmResponse.setTemplateId(template.getUuid());
        }
        vmResponse.setCreated(vm.getCreated());
        if (vm.getHostId() != null) {
            Host host = ApiDBUtils.findHostById(vm.getHostId());
            if (host != null) {
                vmResponse.setHostId(host.getUuid());
                vmResponse.setHostName(host.getName());
                vmResponse.setHypervisor(host.getHypervisorType().toString());
            }
        }
        if (vm.getState() != null) {
            vmResponse.setState(vm.getState().toString());
        }
        // for console proxies, add the active sessions
        if (vm.getType() == Type.ConsoleProxy) {
            ConsoleProxyVO proxy = ApiDBUtils.findConsoleProxy(vm.getId());
            // proxy can be already destroyed
            if (proxy != null) {
                vmResponse.setActiveViewerSessions(proxy.getActiveSession());
            }
        }
        DataCenter zone = ApiDBUtils.findZoneById(vm.getDataCenterId());
        if (zone != null) {
            vmResponse.setZoneId(zone.getUuid());
            vmResponse.setZoneName(zone.getName());
            vmResponse.setDns1(zone.getDns1());
            vmResponse.setDns2(zone.getDns2());
        }
        List<NicProfile> nicProfiles = ApiDBUtils.getNics(vm);
        for (NicProfile singleNicProfile : nicProfiles) {
            Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
            if (network != null) {
                if (network.getTrafficType() == TrafficType.Management) {
                    vmResponse.setPrivateIp(singleNicProfile.getIPv4Address());
                    vmResponse.setPrivateMacAddress(singleNicProfile.getMacAddress());
                    vmResponse.setPrivateNetmask(singleNicProfile.getIPv4Netmask());
                } else if (network.getTrafficType() == TrafficType.Control) {
                    vmResponse.setLinkLocalIp(singleNicProfile.getIPv4Address());
                    vmResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress());
                    vmResponse.setLinkLocalNetmask(singleNicProfile.getIPv4Netmask());
                } else if (network.getTrafficType() == TrafficType.Public) {
                    vmResponse.setPublicIp(singleNicProfile.getIPv4Address());
                    vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
                    vmResponse.setPublicNetmask(singleNicProfile.getIPv4Netmask());
                    vmResponse.setGateway(singleNicProfile.getIPv4Gateway());
                } else if (network.getTrafficType() == TrafficType.Guest) {
                    /*
                          * In basic zone, public ip has TrafficType.Guest in case EIP service is not enabled.
                          * When EIP service is enabled in the basic zone, system VM by default get the public
                          * IP allocated for EIP. So return the guest/public IP accordingly.
                          * */
                    NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
                    if (networkOffering.getElasticIp()) {
                        IpAddress ip = ApiDBUtils.findIpByAssociatedVmId(vm.getId());
                        if (ip != null) {
                            Vlan vlan = ApiDBUtils.findVlanById(ip.getVlanId());
                            vmResponse.setPublicIp(ip.getAddress().addr());
                            vmResponse.setPublicNetmask(vlan.getVlanNetmask());
                            vmResponse.setGateway(vlan.getVlanGateway());
                        }
                    } else {
                        vmResponse.setPublicIp(singleNicProfile.getIPv4Address());
                        vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
                        vmResponse.setPublicNetmask(singleNicProfile.getIPv4Netmask());
                        vmResponse.setGateway(singleNicProfile.getIPv4Gateway());
                    }
                }
            }
        }
    }
    vmResponse.setObjectName("systemvm");
    return vmResponse;
}
Also used : SystemVmResponse(org.apache.cloudstack.api.response.SystemVmResponse) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VMTemplateVO(com.cloud.storage.VMTemplateVO) Host(com.cloud.host.Host) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) IpAddress(com.cloud.network.IpAddress) Vlan(com.cloud.dc.Vlan) GuestVlan(com.cloud.network.GuestVlan) NicProfile(com.cloud.vm.NicProfile) HostPodVO(com.cloud.dc.HostPodVO)

Example 75 with VMTemplateVO

use of com.cloud.storage.VMTemplateVO in project cloudstack by apache.

the class ApiResponseHelper method createExtractResponse.

@Override
public ExtractResponse createExtractResponse(Long uploadId, Long id, Long zoneId, Long accountId, String mode, String url) {
    ExtractResponse response = new ExtractResponse();
    response.setObjectName("template");
    VMTemplateVO template = ApiDBUtils.findTemplateById(id);
    response.setId(template.getUuid());
    response.setName(template.getName());
    if (zoneId != null) {
        DataCenter zone = ApiDBUtils.findZoneById(zoneId);
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    response.setMode(mode);
    if (uploadId == null) {
        // region-wide image store
        response.setUrl(url);
        response.setState(Upload.Status.DOWNLOAD_URL_CREATED.toString());
    } else {
        UploadVO uploadInfo = ApiDBUtils.findUploadById(uploadId);
        response.setUploadId(uploadInfo.getUuid());
        response.setState(uploadInfo.getUploadState().toString());
        response.setUrl(uploadInfo.getUploadUrl());
    }
    Account account = ApiDBUtils.findAccountById(accountId);
    response.setAccountId(account.getUuid());
    return response;
}
Also used : ProjectAccount(com.cloud.projects.ProjectAccount) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) ExtractResponse(org.apache.cloudstack.api.response.ExtractResponse) VMTemplateVO(com.cloud.storage.VMTemplateVO) UploadVO(com.cloud.storage.UploadVO)

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