Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12239207
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/_modules/node.py b/_modules/node.py
index 0f99029..18ad56e 100644
--- a/_modules/node.py
+++ b/_modules/node.py
@@ -1,95 +1,117 @@
# -*- coding: utf-8 -*-
# -------------------------------------------------------------
# Salt — Node execution module
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2017-10-21
# Description: Functions related to the nodes pillar entry
# License: BSD-2-Clause
# -------------------------------------------------------------
+from salt.exceptions import CommandExecutionError, SaltCloudConfigError
+
+
def _get_all_nodes():
return __pillar__.get('nodes', {})
-def get(nodename=None):
+def get_all_properties(nodename=None):
'''
A function to get a node pillar configuration.
CLI Example:
- salt * node.get
+ salt * node.get_all_properties
'''
if nodename is None:
nodename = __grains__['id']
all_nodes = _get_all_nodes()
+
+ if nodename not in all_nodes:
+ raise CommandExecutionError(
+ SaltCloudConfigError(
+ "Node {0} not declared in pillar.".format(nodename)
+ )
+ )
+
return all_nodes[nodename]
+def get(key, nodename=None):
+ '''
+ A function to get a node pillar configuration key.
+
+ CLI Example:
+
+ salt * node.get hostname
+ '''
+ return _get_property(key, nodename, None)
+
+
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)
+ parent = get_all_properties(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
'''
value = _get_property(key, nodename, False)
return bool(value)
def has_role(role, nodename=None):
'''
A function to determine if a node has the specified role.
Returns a boolean, False if not found.
CLI Example:
salt * node.has_role devserver
'''
return role in list('roles', nodename)
diff --git a/roles/core/network/init.sls b/roles/core/network/init.sls
index 559145b..971e2c6 100644
--- a/roles/core/network/init.sls
+++ b/roles/core/network/init.sls
@@ -1,50 +1,50 @@
# -------------------------------------------------------------
# Salt — Network
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Nasqueron
# Created: 2016-06-15
# License: Trivial work, not eligible to copyright
# -------------------------------------------------------------
{% from "map.jinja" import dirs with context %}
-{% set network = salt['node.get']()['network'] %}
+{% 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'] }}
ipv6_gateway: {{ network['ipv6_gateway'] | default('') }}
{% endif %}
# -------------------------------------------------------------
# IPv6
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{% if salt['node.has']('network.ipv6_tunnel') %}
network_ipv6:
file.managed:
- name : {{ dirs.sbin }}/ipv6-setup-tunnel
- source: salt://roles/core/network/files/{{ grains['id'] }}_ipv6.sh.jinja
- template: jinja
- mode: 755
{% endif %}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Oct 11, 20:50 (15 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3063986
Default Alt Text
(4 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment