Search in sources :

Example 11 with Network

use of org.openstack4j.model.network.Network in project airavata by apache.

the class OpenstackIntfImpl method createRouter.

@Override
public Object createRouter(String routerName, String externalGatewayName) {
    String publicNetId = null;
    Router router = null;
    try {
        for (Network net : os.networking().network().list()) {
            if (net.getName().equals(externalGatewayName)) {
                publicNetId = net.getId();
            }
        }
        if (publicNetId != null) {
            router = os.networking().router().create(Builders.router().name(routerName).adminStateUp(true).externalGateway(publicNetId).build());
            logger.info("Created a new router " + router + " for external gateway : [" + externalGatewayName + "]");
        } else {
            logger.error("Failed to create router because external gateway [ " + externalGatewayName + "] is not found!");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        // TODO: Check with the team on how to handle exceptions.
        logger.error("Failed to create network: " + routerName + ". Exception: " + ex.getMessage(), ex);
    }
    return router;
}
Also used : Network(org.openstack4j.model.network.Network) Router(org.openstack4j.model.network.Router) FileNotFoundException(java.io.FileNotFoundException)

Example 12 with Network

use of org.openstack4j.model.network.Network in project airavata by apache.

the class OpenstackIntfImpl method deleteNetwork.

@Override
public void deleteNetwork(String networkName) {
    try {
        for (Network network : os.networking().network().list()) {
            if (network.getName().equals(networkName)) {
                os.networking().network().delete(network.getId());
                logger.info("Deleted Network [" + network.getName() + "] Successfully.");
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        // TODO: Check with the team on how to handle exceptions.
        logger.error("Failed to delete network: " + networkName + ". Exception: " + ex.getMessage(), ex);
    }
}
Also used : Network(org.openstack4j.model.network.Network) FileNotFoundException(java.io.FileNotFoundException)

Example 13 with Network

use of org.openstack4j.model.network.Network in project airavata by apache.

the class OpenstackIntfImpl method createNetwork.

@Override
public Object createNetwork(String networkName) {
    Network network = null;
    try {
        network = os.networking().network().create(Builders.network().name(networkName).adminStateUp(true).build());
        logger.info("Created a new network : " + network);
    } catch (Exception ex) {
        ex.printStackTrace();
        // TODO: Check with the team on how to handle exceptions.
        logger.error("Failed to create network: " + networkName + ". Exception: " + ex.getMessage(), ex);
    }
    return network;
}
Also used : Network(org.openstack4j.model.network.Network) FileNotFoundException(java.io.FileNotFoundException)

Example 14 with Network

use of org.openstack4j.model.network.Network in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method networks.

@Override
public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential);
    Set<CloudNetwork> cloudNetworks = new HashSet<>();
    List<? extends Network> networks = getNetworks(osClient);
    for (Network network : networks) {
        Map<String, Object> properties = new HashMap<>();
        properties.put("networkType", network.getNetworkType());
        properties.put("providerPhyNet", network.getProviderPhyNet());
        properties.put("providerSegID", network.getProviderSegID());
        properties.put("tenantId", network.getTenantId());
        Map<String, String> subnets = new HashMap<>();
        List<? extends Subnet> neutronSubnets = network.getNeutronSubnets();
        LOGGER.info("neutron subnets for {}: {}", network.getName(), neutronSubnets);
        if (neutronSubnets != null) {
            for (Subnet neutronSubnet : neutronSubnets) {
                if (neutronSubnet != null) {
                    subnets.put(neutronSubnet.getId(), neutronSubnet.getName());
                }
            }
        }
        CloudNetwork cloudNetwork = new CloudNetwork(network.getName(), network.getId(), subnets, properties);
        cloudNetworks.add(cloudNetwork);
    }
    Map<String, Set<CloudNetwork>> result = new HashMap<>(1);
    result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudNetworks);
    LOGGER.info("openstack cloud networks result: {}", result);
    return new CloudNetworks(result);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) Network(org.openstack4j.model.network.Network) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) KeystoneCredentialView(com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView) Subnet(org.openstack4j.model.network.Subnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) HashSet(java.util.HashSet)

Example 15 with Network

use of org.openstack4j.model.network.Network in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method publicIpPool.

@Override
public CloudIpPools publicIpPool(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    Map<String, Set<CloudIpPool>> cloudIpPools = new HashMap<>();
    CloudRegions regions = regions(cloudCredential, region, filters);
    for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
        Set<CloudIpPool> cloudGateWays = new HashSet<>();
        List<? extends Network> networks = getNetworks(osClient);
        List<? extends Network> networksWithExternalRouter = networks.stream().filter(Network::isRouterExternal).collect(Collectors.toList());
        for (Network network : networksWithExternalRouter) {
            CloudIpPool cloudIpPool = new CloudIpPool();
            cloudIpPool.setId(network.getId());
            cloudIpPool.setName(network.getName());
            cloudGateWays.add(cloudIpPool);
        }
        for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
            cloudIpPools.put(availabilityZone.value(), cloudGateWays);
        }
    }
    LOGGER.info("openstack public ip pool result: {}", cloudIpPools);
    return new CloudIpPools(cloudIpPools);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CloudIpPool(com.sequenceiq.cloudbreak.cloud.model.CloudIpPool) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Network(org.openstack4j.model.network.Network) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) Region(com.sequenceiq.cloudbreak.cloud.model.Region) List(java.util.List) HashSet(java.util.HashSet)

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