Search in sources :

Example 1 with SSHKeysHelper

use of com.cloud.utils.ssh.SSHKeysHelper in project cloudstack by apache.

the class ManagementServerImpl method createSSHKeyPair.

@Override
public SSHKeyPair createSSHKeyPair(final CreateSSHKeyPairCmd cmd) {
    final Account caller = getCaller();
    final String accountName = cmd.getAccountName();
    final Long domainId = cmd.getDomainId();
    final Long projectId = cmd.getProjectId();
    final String name = cmd.getName();
    if (StringUtils.isBlank(name)) {
        throw new InvalidParameterValueException("Please specify a valid name for the key pair. The key name can't be empty");
    }
    final Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
    final SSHKeyPairVO s = _sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), cmd.getName());
    if (s != null) {
        throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' already exists.");
    }
    final SSHKeysHelper keys = new SSHKeysHelper(sshKeyLength.value());
    final String publicKey = keys.getPublicKey();
    final String fingerprint = keys.getPublicKeyFingerPrint();
    final String privateKey = keys.getPrivateKey();
    return createAndSaveSSHKeyPair(name, fingerprint, publicKey, privateKey, owner);
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) SSHKeysHelper(com.cloud.utils.ssh.SSHKeysHelper) SSHKeyPairVO(com.cloud.user.SSHKeyPairVO)

Example 2 with SSHKeysHelper

use of com.cloud.utils.ssh.SSHKeysHelper in project cosmic by MissionCriticalCloud.

the class ManagementServerImpl method createSSHKeyPair.

@Override
public SSHKeyPair createSSHKeyPair(final CreateSSHKeyPairCmd cmd) {
    final Account caller = getCaller();
    final String accountName = cmd.getAccountName();
    final Long domainId = cmd.getDomainId();
    final Long projectId = cmd.getProjectId();
    final Account owner = _accountMgr.finalizeOwner(caller, accountName, domainId, projectId);
    final SSHKeyPairVO s = _sshKeyPairDao.findByName(owner.getAccountId(), owner.getDomainId(), cmd.getName());
    if (s != null) {
        throw new InvalidParameterValueException("A key pair with name '" + cmd.getName() + "' already exists.");
    }
    final SSHKeysHelper keys = new SSHKeysHelper();
    final String name = cmd.getName();
    final String publicKey = keys.getPublicKey();
    final String fingerprint = keys.getPublicKeyFingerPrint();
    final String privateKey = keys.getPrivateKey();
    return createAndSaveSSHKeyPair(name, fingerprint, publicKey, privateKey, owner);
}
Also used : Account(com.cloud.user.Account) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) SSHKeysHelper(com.cloud.utils.ssh.SSHKeysHelper) SSHKeyPairVO(com.cloud.user.SSHKeyPairVO)

Aggregations

Account (com.cloud.user.Account)2 SSHKeyPairVO (com.cloud.user.SSHKeyPairVO)2 SSHKeysHelper (com.cloud.utils.ssh.SSHKeysHelper)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1