Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3789139
D1095.id2800.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D1095.id2800.diff
View Options
diff --git a/_modules/node.py b/_modules/node.py
new file mode 100644
--- /dev/null
+++ b/_modules/node.py
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+
+# -------------------------------------------------------------
+# Salt — Node execution module
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Created: 2017-10-21
+# Description: Functions related to FreeBSD jails
+# License: BSD-2-Clause
+# -------------------------------------------------------------
+
+
+def _get_all_nodes():
+ return __pillar__.get('nodes', {})
+
+
+def get(nodename=None):
+ '''
+ A function to get a node pillar configuration.
+
+ CLI Example:
+
+ salt * node.get
+ '''
+ if nodename is None:
+ nodename = __grains__['id']
+
+ all_nodes = _get_all_nodes()
+ return all_nodes[nodename]
+
+
+def _explode_key(k): return k.split(':')
+
+
+def _get_first_key(k): return _explode_key(k)[0]
+
+
+def _strip_first_key(k): return ':'.join(_explode_key(k)[1:])
+
+
+def _get_property(key, nodename, default_value, parent=None):
+ if parent is None:
+ parent = get(nodename)
+
+ if ':' in key:
+ first_key = _get_first_key(key)
+ if first_key in parent:
+ return _get_property(
+ _strip_first_key(key), nodename,
+ default_value, parent[first_key]
+ )
+ elif key in parent:
+ return parent[key]
+
+ return default_value
+
+
+def list(key, nodename=None):
+ '''
+ A function to get a node pillar configuration.
+
+ Returns a list if found, or an empty list if not found.
+
+ CLI Example:
+
+ salt * node.list network:ipv4_aliases
+ '''
+ return _get_property(key, nodename, [])
+
+
+def has(key, nodename=None):
+ '''
+ A function to get a node pillar configuration.
+
+ Returns a boolean, False if not found.
+
+ CLI Example:
+
+ salt * node.has network:ipv6_tunnel
+ '''
+ return _get_property(bool(key), nodename, False)
diff --git a/pillar/nodes/nodes.sls b/pillar/nodes/nodes.sls
--- a/pillar/nodes/nodes.sls
+++ b/pillar/nodes/nodes.sls
@@ -33,6 +33,11 @@
- devserver
- saltmaster
network:
+ ipv4_interface: igb0
+ ipv4_address: 163.172.49.16
+ ipv4_gateway: 163.172.49.1
+ ipv4_aliases:
+ - 213.83.187.132
ipv6_tunnel: True
##
## Forest: Eglide
diff --git a/roles/core/network/files/netif.rc b/roles/core/network/files/netif.rc
new file mode 100644
--- /dev/null
+++ b/roles/core/network/files/netif.rc
@@ -0,0 +1,23 @@
+# -------------------------------------------------------------
+# Network — rc configuration
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# Source file: roles/core/network/files/netif.rc
+# -------------------------------------------------------------
+#
+# <auto-generated>
+# This file is managed by our rOPS SaltStack repository.
+#
+# Changes to this file may cause incorrect behavior
+# and will be lost if the state is redeployed.
+# </auto-generated>
+
+{% if dhcp_required %}
+ifconfig_{{ interface }}="DHCP"
+{% else %}
+ifconfig_{{ interface }}="inet {{ ipv4_address }} netmask {{ ipv4_netmask }}"
+{% endif %}
+{% for ip in ipv4_aliases %}
+ifconfig_{{ interface }}_alias{{ loop.index0 }}="inet {{ ip }} netmask 255.255.255.255"
+{% endfor %}
diff --git a/roles/core/network/files/routing.rc b/roles/core/network/files/routing.rc
new file mode 100644
--- /dev/null
+++ b/roles/core/network/files/routing.rc
@@ -0,0 +1,16 @@
+# -------------------------------------------------------------
+# Network — rc configuration
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# Source file: roles/core/network/files/routing.rc
+# -------------------------------------------------------------
+#
+# <auto-generated>
+# This file is managed by our rOPS SaltStack repository.
+#
+# Changes to this file may cause incorrect behavior
+# and will be lost if the state is redeployed.
+# </auto-generated>
+
+defaultrouter="{{ ipv4_gateway }}"
diff --git a/roles/core/network/init.sls b/roles/core/network/init.sls
--- a/roles/core/network/init.sls
+++ b/roles/core/network/init.sls
@@ -8,11 +8,38 @@
{% from "map.jinja" import dirs with context %}
+{% set network = salt['node.get']()['network'] %}
+
+# -------------------------------------------------------------
+# IPv4
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{% if grains['os'] == 'FreeBSD' %}
+/etc/rc.conf.d/netif/ipv4_{{ network['ipv4_interface'] }}:
+ file.managed:
+ - source: salt://roles/core/network/files/netif.rc
+ - makedirs: True
+ - template: jinja
+ - context:
+ interface: {{ network['ipv4_interface'] }}
+ ipv4_address: {{ network['ipv4_address'] }}
+ ipv4_netmask: {{ network['ipv4_netmask'] | default('255.255.255.0') }}
+ ipv4_aliases: {{ salt['node.list']('network:ipv4_aliases') }}
+ dhcp_required: {{ salt['node.has']('network:dhcp_required') }}
+
+/etc/rc.conf.d/routing:
+ file.managed:
+ - source: salt://roles/core/network/files/routing.rc
+ - template: jinja
+ - context:
+ ipv4_gateway: {{ network['ipv4_gateway'] }}
+{% endif %}
+
# -------------------------------------------------------------
# IPv6
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-{% if salt['pillar.get']("nodes:" + grains['id'] + ":network:ipv6_tunnel", False) %}
+{% if salt['node.has']('network.ipv6_tunnel') %}
network_ipv6:
file.managed:
- name : {{ dirs.sbin }}/ipv6-setup-tunnel
diff --git a/roles/paas-jails/jails/init.sls b/roles/paas-jails/jails/init.sls
--- a/roles/paas-jails/jails/init.sls
+++ b/roles/paas-jails/jails/init.sls
@@ -28,7 +28,8 @@
jails_rc_netif:
file.managed:
- - name: /etc/rc.conf.d/netif
+ - name: /etc/rc.conf.d/netif/jails
+ - makedirs: True
- source: salt://roles/paas-jails/jails/files/netif.rc
jails_rc_ezjail:
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 28, 01:34 (21 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2267908
Default Alt Text
D1095.id2800.diff (6 KB)
Attached To
Mode
D1095: Configure network for FreeBSD servers
Attached
Detach File
Event Timeline
Log In to Comment