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