use of org.openstack4j.model.compute.Server 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.Server in project cloudbreak by hortonworks.
the class OpenStackInstanceConnector method check.
@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
List<CloudVmInstanceStatus> statuses = new ArrayList<>();
OSClient<?> osClient = openStackClient.createOSClient(ac);
for (CloudInstance vm : vms) {
Optional<Server> server = Optional.ofNullable(vm.getInstanceId()).map(iid -> osClient.compute().servers().get(iid));
if (server.isPresent()) {
statuses.add(new CloudVmInstanceStatus(vm, NovaInstanceStatus.get(server.get())));
} else {
statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
}
}
return statuses;
}
use of org.openstack4j.model.compute.Server in project cloudbreak by hortonworks.
the class OpenStackMetadataCollector method collect.
@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
CloudResource resource = utils.getHeatResource(resources);
String stackName = utils.getStackName(authenticatedContext);
String heatStackId = resource.getName();
List<InstanceTemplate> templates = Lists.transform(vms, CloudInstance::getTemplate);
Map<String, InstanceTemplate> templateMap = Maps.uniqueIndex(templates, from -> utils.getPrivateInstanceId(from.getGroupName(), Long.toString(from.getPrivateId())));
OSClient<?> client = openStackClient.createOSClient(authenticatedContext);
Stack heatStack = client.heat().stacks().getDetails(stackName, heatStackId);
List<CloudVmMetaDataStatus> results = new ArrayList<>();
List<Map<String, Object>> outputs = heatStack.getOutputs();
for (Map<String, Object> map : outputs) {
String instanceUUID = (String) map.get("output_value");
if (!StringUtils.isEmpty(instanceUUID)) {
Server server = client.compute().servers().get(instanceUUID);
Map<String, String> metadata = server.getMetadata();
String privateInstanceId = utils.getPrivateInstanceId(metadata);
InstanceTemplate template = templateMap.get(privateInstanceId);
if (template != null) {
CloudInstanceMetaData md = cloudInstanceMetaDataExtractor.extractMetadata(client, server, instanceUUID);
// TODO use here sshkey
CloudInstance cloudInstance = new CloudInstance(instanceUUID, template, null);
CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
results.add(new CloudVmMetaDataStatus(status, md));
}
}
}
return results;
}
use of org.openstack4j.model.compute.Server in project cloudbreak by hortonworks.
the class OpenStackInstanceBuilder method getStatus.
private Status getStatus(AuthenticatedContext auth, String serverId) {
OSClient<?> osClient = createOSClient(auth);
Server server = osClient.compute().servers().get(serverId);
Status status = null;
if (server != null) {
status = server.getStatus();
}
return status;
}
use of org.openstack4j.model.compute.Server in project cloudbreak by hortonworks.
the class OpenStackNativeInstanceConnector method check.
@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
List<CloudVmInstanceStatus> statuses = new ArrayList<>();
OSClient<?> osClient = openStackClient.createOSClient(ac);
for (CloudInstance vm : vms) {
Server server = osClient.compute().servers().get(vm.getInstanceId());
if (server == null) {
statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
} else {
statuses.add(new CloudVmInstanceStatus(vm, NovaInstanceStatus.get(server)));
}
}
return statuses;
}
Aggregations