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;
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations