Browse Source

Merge pull request #86 from avlasov-mos-de/master

Add dhclient basic configuration
pr/linux_system_repo_key
Filip Pytloun 7 years ago
parent
commit
be897231ea
6 changed files with 265 additions and 2 deletions
  1. +78
    -2
      README.rst
  2. +106
    -0
      linux/files/dhclient.conf
  3. +3
    -0
      linux/map.jinja
  4. +11
    -0
      linux/network/dhclient.sls
  5. +3
    -0
      linux/network/init.sls
  6. +64
    -0
      tests/pillar/network.sls

+ 78
- 2
README.rst View File

https: http://maas-01:8080 https: http://maas-01:8080
... ...
proxy: proxy:
# package manager fallback defaults
# package manager fallback defaults
# used if linux:system:repo:apt-mk:proxy has no protocol specific entries # used if linux:system:repo:apt-mk:proxy has no protocol specific entries
pkg: pkg:
enabled: true enabled: true
ftp: ftp://proxy.host.local:2121 ftp: ftp://proxy.host.local:2121
#http: http://proxy.host.local:3142 #http: http://proxy.host.local:3142
#https: https://proxy.host.local:3143 #https: https://proxy.host.local:3143
...
...
# global system fallback system defaults # global system fallback system defaults
ftp: ftp://proxy.host.local:2121 ftp: ftp://proxy.host.local:2121
http: http://proxy.host.local:3142 http: http://proxy.host.local:3142
use_interfaces: use_interfaces:
- eth1 - eth1


DHCP client configuration

None of the keys is mandatory, include only those you really need. For full list
of available options under send, supersede, prepend, append refer to dhcp-options(5)

.. code-block:: yaml

linux:
network:
dhclient:
enabled: true
backoff_cutoff: 15
initial_interval: 10
reboot: 10
retry: 60
select_timeout: 0
timeout: 120
send:
- option: host-name
declaration: "= gethostname()"
supersede:
- option: host-name
declaration: "spaceship"
- option: domain-name
declaration: "domain.home"
#- option: arp-cache-timeout
# declaration: 20
prepend:
- option: domain-name-servers
declaration:
- 8.8.8.8
- 8.8.4.4
- option: domain-search
declaration:
- example.com
- eng.example.com
#append:
#- option: domain-name-servers
# declaration: 127.0.0.1
# ip or subnet to reject dhcp offer from
reject:
- 192.33.137.209
- 10.0.2.0/24
request:
- subnet-mask
- broadcast-address
- time-offset
- routers
- domain-name
- domain-name-servers
- domain-search
- host-name
- dhcp6.name-servers
- dhcp6.domain-search
- dhcp6.fqdn
- dhcp6.sntp-servers
- netbios-name-servers
- netbios-scope
- interface-mtu
- rfc3442-classless-static-routes
- ntp-servers
require:
- subnet-mask
- domain-name-servers
# if per interface configuration required add below
interface:
ens2:
initial_interval: 11
reject:
- 192.33.137.210
ens3:
initial_interval: 12
reject:
- 192.33.137.211


Configure global environment variables Configure global environment variables
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



+ 106
- 0
linux/files/dhclient.conf View File

{# Macro, put quotation marks around strings that are not ipv4 address #}
{%- macro quote_if_not_ip(var) -%}
{%- set var_split_str = var.split(".") -%}
{%- if var_split_str|length == 4 -%}
{%- set var_is_ipaddr = True -%}
{%- for octet in var_split_str -%}
{%- if not octet|int in range(255) -%}
{%- set var_is_ipaddr = False -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- if var_is_ipaddr is defined and var_is_ipaddr == True -%}
{{ var }}
{%- else -%}
"{{ var }}"
{%- endif -%}
{%- endmacro -%}

{# Macro, renders nested options for specific key #}
{%- macro render_key(section, key) -%}
{%- if section.get(key) and section.get(key)|length > 0 %}
{%- for item in section.get(key) %}
{%- if item.declaration is string %}
{{ key }} {{ item.option }} {{ quote_if_not_ip(item.declaration) }};
{%- elif item.declaration is sequence %}
{{ key }} {{ item.option }}
{%- for value in item.declaration -%}
{%- set space = " " -%}
{{ space }}{{ quote_if_not_ip(value) }}
{%- if not loop.last -%},{%- endif -%}
{%- endfor -%}
;
{%- else %}
{{ key }} {{ item.option }} {{ item.declaration }};
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endmacro -%}

{# Macro, renders set of options for global section or for interface section #}
{%- macro render_section(section) -%}
{%- if section.backoff_cutoff is defined %}
backoff-cutoff {{ section.backoff_cutoff|default(15, true) }};
{%- endif -%}

{%- if section.initial_interval is defined %}
initial-interval {{ section.initial_interval|default(10, true) }};
{%- endif -%}

{%- if section.reboot is defined %}
# The reboot statement sets the time that must elapse after the client
# first tries to reacquire its old address before it gives up and tries
# to discover a new address.
reboot {{ section.reboot|default(10, true) }};
{%- endif -%}

{%- if section.retry is defined %}
retry {{ section.retry|default(60, true) }};
{%- endif -%}

{%- if section.select_timeout is defined %}
# The select-timeout is the time after the client sends its first lease
# discovery request at which it stops waiting for offers from servers,
# assuming that it has received at least one such offer
select-timeout {{ section.select_timeout|default(0, True) }};
{%- endif -%}

{%- if section.timeout is defined %}
timeout {{ section.timeout|default(120, True) }};
{%- endif -%}

{{ render_key(section, "send") }}
{{ render_key(section, "supersede") }}
{{ render_key(section, "prepend") }}
{{ render_key(section, "append") }}

{%- if section.reject is defined and section.reject|length > 0 %}
reject {{ section.reject|join(",\n ") }};
{%- endif %}

{%- if section.request is defined and section.request|length > 0 %}
request {{ section.request|join(",\n ") }};
{%- endif %}

{%- if section.require is defined and section.require|length > 0 %}
require {{ section.require|join(",\n ") }};
{% endif -%}
{%- endmacro -%}

{# Actual template start #}
{%- from "linux/map.jinja" import network with context -%}
{%- set dhclient = network.get('dhclient', {}) %}
# dhclient.conf(5) file managed by salt-minion(1)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
{{ render_section(dhclient) }}
{%- if dhclient.get("interface") -%}
{%- for iface_name, options in dhclient.interface.iteritems() %}
{%- if network.interface.get(iface_name) and network.interface.get(iface_name).enabled == True
and network.interface.get(iface_name).proto == 'dhcp' -%}
interface "{{ iface_name }}" {
{{ render_section(options)|indent }}
}
{%- endif -%}
{%- endfor %}
{%- endif -%}

+ 3
- 0
linux/map.jinja View File

'host': 'none', 'host': 'none',
}, },
'host': {}, 'host': {},
'dhclient_config': '/etc/dhcp/dhclient.conf',
}, },
'Debian': { 'Debian': {
'hostname_file': '/etc/hostname', 'hostname_file': '/etc/hostname',
'host': 'none' 'host': 'none'
}, },
'host': {}, 'host': {},
'dhclient_config': '/etc/dhcp/dhclient.conf',
}, },
'RedHat': { 'RedHat': {
'bridge_pkgs': ['bridge-utils'], 'bridge_pkgs': ['bridge-utils'],
'host': 'none' 'host': 'none'
}, },
'host': {}, 'host': {},
'dhclient_config': '/etc/dhcp/dhclient.conf',
}, },
}, grain='os_family', merge=salt['pillar.get']('linux:network')) %} }, grain='os_family', merge=salt['pillar.get']('linux:network')) %}



+ 11
- 0
linux/network/dhclient.sls View File

{%- from "linux/map.jinja" import network with context %}

{%- if network.dhclient.enabled|default(False) %}

dhclient_conf:
file.managed:
- name: {{ network.dhclient_config }}
- source: salt://linux/files/dhclient.conf
- template: jinja

{%- endif %}

+ 3
- 0
linux/network/init.sls View File

{%- if network.dpdk is defined %} {%- if network.dpdk is defined %}
- linux.network.dpdk - linux.network.dpdk
{%- endif %} {%- endif %}
{%- if network.dhclient is defined %}
- linux.network.dhclient
{%- endif %}
{%- if network.interface|length > 0 %} {%- if network.interface|length > 0 %}
- linux.network.interface - linux.network.interface
{%- endif %} {%- endif %}

+ 64
- 0
tests/pillar/network.sls View File

#type: vlan #type: vlan
#use_interfaces: #use_interfaces:
#- interface: ${linux:interface:eth0} #- interface: ${linux:interface:eth0}
dhclient:
enabled: true
backoff_cutoff: 15
initial_interval: 10
reboot: 10
retry: 60
select_timeout: 0
timeout: 120
send:
- option: host-name
declaration: "= gethostname()"
supersede:
- option: host-name
declaration: linux
- option: domain-name
declaration: ci.local
#- option: arp-cache-timeout
# declaration: 20
prepend:
- option: domain-name-servers
declaration:
- 8.8.8.8
- 8.8.4.4
- option: domain-search
declaration:
- example.com
- eng.example.com
# ip or subnet to reject dhcp offer from
reject:
- 10.0.2.0/24
request:
- subnet-mask
- broadcast-address
- time-offset
- routers
- domain-name
- domain-name-servers
- domain-search
- host-name
- dhcp6.name-servers
- dhcp6.domain-search
- dhcp6.fqdn
- dhcp6.sntp-servers
- netbios-name-servers
- netbios-scope
- interface-mtu
- rfc3442-classless-static-routes
- ntp-servers
require:
- subnet-mask
- domain-name-servers
# if per interface configuration required add below
# interface:
# ens2:
# initial_interval: 11
# request:
# - subnet-mask
# - broadcast-address
# reject:
# - 10.0.3.0/24
# ens3:
# initial_interval: 12
# reject:
# - 10.0.4.0/24

Loading…
Cancel
Save