Search in sources :

Example 31 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method handleAgentDisconnect.

public void handleAgentDisconnect(long agentId, com.cloud.host.Status state) {
    if (state == com.cloud.host.Status.Alert || state == com.cloud.host.Status.Disconnected) {
        HostVO host = hostDao.findById(agentId);
        if (host.getType() == Type.ConsoleProxy) {
            String name = host.getName();
            if (s_logger.isInfoEnabled()) {
                s_logger.info("Console proxy agent disconnected, proxy: " + name);
            }
            if (name != null && name.startsWith("v-")) {
                String[] tokens = name.split("-");
                long proxyVmId;
                try {
                    proxyVmId = Long.parseLong(tokens[1]);
                } catch (NumberFormatException e) {
                    s_logger.error("Unexpected exception " + e.getMessage(), e);
                    return;
                }
                final ConsoleProxyVO proxy = consoleProxyDao.findById(proxyVmId);
                if (proxy == null && s_logger.isInfoEnabled()) {
                    s_logger.info("Console proxy agent disconnected but corresponding console proxy VM no longer exists in DB, proxy: " + name);
                }
            } else {
                assert (false) : "Invalid console proxy name: " + name;
            }
        }
    }
}
Also used : ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) HostVO(com.cloud.host.HostVO)

Example 32 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method finalizeDeployment.

@Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
    finalizeCommandsOnStart(cmds, profile);
    ConsoleProxyVO proxy = consoleProxyDao.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()))) {
            proxy.setPublicIpAddress(nic.getIPv4Address());
            proxy.setPublicNetmask(nic.getIPv4Netmask());
            proxy.setPublicMacAddress(nic.getMacAddress());
        } else if (nic.getTrafficType() == TrafficType.Management) {
            proxy.setPrivateIpAddress(nic.getIPv4Address());
            proxy.setPrivateMacAddress(nic.getMacAddress());
        }
    }
    consoleProxyDao.update(proxy.getId(), proxy);
    return true;
}
Also used : DataCenter(com.cloud.dc.DataCenter) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) NicProfile(com.cloud.vm.NicProfile)

Example 33 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method assignProxy.

@Override
public ConsoleProxyInfo assignProxy(final long dataCenterId, final long vmId) {
    ConsoleProxyVO proxy = doAssignProxy(dataCenterId, vmId);
    if (proxy == null) {
        return null;
    }
    if (proxy.getPublicIpAddress() == null) {
        s_logger.warn(String.format("Assigned console proxy [%s] does not have a valid public IP address.", proxy.toString()));
        return null;
    }
    KeystoreVO ksVo = _ksDao.findByName(ConsoleProxyManager.CERTIFICATE_NAME);
    if (proxy.isSslEnabled() && ksVo == null) {
        s_logger.warn(String.format("SSL is enabled for console proxy [%s] but no server certificate found in database.", proxy.toString()));
    }
    if (staticPublicIp == null) {
        return new ConsoleProxyInfo(proxy.isSslEnabled(), proxy.getPublicIpAddress(), consoleProxyPort, proxy.getPort(), consoleProxyUrlDomain);
    } else {
        return new ConsoleProxyInfo(proxy.isSslEnabled(), staticPublicIp, consoleProxyPort, staticPort, consoleProxyUrlDomain);
    }
}
Also used : ConsoleProxyInfo(com.cloud.info.ConsoleProxyInfo) KeystoreVO(org.apache.cloudstack.framework.security.keystore.KeystoreVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO)

Example 34 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method finalizeVirtualMachineProfile.

@Override
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
    ConsoleProxyVO vm = consoleProxyDao.findById(profile.getId());
    Map<String, String> details = userVmDetailsDao.listDetailsKeyPairs(vm.getId());
    vm.setDetails(details);
    StringBuilder buf = profile.getBootArgsBuilder();
    buf.append(" template=domP type=consoleproxy");
    buf.append(" host=").append(StringUtils.toCSVList(indirectAgentLB.getManagementServerList(dest.getHost().getId(), dest.getDataCenter().getId(), null)));
    buf.append(" port=").append(managementPort);
    buf.append(" name=").append(profile.getVirtualMachine().getHostName());
    if (sslEnabled) {
        buf.append(" premium=true");
    }
    buf.append(" zone=").append(dest.getDataCenter().getId());
    buf.append(" pod=").append(dest.getPod().getId());
    buf.append(" guid=Proxy.").append(profile.getId());
    buf.append(" proxy_vm=").append(profile.getId());
    if (disableRpFilter) {
        buf.append(" disable_rp_filter=true");
    }
    String msPublicKey = configurationDao.getValue("ssh.publickey");
    buf.append(" authorized_key=").append(VirtualMachineGuru.getEncodedMsPublicKey(msPublicKey));
    boolean externalDhcp = false;
    String externalDhcpStr = configurationDao.getValue("direct.attach.network.externalIpAllocator.enabled");
    if (externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) {
        externalDhcp = true;
    }
    if (Boolean.valueOf(configurationDao.getValue("system.vm.random.password"))) {
        buf.append(" vmpassword=").append(configurationDao.getValue("system.vm.password"));
    }
    for (NicProfile nic : profile.getNics()) {
        int deviceId = nic.getDeviceId();
        if (nic.getIPv4Address() == null) {
            buf.append(" eth").append(deviceId).append("ip=").append("0.0.0.0");
            buf.append(" eth").append(deviceId).append("mask=").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 = configurationDao.getValue(Config.ManagementNetwork.key());
            if (NetUtils.isValidCidrList(mgmt_cidr)) {
                s_logger.debug("Management server cidr list is " + mgmt_cidr);
                buf.append(" mgmtcidr=").append(mgmt_cidr);
            } else {
                s_logger.error("Invalid management cidr list: " + mgmt_cidr);
            }
            buf.append(" localgw=").append(dest.getPod().getGateway());
        }
    }
    if (externalDhcp) {
        buf.append(" bootproto=dhcp");
    }
    DataCenterVO dc = dataCenterDao.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());
    }
    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) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) NicProfile(com.cloud.vm.NicProfile)

Example 35 with ConsoleProxyVO

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

the class ConsoleProxyManagerImpl method allocCapacity.

private void allocCapacity(long dataCenterId) {
    if (s_logger.isDebugEnabled()) {
        s_logger.debug(String.format("Allocating console proxy standby capacity for zone [%s].", dataCenterId));
    }
    ConsoleProxyVO proxy = null;
    String errorString = null;
    try {
        boolean consoleProxyVmFromStoppedPool = false;
        proxy = assignProxyFromStoppedPool(dataCenterId);
        if (proxy == null) {
            if (s_logger.isInfoEnabled()) {
                s_logger.info("No stopped console proxy is available, need to allocate a new console proxy");
            }
            if (allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC_IN_SECONDS)) {
                try {
                    proxy = startNew(dataCenterId);
                } catch (ConcurrentOperationException e) {
                    s_logger.warn(String.format("Unable to start new console proxy on zone [%s] due to [%s].", dataCenterId, e.getMessage()), e);
                } finally {
                    allocProxyLock.unlock();
                }
            } else {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Unable to acquire synchronization lock for console proxy vm allocation, wait for next scan");
                }
            }
        } else {
            if (s_logger.isInfoEnabled()) {
                s_logger.info("Found a stopped console proxy, starting it. Vm id : " + proxy.getId());
            }
            consoleProxyVmFromStoppedPool = true;
        }
        if (proxy != null) {
            long proxyVmId = proxy.getId();
            proxy = startProxy(proxyVmId, false);
            if (proxy != null) {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Console proxy " + proxy.getHostName() + " is started");
                }
                SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_UP, dataCenterId, proxy.getId(), proxy, null));
            } else {
                if (s_logger.isInfoEnabled()) {
                    s_logger.info("Unable to start console proxy vm for standby capacity, vm id : " + proxyVmId + ", will recycle it and start a new one");
                }
                if (consoleProxyVmFromStoppedPool) {
                    destroyProxy(proxyVmId);
                }
            }
        }
    } catch (Exception e) {
        errorString = e.getMessage();
        s_logger.warn(String.format("Unable to allocate console proxy standby capacity for zone [%s] due to [%s].", dataCenterId, e.getMessage()), e);
        throw e;
    } finally {
        if (proxy == null || proxy.getState() != State.Running)
            SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_CREATE_FAILURE, dataCenterId, 0l, null, errorString));
    }
}
Also used : ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) JsonParseException(com.google.gson.JsonParseException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException)

Aggregations

ConsoleProxyVO (com.cloud.vm.ConsoleProxyVO)41 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 NicProfile (com.cloud.vm.NicProfile)9 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)8 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 HostVO (com.cloud.host.HostVO)8 Answer (com.cloud.agent.api.Answer)7 Account (com.cloud.user.Account)7 VMInstanceVO (com.cloud.vm.VMInstanceVO)7 ArrayList (java.util.ArrayList)7 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)6 CheckSshAnswer (com.cloud.agent.api.check.CheckSshAnswer)5 HostPodVO (com.cloud.dc.HostPodVO)5 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)5 Network (com.cloud.network.Network)5 NetworkOffering (com.cloud.offering.NetworkOffering)5 VMTemplateVO (com.cloud.storage.VMTemplateVO)5 ModifyStoragePoolCommand (com.cloud.agent.api.ModifyStoragePoolCommand)4 Zone (com.cloud.db.model.Zone)4 DataCenter (com.cloud.dc.DataCenter)4