Search in sources :

Example 1 with SetupKeystoreAnswer

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

the class Agent method setupAgentKeystore.

public Answer setupAgentKeystore(final SetupKeyStoreCommand cmd) {
    final String keyStorePassword = cmd.getKeystorePassword();
    final long validityDays = cmd.getValidityDays();
    s_logger.debug("Setting up agent keystore file and generating CSR");
    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 csrFile = agentFile.getParent() + "/" + KeyStoreUtils.CSR_FILENAME;
    String storedPassword = _shell.getPersistentProperty(null, KeyStoreUtils.KS_PASSPHRASE_PROPERTY);
    if (StringUtils.isEmpty(storedPassword)) {
        storedPassword = keyStorePassword;
        _shell.setPersistentProperty(null, KeyStoreUtils.KS_PASSPHRASE_PROPERTY, storedPassword);
    }
    Script script = new Script(_keystoreSetupPath, 300000, s_logger);
    script.add(agentFile.getAbsolutePath());
    script.add(keyStoreFile);
    script.add(storedPassword);
    script.add(String.valueOf(validityDays));
    script.add(csrFile);
    String result = script.execute();
    if (result != null) {
        throw new CloudRuntimeException("Unable to setup keystore file");
    }
    final String csrString;
    try {
        csrString = FileUtils.readFileToString(new File(csrFile), Charset.defaultCharset());
    } catch (IOException e) {
        throw new CloudRuntimeException("Unable to read generated CSR file", e);
    }
    return new SetupKeystoreAnswer(csrString);
}
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) SetupKeystoreAnswer(org.apache.cloudstack.ca.SetupKeystoreAnswer) IOException(java.io.IOException) File(java.io.File)

Example 2 with SetupKeystoreAnswer

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

the class VirtualRoutingResource method execute.

private Answer execute(final SetupKeyStoreCommand cmd) {
    final String args = String.format("/usr/local/cloud/systemvm/conf/agent.properties " + "/usr/local/cloud/systemvm/conf/%s " + "%s %d " + "/usr/local/cloud/systemvm/conf/%s", KeyStoreUtils.KS_FILENAME, cmd.getKeystorePassword(), cmd.getValidityDays(), KeyStoreUtils.CSR_FILENAME);
    ExecutionResult result = _vrDeployer.executeInVR(cmd.getRouterAccessIp(), KeyStoreUtils.KS_SETUP_SCRIPT, args, Duration.standardMinutes(15));
    return new SetupKeystoreAnswer(result.getDetails());
}
Also used : SetupKeystoreAnswer(org.apache.cloudstack.ca.SetupKeystoreAnswer) ExecutionResult(com.cloud.utils.ExecutionResult)

Aggregations

SetupKeystoreAnswer (org.apache.cloudstack.ca.SetupKeystoreAnswer)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 Script (com.cloud.utils.script.Script)1 File (java.io.File)1 IOException (java.io.IOException)1 SetupMSListAnswer (org.apache.cloudstack.agent.lb.SetupMSListAnswer)1 SetupCertificateAnswer (org.apache.cloudstack.ca.SetupCertificateAnswer)1