Search in sources :

Example 16 with OS4JException

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);
    }
}
Also used : OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView) OS4JException(org.openstack4j.api.exceptions.OS4JException)

Example 17 with OS4JException

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);
    }
}
Also used : OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView) OS4JException(org.openstack4j.api.exceptions.OS4JException) ActionResponse(org.openstack4j.model.common.ActionResponse)

Aggregations

OS4JException (org.openstack4j.api.exceptions.OS4JException)17 OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)15 ActionResponse (org.openstack4j.model.common.ActionResponse)8 NeutronNetworkView (com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)7 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)5 ArrayList (java.util.ArrayList)2 Server (org.openstack4j.model.compute.Server)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)1 ResourceStatus (com.sequenceiq.cloudbreak.cloud.model.ResourceStatus)1 SecurityRule (com.sequenceiq.cloudbreak.cloud.model.SecurityRule)1 CinderVolumeView (com.sequenceiq.cloudbreak.cloud.openstack.view.CinderVolumeView)1 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)1 NovaInstanceView (com.sequenceiq.cloudbreak.cloud.openstack.view.NovaInstanceView)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)1 ComputeSecurityGroupService (org.openstack4j.api.compute.ComputeSecurityGroupService)1 BlockDeviceMappingCreate (org.openstack4j.model.compute.BlockDeviceMappingCreate)1 FloatingIP (org.openstack4j.model.compute.FloatingIP)1