org.openstack4j.model.common.ActionResponse Java Examples
The following examples show how to use
org.openstack4j.model.common.ActionResponse.
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: OpenStackRouterResourceBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) { try { OSClient<?> osClient = createOSClient(auth); NeutronNetworkView networkView = new NeutronNetworkView(network); if (!networkView.isExistingSubnet()) { String subnetId = context.getStringParameter(OpenStackConstants.SUBNET_ID); osClient.networking().router().detachInterface(resource.getReference(), subnetId, null); } if (!networkView.isExistingNetwork()) { ActionResponse response = osClient.networking().router().delete(resource.getReference()); return checkDeleteResponse(response, resourceType(), auth, resource, "Router deletion failed"); } return null; } catch (OS4JException ex) { throw new OpenStackResourceException("Router deletion failed", resourceType(), resource.getName(), ex); } }
Example #3
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 #4
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 #5
Source File: OpenStackInstanceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) { try { OSClient<?> osClient = createOSClient(auth); ActionResponse response = osClient.compute().servers().delete(resource.getReference()); return checkDeleteResponse(response, resourceType(), auth, resource, "Instance deletion failed"); } catch (OS4JException ex) { throw new OpenStackResourceException("Instance deletion failed", resourceType(), resource.getName(), ex); } }
Example #6
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 #7
Source File: OpenStackAttachedDiskResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) { try { OSClient<?> osClient = createOSClient(auth); ActionResponse response = osClient.blockStorage().volumes().delete(resource.getReference()); return checkDeleteResponse(response, resourceType(), auth, resource, "Volume deletion failed"); } catch (OS4JException ex) { throw new OpenStackResourceException("Volume deletion failed", resourceType(), resource.getName(), ex); } }
Example #8
Source File: OpenStackPortBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) { try { OSClient<?> osClient = createOSClient(auth); ActionResponse response = osClient.networking().port().delete(resource.getReference()); return checkDeleteResponse(response, resourceType(), auth, resource, "Port deletion failed"); } catch (OS4JException ex) { throw new OpenStackResourceException("Port deletion failed", resourceType(), resource.getName(), ex); } }
Example #9
Source File: OpenStackNetworkResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) { try { OSClient<?> osClient = createOSClient(auth); deAllocateFloatingIps(context, osClient); NeutronNetworkView neutronView = new NeutronNetworkView(network); if (!neutronView.isExistingNetwork()) { ActionResponse response = osClient.networking().network().delete(resource.getReference()); return checkDeleteResponse(response, resourceType(), auth, resource, "Network deletion failed"); } return null; } catch (OS4JException ex) { throw new OpenStackResourceException("Network deletion failed", resourceType(), resource.getName(), ex); } }
Example #10
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 #11
Source File: OpenStackSubnetResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) { try { NeutronNetworkView neutronView = new NeutronNetworkView(network); if (!neutronView.isExistingSubnet()) { OSClient<?> osClient = createOSClient(auth); ActionResponse response = osClient.networking().subnet().delete(resource.getReference()); return checkDeleteResponse(response, resourceType(), auth, resource, "Subnet deletion failed"); } return null; } catch (OS4JException ex) { throw new OpenStackResourceException("Subnet deletion failed", resourceType(), resource.getName(), ex); } }
Example #12
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; }
Example #13
Source File: OpenStackSecurityGroupResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) { try { OSClient<?> osClient = createOSClient(auth); ActionResponse response = osClient.compute().securityGroups().delete(resource.getReference()); return checkDeleteResponse(response, resourceType(), auth, resource, "SecurityGroup deletion failed"); } catch (OS4JException ex) { throw new OpenStackResourceException("SecurityGroup deletion failed", resourceType(), resource.getName(), ex); } }