use of org.openstack4j.model.network.Subnet 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;
}
use of org.openstack4j.model.network.Subnet in project airavata by apache.
the class OpenstackIntfImpl method deleteSubnet.
@Override
public void deleteSubnet(String subnetName) {
try {
for (Subnet subnet : os.networking().subnet().list()) {
if (subnet.getName().equals(subnetName)) {
os.networking().subnet().delete(subnet.getId());
logger.info("Deleted Subnet [" + subnet.getName() + "] Successfully.");
}
}
} catch (Exception ex) {
ex.printStackTrace();
// TODO: Check with the team on how to handle exceptions.
logger.error("Failed to delete subnet: " + subnetName + ". Exception: " + ex.getMessage(), ex);
}
}
use of org.openstack4j.model.network.Subnet 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);
}
Aggregations