String publicKey = keyPair.get("public");
String privateKey = keyPair.get("private");
logger.debug(">> creating key datacenter(%s) prefix(%s)", datacenterId, prefix);
Key key = null;
while (key == null) {
String name = namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix);
try {
key = cloudApiApi.getKeyApi().create(Key.builder().name(name).key(publicKey).build());
} catch (IllegalStateException e) {
logger.trace("error creating keypair named %s, %s", name, e.getMessage());
}
}
logger.debug("<< created key(%s)", key.getName());
return KeyAndPrivateKey.fromKeyAndPrivateKey(key, privateKey);
}