Search in sources :

Example 16 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method finalizeDeployment.

@Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
    finalizeCommandsOnStart(cmds, profile);
    SecondaryStorageVmVO secVm = _secStorageVmDao.findById(profile.getId());
    DataCenter dc = dest.getDataCenter();
    List<NicProfile> nics = profile.getNics();
    for (NicProfile nic : nics) {
        if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) {
            secVm.setPublicIpAddress(nic.getIPv4Address());
            secVm.setPublicNetmask(nic.getIPv4Netmask());
            secVm.setPublicMacAddress(nic.getMacAddress());
        } else if (nic.getTrafficType() == TrafficType.Management) {
            secVm.setPrivateIpAddress(nic.getIPv4Address());
            secVm.setPrivateMacAddress(nic.getMacAddress());
        }
    }
    _secStorageVmDao.update(secVm.getId(), secVm);
    return true;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) DataCenter(com.cloud.dc.DataCenter) NicProfile(com.cloud.vm.NicProfile)

Example 17 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method finalizeVirtualMachineProfile.

@Override
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
    SecondaryStorageVmVO vm = _secStorageVmDao.findById(profile.getId());
    Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(vm.getId());
    vm.setDetails(details);
    DataStore secStore = _dataStoreMgr.getImageStore(dest.getDataCenter().getId());
    assert (secStore != null);
    StringBuilder buf = profile.getBootArgsBuilder();
    buf.append(" template=domP type=secstorage");
    buf.append(" host=").append(ApiServiceConfiguration.ManagementHostIPAdr.value());
    buf.append(" port=").append(_mgmtPort);
    buf.append(" name=").append(profile.getVirtualMachine().getHostName());
    buf.append(" zone=").append(dest.getDataCenter().getId());
    buf.append(" pod=").append(dest.getPod().getId());
    buf.append(" guid=").append(profile.getVirtualMachine().getHostName());
    buf.append(" workers=").append(_configDao.getValue("workers"));
    if (_configDao.isPremium()) {
        s_logger.debug("VmWare hypervisor configured, telling the ssvm to load the PremiumSecondaryStorageResource");
        buf.append(" resource=com.cloud.storage.resource.PremiumSecondaryStorageResource");
    } else {
        buf.append(" resource=org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource");
    }
    buf.append(" instance=SecStorage");
    buf.append(" sslcopy=").append(Boolean.toString(_useSSlCopy));
    buf.append(" role=").append(vm.getRole().toString());
    buf.append(" mtu=").append(_secStorageVmMtuSize);
    boolean externalDhcp = false;
    String externalDhcpStr = _configDao.getValue("direct.attach.network.externalIpAllocator.enabled");
    if (externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) {
        externalDhcp = true;
    }
    if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) {
        buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password"));
    }
    for (NicProfile nic : profile.getNics()) {
        int deviceId = nic.getDeviceId();
        if (nic.getIPv4Address() == null) {
            buf.append(" eth").append(deviceId).append("mask=").append("0.0.0.0");
            buf.append(" eth").append(deviceId).append("ip=").append("0.0.0.0");
        } else {
            buf.append(" eth").append(deviceId).append("ip=").append(nic.getIPv4Address());
            buf.append(" eth").append(deviceId).append("mask=").append(nic.getIPv4Netmask());
        }
        if (nic.isDefaultNic()) {
            buf.append(" gateway=").append(nic.getIPv4Gateway());
        }
        if (nic.getTrafficType() == TrafficType.Management) {
            String mgmt_cidr = _configDao.getValue(Config.ManagementNetwork.key());
            if (NetUtils.isValidCIDR(mgmt_cidr)) {
                buf.append(" mgmtcidr=").append(mgmt_cidr);
            }
            buf.append(" localgw=").append(dest.getPod().getGateway());
            buf.append(" private.network.device=").append("eth").append(deviceId);
        } else if (nic.getTrafficType() == TrafficType.Public) {
            buf.append(" public.network.device=").append("eth").append(deviceId);
        } else if (nic.getTrafficType() == TrafficType.Storage) {
            buf.append(" storageip=").append(nic.getIPv4Address());
            buf.append(" storagenetmask=").append(nic.getIPv4Netmask());
            buf.append(" storagegateway=").append(nic.getIPv4Gateway());
        }
    }
    /* External DHCP mode */
    if (externalDhcp) {
        buf.append(" bootproto=dhcp");
    }
    DataCenterVO dc = _dcDao.findById(profile.getVirtualMachine().getDataCenterId());
    buf.append(" internaldns1=").append(dc.getInternalDns1());
    if (dc.getInternalDns2() != null) {
        buf.append(" internaldns2=").append(dc.getInternalDns2());
    }
    buf.append(" dns1=").append(dc.getDns1());
    if (dc.getDns2() != null) {
        buf.append(" dns2=").append(dc.getDns2());
    }
    Integer nfsVersion = imageStoreDetailsUtil != null ? imageStoreDetailsUtil.getNfsVersion(secStore.getId()) : null;
    buf.append(" nfsVersion=").append(nfsVersion);
    String bootArgs = buf.toString();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Boot Args for " + profile + ": " + bootArgs);
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) NicProfile(com.cloud.vm.NicProfile)

Example 18 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method createSecStorageVmInstance.

protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, SecondaryStorageVm.Role role) {
    DataStore secStore = _dataStoreMgr.getImageStore(dataCenterId);
    if (secStore == null) {
        String msg = "No secondary storage available in zone " + dataCenterId + ", cannot create secondary storage vm";
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    long id = _secStorageVmDao.getNextInSequence(Long.class, "id");
    String name = VirtualMachineName.getSystemVmName(id, _instance, "s").intern();
    Account systemAcct = _accountMgr.getSystemAccount();
    DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
    DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    NetworkVO defaultNetwork = getDefaultNetworkForCreation(dc);
    List<? extends NetworkOffering> offerings = null;
    if (_sNwMgr.isStorageIpRangeAvailable(dataCenterId)) {
        offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork, NetworkOffering.SystemStorageNetwork);
    } else {
        offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork);
    }
    LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<Network, List<? extends NicProfile>>(offerings.size() + 1);
    NicProfile defaultNic = new NicProfile();
    defaultNic.setDefaultNic(true);
    defaultNic.setDeviceId(2);
    try {
        networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic)));
        for (NetworkOffering offering : offerings) {
            networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), new ArrayList<NicProfile>());
        }
    } catch (ConcurrentOperationException e) {
        s_logger.info("Unable to setup due to concurrent operation. " + e);
        return new HashMap<String, Object>();
    }
    VMTemplateVO template = null;
    HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId);
    template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor);
    if (template == null) {
        throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
    }
    ServiceOfferingVO serviceOffering = _serviceOffering;
    if (serviceOffering == null) {
        serviceOffering = _offeringDao.findDefaultSystemOffering(ServiceOffering.ssvmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId));
    }
    SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), _accountMgr.getSystemUser().getId(), role, serviceOffering.getOfferHA());
    secStorageVm.setDynamicallyScalable(template.isDynamicallyScalable());
    secStorageVm = _secStorageVmDao.persist(secStorageVm);
    try {
        _itMgr.allocate(name, template, serviceOffering, networks, plan, null);
        secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
    } catch (InsufficientCapacityException e) {
        s_logger.warn("InsufficientCapacity", e);
        throw new CloudRuntimeException("Insufficient capacity exception", e);
    }
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("secStorageVmId", secStorageVm.getId());
    return context;
}
Also used : Account(com.cloud.user.Account) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) VMTemplateVO(com.cloud.storage.VMTemplateVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) LinkedHashMap(java.util.LinkedHashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) NetworkOffering(com.cloud.offering.NetworkOffering) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) DataCenter(com.cloud.dc.DataCenter)

Example 19 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method generateFirewallConfiguration.

@Override
public boolean generateFirewallConfiguration(Long ssAHostId) {
    if (ssAHostId == null) {
        return true;
    }
    HostVO ssAHost = _hostDao.findById(ssAHostId);
    SecondaryStorageVmVO thisSecStorageVm = _secStorageVmDao.findByInstanceName(ssAHost.getName());
    if (thisSecStorageVm == null) {
        s_logger.warn("secondary storage VM " + ssAHost.getName() + " doesn't exist");
        return false;
    }
    String copyPort = _useSSlCopy ? "443" : Integer.toString(TemplateConstants.DEFAULT_TMPLT_COPY_PORT);
    SecStorageFirewallCfgCommand thiscpc = new SecStorageFirewallCfgCommand(true);
    thiscpc.addPortConfig(thisSecStorageVm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
    QueryBuilder<HostVO> sc = QueryBuilder.create(HostVO.class);
    sc.and(sc.entity().getType(), Op.EQ, Host.Type.SecondaryStorageVM);
    sc.and(sc.entity().getStatus(), Op.IN, Status.Up, Status.Connecting);
    List<HostVO> ssvms = sc.list();
    for (HostVO ssvm : ssvms) {
        if (ssvm.getId() == ssAHostId) {
            continue;
        }
        Answer answer = _agentMgr.easySend(ssvm.getId(), thiscpc);
        if (answer != null && answer.getResult()) {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Successfully programmed firewall rules into SSVM " + ssvm.getName());
            }
        } else {
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("failed to program firewall rules into secondary storage vm : " + ssvm.getName());
            }
            return false;
        }
    }
    SecStorageFirewallCfgCommand allSSVMIpList = new SecStorageFirewallCfgCommand(false);
    for (HostVO ssvm : ssvms) {
        if (ssvm.getId() == ssAHostId) {
            continue;
        }
        allSSVMIpList.addPortConfig(ssvm.getPublicIpAddress(), copyPort, true, TemplateConstants.DEFAULT_TMPLT_COPY_INTF);
    }
    Answer answer = _agentMgr.easySend(ssAHostId, allSSVMIpList);
    if (answer != null && answer.getResult()) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Successfully programmed firewall rules into " + thisSecStorageVm.getHostName());
        }
    } else {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("failed to program firewall rules into secondary storage vm : " + thisSecStorageVm.getHostName());
        }
        return false;
    }
    return true;
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) Answer(com.cloud.agent.api.Answer) SecStorageSetupAnswer(com.cloud.agent.api.SecStorageSetupAnswer) SecStorageFirewallCfgCommand(com.cloud.agent.api.SecStorageFirewallCfgCommand) HostVO(com.cloud.host.HostVO)

Example 20 with SecondaryStorageVmVO

use of com.cloud.vm.SecondaryStorageVmVO in project cloudstack by apache.

the class SecondaryStorageManagerImpl method finalizeExpunge.

@Override
public void finalizeExpunge(VirtualMachine vm) {
    SecondaryStorageVmVO ssvm = _secStorageVmDao.findByUuid(vm.getUuid());
    ssvm.setPublicIpAddress(null);
    ssvm.setPublicMacAddress(null);
    ssvm.setPublicNetmask(null);
    _secStorageVmDao.update(ssvm.getId(), ssvm);
}
Also used : SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO)

Aggregations

SecondaryStorageVmVO (com.cloud.vm.SecondaryStorageVmVO)27 HostVO (com.cloud.host.HostVO)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 Answer (com.cloud.agent.api.Answer)7 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)6 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)5 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)5 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)5 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)5 SecStorageSetupAnswer (com.cloud.agent.api.SecStorageSetupAnswer)4 ArrayList (java.util.ArrayList)4 ConfigurationException (javax.naming.ConfigurationException)4 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)3 SecStorageVmAlertEventArgs (com.cloud.storage.secondary.SecStorageVmAlertEventArgs)3 Account (com.cloud.user.Account)3 Pair (com.cloud.utils.Pair)3 DB (com.cloud.utils.db.DB)3 NicProfile (com.cloud.vm.NicProfile)3 URISyntaxException (java.net.URISyntaxException)3