use of org.openstack4j.model.network.Network in project camel by apache.
the class NetworkProducer method messageToNetwork.
private Network messageToNetwork(Message message) {
Network network = message.getBody(Network.class);
if (network == null) {
Map headers = message.getHeaders();
NetworkBuilder builder = Builders.network();
ObjectHelper.notEmpty(message.getHeader(OpenstackConstants.NAME, String.class), "Name");
builder.name(message.getHeader(OpenstackConstants.NAME, String.class));
if (headers.containsKey(NeutronConstants.ADMIN_STATE_UP)) {
builder.adminStateUp(message.getHeader(NeutronConstants.ADMIN_STATE_UP, Boolean.class));
}
if (headers.containsKey(NeutronConstants.NETWORK_TYPE)) {
builder.networkType(message.getHeader(NeutronConstants.NETWORK_TYPE, NetworkType.class));
}
if (headers.containsKey(NeutronConstants.IS_SHARED)) {
builder.isShared(message.getHeader(NeutronConstants.IS_SHARED, Boolean.class));
}
if (headers.containsKey(NeutronConstants.IS_ROUTER_EXTERNAL)) {
builder.isRouterExternal(message.getHeader(NeutronConstants.IS_ROUTER_EXTERNAL, Boolean.class));
}
if (headers.containsKey(NeutronConstants.TENANT_ID)) {
builder.tenantId(message.getHeader(NeutronConstants.TENANT_ID, String.class));
}
if (headers.containsKey(NeutronConstants.PHYSICAL_NETWORK)) {
builder.physicalNetwork(message.getHeader(NeutronConstants.PHYSICAL_NETWORK, String.class));
}
if (headers.containsKey(NeutronConstants.SEGMENT_ID)) {
builder.segmentId(message.getHeader(NeutronConstants.SEGMENT_ID, String.class));
}
network = builder.build();
}
return network;
}
use of org.openstack4j.model.network.Network in project airavata by apache.
the class CloudIntfTest method jetstreamCreateDeleteNetworkTest.
/**
* Jetstream create delete network test.
*/
@Test
@Ignore
public void jetstreamCreateDeleteNetworkTest() {
try {
CloudInterface cloudIntf = new OpenstackIntfImpl("jetstream_openrc.properties");
/* fetch sample data from properties file */
String networkName = properties.getProperty("jetstream_network_name");
String subnetCIDR = properties.getProperty("jetstream_subnet_cidr");
Integer ipVersion = Integer.valueOf(properties.getProperty("jetstream_ip_version", Constants.OS_IP_VERSION_DEFAULT.toString()));
String externalGateway = properties.getProperty("jetstream_public_network_name");
/* build router and subnet names */
String subnetName = "subnet-" + networkName;
String routerName = "router-" + networkName;
/* create network */
logger.info("Creating network with name = " + networkName);
Network network = (Network) cloudIntf.createNetwork(networkName);
assertTrue(network != null && network.getName().equals(networkName));
/* create subnet for network */
logger.info("Creating subnet with name = " + subnetName + ", and CIDR = " + subnetCIDR + ", and version = " + ipVersion);
Subnet subnet = (Subnet) cloudIntf.createSubnet(subnetName, networkName, subnetCIDR, ipVersion);
assertTrue(subnet != null && subnet.getName().equals(subnetName) && subnet.getCidr().equals(subnetCIDR) && subnet.getIpVersion().getVersion() == ipVersion.intValue());
/* create router for external gateway */
logger.info("Creating router with name = " + routerName + ", and external gateway = " + externalGateway);
Router router = (Router) cloudIntf.createRouter(routerName, externalGateway);
assertTrue(router != null && router.getName().equals(routerName));
/* create router-subnet interface */
logger.info("Creating interface between router = " + routerName + ", and subnet = " + subnetName);
RouterInterface iface = (RouterInterface) cloudIntf.createRouterSubnetInterface(routerName, subnetName);
assertTrue(iface != null && iface.getSubnetId().equals(subnet.getId()));
/* delete router-subnet interface */
logger.info("Deleting interface between router = " + routerName + ", and subnet = " + subnetName);
cloudIntf.deleteRouterSubnetInterface(routerName, subnetName);
/* delete router for external gateway */
logger.info("Creating router with name = " + routerName);
cloudIntf.deleteRouter(routerName);
/* delete subnet for network */
logger.info("Creating subnet with name = " + subnetName);
cloudIntf.deleteSubnet(subnetName);
/* delete network */
logger.info("Deleting network with name = " + networkName);
cloudIntf.deleteNetwork(networkName);
} catch (Exception ex) {
ex.printStackTrace();
fail();
}
}
use of org.openstack4j.model.network.Network in project openstack4j by ContainX.
the class NetworkTests method getNetwork.
@Test
public void getNetwork() throws Exception {
respondWith(JSON_NETWORK);
Network n = osv3().networking().network().get(NETWORK_ID);
server.takeRequest();
assertEquals(n.getName(), NETWORK_NAME);
assertEquals(n.getStatus(), State.ACTIVE);
assertEquals(n.isRouterExternal(), false);
}
use of org.openstack4j.model.network.Network in project openstack4j by ContainX.
the class NetworkTests method createNetworkWithZone.
@Test
public void createNetworkWithZone() throws Exception {
respondWith(JSON_NETWORK_ZONE);
Network n = osv3().networking().network().create(Builders.network().name(NETWORK_NAME).isRouterExternal(true).adminStateUp(true).addAvailabilityZoneHints("nova").build());
server.takeRequest();
assertEquals(n.getName(), NETWORK_NAME);
assertEquals(n.getStatus(), State.ACTIVE);
assertEquals(n.getAvailabilityZoneHints().get(0), "nova");
}
use of org.openstack4j.model.network.Network in project camel by apache.
the class NetworkProducer method doCreate.
private void doCreate(Exchange exchange) {
final Network in = messageToNetwork(exchange.getIn());
final Network out = os.networking().network().create(in);
exchange.getIn().setBody(out);
}
Aggregations