Networking

The nova.network.manager Module

Network Hosts are responsible for allocating ips and setting up network.

There are multiple backend drivers that handle specific types of networking topologies. All of the network commands are issued to a subclass of NetworkManager.

Related Flags

network_driver:Driver to use for network creation
flat_network_bridge:
 Bridge device for simple network instances
flat_interface:FlatDhcp will bridge into this interface if set
flat_network_dns:
 Dns for simple network
vlan_start:First VLAN for private networks
vpn_ip:Public IP for the cloudpipe VPN servers
vpn_start:First Vpn port for private networks
cnt_vpn_clients:
 Number of addresses reserved for vpn clients
network_size:Number of addresses in each private subnet
fixed_range:Fixed IP address block
fixed_ip_disassociate_timeout:
 Seconds after which a deallocated ip is disassociated
create_unique_mac_address_attempts:
 Number of times to attempt creating a unique mac address
class FlatDHCPManager(network_driver=None, *args, **kwargs)

Bases: nova.network.manager.RPCAllocateFixedIP, nova.network.floating_ips.FloatingIP, nova.network.manager.NetworkManager

Flat networking with dhcp.

FlatDHCPManager will start up one dhcp server to give out addresses. It never injects network settings into the guest. It also manages bridges. Otherwise it behaves like FlatManager.

FlatDHCPManager.DHCP = True
FlatDHCPManager.SHOULD_CREATE_BRIDGE = True
FlatDHCPManager.init_host()

Do any initialization that needs to be run if this is a standalone service.

FlatDHCPManager.required_create_args = ['bridge']
class FlatManager(network_driver=None, *args, **kwargs)

Bases: nova.network.manager.NetworkManager

Basic network where no vlans are used.

FlatManager does not do any bridge or vlan creation. The user is responsible for setting up whatever bridges are specified when creating networks through nova-manage. This bridge needs to be created on all compute hosts.

The idea is to create a single network for the host with a command like: nova-manage network create 192.168.0.0/24 1 256. Creating multiple networks for for one manager is currently not supported, but could be added by modifying allocate_fixed_ip and get_network to get the network with new logic. Arbitrary lists of addresses in a single network can be accomplished with manual db editing.

If flat_injected is True, the compute host will attempt to inject network config into the guest. It attempts to modify /etc/network/interfaces and currently only works on debian based systems. To support a wider range of OSes, some other method may need to be devised to let the guest know which ip it should be using so that it can configure itself. Perhaps an attached disk or serial device with configuration info.

Metadata forwarding must be handled by the gateway, and since nova does not do any setup in this mode, it must be done manually. Requests to 169.254.169.254 port 80 will need to be forwarded to the api server.

FlatManager.allocate_floating_ip(context, *args, **kwargs)

Gets a floating ip from the pool.

FlatManager.associate_floating_ip(context, *args, **kwargs)

Associates a floating ip with a fixed ip.

Makes sure everything makes sense then calls _associate_floating_ip, rpc’ing to correct host if i’m not it.

FlatManager.deallocate_fixed_ip(context, address, host=None, teardown=True)

Returns a fixed ip to the pool.

FlatManager.deallocate_floating_ip(context, *args, **kwargs)

Returns a floating ip to the pool.

FlatManager.disassociate_floating_ip(context, *args, **kwargs)

Disassociates a floating ip from its fixed ip.

Makes sure everything makes sense then calls _disassociate_floating_ip, rpc’ing to correct host if i’m not it.

FlatManager.get_floating_ip(context, id)

Returns a floating IP as a dict.

FlatManager.get_floating_ip_by_address(context, address)

Returns a floating IP as a dict.

FlatManager.get_floating_ip_pools(context)

Returns list of floating ip pools.

FlatManager.get_floating_ips_by_fixed_address(context, fixed_address)

Returns the floating IPs associated with a fixed_address.

FlatManager.get_floating_ips_by_project(context)

Returns the floating IPs allocated to a project.

FlatManager.get_floating_pools(context)

Returns list of floating pools.

FlatManager.migrate_instance_finish(context, instance_uuid, floating_addresses, host=None, rxtx_factor=None, project_id=None, source=None, dest=None)
FlatManager.migrate_instance_start(context, instance_uuid, floating_addresses, rxtx_factor=None, project_id=None, source=None, dest=None)
FlatManager.required_create_args = ['bridge']
FlatManager.timeout_fixed_ips = False
FlatManager.update_dns(context, network_ids)

Called when fixed IP is allocated or deallocated.

class NetworkManager(network_driver=None, *args, **kwargs)

Bases: nova.manager.Manager

Implements common network manager functionality.

This class must be subclassed to support specific topologies.

host management:
hosts configure themselves for networks they are assigned to in the table upon startup. If there are networks in the table which do not have hosts, those will be filled in and have hosts configured as the hosts pick them up one at time during their periodic task. The one at a time part is to flatten the layout to help scale
NetworkManager.DHCP = False
NetworkManager.RPC_API_VERSION = '1.9'
NetworkManager.SHOULD_CREATE_BRIDGE = False
NetworkManager.SHOULD_CREATE_VLAN = False
NetworkManager.add_fixed_ip_to_instance(context, instance_id, host, network_id, rxtx_factor=None)

Adds a fixed ip to an instance from specified network.

NetworkManager.add_network_to_project(ctxt, project_id, network_uuid)
NetworkManager.allocate_fixed_ip(context, instance_id, network, **kwargs)

Gets a fixed ip from the pool.

NetworkManager.allocate_for_instance(context, **kwargs)

Handles allocating the various network resources for an instance.

rpc.called by network_api

NetworkManager.build_network_info_model(context, vifs, networks, rxtx_factor, instance_host)

Builds a NetworkInfo object containing all network information for an instance

NetworkManager.create_networks(context, label, cidr=None, multi_host=None, num_networks=None, network_size=None, cidr_v6=None, gateway=None, gateway_v6=None, bridge=None, bridge_interface=None, dns1=None, dns2=None, fixed_cidr=None, **kwargs)
NetworkManager.deallocate_fixed_ip(context, address, host=None, teardown=True)

Returns a fixed ip to the pool.

NetworkManager.deallocate_for_instance(context, **kwargs)

Handles deallocating various network resources for an instance.

rpc.called by network_api kwargs can contain fixed_ips to circumvent another db lookup

NetworkManager.delete_network(context, fixed_range, uuid, require_disassociated=True)
NetworkManager.disassociate_network(context, network_uuid)
NetworkManager.get_all_networks(context)
NetworkManager.get_backdoor_port(context)

Return backdoor port for eventlet_backdoor.

NetworkManager.get_dhcp_leases(ctxt, network_ref)

Broker the request to the driver to fetch the dhcp leases.

NetworkManager.get_fixed_ip(context, id)

Return a fixed ip.

NetworkManager.get_fixed_ip_by_address(context, address)
NetworkManager.get_floating_ips_by_fixed_address(context, fixed_address)
NetworkManager.get_instance_id_by_floating_address(context, address)

Returns the instance id a floating ip’s fixed ip is allocated to.

NetworkManager.get_instance_nw_info(context, instance_id, rxtx_factor, host, instance_uuid=None, **kwargs)

Creates network info list for instance.

called by allocate_for_instance and network_api context needs to be elevated :returns: network info list [(network,info),(network,info)...] where network = dict containing pertinent data from a network db object and info = dict containing pertinent networking data

NetworkManager.get_instance_uuids_by_ip_filter(context, filters)
NetworkManager.get_network(context, network_uuid)
NetworkManager.get_vif_by_mac_address(context, mac_address)

Returns the vifs record for the mac_address.

NetworkManager.get_vifs_by_instance(context, instance_id)

Returns the vifs associated with an instance.

NetworkManager.init_host()

Do any initialization that needs to be run if this is a standalone service.

NetworkManager.lease_fixed_ip(context, address)

Called by dhcp-bridge when ip is leased.

NetworkManager.release_fixed_ip(context, address)

Called by dhcp-bridge when ip is released.

NetworkManager.remove_fixed_ip_from_instance(context, instance_id, host, address, rxtx_factor=None)

Removes a fixed ip from an instance from specified network.

NetworkManager.required_create_args = []
NetworkManager.rpc_setup_network_on_host(context, network_id, teardown)
NetworkManager.set_network_host(context, network_ref)

Safely sets the host of the network.

NetworkManager.setup_networks_on_host(context, instance_id, host, teardown=False)

calls setup/teardown on network hosts for an instance.

NetworkManager.timeout_fixed_ips = True
NetworkManager.update_dns(context, network_ids)

Called when fixed IP is allocated or deallocated.

NetworkManager.validate_networks(context, networks)

check if the networks exists and host is set to each network.

class RPCAllocateFixedIP

Bases: object

Mixin class originally for FlatDCHP and VLAN network managers.

used since they share code to RPC.call allocate_fixed_ip on the correct network host to configure dnsmasq

RPCAllocateFixedIP.deallocate_fixed_ip(context, address, host=None, teardown=True)

Call the superclass deallocate_fixed_ip if i’m the correct host otherwise call to the correct host

RPCAllocateFixedIP.servicegroup_api = None
class VlanManager(network_driver=None, *args, **kwargs)

Bases: nova.network.manager.RPCAllocateFixedIP, nova.network.floating_ips.FloatingIP, nova.network.manager.NetworkManager

Vlan network with dhcp.

VlanManager is the most complicated. It will create a host-managed vlan for each project. Each project gets its own subnet. The networks and associated subnets are created with nova-manage using a command like: nova-manage network create 10.0.0.0/8 3 16. This will create 3 networks of 16 addresses from the beginning of the 10.0.0.0 range.

A dhcp server is run for each subnet, so each project will have its own. For this mode to be useful, each project will need a vpn to access the instances in its subnet.

VlanManager.DHCP = True
VlanManager.SHOULD_CREATE_BRIDGE = True
VlanManager.SHOULD_CREATE_VLAN = True
VlanManager.add_network_to_project(context, project_id, network_uuid=None)

Force adds another network to a project.

VlanManager.allocate_fixed_ip(context, instance_id, network, **kwargs)

Gets a fixed ip from the pool.

VlanManager.associate(context, network_uuid, associations)

Associate or disassociate host or project to network.

VlanManager.create_networks(context, **kwargs)

Create networks based on parameters.

VlanManager.init_host()

Do any initialization that needs to be run if this is a standalone service.

VlanManager.required_create_args = ['bridge_interface']

The nova.network.linux_net Driver

Implements vlans, bridges, and iptables rules using linux utilities.

class IptablesManager(execute=None)

Bases: object

Wrapper for iptables.

See IptablesTable for some usage docs

A number of chains are set up to begin with.

First, nova-filter-top. It’s added at the top of FORWARD and OUTPUT. Its name is not wrapped, so it’s shared between the various nova workers. It’s intended for rules that need to live at the top of the FORWARD and OUTPUT chains. It’s in both the ipv4 and ipv6 set of tables.

For ipv4 and ipv6, the built-in INPUT, OUTPUT, and FORWARD filter chains are wrapped, meaning that the “real” INPUT chain has a rule that jumps to the wrapped INPUT chain, etc. Additionally, there’s a wrapped chain named “local” which is jumped to from nova-filter-top.

For ipv4, the built-in PREROUTING, OUTPUT, and POSTROUTING nat chains are wrapped in the same was as the built-in filter chains. Additionally, there’s a snat chain that is applied after the POSTROUTING chain.

IptablesManager.apply()
IptablesManager.defer_apply_off()
IptablesManager.defer_apply_on()
IptablesManager.dirty()
class IptablesRule(chain, rule, wrap=True, top=False)

Bases: object

An iptables rule.

You shouldn’t need to use this class directly, it’s only used by IptablesManager.

class IptablesTable

Bases: object

An iptables table.

IptablesTable.add_chain(name, wrap=True)

Adds a named chain to the table.

The chain name is wrapped to be unique for the component creating it, so different components of Nova can safely create identically named chains without interfering with one another.

At the moment, its wrapped name is <binary name>-<chain name>, so if nova-compute creates a chain named ‘OUTPUT’, it’ll actually end up named ‘nova-compute-OUTPUT’.

IptablesTable.add_rule(chain, rule, wrap=True, top=False)

Add a rule to the table.

This is just like what you’d feed to iptables, just without the ‘-A <chain name>’ bit at the start.

However, if you need to jump to one of your wrapped chains, prepend its name with a ‘$’ which will ensure the wrapping is applied correctly.

IptablesTable.empty_chain(chain, wrap=True)

Remove all rules from a chain.

IptablesTable.remove_chain(name, wrap=True)

Remove named chain.

This removal “cascades”. All rule in the chain are removed, as are all rules in other chains that jump to it.

If the chain is not found, this is merely logged.

IptablesTable.remove_rule(chain, rule, wrap=True, top=False)

Remove a rule from a chain.

Note: The rule must be exactly identical to the one that was added. You cannot switch arguments around like you can with the iptables CLI tool.

IptablesTable.remove_rules_regex(regex)

Remove all rules matching regex.

class LinuxBridgeInterfaceDriver

Bases: nova.network.linux_net.LinuxNetInterfaceDriver

classmethod LinuxBridgeInterfaceDriver.ensure_bridge(*args, **kwargs)

Create a bridge unless it already exists.

Parameters:
  • interface – the interface to create the bridge on.
  • net_attrs – dictionary with attributes used to create bridge.
  • gateway – whether or not the bridge is a gateway.
  • filtering – whether or not to create filters on the bridge.

If net_attrs is set, it will add the net_attrs[‘gateway’] to the bridge using net_attrs[‘broadcast’] and net_attrs[‘cidr’]. It will also add the ip_v6 address specified in net_attrs[‘cidr_v6’] if use_ipv6 is set.

The code will attempt to move any ips that already exist on the interface onto the bridge and reset the default gateway if necessary.

classmethod LinuxBridgeInterfaceDriver.ensure_vlan(*args, **kwargs)

Create a vlan unless it already exists.

classmethod LinuxBridgeInterfaceDriver.ensure_vlan_bridge(_self, vlan_num, bridge, bridge_interface, net_attrs=None, mac_address=None)

Create a vlan and bridge unless they already exist.

LinuxBridgeInterfaceDriver.get_dev(network)
LinuxBridgeInterfaceDriver.plug(network, mac_address, gateway=True)
classmethod LinuxBridgeInterfaceDriver.remove_bridge(*args, **kwargs)

Delete a bridge.

classmethod LinuxBridgeInterfaceDriver.remove_vlan(*args, **kwargs)

Delete a vlan.

classmethod LinuxBridgeInterfaceDriver.remove_vlan_bridge(vlan_num, bridge)

Delete a bridge and vlan.

LinuxBridgeInterfaceDriver.unplug(network, gateway=True)
class LinuxNetInterfaceDriver

Bases: object

Abstract class that defines generic network host API for for all Linux interface drivers.

LinuxNetInterfaceDriver.get_dev(network)

Get device name.

LinuxNetInterfaceDriver.plug(network, mac_address)

Create Linux device, return device name.

LinuxNetInterfaceDriver.unplug(network)

Destroy Linux device, return device name.

class LinuxOVSInterfaceDriver

Bases: nova.network.linux_net.LinuxNetInterfaceDriver

LinuxOVSInterfaceDriver.get_dev(network)
LinuxOVSInterfaceDriver.plug(network, mac_address, gateway=True)
LinuxOVSInterfaceDriver.unplug(network)
class QuantumLinuxBridgeInterfaceDriver

Bases: nova.network.linux_net.LinuxNetInterfaceDriver

QuantumLinuxBridgeInterfaceDriver.BRIDGE_NAME_PREFIX = 'brq'
QuantumLinuxBridgeInterfaceDriver.GATEWAY_INTERFACE_PREFIX = 'gw-'
QuantumLinuxBridgeInterfaceDriver.get_bridge(network)
QuantumLinuxBridgeInterfaceDriver.get_dev(network)
QuantumLinuxBridgeInterfaceDriver.plug(network, mac_address, gateway=True)
QuantumLinuxBridgeInterfaceDriver.unplug(network)
add_snat_rule(ip_range)
bind_floating_ip(floating_ip, device)

Bind ip to public interface.

create_ovs_vif_port(bridge, dev, iface_id, mac, instance_id)
create_tap_dev(dev, mac_address=None)
delete_ovs_vif_port(bridge, dev)
device_exists(device)

Check if ethernet device exists.

ensure_ebtables_rules(*args, **kwargs)
ensure_floating_forward(floating_ip, fixed_ip, device, network)

Ensure floating ip forwarding rule.

ensure_metadata_ip()

Sets up local metadata ip.

ensure_vpn_forward(public_ip, port, private_ip)

Sets up forwarding rules for vlan.

floating_ebtables_rules(fixed_ip, network)

Makes sure only in-network traffic is bridged.

floating_forward_rules(floating_ip, fixed_ip, device)
get_binary_name()

Grab the name of the binary we’re running in.

get_dev(network)
get_dhcp_hosts(context, network_ref)

Get network’s hosts config in dhcp-host format.

get_dhcp_leases(context, network_ref)

Return a network’s hosts config in dnsmasq leasefile format.

get_dhcp_opts(context, network_ref)

Get network’s hosts config in dhcp-opts format.

get_dns_hosts(context, network_ref)

Get network’s DNS hosts in hosts format.

get_gateway_rules(bridge)
init_host(ip_range=None)

Basic networking setup goes here.

initialize_gateway_device(dev, network_ref)
isolate_dhcp_address(interface, address)
kill_dhcp(dev)
metadata_accept()

Create the filter accept rule for metadata.

metadata_forward()

Create forwarding rule for metadata.

plug(network, mac_address, gateway=True)
release_dhcp(dev, address, mac_address)
remove_ebtables_rules(*args, **kwargs)
remove_floating_forward(floating_ip, fixed_ip, device, network)

Remove forwarding for floating ip.

remove_isolate_dhcp_address(interface, address)
restart_dhcp(*args, **kwargs)

(Re)starts a dnsmasq server for a given network.

If a dnsmasq instance is already running then send a HUP signal causing it to reload, otherwise spawn a new instance.

send_arp_for_ip(ip, device, count)
unbind_floating_ip(floating_ip, device)

Unbind a public ip from public interface.

unplug(network)
update_dhcp(context, dev, network_ref)
update_dhcp_hostfile_with_text(dev, hosts_text)
update_dns(context, dev, network_ref)
update_ra(*args, **kwargs)
write_to_file(file, data, mode='w')

Tests

The network_unittest Module

Table Of Contents

Previous topic

Virtualization

Next topic

API Endpoint

This Page