Search in sources :

Example 1 with AttachInterfaceType

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

the class RouterProducer method doAttach.

private void doAttach(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String routerId = msg.getHeader(NeutronConstants.ROUTER_ID, String.class);
    final String subnetPortId = msg.getHeader(NeutronConstants.SUBNET_ID, msg.getHeader(NeutronConstants.PORT_ID), String.class);
    final AttachInterfaceType type = msg.getHeader(NeutronConstants.ITERFACE_TYPE, AttachInterfaceType.class);
    ObjectHelper.notEmpty(routerId, "Router ID");
    ObjectHelper.notEmpty(subnetPortId, "Subnet/Port ID");
    ObjectHelper.notNull(type, "AttachInterfaceType ");
    RouterInterface routerInterface = os.networking().router().attachInterface(routerId, type, subnetPortId);
    msg.setBody(routerInterface);
}
Also used : Message(org.apache.camel.Message) RouterInterface(org.openstack4j.model.network.RouterInterface) AttachInterfaceType(org.openstack4j.model.network.AttachInterfaceType)

Example 2 with AttachInterfaceType

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

the class RouterProducerTest method attachTest.

@Test
public void attachTest() throws Exception {
    final String routerID = "myRouterID";
    final String subnetId = "subnet";
    final RouterInterface ifce = new NeutronRouterInterface(subnetId, null);
    when(routerService.attachInterface(anyString(), any(AttachInterfaceType.class), anyString())).thenReturn(ifce);
    msg.setHeader(OpenstackConstants.OPERATION, NeutronConstants.ATTACH_INTERFACE);
    msg.setHeader(NeutronConstants.ROUTER_ID, routerID);
    msg.setHeader(NeutronConstants.SUBNET_ID, subnetId);
    msg.setHeader(NeutronConstants.ITERFACE_TYPE, AttachInterfaceType.SUBNET);
    producer.process(exchange);
    ArgumentCaptor<String> routerC = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<AttachInterfaceType> itfType = ArgumentCaptor.forClass(AttachInterfaceType.class);
    ArgumentCaptor<String> subnetC = ArgumentCaptor.forClass(String.class);
    verify(routerService).attachInterface(routerC.capture(), itfType.capture(), subnetC.capture());
    assertEquals(routerID, routerC.getValue());
    assertEquals(AttachInterfaceType.SUBNET, itfType.getValue());
    assertEquals(subnetId, subnetC.getValue());
    assertEquals(ifce, msg.getBody(RouterInterface.class));
}
Also used : RouterInterface(org.openstack4j.model.network.RouterInterface) NeutronRouterInterface(org.openstack4j.openstack.networking.domain.NeutronRouterInterface) Matchers.anyString(org.mockito.Matchers.anyString) NeutronRouterInterface(org.openstack4j.openstack.networking.domain.NeutronRouterInterface) AttachInterfaceType(org.openstack4j.model.network.AttachInterfaceType) Test(org.junit.Test)

Aggregations

AttachInterfaceType (org.openstack4j.model.network.AttachInterfaceType)2 RouterInterface (org.openstack4j.model.network.RouterInterface)2 Message (org.apache.camel.Message)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 NeutronRouterInterface (org.openstack4j.openstack.networking.domain.NeutronRouterInterface)1