The nova.network.linux_net Module

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.

apply()
defer_apply_off()
defer_apply_on()
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.

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’.

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.

empty_chain(chain, wrap=True)

Remove all rules from a chain.

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.

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.

class LinuxBridgeInterfaceDriver

Bases: nova.network.linux_net.LinuxNetInterfaceDriver

classmethod 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.

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 ensure_vlan(*args, **kwargs)

Create a vlan unless it already exists.

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

Create a vlan and bridge unless they already exist.

get_dev(network)
plug(network, mac_address, gateway=True)
unplug(network)
class LinuxNetInterfaceDriver

Bases: object

Abstract class that defines generic network host API

get_dev(network)

Get device name

plug(network, mac_address)

Create Linux device, return device name

unplug(network)

Destory Linux device, return device name

class LinuxOVSInterfaceDriver

Bases: nova.network.linux_net.LinuxNetInterfaceDriver

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

Bases: nova.network.linux_net.LinuxNetInterfaceDriver

BRIDGE_NAME_PREFIX = 'brq'
GATEWAY_INTERFACE_PREFIX = 'gw-'
classmethod create_tap_dev(_self, dev, mac_address=None)
get_bridge(network)
get_dev(network)
plug(network, mac_address, gateway=True)
unplug(network)
add_snat_rule(ip_range)
bind_floating_ip(floating_ip, device)

Bind ip to public interface.

ensure_floating_forward(floating_ip, fixed_ip)

Ensure floating ip forwarding rule.

ensure_metadata_ip()

Sets up local metadata ip.

ensure_path(path)
ensure_vpn_forward(public_ip, port, private_ip)

Sets up forwarding rules for vlan.

floating_forward_rules(floating_ip, fixed_ip)
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.

init_host(ip_range=None)

Basic networking setup goes here.

initialize_gateway_device(dev, network_ref)
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_floating_forward(floating_ip, fixed_ip)

Remove forwarding for floating ip.

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.

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_ra(*args, **kwargs)
write_to_file(file, data, mode='w')

Previous topic

The nova.network.ldapdns Module

Next topic

The nova.network.manager Module

This Page