public void execute(CloudStackClient cloudStackClient, Pool pool, DelegateExecution execution) {
String keyName = KeyPairs.formatNameFromBusinessKey(execution.getProcessBusinessKey());
LOG.info("Creating admin access key pair as {}", keyName);
SSHKeyPairClient sshKeyPairClient = cloudStackClient.getSSHKeyPairClient();
try {
SshKeyPair sshKeyPair = sshKeyPairClient.registerSSHKeyPair(keyName, pool.getAdminAccess().getPublicKey());
LOG.info("Registered remote key with fingerprint {}", sshKeyPair.getFingerprint());
} catch (IllegalStateException e) {
LOG.warn("Key with name {} already exists", keyName);
SshKeyPair key = sshKeyPairClient.getSSHKeyPair(keyName);
if (key.getFingerprint().equals(SshKeys.fingerprintPublicKey(pool.getAdminAccess().getPublicKey()))) {
LOG.info("Fingerprints match. Not updating admin access key pair.");
} else {
LOG.info("Fingerprint do not match. Replacing admin access key pair.");
sshKeyPairClient.deleteSSHKeyPair(keyName);
sshKeyPairClient.registerSSHKeyPair(keyName, pool.getAdminAccess().getPublicKey());