use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class OpenStackNetworkResourceBuilder method build.
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Network network, Security security, CloudResource buildableResource) {
OSClient<?> osClient = createOSClient(auth);
try {
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String networkId = neutronView.isExistingNetwork() ? neutronView.getCustomNetworkId() : context.getParameter(NETWORK_ID, String.class);
if (!neutronView.isExistingNetwork()) {
org.openstack4j.model.network.Network osNetwork = Builders.network().name(buildableResource.getName()).tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)).adminStateUp(true).build();
networkId = osClient.networking().network().create(osNetwork).getId();
}
context.putParameter(NETWORK_ID, networkId);
return createPersistedResource(buildableResource, networkId);
} catch (OS4JException ex) {
throw new OpenStackResourceException("Network creation failed", resourceType(), buildableResource.getName(), ex);
}
}
use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.
the class OpenStackNetworkResourceBuilder method delete.
@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);
}
}
Aggregations