Search in sources :

Example 1 with SubnetBuilder

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

Map (java.util.Map)1 IPVersionType (org.openstack4j.model.network.IPVersionType)1 Subnet (org.openstack4j.model.network.Subnet)1 SubnetBuilder (org.openstack4j.model.network.builder.SubnetBuilder)1 NeutronPool (org.openstack4j.openstack.networking.domain.NeutronPool)1