use of org.openstack4j.model.network.Network in project camel by apache.
the class NetworkProducer method doGet.
private void doGet(Exchange exchange) {
final Message msg = exchange.getIn();
final String id = msg.getHeader(OpenstackConstants.ID, msg.getHeader(NeutronConstants.NETWORK_ID, String.class), String.class);
ObjectHelper.notEmpty(id, "Network ID");
final Network out = os.networking().network().get(id);
exchange.getIn().setBody(out);
}
use of org.openstack4j.model.network.Network in project camel by apache.
the class NetworkProducerTest method setUp.
@Before
public void setUp() {
producer = new NetworkProducer(endpoint, client);
when(networkService.create(any(Network.class))).thenReturn(testOSnetwork);
when(networkService.get(anyString())).thenReturn(testOSnetwork);
List<Network> getAllList = new ArrayList<>();
getAllList.add(testOSnetwork);
getAllList.add(testOSnetwork);
doReturn(getAllList).when(networkService).list();
dummyNetwork = createNetwork();
when(testOSnetwork.getName()).thenReturn(dummyNetwork.getName());
when(testOSnetwork.getTenantId()).thenReturn(dummyNetwork.getTenantId());
when(testOSnetwork.getNetworkType()).thenReturn(dummyNetwork.getNetworkType());
when(testOSnetwork.getId()).thenReturn(UUID.randomUUID().toString());
}
use of org.openstack4j.model.network.Network in project openstack4j by ContainX.
the class NetworkTests method createNetwork.
@Test
public void createNetwork() throws Exception {
respondWith(JSON_NETWORK_EXTERNAL);
Network n = osv3().networking().network().create(Builders.network().name(NETWORK_NAME).isRouterExternal(true).adminStateUp(true).build());
server.takeRequest();
assertEquals(n.getName(), NETWORK_NAME);
assertEquals(n.getStatus(), State.ACTIVE);
assertEquals(n.isRouterExternal(), true);
}
use of org.openstack4j.model.network.Network in project wildfly-camel by wildfly-extras.
the class OpenstackIntegrationTest method createNeutronNetwork.
@Test
public void createNeutronNetwork() throws Exception {
CamelContext camelContext = Mockito.mock(CamelContext.class);
when(camelContext.getHeadersMapFactory()).thenReturn(new DefaultHeadersMapFactory());
Message msg = new DefaultMessage(camelContext);
Exchange exchange = Mockito.mock(Exchange.class);
when(exchange.getIn()).thenReturn(msg);
msg.setHeader(OpenstackConstants.OPERATION, OpenstackConstants.CREATE);
msg.setHeader(OpenstackConstants.NAME, dummyNetwork.getName());
msg.setHeader(NeutronConstants.NETWORK_TYPE, dummyNetwork.getNetworkType());
msg.setHeader(NeutronConstants.TENANT_ID, dummyNetwork.getTenantId());
NeutronEndpoint endpoint = Mockito.mock(NeutronEndpoint.class);
Producer producer = new NetworkProducer(endpoint, client);
producer.process(exchange);
ArgumentCaptor<Network> captor = ArgumentCaptor.forClass(Network.class);
verify(networkService).create(captor.capture());
assertEqualsNetwork(dummyNetwork, captor.getValue());
assertNotNull(msg.getBody(Network.class).getId());
}
use of org.openstack4j.model.network.Network in project airavata by apache.
the class OpenstackIntfImpl method createSubnet.
@Override
public Object createSubnet(String subnetName, String networkName, String subnetCIDR, int ipVersion) {
String networkId = null;
Subnet subnet = null;
try {
// get network id
for (Network network : os.networking().network().list()) {
if (network.getName().equals(networkName)) {
networkId = network.getId();
}
}
if (networkId != null) {
subnet = os.networking().subnet().create(Builders.subnet().enableDHCP(true).name(subnetName).networkId(networkId).ipVersion(IPVersionType.valueOf(ipVersion)).cidr(subnetCIDR).build());
logger.info("Created a subnet : " + subnetName + " for network [ " + networkName + "]");
} else {
logger.error("Failed to create subnet because network [ " + networkName + "] is not found!");
}
} catch (Exception ex) {
ex.printStackTrace();
// TODO: Check with the team on how to handle exceptions.
logger.error("Failed to create subnet: " + subnetName + ". Exception: " + ex.getMessage(), ex);
}
return subnet;
}
Aggregations