Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12870361
node.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
node.py
View Options
# -*- 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
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Mon, Nov 17, 15:48 (21 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3107985
Default Alt Text
node.py (1 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment