Search in sources :

Example 6 with Subnet

use of org.openstack4j.model.network.Subnet in project cloudbreak by hortonworks.

the class OpenStackUtils method getExistingSubnetCidr.

public String getExistingSubnetCidr(AuthenticatedContext authenticatedContext, NeutronNetworkView neutronNetwork) {
    if (neutronNetwork.isExistingSubnet()) {
        String subnetId = neutronNetwork.getCustomSubnetId();
        OSClient<?> osClient = openStackClient.createOSClient(authenticatedContext);
        Subnet subnet = osClient.networking().subnet().get(subnetId);
        if (subnet == null) {
            throw new CloudConnectorException("The specified subnet does not exist: " + subnetId);
        }
        return subnet.getCidr();
    }
    return null;
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Subnet(org.openstack4j.model.network.Subnet)

Example 7 with Subnet

use of org.openstack4j.model.network.Subnet 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 Subnet

use of org.openstack4j.model.network.Subnet in project camel by apache.

the class SubnetProducer method doCreate.

private void doCreate(Exchange exchange) {
    final Subnet in = messageToSubnet(exchange.getIn());
    final Subnet out = os.networking().subnet().create(in);
    exchange.getIn().setBody(out);
}
Also used : Subnet(org.openstack4j.model.network.Subnet)

Example 9 with Subnet

use of org.openstack4j.model.network.Subnet in project camel by apache.

the class SubnetProducer method doGet.

private void doGet(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String id = msg.getHeader(OpenstackConstants.ID, msg.getHeader(NeutronConstants.SUBNET_ID, String.class), String.class);
    ObjectHelper.notEmpty(id, "Subnet ID");
    final Subnet out = os.networking().subnet().get(id);
    exchange.getIn().setBody(out);
}
Also used : Message(org.apache.camel.Message) Subnet(org.openstack4j.model.network.Subnet)

Example 10 with Subnet

use of org.openstack4j.model.network.Subnet in project camel by apache.

the class SubnetProducer method messageToSubnet.

private Subnet messageToSubnet(Message message) {
    Subnet subnet = message.getBody(Subnet.class);
    if (subnet == null) {
        Map headers = message.getHeaders();
        SubnetBuilder builder = Builders.subnet();
        ObjectHelper.notEmpty(message.getHeader(OpenstackConstants.NAME, String.class), "Name");
        builder.name(message.getHeader(OpenstackConstants.NAME, String.class));
        ObjectHelper.notEmpty(message.getHeader(NeutronConstants.NETWORK_ID, String.class), "Network ID");
        builder.networkId(message.getHeader(NeutronConstants.NETWORK_ID, String.class));
        ObjectHelper.notNull(message.getHeader(NeutronConstants.IP_VERSION, IPVersionType.class), "IP version");
        builder.ipVersion(message.getHeader(NeutronConstants.IP_VERSION, IPVersionType.class));
        if (headers.containsKey(NeutronConstants.CIDR)) {
            builder.cidr(message.getHeader(NeutronConstants.CIDR, String.class));
        }
        if (headers.containsKey(NeutronConstants.SUBNET_POOL)) {
            final NeutronPool pool = message.getHeader(NeutronConstants.SUBNET_POOL, NeutronPool.class);
            builder.addPool(pool.getStart(), pool.getEnd());
        }
        if (headers.containsKey(NeutronConstants.NETWORK_ID)) {
            builder.networkId(message.getHeader(NeutronConstants.NETWORK_ID, String.class));
        }
        if (headers.containsKey(NeutronConstants.ENABLE_DHCP)) {
            builder.enableDHCP(message.getHeader(NeutronConstants.ENABLE_DHCP, Boolean.class));
        }
        if (headers.containsKey(NeutronConstants.GATEWAY)) {
            builder.gateway(message.getHeader(NeutronConstants.GATEWAY, String.class));
        }
        subnet = builder.build();
    }
    return subnet;
}
Also used : SubnetBuilder(org.openstack4j.model.network.builder.SubnetBuilder) IPVersionType(org.openstack4j.model.network.IPVersionType) Subnet(org.openstack4j.model.network.Subnet) NeutronPool(org.openstack4j.openstack.networking.domain.NeutronPool) Map(java.util.Map)

Aggregations

Subnet (org.openstack4j.model.network.Subnet)13 FileNotFoundException (java.io.FileNotFoundException)5 Network (org.openstack4j.model.network.Network)3 Router (org.openstack4j.model.network.Router)2 RouterInterface (org.openstack4j.model.network.RouterInterface)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)1 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)1 OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)1 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)1 NeutronNetworkView (com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1 CloudInterface (org.apache.airavata.cloud.intf.CloudInterface)1 OpenstackIntfImpl (org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl)1 Message (org.apache.camel.Message)1