Search in sources :

Example 1 with SetupCertificateAnswer

use of org.apache.cloudstack.ca.SetupCertificateAnswer in project cloudstack by apache.

the class Agent method setupAgentCertificate.

private Answer setupAgentCertificate(final SetupCertificateCommand cmd) {
    final String certificate = cmd.getCertificate();
    final String privateKey = cmd.getPrivateKey();
    final String caCertificates = cmd.getCaCertificates();
    s_logger.debug("Importing received certificate to agent's keystore");
    final File agentFile = PropertiesUtil.findConfigFile("agent.properties");
    if (agentFile == null) {
        return new Answer(cmd, false, "Failed to find agent.properties file");
    }
    final String keyStoreFile = agentFile.getParent() + "/" + KeyStoreUtils.KS_FILENAME;
    final String certFile = agentFile.getParent() + "/" + KeyStoreUtils.CERT_FILENAME;
    final String privateKeyFile = agentFile.getParent() + "/" + KeyStoreUtils.PKEY_FILENAME;
    final String caCertFile = agentFile.getParent() + "/" + KeyStoreUtils.CACERT_FILENAME;
    try {
        FileUtils.writeStringToFile(new File(certFile), certificate, Charset.defaultCharset());
        FileUtils.writeStringToFile(new File(caCertFile), caCertificates, Charset.defaultCharset());
        s_logger.debug("Saved received client certificate to: " + certFile);
    } catch (IOException e) {
        throw new CloudRuntimeException("Unable to save received agent client and ca certificates", e);
    }
    Script script = new Script(_keystoreCertImportPath, 300000, s_logger);
    script.add(agentFile.getAbsolutePath());
    script.add(keyStoreFile);
    script.add(KeyStoreUtils.AGENT_MODE);
    script.add(certFile);
    script.add("");
    script.add(caCertFile);
    script.add("");
    script.add(privateKeyFile);
    script.add(privateKey);
    String result = script.execute();
    if (result != null) {
        throw new CloudRuntimeException("Unable to import certificate into keystore file");
    }
    return new SetupCertificateAnswer(true);
}
Also used : SetupKeystoreAnswer(org.apache.cloudstack.ca.SetupKeystoreAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) SetupMSListAnswer(org.apache.cloudstack.agent.lb.SetupMSListAnswer) StartupAnswer(com.cloud.agent.api.StartupAnswer) SetupCertificateAnswer(org.apache.cloudstack.ca.SetupCertificateAnswer) Script(com.cloud.utils.script.Script) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) File(java.io.File) SetupCertificateAnswer(org.apache.cloudstack.ca.SetupCertificateAnswer)

Example 2 with SetupCertificateAnswer

use of org.apache.cloudstack.ca.SetupCertificateAnswer in project cloudstack by apache.

the class VirtualRoutingResource method execute.

private Answer execute(final SetupCertificateCommand cmd) {
    final String args = String.format("/usr/local/cloud/systemvm/conf/agent.properties " + "/usr/local/cloud/systemvm/conf/%s %s " + "/usr/local/cloud/systemvm/conf/%s \"%s\" " + "/usr/local/cloud/systemvm/conf/%s \"%s\" " + "/usr/local/cloud/systemvm/conf/%s \"%s\"", KeyStoreUtils.KS_FILENAME, KeyStoreUtils.SSH_MODE, KeyStoreUtils.CERT_FILENAME, cmd.getEncodedCertificate(), KeyStoreUtils.CACERT_FILENAME, cmd.getEncodedCaCertificates(), KeyStoreUtils.PKEY_FILENAME, cmd.getEncodedPrivateKey());
    ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), KeyStoreUtils.KS_IMPORT_SCRIPT, args, Duration.standardMinutes(15));
    return new SetupCertificateAnswer(result.isSuccess());
}
Also used : ExecutionResult(com.cloud.utils.ExecutionResult) SetupCertificateAnswer(org.apache.cloudstack.ca.SetupCertificateAnswer)

Example 3 with SetupCertificateAnswer

use of org.apache.cloudstack.ca.SetupCertificateAnswer in project cloudstack by apache.

the class LibvirtPostCertificateRenewalCommandWrapper method execute.

@Override
public Answer execute(final PostCertificateRenewalCommand command, final LibvirtComputingResource serverResource) {
    s_logger.info("Restarting libvirt after certificate provisioning/renewal");
    if (command != null) {
        final int timeout = 30000;
        Script script = new Script(true, "service", timeout, s_logger);
        script.add("libvirtd");
        script.add("restart");
        script.execute();
        return new SetupCertificateAnswer(true);
    }
    return new SetupCertificateAnswer(false);
}
Also used : Script(com.cloud.utils.script.Script) SetupCertificateAnswer(org.apache.cloudstack.ca.SetupCertificateAnswer)

Aggregations

SetupCertificateAnswer (org.apache.cloudstack.ca.SetupCertificateAnswer)3 Script (com.cloud.utils.script.Script)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 Answer (com.cloud.agent.api.Answer)1 MaintainAnswer (com.cloud.agent.api.MaintainAnswer)1 StartupAnswer (com.cloud.agent.api.StartupAnswer)1 ExecutionResult (com.cloud.utils.ExecutionResult)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 File (java.io.File)1 IOException (java.io.IOException)1 SetupMSListAnswer (org.apache.cloudstack.agent.lb.SetupMSListAnswer)1 SetupKeystoreAnswer (org.apache.cloudstack.ca.SetupKeystoreAnswer)1