|
|
@ -141,25 +141,25 @@ def get_vlan_parent(device, vlan):
|
|
|
|
return re.sub(r'\.{}$'.format(vlan), '', device)
|
|
|
|
return re.sub(r'\.{}$'.format(vlan), '', device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_attr(context, name, attr, inventory_hostname=None):
|
|
|
|
def net_attr(context, name, attr, inventory_hostname=None):
|
|
|
|
var_name = "%s_%s" % (name, attr)
|
|
|
|
var_name = "%s_%s" % (name, attr)
|
|
|
|
return utils.get_hostvar(context, var_name, inventory_hostname)
|
|
|
|
return utils.get_hostvar(context, var_name, inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _make_attr_filter(attr):
|
|
|
|
def _make_attr_filter(attr):
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def func(context, name, inventory_hostname=None):
|
|
|
|
def func(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, attr, inventory_hostname)
|
|
|
|
return net_attr(context, name, attr, inventory_hostname)
|
|
|
|
return func
|
|
|
|
return func
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_vip_address(context, name, inventory_hostname=None):
|
|
|
|
def net_vip_address(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'vip_address', inventory_hostname)
|
|
|
|
return net_attr(context, name, 'vip_address', inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_ip(context, name, inventory_hostname=None):
|
|
|
|
def net_ip(context, name, inventory_hostname=None):
|
|
|
|
ips = net_attr(context, name, 'ips', inventory_hostname)
|
|
|
|
ips = net_attr(context, name, 'ips', inventory_hostname)
|
|
|
|
if ips:
|
|
|
|
if ips:
|
|
|
@ -169,56 +169,56 @@ def net_ip(context, name, inventory_hostname=None):
|
|
|
|
return ips.get(inventory_hostname)
|
|
|
|
return ips.get(inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_interface(context, name, inventory_hostname=None):
|
|
|
|
def net_interface(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'interface', inventory_hostname)
|
|
|
|
return net_attr(context, name, 'interface', inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_no_ip(context, name, inventory_hostname=None):
|
|
|
|
def net_no_ip(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'no_ip', inventory_hostname)
|
|
|
|
return net_attr(context, name, 'no_ip', inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_cidr(context, name, inventory_hostname=None):
|
|
|
|
def net_cidr(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'cidr', inventory_hostname)
|
|
|
|
return net_attr(context, name, 'cidr', inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_mask(context, name, inventory_hostname=None):
|
|
|
|
def net_mask(context, name, inventory_hostname=None):
|
|
|
|
cidr = net_cidr(context, name, inventory_hostname)
|
|
|
|
cidr = net_cidr(context, name, inventory_hostname)
|
|
|
|
return str(netaddr.IPNetwork(cidr).netmask) if cidr is not None else None
|
|
|
|
return str(netaddr.IPNetwork(cidr).netmask) if cidr is not None else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_prefix(context, name, inventory_hostname=None):
|
|
|
|
def net_prefix(context, name, inventory_hostname=None):
|
|
|
|
cidr = net_cidr(context, name, inventory_hostname)
|
|
|
|
cidr = net_cidr(context, name, inventory_hostname)
|
|
|
|
return str(netaddr.IPNetwork(cidr).prefixlen) if cidr is not None else None
|
|
|
|
return str(netaddr.IPNetwork(cidr).prefixlen) if cidr is not None else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_gateway(context, name, inventory_hostname=None):
|
|
|
|
def net_gateway(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'gateway', inventory_hostname)
|
|
|
|
return net_attr(context, name, 'gateway', inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_allocation_pool_start(context, name, inventory_hostname=None):
|
|
|
|
def net_allocation_pool_start(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'allocation_pool_start', inventory_hostname)
|
|
|
|
return net_attr(context, name, 'allocation_pool_start', inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_allocation_pool_end(context, name, inventory_hostname=None):
|
|
|
|
def net_allocation_pool_end(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'allocation_pool_end', inventory_hostname)
|
|
|
|
return net_attr(context, name, 'allocation_pool_end', inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_inspection_allocation_pool_start(context, name,
|
|
|
|
def net_inspection_allocation_pool_start(context, name,
|
|
|
|
inventory_hostname=None):
|
|
|
|
inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'inspection_allocation_pool_start',
|
|
|
|
return net_attr(context, name, 'inspection_allocation_pool_start',
|
|
|
|
inventory_hostname)
|
|
|
|
inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_inspection_allocation_pool_end(context, name, inventory_hostname=None):
|
|
|
|
def net_inspection_allocation_pool_end(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'inspection_allocation_pool_end',
|
|
|
|
return net_attr(context, name, 'inspection_allocation_pool_end',
|
|
|
|
inventory_hostname)
|
|
|
|
inventory_hostname)
|
|
|
@ -227,13 +227,13 @@ def net_inspection_allocation_pool_end(context, name, inventory_hostname=None):
|
|
|
|
net_inspection_gateway = _make_attr_filter('inspection_gateway')
|
|
|
|
net_inspection_gateway = _make_attr_filter('inspection_gateway')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_neutron_allocation_pool_start(context, name, inventory_hostname=None):
|
|
|
|
def net_neutron_allocation_pool_start(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'neutron_allocation_pool_start',
|
|
|
|
return net_attr(context, name, 'neutron_allocation_pool_start',
|
|
|
|
inventory_hostname)
|
|
|
|
inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_neutron_allocation_pool_end(context, name, inventory_hostname=None):
|
|
|
|
def net_neutron_allocation_pool_end(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'neutron_allocation_pool_end',
|
|
|
|
return net_attr(context, name, 'neutron_allocation_pool_end',
|
|
|
|
inventory_hostname)
|
|
|
|
inventory_hostname)
|
|
|
@ -242,12 +242,12 @@ def net_neutron_allocation_pool_end(context, name, inventory_hostname=None):
|
|
|
|
net_neutron_gateway = _make_attr_filter('neutron_gateway')
|
|
|
|
net_neutron_gateway = _make_attr_filter('neutron_gateway')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_vlan(context, name, inventory_hostname=None):
|
|
|
|
def net_vlan(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'vlan', inventory_hostname)
|
|
|
|
return net_attr(context, name, 'vlan', inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_mtu(context, name, inventory_hostname=None):
|
|
|
|
def net_mtu(context, name, inventory_hostname=None):
|
|
|
|
mtu = net_attr(context, name, 'mtu', inventory_hostname)
|
|
|
|
mtu = net_attr(context, name, 'mtu', inventory_hostname)
|
|
|
|
if mtu is not None:
|
|
|
|
if mtu is not None:
|
|
|
@ -264,7 +264,7 @@ net_ethtool_opts = _make_attr_filter('ethtool_opts')
|
|
|
|
net_zone = _make_attr_filter('zone')
|
|
|
|
net_zone = _make_attr_filter('zone')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_libvirt_network_name(context, name, inventory_hostname=None):
|
|
|
|
def net_libvirt_network_name(context, name, inventory_hostname=None):
|
|
|
|
"""Return the configured Libvirt name for a network.
|
|
|
|
"""Return the configured Libvirt name for a network.
|
|
|
|
|
|
|
|
|
|
|
@ -275,7 +275,7 @@ def net_libvirt_network_name(context, name, inventory_hostname=None):
|
|
|
|
return libvirt_name or name
|
|
|
|
return libvirt_name or name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_bridge_ports(context, name, inventory_hostname=None):
|
|
|
|
def net_bridge_ports(context, name, inventory_hostname=None):
|
|
|
|
return net_attr(context, name, 'bridge_ports', inventory_hostname)
|
|
|
|
return net_attr(context, name, 'bridge_ports', inventory_hostname)
|
|
|
|
|
|
|
|
|
|
|
@ -326,7 +326,7 @@ def _validate_rules(rules):
|
|
|
|
"for CentOS")
|
|
|
|
"for CentOS")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_interface_obj(context, name, inventory_hostname=None):
|
|
|
|
def net_interface_obj(context, name, inventory_hostname=None):
|
|
|
|
"""Return a dict representation of a network interface.
|
|
|
|
"""Return a dict representation of a network interface.
|
|
|
|
|
|
|
|
|
|
|
@ -378,7 +378,7 @@ def net_interface_obj(context, name, inventory_hostname=None):
|
|
|
|
return interface
|
|
|
|
return interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_bridge_obj(context, name, inventory_hostname=None):
|
|
|
|
def net_bridge_obj(context, name, inventory_hostname=None):
|
|
|
|
"""Return a dict representation of a network bridge interface.
|
|
|
|
"""Return a dict representation of a network bridge interface.
|
|
|
|
|
|
|
|
|
|
|
@ -432,7 +432,7 @@ def net_bridge_obj(context, name, inventory_hostname=None):
|
|
|
|
return interface
|
|
|
|
return interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_bond_obj(context, name, inventory_hostname=None):
|
|
|
|
def net_bond_obj(context, name, inventory_hostname=None):
|
|
|
|
"""Return a dict representation of a network bond interface.
|
|
|
|
"""Return a dict representation of a network bond interface.
|
|
|
|
|
|
|
|
|
|
|
@ -523,27 +523,27 @@ def _net_interface_type(context, name, inventory_hostname):
|
|
|
|
return 'bond'
|
|
|
|
return 'bond'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_is_ether(context, name, inventory_hostname=None):
|
|
|
|
def net_is_ether(context, name, inventory_hostname=None):
|
|
|
|
return _net_interface_type(context, name, inventory_hostname) == 'ether'
|
|
|
|
return _net_interface_type(context, name, inventory_hostname) == 'ether'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_is_bridge(context, name, inventory_hostname=None):
|
|
|
|
def net_is_bridge(context, name, inventory_hostname=None):
|
|
|
|
return _net_interface_type(context, name, inventory_hostname) == 'bridge'
|
|
|
|
return _net_interface_type(context, name, inventory_hostname) == 'bridge'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_is_bond(context, name, inventory_hostname=None):
|
|
|
|
def net_is_bond(context, name, inventory_hostname=None):
|
|
|
|
return _net_interface_type(context, name, inventory_hostname) == 'bond'
|
|
|
|
return _net_interface_type(context, name, inventory_hostname) == 'bond'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_is_vlan(context, name, inventory_hostname=None):
|
|
|
|
def net_is_vlan(context, name, inventory_hostname=None):
|
|
|
|
return net_vlan(context, name) is not None
|
|
|
|
return net_vlan(context, name) is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_is_vlan_interface(context, name, inventory_hostname=None):
|
|
|
|
def net_is_vlan_interface(context, name, inventory_hostname=None):
|
|
|
|
device = get_and_validate_interface(context, name, inventory_hostname)
|
|
|
|
device = get_and_validate_interface(context, name, inventory_hostname)
|
|
|
|
# Use a heuristic to match conventional VLAN names, ending with a
|
|
|
|
# Use a heuristic to match conventional VLAN names, ending with a
|
|
|
@ -551,43 +551,43 @@ def net_is_vlan_interface(context, name, inventory_hostname=None):
|
|
|
|
return re.match(r"^[a-zA-Z0-9_\-]+\.[1-9][\d]{0,3}$", device)
|
|
|
|
return re.match(r"^[a-zA-Z0-9_\-]+\.[1-9][\d]{0,3}$", device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_select_ethers(context, names, inventory_hostname=None):
|
|
|
|
def net_select_ethers(context, names, inventory_hostname=None):
|
|
|
|
return [name for name in names
|
|
|
|
return [name for name in names
|
|
|
|
if net_is_ether(context, name, inventory_hostname)]
|
|
|
|
if net_is_ether(context, name, inventory_hostname)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_select_bridges(context, names, inventory_hostname=None):
|
|
|
|
def net_select_bridges(context, names, inventory_hostname=None):
|
|
|
|
return [name for name in names
|
|
|
|
return [name for name in names
|
|
|
|
if net_is_bridge(context, name, inventory_hostname)]
|
|
|
|
if net_is_bridge(context, name, inventory_hostname)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_select_bonds(context, names, inventory_hostname=None):
|
|
|
|
def net_select_bonds(context, names, inventory_hostname=None):
|
|
|
|
return [name for name in names
|
|
|
|
return [name for name in names
|
|
|
|
if net_is_bond(context, name, inventory_hostname)]
|
|
|
|
if net_is_bond(context, name, inventory_hostname)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_select_vlans(context, names, inventory_hostname=None):
|
|
|
|
def net_select_vlans(context, names, inventory_hostname=None):
|
|
|
|
return [name for name in names
|
|
|
|
return [name for name in names
|
|
|
|
if net_is_vlan(context, name, inventory_hostname)]
|
|
|
|
if net_is_vlan(context, name, inventory_hostname)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_select_vlan_interfaces(context, names, inventory_hostname=None):
|
|
|
|
def net_select_vlan_interfaces(context, names, inventory_hostname=None):
|
|
|
|
return [name for name in names
|
|
|
|
return [name for name in names
|
|
|
|
if net_is_vlan_interface(context, name, inventory_hostname)]
|
|
|
|
if net_is_vlan_interface(context, name, inventory_hostname)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_reject_vlans(context, names, inventory_hostname=None):
|
|
|
|
def net_reject_vlans(context, names, inventory_hostname=None):
|
|
|
|
return [name for name in names
|
|
|
|
return [name for name in names
|
|
|
|
if not net_is_vlan(context, name, inventory_hostname)]
|
|
|
|
if not net_is_vlan(context, name, inventory_hostname)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_configdrive_network_device(context, name, inventory_hostname=None):
|
|
|
|
def net_configdrive_network_device(context, name, inventory_hostname=None):
|
|
|
|
device = net_interface(context, name, inventory_hostname)
|
|
|
|
device = net_interface(context, name, inventory_hostname)
|
|
|
|
if not device:
|
|
|
|
if not device:
|
|
|
@ -619,7 +619,7 @@ def net_configdrive_network_device(context, name, inventory_hostname=None):
|
|
|
|
return interface
|
|
|
|
return interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_libvirt_network(context, name, inventory_hostname=None):
|
|
|
|
def net_libvirt_network(context, name, inventory_hostname=None):
|
|
|
|
"""Return a dict which describes the Libvirt network for a network.
|
|
|
|
"""Return a dict which describes the Libvirt network for a network.
|
|
|
|
|
|
|
|
|
|
|
@ -634,7 +634,7 @@ def net_libvirt_network(context, name, inventory_hostname=None):
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_libvirt_vm_network(context, name, inventory_hostname=None):
|
|
|
|
def net_libvirt_vm_network(context, name, inventory_hostname=None):
|
|
|
|
"""Return a dict which describes the Libvirt VM's network for a network.
|
|
|
|
"""Return a dict which describes the Libvirt VM's network for a network.
|
|
|
|
|
|
|
|
|
|
|
@ -648,7 +648,7 @@ def net_libvirt_vm_network(context, name, inventory_hostname=None):
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@jinja2.contextfilter
|
|
|
|
@jinja2.pass_context
|
|
|
|
def net_ovs_veths(context, names, inventory_hostname=None):
|
|
|
|
def net_ovs_veths(context, names, inventory_hostname=None):
|
|
|
|
"""Return a list of virtual Ethernet pairs for OVS.
|
|
|
|
"""Return a list of virtual Ethernet pairs for OVS.
|
|
|
|
|
|
|
|
|
|
|
|