Search in sources :

Example 6 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException in project cloudbreak by hortonworks.

the class OpenStackRouterResourceBuilder method delete.

@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);
    }
}
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)

Example 7 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException in project cloudbreak by hortonworks.

the class OpenStackSubnetResourceBuilder method build.

@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) {
    try {
        NeutronNetworkView neutronView = new NeutronNetworkView(network);
        String subnetId = neutronView.isExistingSubnet() ? neutronView.getCustomSubnetId() : context.getParameter(SUBNET_ID, String.class);
        if (!neutronView.isExistingSubnet()) {
            OSClient<?> osClient = createOSClient(auth);
            NeutronNetworkView networkView = new NeutronNetworkView(network);
            Subnet subnet = Builders.subnet().name(resource.getName()).networkId(context.getParameter(OpenStackConstants.NETWORK_ID, String.class)).tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)).ipVersion(IPVersionType.V4).cidr(networkView.getSubnetCIDR()).enableDHCP(true).build();
            subnetId = osClient.networking().subnet().create(subnet).getId();
        }
        context.putParameter(SUBNET_ID, subnetId);
        return createPersistedResource(resource, subnetId);
    } catch (OS4JException ex) {
        throw new OpenStackResourceException("Subnet creation failed", resourceType(), resource.getName(), ex);
    }
}
Also used : OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) Subnet(org.openstack4j.model.network.Subnet) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView) OS4JException(org.openstack4j.api.exceptions.OS4JException)

Example 8 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException in project cloudbreak by hortonworks.

the class OpenStackSubnetResourceBuilder method delete.

@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);
    }
}
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)

Example 9 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException in project cloudbreak by hortonworks.

the class OpenStackAttachedDiskResourceBuilder method delete.

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

Example 10 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException in project cloudbreak by hortonworks.

the class OpenStackInstanceBuilder method delete.

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

Aggregations

OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)18 OS4JException (org.openstack4j.api.exceptions.OS4JException)15 ActionResponse (org.openstack4j.model.common.ActionResponse)8 NeutronNetworkView (com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)7 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)4 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)3 Server (org.openstack4j.model.compute.Server)2 Router (org.openstack4j.model.network.Router)2 State (org.openstack4j.model.network.State)2 Volume (org.openstack4j.model.storage.block.Volume)2 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)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 ArrayList (java.util.ArrayList)1 Future (java.util.concurrent.Future)1 ComputeSecurityGroupService (org.openstack4j.api.compute.ComputeSecurityGroupService)1 BlockDeviceMappingCreate (org.openstack4j.model.compute.BlockDeviceMappingCreate)1