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);
}
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);
}
Aggregations