Search in sources :

Example 1 with Connection

use of com.cloud.hypervisor.ovm3.objects.Connection in project cloudstack by apache.

the class Ovm3StoragePool method addMembers.

/**
 * Adding members to a pool, this is seperate from cluster configuration in
 * OVM.
 *
 * @return
 * @throws Ovm3ResourceException
 */
private Boolean addMembers() throws Ovm3ResourceException {
    List<String> members = new ArrayList<String>();
    try {
        Connection m = new Connection(config.getOvm3PoolVip(), c.getPort(), c.getUserName(), c.getPassword());
        Pool poolPrimary = new Pool(m);
        if (poolPrimary.isInAPool()) {
            members.addAll(poolPrimary.getPoolMemberList());
            if (!poolPrimary.getPoolMemberList().contains(c.getIp()) && c.getIp().equals(config.getOvm3PoolVip())) {
                members.add(c.getIp());
            }
        } else {
            LOGGER.warn(c.getIp() + " noticed primary " + config.getOvm3PoolVip() + " is not part of pool");
            return false;
        }
        /* a cluster shares usernames and passwords */
        for (String member : members) {
            Connection x = new Connection(member, c.getPort(), c.getUserName(), c.getPassword());
            Pool poolM = new Pool(x);
            if (poolM.isInAPool()) {
                poolM.setPoolMemberList(members);
                LOGGER.debug("Added " + members + " to pool " + poolM.getPoolId() + " on member " + member);
            } else {
                LOGGER.warn(member + " unable to be member of a pool it's not in");
                return false;
            }
        }
    } catch (Exception e) {
        throw new Ovm3ResourceException("Unable to add members: " + e.getMessage(), e);
    }
    return true;
}
Also used : Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) ArrayList(java.util.ArrayList) Connection(com.cloud.hypervisor.ovm3.objects.Connection) Pool(com.cloud.hypervisor.ovm3.objects.Pool) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 2 with Connection

use of com.cloud.hypervisor.ovm3.objects.Connection in project cloudstack by apache.

the class Ovm3Discoverer method find.

@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) throws DiscoveryException {
    Connection c = null;
    CheckUrl(url);
    if (clusterId == null) {
        String msg = "must specify cluster Id when add host";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    }
    if (podId == null) {
        String msg = "must specify pod Id when add host";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    }
    ClusterVO cluster = clusterDao.findById(clusterId);
    if (cluster == null || (cluster.getHypervisorType() != HypervisorType.Ovm3)) {
        String msg = "invalid cluster id or cluster is not for Ovm3 hypervisors";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    } else {
        LOGGER.debug("cluster: " + cluster);
    }
    String agentUsername = _params.get("agentusername");
    if (agentUsername == null) {
        String msg = "Agent user name must be specified";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    }
    String agentPassword = _params.get("agentpassword");
    if (agentPassword == null) {
        String msg = "Agent password must be specified";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    }
    String agentPort = _params.get("agentport");
    if (agentPort == null) {
        String msg = "Agent port must be specified";
        LOGGER.info(msg);
        throw new DiscoveryException(msg);
    }
    try {
        String hostname = url.getHost();
        InetAddress ia = InetAddress.getByName(hostname);
        String hostIp = ia.getHostAddress();
        String guid = UUID.nameUUIDFromBytes(hostIp.getBytes("UTF8")).toString();
        if (checkIfExisted(guid)) {
            String msg = "The host " + hostIp + " has been added before";
            LOGGER.info(msg);
            throw new DiscoveryException(msg);
        }
        LOGGER.debug("Ovm3 discover is going to disover host having guid " + guid);
        ClusterVO clu = clusterDao.findById(clusterId);
        if (clu.getGuid() == null) {
            clu.setGuid(UUID.randomUUID().toString());
        }
        clusterDao.update(clusterId, clu);
        Map<String, String> clusterDetails = clusterDetailsDao.findDetails(clusterId);
        String ovm3vip = (clusterDetails.get("ovm3vip") == null) ? "" : clusterDetails.get("ovm3vip");
        String ovm3pool = (clusterDetails.get("ovm3pool") == null) ? "false" : clusterDetails.get("ovm3pool");
        String ovm3cluster = (clusterDetails.get("ovm3cluster") == null) ? "false" : clusterDetails.get("ovm3cluster");
        /* should perhaps only make this connect to the agent port ? */
        com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(hostIp, 22);
        sshConnection.connect(null, 60000, 60000);
        sshConnection = SSHCmdHelper.acquireAuthorizedConnection(hostIp, username, password);
        if (sshConnection == null) {
            String msg = "Cannot Ssh to Ovm3 host(IP=" + hostIp + ", username=" + username + ", password=*******), discovery failed";
            LOGGER.warn(msg);
            throw new DiscoveryException(msg);
        }
        Map<String, String> details = new HashMap<String, String>();
        Ovm3HypervisorResource ovmResource = new Ovm3HypervisorResource();
        details.put("ip", hostIp);
        details.put("host", hostname);
        details.put("username", username);
        details.put("password", password);
        details.put("zone", Long.toString(dcId));
        details.put("guid", guid);
        details.put("pod", Long.toString(podId));
        details.put("cluster", Long.toString(clusterId));
        details.put("agentusername", agentUsername);
        details.put("agentpassword", agentPassword);
        details.put("agentport", agentPort.toString());
        details.put("ovm3vip", ovm3vip);
        details.put("ovm3pool", ovm3pool);
        details.put("ovm3cluster", ovm3cluster);
        if (publicNetworkDevice != null) {
            details.put("public.network.device", publicNetworkDevice);
        }
        if (privateNetworkDevice != null) {
            details.put("private.network.device", privateNetworkDevice);
        }
        if (guestNetworkDevice != null) {
            details.put("guest.network.device", guestNetworkDevice);
        }
        if (storageNetworkDevice != null) {
            details.put("storage.network.device", storageNetworkDevice);
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.putAll(details);
        ovmResource.configure(hostname, params);
        ovmResource.start();
        c = new Connection(hostIp, Integer.parseInt(agentPort), agentUsername, agentPassword);
        /* After resource start, we are able to execute our agent api */
        Linux host = new Linux(c);
        details.put("agentVersion", host.getAgentVersion());
        details.put(HostInfo.HOST_OS_KERNEL_VERSION, host.getHostKernelRelease());
        details.put(HostInfo.HOST_OS, host.getHostOs());
        details.put(HostInfo.HOST_OS_VERSION, host.getHostOsVersion());
        details.put(HostInfo.HYPERVISOR_VERSION, host.getHypervisorVersion());
        Map<Ovm3HypervisorResource, Map<String, String>> resources = new HashMap<Ovm3HypervisorResource, Map<String, String>>();
        resources.put(ovmResource, details);
        return resources;
    } catch (UnknownHostException e) {
        LOGGER.error("Host name resolve failed exception, Unable to discover Ovm3 host: " + url.getHost(), e);
        return null;
    } catch (ConfigurationException e) {
        LOGGER.error("Configure resource failed, Unable to discover Ovm3 host: " + url.getHost(), e);
        return null;
    } catch (IOException | Ovm3ResourceException e) {
        LOGGER.error("Unable to discover Ovm3 host: " + url.getHost(), e);
        return null;
    }
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) Connection(com.cloud.hypervisor.ovm3.objects.Connection) IOException(java.io.IOException) Linux(com.cloud.hypervisor.ovm3.objects.Linux) ConfigurationException(javax.naming.ConfigurationException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) DiscoveryException(com.cloud.exception.DiscoveryException) InetAddress(java.net.InetAddress) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Connection

use of com.cloud.hypervisor.ovm3.objects.Connection in project cloudstack by apache.

the class Ovm3HypervisorSupport method setupServer.

/**
 * setupServer:
 * Add the cloudstack plugin and setup the agent.
 * Add the ssh keys to the host.
 *
 * @param c
 * @throws IOException
 */
public Boolean setupServer(String key) throws IOException {
    LOGGER.debug("Setup all bits on agent: " + config.getAgentHostname());
    /* version dependent patching ? */
    try {
        com.trilead.ssh2.Connection sshConnection = SSHCmdHelper.acquireAuthorizedConnection(config.getAgentIp(), config.getAgentSshUserName(), config.getAgentSshPassword());
        if (sshConnection == null) {
            throw new ConfigurationException(String.format("Unable to " + "connect to server(IP=%1$s, username=%2$s, " + "password=%3$s", config.getAgentIp(), config.getAgentSshUserName(), config.getAgentSshPassword()));
        }
        SCPClient scp = new SCPClient(sshConnection);
        String userDataScriptDir = "scripts/vm/hypervisor/ovm3/";
        String userDataScriptPath = Script.findScript("", userDataScriptDir);
        if (userDataScriptPath == null) {
            throw new ConfigurationException("Can not find " + userDataScriptDir);
        }
        String mkdir = "mkdir -p " + config.getAgentScriptsDir();
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, mkdir)) {
            throw new ConfigurationException("Failed " + mkdir + " on " + config.getAgentHostname());
        }
        for (String script : config.getAgentScripts()) {
            script = userDataScriptPath + "/" + script;
            scp.put(script, config.getAgentScriptsDir(), "0755");
        }
        String prepareCmd = String.format(config.getAgentScriptsDir() + "/" + config.getAgentScript() + " --ssl=" + c.getUseSsl() + " " + "--port=" + c.getPort());
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, prepareCmd)) {
            throw new ConfigurationException("Failed to insert module on " + config.getAgentHostname());
        } else {
            /* because of OVM 3.3.1 (might be 2000) */
            Thread.sleep(5000);
        }
        CloudstackPlugin cSp = new CloudstackPlugin(c);
        cSp.ovsUploadSshKey(config.getAgentSshKeyFileName(), FileUtils.readFileToString(getSystemVMKeyFile(key)));
        cSp.dom0CheckStorageHealthCheck(config.getAgentScriptsDir(), config.getAgentCheckStorageScript(), config.getCsHostGuid(), config.getAgentStorageCheckTimeout(), config.getAgentStorageCheckInterval());
    } catch (Exception es) {
        LOGGER.error("Unexpected exception ", es);
        String msg = "Unable to install module in agent";
        throw new CloudRuntimeException(msg);
    }
    return true;
}
Also used : SCPClient(com.trilead.ssh2.SCPClient) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CloudstackPlugin(com.cloud.hypervisor.ovm3.objects.CloudstackPlugin) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 4 with Connection

use of com.cloud.hypervisor.ovm3.objects.Connection in project cloudstack by apache.

the class Ovm3HypervisorResource method initialize.

/*
     * configure is called before this, does setup of the connection and
     * gets the params.
     *
     * @see com.cloud.resource.ServerResource#initialize()
     */
@Override
public StartupCommand[] initialize() {
    LOGGER.debug("Ovm3 resource intializing");
    try {
        StartupRoutingCommand srCmd = new StartupRoutingCommand();
        StartupStorageCommand ssCmd = new StartupStorageCommand();
        /* here stuff gets completed, but where should state live ? */
        hypervisorsupport.fillHostInfo(srCmd);
        hypervisorsupport.vmStateMapClear();
        LOGGER.debug("Ovm3 pool " + ssCmd + " " + srCmd);
        return new StartupCommand[] { srCmd, ssCmd };
    } catch (Exception e) {
        LOGGER.debug("Ovm3 resource initializes failed", e);
        return new StartupCommand[] {};
    }
}
Also used : StartupCommand(com.cloud.agent.api.StartupCommand) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)

Example 5 with Connection

use of com.cloud.hypervisor.ovm3.objects.Connection in project cloudstack by apache.

the class Ovm3HypervisorResource method configure.

/**
 * Base configuration of the plugins components.
 */
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
    LOGGER.debug("configure " + name + " with params: " + params);
    /* check if we're primary or not and if we can connect */
    try {
        configuration = new Ovm3Configuration(params);
        if (!configuration.getIsTest()) {
            c = new Connection(configuration.getAgentIp(), configuration.getAgentOvsAgentPort(), configuration.getAgentOvsAgentUser(), configuration.getAgentOvsAgentPassword());
            c.setHostName(configuration.getAgentHostname());
        }
        hypervisorsupport = new Ovm3HypervisorSupport(c, configuration);
        if (!configuration.getIsTest()) {
            hypervisorsupport.setupServer(configuration.getAgentSshKeyFileName());
        }
        hypervisorsupport.primaryCheck();
    } catch (Exception e) {
        throw new CloudRuntimeException("Base checks failed for " + configuration.getAgentHostname(), e);
    }
    hypervisornetwork = new Ovm3HypervisorNetwork(c, configuration);
    hypervisornetwork.configureNetworking();
    virtualroutingresource = new Ovm3VirtualRoutingResource(c);
    storagepool = new Ovm3StoragePool(c, configuration);
    storagepool.prepareForPool();
    storageprocessor = new Ovm3StorageProcessor(c, configuration, storagepool);
    vmsupport = new Ovm3VmSupport(c, configuration, hypervisorsupport, storageprocessor, storagepool, hypervisornetwork);
    vrResource = new VirtualRoutingResource(virtualroutingresource);
    if (!vrResource.configure(name, params)) {
        throw new ConfigurationException("Unable to configure VirtualRoutingResource");
    }
    guesttypes = new Ovm3VmGuestTypes();
    storageHandler = new StorageSubsystemCommandHandlerBase(storageprocessor);
    virtualroutingsupport = new Ovm3VirtualRoutingSupport(c, configuration, virtualroutingresource);
    setConfigParams(params);
    return true;
}
Also used : Connection(com.cloud.hypervisor.ovm3.objects.Connection) Ovm3HypervisorSupport(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3HypervisorSupport) Ovm3VirtualRoutingSupport(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3VirtualRoutingSupport) VirtualRoutingResource(com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource) StorageSubsystemCommandHandlerBase(com.cloud.storage.resource.StorageSubsystemCommandHandlerBase) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3ResourceException(com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException) Ovm3VmSupport(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3VmSupport) ConfigurationException(javax.naming.ConfigurationException) Ovm3VmGuestTypes(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3VmGuestTypes) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Ovm3StoragePool(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3StoragePool) Ovm3HypervisorNetwork(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3HypervisorNetwork) Ovm3Configuration(com.cloud.hypervisor.ovm3.resources.helpers.Ovm3Configuration)

Aggregations

Ovm3ResourceException (com.cloud.hypervisor.ovm3.objects.Ovm3ResourceException)5 ConfigurationException (javax.naming.ConfigurationException)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 Connection (com.cloud.hypervisor.ovm3.objects.Connection)3 IOException (java.io.IOException)2 StartupCommand (com.cloud.agent.api.StartupCommand)1 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)1 StartupStorageCommand (com.cloud.agent.api.StartupStorageCommand)1 VirtualRoutingResource (com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource)1 ClusterVO (com.cloud.dc.ClusterVO)1 DiscoveryException (com.cloud.exception.DiscoveryException)1 CloudstackPlugin (com.cloud.hypervisor.ovm3.objects.CloudstackPlugin)1 Linux (com.cloud.hypervisor.ovm3.objects.Linux)1 Pool (com.cloud.hypervisor.ovm3.objects.Pool)1 Ovm3Configuration (com.cloud.hypervisor.ovm3.resources.helpers.Ovm3Configuration)1 Ovm3HypervisorNetwork (com.cloud.hypervisor.ovm3.resources.helpers.Ovm3HypervisorNetwork)1 Ovm3HypervisorSupport (com.cloud.hypervisor.ovm3.resources.helpers.Ovm3HypervisorSupport)1 Ovm3StoragePool (com.cloud.hypervisor.ovm3.resources.helpers.Ovm3StoragePool)1 Ovm3VirtualRoutingSupport (com.cloud.hypervisor.ovm3.resources.helpers.Ovm3VirtualRoutingSupport)1 Ovm3VmGuestTypes (com.cloud.hypervisor.ovm3.resources.helpers.Ovm3VmGuestTypes)1