use of org.openstack4j.model.compute.Keypair in project airavata by apache.
the class OpenstackIntfImpl method createKeyPair.
@Override
public Keypair createKeyPair(String keyPairName, String publicKey) {
try {
Keypair keyp = os.compute().keypairs().create(keyPairName, publicKey);
logger.info("Keypair created successfully: " + keyp.getName());
return keyp;
} catch (Exception ex) {
ex.printStackTrace();
// TODO: Check with the team on how to handle exceptions.
logger.error("Failed to create keypair: " + keyPairName);
return null;
}
}
use of org.openstack4j.model.compute.Keypair in project airavata by apache.
the class CloudIntfTest method jetstreamCreateDeleteServerTest.
/**
* Test that will create keypair, create server with keypair, delete server, delete keypair.
*/
@Test
@Ignore
public void jetstreamCreateDeleteServerTest() {
try {
CloudInterface cloudIntf = new OpenstackIntfImpl("jetstream_openrc.properties");
// Sample data. This can be determined by the inputs from Airavata.
String imageId = properties.getProperty("jetstream_imageId");
String flavorId = properties.getProperty("jetstream_flavorId");
// Delay in milliseconds used for waiting for server create and delete.
Integer delay = 30000;
/* Create Keypair */
String publicKeyFile = properties.getProperty("publicKeyFile");
String keyPairName = "testKey";
Scanner fileScan = new Scanner(new FileInputStream(publicKeyFile));
String publicKey = fileScan.nextLine();
Keypair kp = (Keypair) cloudIntf.getKeyPair(keyPairName);
if (kp == null) {
kp = (Keypair) cloudIntf.createKeyPair(keyPairName, publicKey);
}
logger.info("Keypair created/ retrieved: " + kp.getFingerprint());
/* Create Server */
Server newServer = (Server) cloudIntf.createServer("AiravataTest", imageId, flavorId, kp.getName());
logger.info("Server Created: " + newServer.getId());
/* Wait 30 seconds until server is active */
logger.info("Waiting for instance to go ACTIVE...");
Thread.sleep(delay);
/* Associate floating ip */
cloudIntf.addFloatingIP(newServer.getId());
/* Delete Server */
cloudIntf.deleteServer(newServer.getId());
logger.info("Server deleted: " + newServer.getId());
/* Wait 30 seconds until server is terminated */
logger.info("Waiting for instance to terminate...");
Thread.sleep(delay);
/* Delete Keypair */
cloudIntf.deleteKeyPair(kp.getName());
logger.info("Keypair deleted: " + kp.getName());
Server deleted = (Server) cloudIntf.getServer(newServer.getId());
assertTrue(newServer != null && deleted == null);
} catch (Exception ex) {
ex.printStackTrace();
fail();
}
}
use of org.openstack4j.model.compute.Keypair in project cloudbreak by hortonworks.
the class OpenStackResourceConnector method createKeyPair.
private void createKeyPair(AuthenticatedContext authenticatedContext, CloudStack stack, OSClient<?> client) {
KeystoneCredentialView keystoneCredential = openStackClient.createKeystoneCredential(authenticatedContext);
String keyPairName = keystoneCredential.getKeyPairName();
if (client.compute().keypairs().get(keyPairName) == null) {
try {
Keypair keyPair = client.compute().keypairs().create(keyPairName, stack.getInstanceAuthentication().getPublicKey());
LOGGER.info("Keypair has been created: {}", keyPair);
} catch (Exception e) {
LOGGER.error("Failed to create keypair", e);
throw new CloudConnectorException(e.getMessage(), e);
}
} else {
LOGGER.info("Keypair already exists: {}", keyPairName);
}
}
use of org.openstack4j.model.compute.Keypair in project cloudbreak by hortonworks.
the class OpenStackPlatformResources method sshKeys.
@Override
public CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);
Set<CloudSshKey> cloudSshKeys = new HashSet<>();
for (Keypair keypair : osClient.compute().keypairs().list()) {
Map<String, Object> properties = new HashMap<>();
properties.put("fingerprint", keypair.getFingerprint());
properties.put("id", keypair.getId());
properties.put("publicKey", keypair.getPublicKey());
properties.put("createdAt", keypair.getCreatedAt());
CloudSshKey cloudSshKey = new CloudSshKey();
cloudSshKey.setName(keypair.getName());
cloudSshKey.setProperties(properties);
cloudSshKeys.add(cloudSshKey);
}
Map<String, Set<CloudSshKey>> result = new HashMap<>();
result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudSshKeys);
LOGGER.info("openstack cloud ssh keys result: {}", result);
return new CloudSshKeys(result);
}
Aggregations