Search in sources :

Example 11 with Subnet

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

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

Example 13 with Subnet

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

Aggregations

Subnet (org.openstack4j.model.network.Subnet)13 FileNotFoundException (java.io.FileNotFoundException)5 Network (org.openstack4j.model.network.Network)3 Router (org.openstack4j.model.network.Router)2 RouterInterface (org.openstack4j.model.network.RouterInterface)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)1 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)1 OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)1 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)1 NeutronNetworkView (com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1 CloudInterface (org.apache.airavata.cloud.intf.CloudInterface)1 OpenstackIntfImpl (org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl)1 Message (org.apache.camel.Message)1