OpenStack4j > Documentation / Network (Neutron)

Network (Neutron)

Neutron is the Network service for OpenStack. Unlike Nova Networking, Neutron allows you to configure advanced virtual network topologies. An example of this is per-tenant private networks.

Neutron is broken up into the following abstractions: Networks, Subnets and Routers. Each has functionality that mimics the physical layers.


A network represents a slice of the outside network. Networks contain subnets, and routers to route traffic between different subnets and networks.

Create a Network

Network network = os.networking().network()

Querying for Networks

// List the networks which the current tenant has access to
List<? extends Network> networks = os.networking().network().list();
// Get a network by ID
Network network = os.networking().network().get("networkId");

Delete a Network



A subnet is a subdivision of an IP Network. The examples below will cover basic subnet management and how we leverage them using OpenStack4j.

Create a Subnet

Subnet subnet = os.networking().subnet().create(Builders.subnet()
                  .addPool("", "")

Querying for Subnets

// List all subnets which the current authorized tenant has access to
List<? extends Subnet> subnets = os.networking().subnet().list();

// Get a Subnet by ID
Subnet subnet = os.networking().subnet().get("subnetId");

Delete a Subnet



A port is exactly what you think it is. It mimics a physical port which is tied to a network and can be allocated a fixed ip from a subnet.

Create a Port

In the example below we will create a new port and assign it a fixed IP Address from the subnet we defined in the above examples.

Port port = os.networking().port().create(Builders.port()
              .fixedIp("", "subnetId")

Updating the Port

Port updatedPort = os.networking().port().update(port.builder().name("port-1-1").build());

Querying for Ports

// List all Ports which the current authorized tenant has access to
List<? extends Port> ports = os.networking().port().list();

// Get a Port by ID
Port port = os.networking().port().get("portId");

Delete a Port



For outside networks to access VMs, routers between subnets are needed. Each router has one gateway that is connected to a network and many interfaces that are connected to various subnets. Like a real world physical router, subnets can access machines on other subnets that are connected to the same router. More information about routers can be found at Neutron Concepts

Create a Router

Router router = os.networking().router().create(Builders.router()
                  .route("", "")

Update a Router

router = os.networking().router().update(router.toBuilder().name("ext_net2").build());

Toggle Administrative State

Router router = os.networking().router().toggleAdminStateUp("routerId", true);

Attaching / Detaching External Interfaces

// Attach an External Interface
RouterInterface iface = os.networking().router()
                          .attachInterface("routerId", AttachInterfaceType.SUBNET, "subnetId");

// Detach an External Interface
RouterInterface iface = os.networking().router()
                          .detachInterface("routerId", "subnetId", null);

Delete a Router


Querying for Routers

List<Router> = os.networking().router().list();

// Get a Router by ID
Router router = os.networking().router().get("routerId");