mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Modify template loading
Having the templates in seperate files is fine with me, btu we will need to figure out how to cleanly load them via the setup.py. rh_network's __virtual__ function was returning network, this created a collision with the network module, I have renamed it to netcfg. I know I am an Archer, so if anyone has any suggestions how to rename the netcfg module I am all ears
This commit is contained in:
parent
3cac1bd90e
commit
2ddd36f696
@ -1,27 +1,52 @@
|
||||
'''
|
||||
The networking module for RHEL/Fedora based distros
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from os.path import exists, dirname, join
|
||||
|
||||
from jinja2 import Environment, PackageLoader
|
||||
# import third party libs
|
||||
import jinja2
|
||||
|
||||
# Set up logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Set up template environment
|
||||
env = Environment(loader=PackageLoader('salt.modules', 'rh_network'))
|
||||
# Set up template environment and template strings
|
||||
conf_jinja = '''alias {{name}} bonding
|
||||
options {{name}} {% for item in bonding %}{{item}}={{bonding[item]}} {%endfor%}
|
||||
'''
|
||||
|
||||
eth_jinja = '''{% if proto %}BOOTPROTO={{proto}}
|
||||
{%endif%}DEVICE={{name}}
|
||||
{% for server in dns -%}
|
||||
DNS{{loop.index}}={{server}}
|
||||
{% endfor -%}
|
||||
{% if ethtool %}ETHTOOL_OPTS={%for item in ethtool %}{{item}} {{ethtool[item]}} {%endfor%}
|
||||
{%endif%}{%if bonding %}BONDING_OPTS={%for item in bonding %}{{item}}={{bonding[item]}} {%endfor%}
|
||||
{%endif%}{% if gateway %}GATEWAY={{gateway}}
|
||||
{%endif%}{% if addr %}HWADDR={{addr}}
|
||||
{%endif%}{% if ipaddr %}IPADDR={{ipaddr}}
|
||||
{%endif%}{% if master %}MASTER={{master}}
|
||||
{%endif%}{% if netmask %}NETMASK={{netmask}}
|
||||
{%endif%}{% if onboot %}ONBOOT={{onboot}}
|
||||
{%endif%}{% if peerdns %}PEERDNS={{peerdns}}
|
||||
{%endif%}{% if slave %}SLAVE={{slave}}
|
||||
{%endif%}{% if srcaddr %}SRCADDR={{srcaddr}}
|
||||
{%endif%}{% if userctl %}USERCTL={{userctl}}
|
||||
{%endif%}{% if userctl %}VLAN={{vlan}}{%endif%}
|
||||
'''
|
||||
|
||||
env = jinja2.Environment()
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Confine this module to RHEL/Fedora based distros$
|
||||
'''
|
||||
dists = ('CentOS', 'Scientific', 'RedHat')
|
||||
dists = ('CentOS', 'Scientific', 'RedHat', 'Fedora')
|
||||
if __grains__['os'] in dists:
|
||||
return 'network'
|
||||
return 'netcfg'
|
||||
return False
|
||||
|
||||
|
||||
@ -532,7 +557,7 @@ def build_bond(iface, settings):
|
||||
Create a bond script in /etc/modprobe.d
|
||||
'''
|
||||
opts = _parse_settings_bond(settings, iface)
|
||||
template = env.get_template('conf.jinja')
|
||||
template = env.from_string(conf_jinja)
|
||||
data = template.render({'name': iface, 'bonding': opts})
|
||||
_write_file(iface, data, _RH_NETWORK_CONF_FILES, '%s.conf')
|
||||
path = join(_RH_NETWORK_CONF_FILES, '%s.conf' % iface)
|
||||
@ -557,7 +582,8 @@ def build_interface(iface, type, settings):
|
||||
|
||||
if type in ['eth', 'bond', 'slave', 'vlan']:
|
||||
opts = _parse_settings_eth(settings, iface)
|
||||
template = env.get_template('eth.jinja')
|
||||
template = env.from_string(eth_jinja)
|
||||
print template
|
||||
ifcfg = template.render(opts)
|
||||
|
||||
_write_file(iface, ifcfg, _RH_NETWORK_SCRIPT_DIR, 'ifcfg-%s')
|
@ -1,2 +0,0 @@
|
||||
alias {{name}} bonding
|
||||
options {{name}} {% for item in bonding %}{{item}}={{bonding[item]}} {%endfor%}
|
@ -1,18 +0,0 @@
|
||||
{% if proto %}BOOTPROTO={{proto}}
|
||||
{%endif%}DEVICE={{name}}
|
||||
{% for server in dns -%}
|
||||
DNS{{loop.index}}={{server}}
|
||||
{% endfor -%}
|
||||
{% if ethtool %}ETHTOOL_OPTS={%for item in ethtool %}{{item}} {{ethtool[item]}} {%endfor%}
|
||||
{%endif%}{%if bonding %}BONDING_OPTS={%for item in bonding %}{{item}}={{bonding[item]}} {%endfor%}
|
||||
{%endif%}{% if gateway %}GATEWAY={{gateway}}
|
||||
{%endif%}{% if addr %}HWADDR={{addr}}
|
||||
{%endif%}{% if ipaddr %}IPADDR={{ipaddr}}
|
||||
{%endif%}{% if master %}MASTER={{master}}
|
||||
{%endif%}{% if netmask %}NETMASK={{netmask}}
|
||||
{%endif%}{% if onboot %}ONBOOT={{onboot}}
|
||||
{%endif%}{% if peerdns %}PEERDNS={{peerdns}}
|
||||
{%endif%}{% if slave %}SLAVE={{slave}}
|
||||
{%endif%}{% if srcaddr %}SRCADDR={{srcaddr}}
|
||||
{%endif%}{% if userctl %}USERCTL={{userctl}}
|
||||
{%endif%}{% if userctl %}VLAN={{vlan}}{%endif%}
|
Loading…
Reference in New Issue
Block a user