Search in sources :

Example 11 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException 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 12 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException 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 13 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException 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 14 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException 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)

Example 15 with OpenStackResourceException

use of com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException 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)

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