Java Code Examples for org.openstack4j.model.common.ActionResponse#isSuccess()
The following examples show how to use
org.openstack4j.model.common.ActionResponse#isSuccess() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenStackFloatingIPBuilder.java From cloudbreak with Apache License 2.0 | 7 votes |
@Override public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResource, CloudStack cloudStack) { CloudResource resource = buildableResource.get(0); try { String publicNetId = context.getStringParameter(OpenStackConstants.PUBLIC_NET_ID); if (publicNetId != null) { OSClient<?> osClient = createOSClient(auth); List<CloudResource> computeResources = context.getComputeResources(privateId); CloudResource instance = getInstance(computeResources); FloatingIP unusedIp = osClient.compute().floatingIps().allocateIP(publicNetId); ActionResponse response = osClient.compute().floatingIps().addFloatingIP(instance.getParameter(OpenStackConstants.SERVER, Server.class), unusedIp.getFloatingIpAddress()); if (!response.isSuccess()) { throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(), auth.getCloudContext().getId(), response.getFault()); } return Collections.singletonList(createPersistedResource(resource, group.getName(), unusedIp.getId())); } return Collections.emptyList(); } catch (OS4JException ex) { throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(), ex); } }
Example 2
Source File: NovaV3Launcher.java From karamel with Apache License 2.0 | 5 votes |
public boolean uploadSshPublicKey(String keyPairName, Nova nova, boolean removeOld) { if (removeOld) { ActionResponse res = this.novaContext.getCompute().keypairs().delete(keyPairName); if (!res.isSuccess()) logger.info(String.format("Could not remove key maube it does not exist '%s'", keyPairName)); } logger.info(String.format("New keypair '%s' is being uploaded to Nova OpenStack", keyPairName)); this.novaContext.getCompute().keypairs().create(keyPairName, sshKeyPair.getPublicKey()); return true; }
Example 3
Source File: OpenStackInstanceConnector.java From cloudbreak with Apache License 2.0 | 5 votes |
private List<CloudVmInstanceStatus> executeAction(AuthenticatedContext ac, Iterable<CloudInstance> cloudInstances, Action action) { List<CloudVmInstanceStatus> statuses = new ArrayList<>(); OSClient<?> osClient = openStackClient.createOSClient(ac); for (CloudInstance cloudInstance : cloudInstances) { ActionResponse actionResponse = osClient.compute().servers().action(cloudInstance.getInstanceId(), action); if (actionResponse.isSuccess()) { statuses.add(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.IN_PROGRESS)); } else { statuses.add(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.FAILED, actionResponse.getFault())); } } return statuses; }
Example 4
Source File: OpenStackInstanceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
private CloudVmInstanceStatus executeAction(AuthenticatedContext auth, CloudInstance instance, Action action) { OSClient<?> osClient = createOSClient(auth); ActionResponse actionResponse = osClient.compute().servers().action(instance.getInstanceId(), action); if (actionResponse.isSuccess()) { return new CloudVmInstanceStatus(instance, InstanceStatus.IN_PROGRESS); } return new CloudVmInstanceStatus(instance, InstanceStatus.FAILED, actionResponse.getFault()); }
Example 5
Source File: OpenStackNetworkResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void deAllocateFloatingIps(OpenStackContext context, OSClient<?> osClient) { List<String> floatingIpIds = context.getParameter(OpenStackConstants.FLOATING_IP_IDS, List.class); for (String floatingIpId : floatingIpIds) { try { ActionResponse response = osClient.compute().floatingIps().deallocateIP(floatingIpId); if (!response.isSuccess()) { LOGGER.debug("FloatingIp {} cannot be deallocated: {}", floatingIpId, response.getFault()); } } catch (OS4JException ex) { LOGGER.debug("FloatingIp {} cannot be deallocated: {}", floatingIpId, ex.getMessage()); } } }
Example 6
Source File: AbstractOpenStackResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
protected CloudResource checkDeleteResponse(ActionResponse response, ResourceType resourceType, AuthenticatedContext auth, CloudResource resource, String faultMsg) { if (!response.isSuccess()) { if (response.getCode() != StatusCode.NOT_FOUND.getCode()) { throw new OpenStackResourceException(faultMsg, resourceType, resource.getName(), auth.getCloudContext().getId(), response.getFault()); } else { return null; } } return resource; }