Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12241998
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/_modules/node.py b/_modules/node.py
index 012ba80..0058e3e 100644
--- a/_modules/node.py
+++ b/_modules/node.py
@@ -1,82 +1,95 @@
# -*- 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
'''
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)
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Oct 12, 07:13 (19 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3061059
Default Alt Text
(2 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment