Search in sources :

Example 6 with Network

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);
}
Also used : Message(org.apache.camel.Message) Network(org.openstack4j.model.network.Network)

Example 7 with Network

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());
}
Also used : Network(org.openstack4j.model.network.Network) ArrayList(java.util.ArrayList) NetworkProducer(org.apache.camel.component.openstack.neutron.producer.NetworkProducer) Before(org.junit.Before)

Example 8 with Network

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);
}
Also used : Network(org.openstack4j.model.network.Network) Test(org.testng.annotations.Test) AbstractTest(org.openstack4j.api.AbstractTest)

Example 9 with Network

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());
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) DefaultMessage(org.apache.camel.impl.DefaultMessage) Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) NeutronEndpoint(org.apache.camel.component.openstack.neutron.NeutronEndpoint) VolumeProducer(org.apache.camel.component.openstack.cinder.producer.VolumeProducer) ProjectProducer(org.apache.camel.component.openstack.keystone.producer.ProjectProducer) ContainerProducer(org.apache.camel.component.openstack.swift.producer.ContainerProducer) GlanceProducer(org.apache.camel.component.openstack.glance.GlanceProducer) KeypairProducer(org.apache.camel.component.openstack.nova.producer.KeypairProducer) Producer(org.apache.camel.Producer) NetworkProducer(org.apache.camel.component.openstack.neutron.producer.NetworkProducer) Network(org.openstack4j.model.network.Network) DefaultHeadersMapFactory(org.apache.camel.impl.DefaultHeadersMapFactory) NetworkProducer(org.apache.camel.component.openstack.neutron.producer.NetworkProducer) Test(org.junit.Test)

Example 10 with Network

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;
}
Also used : Network(org.openstack4j.model.network.Network) Subnet(org.openstack4j.model.network.Subnet) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Network (org.openstack4j.model.network.Network)15 FileNotFoundException (java.io.FileNotFoundException)5 AbstractTest (org.openstack4j.api.AbstractTest)3 Subnet (org.openstack4j.model.network.Subnet)3 Test (org.testng.annotations.Test)3 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Message (org.apache.camel.Message)2 NetworkProducer (org.apache.camel.component.openstack.neutron.producer.NetworkProducer)2 Test (org.junit.Test)2 Router (org.openstack4j.model.network.Router)2 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)1 CloudIpPool (com.sequenceiq.cloudbreak.cloud.model.CloudIpPool)1 CloudIpPools (com.sequenceiq.cloudbreak.cloud.model.CloudIpPools)1 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)1 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)1 Region (com.sequenceiq.cloudbreak.cloud.model.Region)1 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)1