Search in sources :

Example 11 with OS4JException

use of org.openstack4j.api.exceptions.OS4JException 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)

Example 12 with OS4JException

use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.

the class OpenStackPortBuilder method build.

@Override
public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResource, Map<String, String> tags) {
    CloudResource resource = buildableResource.get(0);
    try {
        OSClient<?> osClient = createOSClient(auth);
        Port port = Builders.port().tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)).networkId(context.getStringParameter(OpenStackConstants.NETWORK_ID)).fixedIp(null, context.getStringParameter(OpenStackConstants.SUBNET_ID)).securityGroup(context.getGroupResources(group.getName()).get(0).getReference()).build();
        port = osClient.networking().port().create(port);
        return Collections.singletonList(createPersistedResource(resource, group.getName(), port.getId(), Collections.singletonMap(OpenStackConstants.PORT_ID, port.getId())));
    } catch (OS4JException ex) {
        throw new OpenStackResourceException("Port creation failed", resourceType(), resource.getName(), ex);
    }
}
Also used : Port(org.openstack4j.model.network.Port) OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) OS4JException(org.openstack4j.api.exceptions.OS4JException)

Example 13 with OS4JException

use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.

the class OpenStackPortBuilder method delete.

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

Example 14 with OS4JException

use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.

the class OpenStackSecurityGroupResourceBuilder method delete.

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

Example 15 with OS4JException

use of org.openstack4j.api.exceptions.OS4JException in project cloudbreak by hortonworks.

the class OpenStackSecurityGroupResourceBuilder method build.

@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource resource) {
    try {
        OSClient<?> osClient = createOSClient(auth);
        ComputeSecurityGroupService securityGroupService = osClient.compute().securityGroups();
        SecGroupExtension securityGroup = securityGroupService.create(resource.getName(), "");
        String securityGroupId = securityGroup.getId();
        for (SecurityRule rule : security.getRules()) {
            IPProtocol osProtocol = getProtocol(rule.getProtocol());
            String cidr = rule.getCidr();
            for (PortDefinition portStr : rule.getPorts()) {
                int from = Integer.parseInt(portStr.getFrom());
                int to = Integer.parseInt(portStr.getTo());
                securityGroupService.createRule(createRule(securityGroupId, osProtocol, cidr, from, to));
            }
        }
        NeutronNetworkView neutronView = new NeutronNetworkView(network);
        String subnetCidr = neutronView.isExistingSubnet() ? utils.getExistingSubnetCidr(auth, neutronView) : network.getSubnet().getCidr();
        securityGroupService.createRule(createRule(securityGroupId, IPProtocol.TCP, subnetCidr, MIN_PORT, MAX_PORT));
        securityGroupService.createRule(createRule(securityGroupId, IPProtocol.UDP, subnetCidr, MIN_PORT, MAX_PORT));
        securityGroupService.createRule(createRule(securityGroupId, IPProtocol.ICMP, "0.0.0.0/0"));
        return createPersistedResource(resource, group.getName(), securityGroup.getId());
    } catch (OS4JException ex) {
        throw new OpenStackResourceException("SecurityGroup creation failed", resourceType(), resource.getName(), ex);
    }
}
Also used : PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) SecGroupExtension(org.openstack4j.model.compute.SecGroupExtension) ComputeSecurityGroupService(org.openstack4j.api.compute.ComputeSecurityGroupService) IPProtocol(org.openstack4j.model.compute.IPProtocol) OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView) OS4JException(org.openstack4j.api.exceptions.OS4JException)

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